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