2 // System.Drawing.Drawing2D.GraphicsPath.cs
\r
6 // Miguel de Icaza (miguel@ximian.com)
\r
7 // Duncan Mak (duncan@ximian.com)
\r
8 // Jordi Mas i Hernandez (jordi@ximian.com)
\r
10 // (C) 2004 Novell, Inc
\r
14 using System.Drawing;
\r
15 using System.Runtime.InteropServices;
\r
17 namespace System.Drawing.Drawing2D
\r
19 public sealed class GraphicsPath : MarshalByRefObject, ICloneable, IDisposable {
\r
21 internal IntPtr nativePath = IntPtr.Zero;
\r
23 GraphicsPath (IntPtr ptr)
\r
28 public GraphicsPath ()
\r
30 Status status = GDIPlus.GdipCreatePath (FillMode.Alternate, out nativePath);
\r
31 GDIPlus.CheckStatus (status);
\r
34 public GraphicsPath (FillMode fillMode)
\r
36 Status status = GDIPlus.GdipCreatePath (fillMode, out nativePath);
\r
37 GDIPlus.CheckStatus (status);
\r
40 public GraphicsPath (Point[] pts, byte[] types)
\r
42 Status status = GDIPlus.GdipCreatePath2I (
\r
43 pts, types, pts.Length, FillMode.Alternate, out nativePath);
\r
44 GDIPlus.CheckStatus (status);
\r
47 public GraphicsPath (PointF[] pts, byte[] types)
\r
49 Status status = GDIPlus.GdipCreatePath2 (pts, types, pts.Length, FillMode.Alternate, out nativePath);
\r
50 GDIPlus.CheckStatus (status);
\r
53 public GraphicsPath (Point[] pts, byte[] types, FillMode fillMode)
\r
55 Status status = GDIPlus.GdipCreatePath2I (
\r
56 pts, types, pts.Length, fillMode, out nativePath);
\r
57 GDIPlus.CheckStatus (status);
\r
60 public GraphicsPath (PointF[] pts, byte[] types, FillMode fillMode)
\r
62 Status status = GDIPlus.GdipCreatePath2 (pts, types, pts.Length, fillMode, out nativePath);
\r
63 GDIPlus.CheckStatus (status);
\r
66 public object Clone ()
\r
70 Status status = GDIPlus.GdipClonePath (nativePath, out clone);
\r
71 GDIPlus.CheckStatus (status);
\r
73 return new GraphicsPath (clone);
\r
76 public void Dispose ()
\r
79 System.GC.SuppressFinalize (this);
\r
87 void Dispose (bool disposing)
\r
93 public FillMode FillMode {
\r
97 Status status = GDIPlus.GdipGetPathFillMode (nativePath, out mode);
\r
98 GDIPlus.CheckStatus (status);
\r
104 Status status = GDIPlus.GdipSetPathFillMode (nativePath, value);
\r
105 GDIPlus.CheckStatus (status);
\r
109 public PathData PathData {
\r
113 Status status = GDIPlus.GdipGetPathData (nativePath, out tmp);
\r
114 GDIPlus.CheckStatus (status);
\r
116 throw new Exception ();
\r
120 public PointF [] PathPoints {
\r
125 Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
\r
126 GDIPlus.CheckStatus (status);
\r
128 PointF [] points = new PointF [count];
\r
130 status = GDIPlus.GdipGetPathPoints (nativePath, points, count);
\r
131 GDIPlus.CheckStatus (status);
\r
137 public byte [] PathTypes {
\r
141 Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
\r
142 GDIPlus.CheckStatus (status);
\r
144 byte [] types = new byte [count];
\r
145 status = GDIPlus.GdipGetPathTypes (nativePath, types, count);
\r
146 GDIPlus.CheckStatus (status);
\r
152 public int PointCount {
\r
157 Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
\r
158 GDIPlus.CheckStatus (status);
\r
164 internal IntPtr NativeObject{
\r
170 nativePath = value;
\r
177 public void AddArc (Rectangle rect, float start_angle, float sweep_angle)
\r
179 Status status = GDIPlus.GdipAddPathArcI (nativePath, rect.X, rect.Y, rect.Width, rect.Height, start_angle, sweep_angle);
\r
180 GDIPlus.CheckStatus (status);
\r
183 public void AddArc (RectangleF rect, float start_angle, float sweep_angle)
\r
185 Status status = GDIPlus.GdipAddPathArc (nativePath, rect.X, rect.Y, rect.Width, rect.Height, start_angle, sweep_angle);
\r
186 GDIPlus.CheckStatus (status);
\r
189 public void AddArc (int x, int y, int width, int height, float start_angle, float sweep_angle)
\r
191 Status status = GDIPlus.GdipAddPathArcI (nativePath, x, y, width, height, start_angle, sweep_angle);
\r
192 GDIPlus.CheckStatus (status);
\r
195 public void AddArc (float x, float y, float width, float height, float start_angle, float sweep_angle)
\r
197 Status status = GDIPlus.GdipAddPathArc (nativePath, x, y, width, height, start_angle, sweep_angle);
\r
198 GDIPlus.CheckStatus (status);
\r
204 public void AddBezier (Point pt1, Point pt2, Point pt3, Point pt4)
\r
206 Status status = GDIPlus.GdipAddPathBezierI (nativePath, pt1.X, pt1.Y,
\r
207 pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
\r
209 GDIPlus.CheckStatus (status);
\r
212 public void AddBezier (PointF pt1, PointF pt2, PointF pt3, PointF pt4)
\r
214 Status status = GDIPlus.GdipAddPathBezier (nativePath, pt1.X, pt1.Y,
\r
215 pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
\r
217 GDIPlus.CheckStatus (status);
\r
220 public void AddBezier (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
\r
222 Status status = GDIPlus.GdipAddPathBezierI (nativePath, x1, y1, x2, y2, x3, y3, x4, y4);
\r
223 GDIPlus.CheckStatus (status);
\r
226 public void AddBezier (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
\r
228 Status status = GDIPlus.GdipAddPathBezier (nativePath, x1, y1, x2, y2, x3, y3, x4, y4);
\r
229 GDIPlus.CheckStatus (status);
\r
235 public void AddBeziers (Point [] pts)
\r
237 Status status = GDIPlus.GdipAddPathBeziersI (nativePath, pts, pts.Length);
\r
238 GDIPlus.CheckStatus (status);
\r
241 public void AddBeziers (PointF [] pts)
\r
243 Status status = GDIPlus.GdipAddPathBeziers (nativePath, pts, pts.Length);
\r
244 GDIPlus.CheckStatus (status);
\r
250 public void AddEllipse (RectangleF r)
\r
252 Status status = GDIPlus.GdipAddPathEllipse (nativePath, r.X, r.Y, r.Width, r.Height);
\r
253 GDIPlus.CheckStatus (status);
\r
256 public void AddEllipse (float x, float y, float width, float height)
\r
258 Status status = GDIPlus.GdipAddPathEllipse (nativePath, x, y, width, height);
\r
259 GDIPlus.CheckStatus (status);
\r
262 public void AddEllipse (Rectangle r)
\r
264 Status status = GDIPlus.GdipAddPathEllipseI (nativePath, r.X, r.Y, r.Width, r.Height);
\r
265 GDIPlus.CheckStatus (status);
\r
268 public void AddEllipse (int x, int y, int width, int height)
\r
270 Status status = GDIPlus.GdipAddPathEllipseI (nativePath, x, y, width, height);
\r
271 GDIPlus.CheckStatus (status);
\r
278 public void AddLine (Point a, Point b)
\r
280 Status status = GDIPlus.GdipAddPathLineI (nativePath, a.X, a.Y, b.X, b.Y);
\r
281 GDIPlus.CheckStatus (status);
\r
284 public void AddLine (PointF a, PointF b)
\r
286 Status status = GDIPlus.GdipAddPathLine (nativePath, a.X, a.Y, b.X,
\r
289 GDIPlus.CheckStatus (status);
\r
292 public void AddLine (int x1, int y1, int x2, int y2)
\r
294 Status status = GDIPlus.GdipAddPathLineI (nativePath, x1, y1, x2, y2);
\r
295 GDIPlus.CheckStatus (status);
\r
298 public void AddLine (float x1, float y1, float x2, float y2)
\r
300 Status status = GDIPlus.GdipAddPathLine (nativePath, x1, y1, x2,
\r
303 GDIPlus.CheckStatus (status);
\r
309 public void AddLines (Point [] points)
\r
311 int length = points.Length;
\r
313 for (int i = 0; i < length - 2; i += 2) {
\r
315 Status status = GDIPlus.GdipAddPathLineI (
\r
316 nativePath, points [i].X, points [i].Y, points [j].X, points [j].Y);
\r
317 GDIPlus.CheckStatus (status);
\r
321 public void AddLines (PointF [] points)
\r
323 int length = points.Length;
\r
325 for (int i = 0; i < length - 2; i += 2) {
\r
327 Status status = GDIPlus.GdipAddPathLine (
\r
328 nativePath, points [i].X, points [i].Y, points [j].X, points [j].Y);
\r
329 GDIPlus.CheckStatus (status);
\r
336 public void AddPie (Rectangle rect, float startAngle, float sweepAngle)
\r
338 Status status = GDIPlus.GdipAddPathPie (
\r
339 nativePath, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
\r
340 GDIPlus.CheckStatus (status);
\r
343 public void AddPie (int x, int y, int width, int height, float startAngle, float sweepAngle)
\r
345 Status status = GDIPlus.GdipAddPathPieI (nativePath, x, y, width, height, startAngle, sweepAngle);
\r
346 GDIPlus.CheckStatus (status);
\r
349 public void AddPie (float x, float y, float width, float height, float startAngle, float sweepAngle)
\r
351 Status status = GDIPlus.GdipAddPathPie (nativePath, x, y, width, height, startAngle, sweepAngle);
\r
352 GDIPlus.CheckStatus (status);
\r
358 public void AddPolygon (Point [] points)
\r
360 Status status = GDIPlus.GdipAddPathPolygonI (nativePath, points, points.Length);
\r
361 GDIPlus.CheckStatus (status);
\r
364 public void AddPolygon (PointF [] points)
\r
366 Status status = GDIPlus.GdipAddPathPolygon (nativePath, points, points.Length);
\r
367 GDIPlus.CheckStatus (status);
\r
373 public void AddRectangle (Rectangle rect)
\r
375 Status status = GDIPlus.GdipAddPathRectangleI (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
\r
376 GDIPlus.CheckStatus (status);
\r
379 public void AddRectangle (RectangleF rect)
\r
381 Status status = GDIPlus.GdipAddPathRectangle (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
\r
382 GDIPlus.CheckStatus (status);
\r
388 public void AddRectangles (Rectangle [] rects)
\r
390 Status status = GDIPlus.GdipAddPathRectanglesI (nativePath, rects, rects.Length);
\r
391 GDIPlus.CheckStatus (status);
\r
394 public void AddRectangles (RectangleF [] rects)
\r
396 Status status = GDIPlus.GdipAddPathRectangles (nativePath, rects, rects.Length);
\r
397 GDIPlus.CheckStatus (status);
\r
403 public void AddPath (GraphicsPath addingPath, bool connect)
\r
405 Status status = GDIPlus.GdipAddPathPath (nativePath, addingPath.nativePath, connect);
\r
406 GDIPlus.CheckStatus (status);
\r
409 public PointF GetLastPoint ()
\r
412 Status status = GDIPlus.GdipGetPathLastPoint (nativePath, out pt);
\r
413 GDIPlus.CheckStatus (status);
\r
421 public void AddClosedCurve (Point [] points)
\r
423 Status status = GDIPlus.GdipAddPathClosedCurveI (nativePath, points, points.Length);
\r
424 GDIPlus.CheckStatus (status);
\r
427 public void AddClosedCurve (PointF [] points)
\r
429 Status status = GDIPlus.GdipAddPathClosedCurve (nativePath, points, points.Length);
\r
430 GDIPlus.CheckStatus (status);
\r
433 public void AddClosedCurve (Point [] points, float tension)
\r
435 Status status = GDIPlus.GdipAddPathClosedCurve2I (nativePath, points, points.Length, tension);
\r
436 GDIPlus.CheckStatus (status);
\r
439 public void AddClosedCurve (PointF [] points, float tension)
\r
441 Status status = GDIPlus.GdipAddPathClosedCurve2 (nativePath, points, points.Length, tension);
\r
442 GDIPlus.CheckStatus (status);
\r
448 public void AddCurve (Point [] points)
\r
450 Status status = GDIPlus.GdipAddPathCurveI (nativePath, points, points.Length);
\r
451 GDIPlus.CheckStatus (status);
\r
454 public void AddCurve (PointF [] points)
\r
456 Status status = GDIPlus.GdipAddPathCurve (nativePath, points, points.Length);
\r
457 GDIPlus.CheckStatus (status);
\r
460 public void AddCurve (Point [] points, float tension)
\r
462 Status status = GDIPlus.GdipAddPathCurve2I (nativePath, points, points.Length, tension);
\r
463 GDIPlus.CheckStatus (status);
\r
466 public void AddCurve (PointF [] points, float tension)
\r
468 Status status = GDIPlus.GdipAddPathCurve2 (nativePath, points, points.Length, tension);
\r
469 GDIPlus.CheckStatus (status);
\r
472 public void AddCurve (Point [] points, int offset, int numberOfSegments, float tension)
\r
474 Status status = GDIPlus.GdipAddPathCurve3I (nativePath, points, points.Length,
\r
475 offset, numberOfSegments, tension);
\r
477 GDIPlus.CheckStatus (status);
\r
480 public void AddCurve (PointF [] points, int offset, int numberOfSegments, float tension)
\r
482 Status status = GDIPlus.GdipAddPathCurve3 (nativePath, points, points.Length,
\r
483 offset, numberOfSegments, tension);
\r
485 GDIPlus.CheckStatus (status);
\r
488 public void Reset ()
\r
490 Status status = GDIPlus.GdipResetPath (nativePath);
\r
491 GDIPlus.CheckStatus (status);
\r
494 public void Reverse ()
\r
496 Status status = GDIPlus.GdipReversePath (nativePath);
\r
497 GDIPlus.CheckStatus (status);
\r
500 public void Transform (Matrix matrix)
\r
502 Status status = GDIPlus.GdipTransformPath (nativePath, matrix.nativeMatrix);
\r
503 GDIPlus.CheckStatus (status);
\r
507 public void AddString (string s, FontFamily family, int style, float emSize, Point origin, StringFormat format)
\r
509 throw new NotImplementedException ();
\r
513 public void AddString (string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
\r
515 throw new NotImplementedException ();
\r
519 public void AddString (string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
\r
521 throw new NotImplementedException ();
\r
525 public void AddString (string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format)
\r
527 throw new NotImplementedException ();
\r
530 public void ClearMarkers()
\r
532 Status s = GDIPlus.GdipClearPathMarkers (nativePath);
\r
534 GDIPlus.CheckStatus (s);
\r
537 public void CloseAllFigures()
\r
539 Status s = GDIPlus.GdipClosePathFigures (nativePath);
\r
541 GDIPlus.CheckStatus (s);
\r
544 public void CloseFigure()
\r
546 Status s = GDIPlus.GdipClosePathFigure (nativePath);
\r
548 GDIPlus.CheckStatus (s);
\r
551 public void Flatten ()
\r
553 // 1/4 is the FlatnessDefault as defined in GdiPlusEnums.h
\r
554 Flatten (null, 1.0f / 4.0f);
\r
557 public void Flatten (Matrix matrix)
\r
559 Flatten (matrix, 1.0f / 4.0f);
\r
562 public void Flatten (Matrix matrix, float flatness)
\r
564 Status status = GDIPlus.GdipFlattenPath (nativePath, matrix.nativeMatrix, flatness);
\r
566 GDIPlus.CheckStatus (status);
\r
569 public RectangleF GetBounds ()
\r
571 return GetBounds (null, null);
\r
574 public RectangleF GetBounds (Matrix matrix)
\r
576 return GetBounds (matrix, null);
\r
580 public RectangleF GetBounds (Matrix matrix, Pen pen)
\r
583 IntPtr m = (matrix == null) ? (IntPtr) null : matrix.nativeMatrix;
\r
584 IntPtr p = (pen == null) ? (IntPtr) null : pen.nativeObject;
\r
586 Status s = GDIPlus.GdipGetPathWorldBounds (nativePath, out retval, m, p);
\r
588 GDIPlus.CheckStatus (s);
\r
593 public bool IsOutlineVisible (Point point, Pen pen)
\r
595 return IsOutlineVisible (point.X, point.Y, pen, null);
\r
598 public bool IsOutlineVisible (PointF point, Pen pen)
\r
600 return IsOutlineVisible (point.X, point.Y, pen, null);
\r
603 public bool IsOutlineVisible (int x, int y, Pen pen)
\r
605 return IsOutlineVisible (x, y, pen, null);
\r
608 public bool IsOutlineVisible (float x, float y, Pen pen)
\r
610 return IsOutlineVisible (x, y, pen, null);
\r
613 public bool IsOutlineVisible (Point pt, Pen pen, Graphics graphics)
\r
615 return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
\r
618 public bool IsOutlineVisible (PointF pt, Pen pen, Graphics graphics)
\r
620 return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
\r
624 public bool IsOutlineVisible (int x, int y, Pen pen, Graphics graphics)
\r
627 IntPtr g = (graphics == null) ? (IntPtr) null : graphics.nativeObject;
\r
629 Status s = GDIPlus.GdipIsOutlineVisiblePathPointI (nativePath, x, y, g, out result);
\r
630 GDIPlus.CheckStatus (s);
\r
636 public bool IsOutlineVisible (float x, float y, Pen pen, Graphics graphics)
\r
639 IntPtr g = (graphics == null) ? (IntPtr) null : graphics.nativeObject;
\r
641 Status s = GDIPlus.GdipIsOutlineVisiblePathPoint (nativePath, x, y, g, out result);
\r
642 GDIPlus.CheckStatus (s);
\r
647 public bool IsVisible (Point point)
\r
649 return IsVisible (point.X, point.Y, null);
\r
652 public bool IsVisible (PointF point)
\r
654 return IsVisible (point.X, point.Y, null);
\r
657 public bool IsVisible (int x, int y)
\r
659 return IsVisible (x, y, null);
\r
662 public bool IsVisible (float x, float y)
\r
664 return IsVisible (x, y, null);
\r
667 public bool IsVisible (Point pt, Graphics graphics)
\r
669 return IsVisible (pt.X, pt.Y, graphics);
\r
672 public bool IsVisible (PointF pt, Graphics graphics)
\r
674 return IsVisible (pt.X, pt.Y, graphics);
\r
678 public bool IsVisible (int x, int y, Graphics graphics)
\r
682 IntPtr g = (graphics == null) ? (IntPtr) null : graphics.nativeObject;
\r
684 Status s = GDIPlus.GdipIsVisiblePathPointI (nativePath, x, y, g, out retval);
\r
686 GDIPlus.CheckStatus (s);
\r
692 public bool IsVisible (float x, float y, Graphics graphics)
\r
696 IntPtr g = (graphics == null) ? (IntPtr) null : graphics.nativeObject;
\r
698 Status s = GDIPlus.GdipIsVisiblePathPoint (nativePath, x, y, g, out retval);
\r
700 GDIPlus.CheckStatus (s);
\r
705 public void SetMarker ()
\r
707 Status s = GDIPlus.GdipSetPathMarker (nativePath);
\r
709 GDIPlus.CheckStatus (s);
\r
712 public void StartFigure()
\r
714 Status s = GDIPlus.GdipStartPathFigure (nativePath);
\r
716 GDIPlus.CheckStatus (s);
\r
719 public void Warp (PointF[] destPoints, RectangleF srcRect)
\r
721 Warp (destPoints, srcRect, null, WarpMode.Perspective, 1.0f / 4.0f);
\r
724 public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix)
\r
726 Warp (destPoints, srcRect, matrix, WarpMode.Perspective, 1.0f / 4.0f);
\r
729 public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode)
\r
731 Warp (destPoints, srcRect, matrix, warpMode, 1.0f / 4.0f);
\r
735 public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode, float flatness)
\r
737 IntPtr m = (matrix == null) ? (IntPtr) null : matrix.nativeMatrix;
\r
739 Status s = GDIPlus.GdipWarpPath (nativePath, m, destPoints, destPoints.Length,
\r
740 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, warpMode, flatness);
\r
742 GDIPlus.CheckStatus (s);
\r
745 public void Widen (Pen pen)
\r
747 Widen (pen, null, 1.0f / 4.0f);
\r
750 public void Widen (Pen pen, Matrix matrix)
\r
752 Widen (pen, matrix, 1.0f / 4.0f);
\r
756 public void Widen (Pen pen, Matrix matrix, float flatness)
\r
758 IntPtr p = (pen == null) ? (IntPtr) null : pen.nativeObject;
\r
759 IntPtr m = (matrix == null) ? (IntPtr) null : matrix.nativeMatrix;
\r
761 Status s = GDIPlus.GdipWidenPath (nativePath, p, m, flatness);
\r
763 GDIPlus.CheckStatus (s);
\r