annotate doodle/dia/grid_layer.d @ 91:42766e14534e

Update screenViewBounds when the window is resized
author daveb
date Thu, 19 Aug 2010 18:28:18 +0930
parents 885914257e0e
children a98116479793
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents: 27
diff changeset
1 module doodle.dia.grid_layer;
16
9e63308b749c * Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents: 12
diff changeset
2
24
a24c13bb9c98 Builds again.
"David Bryant <bagnose@gmail.com>"
parents: 22
diff changeset
3 public {
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents: 27
diff changeset
4 import doodle.dia.icanvas;
24
a24c13bb9c98 Builds again.
"David Bryant <bagnose@gmail.com>"
parents: 22
diff changeset
5 }
a24c13bb9c98 Builds again.
"David Bryant <bagnose@gmail.com>"
parents: 22
diff changeset
6
a24c13bb9c98 Builds again.
"David Bryant <bagnose@gmail.com>"
parents: 22
diff changeset
7 private {
a24c13bb9c98 Builds again.
"David Bryant <bagnose@gmail.com>"
parents: 22
diff changeset
8 import std.math;
89
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
9 import std.stdio;
24
a24c13bb9c98 Builds again.
"David Bryant <bagnose@gmail.com>"
parents: 22
diff changeset
10 }
11
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
11
35
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
12 private {
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
13 double start(in double value, in double spacing) {
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
14 real r = floor(value / spacing);
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
15 return r * spacing;
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
16 }
11
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
17 }
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
18
57
9960c4fbd0dd I is for Interface
"David Bryant <bagnose@gmail.com>"
parents: 48
diff changeset
19 class GridLayer : Layer, IGrid {
58
c63719604adb Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents: 57
diff changeset
20 immutable double MIN_SPACING = 5.0; // pixels
35
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
21
58
c63719604adb Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents: 57
diff changeset
22 this(in string name = "Grid") {
24
a24c13bb9c98 Builds again.
"David Bryant <bagnose@gmail.com>"
parents: 22
diff changeset
23 super(name);
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 41
diff changeset
24 _zoomValid = false;
24
a24c13bb9c98 Builds again.
"David Bryant <bagnose@gmail.com>"
parents: 22
diff changeset
25 }
a24c13bb9c98 Builds again.
"David Bryant <bagnose@gmail.com>"
parents: 22
diff changeset
26
35
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
27 // Layer overrides:
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
28
11
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
29 override Rectangle bounds() const {
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
30 // We don't require any geometry
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
31 return Rectangle();
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
32 }
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
33
84
cdd4fc728d94 Renamed Drawable to Renderer
daveb
parents: 81
diff changeset
34 override void draw(in Rectangle screenDamage, scope Renderer screenRenderer,
89
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
35 in Rectangle modelDamage, scope Renderer modelRenderer,
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
36 in ScreenModel screenModel) const {
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 41
diff changeset
37 assert(_zoomValid);
35
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
38
89
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
39 auto z = screenModel.zoom;
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
40
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
41 modelRenderer.pushState; {
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
42 modelRenderer.setColor(Color(0.0, 0.0, 0.0, 0.3));
91
42766e14534e Update screenViewBounds when the window is resized
daveb
parents: 90
diff changeset
43 modelRenderer.setLineWidth(1 / z);
90
885914257e0e Ok, the cairo resource leak (and cost of reqaquisition) in GtkD is the cause
David Bryant <bagnose@gmail.com>
parents: 89
diff changeset
44
89
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
45 auto x = start(modelDamage.corner0.x, _spacing);
36
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 35
diff changeset
46
89
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
47 for (;;) {
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
48 modelRenderer.drawVLine(x, modelDamage.corner0.y, modelDamage.corner1.y);
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
49 x += _spacing;
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
50 if (x > modelDamage.corner1.x) break;
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
51 }
90
885914257e0e Ok, the cairo resource leak (and cost of reqaquisition) in GtkD is the cause
David Bryant <bagnose@gmail.com>
parents: 89
diff changeset
52
885914257e0e Ok, the cairo resource leak (and cost of reqaquisition) in GtkD is the cause
David Bryant <bagnose@gmail.com>
parents: 89
diff changeset
53 auto y = start(modelDamage.corner0.y, _spacing);
885914257e0e Ok, the cairo resource leak (and cost of reqaquisition) in GtkD is the cause
David Bryant <bagnose@gmail.com>
parents: 89
diff changeset
54
885914257e0e Ok, the cairo resource leak (and cost of reqaquisition) in GtkD is the cause
David Bryant <bagnose@gmail.com>
parents: 89
diff changeset
55 for (;;) {
885914257e0e Ok, the cairo resource leak (and cost of reqaquisition) in GtkD is the cause
David Bryant <bagnose@gmail.com>
parents: 89
diff changeset
56 modelRenderer.drawHLine(y, modelDamage.corner0.x, modelDamage.corner1.x);
885914257e0e Ok, the cairo resource leak (and cost of reqaquisition) in GtkD is the cause
David Bryant <bagnose@gmail.com>
parents: 89
diff changeset
57 y += _spacing;
885914257e0e Ok, the cairo resource leak (and cost of reqaquisition) in GtkD is the cause
David Bryant <bagnose@gmail.com>
parents: 89
diff changeset
58 if (y > modelDamage.corner1.y) break;
885914257e0e Ok, the cairo resource leak (and cost of reqaquisition) in GtkD is the cause
David Bryant <bagnose@gmail.com>
parents: 89
diff changeset
59 }
89
467febed7367 * Ignore excre
David Bryant <bagnose@gmail.com>
parents: 84
diff changeset
60 } modelRenderer.popState;
11
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
61 }
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
62
57
9960c4fbd0dd I is for Interface
"David Bryant <bagnose@gmail.com>"
parents: 48
diff changeset
63 // IGrid overrides:
35
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
64
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 41
diff changeset
65 override void zoomChanged(double zoom) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 41
diff changeset
66 _zoom = zoom;
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 41
diff changeset
67 _zoomValid = true;
36
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 35
diff changeset
68
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 35
diff changeset
69 // FIXME compute spacing properly
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 41
diff changeset
70 _spacing = 20.0 / _zoom; // mm
35
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
71 }
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
72
36
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 35
diff changeset
73 // FIXME use inout parameter?
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 35
diff changeset
74 override bool snap(in Point a, out Point b) const {
35
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
75 b = a;
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
76 return false;
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
77 }
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
78
11
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
79 private {
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 41
diff changeset
80 bool _zoomValid;
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 41
diff changeset
81 double _zoom; // pixels per millimetre
35
3f6bb0bb22dc Beginnings of grid
David Bryant <bagnose@gmail.com>
parents: 34
diff changeset
82
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 41
diff changeset
83 double _spacing; // model spacing
11
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
84 }
fb571a3b1f0d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents:
diff changeset
85 }