comparison dwt/graphics/Region.d @ 0:380af2bdd8e5

Upload of whole dwt tree
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sat, 09 Aug 2008 17:00:02 +0200
parents
children 649b8e223d5a
comparison
equal deleted inserted replaced
-1:000000000000 0:380af2bdd8e5
1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 module dwt.graphics.Region;
12
13 import dwt.dwthelper.utils;
14
15
16 import dwt.DWT;
17 import dwt.DWTError;
18 import dwt.DWTException;
19 import dwt.internal.Callback;
20 import dwt.internal.cocoa.NSAffineTransform;
21 import dwt.internal.cocoa.NSBezierPath;
22 import dwt.internal.cocoa.NSPoint;
23 import dwt.internal.cocoa.NSRect;
24 import dwt.internal.cocoa.OS;
25
26 /**
27 * Instances of this class represent areas of an x-y coordinate
28 * system that are aggregates of the areas covered by a number
29 * of polygons.
30 * <p>
31 * Application code must explicitly invoke the <code>Region.dispose()</code>
32 * method to release the operating system resources managed by each instance
33 * when those instances are no longer required.
34 * </p>
35 */
36 public final class Region extends Resource {
37 /**
38 * the OS resource for the region
39 * (Warning: This field is platform dependent)
40 * <p>
41 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT
42 * public API. It is marked public only so that it can be shared
43 * within the packages provided by DWT. It is not available on all
44 * platforms and should never be accessed from application code.
45 * </p>
46 */
47 public int handle;
48
49 /**
50 * Constructs a new empty region.
51 *
52 * @exception DWTError <ul>
53 * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
54 * </ul>
55 */
56 public Region() {
57 this(null);
58 }
59
60 /**
61 * Constructs a new empty region.
62 * <p>
63 * You must dispose the region when it is no longer required.
64 * </p>
65 *
66 * @param device the device on which to allocate the region
67 *
68 * @exception IllegalArgumentException <ul>
69 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
70 * </ul>
71 * @exception DWTError <ul>
72 * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
73 * </ul>
74 *
75 * @see #dispose
76 *
77 * @since 3.0
78 */
79 public Region(Device device) {
80 super(device);
81 handle = OS.NewRgn();
82 if (handle is 0) DWT.error(DWT.ERROR_NO_HANDLES);
83 init();
84 }
85
86 Region(Device device, int handle) {
87 super(device);
88 this.handle = handle;
89 }
90
91 /**
92 * Adds the given polygon to the collection of polygons
93 * the receiver maintains to describe its area.
94 *
95 * @param pointArray points that describe the polygon to merge with the receiver
96 *
97 * @exception IllegalArgumentException <ul>
98 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
99 * </ul>
100 * @exception DWTException <ul>
101 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
102 * </ul>
103 *
104 * @since 3.0
105 *
106 */
107 public void add (int[] pointArray) {
108 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
109 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
110 add(pointArray, pointArray.length);
111 }
112
113 void add(int[] pointArray, int count) {
114 if (count <= 2) return;
115 int polyRgn = OS.NewRgn();
116 OS.OpenRgn();
117 OS.MoveTo((short)pointArray[0], (short)pointArray[1]);
118 for (int i = 1; i < count / 2; i++) {
119 OS.LineTo((short)pointArray[2 * i], (short)pointArray[2 * i + 1]);
120 }
121 OS.LineTo((short)pointArray[0], (short)pointArray[1]);
122 OS.CloseRgn(polyRgn);
123 OS.UnionRgn(handle, polyRgn, handle);
124 OS.DisposeRgn(polyRgn);
125 }
126
127 /**
128 * Adds the given rectangle to the collection of polygons
129 * the receiver maintains to describe its area.
130 *
131 * @param rect the rectangle to merge with the receiver
132 *
133 * @exception IllegalArgumentException <ul>
134 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
135 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
136 * </ul>
137 * @exception DWTException <ul>
138 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
139 * </ul>
140 */
141 public void add(Rectangle rect) {
142 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
143 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
144 if (rect.width < 0 || rect.height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
145 add (rect.x, rect.y, rect.width, rect.height);
146 }
147
148 /**
149 * Adds the given rectangle to the collection of polygons
150 * the receiver maintains to describe its area.
151 *
152 * @param x the x coordinate of the rectangle
153 * @param y the y coordinate of the rectangle
154 * @param width the width coordinate of the rectangle
155 * @param height the height coordinate of the rectangle
156 *
157 * @exception IllegalArgumentException <ul>
158 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
159 * </ul>
160 * @exception DWTException <ul>
161 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
162 * </ul>
163 *
164 * @since 3.1
165 */
166 public void add(int x, int y, int width, int height) {
167 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
168 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
169 int rectRgn = OS.NewRgn();
170 short[] r = new short[4];
171 OS.SetRect(r, (short)x, (short)y, (short)(x + width),(short)(y + height));
172 OS.RectRgn(rectRgn, r);
173 OS.UnionRgn(handle, rectRgn, handle);
174 OS.DisposeRgn(rectRgn);
175 }
176
177 /**
178 * Adds all of the polygons which make up the area covered
179 * by the argument to the collection of polygons the receiver
180 * maintains to describe its area.
181 *
182 * @param region the region to merge
183 *
184 * @exception IllegalArgumentException <ul>
185 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
186 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
187 * </ul>
188 * @exception DWTException <ul>
189 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
190 * </ul>
191 */
192 public void add(Region region) {
193 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
194 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
195 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
196 OS.UnionRgn(handle, region.handle, handle);
197 }
198
199 /**
200 * Returns <code>true</code> if the point specified by the
201 * arguments is inside the area specified by the receiver,
202 * and <code>false</code> otherwise.
203 *
204 * @param x the x coordinate of the point to test for containment
205 * @param y the y coordinate of the point to test for containment
206 * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
207 *
208 * @exception DWTException <ul>
209 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
210 * </ul>
211 */
212 public bool contains(int x, int y) {
213 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
214 short[] point = new short[]{(short)x, (short)y};
215 return OS.PtInRgn(point, handle);
216 }
217
218 /**
219 * Returns <code>true</code> if the given point is inside the
220 * area specified by the receiver, and <code>false</code>
221 * otherwise.
222 *
223 * @param pt the point to test for containment
224 * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
225 *
226 * @exception IllegalArgumentException <ul>
227 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
228 * </ul>
229 * @exception DWTException <ul>
230 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
231 * </ul>
232 */
233 public bool contains(Point pt) {
234 if (pt is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
235 return contains(pt.x, pt.y);
236 }
237
238 NSAffineTransform transform;
239 void convertRgn(NSAffineTransform transform) {
240 int newRgn = OS.NewRgn();
241 Callback callback = new Callback(this, "convertRgn", 4);
242 int proc = callback.getAddress();
243 if (proc is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS);
244 this.transform = transform;
245 OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, proc, newRgn);
246 this.transform = null;
247 callback.dispose();
248 OS.CopyRgn(newRgn, handle);
249 OS.DisposeRgn(newRgn);
250 }
251
252 int convertRgn(int message, int rgn, int r, int newRgn) {
253 if (message is OS.kQDRegionToRectsMsgParse) {
254 short[] rect = new short[4];
255 OS.memmove(rect, r, rect.length * 2);
256 NSPoint point = new NSPoint();
257 int polyRgn = OS.NewRgn();
258 OS.OpenRgn();
259 point.x = rect[1];
260 point.y = rect[0];
261 point = transform.transformPoint(point);
262 short startX, startY;
263 OS.MoveTo(startX = (short)point.x, startY = (short)point.y);
264 point.x = rect[3];
265 point.y = rect[0];
266 point = transform.transformPoint(point);
267 OS.LineTo((short)Math.round(point.x), (short)point.y);
268 point.x = rect[3];
269 point.y = rect[2];
270 point = transform.transformPoint(point);
271 OS.LineTo((short)Math.round(point.x), (short)Math.round(point.y));
272 point.x = rect[1];
273 point.y = rect[2];
274 point = transform.transformPoint(point);
275 OS.LineTo((short)point.x, (short)Math.round(point.y));
276 OS.LineTo(startX, startY);
277 OS.CloseRgn(polyRgn);
278 OS.UnionRgn(newRgn, polyRgn, newRgn);
279 OS.DisposeRgn(polyRgn);
280 }
281 return 0;
282 }
283
284 void destroy() {
285 OS.DisposeRgn(handle);
286 handle = 0;
287 }
288
289 /**
290 * Compares the argument to the receiver, and returns true
291 * if they represent the <em>same</em> object using a class
292 * specific comparison.
293 *
294 * @param object the object to compare with this object
295 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
296 *
297 * @see #hashCode
298 */
299 public bool equals(Object object) {
300 if (this is object) return true;
301 if (!(object instanceof Region)) return false;
302 Region region = (Region)object;
303 return handle is region.handle;
304 }
305
306 /**
307 * Returns a rectangle which represents the rectangular
308 * union of the collection of polygons the receiver
309 * maintains to describe its area.
310 *
311 * @return a bounding rectangle for the region
312 *
313 * @exception DWTException <ul>
314 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
315 * </ul>
316 *
317 * @see Rectangle#union
318 */
319 public Rectangle getBounds() {
320 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
321 short[] bounds = new short[4];
322 OS.GetRegionBounds(handle, bounds);
323 int width = bounds[3] - bounds[1];
324 int height = bounds[2] - bounds[0];
325 return new Rectangle(bounds[1], bounds[0], width, height);
326 }
327
328 NSBezierPath getPath() {
329 Callback callback = new Callback(this, "regionToRects", 4);
330 if (callback.getAddress() is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS);
331 NSBezierPath path = NSBezierPath.bezierPath();
332 path.retain();
333 OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, callback.getAddress(), path.id);
334 callback.dispose();
335 if (path.isEmpty()) path.appendBezierPathWithRect(new NSRect());
336 return path;
337 }
338
339 NSPoint pt = new NSPoint();
340 short[] rect = new short[4];
341 int regionToRects(int message, int rgn, int r, int path) {
342 if (message is OS.kQDRegionToRectsMsgParse) {
343 OS.memmove(rect, r, rect.length * 2);
344 pt.x = rect[1];
345 pt.y = rect[0];
346 OS.objc_msgSend(path, OS.sel_moveToPoint_1, pt);
347 pt.x = rect[3];
348 OS.objc_msgSend(path, OS.sel_lineToPoint_1, pt);
349 pt.x = rect[3];
350 pt.y = rect[2];
351 OS.objc_msgSend(path, OS.sel_lineToPoint_1, pt);
352 pt.x = rect[1];
353 OS.objc_msgSend(path, OS.sel_lineToPoint_1, pt);
354 OS.objc_msgSend(path, OS.sel_closePath);
355 }
356 return 0;
357 }
358
359 public static Region carbon_new(Device device, int handle) {
360 return new Region(device, handle);
361 }
362
363 /**
364 * Returns an integer hash code for the receiver. Any two
365 * objects that return <code>true</code> when passed to
366 * <code>equals</code> must return the same value for this
367 * method.
368 *
369 * @return the receiver's hash
370 *
371 * @see #equals
372 */
373 public int hashCode() {
374 return handle;
375 }
376
377 /**
378 * Intersects the given rectangle to the collection of polygons
379 * the receiver maintains to describe its area.
380 *
381 * @param rect the rectangle to intersect with the receiver
382 *
383 * @exception IllegalArgumentException <ul>
384 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
385 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
386 * </ul>
387 * @exception DWTException <ul>
388 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
389 * </ul>
390 *
391 * @since 3.0
392 */
393 public void intersect(Rectangle rect) {
394 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
395 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
396 intersect (rect.x, rect.y, rect.width, rect.height);
397 }
398
399 /**
400 * Intersects the given rectangle to the collection of polygons
401 * the receiver maintains to describe its area.
402 *
403 * @param x the x coordinate of the rectangle
404 * @param y the y coordinate of the rectangle
405 * @param width the width coordinate of the rectangle
406 * @param height the height coordinate of the rectangle
407 *
408 * @exception IllegalArgumentException <ul>
409 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
410 * </ul>
411 * @exception DWTException <ul>
412 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
413 * </ul>
414 *
415 * @since 3.1
416 */
417 public void intersect(int x, int y, int width, int height) {
418 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
419 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
420 int rectRgn = OS.NewRgn();
421 short[] r = new short[4];
422 OS.SetRect(r, (short)x, (short)y, (short)(x + width),(short)(y + height));
423 OS.RectRgn(rectRgn, r);
424 OS.SectRgn(handle, rectRgn, handle);
425 OS.DisposeRgn(rectRgn);
426 }
427
428 /**
429 * Intersects all of the polygons which make up the area covered
430 * by the argument to the collection of polygons the receiver
431 * maintains to describe its area.
432 *
433 * @param region the region to intersect
434 *
435 * @exception IllegalArgumentException <ul>
436 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
437 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
438 * </ul>
439 * @exception DWTException <ul>
440 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
441 * </ul>
442 *
443 * @since 3.0
444 */
445 public void intersect(Region region) {
446 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
447 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
448 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
449 OS.SectRgn(handle, region.handle, handle);
450 }
451
452 /**
453 * Returns <code>true</code> if the rectangle described by the
454 * arguments intersects with any of the polygons the receiver
455 * maintains to describe its area, and <code>false</code> otherwise.
456 *
457 * @param x the x coordinate of the origin of the rectangle
458 * @param y the y coordinate of the origin of the rectangle
459 * @param width the width of the rectangle
460 * @param height the height of the rectangle
461 * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
462 *
463 * @exception DWTException <ul>
464 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
465 * </ul>
466 *
467 * @see Rectangle#intersects(Rectangle)
468 */
469 public bool intersects (int x, int y, int width, int height) {
470 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
471 short[] r = new short[4];
472 OS.SetRect(r, (short)x, (short)y, (short)(x + width),(short)(y + height));
473 return OS.RectInRgn(rect, handle);
474 }
475
476 /**
477 * Returns <code>true</code> if the given rectangle intersects
478 * with any of the polygons the receiver maintains to describe
479 * its area and <code>false</code> otherwise.
480 *
481 * @param rect the rectangle to test for intersection
482 * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
483 *
484 * @exception IllegalArgumentException <ul>
485 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
486 * </ul>
487 * @exception DWTException <ul>
488 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
489 * </ul>
490 *
491 * @see Rectangle#intersects(Rectangle)
492 */
493 public bool intersects(Rectangle rect) {
494 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
495 return intersects(rect.x, rect.y, rect.width, rect.height);
496 }
497
498 /**
499 * Returns <code>true</code> if the region has been disposed,
500 * and <code>false</code> otherwise.
501 * <p>
502 * This method gets the dispose state for the region.
503 * When a region has been disposed, it is an error to
504 * invoke any other method using the region.
505 *
506 * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
507 */
508 public bool isDisposed() {
509 return handle is 0;
510 }
511
512 /**
513 * Returns <code>true</code> if the receiver does not cover any
514 * area in the (x, y) coordinate plane, and <code>false</code> if
515 * the receiver does cover some area in the plane.
516 *
517 * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise
518 *
519 * @exception DWTException <ul>
520 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
521 * </ul>
522 */
523 public bool isEmpty() {
524 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
525 return OS.EmptyRgn(handle);
526 }
527
528 /**
529 * Subtracts the given polygon from the collection of polygons
530 * the receiver maintains to describe its area.
531 *
532 * @param pointArray points that describe the polygon to merge with the receiver
533 *
534 * @exception IllegalArgumentException <ul>
535 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
536 * </ul>
537 * @exception DWTException <ul>
538 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
539 * </ul>
540 *
541 * @since 3.0
542 */
543 public void subtract (int[] pointArray) {
544 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
545 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
546 if (pointArray.length < 2) return;
547 int polyRgn = OS.NewRgn();
548 OS.OpenRgn();
549 OS.MoveTo((short)pointArray[0], (short)pointArray[1]);
550 for (int i = 1; i < pointArray.length / 2; i++) {
551 OS.LineTo((short)pointArray[2 * i], (short)pointArray[2 * i + 1]);
552 }
553 OS.LineTo((short)pointArray[0], (short)pointArray[1]);
554 OS.CloseRgn(polyRgn);
555 OS.DiffRgn(handle, polyRgn, handle);
556 OS.DisposeRgn(polyRgn);
557 }
558
559 /**
560 * Subtracts the given rectangle from the collection of polygons
561 * the receiver maintains to describe its area.
562 *
563 * @param rect the rectangle to subtract from the receiver
564 *
565 * @exception IllegalArgumentException <ul>
566 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
567 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
568 * </ul>
569 * @exception DWTException <ul>
570 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
571 * </ul>
572 *
573 * @since 3.0
574 */
575 public void subtract(Rectangle rect) {
576 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
577 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
578 subtract (rect.x, rect.y, rect.width, rect.height);
579 }
580
581 /**
582 * Subtracts the given rectangle from the collection of polygons
583 * the receiver maintains to describe its area.
584 *
585 * @param x the x coordinate of the rectangle
586 * @param y the y coordinate of the rectangle
587 * @param width the width coordinate of the rectangle
588 * @param height the height coordinate of the rectangle
589 *
590 * @exception IllegalArgumentException <ul>
591 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
592 * </ul>
593 * @exception DWTException <ul>
594 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
595 * </ul>
596 *
597 * @since 3.1
598 */
599 public void subtract(int x, int y, int width, int height) {
600 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
601 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
602 int rectRgn = OS.NewRgn();
603 short[] r = new short[4];
604 OS.SetRect(r, (short)x, (short)y, (short)(x + width),(short)(y + height));
605 OS.RectRgn(rectRgn, r);
606 OS.DiffRgn(handle, rectRgn, handle);
607 OS.DisposeRgn(rectRgn);
608 }
609
610 /**
611 * Subtracts all of the polygons which make up the area covered
612 * by the argument from the collection of polygons the receiver
613 * maintains to describe its area.
614 *
615 * @param region the region to subtract
616 *
617 * @exception IllegalArgumentException <ul>
618 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
619 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
620 * </ul>
621 * @exception DWTException <ul>
622 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
623 * </ul>
624 *
625 * @since 3.0
626 */
627 public void subtract(Region region) {
628 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
629 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
630 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
631 OS.DiffRgn(handle, region.handle, handle);
632 }
633
634 /**
635 * Translate all of the polygons the receiver maintains to describe
636 * its area by the specified point.
637 *
638 * @param x the x coordinate of the point to translate
639 * @param y the y coordinate of the point to translate
640 *
641 * @exception DWTException <ul>
642 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
643 * </ul>
644 *
645 * @since 3.1
646 */
647 public void translate (int x, int y) {
648 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
649 OS.OffsetRgn (handle, (short)x, (short)y);
650 }
651
652 /**
653 * Translate all of the polygons the receiver maintains to describe
654 * its area by the specified point.
655 *
656 * @param pt the point to translate
657 *
658 * @exception IllegalArgumentException <ul>
659 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
660 * </ul>
661 * @exception DWTException <ul>
662 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
663 * </ul>
664 *
665 * @since 3.1
666 */
667 public void translate (Point pt) {
668 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
669 if (pt is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
670 translate (pt.x, pt.y);
671 }
672
673 /**
674 * Returns a string containing a concise, human-readable
675 * description of the receiver.
676 *
677 * @return a string representation of the receiver
678 */
679 public String toString () {
680 if (isDisposed()) return "Region {*DISPOSED*}";
681 return "Region {" + handle + "}";
682 }
683 }