SVGGraphics.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. using UnityEngine;
  2. using System;
  3. using System.Collections.Generic;
  4. // TODO: Find a way to break this the hell up.
  5. // TODO: Normalize conventions away from Java-style SetX to properties.
  6. public class SVGGraphics {
  7. private ISVGDevice device;
  8. private SVGGraphicsFill graphicsFill;
  9. private SVGGraphicsStroke graphicsStroke;
  10. public Vector2 Size {
  11. set {
  12. int width = (int)value.x,
  13. height = (int)value.y;
  14. device.SetDevice(width, height);
  15. graphicsFill.Size = new Vector2(width, height);
  16. Clean();
  17. }
  18. }
  19. public SVGStrokeLineCapMethod StrokeLineCap { get; set; }
  20. public SVGStrokeLineJoinMethod StrokeLineJoin { get; set; }
  21. public SVGGraphics() {
  22. graphicsFill = new SVGGraphicsFill(this);
  23. graphicsStroke = new SVGGraphicsStroke(this);
  24. }
  25. public SVGGraphics(ISVGDevice dev) {
  26. device = dev;
  27. graphicsFill = new SVGGraphicsFill(this);
  28. graphicsStroke = new SVGGraphicsStroke(this);
  29. }
  30. public void SetColor(Color color) {
  31. device.SetColor(color);
  32. }
  33. public void SetPixel(int x, int y) {
  34. device.SetPixel(x, y);
  35. }
  36. public Texture2D Render() {
  37. return device.Render();
  38. }
  39. public void Clean() {
  40. int width = device.Width;
  41. int height = device.Height;
  42. SetColor(Color.white);
  43. for(int i = 0; i < width; i++) {
  44. for(int j = 0; j < height; j++)
  45. SetPixel(i, j);
  46. }
  47. }
  48. //Tinh 4 diem 1, 2, 3, 4 cua 1 line voi width
  49. public bool GetThickLine(Vector2 p1, Vector2 p2, float width,
  50. ref Vector2 rp1, ref Vector2 rp2, ref Vector2 rp3, ref Vector2 rp4) {
  51. float cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
  52. float dtx, dty, temp, _half;
  53. int _ihalf1, _ihalf2;
  54. _half = width / 2f;
  55. _ihalf1 = (int)_half;
  56. _ihalf2 = (int)(width - _ihalf1 + 0.5f);
  57. dtx = p2.x - p1.x;
  58. dty = p2.y - p1.y;
  59. temp = dtx * dtx + dty * dty;
  60. if(temp == 0f) {
  61. rp1.x = p1.x - _ihalf2;
  62. rp1.y = p1.y + _ihalf2;
  63. rp2.x = p1.x - _ihalf2;
  64. rp2.y = p1.y - _ihalf2;
  65. rp3.x = p1.x + _ihalf1;
  66. rp3.y = p1.y + _ihalf1;
  67. rp4.x = p1.x + _ihalf1;
  68. rp4.y = p1.y - _ihalf1;
  69. return false;
  70. }
  71. cy1 = _ihalf1 * dtx / (float)Math.Sqrt(temp) + p1.y;
  72. if(dtx == 0) {
  73. if(dty > 0)
  74. cx1 = p1.x - _ihalf1;
  75. else
  76. cx1 = p1.x + _ihalf1;
  77. } else
  78. cx1 = (-(cy1 - p1.y) * dty) / dtx + p1.x;
  79. cy2 = -(_ihalf2 * dtx / (float)Math.Sqrt(temp)) + p1.y;
  80. if(dtx == 0) {
  81. if(dty > 0)
  82. cx2 = p1.x + _ihalf2;
  83. else
  84. cx2 = p1.x - _ihalf2;
  85. } else
  86. cx2 = (-(cy2 - p1.y) * dty) / dtx + p1.x;
  87. dtx = p1.x - p2.x;
  88. dty = p1.y - p2.y;
  89. temp = dtx * dtx + dty * dty;
  90. cy3 = _ihalf1 * dtx / (float)Math.Sqrt(temp) + p2.y;
  91. if(dtx == 0) {
  92. if(dty > 0)
  93. cx3 = p2.x - _ihalf1;
  94. else
  95. cx3 = p2.x + _ihalf1;
  96. } else
  97. cx3 = (-(cy3 - p2.y) * dty) / dtx + p2.x;
  98. cy4 = -(_ihalf2 * dtx / (float)Math.Sqrt(temp)) + p2.y;
  99. if(dtx == 0) {
  100. if(dty > 0)
  101. cx4 = p2.x + _ihalf2;
  102. else
  103. cx4 = p2.x - _ihalf2;
  104. } else
  105. cx4 = (-(cy4 - p2.y) * dty) / dtx + p2.x;
  106. rp1.x = cx1;
  107. rp1.y = cy1;
  108. rp2.x = cx2;
  109. rp2.y = cy2;
  110. float t1, t2;
  111. t1 = ((p1.y - cy1) * (p2.x - p1.x)) - ((p1.x - cx1) * (p2.y - p1.y));
  112. t2 = ((p1.y - cy4) * (p2.x - p1.x)) - ((p1.x - cx4) * (p2.y - p1.y));
  113. if(t1 * t2 > 0) {
  114. //bi lech
  115. if(_ihalf1 != _ihalf2) {
  116. cy3 = _ihalf2 * dtx / (float)Math.Sqrt(temp) + p2.y;
  117. if(dtx == 0) {
  118. if(dty > 0)
  119. cx3 = p2.x - _ihalf2;
  120. else
  121. cx3 = p2.x + _ihalf2;
  122. } else
  123. cx3 = (-(cy3 - p2.y) * dty) / dtx + p2.x;
  124. cy4 = -(_ihalf1 * dtx / (float)Math.Sqrt(temp)) + p2.y;
  125. if(dtx == 0) {
  126. if(dty > 0)
  127. cx4 = p2.x + _ihalf1;
  128. else
  129. cx4 = p2.x - _ihalf1;
  130. } else
  131. cx4 = (-(cy4 - p2.y) * dty) / dtx + p2.x;
  132. }
  133. rp3.x = cx4;
  134. rp3.y = cy4;
  135. rp4.x = cx3;
  136. rp4.y = cy3;
  137. } else {
  138. rp3.x = cx3;
  139. rp3.y = cy3;
  140. rp4.x = cx4;
  141. rp4.y = cy4;
  142. }
  143. return true;
  144. }
  145. //Tinh diem giao nhau giua 2 doan thang
  146. public Vector2 GetCrossPoint(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4) {
  147. Vector2 _return = new Vector2(0f, 0f);
  148. float a1 = 0f, b1 = 0f, a2 = 0f, b2 = 0f;
  149. float dx1, dy1, dx2, dy2;
  150. dx1 = p1.x - p2.x;
  151. dy1 = p1.y - p2.y;
  152. dx2 = p3.x - p4.x;
  153. dy2 = p3.y - p4.y;
  154. if(dx1 != 0f) {
  155. a1 = dy1 / dx1;
  156. b1 = p1.y - a1 * p1.x;
  157. }
  158. if(dx2 != 0) {
  159. a2 = dy2 / dx2;
  160. b2 = p3.y - a2 * p3.x;
  161. }
  162. float tx = 0f, ty = 0f;
  163. //truong hop nam tren duong thang
  164. if((a1 == a2) && (b1 == b2)) {
  165. Vector2 t_p1 = p1;
  166. Vector2 t_p2 = p1;
  167. if(dx1 == 0f) {
  168. if(p2.y < t_p1.y)
  169. t_p1 = p2;
  170. if(p3.y < t_p1.y)
  171. t_p1 = p3;
  172. if(p4.y < t_p1.y)
  173. t_p1 = p4;
  174. if(p2.y > t_p2.y)
  175. t_p2 = p2;
  176. if(p3.y > t_p2.y)
  177. t_p2 = p3;
  178. if(p4.y > t_p2.y)
  179. t_p2 = p4;
  180. } else {
  181. if(p2.x < t_p1.x)
  182. t_p1 = p2;
  183. if(p3.x < t_p1.x)
  184. t_p1 = p3;
  185. if(p4.x < t_p1.x)
  186. t_p1 = p4;
  187. if(p2.x > t_p2.x)
  188. t_p2 = p2;
  189. if(p3.x > t_p2.x)
  190. t_p2 = p3;
  191. if(p4.x > t_p2.x)
  192. t_p2 = p4;
  193. }
  194. tx = (t_p1.x - t_p2.x) / 2f;
  195. tx = t_p2.x + tx;
  196. ty = (t_p1.y - t_p2.y) / 2f;
  197. ty = t_p2.y + ty;
  198. _return.x = tx;
  199. _return.y = ty;
  200. return _return;
  201. }
  202. if((dx1 != 0) && (dx2 != 0)) {
  203. tx = -(b1 - b2) / (a1 - a2);
  204. ty = a1 * tx + b1;
  205. } else if((dx1 == 0) && (dx2 != 0)) {
  206. tx = p1.x;
  207. ty = a2 * tx + b2;
  208. } else if((dx1 != 0) && (dx2 == 0)) {
  209. tx = p3.x;
  210. ty = a1 * tx + b1;
  211. }
  212. _return.x = tx;
  213. _return.y = ty;
  214. return _return;
  215. }
  216. public float AngleBetween2Vector(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4) {
  217. Vector2 vt1, vt2;
  218. vt1 = new Vector2(p2.x - p1.x, p2.y - p1.y);
  219. vt2 = new Vector2(p4.x - p3.x, p4.y - p3.y);
  220. float t1 = vt1.x * vt2.x + vt1.y * vt2.y;
  221. float gtvt1 = (float)Math.Sqrt(vt1.x * vt1.x + vt1.y * vt1.y);
  222. float gtvt2 = (float)Math.Sqrt(vt2.x * vt2.x + vt2.y * vt2.y);
  223. float t2 = gtvt1 * gtvt2;
  224. float cosAngle = t1 / t2;
  225. return ((float)Math.Acos(cosAngle));
  226. }
  227. public void Line(Vector2 p1, Vector2 p2) {
  228. graphicsStroke.Line(p1, p2);
  229. }
  230. public void Line(Vector2 p1, Vector2 p2, SVGColor? strokeColor) {
  231. if(strokeColor != null)
  232. SetColor(strokeColor.Value.color);
  233. Line(p1, p2);
  234. }
  235. public void Line(Vector2 p1, Vector2 p2, float width) {
  236. graphicsStroke.Line(p1, p2, width);
  237. }
  238. public void Line(Vector2 p1, Vector2 p2, SVGColor? strokeColor, float width) {
  239. if(strokeColor != null)
  240. SetColor(strokeColor.Value.color);
  241. Line(p1, p2, width);
  242. }
  243. public void Rect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4) {
  244. graphicsStroke.Rect(p1, p2, p3, p4);
  245. }
  246. public void Rect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, SVGColor? strokeColor) {
  247. if(strokeColor != null)
  248. SetColor(strokeColor.Value.color);
  249. Rect(p1, p2, p3, p4);
  250. }
  251. public void Rect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float width) {
  252. graphicsStroke.Rect(p1, p2, p3, p4, width);
  253. }
  254. public void Rect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  255. SVGColor? strokeColor, float width) {
  256. if(strokeColor != null)
  257. SetColor(strokeColor.Value.color);
  258. Rect(p1, p2, p3, p4, width);
  259. }
  260. public void RoundedRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  261. Vector2 p5, Vector2 p6, Vector2 p7, Vector2 p8,
  262. float r1, float r2, float angle) {
  263. graphicsStroke.RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle);
  264. }
  265. public void RoundedRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  266. Vector2 p5, Vector2 p6, Vector2 p7, Vector2 p8,
  267. float r1, float r2, float angle, SVGColor? strokeColor) {
  268. if(strokeColor != null)
  269. SetColor(strokeColor.Value.color);
  270. RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle);
  271. }
  272. public void RoundedRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  273. Vector2 p5, Vector2 p6, Vector2 p7, Vector2 p8,
  274. float r1, float r2, float angle, float width) {
  275. if((int)width == 1) {
  276. RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle);
  277. return;
  278. }
  279. graphicsStroke.RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle, width);
  280. }
  281. public void RoundedRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  282. Vector2 p5, Vector2 p6, Vector2 p7, Vector2 p8,
  283. float r1, float r2, float angle, SVGColor? strokeColor, float width) {
  284. if(strokeColor != null)
  285. SetColor(strokeColor.Value.color);
  286. RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle, width);
  287. }
  288. public void FillRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4) {
  289. graphicsFill.Rect(p1, p2, p3, p4);
  290. }
  291. public void FillRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  292. SVGColor? strokeColor) {
  293. graphicsFill.Rect(p1, p2, p3, p4, strokeColor);
  294. }
  295. public void FillRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  296. SVGColor fillColor, SVGColor? strokeColor) {
  297. graphicsFill.Rect(p1, p2, p3, p4, fillColor, strokeColor);
  298. }
  299. public void FillRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  300. SVGColor? strokeColor, float width) {
  301. if((int)width == 1) {
  302. FillRect(p1, p2, p3, p4, strokeColor);
  303. return;
  304. }
  305. FillRect(p1, p2, p3, p4);
  306. if(strokeColor == null)
  307. return;
  308. SetColor(strokeColor.Value.color);
  309. Rect(p1, p2, p3, p4, strokeColor, width);
  310. }
  311. public void FillRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  312. SVGColor fillColor, SVGColor? strokeColor, float width) {
  313. if((int)width == 1) {
  314. FillRect(p1, p2, p3, p4, fillColor, strokeColor);
  315. return;
  316. }
  317. SetColor(fillColor.color);
  318. FillRect(p1, p2, p3, p4);
  319. if(strokeColor == null)
  320. return;
  321. SetColor(strokeColor.Value.color);
  322. Rect(p1, p2, p3, p4, strokeColor, width);
  323. }
  324. public void FillRoundedRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  325. Vector2 p5, Vector2 p6, Vector2 p7, Vector2 p8,
  326. float r1, float r2, float angle) {
  327. graphicsFill.RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle);
  328. }
  329. public void FillRoundedRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  330. Vector2 p5, Vector2 p6, Vector2 p7, Vector2 p8,
  331. float r1, float r2, float angle,
  332. SVGColor? strokeColor) {
  333. graphicsFill.RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle, strokeColor);
  334. }
  335. public void FillRoundedRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  336. Vector2 p5, Vector2 p6, Vector2 p7, Vector2 p8,
  337. float r1, float r2, float angle,
  338. SVGColor fillColor, SVGColor? strokeColor) {
  339. graphicsFill.RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle,
  340. fillColor, strokeColor);
  341. }
  342. public void FillRoundedRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  343. Vector2 p5, Vector2 p6, Vector2 p7, Vector2 p8,
  344. float r1, float r2, float angle,
  345. SVGColor? strokeColor, float width) {
  346. if((int)width == 1) {
  347. FillRoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle, strokeColor);
  348. return;
  349. }
  350. graphicsFill.RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle);
  351. if(strokeColor == null)
  352. return;
  353. SetColor(strokeColor.Value.color);
  354. RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle, strokeColor);
  355. }
  356. public void FillRoundedRect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
  357. Vector2 p5, Vector2 p6, Vector2 p7, Vector2 p8,
  358. float r1, float r2, float angle,
  359. SVGColor fillColor, SVGColor? strokeColor, float width) {
  360. if((int)width == 1) {
  361. FillRoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle, strokeColor);
  362. return;
  363. }
  364. SetColor(fillColor.color);
  365. graphicsFill.RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle);
  366. if(strokeColor == null)
  367. return;
  368. SetColor(strokeColor.Value.color);
  369. RoundedRect(p1, p2, p3, p4, p5, p6, p7, p8, r1, r2, angle, strokeColor);
  370. }
  371. public void Circle(Vector2 p, float r) {
  372. graphicsStroke.Circle(p, r);
  373. }
  374. public void Circle(Vector2 p, float r, SVGColor? strokeColor) {
  375. if(strokeColor != null)
  376. SetColor(strokeColor.Value.color);
  377. Circle(p, r);
  378. }
  379. public void Circle(Vector2 p, float r, float width) {
  380. graphicsStroke.Circle(p, r, width);
  381. }
  382. public void Circle(Vector2 p, float r,
  383. SVGColor? strokeColor, float width) {
  384. if(strokeColor != null)
  385. SetColor(strokeColor.Value.color);
  386. Circle(p, r, width);
  387. }
  388. public void FillCircle(Vector2 p, float r) {
  389. graphicsFill.Circle(p, r);
  390. }
  391. public void FillCircle(Vector2 p, float r, SVGColor? strokeColor) {
  392. graphicsFill.Circle(p, r, strokeColor);
  393. }
  394. public void FillCircle(Vector2 p, float r, SVGColor fillColor, SVGColor? strokeColor) {
  395. graphicsFill.Circle(p, r, fillColor, strokeColor);
  396. }
  397. public void FillCircle(Vector2 p, float r,
  398. SVGColor? strokeColor, float width) {
  399. if((int)width == 1) {
  400. FillCircle(p, r, strokeColor);
  401. return;
  402. }
  403. FillCircle(p, r);
  404. if(strokeColor == null)
  405. return;
  406. SetColor(strokeColor.Value.color);
  407. Circle(p, r, strokeColor, width);
  408. }
  409. public void FillCircle(Vector2 p, float r,
  410. SVGColor fillColor, SVGColor? strokeColor, float width) {
  411. if((int)width == 1) {
  412. FillCircle(p, r, strokeColor);
  413. return;
  414. }
  415. SetColor(fillColor.color);
  416. FillCircle(p, r);
  417. if(strokeColor == null)
  418. return;
  419. SetColor(strokeColor.Value.color);
  420. Circle(p, r, strokeColor, width);
  421. }
  422. public void Ellipse(Vector2 p, float rx, float ry, float angle) {
  423. graphicsStroke.Ellipse(p, rx, ry, angle);
  424. }
  425. public void Ellipse(Vector2 p, float rx, float ry, float angle, SVGColor? strokeColor) {
  426. if(strokeColor != null)
  427. SetColor(strokeColor.Value.color);
  428. Ellipse(p, rx, ry, angle);
  429. }
  430. public void Ellipse(Vector2 p, float rx, float ry, float angle, float width) {
  431. graphicsStroke.Ellipse(p, rx, ry, angle, width);
  432. }
  433. public void Ellipse(Vector2 p, float rx, float ry, float angle,
  434. SVGColor? strokeColor, float width) {
  435. if(strokeColor != null)
  436. SetColor(strokeColor.Value.color);
  437. Ellipse(p, rx, ry, angle, width);
  438. }
  439. public void FillEllipse(Vector2 p, float rx, float ry, float angle) {
  440. graphicsFill.Ellipse(p, rx, ry, angle);
  441. }
  442. public void FillEllipse(Vector2 p, float rx, float ry, float angle, SVGColor? strokeColor) {
  443. graphicsFill.Ellipse(p, rx, ry, angle, strokeColor);
  444. }
  445. public void FillEllipse(Vector2 p, float rx, float ry, float angle,
  446. SVGColor fillColor, SVGColor? strokeColor) {
  447. graphicsFill.Ellipse(p, rx, ry, angle, fillColor, strokeColor);
  448. }
  449. public void FillEllipse(Vector2 p, float rx, float ry, float angle,
  450. SVGColor? strokeColor, float width) {
  451. if((int)width == 1) {
  452. FillEllipse(p, rx, ry, angle, strokeColor);
  453. return;
  454. }
  455. FillEllipse(p, rx, ry, angle);
  456. if(strokeColor == null)
  457. return;
  458. SetColor(strokeColor.Value.color);
  459. Ellipse(p, rx, ry, angle, width);
  460. }
  461. public void FillEllipse(Vector2 p, float rx, float ry, float angle,
  462. SVGColor fillColor, SVGColor? strokeColor, float width) {
  463. if((int)width == 1) {
  464. FillEllipse(p, rx, ry, angle, strokeColor);
  465. return;
  466. }
  467. SetColor(fillColor.color);
  468. FillEllipse(p, rx, ry, angle);
  469. if(strokeColor == null)
  470. return;
  471. SetColor(strokeColor.Value.color);
  472. Ellipse(p, rx, ry, angle, width);
  473. }
  474. public void Polygon(Vector2[] points) {
  475. graphicsStroke.Polygon(points);
  476. }
  477. public void Polygon(Vector2[] points, SVGColor? strokeColor) {
  478. if(strokeColor != null)
  479. SetColor(strokeColor.Value.color);
  480. Polygon(points);
  481. }
  482. public void Polygon(Vector2[] points, float width) {
  483. graphicsStroke.Polygon(points, width);
  484. }
  485. public void Polygon(Vector2[] points, SVGColor? strokeColor, float width) {
  486. if(strokeColor != null)
  487. SetColor(strokeColor.Value.color);
  488. Polygon(points, width);
  489. }
  490. public void FillPolygon(Vector2[] points) {
  491. graphicsFill.Polygon(points);
  492. }
  493. public void FillPolygon(Vector2[] points, SVGColor? strokeColor) {
  494. graphicsFill.Polygon(points, strokeColor);
  495. }
  496. public void FillPolygon(Vector2[] points, SVGColor fillColor, SVGColor? strokeColor) {
  497. graphicsFill.Polygon(points, fillColor, strokeColor);
  498. }
  499. public void FillPolygon(Vector2[] points, SVGColor? strokeColor, float width) {
  500. if((int)width == 1) {
  501. FillPolygon(points, strokeColor);
  502. return;
  503. }
  504. FillPolygon(points);
  505. if(strokeColor == null)
  506. return;
  507. SetColor(strokeColor.Value.color);
  508. Polygon(points, width);
  509. }
  510. public void FillPolygon(Vector2[] points,
  511. SVGColor fillColor, SVGColor? strokeColor, float width) {
  512. if((int)width == 1) {
  513. FillPolygon(points, strokeColor);
  514. return;
  515. }
  516. SetColor(fillColor.color);
  517. FillPolygon(points);
  518. if(strokeColor == null)
  519. return;
  520. SetColor(strokeColor.Value.color);
  521. Polygon(points, width);
  522. }
  523. //Fill khong to Stroke
  524. public void FillPath(SVGLinearGradientBrush linearGradientBrush,
  525. SVGGraphicsPath graphicsPath) {
  526. graphicsFill.FillPath(linearGradientBrush, graphicsPath);
  527. }
  528. //Fill co Stroke trong do luon
  529. public void FillPath(SVGLinearGradientBrush linearGradientBrush,
  530. SVGColor? strokePathColor,
  531. SVGGraphicsPath graphicsPath) {
  532. graphicsFill.FillPath(linearGradientBrush, strokePathColor, graphicsPath);
  533. }
  534. //Fill khong co Stroke, va ve stroke sau
  535. public void FillPath(SVGLinearGradientBrush linearGradientBrush,
  536. SVGColor? strokePathColor,
  537. float width,
  538. SVGGraphicsPath graphicsPath) {
  539. graphicsFill.FillPath(linearGradientBrush, strokePathColor, graphicsPath);
  540. if((int)width == 1)
  541. graphicsFill.FillPath(linearGradientBrush, strokePathColor, graphicsPath);
  542. else
  543. graphicsFill.FillPath(linearGradientBrush, graphicsPath);
  544. if(strokePathColor == null)
  545. return;
  546. SetColor(strokePathColor.Value.color);
  547. }
  548. //Fill khong to Stroke
  549. public void FillPath(SVGRadialGradientBrush radialGradientBrush,
  550. SVGGraphicsPath graphicsPath) {
  551. graphicsFill.FillPath(radialGradientBrush, graphicsPath);
  552. }
  553. //Fill co Stroke trong do luon
  554. public void FillPath(SVGRadialGradientBrush radialGradientBrush,
  555. SVGColor? strokePathColor,
  556. SVGGraphicsPath graphicsPath) {
  557. graphicsFill.FillPath(radialGradientBrush, strokePathColor, graphicsPath);
  558. }
  559. //Fill khong co Stroke, va ve stroke sau
  560. public void FillPath(SVGRadialGradientBrush radialGradientBrush,
  561. SVGColor? strokePathColor,
  562. float width,
  563. SVGGraphicsPath graphicsPath) {
  564. graphicsFill.FillPath(radialGradientBrush, strokePathColor, graphicsPath);
  565. if((int)width == 1)
  566. graphicsFill.FillPath(radialGradientBrush, strokePathColor, graphicsPath);
  567. else
  568. graphicsFill.FillPath(radialGradientBrush, graphicsPath);
  569. if(strokePathColor == null)
  570. return;
  571. SetColor(strokePathColor.Value.color);
  572. //graphicsPath.RenderPath(this, width, false);
  573. }
  574. //Fill khong to Stroke
  575. public void FillPath(SVGGraphicsPath graphicsPath) {
  576. graphicsFill.FillPath(graphicsPath);
  577. }
  578. //Fill khong to Stroke
  579. public void FillPath(SVGColor fillColor, SVGGraphicsPath graphicsPath) {
  580. graphicsFill.FillPath(fillColor, graphicsPath);
  581. }
  582. //Fill co Stroke trong do luon
  583. public void FillPath(SVGColor fillColor, SVGColor? strokePathColor,
  584. SVGGraphicsPath graphicsPath) {
  585. graphicsFill.FillPath(fillColor, strokePathColor, graphicsPath);
  586. }
  587. //Fill khong co Stroke, va ve stroke sau
  588. public void FillPath(SVGColor fillColor, SVGColor? strokePathColor,
  589. float width,
  590. SVGGraphicsPath graphicsPath) {
  591. graphicsFill.FillPath(fillColor, strokePathColor, graphicsPath);
  592. if((int)width == 1)
  593. graphicsFill.FillPath(fillColor, strokePathColor, graphicsPath);
  594. else
  595. graphicsFill.FillPath(fillColor, graphicsPath);
  596. if(strokePathColor == null)
  597. return;
  598. SetColor(strokePathColor.Value.color);
  599. }
  600. public void FillPath(SVGGraphicsPath graphicsPath, Vector2[] points) {
  601. graphicsFill.FillPath(graphicsPath, points);
  602. }
  603. public void FillPath(SVGGraphicsPath graphicsPath, Vector2 point) {
  604. graphicsFill.FillPath(graphicsPath, point);
  605. }
  606. public void DrawPath(SVGGraphicsPath graphicsPath) {
  607. graphicsStroke.DrawPath(graphicsPath);
  608. }
  609. //Fill co Stroke trong do luon
  610. public void DrawPath(SVGGraphicsPath graphicsPath, float width) {
  611. graphicsStroke.DrawPath(graphicsPath, width);
  612. }
  613. //Fill khong co Stroke, va ve stroke sau
  614. public void DrawPath(SVGGraphicsPath graphicsPath, float width, SVGColor? strokePathColor) {
  615. if(strokePathColor == null)
  616. return;
  617. SetColor(strokePathColor.Value.color);
  618. graphicsStroke.DrawPath(graphicsPath, width);
  619. }
  620. }