GraphicsPath.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. //
  2. // System.Drawing.Drawing2D.GraphicsPath.cs
  3. //
  4. // Authors:
  5. //
  6. // Miguel de Icaza ([email protected])
  7. // Duncan Mak ([email protected])
  8. //
  9. // (C) 2004 Novell, Inc
  10. //
  11. using System;
  12. using System.Drawing;
  13. using System.Runtime.InteropServices;
  14. namespace System.Drawing.Drawing2D
  15. {
  16. public sealed class GraphicsPath : MarshalByRefObject, ICloneable, IDisposable {
  17. internal IntPtr nativePath;
  18. GraphicsPath (IntPtr ptr)
  19. {
  20. nativePath = ptr;
  21. }
  22. public GraphicsPath ()
  23. {
  24. GDIPlus.GdipCreatePath (FillMode.Alternate, out nativePath);
  25. }
  26. public object Clone ()
  27. {
  28. IntPtr clone;
  29. GDIPlus.GdipClonePath (nativePath, out clone);
  30. return new GraphicsPath (clone);
  31. }
  32. public void Dispose ()
  33. {
  34. Dispose (true);
  35. System.GC.SuppressFinalize (this);
  36. }
  37. ~GraphicsPath ()
  38. {
  39. Dispose (false);
  40. }
  41. void Dispose (bool disposing)
  42. {
  43. }
  44. public FillMode FillMode {
  45. get {
  46. FillMode mode;
  47. GDIPlus.GdipGetPathFillMode (nativePath, out mode);
  48. return mode;
  49. }
  50. set {
  51. GDIPlus.GdipSetPathFillMode (nativePath, value);
  52. }
  53. }
  54. public PathData PathData {
  55. get {
  56. IntPtr tmp;
  57. GDIPlus.GdipGetPathData (nativePath, out tmp);
  58. throw new Exception ();
  59. }
  60. }
  61. public PointF [] PathPoints {
  62. get {
  63. int count;
  64. GDIPlus.GdipGetPointCount (nativePath, out count);
  65. PointF [] points = new PointF [count];
  66. GDIPlus.GdipGetPathPoints (nativePath, points, count);
  67. return points;
  68. }
  69. }
  70. public byte [] PathTypes {
  71. get {
  72. int count;
  73. GDIPlus.GdipGetPointCount (nativePath, out count);
  74. byte [] types = new byte [count];
  75. GDIPlus.GdipGetPathTypes (nativePath, types, count);
  76. return types;
  77. }
  78. }
  79. public int PointCount {
  80. get {
  81. int count;
  82. GDIPlus.GdipGetPointCount (nativePath, out count);
  83. return count;
  84. }
  85. }
  86. internal IntPtr NativeObject{
  87. get{
  88. return nativePath;
  89. }
  90. set {
  91. nativePath = value;
  92. }
  93. }
  94. //
  95. // AddArc
  96. //
  97. public void AddArc (Rectangle rect, float start_angle, float sweep_angle)
  98. {
  99. GDIPlus.GdipAddPathArcI (nativePath, rect.X, rect.Y, rect.Width, rect.Height, start_angle, sweep_angle);
  100. }
  101. public void AddArc (RectangleF rect, float start_angle, float sweep_angle)
  102. {
  103. GDIPlus.GdipAddPathArc (nativePath, rect.X, rect.Y, rect.Width, rect.Height, start_angle, sweep_angle);
  104. }
  105. public void AddArc (int x, int y, int width, int height, float start_angle, float sweep_angle)
  106. {
  107. GDIPlus.GdipAddPathArcI (nativePath, x, y, width, height, start_angle, sweep_angle);
  108. }
  109. public void AddArc (float x, float y, float width, float height, float start_angle, float sweep_angle)
  110. {
  111. GDIPlus.GdipAddPathArc (nativePath, x, y, width, height, start_angle, sweep_angle);
  112. }
  113. //
  114. // AddBezier
  115. //
  116. public void AddBezier (Point pt1, Point pt2, Point pt3, Point pt4)
  117. {
  118. GDIPlus.GdipAddPathBezierI (nativePath, pt1.X, pt1.Y,
  119. pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
  120. }
  121. public void AddBezier (PointF pt1, PointF pt2, PointF pt3, PointF pt4)
  122. {
  123. GDIPlus.GdipAddPathBezier (nativePath, pt1.X, pt1.Y,
  124. pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
  125. }
  126. public void AddBezier (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
  127. {
  128. GDIPlus.GdipAddPathBezierI (nativePath, x1, y1, x2, y2, x3, y3, x4, y4);
  129. }
  130. public void AddBezier (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
  131. {
  132. GDIPlus.GdipAddPathBezier (nativePath, x1, y1, x2, y2, x3, y3, x4, y4);
  133. }
  134. //
  135. // AddBeziers
  136. //
  137. public void AddBeziers (Point [] pts)
  138. {
  139. GDIPlus.GdipAddPathBeziersI (nativePath, pts, pts.Length);
  140. }
  141. public void AddBeziers (PointF [] pts)
  142. {
  143. GDIPlus.GdipAddPathBeziers (nativePath, pts, pts.Length);
  144. }
  145. //
  146. // AddEllipse
  147. //
  148. public void AddEllipse (RectangleF r)
  149. {
  150. GDIPlus.GdipAddPathEllipse (nativePath, r.X, r.Y, r.Width, r.Height);
  151. }
  152. public void AddEllipse (float x, float y, float width, float height)
  153. {
  154. GDIPlus.GdipAddPathEllipse (nativePath, x, y, width, height);
  155. }
  156. public void AddEllipse (Rectangle r)
  157. {
  158. GDIPlus.GdipAddPathEllipseI (nativePath, r.X, r.Y, r.Width, r.Height);
  159. }
  160. public void AddEllipse (int x, int y, int width, int height)
  161. {
  162. GDIPlus.GdipAddPathEllipseI (nativePath, x, y, width, height);
  163. }
  164. //
  165. // AddLine
  166. //
  167. public void AddLine (Point a, Point b)
  168. {
  169. GDIPlus.GdipAddPathLineI (nativePath, a.X, a.Y, b.X, b.Y);
  170. }
  171. public void AddLine (PointF a, PointF b)
  172. {
  173. GDIPlus.GdipAddPathLine (nativePath, a.X, a.Y, b.X,
  174. b.Y);
  175. }
  176. public void AddLine (int x1, int y1, int x2, int y2)
  177. {
  178. GDIPlus.GdipAddPathLineI (nativePath, x1, y1, x2, y2);
  179. }
  180. public void AddLine (float x1, float y1, float x2, float y2)
  181. {
  182. GDIPlus.GdipAddPathLine (nativePath, x1, y1, x2,
  183. y2);
  184. }
  185. //
  186. // AddLines
  187. //
  188. public void AddLines (Point [] points)
  189. {
  190. int length = points.Length;
  191. for (int i = 0; i < length - 2; i += 2) {
  192. int j = i + 1;
  193. GDIPlus.GdipAddPathLineI (nativePath, points [i].X, points [i].Y, points [j].X, points [j].Y);
  194. }
  195. }
  196. public void AddLines (PointF [] points)
  197. {
  198. int length = points.Length;
  199. for (int i = 0; i < length - 2; i += 2) {
  200. int j = i + 1;
  201. GDIPlus.GdipAddPathLine (nativePath, points [i].X, points [i].Y, points [j].X, points [j].Y);
  202. }
  203. }
  204. //
  205. // AddPie
  206. //
  207. public void AddPie (Rectangle rect, float startAngle, float sweepAngle)
  208. {
  209. GDIPlus.GdipAddPathPie (nativePath, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
  210. }
  211. public void AddPie (int x, int y, int width, int height, float startAngle, float sweepAngle)
  212. {
  213. GDIPlus.GdipAddPathPie (nativePath, x, y, width, height, startAngle, sweepAngle);
  214. }
  215. public void AddPie (float x, float y, float width, float height, float startAngle, float sweepAngle)
  216. {
  217. GDIPlus.GdipAddPathPie (nativePath, x, y, width, height, startAngle, sweepAngle);
  218. }
  219. //
  220. // AddPolygon
  221. //
  222. public void AddPolygon (Point [] points)
  223. {
  224. GDIPlus.GdipAddPathPolygonI (nativePath, points, points.Length);
  225. }
  226. public void AddPolygon (PointF [] points)
  227. {
  228. GDIPlus.GdipAddPathPolygon (nativePath, points, points.Length);
  229. }
  230. //
  231. // AddRectangle
  232. //
  233. public void AddRectangle (Rectangle rect)
  234. {
  235. GDIPlus.GdipAddPathRectangleI (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
  236. }
  237. public void AddRectangle (RectangleF rect)
  238. {
  239. GDIPlus.GdipAddPathRectangle (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
  240. }
  241. //
  242. // AddRectangles
  243. //
  244. public void AddRectangles (Rectangle [] rects)
  245. {
  246. GDIPlus.GdipAddPathRectanglesI (nativePath, rects, rects.Length);
  247. }
  248. public void AddRectangles (RectangleF [] rects)
  249. {
  250. GDIPlus.GdipAddPathRectangles (nativePath, rects, rects.Length);
  251. }
  252. //
  253. // AddPath
  254. //
  255. public void AddPath (GraphicsPath addingPath, bool connect)
  256. {
  257. GDIPlus.GdipAddPathPath (nativePath, addingPath.nativePath, connect);
  258. }
  259. public PointF GetLastPoint ()
  260. {
  261. PointF pt;
  262. GDIPlus.GdipGetPathLastPoint (nativePath, out pt);
  263. return pt;
  264. }
  265. public void Reset ()
  266. {
  267. GDIPlus.GdipResetPath (nativePath);
  268. }
  269. public void Reverse ()
  270. {
  271. GDIPlus.GdipReversePath (nativePath);
  272. }
  273. public void Transform (Matrix matrix)
  274. {
  275. GDIPlus.GdipTransformPath (nativePath, matrix.nativeMatrix);
  276. }
  277. }
  278. }