2005-04-12 Dick Porter <dick@ximian.com>
[mono.git] / mcs / class / System.Drawing / System.Drawing.Drawing2D / GraphicsPathIterator.cs
1 //
2 // System.Drawing.Drawing2D.GraphicsPathIterator.cs
3 //
4 // Author:
5 //   Dennis Hayes (dennish@Raytek.com)
6 //   Duncan Mak (duncan@ximian.com)
7 //   Ravindra (rkumar@novell.com)
8 //
9 // Copyright (C) 2002/3 Ximian, Inc (http://www.ximian.com)
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32 using System;
33 using System.Drawing;
34
35 namespace System.Drawing.Drawing2D
36 {
37         public sealed class GraphicsPathIterator : MarshalByRefObject, IDisposable
38         {
39                 private IntPtr nativeObject = IntPtr.Zero;
40
41                 // Constructors
42                 internal GraphicsPathIterator (IntPtr native)
43                 {
44                         this.nativeObject = native;
45                 }
46
47                 public GraphicsPathIterator (GraphicsPath path)
48                 {
49                         Status status = GDIPlus.GdipCreatePathIter (out nativeObject, path.NativeObject);
50                         GDIPlus.CheckStatus (status);
51                 }
52
53                 internal IntPtr NativeObject {
54                         get {
55                                 return nativeObject;
56                         }
57                         set {
58                                 nativeObject = value;
59                         }
60                 }
61
62                 // Public Properites
63
64                 public int Count {
65                         get {
66                                 int count;
67                                 Status status = GDIPlus.GdipPathIterGetCount (nativeObject, out count);
68                                 GDIPlus.CheckStatus (status);
69
70                                 return count;
71                         }
72                 }
73
74                 public int SubpathCount {
75                         get {
76                                 int count;
77                                 Status status = GDIPlus.GdipPathIterGetSubpathCount (nativeObject, out count);
78                                 GDIPlus.CheckStatus (status);
79
80                                 return count;
81                         }
82                 }
83
84                 internal void Dispose (bool disposing)
85                 {
86                         Status status;
87                         if (nativeObject != IntPtr.Zero) {
88                                 status = GDIPlus.GdipDeletePathIter (nativeObject);
89                                 GDIPlus.CheckStatus (status);
90
91                                 nativeObject = IntPtr.Zero;
92                         }
93                 }
94
95                 // Public Methods.
96
97                 public int CopyData (ref PointF [] points, ref byte [] types, int startIndex, int endIndex)
98                 {
99                         Status status;
100                         int resultCount;
101
102                         if (points.Length != types.Length)
103                                 throw new ArgumentException ("Invalid arguments passed. Both arrays should have the same length.");
104
105                         status = GDIPlus.GdipPathIterCopyData (nativeObject, out resultCount, points, types, startIndex, endIndex);
106                         GDIPlus.CheckStatus (status);
107
108                         return resultCount;
109                 }
110
111                 public void Dispose ()
112                 {
113                         Dispose (true);
114                         System.GC.SuppressFinalize (this);
115                 }
116
117                 ~GraphicsPathIterator ()
118                 {
119                         Dispose (false);
120                 }
121
122                 public int Enumerate (ref PointF [] points, ref byte [] types)
123                 {
124                         Status status;
125                         int resultCount;
126                         int count = points.Length;
127
128                         if (count != types.Length)
129                                 throw new ArgumentException ("Invalid arguments passed. Both arrays should have the same length.");
130
131                         status = GDIPlus.GdipPathIterEnumerate (nativeObject, out resultCount, points, types, count);
132                         GDIPlus.CheckStatus (status);
133
134                         return resultCount;
135                 }
136
137                 public bool HasCurve ()
138                 {
139                         bool curve;
140                         Status status = GDIPlus.GdipPathIterHasCurve (nativeObject, out curve);
141                         GDIPlus.CheckStatus (status);
142
143                         return curve;
144                 }
145
146                 public int NextMarker (GraphicsPath path)
147                 {
148                         Status status;
149                         int resultCount;
150                         status = GDIPlus.GdipPathIterNextMarkerPath (nativeObject, out resultCount, path.NativeObject);
151                         GDIPlus.CheckStatus (status);
152
153                         return resultCount;
154                 }
155
156                 public int NextMarker (out int startIndex, out int endIndex)
157                 {
158                         Status status;
159                         int resultCount;
160                         status = GDIPlus.GdipPathIterNextMarker (nativeObject, out resultCount, out startIndex, out endIndex);
161                         GDIPlus.CheckStatus (status);
162
163                         return resultCount;
164                 }
165
166                 public int NextPathType (out byte pathType, out int startIndex, out int endIndex)
167                 {
168                         Status status;
169                         int resultCount;
170                         status = GDIPlus.GdipPathIterNextPathType (nativeObject, out resultCount, out pathType, out startIndex, out endIndex);
171                         GDIPlus.CheckStatus (status);
172
173                         return resultCount;
174                 }
175
176                 public int NextSubpath (GraphicsPath path, out bool isClosed)
177                 {
178                         Status status;
179                         int resultCount;
180                         status = GDIPlus.GdipPathIterNextSubpathPath (nativeObject, out resultCount, path.NativeObject, out isClosed);
181                         GDIPlus.CheckStatus (status);
182
183                         return resultCount;
184                 }
185
186                 public int NextSubpath (out int startIndex, out int endIndex, out bool isClosed)
187                 {
188                         Status status;
189                         int resultCount;
190                         status = GDIPlus.GdipPathIterNextSubpath (nativeObject, out resultCount, out startIndex, out endIndex, out isClosed);
191                         GDIPlus.CheckStatus (status);
192
193                         return resultCount;
194                 }
195
196                 public void Rewind ()
197                 {
198                         Status status = GDIPlus.GdipPathIterRewind (nativeObject);
199                         GDIPlus.CheckStatus (status);
200                 }
201         }
202 }