annotate doodle/dia/tool_layer.d @ 57:9960c4fbd0dd

I is for Interface
author "David Bryant <bagnose@gmail.com>"
date Sun, 08 Aug 2010 22:01:54 +0930
parents b190a9d9352e
children c63719604adb
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
57
9960c4fbd0dd I is for Interface
"David Bryant <bagnose@gmail.com>"
parents: 56
diff changeset
12 interface IToolStack {
56
b190a9d9352e Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 48
diff changeset
13 }
b190a9d9352e Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 48
diff changeset
14
57
9960c4fbd0dd I is for Interface
"David Bryant <bagnose@gmail.com>"
parents: 56
diff changeset
15 class ToolLayer : Layer, IEventHandler, IToolStack {
12
a093c4fbdd43 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 10
diff changeset
16 this(in Tool[] tools, in string name) {
a093c4fbdd43 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 10
diff changeset
17 super(name);
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
18 _tools = tools.dup;
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
19 }
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
20
36
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
21 // Layer overrides:
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 override Rectangle bounds() const {
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
24 return Rectangle();
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
25 }
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
26
57
9960c4fbd0dd I is for Interface
"David Bryant <bagnose@gmail.com>"
parents: 56
diff changeset
27 override void draw(const IViewport viewport,
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
28 in Rectangle pixelDamage, scope Context pixelCr,
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
29 in Rectangle modelDamage, scope Context modelCr) const {
56
b190a9d9352e Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 48
diff changeset
30 if (_grabbedTool) {
b190a9d9352e Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 48
diff changeset
31 _grabbedTool.draw(viewport, pixelDamage, pixelCr);
36
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 }
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
34
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
35 // EventHandler overrides:
188397ef9a12 Late night tinkering
David Bryant <bagnose@gmail.com>
parents: 28
diff changeset
36
57
9960c4fbd0dd I is for Interface
"David Bryant <bagnose@gmail.com>"
parents: 56
diff changeset
37 override bool handleButtonPress(scope IViewport viewport, in ButtonEvent event) {
14
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
38 // writefln("%s", event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
39
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
40 if (_grabbedTool is null) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
41 foreach_reverse(ref tool; _tools) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
42 if (tool.handleButtonPress(viewport, event)) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
43 _grabbedTool = &tool;
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
44 _grabbedButton = event.button_name;
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
45 break;
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
46 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
47 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
48 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
49 else {
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
50 _grabbedTool.handleButtonPress(viewport, event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
51 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
52
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
53 return true;
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
54 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
55
57
9960c4fbd0dd I is for Interface
"David Bryant <bagnose@gmail.com>"
parents: 56
diff changeset
56 override bool handleButtonRelease(scope IViewport viewport, in ButtonEvent event) {
14
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
57 // writefln("%s", event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
58
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
59 if (_grabbedTool !is null) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
60 _grabbedTool.handleButtonRelease(viewport, event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
61
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
62 if (_grabbedButton == event.button_name) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
63 _grabbedTool = null;
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
64 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
65 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
66
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
67 return true;
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
68 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
69
57
9960c4fbd0dd I is for Interface
"David Bryant <bagnose@gmail.com>"
parents: 56
diff changeset
70 override bool handleKeyPress(scope IViewport viewport, in KeyEvent event) {
14
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
71 // writefln("%s", event);
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
72
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
73 return true;
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
74 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
75
57
9960c4fbd0dd I is for Interface
"David Bryant <bagnose@gmail.com>"
parents: 56
diff changeset
76 override bool handleKeyRelease(scope IViewport viewport, in KeyEvent event) {
14
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
77 // writefln("%s", event);
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
78
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
79 return true;
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
80 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
81
57
9960c4fbd0dd I is for Interface
"David Bryant <bagnose@gmail.com>"
parents: 56
diff changeset
82 override bool handleMotion(scope IViewport viewport, in MotionEvent event) {
17
c643c04e3f5e Checkpoint
David Bryant <daveb@acres.com.au>
parents: 16
diff changeset
83 //writefln("%s", event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
84
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
85 if (_grabbedTool is null) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
86 foreach_reverse(ref tool; _tools) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
87 if (tool.handleMotion(viewport, event)) {
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
88 break;
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
89 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
90 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
91 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
92 else {
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
93 _grabbedTool.handleMotion(viewport, event);
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
94 }
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
95
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
96 return true;
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
97 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
98
57
9960c4fbd0dd I is for Interface
"David Bryant <bagnose@gmail.com>"
parents: 56
diff changeset
99 override bool handleScroll(scope IViewport viewport, in ScrollEvent event) {
14
0b7e7d43a79d Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 12
diff changeset
100 // writefln("%s", event);
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
101
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
102 if (_grabbedTool is null) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
103 foreach_reverse(ref tool; _tools) {
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
104 if (tool.handleScroll(viewport, event)) {
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
105 break;
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
106 }
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
107 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
108 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
109 else {
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
110 _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
111 }
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 return true;
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
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 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
118 }
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 override void pop() {
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
121 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
122
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
123 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
124 }
7
936feb16eed4 Checkpoint
"David Bryant <bagnose@gmail.com>"
parents: 6
diff changeset
125 */
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
126
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
127 private {
48
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
128 Tool[] _tools;
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
129 Tool * _grabbedTool;
1b4c9ba58673 Stylistic overhaul.
daveb
parents: 36
diff changeset
130 ButtonName _grabbedButton;
2
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
131 }
d6f44347373d * Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff changeset
132 }