3 using System.Drawing.Drawing2D;
4 using System.Runtime.InteropServices;
7 using geom = java.awt.geom;
9 namespace System.Drawing
12 public sealed class Region : BasicShape
15 internal static readonly Region InfiniteRegion = new Region(new Rectangle(-0x400000, -0x400000, 0x800000, 0x800000));
19 internal geom.Area NativeObject
23 return (geom.Area)Shape;
28 #region Ctors. and Dtor
31 public Region() : this((geom.Area)InfiniteRegion.NativeObject.clone())
35 internal Region(geom.Area native) : base(native)
40 public Region (GraphicsPath path) : this(new geom.Area(path.NativeObject))
44 public Region (Rectangle rect) : this(new geom.Area(new awt.Rectangle(rect.X,rect.Y,rect.Width,rect.Height)))
48 public Region (RectangleF rect) : this(new geom.Area(new geom.Rectangle2D.Float(rect.X,rect.Y,rect.Width,rect.Height)))
52 public Region (RegionData region_data) : this((geom.Area)null)
54 throw new NotImplementedException ();
59 public void Union (GraphicsPath path)
62 throw new ArgumentNullException("path");
63 NativeObject.add(new geom.Area(path.NativeObject));
67 public void Union (Rectangle rect)
69 NativeObject.add(new geom.Area(new awt.Rectangle(rect.X,rect.Y,rect.Width,rect.Height)));
72 public void Union (RectangleF rect)
74 NativeObject.add(new geom.Area(new geom.Rectangle2D.Float(rect.X,rect.Y,rect.Width,rect.Height)));
77 public void Union (Region region)
80 throw new ArgumentNullException("region");
81 NativeObject.add(new geom.Area(region.NativeObject));
87 public void Intersect (GraphicsPath path)
90 throw new ArgumentNullException("path");
91 NativeObject.intersect(new geom.Area(path.NativeObject));
94 public void Intersect (Rectangle rect)
96 NativeObject.intersect(new geom.Area(new awt.Rectangle(rect.X,rect.Y,rect.Width,rect.Height)));
99 public void Intersect (RectangleF rect)
101 NativeObject.intersect(new geom.Area(new geom.Rectangle2D.Float(rect.X,rect.Y,rect.Width,rect.Height)));
104 public void Intersect (Region region)
107 throw new ArgumentNullException("region");
108 NativeObject.intersect(new geom.Area(region.NativeObject));
114 public void Complement (GraphicsPath path)
117 throw new ArgumentNullException("path");
118 geom.Area a = new geom.Area(path.NativeObject);
119 a.subtract(NativeObject);
123 public void Complement (Rectangle rect)
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);
130 public void Complement (RectangleF rect)
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);
137 public void Complement (Region region)
140 throw new ArgumentNullException("region");
141 geom.Area a = new geom.Area(region);
142 a.subtract(NativeObject);
149 public void Exclude (GraphicsPath path)
152 throw new ArgumentNullException("path");
153 NativeObject.subtract(new geom.Area(path.NativeObject));
156 public void Exclude (Rectangle rect)
158 NativeObject.subtract(new geom.Area(new awt.Rectangle(rect.X,rect.Y,rect.Width,rect.Height)));
161 public void Exclude (RectangleF rect)
163 NativeObject.subtract(new geom.Area(new geom.Rectangle2D.Float(rect.X,rect.Y,rect.Width,rect.Height)));
166 public void Exclude (Region region)
169 throw new ArgumentNullException("region");
170 NativeObject.subtract(region.NativeObject);
176 public void Xor (GraphicsPath path)
179 throw new ArgumentNullException("path");
180 NativeObject.exclusiveOr(new geom.Area(path.NativeObject));
183 public void Xor (Rectangle rect)
185 NativeObject.exclusiveOr(new geom.Area(new awt.Rectangle(rect.X,rect.Y,rect.Width,rect.Height)));
188 public void Xor (RectangleF rect)
190 NativeObject.exclusiveOr(new geom.Area(new geom.Rectangle2D.Float(rect.X,rect.Y,rect.Width,rect.Height)));
193 public void Xor (Region region)
196 throw new ArgumentNullException("region");
197 NativeObject.exclusiveOr(region.NativeObject);
203 public RectangleF GetBounds (Graphics graphics)
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());
214 public void Translate (int dx, int dy)
216 NativeObject.transform(geom.AffineTransform.getTranslateInstance(
221 public void Translate (float dx, float dy)
223 NativeObject.transform(geom.AffineTransform.getTranslateInstance(
229 #region IsVisible [TODO]
231 public bool IsVisible (int x, int y, Graphics g)
233 return IsVisible((float)x, (float)y, g);
236 public bool IsVisible (int x, int y, int width, int height)
238 return IsVisible((float)x, (float)y, (float)width, (float)height);
241 public bool IsVisible (int x, int y, int width, int height, Graphics g)
243 return IsVisible((float)x, (float)y, (float)width, (float)height, g);
246 public bool IsVisible (Point point)
248 return IsVisible(point.X, point.Y);
251 public bool IsVisible (PointF point)
253 return IsVisible(point.X, point.Y);
256 public bool IsVisible (Point point, Graphics g)
258 return IsVisible(point.X, point.Y, g);
261 public bool IsVisible (PointF point, Graphics g)
263 return IsVisible(point.X, point.Y, g);
266 public bool IsVisible (Rectangle rect)
268 return IsVisible(rect.X, rect.Y, rect.Width, rect.Height);
271 public bool IsVisible (RectangleF rect)
273 return IsVisible(rect.X, rect.Y, rect.Width, rect.Height);
276 public bool IsVisible (Rectangle rect, Graphics g)
278 return IsVisible(rect.X, rect.Y, rect.Width, rect.Height, g);
281 public bool IsVisible (RectangleF rect, Graphics g)
283 return IsVisible(rect.X, rect.Y, rect.Width, rect.Height, g);
286 public bool IsVisible (float x, float y)
288 return NativeObject.contains(x,y);
291 public bool IsVisible (float x, float y, Graphics g)
294 throw new ArgumentNullException("graphics");
295 return NativeObject.contains(x,y);
298 public bool IsVisible (float x, float y, float width, float height)
300 return NativeObject.intersects(x,y,width,height);
303 public bool IsVisible (float x, float y, float width, float height, Graphics g)
306 throw new ArgumentNullException("graphics");
307 return NativeObject.intersects(x,y,width,height);
312 public bool IsEmpty(Graphics g)
315 throw new ArgumentNullException("graphics");
316 return NativeObject.isEmpty();
321 public bool IsInfinite(Graphics g)
324 throw new ArgumentNullException("graphics");
325 //probably too naive.
326 return NativeObject.equals(InfiniteRegion.NativeObject);
331 public void MakeEmpty()
333 NativeObject.reset();
338 public void MakeInfinite()
340 Shape = (geom.Area)InfiniteRegion.NativeObject.clone();
345 public bool Equals(Region region, Graphics g)
348 throw new ArgumentNullException("graphics");
349 return NativeObject.equals(region.NativeObject);
353 public RegionData GetRegionData()
355 throw new NotImplementedException();
359 #region GetRegionScans [TODO]
360 public RectangleF[] GetRegionScans(Matrix matrix)
362 geom.Area area = NativeObject;
364 area = area.createTransformedArea (matrix.NativeObject);
365 //FIXME: return more exact result
366 return new RectangleF [] {new RectangleF (area.getBounds2D ())};
371 public void Transform(Matrix matrix)
374 throw new ArgumentNullException("matrix");
375 NativeObject.transform(matrix.NativeObject);
380 public Region Clone()
382 return new Region((geom.Area)NativeObject.clone());