044e219b7d4fbe05ae8aee61452bb7f678132384
[mono.git] / mcs / class / System.Drawing / System.Drawing / Region.jvm.cs
1
2 using System;
3 using System.Drawing.Drawing2D;
4 using System.Runtime.InteropServices;
5
6 using awt = java.awt;
7 using geom = java.awt.geom;
8
9 namespace System.Drawing
10 {
11         [ComVisible (false)]
12         public sealed class Region : BasicShape
13         {
14                 #region Member Vars
15                 internal static readonly Region InfiniteRegion = new Region(new Rectangle(-0x400000, -0x400000, 0x800000, 0x800000));
16                 #endregion
17         
18                 #region Internals
19                 internal geom.Area NativeObject
20                 {
21                         get
22                         {
23                                 return (geom.Area)Shape;
24                         }
25                 }
26                 #endregion
27                 
28                 #region Ctors. and Dtor\r
29 \r
30 \r
31                 public Region ()\r
32                         : this ((geom.Area) InfiniteRegion.NativeObject.MemberwiseClone ())
33                 {                  
34                 }
35
36         internal Region(geom.Area native) : base(native)
37                 {
38         }
39                 
40                 
41                 public Region (GraphicsPath path) : this(new geom.Area(path.NativeObject))
42                 {       
43                 }
44
45                 public Region (Rectangle rect) : this(new geom.Area(rect.NativeObject))
46                 {
47                 }
48
49                 public Region (RectangleF rect) : this(new geom.Area(rect.NativeObject))
50                 {
51                 }
52
53                 [MonoTODO]
54                 public Region (RegionData region_data) : this((geom.Area)null)
55                 {
56                         throw new NotImplementedException ();
57                 }
58                 #endregion
59                 
60                 #region Union
61                 public void Union (GraphicsPath path)
62                 {
63                         if (path == null)
64                                 throw new ArgumentNullException("path");
65                         NativeObject.add(new geom.Area(path.NativeObject));
66                 }
67
68
69                 public void Union (Rectangle rect)
70                 {                                    
71                         NativeObject.add(new geom.Area(rect.NativeObject));
72                 }
73
74                 public void Union (RectangleF rect)
75                 {
76                         NativeObject.add(new geom.Area(rect.NativeObject));
77                 }
78
79                 public void Union (Region region)
80                 {
81                         if (region == null)
82                                 throw new ArgumentNullException("region");
83                         NativeObject.add(region.NativeObject);
84                 }
85                 #endregion                                                                                 
86
87                 #region Intersect
88                 //
89                 public void Intersect (GraphicsPath path)
90                 {
91                         if (path == null)
92                                 throw new ArgumentNullException("path");
93                         NativeObject.intersect(new geom.Area(path.NativeObject));
94                 }
95
96                 public void Intersect (Rectangle rect)
97                 {
98                         NativeObject.intersect(new geom.Area(rect.NativeObject));
99                 }
100
101                 public void Intersect (RectangleF rect)
102                 {
103                         NativeObject.intersect(new geom.Area(rect.NativeObject));
104                 }
105
106                 public void Intersect (Region region)
107                 {
108                         if (region == null)
109                                 throw new ArgumentNullException("region");
110                         NativeObject.intersect(region.NativeObject);
111                 }
112                 #endregion
113
114                 #region  Complement
115                 //
116                 public void Complement (GraphicsPath path)
117                 {
118                         if (path == null)
119                                 throw new ArgumentNullException("path");
120                         geom.Area a = new geom.Area(path.NativeObject);
121                         a.subtract(NativeObject);
122                         Shape = a;
123                 }
124
125                 public void Complement (Rectangle rect)
126                 {
127                         geom.Area a = new geom.Area(rect.NativeObject);
128                         a.subtract(NativeObject);
129                         Shape = a;
130                 }
131
132                 public void Complement (RectangleF rect)
133                 {
134                         geom.Area a = new geom.Area(rect.NativeObject);
135                         a.subtract(NativeObject);
136                         Shape = a;
137                 }
138
139                 public void Complement (Region region)
140                 {
141                         if (region == null)
142                                 throw new ArgumentNullException("region");\r
143                         geom.Area a = (geom.Area) region.NativeObject.MemberwiseClone ();
144                         a.subtract(NativeObject);
145                         Shape = a;
146                 }
147                 #endregion
148
149                 #region Exclude
150                 //
151                 public void Exclude (GraphicsPath path)
152                 {
153                         if (path == null)
154                                 throw new ArgumentNullException("path");
155                         NativeObject.subtract(new geom.Area(path.NativeObject));
156                 }
157
158                 public void Exclude (Rectangle rect)
159                 {
160                         NativeObject.subtract(new geom.Area(rect.NativeObject));
161                 }
162
163                 public void Exclude (RectangleF rect)
164                 {
165                         NativeObject.subtract(new geom.Area(rect.NativeObject));
166                 }
167
168                 public void Exclude (Region region)
169                 {
170                         if (region == null)
171                                 throw new ArgumentNullException("region");
172                         NativeObject.subtract(region.NativeObject);
173                 }
174                 #endregion
175
176                 #region  Xor
177                 //
178                 public void Xor (GraphicsPath path)
179                 {
180                         if (path == null)
181                                 throw new ArgumentNullException("path");
182                         NativeObject.exclusiveOr(new geom.Area(path.NativeObject));
183                 }
184
185                 public void Xor (Rectangle rect)
186                 {
187                         NativeObject.exclusiveOr(new geom.Area(rect.NativeObject));
188                 }
189
190                 public void Xor (RectangleF rect)
191                 {
192                         NativeObject.exclusiveOr(new geom.Area(rect.NativeObject));
193                 }
194
195                 public void Xor (Region region)
196                 {
197                         if (region == null)
198                                 throw new ArgumentNullException("region");
199                         NativeObject.exclusiveOr(region.NativeObject);
200                 }
201                 #endregion
202
203                 #region GetBounds
204                 //
205                 public RectangleF GetBounds (Graphics graphics)
206                 {
207                         if (graphics == null)
208                                 throw new ArgumentNullException("graphics");
209                         return new RectangleF(NativeObject.getBounds2D());
210                 }
211                 #endregion
212
213                 #region  Translate
214                 //
215                 public void Translate (int dx, int dy)
216                 {
217                         Translate((float)dx, (float)dy);
218                 }
219
220                 public void Translate (float dx, float dy)
221                 {
222                         NativeObject.transform(geom.AffineTransform.getTranslateInstance(
223                                 dx,
224                                 dy));
225                 }
226                 #endregion
227
228                 #region  IsVisible [TODO]
229                 //
230                 public bool IsVisible (int x, int y, Graphics g)
231                 {
232                         return IsVisible((float)x, (float)y, g);
233                 }
234
235                 public bool IsVisible (int x, int y, int width, int height)
236                 {
237                         return IsVisible((float)x, (float)y, (float)width, (float)height);
238                 }
239
240                 public bool IsVisible (int x, int y, int width, int height, Graphics g)
241                 {
242                         return IsVisible((float)x, (float)y, (float)width, (float)height, g);
243                 }
244
245                 public bool IsVisible (Point point)
246                 {
247                         return IsVisible(point.X, point.Y);
248                 }
249
250                 public bool IsVisible (PointF point)
251                 {
252                         return IsVisible(point.X, point.Y);
253                 }
254
255                 public bool IsVisible (Point point, Graphics g)
256                 {
257                         return IsVisible(point.X, point.Y, g);
258                 }
259
260                 public bool IsVisible (PointF point, Graphics g)
261                 {
262                         return IsVisible(point.X, point.Y, g);
263                 }
264
265                 public bool IsVisible (Rectangle rect)
266                 {
267                         return IsVisible(rect.X, rect.Y, rect.Width, rect.Height);
268                 }
269
270                 public bool IsVisible (RectangleF rect)
271                 {
272                         return IsVisible(rect.X, rect.Y, rect.Width, rect.Height);
273                 }
274
275                 public bool IsVisible (Rectangle rect, Graphics g)
276                 {
277                         return IsVisible(rect.X, rect.Y, rect.Width, rect.Height, g);
278                 }
279
280                 public bool IsVisible (RectangleF rect, Graphics g)
281                 {
282                         return IsVisible(rect.X, rect.Y, rect.Width, rect.Height, g);
283                 }
284
285                 public bool IsVisible (float x, float y)
286                 {
287                         return NativeObject.contains(x,y);
288                 }
289
290                 public bool IsVisible (float x, float y, Graphics g)
291                 {
292                         if (g == null)
293                                 throw new ArgumentNullException("graphics");
294                         return NativeObject.contains(x,y);
295                 }
296
297                 public bool IsVisible (float x, float y, float width, float height)
298                 {
299                         return NativeObject.intersects(x,y,width,height);
300                 }
301
302                 public bool IsVisible (float x, float y, float width, float height, Graphics g) 
303                 {
304                         if (g == null)
305                                 throw new ArgumentNullException("graphics");
306                         return NativeObject.intersects(x,y,width,height);
307                 }
308                 #endregion
309
310                 #region IsEmpty
311                 public bool IsEmpty(Graphics g)
312                 {
313                         if (g == null)
314                                 throw new ArgumentNullException("graphics");
315                         return NativeObject.isEmpty();
316                 }
317                 #endregion
318
319                 #region IsInfinite
320                 public bool IsInfinite(Graphics g)
321                 {
322                         if (g == null)
323                                 throw new ArgumentNullException("graphics");
324                         //probably too naive.
325                         return NativeObject.equals(InfiniteRegion.NativeObject);
326                 }
327                 #endregion
328
329                 #region MakeEmpty
330                 public void MakeEmpty()
331                 {
332                         NativeObject.reset();
333                 }
334                 #endregion
335
336                 #region MakeInfinite
337                 public void MakeInfinite()
338                 {\r
339                         Shape = (geom.Area) InfiniteRegion.NativeObject.MemberwiseClone ();
340                 }
341                 #endregion 
342
343                 #region Equals
344                 public bool Equals(Region region, Graphics g)
345                 {
346                         if (g == null)
347                                 throw new ArgumentNullException("graphics");
348                         return NativeObject.equals(region.NativeObject);
349                 }
350                 #endregion
351                                 
352                 [MonoTODO]
353                 public RegionData GetRegionData()
354                 {
355                         throw new NotImplementedException();
356                 }
357 \r
358                 [MonoTODO]\r
359                 public IntPtr GetHrgn(Graphics g) {
360                         throw new NotImplementedException();
361                 }
362                 
363                 
364                 public RectangleF[] GetRegionScans(Matrix matrix)
365                 {
366                         throw new NotSupportedException();
367                 }
368                 
369                 #region Transform 
370                 public void Transform(Matrix matrix)
371                 {
372                         if (matrix == null)
373                                 throw new ArgumentNullException("matrix");
374                         NativeObject.transform(matrix.NativeObject);
375                 }               
376                 #endregion
377
378                 #region Clone
379                 public Region Clone()
380                 {\r
381                         return new Region ((geom.Area) NativeObject.MemberwiseClone ());
382                 }
383                 #endregion
384         }
385 }