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