Mercurial > projects > dwt-win
annotate dwt/graphics/Region.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | ab60f3309436 |
children | fd9c62a2998e |
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 { | |
213 | 41 alias Resource.init_ init_; |
20 | 42 |
43 /** | |
44 * the OS resource for the region | |
45 * (Warning: This field is platform dependent) | |
46 * <p> | |
47 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT | |
48 * public API. It is marked public only so that it can be shared | |
49 * within the packages provided by DWT. It is not available on all | |
50 * platforms and should never be accessed from application code. | |
51 * </p> | |
52 */ | |
53 public HRGN handle; | |
54 | |
55 /** | |
56 * Constructs a new empty region. | |
57 * | |
58 * @exception DWTError <ul> | |
59 * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li> | |
60 * </ul> | |
61 */ | |
62 public this () { | |
63 this(null); | |
64 } | |
65 | |
66 /** | |
67 * Constructs a new empty region. | |
68 * <p> | |
69 * You must dispose the region when it is no longer required. | |
70 * </p> | |
71 * | |
72 * @param device the device on which to allocate the region | |
73 * | |
74 * @exception IllegalArgumentException <ul> | |
75 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> | |
76 * </ul> | |
77 * @exception DWTError <ul> | |
78 * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li> | |
79 * </ul> | |
80 * | |
81 * @see #dispose | |
82 * | |
83 * @since 3.0 | |
84 */ | |
85 public this (Device device) { | |
213 | 86 super(device); |
20 | 87 handle = OS.CreateRectRgn (0, 0, 0, 0); |
88 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
213 | 89 init_(); |
20 | 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) { | |
213 | 99 super(device); |
20 | 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); | |
117 | 122 static if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); |
20 | 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 | |
213 | 235 void destroy () { |
20 | 236 OS.DeleteObject(handle); |
237 handle = null; | |
238 } | |
239 | |
240 /** | |
241 * Compares the argument to the receiver, and returns true | |
242 * if they represent the <em>same</em> object using a class | |
243 * specific comparison. | |
244 * | |
245 * @param object the object to compare with this object | |
246 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
247 * | |
248 * @see #hashCode | |
249 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
250 override public int opEquals (Object object) { |
20 | 251 if (this is object) return true; |
252 if (!(cast(Region)object)) return false; | |
253 Region rgn = cast(Region)object; | |
254 return handle is rgn.handle; | |
255 } | |
256 | |
257 /** | |
258 * Returns a rectangle which represents the rectangular | |
259 * union of the collection of polygons the receiver | |
260 * maintains to describe its area. | |
261 * | |
262 * @return a bounding rectangle for the region | |
263 * | |
264 * @exception DWTException <ul> | |
265 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
266 * </ul> | |
267 * | |
268 * @see Rectangle#union | |
269 */ | |
270 public Rectangle getBounds() { | |
271 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
272 RECT rect; | |
273 OS.GetRgnBox(handle, &rect); | |
274 return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); | |
275 } | |
276 | |
277 /** | |
278 * Returns an integer hash code for the receiver. Any two | |
279 * objects that return <code>true</code> when passed to | |
280 * <code>equals</code> must return the same value for this | |
281 * method. | |
282 * | |
283 * @return the receiver's hash | |
284 * | |
285 * @see #equals | |
286 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
287 override public hash_t toHash () { |
20 | 288 return cast(hash_t)handle; |
289 } | |
290 | |
291 /** | |
292 * Intersects the given rectangle to the collection of polygons | |
293 * the receiver maintains to describe its area. | |
294 * | |
295 * @param rect the rectangle to intersect with the receiver | |
296 * | |
297 * @exception IllegalArgumentException <ul> | |
298 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
299 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> | |
300 * </ul> | |
301 * @exception DWTException <ul> | |
302 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
303 * </ul> | |
304 * | |
305 * @since 3.0 | |
306 */ | |
307 public void intersect (Rectangle rect) { | |
308 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
309 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
310 intersect (rect.x, rect.y, rect.width, rect.height); | |
311 } | |
312 | |
313 /** | |
314 * Intersects the given rectangle to the collection of polygons | |
315 * the receiver maintains to describe its area. | |
316 * | |
317 * @param x the x coordinate of the rectangle | |
318 * @param y the y coordinate of the rectangle | |
319 * @param width the width coordinate of the rectangle | |
320 * @param height the height coordinate of the rectangle | |
321 * | |
322 * @exception IllegalArgumentException <ul> | |
323 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> | |
324 * </ul> | |
325 * @exception DWTException <ul> | |
326 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
327 * </ul> | |
328 * | |
329 * @since 3.1 | |
330 */ | |
331 public void intersect (int x, int y, int width, int height) { | |
332 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
333 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
334 auto rectRgn = OS.CreateRectRgn (x, y, x + width, y + height); | |
335 OS.CombineRgn (handle, handle, rectRgn, OS.RGN_AND); | |
336 OS.DeleteObject (rectRgn); | |
337 } | |
338 | |
339 /** | |
340 * Intersects all of the polygons which make up the area covered | |
341 * by the argument to the collection of polygons the receiver | |
342 * maintains to describe its area. | |
343 * | |
344 * @param region the region to intersect | |
345 * | |
346 * @exception IllegalArgumentException <ul> | |
347 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
348 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
349 * </ul> | |
350 * @exception DWTException <ul> | |
351 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
352 * </ul> | |
353 * | |
354 * @since 3.0 | |
355 */ | |
356 public void intersect (Region region) { | |
357 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
358 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
359 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
360 OS.CombineRgn (handle, handle, region.handle, OS.RGN_AND); | |
361 } | |
362 | |
363 /** | |
364 * Returns <code>true</code> if the rectangle described by the | |
365 * arguments intersects with any of the polygons the receiver | |
366 * maintains to describe its area, and <code>false</code> otherwise. | |
367 * | |
368 * @param x the x coordinate of the origin of the rectangle | |
369 * @param y the y coordinate of the origin of the rectangle | |
370 * @param width the width of the rectangle | |
371 * @param height the height of the rectangle | |
372 * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise | |
373 * | |
374 * @exception DWTException <ul> | |
375 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
376 * </ul> | |
377 * | |
378 * @see Rectangle#intersects(Rectangle) | |
379 */ | |
380 public bool intersects (int x, int y, int width, int height) { | |
381 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
382 RECT r; | |
383 OS.SetRect (&r, x, y, x + width, y + height); | |
384 return cast(bool) OS.RectInRegion (handle, &r); | |
385 } | |
386 | |
387 /** | |
388 * Returns <code>true</code> if the given rectangle intersects | |
389 * with any of the polygons the receiver maintains to describe | |
390 * its area and <code>false</code> otherwise. | |
391 * | |
392 * @param rect the rectangle to test for intersection | |
393 * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise | |
394 * | |
395 * @exception IllegalArgumentException <ul> | |
396 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
397 * </ul> | |
398 * @exception DWTException <ul> | |
399 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
400 * </ul> | |
401 * | |
402 * @see Rectangle#intersects(Rectangle) | |
403 */ | |
404 public bool intersects (Rectangle rect) { | |
405 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
406 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
407 return intersects(rect.x, rect.y, rect.width, rect.height); | |
408 } | |
409 | |
410 /** | |
411 * Returns <code>true</code> if the region has been disposed, | |
412 * and <code>false</code> otherwise. | |
413 * <p> | |
414 * This method gets the dispose state for the region. | |
415 * When a region has been disposed, it is an error to | |
416 * invoke any other method using the region. | |
417 * | |
418 * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise | |
419 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
420 override public bool isDisposed() { |
20 | 421 return handle is null; |
422 } | |
423 | |
424 /** | |
425 * Returns <code>true</code> if the receiver does not cover any | |
426 * area in the (x, y) coordinate plane, and <code>false</code> if | |
427 * the receiver does cover some area in the plane. | |
428 * | |
429 * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise | |
430 * | |
431 * @exception DWTException <ul> | |
432 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
433 * </ul> | |
434 */ | |
435 public bool isEmpty () { | |
436 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
437 RECT rect; | |
438 auto result = OS.GetRgnBox (handle, &rect); | |
439 if (result is OS.NULLREGION) return true; | |
440 return ((rect.right - rect.left) <= 0) || ((rect.bottom - rect.top) <= 0); | |
441 } | |
442 | |
443 /** | |
444 * Subtracts the given polygon from the collection of polygons | |
445 * the receiver maintains to describe its area. | |
446 * | |
447 * @param pointArray points that describe the polygon to merge with the receiver | |
448 * | |
449 * @exception IllegalArgumentException <ul> | |
450 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
451 * </ul> | |
452 * @exception DWTException <ul> | |
453 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
454 * </ul> | |
455 * | |
456 * @since 3.0 | |
457 */ | |
458 public void subtract (int[] pointArray) { | |
459 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
460 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
117 | 461 static if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); |
20 | 462 auto polyRgn = OS.CreatePolygonRgn(cast(POINT*)pointArray.ptr, pointArray.length / 2, OS.ALTERNATE); |
463 OS.CombineRgn (handle, handle, polyRgn, OS.RGN_DIFF); | |
464 OS.DeleteObject (polyRgn); | |
465 } | |
466 | |
467 /** | |
468 * Subtracts the given rectangle from the collection of polygons | |
469 * the receiver maintains to describe its area. | |
470 * | |
471 * @param rect the rectangle to subtract from the receiver | |
472 * | |
473 * @exception IllegalArgumentException <ul> | |
474 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
475 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> | |
476 * </ul> | |
477 * @exception DWTException <ul> | |
478 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
479 * </ul> | |
480 * | |
481 * @since 3.0 | |
482 */ | |
483 public void subtract (Rectangle rect) { | |
484 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
485 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
486 subtract (rect.x, rect.y, rect.width, rect.height); | |
487 } | |
488 | |
489 /** | |
490 * Subtracts the given rectangle from the collection of polygons | |
491 * the receiver maintains to describe its area. | |
492 * | |
493 * @param x the x coordinate of the rectangle | |
494 * @param y the y coordinate of the rectangle | |
495 * @param width the width coordinate of the rectangle | |
496 * @param height the height coordinate of the rectangle | |
497 * | |
498 * @exception IllegalArgumentException <ul> | |
499 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> | |
500 * </ul> | |
501 * @exception DWTException <ul> | |
502 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
503 * </ul> | |
504 * | |
505 * @since 3.1 | |
506 */ | |
507 public void subtract (int x, int y, int width, int height) { | |
508 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
509 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
510 auto rectRgn = OS.CreateRectRgn (x, y, x + width, y + height); | |
511 OS.CombineRgn (handle, handle, rectRgn, OS.RGN_DIFF); | |
512 OS.DeleteObject (rectRgn); | |
513 } | |
514 | |
515 /** | |
516 * Subtracts all of the polygons which make up the area covered | |
517 * by the argument from the collection of polygons the receiver | |
518 * maintains to describe its area. | |
519 * | |
520 * @param region the region to subtract | |
521 * | |
522 * @exception IllegalArgumentException <ul> | |
523 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
524 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
525 * </ul> | |
526 * @exception DWTException <ul> | |
527 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
528 * </ul> | |
529 * | |
530 * @since 3.0 | |
531 */ | |
532 public void subtract (Region region) { | |
533 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
534 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
535 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
536 OS.CombineRgn (handle, handle, region.handle, OS.RGN_DIFF); | |
537 } | |
538 | |
539 /** | |
540 * Translate all of the polygons the receiver maintains to describe | |
541 * its area by the specified point. | |
542 * | |
543 * @param x the x coordinate of the point to translate | |
544 * @param y the y coordinate of the point to translate | |
545 * | |
546 * @exception DWTException <ul> | |
547 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
548 * </ul> | |
549 * | |
550 * @since 3.1 | |
551 */ | |
552 public void translate (int x, int y) { | |
553 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
554 OS.OffsetRgn (handle, x, y); | |
555 } | |
556 | |
557 /** | |
558 * Translate all of the polygons the receiver maintains to describe | |
559 * its area by the specified point. | |
560 * | |
561 * @param pt the point to translate | |
562 * | |
563 * @exception IllegalArgumentException <ul> | |
564 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> | |
565 * </ul> | |
566 * @exception DWTException <ul> | |
567 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
568 * </ul> | |
569 * | |
570 * @since 3.1 | |
571 */ | |
572 public void translate (Point pt) { | |
573 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
574 if (pt is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
575 translate (pt.x, pt.y); | |
576 } | |
577 | |
578 /** | |
579 * Returns a string containing a concise, human-readable | |
580 * description of the receiver. | |
581 * | |
582 * @return a string representation of the receiver | |
583 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
117
diff
changeset
|
584 override public String toString () { |
20 | 585 if (isDisposed()) return "Region {*DISPOSED*}"; |
586 return Format( "Region {{{}}", handle ); | |
587 } | |
588 | |
589 /** | |
590 * Invokes platform specific functionality to allocate a new region. | |
591 * <p> | |
592 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
593 * API for <code>Region</code>. It is marked public only so that it | |
594 * can be shared within the packages provided by DWT. It is not | |
595 * available on all platforms, and should never be called from | |
596 * application code. | |
597 * </p> | |
598 * | |
599 * @param device the device on which to allocate the region | |
600 * @param handle the handle for the region | |
601 * @return a new region object containing the specified device and handle | |
602 */ | |
603 public static Region win32_new(Device device, HRGN handle) { | |
604 return new Region(device, handle); | |
605 } | |
606 | |
607 } |