Mercurial > projects > doodle
annotate standard_tools.d @ 9:66b47e122b31
Checkpoint
author | "David Bryant <bagnose@gmail.com>" |
---|---|
date | Sat, 11 Jul 2009 22:06:09 +0930 |
parents | bf7903435f58 |
children | 71ca82e0eb76 |
rev | line source |
---|---|
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
1 module standard_tools; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
2 |
7 | 3 import tool; |
4 import icanvas; | |
5 import tk.types; | |
6 import tk.events; | |
7 import tk.geometry; | |
8 | 8 import std.math; |
7 | 9 |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
10 final class PanTool : Tool { |
7 | 11 bool handle_button_press(ICanvas canvas, in ButtonEvent event) { |
12 if (event.button_name == ButtonName.MIDDLE) { | |
8 | 13 mLastPosition = event.screen_point; |
7 | 14 return true; |
15 } | |
16 else { | |
17 return false; | |
18 } | |
19 } | |
20 | |
21 bool handle_button_release(ICanvas canvas, in ButtonEvent event) { | |
8 | 22 return true; |
7 | 23 } |
24 | |
25 bool handle_motion(ICanvas canvas, in MotionEvent event) { | |
8 | 26 if (event.mask.is_set(Modifier.BUTTON_MIDDLE)) { |
27 canvas.rel_pan(mLastPosition - event.screen_point); | |
28 mLastPosition = event.screen_point; | |
29 | |
30 return true; | |
31 } | |
32 else { | |
33 return false; | |
34 } | |
7 | 35 } |
36 | |
37 bool handle_scroll(ICanvas canvas, in ScrollEvent event) { | |
8 | 38 if (event.mask.is_unset(Modifier.BUTTON_MIDDLE)) { |
9 | 39 Vector delta; |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
40 |
8 | 41 switch (event.scroll_direction) { |
42 case ScrollDirection.UP: | |
9 | 43 delta = event.mask.is_set(Modifier.SHIFT) ? Vector(-AMOUNT, 0.0) : Vector(0.0, -AMOUNT); |
8 | 44 break; |
45 case ScrollDirection.DOWN: | |
9 | 46 delta = event.mask.is_set(Modifier.SHIFT) ? Vector(AMOUNT, 0.0) : Vector(0.0, AMOUNT); |
8 | 47 break; |
48 case ScrollDirection.LEFT: | |
9 | 49 delta = Vector(-AMOUNT, 0.0); |
8 | 50 break; |
51 case ScrollDirection.RIGHT: | |
9 | 52 delta = Vector(AMOUNT, 0.0); |
8 | 53 break; |
54 } | |
55 | |
9 | 56 canvas.rel_pan(delta); |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
57 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
58 |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
59 return true; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
60 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
61 |
7 | 62 bool handle_key_press(ICanvas canvas, in KeyEvent event) { |
63 return false; | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
64 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
65 |
7 | 66 bool handle_key_release(ICanvas canvas, in KeyEvent event) { |
67 return false; | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
68 } |
8 | 69 |
70 private { | |
71 Point mLastPosition; | |
9 | 72 static invariant double AMOUNT = 60.0; |
8 | 73 } |
2
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 |
7 | 76 final class ZoomTool : Tool { |
77 bool handle_button_press(ICanvas canvas, in ButtonEvent event) { | |
78 return false; | |
79 } | |
80 | |
81 bool handle_button_release(ICanvas canvas, in ButtonEvent event) { | |
82 return false; | |
83 } | |
84 | |
85 bool handle_motion(ICanvas canvas, in MotionEvent event) { | |
86 return false; | |
87 } | |
88 | |
89 bool handle_scroll(ICanvas canvas, in ScrollEvent event) { | |
90 if (event.mask.is_set(Modifier.CONTROL)) { | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
91 if (event.scroll_direction == ScrollDirection.DOWN) { |
9 | 92 canvas.rel_zoom(event.screen_point(), 1.0 / ZOOM); |
93 return true; | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
94 } |
9 | 95 else if (event.scroll_direction == ScrollDirection.UP) { |
96 canvas.rel_zoom(event.screen_point(), ZOOM); | |
97 return true; | |
98 } | |
99 else { | |
100 return false; | |
101 } | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
102 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
103 else { |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
104 return false; |
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 } |
7 | 107 |
108 bool handle_key_press(ICanvas canvas, in KeyEvent event) { | |
109 return false; | |
110 } | |
111 | |
112 bool handle_key_release(ICanvas canvas, in KeyEvent event) { | |
113 return false; | |
114 } | |
9 | 115 |
116 private { | |
117 static invariant double ZOOM = sqrt(2.0); | |
118 } | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
119 } |