Mercurial > projects > dwt-mac
comparison dwt/graphics/GC.d @ 46:cfa563df4fdd
Updated Widget and Display to 3.514
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 05 Dec 2008 16:00:41 +0100 |
parents | d8635bb48c7c |
children | 62202ce0039f |
comparison
equal
deleted
inserted
replaced
45:d8635bb48c7c | 46:cfa563df4fdd |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
26 import dwt.internal.cocoa.NSColor; | 26 import dwt.internal.cocoa.NSColor; |
27 import dwt.internal.cocoa.NSFont; | 27 import dwt.internal.cocoa.NSFont; |
28 import dwt.internal.cocoa.NSGradient; | 28 import dwt.internal.cocoa.NSGradient; |
29 import dwt.internal.cocoa.NSGraphicsContext; | 29 import dwt.internal.cocoa.NSGraphicsContext; |
30 import dwt.internal.cocoa.NSImage; | 30 import dwt.internal.cocoa.NSImage; |
31 import dwt.internal.cocoa.NSInteger; | |
32 import dwt.internal.cocoa.NSMutableDictionary; | 31 import dwt.internal.cocoa.NSMutableDictionary; |
33 import dwt.internal.cocoa.NSMutableParagraphStyle; | 32 import dwt.internal.cocoa.NSMutableParagraphStyle; |
34 import dwt.internal.cocoa.NSPoint; | 33 import dwt.internal.cocoa.NSPoint; |
35 import dwt.internal.cocoa.NSRect; | 34 import dwt.internal.cocoa.NSRect; |
36 import dwt.internal.cocoa.NSSize; | 35 import dwt.internal.cocoa.NSSize; |
57 import dwt.graphics.Rectangle; | 56 import dwt.graphics.Rectangle; |
58 import dwt.graphics.Region; | 57 import dwt.graphics.Region; |
59 import dwt.graphics.Resource; | 58 import dwt.graphics.Resource; |
60 import dwt.graphics.RGB; | 59 import dwt.graphics.RGB; |
61 import dwt.graphics.Transform; | 60 import dwt.graphics.Transform; |
62 import dwt.internal.cocoa.CGFloat; | 61 import dwt.internal.c.Carbon; |
62 import dwt.internal.objc.cocoa.Cocoa; | |
63 import objc = dwt.internal.objc.runtime; | 63 import objc = dwt.internal.objc.runtime; |
64 | 64 |
65 /** | 65 /** |
66 * Class <code>GC</code> is where all of the drawing capabilities that are | 66 * Class <code>GC</code> is where all of the drawing capabilities that are |
67 * supported by DWT are located. Instances are used to draw on either an | 67 * supported by DWT are located. Instances are used to draw on either an |
238 return gc; | 238 return gc; |
239 } | 239 } |
240 | 240 |
241 NSAutoreleasePool checkGC (int mask) { | 241 NSAutoreleasePool checkGC (int mask) { |
242 NSAutoreleasePool pool = null; | 242 NSAutoreleasePool pool = null; |
243 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); | 243 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); |
244 if ((mask & (CLIPPING | TRANSFORM)) !is 0) { | 244 if ((mask & (CLIPPING | TRANSFORM)) !is 0) { |
245 NSGraphicsContext.setCurrentContext(handle); | 245 NSGraphicsContext.setCurrentContext(handle); |
246 NSView view = data.view; | 246 NSView view = data.view; |
247 if (view !is null && data.paintRect is null) { | 247 if (view !is null && data.paintRect is null) { |
248 NSRect rect = view.convertRect_toView_(view.bounds(), null); | 248 NSRect rect = view.convertRect_toView_(view.bounds(), null); |
251 rect.width !is data.windowRect.width || rect.height !is data.windowRect.height || | 251 rect.width !is data.windowRect.width || rect.height !is data.windowRect.height || |
252 visibleRect.x !is data.visibleRect.x || visibleRect.y !is data.visibleRect.y || | 252 visibleRect.x !is data.visibleRect.x || visibleRect.y !is data.visibleRect.y || |
253 visibleRect.width !is data.visibleRect.width || visibleRect.height !is data.visibleRect.height) | 253 visibleRect.width !is data.visibleRect.width || visibleRect.height !is data.visibleRect.height) |
254 { | 254 { |
255 data.state &= ~CLIPPING; | 255 data.state &= ~CLIPPING; |
256 data.windowRect = rect; | 256 data.windowRectStruct = rect; |
257 data.visibleRect = visibleRect; | 257 data.windowRect = &data.windowRectStruct; |
258 data.visibleRectStruct = visibleRect; | |
259 data.visibleRect = &data.visibleRectStruct; | |
258 } | 260 } |
259 } | 261 } |
260 if ((data.state & CLIPPING) is 0 || (data.state & TRANSFORM) is 0) { | 262 if ((data.state & CLIPPING) is 0 || (data.state & TRANSFORM) is 0) { |
261 handle.restoreGraphicsState(); | 263 handle.restoreGraphicsState(); |
262 handle.saveGraphicsState(); | 264 handle.saveGraphicsState(); |
263 if (view !is null && data.paintRect is null) { | 265 if (view !is null && data.paintRect is null) { |
264 NSAffineTransform transform = NSAffineTransform.transform(); | 266 NSAffineTransform transform = NSAffineTransform.transform(); |
265 NSRect rect = data.windowRect; | 267 NSRect rect = data.windowRectStruct; |
266 transform.translateXBy(rect.x, rect.y + rect.height); | 268 transform.translateXBy(rect.x, rect.y + rect.height); |
267 transform.scaleXBy(1, -1); | 269 transform.scaleXBy(1, -1); |
268 transform.concat(); | 270 transform.concat(); |
269 NSBezierPath.bezierPathWithRect(data.visibleRect).addClip(); | 271 NSBezierPath.bezierPathWithRect(data.visibleRectStruct).addClip(); |
270 } | 272 } |
271 if (data.clipPath !is null) data.clipPath.addClip(); | 273 if (data.clipPath !is null) data.clipPath.addClip(); |
272 if (data.transform !is null) data.transform.concat(); | 274 if (data.transform !is null) data.transform.concat(); |
273 mask &= ~(TRANSFORM | CLIPPING); | 275 mask &= ~(TRANSFORM | CLIPPING); |
274 data.state |= TRANSFORM | CLIPPING; | 276 data.state |= TRANSFORM | CLIPPING; |
317 case DWT.LINE_DOT: | 319 case DWT.LINE_DOT: |
318 case DWT.LINE_DASH: | 320 case DWT.LINE_DASH: |
319 case DWT.LINE_DASHDOT: | 321 case DWT.LINE_DASHDOT: |
320 case DWT.LINE_DASHDOTDOT: | 322 case DWT.LINE_DASHDOTDOT: |
321 state |= LINE_STYLE; | 323 state |= LINE_STYLE; |
324 default: assert(false); | |
322 } | 325 } |
323 } | 326 } |
324 if ((state & LINE_STYLE) !is 0) { | 327 if ((state & LINE_STYLE) !is 0) { |
325 CGFloat[] dashes = null; | 328 CGFloat[] dashes = null; |
326 CGFloat width = data.lineWidth; | 329 CGFloat width = data.lineWidth; |
329 case DWT.LINE_DASH: dashes = width !is 0 ? LINE_DASH : LINE_DASH_ZERO; break; | 332 case DWT.LINE_DASH: dashes = width !is 0 ? LINE_DASH : LINE_DASH_ZERO; break; |
330 case DWT.LINE_DOT: dashes = width !is 0 ? LINE_DOT : LINE_DOT_ZERO; break; | 333 case DWT.LINE_DOT: dashes = width !is 0 ? LINE_DOT : LINE_DOT_ZERO; break; |
331 case DWT.LINE_DASHDOT: dashes = width !is 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break; | 334 case DWT.LINE_DASHDOT: dashes = width !is 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break; |
332 case DWT.LINE_DASHDOTDOT: dashes = width !is 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break; | 335 case DWT.LINE_DASHDOTDOT: dashes = width !is 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break; |
333 case DWT.LINE_CUSTOM: dashes = data.lineDashes; break; | 336 case DWT.LINE_CUSTOM: dashes = data.lineDashes; break; |
337 default: assert(false); | |
334 } | 338 } |
335 if (dashes !is null) { | 339 if (dashes !is null) { |
336 CGFloat[] lengths = new CGFloat[dashes.length]; | 340 CGFloat[] lengths = new CGFloat[dashes.length]; |
337 for (int i = 0; i < lengths.length; i++) { | 341 for (int i = 0; i < lengths.length; i++) { |
338 lengths[i] = width is 0 || data.lineStyle is DWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width; | 342 lengths[i] = width is 0 || data.lineStyle is DWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width; |
346 path.setMiterLimit(data.lineMiterLimit); | 350 path.setMiterLimit(data.lineMiterLimit); |
347 } | 351 } |
348 if ((state & LINE_JOIN) !is 0) { | 352 if ((state & LINE_JOIN) !is 0) { |
349 NSLineJoinStyle joinStyle; | 353 NSLineJoinStyle joinStyle; |
350 switch (data.lineJoin) { | 354 switch (data.lineJoin) { |
351 case DWT.JOIN_MITER: joinStyle = NSMiterLineJoinStyle; break; | 355 case DWT.JOIN_MITER: joinStyle = OS.NSMiterLineJoinStyle; break; |
352 case DWT.JOIN_ROUND: joinStyle = NSRoundLineJoinStyle; break; | 356 case DWT.JOIN_ROUND: joinStyle = OS.NSRoundLineJoinStyle; break; |
353 case DWT.JOIN_BEVEL: joinStyle = NSBevelLineJoinStyle; break; | 357 case DWT.JOIN_BEVEL: joinStyle = OS.NSBevelLineJoinStyle; break; |
358 default: assert(false); | |
354 } | 359 } |
355 path.setLineJoinStyle(joinStyle); | 360 path.setLineJoinStyle(joinStyle); |
356 } | 361 } |
357 if ((state & LINE_CAP) !is 0) { | 362 if ((state & LINE_CAP) !is 0) { |
358 NSLineCapStyle capStyle; | 363 NSLineCapStyle capStyle; |
359 switch (data.lineCap) { | 364 switch (data.lineCap) { |
360 case DWT.CAP_ROUND: capStyle = NSRoundLineCapStyle; break; | 365 case DWT.CAP_ROUND: capStyle = OS.NSRoundLineCapStyle; break; |
361 case DWT.CAP_FLAT: capStyle = NSButtLineCapStyle; break; | 366 case DWT.CAP_FLAT: capStyle = OS.NSButtLineCapStyle; break; |
362 case DWT.CAP_SQUARE: capStyle = NSSquareLineCapStyle; break; | 367 case DWT.CAP_SQUARE: capStyle = OS.NSSquareLineCapStyle; break; |
368 default: assert(false); | |
363 } | 369 } |
364 path.setLineCapStyle(capStyle); | 370 path.setLineCapStyle(capStyle); |
365 } | 371 } |
366 if ((state & DRAW_OFFSET) !is 0) { | 372 if ((state & DRAW_OFFSET) !is 0) { |
367 data.drawXOffset = data.drawYOffset = 0; | 373 data.drawXOffset = data.drawYOffset = 0; |
663 dict.setObject(color, OS.NSForegroundColorAttributeName); | 669 dict.setObject(color, OS.NSForegroundColorAttributeName); |
664 dict.setObject(data.font.handle, OS.NSFontAttributeName); | 670 dict.setObject(data.font.handle, OS.NSFontAttributeName); |
665 if ((flags & DWT.DRAW_TRANSPARENT) is 0) { | 671 if ((flags & DWT.DRAW_TRANSPARENT) is 0) { |
666 CGFloat[] background = data.background; | 672 CGFloat[] background = data.background; |
667 color = NSColor.colorWithDeviceRed(background[0], background[1], background[2], data.alpha / 255f); | 673 color = NSColor.colorWithDeviceRed(background[0], background[1], background[2], data.alpha / 255f); |
668 dict.setObject(color, OS.FuncNSBackgroundColorAttributeName()); | 674 dict.setObject(color, OS.NSBackgroundColorAttributeName); |
669 } | 675 } |
670 if ((flags & DWT.DRAW_TAB) is 0) { | 676 if ((flags & DWT.DRAW_TAB) is 0) { |
671 NSMutableParagraphStyle paragraph = (NSMutableParagraphStyle)new NSMutableParagraphStyle().alloc().init(); | 677 NSMutableParagraphStyle paragraph = cast(NSMutableParagraphStyle)(new NSMutableParagraphStyle()).alloc().init(); |
672 paragraph.setAlignment(OS.NSLeftTextAlignment); | 678 paragraph.setAlignment(OS.NSLeftTextAlignment); |
673 paragraph.setLineBreakMode(OS.NSLineBreakByClipping); | 679 paragraph.setLineBreakMode(OS.NSLineBreakByClipping); |
674 paragraph.setTabStops(NSArray.array()); | 680 paragraph.setTabStops(NSArray.array()); |
675 dict.setObject(paragraph, OS.NSParagraphStyleAttributeName); | 681 dict.setObject(paragraph, OS.NSParagraphStyleAttributeName); |
676 paragraph.release(); | 682 paragraph.release(); |
2096 if (paintRect !is null) { | 2102 if (paintRect !is null) { |
2097 region.intersect(cast(int)paintRect.x, cast(int)paintRect.y, cast(int)paintRect.width, cast(int)paintRect.height); | 2103 region.intersect(cast(int)paintRect.x, cast(int)paintRect.y, cast(int)paintRect.width, cast(int)paintRect.height); |
2098 } | 2104 } |
2099 if (data.clipPath !is null) { | 2105 if (data.clipPath !is null) { |
2100 NSBezierPath clip = data.clipPath.bezierPathByFlatteningPath(); | 2106 NSBezierPath clip = data.clipPath.bezierPathByFlatteningPath(); |
2101 int count = (int)/*64*/clip.elementCount(); | 2107 int count = cast(int)/*64*/clip.elementCount(); |
2102 int pointCount = 0; | 2108 int pointCount = 0; |
2103 Region clipRgn = new Region(device); | 2109 Region clipRgn = new Region(device); |
2104 int[] pointArray = new int[count * 2]; | 2110 int[] pointArray = new int[count * 2]; |
2105 NSPointArray points = cast(NSPointArray) OS.malloc(NSPoint.sizeof); | 2111 NSPointArray points = cast(NSPointArray) OS.malloc(NSPoint.sizeof); |
2106 if (points is null) DWT.error(DWT.ERROR_NO_HANDLES); | 2112 if (points is null) DWT.error(DWT.ERROR_NO_HANDLES); |
2265 * | 2271 * |
2266 * @since 3.1 | 2272 * @since 3.1 |
2267 */ | 2273 */ |
2268 public int getInterpolation() { | 2274 public int getInterpolation() { |
2269 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 2275 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
2270 int interpolation = (int)/*64*/handle.imageInterpolation(); | 2276 int interpolation = cast(int)/*64*/handle.imageInterpolation(); |
2271 switch (interpolation) { | 2277 switch (interpolation) { |
2272 case OS.NSImageInterpolationDefault: return DWT.DEFAULT; | 2278 case OS.NSImageInterpolationDefault: return DWT.DEFAULT; |
2273 case OS.NSImageInterpolationNone: return DWT.NONE; | 2279 case OS.NSImageInterpolationNone: return DWT.NONE; |
2274 case OS.NSImageInterpolationLow: return DWT.LOW; | 2280 case OS.NSImageInterpolationLow: return DWT.LOW; |
2275 case OS.NSImageInterpolationHigh: return DWT.HIGH; | 2281 case OS.NSImageInterpolationHigh: return DWT.HIGH; |