Mercurial > projects > dwt-win
annotate dwt/graphics/Region.d @ 48:9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Feb 2008 01:14:54 +0100 |
parents | f5482da87ed8 |
children | f353be82b6be |
rev | line source |
---|---|
20 | 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 | |
23 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
20 | 12 *******************************************************************************/ |
13 module dwt.graphics.Region; | |
14 | |
15 | |
16 import dwt.DWT; | |
17 import dwt.DWTError; | |
18 import dwt.DWTException; | |
19 import dwt.internal.win32.OS; | |
20 | |
21 import dwt.graphics.Resource; | |
22 import dwt.graphics.Point; | |
23 import dwt.graphics.Rectangle; | |
24 import dwt.graphics.Device; | |
25 | |
26 import tango.text.convert.Format; | |
27 | |
28 /** | |
29 * Instances of this class represent areas of an x-y coordinate | |
30 * system that are aggregates of the areas covered by a number | |
31 * of polygons. | |
32 * <p> | |
33 * Application code must explicitly invoke the <code>Region.dispose()</code> | |
34 * method to release the operating system resources managed by each instance | |
35 * when those instances are no longer required. | |
36 * </p> | |
37 */ | |
38 | |
39 public final class Region : Resource { | |
40 | |
41 /** | |
42 * the OS resource for the region | |
43 * (Warning: This field is platform dependent) | |
44 * <p> | |
45 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT | |
46 * public API. It is marked public only so that it can be shared | |
47 * within the packages provided by DWT. It is not available on all | |
48 * platforms and should never be accessed from application code. | |
49 * </p> | |
50 */ | |
51 public HRGN handle; | |
52 | |
53 /** | |
54 * Constructs a new empty region. | |
55 * | |
56 * @exception DWTError <ul> | |
57 * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li> | |
58 * </ul> | |
59 */ | |
60 public this () { | |
61 this(null); | |
62 } | |
63 | |
64 /** | |
65 * Constructs a new empty region. | |
66 * <p> | |
67 * You must dispose the region when it is no longer required. | |
68 * </p> | |
69 * | |
70 * @param device the device on which to allocate the region | |
71 * | |
72 * @exception IllegalArgumentException <ul> | |
73 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> | |
74 * </ul> | |
75 * @exception DWTError <ul> | |
76 * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li> | |
77 * </ul> | |
78 * | |
79 * @see #dispose | |
80 * | |
81 * @since 3.0 | |
82 */ | |
83 public this (Device device) { | |
84 if (device is null) device = Device.getDevice(); | |
85 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
86 this.device = device; | |
87 handle = OS.CreateRectRgn (0, 0, 0, 0); | |
88 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
89 if (device.tracking) device.new_Object(this); | |
90 } | |
91 | |
92 /** | |
93 * Constructs a new region given a handle to the operating | |
94 * system resources that it should represent. | |
95 * | |
96 * @param handle the handle for the result | |
97 */ | |
98 this(Device device, HRGN handle) { | |
99 this.device = device; | |
100 this.handle = handle; | |
101 } | |
102 | |
103 /** | |
104 * Adds the given polygon to the collection of polygons | |
105 * the receiver maintains to describe its area. | |
106 * | |
107 * @param pointArray points that describe the polygon to merge with the receiver | |
108 * | |
109 * @exception IllegalArgumentException <ul> | |
110 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
111 * </ul> | |
112 * @exception DWTException <ul> | |
113 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
114 * </ul> | |
115 * | |
116 * @since 3.0 | |
117 * | |
118 */ | |
119 public void add (int[] pointArray) { | |
120 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
121 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
122 if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); | |
123 auto polyRgn = OS.CreatePolygonRgn(cast(POINT*)pointArray.ptr, pointArray.length / 2, OS.ALTERNATE); | |
124 OS.CombineRgn (handle, handle, polyRgn, OS.RGN_OR); | |
125 OS.DeleteObject (polyRgn); | |
126 } | |
127 | |
128 /** | |
129 * Adds the given rectangle to the collection of polygons | |
130 * the receiver maintains to describe its area. | |
131 * | |
132 * @param rect the rectangle to merge with the receiver | |
133 * | |
134 * @exception IllegalArgumentException <ul> | |
135 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
136 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> | |
137 * </ul> | |
138 * @exception DWTException <ul> | |
139 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
140 * </ul> | |
141 */ | |
142 public void add (Rectangle rect) { | |
143 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
144 if (rect is null) DWT.error(DWT.ERROR_NULL_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 auto rectRgn = OS.CreateRectRgn (x, y, x + width, y + height); | |
170 OS.CombineRgn (handle, handle, rectRgn, OS.RGN_OR); | |
171 OS.DeleteObject (rectRgn); | |
172 } | |
173 | |
174 /** | |
175 * Adds all of the polygons which make up the area covered | |
176 * by the argument to the collection of polygons the receiver | |
177 * maintains to describe its area. | |
178 * | |
179 * @param region the region to merge | |
180 * | |
181 * @exception IllegalArgumentException <ul> | |
182 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
183 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
184 * </ul> | |
185 * @exception DWTException <ul> | |
186 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
187 * </ul> | |
188 */ | |
189 public void add (Region region) { | |
190 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
191 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
192 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
193 OS.CombineRgn (handle, handle, region.handle, OS.RGN_OR); | |
194 } | |
195 | |
196 /** | |
197 * Returns <code>true</code> if the point specified by the | |
198 * arguments is inside the area specified by the receiver, | |
199 * and <code>false</code> otherwise. | |
200 * | |
201 * @param x the x coordinate of the point to test for containment | |
202 * @param y the y coordinate of the point to test for containment | |
203 * @return <code>true</code> if the region contains the point and <code>false</code> otherwise | |
204 * | |
205 * @exception DWTException <ul> | |
206 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
207 * </ul> | |
208 */ | |
209 public bool contains (int x, int y) { | |
210 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
211 return cast(bool) OS.PtInRegion (handle, x, y); | |
212 } | |
213 | |
214 /** | |
215 * Returns <code>true</code> if the given point is inside the | |
216 * area specified by the receiver, and <code>false</code> | |
217 * otherwise. | |
218 * | |
219 * @param pt the point to test for containment | |
220 * @return <code>true</code> if the region contains the point and <code>false</code> otherwise | |
221 * | |
222 * @exception IllegalArgumentException <ul> | |
223 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
224 * </ul> | |
225 * @exception DWTException <ul> | |
226 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
227 * </ul> | |
228 */ | |
229 public bool contains (Point pt) { | |
230 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
231 if (pt is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
232 return contains(pt.x, pt.y); | |
233 } | |
234 | |
235 /** | |
236 * Disposes of the operating system resources associated with | |
237 * the region. Applications must dispose of all regions which | |
238 * they allocate. | |
239 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
240 override public void dispose () { |
20 | 241 if (handle is null) return; |
242 if (device.isDisposed()) return; | |
243 OS.DeleteObject(handle); | |
244 handle = null; | |
245 if (device.tracking) device.dispose_Object(this); | |
246 device = null; | |
247 } | |
248 | |
249 /** | |
250 * Compares the argument to the receiver, and returns true | |
251 * if they represent the <em>same</em> object using a class | |
252 * specific comparison. | |
253 * | |
254 * @param object the object to compare with this object | |
255 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
256 * | |
257 * @see #hashCode | |
258 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
259 override public int opEquals (Object object) { |
20 | 260 if (this is object) return true; |
261 if (!(cast(Region)object)) return false; | |
262 Region rgn = cast(Region)object; | |
263 return handle is rgn.handle; | |
264 } | |
265 | |
266 /** | |
267 * Returns a rectangle which represents the rectangular | |
268 * union of the collection of polygons the receiver | |
269 * maintains to describe its area. | |
270 * | |
271 * @return a bounding rectangle for the region | |
272 * | |
273 * @exception DWTException <ul> | |
274 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
275 * </ul> | |
276 * | |
277 * @see Rectangle#union | |
278 */ | |
279 public Rectangle getBounds() { | |
280 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
281 RECT rect; | |
282 OS.GetRgnBox(handle, &rect); | |
283 return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); | |
284 } | |
285 | |
286 /** | |
287 * Returns an integer hash code for the receiver. Any two | |
288 * objects that return <code>true</code> when passed to | |
289 * <code>equals</code> must return the same value for this | |
290 * method. | |
291 * | |
292 * @return the receiver's hash | |
293 * | |
294 * @see #equals | |
295 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
296 override public hash_t toHash () { |
20 | 297 return cast(hash_t)handle; |
298 } | |
299 | |
300 /** | |
301 * Intersects the given rectangle to the collection of polygons | |
302 * the receiver maintains to describe its area. | |
303 * | |
304 * @param rect the rectangle to intersect with the receiver | |
305 * | |
306 * @exception IllegalArgumentException <ul> | |
307 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
308 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> | |
309 * </ul> | |
310 * @exception DWTException <ul> | |
311 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
312 * </ul> | |
313 * | |
314 * @since 3.0 | |
315 */ | |
316 public void intersect (Rectangle rect) { | |
317 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
318 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
319 intersect (rect.x, rect.y, rect.width, rect.height); | |
320 } | |
321 | |
322 /** | |
323 * Intersects the given rectangle to the collection of polygons | |
324 * the receiver maintains to describe its area. | |
325 * | |
326 * @param x the x coordinate of the rectangle | |
327 * @param y the y coordinate of the rectangle | |
328 * @param width the width coordinate of the rectangle | |
329 * @param height the height coordinate of the rectangle | |
330 * | |
331 * @exception IllegalArgumentException <ul> | |
332 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> | |
333 * </ul> | |
334 * @exception DWTException <ul> | |
335 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
336 * </ul> | |
337 * | |
338 * @since 3.1 | |
339 */ | |
340 public void intersect (int x, int y, int width, int height) { | |
341 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
342 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
343 auto rectRgn = OS.CreateRectRgn (x, y, x + width, y + height); | |
344 OS.CombineRgn (handle, handle, rectRgn, OS.RGN_AND); | |
345 OS.DeleteObject (rectRgn); | |
346 } | |
347 | |
348 /** | |
349 * Intersects all of the polygons which make up the area covered | |
350 * by the argument to the collection of polygons the receiver | |
351 * maintains to describe its area. | |
352 * | |
353 * @param region the region to intersect | |
354 * | |
355 * @exception IllegalArgumentException <ul> | |
356 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
357 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
358 * </ul> | |
359 * @exception DWTException <ul> | |
360 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
361 * </ul> | |
362 * | |
363 * @since 3.0 | |
364 */ | |
365 public void intersect (Region region) { | |
366 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
367 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
368 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
369 OS.CombineRgn (handle, handle, region.handle, OS.RGN_AND); | |
370 } | |
371 | |
372 /** | |
373 * Returns <code>true</code> if the rectangle described by the | |
374 * arguments intersects with any of the polygons the receiver | |
375 * maintains to describe its area, and <code>false</code> otherwise. | |
376 * | |
377 * @param x the x coordinate of the origin of the rectangle | |
378 * @param y the y coordinate of the origin of the rectangle | |
379 * @param width the width of the rectangle | |
380 * @param height the height of the rectangle | |
381 * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise | |
382 * | |
383 * @exception DWTException <ul> | |
384 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
385 * </ul> | |
386 * | |
387 * @see Rectangle#intersects(Rectangle) | |
388 */ | |
389 public bool intersects (int x, int y, int width, int height) { | |
390 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
391 RECT r; | |
392 OS.SetRect (&r, x, y, x + width, y + height); | |
393 return cast(bool) OS.RectInRegion (handle, &r); | |
394 } | |
395 | |
396 /** | |
397 * Returns <code>true</code> if the given rectangle intersects | |
398 * with any of the polygons the receiver maintains to describe | |
399 * its area and <code>false</code> otherwise. | |
400 * | |
401 * @param rect the rectangle to test for intersection | |
402 * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise | |
403 * | |
404 * @exception IllegalArgumentException <ul> | |
405 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
406 * </ul> | |
407 * @exception DWTException <ul> | |
408 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
409 * </ul> | |
410 * | |
411 * @see Rectangle#intersects(Rectangle) | |
412 */ | |
413 public bool intersects (Rectangle rect) { | |
414 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
415 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
416 return intersects(rect.x, rect.y, rect.width, rect.height); | |
417 } | |
418 | |
419 /** | |
420 * Returns <code>true</code> if the region has been disposed, | |
421 * and <code>false</code> otherwise. | |
422 * <p> | |
423 * This method gets the dispose state for the region. | |
424 * When a region has been disposed, it is an error to | |
425 * invoke any other method using the region. | |
426 * | |
427 * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise | |
428 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
429 override public bool isDisposed() { |
20 | 430 return handle is null; |
431 } | |
432 | |
433 /** | |
434 * Returns <code>true</code> if the receiver does not cover any | |
435 * area in the (x, y) coordinate plane, and <code>false</code> if | |
436 * the receiver does cover some area in the plane. | |
437 * | |
438 * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise | |
439 * | |
440 * @exception DWTException <ul> | |
441 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
442 * </ul> | |
443 */ | |
444 public bool isEmpty () { | |
445 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
446 RECT rect; | |
447 auto result = OS.GetRgnBox (handle, &rect); | |
448 if (result is OS.NULLREGION) return true; | |
449 return ((rect.right - rect.left) <= 0) || ((rect.bottom - rect.top) <= 0); | |
450 } | |
451 | |
452 /** | |
453 * Subtracts the given polygon from the collection of polygons | |
454 * the receiver maintains to describe its area. | |
455 * | |
456 * @param pointArray points that describe the polygon to merge with the receiver | |
457 * | |
458 * @exception IllegalArgumentException <ul> | |
459 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
460 * </ul> | |
461 * @exception DWTException <ul> | |
462 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
463 * </ul> | |
464 * | |
465 * @since 3.0 | |
466 */ | |
467 public void subtract (int[] pointArray) { | |
468 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
469 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
470 if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); | |
471 auto polyRgn = OS.CreatePolygonRgn(cast(POINT*)pointArray.ptr, pointArray.length / 2, OS.ALTERNATE); | |
472 OS.CombineRgn (handle, handle, polyRgn, OS.RGN_DIFF); | |
473 OS.DeleteObject (polyRgn); | |
474 } | |
475 | |
476 /** | |
477 * Subtracts the given rectangle from the collection of polygons | |
478 * the receiver maintains to describe its area. | |
479 * | |
480 * @param rect the rectangle to subtract from the receiver | |
481 * | |
482 * @exception IllegalArgumentException <ul> | |
483 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
484 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> | |
485 * </ul> | |
486 * @exception DWTException <ul> | |
487 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
488 * </ul> | |
489 * | |
490 * @since 3.0 | |
491 */ | |
492 public void subtract (Rectangle rect) { | |
493 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
494 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
495 subtract (rect.x, rect.y, rect.width, rect.height); | |
496 } | |
497 | |
498 /** | |
499 * Subtracts the given rectangle from the collection of polygons | |
500 * the receiver maintains to describe its area. | |
501 * | |
502 * @param x the x coordinate of the rectangle | |
503 * @param y the y coordinate of the rectangle | |
504 * @param width the width coordinate of the rectangle | |
505 * @param height the height coordinate of the rectangle | |
506 * | |
507 * @exception IllegalArgumentException <ul> | |
508 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> | |
509 * </ul> | |
510 * @exception DWTException <ul> | |
511 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
512 * </ul> | |
513 * | |
514 * @since 3.1 | |
515 */ | |
516 public void subtract (int x, int y, int width, int height) { | |
517 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
518 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
519 auto rectRgn = OS.CreateRectRgn (x, y, x + width, y + height); | |
520 OS.CombineRgn (handle, handle, rectRgn, OS.RGN_DIFF); | |
521 OS.DeleteObject (rectRgn); | |
522 } | |
523 | |
524 /** | |
525 * Subtracts all of the polygons which make up the area covered | |
526 * by the argument from the collection of polygons the receiver | |
527 * maintains to describe its area. | |
528 * | |
529 * @param region the region to subtract | |
530 * | |
531 * @exception IllegalArgumentException <ul> | |
532 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
533 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
534 * </ul> | |
535 * @exception DWTException <ul> | |
536 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
537 * </ul> | |
538 * | |
539 * @since 3.0 | |
540 */ | |
541 public void subtract (Region region) { | |
542 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
543 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
544 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
545 OS.CombineRgn (handle, handle, region.handle, OS.RGN_DIFF); | |
546 } | |
547 | |
548 /** | |
549 * Translate all of the polygons the receiver maintains to describe | |
550 * its area by the specified point. | |
551 * | |
552 * @param x the x coordinate of the point to translate | |
553 * @param y the y coordinate of the point to translate | |
554 * | |
555 * @exception DWTException <ul> | |
556 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
557 * </ul> | |
558 * | |
559 * @since 3.1 | |
560 */ | |
561 public void translate (int x, int y) { | |
562 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
563 OS.OffsetRgn (handle, x, y); | |
564 } | |
565 | |
566 /** | |
567 * Translate all of the polygons the receiver maintains to describe | |
568 * its area by the specified point. | |
569 * | |
570 * @param pt the point to translate | |
571 * | |
572 * @exception IllegalArgumentException <ul> | |
573 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
574 * </ul> | |
575 * @exception DWTException <ul> | |
576 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
577 * </ul> | |
578 * | |
579 * @since 3.1 | |
580 */ | |
581 public void translate (Point pt) { | |
582 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
583 if (pt is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
584 translate (pt.x, pt.y); | |
585 } | |
586 | |
587 /** | |
588 * Returns a string containing a concise, human-readable | |
589 * description of the receiver. | |
590 * | |
591 * @return a string representation of the receiver | |
592 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
593 override public char[] toString () { |
20 | 594 if (isDisposed()) return "Region {*DISPOSED*}"; |
595 return Format( "Region {{{}}", handle ); | |
596 } | |
597 | |
598 /** | |
599 * Invokes platform specific functionality to allocate a new region. | |
600 * <p> | |
601 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
602 * API for <code>Region</code>. It is marked public only so that it | |
603 * can be shared within the packages provided by DWT. It is not | |
604 * available on all platforms, and should never be called from | |
605 * application code. | |
606 * </p> | |
607 * | |
608 * @param device the device on which to allocate the region | |
609 * @param handle the handle for the region | |
610 * @return a new region object containing the specified device and handle | |
611 */ | |
612 public static Region win32_new(Device device, HRGN handle) { | |
613 return new Region(device, handle); | |
614 } | |
615 | |
616 } |