annotate doodle/dia/tool_layer.d @ 48:1b4c9ba58673

Stylistic overhaul.
author daveb
date Tue, 03 Aug 2010 17:37:21 +0930
parents 188397ef9a12
children b190a9d9352e
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: 26
diff changeset
1 module doodle.dia.tool_layer;
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
2
36
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
3 public {
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
4 import doodle.dia.tool;
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
5 }
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
6
16
9e63308b749c * Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents: 14
diff changeset
7 private {
9e63308b749c * Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents: 14
diff changeset
8 import std.stdio;
28
1754cb773d41 Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents: 26
diff changeset
9 import doodle.cairo.routines;
16
9e63308b749c * Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents: 14
diff changeset
10 }
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
11
12
a093c4fbdd43 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 10
diff changeset
12 class ToolLayer : Layer, EventHandler {
a093c4fbdd43 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 10
diff changeset
13 this(in Tool[] tools, in string name) {
a093c4fbdd43 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 10
diff changeset
14 super(name);
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
15 _tools = tools.dup;
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
16 }
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
17
36
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
18 // Layer overrides:
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
19
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
20 override Rectangle bounds() const {
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
21 return Rectangle();
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
22 }
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
23
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
24 override void draw(const Viewport viewport,
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
25 in Rectangle pixelDamage, scope Context pixelCr,
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
26 in Rectangle modelDamage, scope Context modelCr) const {
36
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
27 // FIXME this isn't how we will really draw the tools...
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
28 foreach (const Tool tool; _tools) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
29 tool.draw(viewport, pixelDamage, pixelCr, modelDamage, modelCr);
36
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
30 }
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
31 }
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
32
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
33 // EventHandler overrides:
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
34
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
35 override bool handleButtonPress(scope Viewport viewport, in ButtonEvent event) {
14
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
36 // writefln("%s", event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
37
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
38 if (_grabbedTool is null) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
39 foreach_reverse(ref tool; _tools) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
40 if (tool.handleButtonPress(viewport, event)) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
41 _grabbedTool = &tool;
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
42 _grabbedButton = event.button_name;
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
43 break;
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
44 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
45 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
46 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
47 else {
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
48 _grabbedTool.handleButtonPress(viewport, event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
49 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
50
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
51 return true;
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
52 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
53
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
54 override bool handleButtonRelease(scope Viewport viewport, in ButtonEvent event) {
14
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
55 // writefln("%s", event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
56
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
57 if (_grabbedTool !is null) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
58 _grabbedTool.handleButtonRelease(viewport, event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
59
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
60 if (_grabbedButton == event.button_name) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
61 _grabbedTool = null;
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
62 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
63 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
64
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
65 return true;
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
66 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
67
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
68 override bool handleKeyPress(scope Viewport viewport, in KeyEvent event) {
14
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
69 // writefln("%s", event);
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
70
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
71 return true;
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
72 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
73
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
74 override bool handleKeyRelease(scope Viewport viewport, in KeyEvent event) {
14
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
75 // writefln("%s", event);
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
76
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
77 return true;
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
78 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
79
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
80 override bool handleMotion(scope Viewport viewport, in MotionEvent event) {
17
c643c04e3f5e Checkpoint
David Bryant <daveb@acres.com.au>
parents: 16
diff changeset
81 //writefln("%s", event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
82
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
83 if (_grabbedTool is null) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
84 foreach_reverse(ref tool; _tools) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
85 if (tool.handleMotion(viewport, event)) {
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
86 break;
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
87 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
88 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
89 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
90 else {
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
91 _grabbedTool.handleMotion(viewport, event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
92 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
93
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
94 return true;
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
95 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
96
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
97 override bool handleScroll(scope Viewport viewport, in ScrollEvent event) {
14
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
98 // writefln("%s", event);
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
99
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
100 if (_grabbedTool is null) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
101 foreach_reverse(ref tool; _tools) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
102 if (tool.handleScroll(viewport, event)) {
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
103 break;
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
104 }
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
105 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
106 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
107 else {
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
108 _grabbedTool.handleScroll(viewport, event);
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
109 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
110
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
111 return true;
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
112 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
113
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
114 /*
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
115 override void push(Tool tool) {
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
116 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
117
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
118 override void pop() {
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
119 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
120
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
121 override void replace(Tool tool) {
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
122 }
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
123 */
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
124
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
125 private {
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
126 Tool[] _tools;
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
127 Tool * _grabbedTool;
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
128 ButtonName _grabbedButton;
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
129 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
130 }