Mercurial > projects > dwt-mac
comparison dwt/widgets/Canvas.d @ 23:9414ecde7ba7
Ported dwt.widgets.Canvas
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Mon, 08 Sep 2008 17:38:05 +0200 |
parents | 1a8b3cb347e0 |
children | 642f460a0908 |
comparison
equal
deleted
inserted
replaced
22:c6edc6e9bd0d | 23:9414ecde7ba7 |
---|---|
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 |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | |
10 *******************************************************************************/ | 13 *******************************************************************************/ |
11 module dwt.widgets.Canvas; | 14 module dwt.widgets.Canvas; |
12 | |
13 import dwt.dwthelper.utils; | |
14 | 15 |
15 | 16 |
16 import dwt.DWT; | 17 import dwt.DWT; |
17 import dwt.DWTException; | 18 import dwt.DWTException; |
18 import dwt.graphics.Font; | 19 import dwt.graphics.Font; |
24 import dwt.internal.cocoa.NSGraphicsContext; | 25 import dwt.internal.cocoa.NSGraphicsContext; |
25 import dwt.internal.cocoa.NSPoint; | 26 import dwt.internal.cocoa.NSPoint; |
26 import dwt.internal.cocoa.NSRect; | 27 import dwt.internal.cocoa.NSRect; |
27 import dwt.internal.cocoa.NSSize; | 28 import dwt.internal.cocoa.NSSize; |
28 import dwt.internal.cocoa.OS; | 29 import dwt.internal.cocoa.OS; |
30 | |
31 import dwt.dwthelper.utils; | |
32 import dwt.widgets.Caret; | |
33 import dwt.widgets.Composite; | |
34 import dwt.widgets.Control; | |
35 import dwt.widgets.IME; | |
29 | 36 |
30 /** | 37 /** |
31 * Instances of this class provide a surface for drawing | 38 * Instances of this class provide a surface for drawing |
32 * arbitrary graphics. | 39 * arbitrary graphics. |
33 * <dl> | 40 * <dl> |
135 if (caret.isShowing) { | 142 if (caret.isShowing) { |
136 NSGraphicsContext context = NSGraphicsContext.currentContext(); | 143 NSGraphicsContext context = NSGraphicsContext.currentContext(); |
137 | 144 |
138 Image image = caret.image; | 145 Image image = caret.image; |
139 if (image !is null) { | 146 if (image !is null) { |
140 NSRect fromRect = new NSRect (); | 147 NSRect fromRect = NSRect (); |
141 NSSize size = image.handle.size(); | 148 NSSize size = image.handle.size(); |
142 fromRect.width = size.width; | 149 fromRect.width = size.width; |
143 fromRect.height = size.height; | 150 fromRect.height = size.height; |
144 NSPoint point = new NSPoint(); | 151 NSPoint point = NSPoint(); |
145 point.x = caret.x; | 152 point.x = caret.x; |
146 point.y = caret.y; | 153 point.y = caret.y; |
147 image.handle.drawAtPoint(point, rect, OS.NSCompositeXOR, 1); | 154 image.handle.drawAtPoint(point, rect, OS.NSCompositeXOR, 1); |
148 } else { | 155 } else { |
149 context.saveGraphicsState(); | 156 context.saveGraphicsState(); |
150 context.setCompositingOperation(OS.NSCompositeXOR); | 157 context.setCompositingOperation(OS.NSCompositeXOR); |
151 NSRect drawRect = new NSRect(); | 158 NSRect drawRect = NSRect(); |
152 drawRect.x = caret.x; | 159 drawRect.x = caret.x; |
153 drawRect.y = caret.y; | 160 drawRect.y = caret.y; |
154 drawRect.width = caret.width !is 0 ? caret.width : Caret.DEFAULT_WIDTH; | 161 drawRect.width = caret.width !is 0 ? caret.width : Caret.DEFAULT_WIDTH; |
155 drawRect.height = caret.height; | 162 drawRect.height = caret.height; |
156 context.setShouldAntialias(false); | 163 context.setShouldAntialias(false); |
249 Rectangle clientRect = getClientArea (); | 256 Rectangle clientRect = getClientArea (); |
250 Rectangle sourceRect = new Rectangle (x, y, width, height); | 257 Rectangle sourceRect = new Rectangle (x, y, width, height); |
251 if (sourceRect.intersects (clientRect)) { | 258 if (sourceRect.intersects (clientRect)) { |
252 update (all); | 259 update (all); |
253 } | 260 } |
254 NSRect damage = new NSRect(); | 261 NSRect damage = NSRect(); |
255 damage.x = x; | 262 damage.x = x; |
256 damage.y = y; | 263 damage.y = y; |
257 damage.width = width; | 264 damage.width = width; |
258 damage.height = height; | 265 damage.height = height; |
259 view.setNeedsDisplayInRect(damage); | 266 view.setNeedsDisplayInRect(damage); |