Graphics.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using CommonUI.Display;
  5. using CommonUI.Gemo;
  6. namespace CommonUI.Display
  7. {
  8. public enum Blend : byte
  9. {
  10. BLEND_MODE_NORMAL = Data.Blend.BLEND_MODE_NORMAL,
  11. BLEND_MODE_SCREEN = Data.Blend.BLEND_MODE_SCREEN,
  12. BLEND_MODE_GRAY = Data.Blend.BLEND_MODE_GRAY,
  13. }
  14. public enum Anchor : byte
  15. {
  16. NONE = Data.Anchor.NONE,
  17. ANCHOR_LEFT = Data.Anchor.ANCHOR_LEFT,
  18. ANCHOR_HCENTER = Data.Anchor.ANCHOR_HCENTER,
  19. ANCHOR_RIGHT = Data.Anchor.ANCHOR_RIGHT,
  20. ANCHOR_TOP = Data.Anchor.ANCHOR_TOP,
  21. ANCHOR_VCENTER = Data.Anchor.ANCHOR_VCENTER,
  22. ANCHOR_BOTTOM = Data.Anchor.ANCHOR_BOTTOM,
  23. }
  24. public enum Trans : byte
  25. {
  26. TRANS_NONE = Data.Trans.TRANS_NONE,
  27. TRANS_ROT90 = Data.Trans.TRANS_ROT90,
  28. TRANS_ROT180 = Data.Trans.TRANS_ROT180,
  29. TRANS_ROT270 = Data.Trans.TRANS_ROT270,
  30. TRANS_MIRROR = Data.Trans.TRANS_MIRROR,
  31. TRANS_MIRROR_ROT90 = Data.Trans.TRANS_MIRROR_ROT90,
  32. TRANS_MIRROR_ROT180 = Data.Trans.TRANS_MIRROR_ROT180,
  33. TRANS_MIRROR_ROT270 = Data.Trans.TRANS_MIRROR_ROT270,
  34. }
  35. public enum ImageAnchor : byte
  36. {
  37. L_T = Data.ImageAnchor.L_T,
  38. C_T = Data.ImageAnchor.C_T,
  39. R_T = Data.ImageAnchor.R_T,
  40. L_C = Data.ImageAnchor.L_C,
  41. C_C = Data.ImageAnchor.C_C,
  42. R_C = Data.ImageAnchor.R_C,
  43. L_B = Data.ImageAnchor.L_B,
  44. C_B = Data.ImageAnchor.C_B,
  45. R_B = Data.ImageAnchor.R_B,
  46. }
  47. public enum ImageTrans : byte
  48. {
  49. NONE = (Trans.TRANS_NONE),
  50. R_90 = (Trans.TRANS_ROT90),
  51. R_180 = (Trans.TRANS_ROT180),
  52. R_270 = (Trans.TRANS_ROT270),
  53. MIRROR = (Trans.TRANS_MIRROR),
  54. MR_90 = (Trans.TRANS_MIRROR_ROT90),
  55. MR_180 = (Trans.TRANS_MIRROR_ROT180),
  56. MR_270 = (Trans.TRANS_MIRROR_ROT270),
  57. }
  58. // ------------------------------------------------------------------------------------------
  59. // -by zhangyifei
  60. // ------------------------------------------------------------------------------------------
  61. public abstract class Graphics : IDisposable
  62. {
  63. public const float ANGLE_90 = (float)(90);
  64. public const float ANGLE_180 = (float)(180);
  65. public const float ANGLE_270 = (float)(270);
  66. public abstract void setBlend(Blend blend);
  67. public abstract Blend getBlend();
  68. public abstract uint getColor();
  69. public abstract void setColor(uint color);
  70. public abstract void setColor(int red, int green, int blue);
  71. public abstract void setColor(int red, int green, int blue, int alpha);
  72. public abstract void setColor(float red, float green, float blue, float alpha);
  73. public abstract void setAlpha(float alpha);
  74. public abstract float getAlpha();
  75. public virtual void addAlpha(float add)
  76. {
  77. setAlpha(getAlpha() * add);
  78. }
  79. public abstract void SetClip(Rectangle2D rect);
  80. public abstract void SetClip(float x, float y, float w, float h);
  81. public abstract void PushClip();
  82. public abstract void PopClip();
  83. #region TRANSFORM
  84. public abstract void translate(float x, float y);
  85. public abstract void rotate(float angle);
  86. public abstract void scale(float sx, float sy);
  87. public abstract void pushTransform();
  88. public abstract void popTransform();
  89. #endregion
  90. #region IMAGE
  91. public abstract void beginImage(Image image);
  92. public abstract void drawVertex(VertexBuffer vertex);
  93. public abstract void drawVertex(VertexBuffer vertex, int[] indices, VertexTopology mode);
  94. public abstract void drawVertexSequence(VertexBuffer vertex, VertexTopology mode);
  95. public abstract void drawImageZoom(
  96. float x, float y, float w, float h);
  97. public abstract void drawImage(
  98. float x, float y);
  99. public abstract void drawImage(
  100. float x, float y, Anchor anchor);
  101. public abstract void drawImageTrans(
  102. float x, float y, Trans trans);
  103. public abstract void drawRegion(
  104. float sx, float sy,
  105. float w, float h,
  106. Trans tx,
  107. float dx, float dy);
  108. public abstract void drawRegion(
  109. float sx, float sy,
  110. float sw, float sh,
  111. float dx, float dy,
  112. float dw, float dh);
  113. public abstract void drawImageEllipse(
  114. float sx, float sy,
  115. float sw, float sh,
  116. float startAngle,
  117. float endAngle);
  118. public abstract void drawImageZoom(Image image,
  119. float x, float y, float w, float h);
  120. public abstract void drawImage(Image image,
  121. float x, float y);
  122. public abstract void drawImage(Image image,
  123. float x, float y, Anchor anchor);
  124. public abstract void drawImageTrans(Image image,
  125. float x, float y, Trans trans);
  126. public abstract void drawRegion(Image src,
  127. float sx, float sy,
  128. float w, float h,
  129. Trans tx,
  130. float dx, float dy);
  131. public abstract void drawRegion(Image src,
  132. float sx, float sy,
  133. float sw, float sh,
  134. float dx, float dy,
  135. float dw, float dh);
  136. #endregion
  137. #region SHAPE
  138. public abstract void drawLine(float x1, float y1, float x2, float y2);
  139. public abstract void drawRect(float x, float y, float w, float h);
  140. public abstract void fillRect(float x, float y, float w, float h);
  141. public abstract void drawRoundRect(float x, float y, float w, float h, float rx, float ry);
  142. public abstract void fillRoundRect(float x, float y, float w, float h, float rx, float ry);
  143. public abstract void drawArc(float x, float y, float w, float h, float startAngle, float arcAngle);
  144. public abstract void fillArc(float x, float y, float w, float h, float startAngle, float arcAngle);
  145. public abstract void fillRect4Color(float x, float y, float w, float h, uint[] rgba);
  146. #endregion
  147. public abstract void drawTextLayer(
  148. TextLayer text,
  149. float x, float y,
  150. Anchor anchor);
  151. public abstract void drawTextLayer(
  152. TextLayer text,
  153. float x, float y, float w, float h,
  154. ImageAnchor anchor);
  155. public abstract void Dispose();
  156. }
  157. public class NullGraphics : CommonUI.Display.Graphics
  158. {
  159. public static NullGraphics SimpleGraphics = new NullGraphics();
  160. private float m_alpha = 1f;
  161. private Blend m_blend = Blend.BLEND_MODE_NORMAL;
  162. private uint m_color = 0xffffffff;
  163. public override void Dispose() { }
  164. public override void beginImage(Image image) { }
  165. public override void drawImage(float x, float y) { }
  166. public override void drawImage(Image image, float x, float y) { }
  167. public override void drawImage(float x, float y, Anchor anchor) { }
  168. public override void drawImage(Image image, float x, float y, Anchor anchor) { }
  169. public override void drawImageEllipse(float sx, float sy, float sw, float sh, float startAngle, float endAngle) { }
  170. public override void drawImageTrans(float x, float y, Trans trans) { }
  171. public override void drawImageTrans(Image image, float x, float y, Trans trans) { }
  172. public override void drawImageZoom(float x, float y, float w, float h) { }
  173. public override void drawImageZoom(Image image, float x, float y, float w, float h) { }
  174. public override void drawArc(float x, float y, float w, float h, float startAngle, float arcAngle) { }
  175. public override void drawLine(float x1, float y1, float x2, float y2) { }
  176. public override void drawRect(float x, float y, float w, float h) { }
  177. public override void drawRegion(float sx, float sy, float w, float h, Trans tx, float dx, float dy) { }
  178. public override void drawRegion(Image src, float sx, float sy, float w, float h, Trans tx, float dx, float dy) { }
  179. public override void drawRegion(float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { }
  180. public override void drawRegion(Image src, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { }
  181. public override void drawRoundRect(float x, float y, float w, float h, float rx, float ry) { }
  182. public override void fillRect4Color(float x, float y, float w, float h, uint[] rgba) { }
  183. public override void fillRoundRect(float x, float y, float w, float h, float rx, float ry) { }
  184. public override void fillArc(float x, float y, float w, float h, float startAngle, float arcAngle) { }
  185. public override void fillRect(float x, float y, float w, float h) { }
  186. public override void drawTextLayer(TextLayer text, float x, float y, Anchor anchor) { }
  187. public override void drawTextLayer(TextLayer text, float x, float y, float w, float h, ImageAnchor anchor) { }
  188. public override void drawVertex(VertexBuffer vertex) { }
  189. public override void drawVertex(VertexBuffer vertex, int[] indices, VertexTopology mode) { }
  190. public override void drawVertexSequence(VertexBuffer vertex, VertexTopology mode) { }
  191. public override float getAlpha() { return m_alpha; }
  192. public override Blend getBlend() { return m_blend; }
  193. public override uint getColor() { return m_color; }
  194. public override void setAlpha(float alpha) { }
  195. public override void setBlend(Blend blend) { }
  196. public override void setColor(uint color) { }
  197. public override void setColor(int red, int green, int blue) { }
  198. public override void setColor(float red, float green, float blue, float alpha) { }
  199. public override void setColor(int red, int green, int blue, int alpha) { }
  200. public override void PopClip() { }
  201. public override void PushClip() { }
  202. public override void SetClip(Rectangle2D rect) { }
  203. public override void SetClip(float x, float y, float w, float h) { }
  204. public override void pushTransform() { }
  205. public override void translate(float x, float y) { }
  206. public override void rotate(float angle) { }
  207. public override void scale(float sx, float sy) { }
  208. public override void popTransform() { }
  209. }
  210. }