comparison doodle/dia/grid_layer.d @ 48:1b4c9ba58673

Stylistic overhaul.
author daveb
date Tue, 03 Aug 2010 17:37:21 +0930
parents f2e4e1d29b98
children 9960c4fbd0dd
comparison
equal deleted inserted replaced
47:14f1c051c35b 48:1b4c9ba58673
20 class GridLayer : Layer, Grid { 20 class GridLayer : Layer, Grid {
21 static const double MIN_SPACING = 5.0; // pixels 21 static const double MIN_SPACING = 5.0; // pixels
22 22
23 this(in string name) { 23 this(in string name) {
24 super(name); 24 super(name);
25 mZoomValid = false; 25 _zoomValid = false;
26 } 26 }
27 27
28 // Layer overrides: 28 // Layer overrides:
29 29
30 override Rectangle bounds() const { 30 override Rectangle bounds() const {
31 // We don't require any geometry 31 // We don't require any geometry
32 return Rectangle(); 32 return Rectangle();
33 } 33 }
34 34
35 override void draw(in Viewport viewport, 35 override void draw(in Viewport viewport,
36 in Rectangle pixel_damage, scope Context pixel_cr, 36 in Rectangle pixelDamage, scope Context pixelCr,
37 in Rectangle model_damage, scope Context model_cr) const { 37 in Rectangle modelDamage, scope Context modelCr) const {
38 assert(mZoomValid); 38 assert(_zoomValid);
39 39
40 double xx = 1.0, yy = 1.0; 40 double xx = 1.0, yy = 1.0;
41 model_cr.userToDeviceDistance(xx, yy); 41 modelCr.userToDeviceDistance(xx, yy);
42 42
43 model_cr.save(); { 43 modelCr.save(); {
44 model_cr.setSourceRgba(0.0, 0.0, 0.0, 0.3); 44 modelCr.setSourceRgba(0.0, 0.0, 0.0, 0.3);
45 model_cr.setLineWidth(0.5); 45 modelCr.setLineWidth(0.5);
46 46
47 { 47 {
48 // vertical grid lines 48 // vertical grid lines
49 double x = start(model_damage.min_corner.x, mSpacing); 49 double x = start(modelDamage.minCorner.x, _spacing);
50 50
51 for (;;) { 51 for (;;) {
52 vline(model_cr, x, model_damage.min_corner.y, model_damage.max_corner.y); 52 vline(modelCr, x, modelDamage.minCorner.y, modelDamage.maxCorner.y);
53 53
54 // Ensure 1 pixel wide FIXME is this naughty? We are sneaking 54 // Ensure 1 pixel wide FIXME is this naughty? We are sneaking
55 // through cairo to mix model and pixel coordinates... 55 // through cairo to mix model and pixel coordinates...
56 model_cr.save(); { 56 modelCr.save(); {
57 model_cr.scale(1.0 / xx, 1.0 / yy); 57 modelCr.scale(1.0 / xx, 1.0 / yy);
58 model_cr.stroke(); 58 modelCr.stroke();
59 } model_cr.restore(); 59 } modelCr.restore();
60 60
61 if (x > model_damage.max_corner.x) { 61 if (x > modelDamage.maxCorner.x) {
62 break; 62 break;
63 } 63 }
64 64
65 x += mSpacing; 65 x += _spacing;
66 } 66 }
67 } 67 }
68 68
69 { 69 {
70 // horizontal grid lines 70 // horizontal grid lines
71 double y = start(model_damage.min_corner.y, mSpacing); 71 double y = start(modelDamage.minCorner.y, _spacing);
72 72
73 for (;;) { 73 for (;;) {
74 hline(model_cr, y, model_damage.min_corner.x, model_damage.max_corner.x); 74 hline(modelCr, y, modelDamage.minCorner.x, modelDamage.maxCorner.x);
75 75
76 // FIXME? 76 // FIXME?
77 model_cr.save(); { 77 modelCr.save(); {
78 model_cr.scale(1.0 / xx, 1.0 / yy); 78 modelCr.scale(1.0 / xx, 1.0 / yy);
79 model_cr.stroke(); 79 modelCr.stroke();
80 } model_cr.restore(); 80 } modelCr.restore();
81 81
82 if (y > model_damage.max_corner.y) { 82 if (y > modelDamage.maxCorner.y) {
83 break; 83 break;
84 } 84 }
85 85
86 y += mSpacing; 86 y += _spacing;
87 } 87 }
88 } 88 }
89 } model_cr.restore(); 89 } modelCr.restore();
90 } 90 }
91 91
92 // Grid overrides: 92 // Grid overrides:
93 93
94 override void zoom_changed(double zoom) { 94 override void zoomChanged(double zoom) {
95 mZoom = zoom; 95 _zoom = zoom;
96 mZoomValid = true; 96 _zoomValid = true;
97 97
98 // FIXME compute spacing properly 98 // FIXME compute spacing properly
99 mSpacing = 20.0 / mZoom; // mm 99 _spacing = 20.0 / _zoom; // mm
100 } 100 }
101 101
102 // FIXME use inout parameter? 102 // FIXME use inout parameter?
103 override bool snap(in Point a, out Point b) const { 103 override bool snap(in Point a, out Point b) const {
104 b = a; 104 b = a;
105 return false; 105 return false;
106 } 106 }
107 107
108 private { 108 private {
109 bool mZoomValid; 109 bool _zoomValid;
110 double mZoom; // pixels per millimetre 110 double _zoom; // pixels per millimetre
111 111
112 double mSpacing; // model spacing 112 double _spacing; // model spacing
113 } 113 }
114 } 114 }