Mercurial > projects > dwt-linux
comparison dwt/graphics/Cursor.d @ 240:ce446666f5a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 12 May 2008 19:13:01 +0200 |
parents | 380bad9f6852 |
children | c0d810de7093 |
comparison
equal
deleted
inserted
replaced
239:06a1f6829310 | 240:ce446666f5a2 |
---|---|
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; | 91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; |
92 | 92 |
93 this () { | 93 this (Device device) { |
94 super(device); | |
94 } | 95 } |
95 | 96 |
96 /** | 97 /** |
97 * Constructs a new cursor given a device and a style | 98 * Constructs a new cursor given a device and a style |
98 * constant describing the desired cursor appearance. | 99 * constant describing the desired cursor appearance. |
133 * @see DWT#CURSOR_IBEAM | 134 * @see DWT#CURSOR_IBEAM |
134 * @see DWT#CURSOR_NO | 135 * @see DWT#CURSOR_NO |
135 * @see DWT#CURSOR_HAND | 136 * @see DWT#CURSOR_HAND |
136 */ | 137 */ |
137 public this(Device device, int style) { | 138 public this(Device device, int style) { |
138 if (device is null) device = Device.getDevice(); | 139 super(device); |
139 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
140 this.device = device; | |
141 int shape = 0; | 140 int shape = 0; |
142 switch (style) { | 141 switch (style) { |
143 case DWT.CURSOR_APPSTARTING: break; | 142 case DWT.CURSOR_APPSTARTING: break; |
144 case DWT.CURSOR_ARROW: shape = OS.GDK_LEFT_PTR; break; | 143 case DWT.CURSOR_ARROW: shape = OS.GDK_LEFT_PTR; break; |
145 case DWT.CURSOR_WAIT: shape = OS.GDK_WATCH; break; | 144 case DWT.CURSOR_WAIT: shape = OS.GDK_WATCH; break; |
169 handle = createCursor(APPSTARTING_SRC, APPSTARTING_MASK, 32, 32, 2, 2, true); | 168 handle = createCursor(APPSTARTING_SRC, APPSTARTING_MASK, 32, 32, 2, 2, true); |
170 } else { | 169 } else { |
171 handle = OS.gdk_cursor_new(shape); | 170 handle = OS.gdk_cursor_new(shape); |
172 } | 171 } |
173 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); | 172 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); |
174 if (device.tracking) device.new_Object(this); | 173 init_(); |
175 } | 174 } |
176 | 175 |
177 /** | 176 /** |
178 * Constructs a new cursor given a device, image and mask | 177 * Constructs a new cursor given a device, image and mask |
179 * data describing the desired cursor appearance, and the x | 178 * data describing the desired cursor appearance, and the x |
204 * @exception DWTError <ul> | 203 * @exception DWTError <ul> |
205 * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> | 204 * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> |
206 * </ul> | 205 * </ul> |
207 */ | 206 */ |
208 public this(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) { | 207 public this(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) { |
209 if (device is null) device = Device.getDevice(); | 208 super(device); |
210 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
211 this.device = device; | |
212 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 209 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
213 if (mask is null) { | 210 if (mask is null) { |
214 if (!(source.getTransparencyType() is DWT.TRANSPARENCY_MASK)) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 211 if (!(source.getTransparencyType() is DWT.TRANSPARENCY_MASK)) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
215 mask = source.getTransparencyMask(); | 212 mask = source.getTransparencyMask(); |
216 } | 213 } |
258 maskData[i] = cast(byte) ~maskData[i]; | 255 maskData[i] = cast(byte) ~maskData[i]; |
259 } | 256 } |
260 maskData = ImageData.convertPad(maskData, mask.width, mask.height, mask.depth, mask.scanlinePad, 1); | 257 maskData = ImageData.convertPad(maskData, mask.width, mask.height, mask.depth, mask.scanlinePad, 1); |
261 handle = createCursor(maskData, sourceData, source.width, source.height, hotspotX, hotspotY, true); | 258 handle = createCursor(maskData, sourceData, source.width, source.height, hotspotX, hotspotY, true); |
262 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); | 259 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); |
263 if (device.tracking) device.new_Object(this); | 260 init_(); |
264 } | 261 } |
265 | 262 |
266 /** | 263 /** |
267 * Constructs a new cursor given a device, image data describing | 264 * Constructs a new cursor given a device, image data describing |
268 * the desired cursor appearance, and the x and y coordinates of | 265 * the desired cursor appearance, and the x and y coordinates of |
289 * </ul> | 286 * </ul> |
290 * | 287 * |
291 * @since 3.0 | 288 * @since 3.0 |
292 */ | 289 */ |
293 public this(Device device, ImageData source, int hotspotX, int hotspotY) { | 290 public this(Device device, ImageData source, int hotspotX, int hotspotY) { |
294 if (device is null) device = Device.getDevice(); | 291 super(device); |
295 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
296 this.device = device; | |
297 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 292 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
298 if (hotspotX >= source.width || hotspotX < 0 || | 293 if (hotspotX >= source.width || hotspotX < 0 || |
299 hotspotY >= source.height || hotspotY < 0) { | 294 hotspotY >= source.height || hotspotY < 0) { |
300 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 295 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
301 } | 296 } |
436 } | 431 } |
437 maskData = ImageData.convertPad(maskData, mask.width, mask.height, mask.depth, mask.scanlinePad, 1); | 432 maskData = ImageData.convertPad(maskData, mask.width, mask.height, mask.depth, mask.scanlinePad, 1); |
438 handle = createCursor(sourceData, maskData, source.width, source.height, hotspotX, hotspotY, false); | 433 handle = createCursor(sourceData, maskData, source.width, source.height, hotspotX, hotspotY, false); |
439 } | 434 } |
440 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); | 435 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); |
441 if (device.tracking) device.new_Object(this); | 436 init_(); |
442 } | 437 } |
443 | 438 |
444 GdkCursor* createCursor(byte[] sourceData, byte[] maskData, int width, int height, int hotspotX, int hotspotY, bool reverse) { | 439 GdkCursor* createCursor(byte[] sourceData, byte[] maskData, int width, int height, int hotspotX, int hotspotY, bool reverse) { |
445 auto sourcePixmap = OS.gdk_bitmap_create_from_data(null, cast(char*)sourceData.ptr, width, height); | 440 auto sourcePixmap = OS.gdk_bitmap_create_from_data(null, cast(char*)sourceData.ptr, width, height); |
446 auto maskPixmap = OS.gdk_bitmap_create_from_data(null, cast(char*)maskData.ptr, width, height); | 441 auto maskPixmap = OS.gdk_bitmap_create_from_data(null, cast(char*)maskData.ptr, width, height); |
455 if (sourcePixmap !is null) OS.g_object_unref (sourcePixmap); | 450 if (sourcePixmap !is null) OS.g_object_unref (sourcePixmap); |
456 if (maskPixmap !is null) OS.g_object_unref (maskPixmap); | 451 if (maskPixmap !is null) OS.g_object_unref (maskPixmap); |
457 return cursor; | 452 return cursor; |
458 } | 453 } |
459 | 454 |
460 /** | 455 void destroy() { |
461 * Disposes of the operating system resources associated with | |
462 * the cursor. Applications must dispose of all cursors which | |
463 * they allocate. | |
464 */ | |
465 public override void dispose() { | |
466 if (handle is null) return; | |
467 if (device.isDisposed()) return; | |
468 OS.gdk_cursor_destroy(handle); | 456 OS.gdk_cursor_destroy(handle); |
469 handle = null; | 457 handle = null; |
470 if (device.tracking) device.dispose_Object(this); | |
471 device = null; | |
472 } | 458 } |
473 | 459 |
474 /** | 460 /** |
475 * Compares the argument to the receiver, and returns true | 461 * Compares the argument to the receiver, and returns true |
476 * if they represent the <em>same</em> object using a class | 462 * if they represent the <em>same</em> object using a class |
503 * @param handle the handle for the cursor | 489 * @param handle the handle for the cursor |
504 * | 490 * |
505 * @private | 491 * @private |
506 */ | 492 */ |
507 public static Cursor gtk_new(Device device, GdkCursor* handle) { | 493 public static Cursor gtk_new(Device device, GdkCursor* handle) { |
508 if (device is null) device = Device.getDevice(); | 494 Cursor cursor = new Cursor(device); |
509 Cursor cursor = new Cursor(); | |
510 cursor.handle = handle; | 495 cursor.handle = handle; |
511 cursor.device = device; | |
512 return cursor; | 496 return cursor; |
513 } | 497 } |
514 | 498 |
515 /** | 499 /** |
516 * Returns an integer hash code for the receiver. Any two | 500 * Returns an integer hash code for the receiver. Any two |