Mercurial > projects > dwt-mac
comparison dwt/graphics/Cursor.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | 1a8b3cb347e0 |
children | a9ab4c738ed8 |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
198 for (int x = 0; x < source.width; x++) { | 198 for (int x = 0; x < source.width; x++) { |
199 int pixel = source.getPixel(x, y); | 199 int pixel = source.getPixel(x, y); |
200 int maskPixel = mask.getPixel(x, y); | 200 int maskPixel = mask.getPixel(x, y); |
201 if (pixel is 0 && maskPixel is 0) { | 201 if (pixel is 0 && maskPixel is 0) { |
202 // BLACK | 202 // BLACK |
203 data[offset] = (byte)0xFF; | 203 data[offset] = cast(byte)0xFF; |
204 } else if (pixel is 0 && maskPixel is 1) { | 204 } else if (pixel is 0 && maskPixel is 1) { |
205 // WHITE - cursor color | 205 // WHITE - cursor color |
206 data[offset] = data[offset + 1] = data[offset + 2] = data[offset + 3] = (byte)0xFF; | 206 data[offset] = data[offset + 1] = data[offset + 2] = data[offset + 3] = cast(byte)0xFF; |
207 } else if (pixel is 1 && maskPixel is 0) { | 207 } else if (pixel is 1 && maskPixel is 0) { |
208 // SCREEN | 208 // SCREEN |
209 } else { | 209 } else { |
210 /* | 210 /* |
211 * Feature in the Macintosh. It is not possible to have | 211 * Feature in the Macintosh. It is not possible to have |
220 createNSCursor(hotspotX, hotspotY, data, source.width, source.height); | 220 createNSCursor(hotspotX, hotspotY, data, source.width, source.height); |
221 init(); | 221 init(); |
222 } | 222 } |
223 | 223 |
224 void createNSCursor(int hotspotX, int hotspotY, byte[] buffer, int width, int height) { | 224 void createNSCursor(int hotspotX, int hotspotY, byte[] buffer, int width, int height) { |
225 NSImage nsImage = (NSImage)new NSImage().alloc(); | 225 NSImage nsImage = cast(NSImage)new NSImage().alloc(); |
226 NSBitmapImageRep nsImageRep = (NSBitmapImageRep)new NSBitmapImageRep().alloc(); | 226 NSBitmapImageRep nsImageRep = cast(NSBitmapImageRep)new NSBitmapImageRep().alloc(); |
227 handle = (NSCursor)new NSCursor().alloc(); | 227 handle = cast(NSCursor)new NSCursor().alloc(); |
228 NSSize size = new NSSize(); | 228 NSSize size = new NSSize(); |
229 size.width = width; | 229 size.width = width; |
230 size.height = height; | 230 size.height = height; |
231 nsImage = nsImage.initWithSize(size); | 231 nsImage = nsImage.initWithSize(size); |
232 nsImageRep = nsImageRep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_(0, width, height, | 232 nsImageRep = nsImageRep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_(0, width, height, |
291 byte[] srcGreens = new byte[length]; | 291 byte[] srcGreens = new byte[length]; |
292 byte[] srcBlues = new byte[length]; | 292 byte[] srcBlues = new byte[length]; |
293 for (int i = 0; i < rgbs.length; i++) { | 293 for (int i = 0; i < rgbs.length; i++) { |
294 RGB rgb = rgbs[i]; | 294 RGB rgb = rgbs[i]; |
295 if (rgb is null) continue; | 295 if (rgb is null) continue; |
296 srcReds[i] = (byte)rgb.red; | 296 srcReds[i] = cast(byte)rgb.red; |
297 srcGreens[i] = (byte)rgb.green; | 297 srcGreens[i] = cast(byte)rgb.green; |
298 srcBlues[i] = (byte)rgb.blue; | 298 srcBlues[i] = cast(byte)rgb.blue; |
299 } | 299 } |
300 ImageData.blit(ImageData.BLIT_SRC, | 300 ImageData.blit(ImageData.BLIT_SRC, |
301 source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, srcReds, srcGreens, srcBlues, | 301 source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, srcReds, srcGreens, srcBlues, |
302 ImageData.ALPHA_OPAQUE, null, 0, 0, 0, | 302 ImageData.ALPHA_OPAQUE, null, 0, 0, 0, |
303 data, 32, source.width * 4, ImageData.MSB_FIRST, 0, 0, source.width, source.height, 0xFF0000, 0xFF00, 0xFF, | 303 data, 32, source.width * 4, ImageData.MSB_FIRST, 0, 0, source.width, source.height, 0xFF0000, 0xFF00, 0xFF, |
308 byte[] maskData = mask.data; | 308 byte[] maskData = mask.data; |
309 int maskBpl = mask.bytesPerLine; | 309 int maskBpl = mask.bytesPerLine; |
310 int offset = 0, maskOffset = 0; | 310 int offset = 0, maskOffset = 0; |
311 for (int y = 0; y<source.height; y++) { | 311 for (int y = 0; y<source.height; y++) { |
312 for (int x = 0; x<source.width; x++) { | 312 for (int x = 0; x<source.width; x++) { |
313 data[offset] = ((maskData[maskOffset + (x >> 3)]) & (1 << (7 - (x & 0x7)))) !is 0 ? (byte)0xff : 0; | 313 data[offset] = ((maskData[maskOffset + (x >> 3)]) & (1 << (7 - (x & 0x7)))) !is 0 ? cast(byte)0xff : 0; |
314 offset += 4; | 314 offset += 4; |
315 } | 315 } |
316 maskOffset += maskBpl; | 316 maskOffset += maskBpl; |
317 } | 317 } |
318 } else if (source.alpha !is -1) { | 318 } else if (source.alpha !is -1) { |
319 byte alpha = (byte)source.alpha; | 319 byte alpha = cast(byte)source.alpha; |
320 for (int i=0; i<data.length; i+=4) { | 320 for (int i=0; i<data.length; i+=4) { |
321 data[i] = alpha; | 321 data[i] = alpha; |
322 } | 322 } |
323 } else if (source.alphaData !is null) { | 323 } else if (source.alphaData !is null) { |
324 byte[] alphaData = source.alphaData; | 324 byte[] alphaData = source.alphaData; |
346 * @see #hashCode | 346 * @see #hashCode |
347 */ | 347 */ |
348 public bool equals (Object object) { | 348 public bool equals (Object object) { |
349 if (object is this) return true; | 349 if (object is this) return true; |
350 if (!(object instanceof Cursor)) return false; | 350 if (!(object instanceof Cursor)) return false; |
351 Cursor cursor = (Cursor) object; | 351 Cursor cursor = cast(Cursor) object; |
352 return device is cursor.device && handle is cursor.handle; | 352 return device is cursor.device && handle is cursor.handle; |
353 } | 353 } |
354 | 354 |
355 /** | 355 /** |
356 * Returns an integer hash code for the receiver. Any two | 356 * Returns an integer hash code for the receiver. Any two |