Mercurial > projects > doodle
comparison doodle/gtk/canvas.d @ 75:3cac0ee8ca35
Ok, things are seem on-track again
author | "David Bryant <bagnose@gmail.com>" |
---|---|
date | Sun, 15 Aug 2010 01:14:26 +0930 |
parents | c03ed75c0f8e |
children | 15ca7d5cd1ed |
comparison
equal
deleted
inserted
replaced
74:c03ed75c0f8e | 75:3cac0ee8ca35 |
---|---|
6 } | 6 } |
7 | 7 |
8 private { | 8 private { |
9 import doodle.core.misc; | 9 import doodle.core.misc; |
10 import doodle.core.logging; | 10 import doodle.core.logging; |
11 import doodle.tk.pixel_model; | |
11 import doodle.tk.cairo; | 12 import doodle.tk.cairo; |
13 import doodle.dia.layer_stack; | |
12 import doodle.gtk.conversions; | 14 import doodle.gtk.conversions; |
13 import doodle.tk.pixel_model; | |
14 | 15 |
15 import cairo.Surface; | 16 import cairo.Surface; |
16 | 17 |
17 import gtk.Widget; | 18 import gtk.Widget; |
18 import gtk.Toolbar; | 19 import gtk.Toolbar; |
45 this(in Layer[] layers, IEventHandler eventHandler, IGrid grid, in double pixelsPerMillimetre) { | 46 this(in Layer[] layers, IEventHandler eventHandler, IGrid grid, in double pixelsPerMillimetre) { |
46 super(3, 3, 0); | 47 super(3, 3, 0); |
47 | 48 |
48 _damageScreen = Rectangle.DEFAULT; | 49 _damageScreen = Rectangle.DEFAULT; |
49 | 50 |
50 _layers = layers.dup; | 51 _layerStack = new LayerStack(layers); |
51 _eventHandler = eventHandler; | 52 _eventHandler = eventHandler; |
52 _grid = grid; | 53 _grid = grid; |
53 _pixelsPerMillimetre = pixelsPerMillimetre; | 54 _pixelsPerMillimetre = pixelsPerMillimetre; |
54 | 55 |
55 // Create our child widgets and register callbacks | 56 // Create our child widgets and register callbacks |
195 } | 196 } |
196 } | 197 } |
197 | 198 |
198 private { | 199 private { |
199 | 200 |
200 Rectangle layerBounds() const { | |
201 Rectangle bounds = Rectangle.DEFAULT; | |
202 foreach (layer; _layers) { bounds = bounds | layer.bounds; } | |
203 assert(bounds.valid); | |
204 return bounds; | |
205 } | |
206 | |
207 void initialiseBounds(in Rectangle viewBounds) { | 201 void initialiseBounds(in Rectangle viewBounds) { |
208 Rectangle lb = layerBounds; | 202 Rectangle lb = _layerStack.bounds; |
209 | 203 |
210 // FIXME use a function that grows a rectangle about its centre | 204 // FIXME use a function that grows a rectangle about its centre |
211 // and change 2.0 to a class-level constant | 205 // and change 2.0 to a class-level constant |
212 Rectangle paddedLayerBounds = expand(move(lb, - lb.size), 2.0 * lb.size); | 206 Rectangle paddedLayerBounds = expand(move(lb, - lb.size), 2.0 * lb.size); |
213 | 207 |
218 updateAdjustments; | 212 updateAdjustments; |
219 updateRulers; | 213 updateRulers; |
220 } | 214 } |
221 | 215 |
222 void consolidateBounds() { | 216 void consolidateBounds() { |
223 Rectangle lb = layerBounds; | 217 Rectangle lb = _layerStack.bounds; |
224 | 218 |
225 // FIXME likewise as above | 219 // FIXME likewise as above |
226 Rectangle paddedLayerBounds = expand(move(lb, - lb.size), 2.0 * lb.size); | 220 Rectangle paddedLayerBounds = expand(move(lb, - lb.size), 2.0 * lb.size); |
227 | 221 |
228 _pixelModel.consolidateCanvasBounds(paddedLayerBounds); | 222 _pixelModel.consolidateCanvasBounds(paddedLayerBounds); |
295 pixelCr.setSourceRgba(0.9, 0.9, 0.9, 1.0); | 289 pixelCr.setSourceRgba(0.9, 0.9, 0.9, 1.0); |
296 rectangle(pixelCr, pixelDamage); | 290 rectangle(pixelCr, pixelDamage); |
297 pixelCr.fill; | 291 pixelCr.fill; |
298 } pixelCr.restore; | 292 } pixelCr.restore; |
299 | 293 |
300 // Draw each layer | 294 _layerStack.draw(pixelDamage, pixelCr, modelDamage, modelCr); |
301 foreach(layer; _layers) { | |
302 layer.draw(pixelDamage, pixelCr, modelDamage, modelCr); | |
303 } | |
304 } pixelCr.restore; modelCr.restore; | 295 } pixelCr.restore; modelCr.restore; |
305 | 296 |
306 return true; | 297 return true; |
307 } | 298 } |
308 | 299 |
494 assert(widget is _drawingArea); | 485 assert(widget is _drawingArea); |
495 //writefln("Got realize\n"); | 486 //writefln("Got realize\n"); |
496 _drawingArea.grabFocus(); | 487 _drawingArea.grabFocus(); |
497 } | 488 } |
498 | 489 |
499 Layer[] _layers; | 490 LayerStack _layerStack; |
500 IEventHandler _eventHandler; | 491 IEventHandler _eventHandler; |
501 IGrid _grid; | 492 IGrid _grid; |
502 double _pixelsPerMillimetre; | 493 double _pixelsPerMillimetre; |
503 | 494 |
504 // Child widgets: | 495 // Child widgets: |