Mercurial > projects > doodle
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 |
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 | 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 | 5 } |
6 | |
7 private { | |
8 import std.math; | |
89 | 9 import std.stdio; |
24 | 10 } |
11 | 11 |
35 | 12 private { |
13 double start(in double value, in double spacing) { | |
14 real r = floor(value / spacing); | |
15 return r * spacing; | |
16 } | |
11 | 17 } |
18 | |
57 | 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 | 21 |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
22 this(in string name = "Grid") { |
24 | 23 super(name); |
48 | 24 _zoomValid = false; |
24 | 25 } |
26 | |
35 | 27 // Layer overrides: |
28 | |
11 | 29 override Rectangle bounds() const { |
30 // We don't require any geometry | |
31 return Rectangle(); | |
32 } | |
33 | |
84 | 34 override void draw(in Rectangle screenDamage, scope Renderer screenRenderer, |
89 | 35 in Rectangle modelDamage, scope Renderer modelRenderer, |
36 in ScreenModel screenModel) const { | |
48 | 37 assert(_zoomValid); |
35 | 38 |
89 | 39 auto z = screenModel.zoom; |
40 | |
41 modelRenderer.pushState; { | |
42 modelRenderer.setColor(Color(0.0, 0.0, 0.0, 0.3)); | |
91 | 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 | 45 auto x = start(modelDamage.corner0.x, _spacing); |
36 | 46 |
89 | 47 for (;;) { |
48 modelRenderer.drawVLine(x, modelDamage.corner0.y, modelDamage.corner1.y); | |
49 x += _spacing; | |
50 if (x > modelDamage.corner1.x) break; | |
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 | 60 } modelRenderer.popState; |
11 | 61 } |
62 | |
57 | 63 // IGrid overrides: |
35 | 64 |
48 | 65 override void zoomChanged(double zoom) { |
66 _zoom = zoom; | |
67 _zoomValid = true; | |
36 | 68 |
69 // FIXME compute spacing properly | |
48 | 70 _spacing = 20.0 / _zoom; // mm |
35 | 71 } |
72 | |
36 | 73 // FIXME use inout parameter? |
74 override bool snap(in Point a, out Point b) const { | |
35 | 75 b = a; |
76 return false; | |
77 } | |
78 | |
11 | 79 private { |
48 | 80 bool _zoomValid; |
81 double _zoom; // pixels per millimetre | |
35 | 82 |
48 | 83 double _spacing; // model spacing |
11 | 84 } |
85 } |