(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Drawing / System.Drawing.Drawing2D / GraphicsPath.cs
blob105f324df4a575dfda5f5891fd3ef35fa903982d
1 //
2 // System.Drawing.Drawing2D.GraphicsPath.cs
3 //
4 // Authors:
5 //
6 // Miguel de Icaza (miguel@ximian.com)
7 // Duncan Mak (duncan@ximian.com)
8 // Jordi Mas i Hernandez (jordi@ximian.com)
9 // Ravindra (rkumar@novell.com)
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System;
35 using System.Drawing;
36 using System.Runtime.InteropServices;
38 namespace System.Drawing.Drawing2D
40 public sealed class GraphicsPath : MarshalByRefObject, ICloneable, IDisposable
42 internal IntPtr nativePath = IntPtr.Zero;
44 GraphicsPath (IntPtr ptr)
46 nativePath = ptr;
49 public GraphicsPath ()
51 Status status = GDIPlus.GdipCreatePath (FillMode.Alternate, out nativePath);
52 GDIPlus.CheckStatus (status);
55 public GraphicsPath (FillMode fillMode)
57 Status status = GDIPlus.GdipCreatePath (fillMode, out nativePath);
58 GDIPlus.CheckStatus (status);
61 public GraphicsPath (Point[] pts, byte[] types)
63 Status status;
64 if (pts.Length != types.Length)
65 throw new ArgumentException ("Invalid parameter passed. Number of points and types must be same.");
67 status = GDIPlus.GdipCreatePath2I (pts, types, pts.Length, FillMode.Alternate, out nativePath);
68 GDIPlus.CheckStatus (status);
71 public GraphicsPath (PointF[] pts, byte[] types)
73 Status status;
74 if (pts.Length != types.Length)
75 throw new ArgumentException ("Invalid parameter passed. Number of points and types must be same.");
77 status = GDIPlus.GdipCreatePath2 (pts, types, pts.Length, FillMode.Alternate, out nativePath);
78 GDIPlus.CheckStatus (status);
81 public GraphicsPath (Point[] pts, byte[] types, FillMode fillMode)
83 Status status;
84 if (pts.Length != types.Length)
85 throw new ArgumentException ("Invalid parameter passed. Number of points and types must be same.");
87 status = GDIPlus.GdipCreatePath2I (pts, types, pts.Length, fillMode, out nativePath);
88 GDIPlus.CheckStatus (status);
91 public GraphicsPath (PointF[] pts, byte[] types, FillMode fillMode)
93 Status status;
94 if (pts.Length != types.Length)
95 throw new ArgumentException ("Invalid parameter passed. Number of points and types must be same.");
97 status = GDIPlus.GdipCreatePath2 (pts, types, pts.Length, fillMode, out nativePath);
98 GDIPlus.CheckStatus (status);
101 public object Clone ()
103 IntPtr clone;
105 Status status = GDIPlus.GdipClonePath (nativePath, out clone);
106 GDIPlus.CheckStatus (status);
108 return new GraphicsPath (clone);
111 public void Dispose ()
113 Dispose (true);
114 System.GC.SuppressFinalize (this);
117 ~GraphicsPath ()
119 Dispose (false);
122 void Dispose (bool disposing)
124 Status status;
125 if (nativePath != IntPtr.Zero) {
126 status = GDIPlus.GdipDeletePath (nativePath);
127 GDIPlus.CheckStatus (status);
129 nativePath = IntPtr.Zero;
133 public FillMode FillMode {
134 get {
135 FillMode mode;
136 Status status = GDIPlus.GdipGetPathFillMode (nativePath, out mode);
137 GDIPlus.CheckStatus (status);
139 return mode;
141 set {
142 Status status = GDIPlus.GdipSetPathFillMode (nativePath, value);
143 GDIPlus.CheckStatus (status);
147 public PathData PathData {
148 get {
149 PathData pdata = new PathData ();
150 pdata.Points = PathPoints;
151 pdata.Types = PathTypes;
152 return pdata;
156 public PointF [] PathPoints {
157 get {
158 int count;
159 Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
160 GDIPlus.CheckStatus (status);
162 PointF [] points = new PointF [count];
163 status = GDIPlus.GdipGetPathPoints (nativePath, points, count);
164 GDIPlus.CheckStatus (status);
166 return points;
170 public byte [] PathTypes {
171 get {
172 int count;
173 Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
174 GDIPlus.CheckStatus (status);
176 byte [] types = new byte [count];
177 status = GDIPlus.GdipGetPathTypes (nativePath, types, count);
178 GDIPlus.CheckStatus (status);
180 return types;
184 public int PointCount {
185 get {
186 int count;
187 Status status = GDIPlus.GdipGetPointCount (nativePath, out count);
188 GDIPlus.CheckStatus (status);
190 return count;
194 internal IntPtr NativeObject {
195 get {
196 return nativePath;
198 set {
199 nativePath = value;
204 // AddArc
206 public void AddArc (Rectangle rect, float start_angle, float sweep_angle)
208 Status status = GDIPlus.GdipAddPathArcI (nativePath, rect.X, rect.Y, rect.Width, rect.Height, start_angle, sweep_angle);
209 GDIPlus.CheckStatus (status);
212 public void AddArc (RectangleF rect, float start_angle, float sweep_angle)
214 Status status = GDIPlus.GdipAddPathArc (nativePath, rect.X, rect.Y, rect.Width, rect.Height, start_angle, sweep_angle);
215 GDIPlus.CheckStatus (status);
218 public void AddArc (int x, int y, int width, int height, float start_angle, float sweep_angle)
220 Status status = GDIPlus.GdipAddPathArcI (nativePath, x, y, width, height, start_angle, sweep_angle);
221 GDIPlus.CheckStatus (status);
224 public void AddArc (float x, float y, float width, float height, float start_angle, float sweep_angle)
226 Status status = GDIPlus.GdipAddPathArc (nativePath, x, y, width, height, start_angle, sweep_angle);
227 GDIPlus.CheckStatus (status);
231 // AddBezier
233 public void AddBezier (Point pt1, Point pt2, Point pt3, Point pt4)
235 Status status = GDIPlus.GdipAddPathBezierI (nativePath, pt1.X, pt1.Y,
236 pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
238 GDIPlus.CheckStatus (status);
241 public void AddBezier (PointF pt1, PointF pt2, PointF pt3, PointF pt4)
243 Status status = GDIPlus.GdipAddPathBezier (nativePath, pt1.X, pt1.Y,
244 pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
246 GDIPlus.CheckStatus (status);
249 public void AddBezier (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
251 Status status = GDIPlus.GdipAddPathBezierI (nativePath, x1, y1, x2, y2, x3, y3, x4, y4);
252 GDIPlus.CheckStatus (status);
255 public void AddBezier (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
257 Status status = GDIPlus.GdipAddPathBezier (nativePath, x1, y1, x2, y2, x3, y3, x4, y4);
258 GDIPlus.CheckStatus (status);
262 // AddBeziers
264 public void AddBeziers (Point [] pts)
266 Status status = GDIPlus.GdipAddPathBeziersI (nativePath, pts, pts.Length);
267 GDIPlus.CheckStatus (status);
270 public void AddBeziers (PointF [] pts)
272 Status status = GDIPlus.GdipAddPathBeziers (nativePath, pts, pts.Length);
273 GDIPlus.CheckStatus (status);
277 // AddEllipse
279 public void AddEllipse (RectangleF r)
281 Status status = GDIPlus.GdipAddPathEllipse (nativePath, r.X, r.Y, r.Width, r.Height);
282 GDIPlus.CheckStatus (status);
285 public void AddEllipse (float x, float y, float width, float height)
287 Status status = GDIPlus.GdipAddPathEllipse (nativePath, x, y, width, height);
288 GDIPlus.CheckStatus (status);
291 public void AddEllipse (Rectangle r)
293 Status status = GDIPlus.GdipAddPathEllipseI (nativePath, r.X, r.Y, r.Width, r.Height);
294 GDIPlus.CheckStatus (status);
297 public void AddEllipse (int x, int y, int width, int height)
299 Status status = GDIPlus.GdipAddPathEllipseI (nativePath, x, y, width, height);
300 GDIPlus.CheckStatus (status);
305 // AddLine
307 public void AddLine (Point a, Point b)
309 Status status = GDIPlus.GdipAddPathLineI (nativePath, a.X, a.Y, b.X, b.Y);
310 GDIPlus.CheckStatus (status);
313 public void AddLine (PointF a, PointF b)
315 Status status = GDIPlus.GdipAddPathLine (nativePath, a.X, a.Y, b.X,
316 b.Y);
318 GDIPlus.CheckStatus (status);
321 public void AddLine (int x1, int y1, int x2, int y2)
323 Status status = GDIPlus.GdipAddPathLineI (nativePath, x1, y1, x2, y2);
324 GDIPlus.CheckStatus (status);
327 public void AddLine (float x1, float y1, float x2, float y2)
329 Status status = GDIPlus.GdipAddPathLine (nativePath, x1, y1, x2,
330 y2);
332 GDIPlus.CheckStatus (status);
336 // AddLines
338 public void AddLines (Point [] points)
340 int length = points.Length;
342 for (int i = 0; i < length - 2; i += 2) {
343 int j = i + 1;
344 Status status = GDIPlus.GdipAddPathLineI (
345 nativePath, points [i].X, points [i].Y, points [j].X, points [j].Y);
346 GDIPlus.CheckStatus (status);
350 public void AddLines (PointF [] points)
352 int length = points.Length;
354 for (int i = 0; i < length - 2; i += 2) {
355 int j = i + 1;
356 Status status = GDIPlus.GdipAddPathLine (
357 nativePath, points [i].X, points [i].Y, points [j].X, points [j].Y);
358 GDIPlus.CheckStatus (status);
363 // AddPie
365 public void AddPie (Rectangle rect, float startAngle, float sweepAngle)
367 Status status = GDIPlus.GdipAddPathPie (
368 nativePath, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
369 GDIPlus.CheckStatus (status);
372 public void AddPie (int x, int y, int width, int height, float startAngle, float sweepAngle)
374 Status status = GDIPlus.GdipAddPathPieI (nativePath, x, y, width, height, startAngle, sweepAngle);
375 GDIPlus.CheckStatus (status);
378 public void AddPie (float x, float y, float width, float height, float startAngle, float sweepAngle)
380 Status status = GDIPlus.GdipAddPathPie (nativePath, x, y, width, height, startAngle, sweepAngle);
381 GDIPlus.CheckStatus (status);
385 // AddPolygon
387 public void AddPolygon (Point [] points)
389 Status status = GDIPlus.GdipAddPathPolygonI (nativePath, points, points.Length);
390 GDIPlus.CheckStatus (status);
393 public void AddPolygon (PointF [] points)
395 Status status = GDIPlus.GdipAddPathPolygon (nativePath, points, points.Length);
396 GDIPlus.CheckStatus (status);
400 // AddRectangle
402 public void AddRectangle (Rectangle rect)
404 Status status = GDIPlus.GdipAddPathRectangleI (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
405 GDIPlus.CheckStatus (status);
408 public void AddRectangle (RectangleF rect)
410 Status status = GDIPlus.GdipAddPathRectangle (nativePath, rect.X, rect.Y, rect.Width, rect.Height);
411 GDIPlus.CheckStatus (status);
415 // AddRectangles
417 public void AddRectangles (Rectangle [] rects)
419 Status status = GDIPlus.GdipAddPathRectanglesI (nativePath, rects, rects.Length);
420 GDIPlus.CheckStatus (status);
423 public void AddRectangles (RectangleF [] rects)
425 Status status = GDIPlus.GdipAddPathRectangles (nativePath, rects, rects.Length);
426 GDIPlus.CheckStatus (status);
430 // AddPath
432 public void AddPath (GraphicsPath addingPath, bool connect)
434 Status status = GDIPlus.GdipAddPathPath (nativePath, addingPath.nativePath, connect);
435 GDIPlus.CheckStatus (status);
438 public PointF GetLastPoint ()
440 PointF pt;
441 Status status = GDIPlus.GdipGetPathLastPoint (nativePath, out pt);
442 GDIPlus.CheckStatus (status);
444 return pt;
448 // AddClosedCurve
450 public void AddClosedCurve (Point [] points)
452 Status status = GDIPlus.GdipAddPathClosedCurveI (nativePath, points, points.Length);
453 GDIPlus.CheckStatus (status);
456 public void AddClosedCurve (PointF [] points)
458 Status status = GDIPlus.GdipAddPathClosedCurve (nativePath, points, points.Length);
459 GDIPlus.CheckStatus (status);
462 public void AddClosedCurve (Point [] points, float tension)
464 Status status = GDIPlus.GdipAddPathClosedCurve2I (nativePath, points, points.Length, tension);
465 GDIPlus.CheckStatus (status);
468 public void AddClosedCurve (PointF [] points, float tension)
470 Status status = GDIPlus.GdipAddPathClosedCurve2 (nativePath, points, points.Length, tension);
471 GDIPlus.CheckStatus (status);
475 // AddCurve
477 public void AddCurve (Point [] points)
479 Status status = GDIPlus.GdipAddPathCurveI (nativePath, points, points.Length);
480 GDIPlus.CheckStatus (status);
483 public void AddCurve (PointF [] points)
485 Status status = GDIPlus.GdipAddPathCurve (nativePath, points, points.Length);
486 GDIPlus.CheckStatus (status);
489 public void AddCurve (Point [] points, float tension)
491 Status status = GDIPlus.GdipAddPathCurve2I (nativePath, points, points.Length, tension);
492 GDIPlus.CheckStatus (status);
495 public void AddCurve (PointF [] points, float tension)
497 Status status = GDIPlus.GdipAddPathCurve2 (nativePath, points, points.Length, tension);
498 GDIPlus.CheckStatus (status);
501 public void AddCurve (Point [] points, int offset, int numberOfSegments, float tension)
503 Status status = GDIPlus.GdipAddPathCurve3I (nativePath, points, points.Length,
504 offset, numberOfSegments, tension);
506 GDIPlus.CheckStatus (status);
509 public void AddCurve (PointF [] points, int offset, int numberOfSegments, float tension)
511 Status status = GDIPlus.GdipAddPathCurve3 (nativePath, points, points.Length,
512 offset, numberOfSegments, tension);
514 GDIPlus.CheckStatus (status);
517 public void Reset ()
519 Status status = GDIPlus.GdipResetPath (nativePath);
520 GDIPlus.CheckStatus (status);
523 public void Reverse ()
525 Status status = GDIPlus.GdipReversePath (nativePath);
526 GDIPlus.CheckStatus (status);
529 public void Transform (Matrix matrix)
531 Status status = GDIPlus.GdipTransformPath (nativePath, matrix.nativeMatrix);
532 GDIPlus.CheckStatus (status);
535 [MonoTODO]
536 public void AddString (string s, FontFamily family, int style, float emSize, Point origin, StringFormat format)
538 throw new NotImplementedException ();
541 [MonoTODO]
542 public void AddString (string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
544 throw new NotImplementedException ();
547 [MonoTODO]
548 public void AddString (string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
550 throw new NotImplementedException ();
553 [MonoTODO]
554 public void AddString (string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format)
556 throw new NotImplementedException ();
559 public void ClearMarkers()
561 Status s = GDIPlus.GdipClearPathMarkers (nativePath);
563 GDIPlus.CheckStatus (s);
566 public void CloseAllFigures()
568 Status s = GDIPlus.GdipClosePathFigures (nativePath);
570 GDIPlus.CheckStatus (s);
573 public void CloseFigure()
575 Status s = GDIPlus.GdipClosePathFigure (nativePath);
577 GDIPlus.CheckStatus (s);
580 public void Flatten ()
582 // 1/4 is the FlatnessDefault as defined in GdiPlusEnums.h
583 Flatten (null, 1.0f / 4.0f);
586 public void Flatten (Matrix matrix)
588 Flatten (matrix, 1.0f / 4.0f);
591 public void Flatten (Matrix matrix, float flatness)
593 Status status = GDIPlus.GdipFlattenPath (nativePath, matrix.nativeMatrix, flatness);
595 GDIPlus.CheckStatus (status);
598 public RectangleF GetBounds ()
600 return GetBounds (null, null);
603 public RectangleF GetBounds (Matrix matrix)
605 return GetBounds (matrix, null);
608 [MonoTODO]
609 public RectangleF GetBounds (Matrix matrix, Pen pen)
611 RectangleF retval;
612 IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
613 IntPtr p = (pen == null) ? IntPtr.Zero : pen.nativeObject;
615 Status s = GDIPlus.GdipGetPathWorldBounds (nativePath, out retval, m, p);
617 GDIPlus.CheckStatus (s);
619 return retval;
622 public bool IsOutlineVisible (Point point, Pen pen)
624 return IsOutlineVisible (point.X, point.Y, pen, null);
627 public bool IsOutlineVisible (PointF point, Pen pen)
629 return IsOutlineVisible (point.X, point.Y, pen, null);
632 public bool IsOutlineVisible (int x, int y, Pen pen)
634 return IsOutlineVisible (x, y, pen, null);
637 public bool IsOutlineVisible (float x, float y, Pen pen)
639 return IsOutlineVisible (x, y, pen, null);
642 public bool IsOutlineVisible (Point pt, Pen pen, Graphics graphics)
644 return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
647 public bool IsOutlineVisible (PointF pt, Pen pen, Graphics graphics)
649 return IsOutlineVisible (pt.X, pt.Y, pen, graphics);
652 [MonoTODO]
653 public bool IsOutlineVisible (int x, int y, Pen pen, Graphics graphics)
655 bool result;
656 IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
658 Status s = GDIPlus.GdipIsOutlineVisiblePathPointI (nativePath, x, y, g, out result);
659 GDIPlus.CheckStatus (s);
661 return result;
664 [MonoTODO]
665 public bool IsOutlineVisible (float x, float y, Pen pen, Graphics graphics)
667 bool result;
668 IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
670 Status s = GDIPlus.GdipIsOutlineVisiblePathPoint (nativePath, x, y, g, out result);
671 GDIPlus.CheckStatus (s);
673 return result;
676 public bool IsVisible (Point point)
678 return IsVisible (point.X, point.Y, null);
681 public bool IsVisible (PointF point)
683 return IsVisible (point.X, point.Y, null);
686 public bool IsVisible (int x, int y)
688 return IsVisible (x, y, null);
691 public bool IsVisible (float x, float y)
693 return IsVisible (x, y, null);
696 public bool IsVisible (Point pt, Graphics graphics)
698 return IsVisible (pt.X, pt.Y, graphics);
701 public bool IsVisible (PointF pt, Graphics graphics)
703 return IsVisible (pt.X, pt.Y, graphics);
706 [MonoTODO]
707 public bool IsVisible (int x, int y, Graphics graphics)
709 bool retval;
711 IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
713 Status s = GDIPlus.GdipIsVisiblePathPointI (nativePath, x, y, g, out retval);
715 GDIPlus.CheckStatus (s);
717 return retval;
720 [MonoTODO]
721 public bool IsVisible (float x, float y, Graphics graphics)
723 bool retval;
725 IntPtr g = (graphics == null) ? IntPtr.Zero : graphics.nativeObject;
727 Status s = GDIPlus.GdipIsVisiblePathPoint (nativePath, x, y, g, out retval);
729 GDIPlus.CheckStatus (s);
731 return retval;
734 public void SetMarkers ()
736 Status s = GDIPlus.GdipSetPathMarker (nativePath);
738 GDIPlus.CheckStatus (s);
741 public void StartFigure()
743 Status s = GDIPlus.GdipStartPathFigure (nativePath);
745 GDIPlus.CheckStatus (s);
748 public void Warp (PointF[] destPoints, RectangleF srcRect)
750 Warp (destPoints, srcRect, null, WarpMode.Perspective, 1.0f / 4.0f);
753 public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix)
755 Warp (destPoints, srcRect, matrix, WarpMode.Perspective, 1.0f / 4.0f);
758 public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode)
760 Warp (destPoints, srcRect, matrix, warpMode, 1.0f / 4.0f);
763 [MonoTODO]
764 public void Warp (PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode, float flatness)
766 IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
768 Status s = GDIPlus.GdipWarpPath (nativePath, m, destPoints, destPoints.Length,
769 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, warpMode, flatness);
771 GDIPlus.CheckStatus (s);
774 public void Widen (Pen pen)
776 Widen (pen, null, 1.0f / 4.0f);
779 public void Widen (Pen pen, Matrix matrix)
781 Widen (pen, matrix, 1.0f / 4.0f);
784 [MonoTODO]
785 public void Widen (Pen pen, Matrix matrix, float flatness)
787 IntPtr p = (pen == null) ? IntPtr.Zero : pen.nativeObject;
788 IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.nativeMatrix;
790 Status s = GDIPlus.GdipWidenPath (nativePath, p, m, flatness);
792 GDIPlus.CheckStatus (s);