Mercurial > projects > doodle
annotate standard_tools.d @ 8:bf7903435f58
Checkpoint
author | "David Bryant <bagnose@gmail.com>" |
---|---|
date | Sat, 11 Jul 2009 21:49:04 +0930 |
parents | 936feb16eed4 |
children | 66b47e122b31 |
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)) { |
39 const double AMOUNT = 60.0; | |
40 Vector v; | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
41 |
8 | 42 switch (event.scroll_direction) { |
43 case ScrollDirection.UP: | |
44 v = event.mask.is_set(Modifier.SHIFT) ? Vector(-AMOUNT, 0.0) : Vector(0.0, -AMOUNT); | |
45 break; | |
46 case ScrollDirection.DOWN: | |
47 v = event.mask.is_set(Modifier.SHIFT) ? Vector(AMOUNT, 0.0) : Vector(0.0, AMOUNT); | |
48 break; | |
49 case ScrollDirection.LEFT: | |
50 v = Vector(-AMOUNT, 0.0); | |
51 break; | |
52 case ScrollDirection.RIGHT: | |
53 v = Vector(AMOUNT, 0.0); | |
54 break; | |
55 } | |
56 | |
57 canvas.rel_pan(v); | |
2
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 |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
60 return true; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
61 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
62 |
7 | 63 bool handle_key_press(ICanvas canvas, in KeyEvent event) { |
64 return false; | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
65 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
66 |
7 | 67 bool handle_key_release(ICanvas canvas, in KeyEvent event) { |
68 return false; | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
69 } |
8 | 70 |
71 private { | |
72 Point mLastPosition; | |
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 { |
8 | 77 static invariant double ZOOM = sqrt(2.0); |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
78 |
7 | 79 bool handle_button_press(ICanvas canvas, in ButtonEvent event) { |
80 return false; | |
81 } | |
82 | |
83 bool handle_button_release(ICanvas canvas, in ButtonEvent event) { | |
84 return false; | |
85 } | |
86 | |
87 bool handle_motion(ICanvas canvas, in MotionEvent event) { | |
88 return false; | |
89 } | |
90 | |
91 bool handle_scroll(ICanvas canvas, in ScrollEvent event) { | |
92 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
|
93 // Zoom about the pointer |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
94 double zoom = 1.44; |
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 if (event.scroll_direction == ScrollDirection.DOWN) { |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
97 zoom = 1.0 / zoom; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
98 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
99 |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
100 canvas.rel_zoom(event.screen_point(), zoom); |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
101 |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
102 return true; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
103 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
104 else { |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
105 return false; |
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 } |
7 | 108 |
109 bool handle_key_press(ICanvas canvas, in KeyEvent event) { | |
110 return false; | |
111 } | |
112 | |
113 bool handle_key_release(ICanvas canvas, in KeyEvent event) { | |
114 return false; | |
115 } | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
116 } |