Mercurial > projects > doodle
annotate doodle/dia/grid_layer.d @ 90:885914257e0e
Ok, the cairo resource leak (and cost of reqaquisition) in GtkD is the cause
of the grid slowdown and the overall memory leak.
No need for backbuffers. Back to the wonderful abstraction I
originally anticipated.
author | David Bryant <bagnose@gmail.com> |
---|---|
date | Thu, 19 Aug 2010 00:28:57 +0930 |
parents | 467febed7367 |
children | 42766e14534e |
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 // Is _zoom like screenModel.zoom ? | |
41 | |
42 modelRenderer.pushState; { | |
43 modelRenderer.setColor(Color(0.0, 0.0, 0.0, 0.3)); | |
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 modelRenderer.setLineWidth(0.5); |
885914257e0e
Ok, the cairo resource leak (and cost of reqaquisition) in GtkD is the cause
David Bryant <bagnose@gmail.com>
parents:
89
diff
changeset
|
45 |
89 | 46 auto x = start(modelDamage.corner0.x, _spacing); |
36 | 47 |
89 | 48 for (;;) { |
49 writefln("Doing something %s", x); | |
50 modelRenderer.drawVLine(x, modelDamage.corner0.y, modelDamage.corner1.y); | |
51 x += _spacing; | |
52 if (x > modelDamage.corner1.x) break; | |
53 } | |
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 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
|
56 |
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 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
|
58 writefln("Doing something %s", y); |
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 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
|
60 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
|
61 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
|
62 } |
89 | 63 } modelRenderer.popState; |
64 | |
65 /+ | |
48 | 66 modelCr.save(); { |
67 modelCr.setSourceRgba(0.0, 0.0, 0.0, 0.3); | |
68 modelCr.setLineWidth(0.5); | |
35 | 69 |
70 { | |
71 // vertical grid lines | |
70 | 72 double x = start(modelDamage.corner0.x, _spacing); |
35 | 73 |
74 for (;;) { | |
70 | 75 vline(modelCr, x, modelDamage.corner0.y, modelDamage.corner1.y); |
36 | 76 |
77 // Ensure 1 pixel wide FIXME is this naughty? We are sneaking | |
78 // through cairo to mix model and pixel coordinates... | |
48 | 79 modelCr.save(); { |
89 | 80 modelCr.scale(1.0 / z, 1.0 / z); |
48 | 81 modelCr.stroke(); |
82 } modelCr.restore(); | |
35 | 83 |
70 | 84 if (x > modelDamage.corner1.x) { |
35 | 85 break; |
86 } | |
87 | |
48 | 88 x += _spacing; |
35 | 89 } |
90 } | |
91 | |
92 { | |
93 // horizontal grid lines | |
70 | 94 double y = start(modelDamage.corner0.y, _spacing); |
35 | 95 |
96 for (;;) { | |
70 | 97 hline(modelCr, y, modelDamage.corner0.x, modelDamage.corner1.x); |
36 | 98 |
41 | 99 // FIXME? |
48 | 100 modelCr.save(); { |
101 modelCr.scale(1.0 / xx, 1.0 / yy); | |
102 modelCr.stroke(); | |
103 } modelCr.restore(); | |
35 | 104 |
70 | 105 if (y > modelDamage.corner1.y) { |
35 | 106 break; |
107 } | |
108 | |
48 | 109 y += _spacing; |
35 | 110 } |
111 } | |
48 | 112 } modelCr.restore(); |
80
b759414d2b72
Switched from cairo to Drawable abstraction
"David Bryant <bagnose@gmail.com>"
parents:
74
diff
changeset
|
113 +/ |
11 | 114 } |
115 | |
57 | 116 // IGrid overrides: |
35 | 117 |
48 | 118 override void zoomChanged(double zoom) { |
119 _zoom = zoom; | |
120 _zoomValid = true; | |
36 | 121 |
122 // FIXME compute spacing properly | |
48 | 123 _spacing = 20.0 / _zoom; // mm |
35 | 124 } |
125 | |
36 | 126 // FIXME use inout parameter? |
127 override bool snap(in Point a, out Point b) const { | |
35 | 128 b = a; |
129 return false; | |
130 } | |
131 | |
11 | 132 private { |
48 | 133 bool _zoomValid; |
134 double _zoom; // pixels per millimetre | |
35 | 135 |
48 | 136 double _spacing; // model spacing |
11 | 137 } |
138 } |