Mercurial > projects > doodle
annotate doodle/dia/grid_layer.d @ 92:a98116479793
Removed GL support. Improved grid.
author | daveb |
---|---|
date | Fri, 20 Aug 2010 18:34:32 +0930 |
parents | 42766e14534e |
children | bc5baa585b32 |
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; |
92 | 10 import std.array; |
11 | |
12 import doodle.core.logging; | |
24 | 13 } |
11 | 14 |
92 | 15 // Draw a grid. |
16 // zoom -> pixels / millimetre | |
17 // Grid lines must have a maximum density | |
18 // | |
11 | 19 |
57 | 20 class GridLayer : Layer, IGrid { |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
21 this(in string name = "Grid") { |
24 | 22 super(name); |
92 | 23 _spacingValid = false; |
24 | 24 } |
25 | |
35 | 26 // Layer overrides: |
27 | |
11 | 28 override Rectangle bounds() const { |
29 // We don't require any geometry | |
30 return Rectangle(); | |
31 } | |
32 | |
84 | 33 override void draw(in Rectangle screenDamage, scope Renderer screenRenderer, |
89 | 34 in Rectangle modelDamage, scope Renderer modelRenderer, |
35 in ScreenModel screenModel) const { | |
92 | 36 assert(_spacingValid); |
35 | 37 |
92 | 38 const z = screenModel.zoom; |
39 const lineWidthModel = LINE_WIDTH_SCREEN / z; | |
89 | 40 |
41 modelRenderer.pushState; { | |
92 | 42 modelRenderer.setColor(doodle.tk.color.Color(0.0, 0.0, 0.7, 1.0)); |
43 modelRenderer.setLineWidth(lineWidthModel); | |
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 |
92 | 45 auto x = roundDownSpacing(modelDamage.corner0.x); |
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 |
92 | 53 auto y = roundDownSpacing(modelDamage.corner0.y); |
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
|
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 |
92 | 65 override void zoomChanged(in double zoom) { |
66 foreach (s; SPACINGS) { | |
67 _spacing = s; | |
68 double pixels = zoom * _spacing; | |
69 if (pixels > MIN_SPACING) { break; } | |
70 } | |
71 _spacingValid = true; | |
35 | 72 } |
73 | |
11 | 74 private { |
92 | 75 double roundDownSpacing(in double value) const { |
76 return _spacing * floor(value / _spacing); | |
77 } | |
78 | |
79 bool _spacingValid; | |
80 double _spacing; // model spacing | |
35 | 81 |
92 | 82 immutable double LINE_WIDTH_SCREEN = 0.25; |
83 immutable double MIN_SPACING = 40.0; // pixels | |
84 immutable double[] SPACINGS = // millimetres | |
85 [ | |
86 5.0, | |
87 10.0, | |
88 20.0, | |
89 50.0 | |
90 ]; | |
11 | 91 } |
92 } |