UnityGraphics.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using UnityEngine;
  5. using CommonUI.Gemo;
  6. using CommonUI.Display;
  7. using CommonLang;
  8. namespace CommonUI_Unity3D.Impl
  9. {
  10. public class UnityGraphics : CommonUI.Display.Graphics
  11. {
  12. private Stack<GraphicsStatus> stack_clips = new Stack<GraphicsStatus>();
  13. private GraphicsStatus cur_clip;
  14. private Matrix4x4 root_matrix;
  15. private Matrix4x4 cur_matrix;
  16. private Stack<Matrix4x4> stack_matrix = new Stack<Matrix4x4>();
  17. private Blend mBlend = Blend.BLEND_MODE_NORMAL;
  18. private uint mColor = 0xFFFFFFFF;
  19. private UnityEngine.Color mUnityColor = UnityEngine.Color.white;
  20. private float mAlpha = 1.0f;
  21. private IUnityImageInterface cur_uimg;
  22. private List<UnityQuards2D> mQuadsBatch = new List<UnityQuards2D>(100);
  23. public UnityGraphics()
  24. {
  25. }
  26. public void Begin()
  27. {
  28. GL.PushMatrix();
  29. GL.Viewport(new Rect(0, 0, Screen.width, Screen.height));
  30. Matrix4x4 m1 = Matrix4x4.TRS(
  31. new Vector3(0, Screen.height, 0),
  32. Quaternion.identity,
  33. new Vector3(1f, -1f, 1f));
  34. GL.MultMatrix(m1);
  35. this.tx_translate = Vector3.zero;
  36. this.root_matrix = m1;
  37. this.cur_matrix = Matrix4x4.identity;
  38. this.stack_matrix.Push(cur_matrix);
  39. this.cur_clip.mat = root_matrix;
  40. this.cur_clip.clip = new Rect(0, 0, Screen.width, Screen.height);
  41. this.stack_clips.Push(cur_clip);
  42. this.mAlpha = 1;
  43. this.mColor = 0xFFFFFFFF;
  44. this.mUnityColor = UnityEngine.Color.white;
  45. this.mBlend = Blend.BLEND_MODE_NORMAL;
  46. UnityShaders.SetAlpha(1);
  47. UnityShaders.SetColor(mUnityColor);
  48. UnityShaders.SetBlend(mBlend);
  49. }
  50. public void End()
  51. {
  52. FlushQuadsBath();
  53. this.stack_clips.Clear();
  54. this.stack_matrix.Clear();
  55. GL.Viewport(new Rect(0, 0, Screen.width, Screen.height));
  56. GL.PopMatrix();
  57. }
  58. public override void Dispose()
  59. {
  60. }
  61. //-----------------------------------------------------------------------------------------------
  62. #region COLOR
  63. public override void setBlend(CommonUI.Display.Blend blend)
  64. {
  65. if(blend != mBlend)
  66. {
  67. FlushQuadsBath();
  68. mBlend = blend;
  69. UnityShaders.SetBlend(blend);
  70. }
  71. }
  72. public override Blend getBlend()
  73. {
  74. return mBlend;
  75. }
  76. public override void setAlpha(float alpha)
  77. {
  78. if(mAlpha != alpha)
  79. {
  80. FlushQuadsBath();
  81. mAlpha = alpha;
  82. UnityShaders.SetAlpha(alpha);
  83. }
  84. }
  85. public override void setColor(uint color)
  86. {
  87. if(mColor != color)
  88. {
  89. mColor = color;
  90. CommonUI.Display.Color.toRGBAF(color,
  91. out mUnityColor.r,
  92. out mUnityColor.g,
  93. out mUnityColor.b,
  94. out mUnityColor.a);
  95. UnityShaders.SetColor(mUnityColor);
  96. }
  97. }
  98. public override void setColor(int red, int green, int blue)
  99. {
  100. uint color = CommonUI.Display.Color.toRGBA(red, green, blue, 255);
  101. setColor(color);
  102. }
  103. public override void setColor(int red, int green, int blue, int alpha)
  104. {
  105. uint color = CommonUI.Display.Color.toRGBA(red, green, blue, alpha);
  106. setColor(color);
  107. }
  108. public override void setColor(float red, float green, float blue, float alpha)
  109. {
  110. uint color = CommonUI.Display.Color.toRGBA(red, green, blue, alpha);
  111. setColor(color);
  112. }
  113. public override uint getColor()
  114. {
  115. return mColor;
  116. }
  117. public override float getAlpha()
  118. {
  119. return mAlpha;
  120. }
  121. #endregion
  122. //-----------------------------------------------------------------------------------------------
  123. #region CLIP
  124. public override void SetClip(Rectangle2D rect)
  125. {
  126. SetClip(rect.x, rect.y, rect.width, rect.height);
  127. }
  128. public override void SetClip(float x, float y, float w, float h)
  129. {
  130. FlushQuadsBath();
  131. float x2 = x + w;
  132. float y2 = y + h;
  133. x = Math.Max(x, 0);
  134. x = Math.Min(x, Screen.width);
  135. y = Math.Max(y, 0);
  136. y = Math.Min(y, Screen.height);
  137. x2 = Math.Max(x2, 0);
  138. x2 = Math.Min(x2, Screen.width);
  139. y2 = Math.Max(y2, 0);
  140. y2 = Math.Min(y2, Screen.height);
  141. w = x2 - x;
  142. h = y2 - y;
  143. if(x != cur_clip.clip.x ||
  144. y != cur_clip.clip.y ||
  145. w != cur_clip.clip.width ||
  146. h != cur_clip.clip.height)
  147. {
  148. Rect clip = new Rect(x, y, w, h);
  149. Matrix4x4 m2 = Matrix4x4.TRS(
  150. Vector3.zero,
  151. Quaternion.identity,
  152. new Vector3(Screen.width / clip.width, (Screen.height / clip.height), 1f));
  153. Matrix4x4 m3 = Matrix4x4.TRS(
  154. new Vector3(0, clip.height, 0),
  155. Quaternion.identity,
  156. new Vector3(1f, -1f, 1f));
  157. Matrix4x4 m4 = Matrix4x4.TRS(
  158. new Vector3(-x, -y, 0),
  159. Quaternion.identity,
  160. Vector3.one);
  161. cur_clip.clip = clip;
  162. cur_clip.mat = m2 * m3 * m4;
  163. root_matrix = cur_clip.mat;
  164. GL.Viewport(new Rect(clip.x, Screen.height - clip.y - clip.height, clip.width, clip.height));
  165. GL.MultMatrix(root_matrix * cur_matrix);
  166. //cur_material.SetColor("_clrBase", mColor);
  167. }
  168. }
  169. public override void PushClip()
  170. {
  171. cur_clip.mat = root_matrix;
  172. stack_clips.Push(cur_clip);
  173. }
  174. public override void PopClip()
  175. {
  176. if (stack_clips.Count > 0)
  177. {
  178. FlushQuadsBath();
  179. cur_clip = stack_clips.Pop();
  180. root_matrix = cur_clip.mat;
  181. Rect clip = cur_clip.clip;
  182. GL.Viewport(new Rect(clip.x, Screen.height - clip.y - clip.height, clip.width, clip.height));
  183. GL.MultMatrix(root_matrix * cur_matrix);
  184. }
  185. }
  186. #endregion
  187. //-----------------------------------------------------------------------------------------------
  188. #region TRANSFORM
  189. private Vector3 tx_translate = Vector3.zero;
  190. public static bool IsIgnoreTranslateDrawcall = false;
  191. private void flush_translate()
  192. {
  193. if (IsIgnoreTranslateDrawcall)
  194. {
  195. if (tx_translate.x != 0 || tx_translate.y != 0)
  196. {
  197. Matrix4x4 m = Matrix4x4.TRS(
  198. tx_translate,
  199. Quaternion.identity,
  200. Vector3.one);
  201. cur_matrix = cur_matrix * m;
  202. GL.MultMatrix(root_matrix * cur_matrix);
  203. tx_translate = Vector3.zero;
  204. }
  205. }
  206. }
  207. public override void translate(float x, float y)
  208. {
  209. if (x != 0 || y != 0)
  210. {
  211. if (IsIgnoreTranslateDrawcall)
  212. {
  213. tx_translate.x += x;
  214. tx_translate.y += y;
  215. }
  216. else
  217. {
  218. FlushQuadsBath();
  219. Matrix4x4 m = Matrix4x4.TRS(
  220. new Vector3(x, y, 0),
  221. Quaternion.identity,
  222. Vector3.one);
  223. cur_matrix = cur_matrix * m;
  224. GL.MultMatrix(root_matrix * cur_matrix);
  225. }
  226. }
  227. }
  228. public override void rotate(float angle)
  229. {
  230. if (angle != 0)
  231. {
  232. FlushQuadsBath();
  233. Matrix4x4 m = Matrix4x4.TRS(
  234. Vector3.zero,
  235. Quaternion.Euler(0f, 0f, angle),
  236. Vector3.one);
  237. cur_matrix = cur_matrix * m;
  238. GL.MultMatrix(root_matrix * cur_matrix);
  239. }
  240. }
  241. public override void scale(float sx, float sy)
  242. {
  243. if (sx != 1 || sy != 1)
  244. {
  245. FlushQuadsBath();
  246. Matrix4x4 m = Matrix4x4.TRS(
  247. Vector3.zero,
  248. Quaternion.identity,
  249. new Vector3(sx, sy, 1.0f));
  250. cur_matrix = cur_matrix * m;
  251. GL.MultMatrix(root_matrix * cur_matrix);
  252. }
  253. }
  254. public override void pushTransform()
  255. {
  256. stack_matrix.Push(cur_matrix);
  257. }
  258. public override void popTransform()
  259. {
  260. FlushQuadsBath();
  261. cur_matrix = stack_matrix.Pop();
  262. GL.MultMatrix(root_matrix * cur_matrix);
  263. }
  264. private static void transAnchor(Anchor anchor, float w, float h, ref float x, ref float y)
  265. {
  266. float tx = 0, ty = 0;
  267. if((anchor & Anchor.ANCHOR_HCENTER) != 0)
  268. {
  269. tx = -w / 2;
  270. }
  271. else if((anchor & Anchor.ANCHOR_RIGHT) != 0)
  272. {
  273. tx = -w;
  274. }
  275. if((anchor & Anchor.ANCHOR_VCENTER) != 0)
  276. {
  277. ty = -h / 2;
  278. }
  279. else if((anchor & Anchor.ANCHOR_BOTTOM) != 0)
  280. {
  281. ty = -h;
  282. }
  283. x += tx;
  284. y += ty;
  285. }
  286. private static void transAnchor(
  287. ImageAnchor anchor,
  288. float sw, float sh, float dw, float dh,
  289. ref float x, ref float y)
  290. {
  291. float dx = 0;
  292. float dy = 0;
  293. switch(anchor)
  294. {
  295. case ImageAnchor.L_T:
  296. break;
  297. case ImageAnchor.C_T:
  298. dx = (dw - sw) / 2;
  299. break;
  300. case ImageAnchor.R_T:
  301. dx = (dw - sw);
  302. break;
  303. case ImageAnchor.L_C:
  304. dy = (dh - sh) / 2;
  305. break;
  306. case ImageAnchor.C_C:
  307. dx = (dw - sw) / 2;
  308. dy = (dh - sh) / 2;
  309. break;
  310. case ImageAnchor.R_C:
  311. dx = (dw - sw);
  312. dy = (dh - sh) / 2;
  313. break;
  314. case ImageAnchor.L_B:
  315. dy = (dh - sh);
  316. break;
  317. case ImageAnchor.C_B:
  318. dx = (dw - sw) / 2;
  319. dy = (dh - sh);
  320. break;
  321. case ImageAnchor.R_B:
  322. dx = (dw - sw);
  323. dy = (dh - sh);
  324. break;
  325. }
  326. x += dx;
  327. y += dy;
  328. }
  329. #endregion
  330. //-----------------------------------------------------------------------------------------------
  331. #region IMAGE
  332. private void FlushQuadsBath()
  333. {
  334. int count = mQuadsBatch.Count;
  335. if(count > 0)
  336. {
  337. GL.Begin(GL.QUADS);
  338. for(int i = 0; i < count; ++i)
  339. {
  340. mQuadsBatch[i].Draw();
  341. }
  342. GL.End();
  343. mQuadsBatch.Clear();
  344. }
  345. flush_translate();
  346. }
  347. private void popImage()
  348. {
  349. if(cur_uimg != null)
  350. {
  351. UnityShaders.BeginImage(cur_uimg);
  352. }
  353. }
  354. public override void beginImage(CommonUI.Display.Image image)
  355. {
  356. if (image != null)
  357. {
  358. if (image != cur_uimg)
  359. {
  360. FlushQuadsBath();
  361. if (image is IUnityImageInterface)
  362. cur_uimg = (IUnityImageInterface)image;
  363. else
  364. cur_uimg = null;
  365. }
  366. UnityShaders.BeginImage((IUnityImageInterface)image);
  367. }
  368. else
  369. {
  370. cur_uimg = null;
  371. }
  372. }
  373. public override void drawVertex(VertexBuffer vertex)
  374. {
  375. flush_translate();
  376. ((UnityVertexBuffer)vertex).Draw();
  377. }
  378. public override void drawVertex(VertexBuffer vertex, int[] indices, VertexTopology mode)
  379. {
  380. flush_translate();
  381. ((UnityVertexBuffer)vertex).DrawVertex(indices, (int)mode);
  382. }
  383. public override void drawVertexSequence(VertexBuffer vertex, VertexTopology mode)
  384. {
  385. flush_translate();
  386. ((UnityVertexBuffer)vertex).DrawSequence((int)mode);
  387. }
  388. public override void drawImageZoom(float x, float y, float w, float h)
  389. {
  390. x += tx_translate.x;
  391. y += tx_translate.y;
  392. mQuadsBatch.Add(UnityQuards2D.DrawImageZoom(cur_uimg, x, y, w, h));
  393. }
  394. public override void drawRegion(float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh)
  395. {
  396. dx += tx_translate.x;
  397. dy += tx_translate.y;
  398. mQuadsBatch.Add(UnityQuards2D.DrawImageRegion(cur_uimg, sx, sy, sw, sh, dx, dy, dw, dh, Trans.TRANS_NONE));
  399. }
  400. public override void drawRegion(float sx, float sy, float w, float h, CommonUI.Display.Trans tx, float dx, float dy)
  401. {
  402. dx += tx_translate.x;
  403. dy += tx_translate.y;
  404. mQuadsBatch.Add(UnityQuards2D.DrawImageRegion(cur_uimg, sx, sy, w, h, dx, dy, w, h, tx));
  405. }
  406. public override void drawImage(float x, float y)
  407. {
  408. x += tx_translate.x;
  409. y += tx_translate.y;
  410. mQuadsBatch.Add(UnityQuards2D.DrawImage(cur_uimg, x, y));
  411. }
  412. public override void drawImage(float x, float y, CommonUI.Display.Anchor anchor)
  413. {
  414. x += tx_translate.x;
  415. y += tx_translate.y;
  416. transAnchor(anchor, cur_uimg.Width, cur_uimg.Height, ref x, ref y);
  417. mQuadsBatch.Add(UnityQuards2D.DrawImageZoom(cur_uimg, x, y, cur_uimg.Width, cur_uimg.Height));
  418. }
  419. public override void drawImageTrans(float x, float y, CommonUI.Display.Trans trans)
  420. {
  421. x += tx_translate.x;
  422. y += tx_translate.y;
  423. mQuadsBatch.Add(UnityQuards2D.DrawImageTrans(cur_uimg, x, y, trans));
  424. }
  425. public override void drawImageEllipse(
  426. float sx, float sy,
  427. float sw, float sh,
  428. float startAngle,
  429. float endAngle)
  430. {
  431. FlushQuadsBath();
  432. int density = 32;//Math.Max(32, 32);
  433. float dlen = 1 - cur_uimg.MaxV;
  434. float rx = sw / 2;
  435. float ry = sh / 2;
  436. float cx = sx + rx;
  437. float cy = sy + ry;
  438. float div_u = 1f / cur_uimg.Width * cur_uimg.MaxU;
  439. float div_v = 1f / cur_uimg.Height * cur_uimg.MaxV;
  440. float tcx = cx * div_u;
  441. float tcy = cy * div_v;
  442. float degree_start = CMath.DegreesToRadians(-startAngle + 90);
  443. float degree_end = CMath.DegreesToRadians(-endAngle + 90);
  444. float degree_delta = (degree_end - degree_start) / density;
  445. pushTransform();
  446. translate(0, sh);
  447. scale(1, -1);
  448. GL.Begin(GL.TRIANGLE_STRIP);
  449. GL.TexCoord2(tcx, tcy);
  450. GL.Vertex3(cx, cx, 0);
  451. for(int i = density; i >= 0; --i)
  452. {
  453. float idegree = degree_start + i * degree_delta;
  454. float ox = cx + Mathf.Cos(idegree) * rx;
  455. float oy = cy + Mathf.Sin(idegree) * ry;
  456. float tdx = ox * div_u;
  457. float tdy = oy * div_v;
  458. GL.TexCoord2(tdx, tdy + dlen);
  459. GL.Vertex3(ox, oy, 0);
  460. GL.TexCoord2(tcx, tcy + dlen);
  461. GL.Vertex3(cx, cy, 0);
  462. }
  463. GL.End();
  464. popTransform();
  465. }
  466. #region WRAPPER
  467. public override void drawImageZoom(CommonUI.Display.Image image, float x, float y, float w, float h)
  468. {
  469. beginImage(image);
  470. drawImageZoom(x, y, w, h);
  471. }
  472. public override void drawImage(CommonUI.Display.Image image, float x, float y)
  473. {
  474. beginImage(image);
  475. drawImage(x, y);
  476. }
  477. public override void drawImage(CommonUI.Display.Image image, float x, float y, CommonUI.Display.Anchor anchor)
  478. {
  479. beginImage(image);
  480. drawImage(x, y, anchor);
  481. }
  482. public override void drawImageTrans(CommonUI.Display.Image image, float x, float y, CommonUI.Display.Trans trans)
  483. {
  484. beginImage(image);
  485. drawImageTrans(x, y, trans);
  486. }
  487. public override void drawRegion(CommonUI.Display.Image src, float sx, float sy, float w, float h, CommonUI.Display.Trans tx, float dx, float dy)
  488. {
  489. beginImage(src);
  490. drawRegion(sx, sy, w, h, tx, dx, dy);
  491. }
  492. public override void drawRegion(CommonUI.Display.Image src, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh)
  493. {
  494. beginImage(src);
  495. drawRegion(sx, sy, sw, sh, dx, dy, dw, dh);
  496. }
  497. #endregion
  498. #endregion
  499. #region TextLayer
  500. private UnityTextLayer beginTextLayer(CommonUI.Display.TextLayer text)
  501. {
  502. if (text != null)
  503. {
  504. UnityTextLayer cur_txt = (UnityTextLayer)text;
  505. cur_txt.Refresh();
  506. if (cur_txt.mTexture != null)
  507. {
  508. FlushQuadsBath();
  509. UnityShaders.BeginText(cur_txt);
  510. return cur_txt;
  511. }
  512. }
  513. return null;
  514. }
  515. private void drawTextQuad(float x1, float y1, UnityTextLayer text)
  516. {
  517. if(text.mTexture == null)
  518. {
  519. return;
  520. }
  521. float x2 = x1 + text.Width;
  522. float y2 = y1 + text.Height;
  523. float u = text.Width / (float)text.mTexture.width;
  524. float v = text.Height / (float)text.mTexture.height;
  525. GL.Begin(GL.QUADS);
  526. GL.TexCoord2(0, v);
  527. GL.Vertex3(x1, y1, 0);
  528. GL.TexCoord2(0, 0);
  529. GL.Vertex3(x1, y2, 0);
  530. GL.TexCoord2(u, 0);
  531. GL.Vertex3(x2, y2, 0);
  532. GL.TexCoord2(u, v);
  533. GL.Vertex3(x2, y1, 0);
  534. GL.End();
  535. }
  536. public override void drawTextLayer(CommonUI.Display.TextLayer text, float x, float y, CommonUI.Display.Anchor anchor)
  537. {
  538. UnityTextLayer cur_txt = beginTextLayer(text);
  539. if(cur_txt != null)
  540. {
  541. transAnchor(anchor, text.Width, text.Height, ref x, ref y);
  542. drawTextQuad(x, y, cur_txt);
  543. popImage();
  544. }
  545. }
  546. public override void drawTextLayer(CommonUI.Display.TextLayer text, float x, float y, float w, float h, CommonUI.Display.ImageAnchor anchor)
  547. {
  548. UnityTextLayer cur_txt = beginTextLayer(text);
  549. if(cur_txt != null)
  550. {
  551. transAnchor(anchor, text.Width, text.Height, w, h, ref x, ref y);
  552. drawTextQuad(x, y, cur_txt);
  553. popImage();
  554. }
  555. }
  556. #endregion
  557. //-----------------------------------------------------------------------------------------------
  558. #region SHAPE
  559. public override void drawLine(float x1, float y1, float x2, float y2)
  560. {
  561. FlushQuadsBath();
  562. UnityShaders.BeginShape();
  563. GL.Begin(GL.LINES);
  564. GL.Vertex3(x1, y1, 0);
  565. GL.Vertex3(x2, y2, 0);
  566. GL.End();
  567. popImage();
  568. }
  569. public override void fillRect4Color(float x, float y, float w, float h, uint[] rgba)
  570. {
  571. FlushQuadsBath();
  572. UnityShaders.BeginShape();
  573. UnityEngine.Color color = new UnityEngine.Color();
  574. GL.Begin(GL.QUADS);
  575. CommonUI.Display.Color.toRGBAF(rgba[0], out color.r, out color.g, out color.b, out color.a);
  576. GL.Color(color);
  577. GL.Vertex3(x, y, 0);
  578. CommonUI.Display.Color.toRGBAF(rgba[1], out color.r, out color.g, out color.b, out color.a);
  579. GL.Color(color);
  580. GL.Vertex3(x, y + h, 0);
  581. CommonUI.Display.Color.toRGBAF(rgba[2], out color.r, out color.g, out color.b, out color.a);
  582. GL.Color(color);
  583. GL.Vertex3(x + w, y + h, 0);
  584. CommonUI.Display.Color.toRGBAF(rgba[3], out color.r, out color.g, out color.b, out color.a);
  585. GL.Color(color);
  586. GL.Vertex3(x + w, y, 0);
  587. GL.End();
  588. popImage();
  589. }
  590. public override void drawRect(float x, float y, float w, float h)
  591. {
  592. FlushQuadsBath();
  593. UnityShaders.BeginShape();
  594. float x2 = x + w;
  595. float y2 = y + h;
  596. GL.Begin(GL.LINES);
  597. GL.Vertex3(x, y, 0);
  598. GL.Vertex3(x2, y, 0);
  599. GL.Vertex3(x2, y, 0);
  600. GL.Vertex3(x2, y2, 0);
  601. GL.Vertex3(x2, y2, 0);
  602. GL.Vertex3(x, y2, 0);
  603. GL.Vertex3(x, y2, 0);
  604. GL.Vertex3(x, y, 0);
  605. GL.End();
  606. popImage();
  607. }
  608. public override void fillRect(float x, float y, float w, float h)
  609. {
  610. FlushQuadsBath();
  611. UnityShaders.BeginShape();
  612. GL.Begin(GL.QUADS);
  613. GL.Color(mUnityColor);
  614. GL.Vertex3(x, y, 0);
  615. GL.Color(mUnityColor);
  616. GL.Vertex3(x, y + h, 0);
  617. GL.Color(mUnityColor);
  618. GL.Vertex3(x + w, y + h, 0);
  619. GL.Color(mUnityColor);
  620. GL.Vertex3(x + w, y, 0);
  621. GL.End();
  622. popImage();
  623. }
  624. public override void fillRoundRect(float x, float y, float w, float h, float rx, float ry)
  625. {
  626. FlushQuadsBath();
  627. UnityShaders.BeginShape();
  628. GL.Begin(GL.QUADS);
  629. GL.Vertex3(x, y, 0);
  630. GL.Vertex3(x, y + h, 0);
  631. GL.Vertex3(x + w, y + h, 0);
  632. GL.Vertex3(x + w, y, 0);
  633. GL.End();
  634. popImage();
  635. }
  636. public override void drawRoundRect(float x, float y, float w, float h, float rx, float ry)
  637. {
  638. FlushQuadsBath();
  639. UnityShaders.BeginShape();
  640. GL.Begin(GL.LINES);
  641. GL.Vertex3(x, y, 0);
  642. GL.Vertex3(x, y + h, 0);
  643. GL.Vertex3(x + w, y + h, 0);
  644. GL.Vertex3(x + w, y, 0);
  645. GL.End();
  646. popImage();
  647. }
  648. public override void fillArc(float x, float y, float w, float h, float startAngle, float arcAngle)
  649. {
  650. FlushQuadsBath();
  651. UnityShaders.BeginShape();
  652. int point_count = 32;
  653. float sw = w / 2;
  654. float sh = h / 2;
  655. float sx = x + sw;
  656. float sy = y + sh;
  657. float degree_start = CMath.DegreesToRadians(startAngle);
  658. float degree_delta = Mathf.PI * 2 / point_count;
  659. point_count++;
  660. GL.Begin(GL.TRIANGLE_STRIP);
  661. for(int i = 0; i < point_count; i++)
  662. {
  663. float idegree = degree_start + i * degree_delta;
  664. GL.Vertex3(sx + Mathf.Cos(idegree) * sw, sy + Mathf.Sin(idegree) * sh, 0);
  665. GL.Vertex3(sx, sy, 0);
  666. }
  667. GL.End();
  668. popImage();
  669. }
  670. public override void drawArc(float x, float y, float w, float h, float startAngle, float arcAngle)
  671. {
  672. FlushQuadsBath();
  673. UnityShaders.BeginShape();
  674. int point_count = 32;
  675. float sw = w / 2;
  676. float sh = h / 2;
  677. float sx = x + sw;
  678. float sy = y + sh;
  679. float degree_start = CMath.DegreesToRadians(startAngle);
  680. float degree_delta = Mathf.PI * 2 / point_count;
  681. point_count++;
  682. GL.Begin(GL.LINES);
  683. for(int i = 0; i < point_count; i++)
  684. {
  685. float idegree = degree_start + i * degree_delta;
  686. GL.Vertex3(sx + Mathf.Cos(idegree) * sw, sy + Mathf.Sin(idegree) * sh, 0);
  687. GL.Vertex3(sx, sy, 0);
  688. }
  689. GL.End();
  690. popImage();
  691. }
  692. #endregion
  693. //-----------------------------------------------------------------------------------------------
  694. private struct GraphicsStatus
  695. {
  696. public Rect clip;
  697. public Matrix4x4 mat;
  698. }
  699. }
  700. }