Mercurial > projects > doodle
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 |
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 | 3 public { |
4 import doodle.dia.tool; | |
5 } | |
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 | 12 class ToolLayer : Layer, EventHandler { |
13 this(in Tool[] tools, in string name) { | |
14 super(name); | |
48 | 15 _tools = tools.dup; |
7 | 16 } |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
17 |
36 | 18 // Layer overrides: |
19 | |
20 override Rectangle bounds() const { | |
21 return Rectangle(); | |
22 } | |
23 | |
24 override void draw(const Viewport viewport, | |
48 | 25 in Rectangle pixelDamage, scope Context pixelCr, |
26 in Rectangle modelDamage, scope Context modelCr) const { | |
36 | 27 // FIXME this isn't how we will really draw the tools... |
48 | 28 foreach (const Tool tool; _tools) { |
29 tool.draw(viewport, pixelDamage, pixelCr, modelDamage, modelCr); | |
36 | 30 } |
31 } | |
32 | |
33 // EventHandler overrides: | |
34 | |
48 | 35 override bool handleButtonPress(scope Viewport viewport, in ButtonEvent event) { |
14 | 36 // writefln("%s", event); |
7 | 37 |
48 | 38 if (_grabbedTool is null) { |
39 foreach_reverse(ref tool; _tools) { | |
40 if (tool.handleButtonPress(viewport, event)) { | |
41 _grabbedTool = &tool; | |
42 _grabbedButton = event.button_name; | |
7 | 43 break; |
44 } | |
45 } | |
46 } | |
47 else { | |
48 | 48 _grabbedTool.handleButtonPress(viewport, event); |
7 | 49 } |
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 | 54 override bool handleButtonRelease(scope Viewport viewport, in ButtonEvent event) { |
14 | 55 // writefln("%s", event); |
7 | 56 |
48 | 57 if (_grabbedTool !is null) { |
58 _grabbedTool.handleButtonRelease(viewport, event); | |
7 | 59 |
48 | 60 if (_grabbedButton == event.button_name) { |
61 _grabbedTool = null; | |
7 | 62 } |
63 } | |
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 | 68 override bool handleKeyPress(scope Viewport viewport, in KeyEvent event) { |
14 | 69 // writefln("%s", event); |
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 | 74 override bool handleKeyRelease(scope Viewport viewport, in KeyEvent event) { |
14 | 75 // writefln("%s", event); |
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 | 80 override bool handleMotion(scope Viewport viewport, in MotionEvent event) { |
17 | 81 //writefln("%s", event); |
7 | 82 |
48 | 83 if (_grabbedTool is null) { |
84 foreach_reverse(ref tool; _tools) { | |
85 if (tool.handleMotion(viewport, event)) { | |
7 | 86 break; |
87 } | |
88 } | |
89 } | |
90 else { | |
48 | 91 _grabbedTool.handleMotion(viewport, event); |
7 | 92 } |
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 | 97 override bool handleScroll(scope Viewport viewport, in ScrollEvent event) { |
14 | 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 | 100 if (_grabbedTool is null) { |
101 foreach_reverse(ref tool; _tools) { | |
102 if (tool.handleScroll(viewport, event)) { | |
7 | 103 break; |
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 | 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 | 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 | 126 Tool[] _tools; |
127 Tool * _grabbedTool; | |
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 } |