Mercurial > projects > doodle
annotate standard_tools.d @ 7:936feb16eed4
Checkpoint
author | "David Bryant <bagnose@gmail.com>" |
---|---|
date | Sat, 11 Jul 2009 21:29:03 +0930 |
parents | 7d57cae10805 |
children | bf7903435f58 |
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 | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
9 final class PanTool : Tool { |
7 | 10 bool handle_button_press(ICanvas canvas, in ButtonEvent event) { |
11 if (event.button_name == ButtonName.MIDDLE) { | |
12 return true; | |
13 } | |
14 else { | |
15 return false; | |
16 } | |
17 } | |
18 | |
19 bool handle_button_release(ICanvas canvas, in ButtonEvent event) { | |
20 return false; | |
21 } | |
22 | |
23 bool handle_motion(ICanvas canvas, in MotionEvent event) { | |
24 return false; | |
25 } | |
26 | |
27 bool handle_scroll(ICanvas canvas, in ScrollEvent event) { | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
28 const double AMOUNT = 30.0; |
3
7d57cae10805
Renamed geometry2 to geometry
David Bryant <daveb@acres.com.au>
parents:
2
diff
changeset
|
29 Vector v; |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
30 |
7 | 31 if (event.mask.is_set(Modifier.SHIFT)) { |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
32 // left to right |
7 | 33 v = Vector(AMOUNT, 0.0); |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
34 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
35 else { |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
36 // down to up |
7 | 37 v = Vector(0.0, AMOUNT); |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
38 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
39 |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
40 if (event.scroll_direction == ScrollDirection.UP) { |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
41 v = -v; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
42 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
43 |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
44 canvas.rel_pan(v); |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
45 |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
46 return true; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
47 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
48 |
7 | 49 bool handle_key_press(ICanvas canvas, in KeyEvent event) { |
50 return false; | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
51 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
52 |
7 | 53 bool handle_key_release(ICanvas canvas, in KeyEvent event) { |
54 return false; | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
55 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
56 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
57 |
7 | 58 final class ZoomTool : Tool { |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
59 static invariant double ZOOM = 1.44; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
60 |
7 | 61 bool handle_button_press(ICanvas canvas, in ButtonEvent event) { |
62 return false; | |
63 } | |
64 | |
65 bool handle_button_release(ICanvas canvas, in ButtonEvent event) { | |
66 return false; | |
67 } | |
68 | |
69 bool handle_motion(ICanvas canvas, in MotionEvent event) { | |
70 return false; | |
71 } | |
72 | |
73 bool handle_scroll(ICanvas canvas, in ScrollEvent event) { | |
74 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
|
75 // Zoom about the pointer |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
76 double zoom = 1.44; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
77 |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
78 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
|
79 zoom = 1.0 / zoom; |
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 |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
82 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
|
83 |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
84 return true; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
85 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
86 else { |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
87 return false; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
88 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
89 } |
7 | 90 |
91 bool handle_key_press(ICanvas canvas, in KeyEvent event) { | |
92 return false; | |
93 } | |
94 | |
95 bool handle_key_release(ICanvas canvas, in KeyEvent event) { | |
96 return false; | |
97 } | |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
98 } |