Mercurial > projects > doodle
annotate doodle/dia/standard_tools.d @ 92:a98116479793
Removed GL support. Improved grid.
author | daveb |
---|---|
date | Fri, 20 Aug 2010 18:34:32 +0930 |
parents | b759414d2b72 |
children |
rev | line source |
---|---|
28
1754cb773d41
Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
27
diff
changeset
|
1 module doodle.dia.standard_tools; |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
2 |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
14
diff
changeset
|
3 public { |
28
1754cb773d41
Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
27
diff
changeset
|
4 import doodle.dia.tool; |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
14
diff
changeset
|
5 } |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
14
diff
changeset
|
6 |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
14
diff
changeset
|
7 private { |
63
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
8 import gdk.Keysyms; |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
14
diff
changeset
|
9 } |
7 | 10 |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
11 final class PanTool : Tool { |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
12 this() { |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
13 super("Pan"); |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
14 } |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
15 |
57 | 16 override bool handleButtonPress(scope IViewport viewport, in ButtonEvent event) { |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
17 if (event.buttonName == ButtonName.MIDDLE) { |
80
b759414d2b72
Switched from cairo to Drawable abstraction
"David Bryant <bagnose@gmail.com>"
parents:
64
diff
changeset
|
18 mLastPosition = event.screenPoint; |
7 | 19 return true; |
20 } | |
21 else { | |
22 return false; | |
23 } | |
24 } | |
25 | |
57 | 26 override bool handleMotion(scope IViewport viewport, in MotionEvent event) { |
48 | 27 if (event.mask.isSet(Modifier.MIDDLE_BUTTON)) { |
80
b759414d2b72
Switched from cairo to Drawable abstraction
"David Bryant <bagnose@gmail.com>"
parents:
64
diff
changeset
|
28 viewport.panRelative(mLastPosition - event.screenPoint); |
b759414d2b72
Switched from cairo to Drawable abstraction
"David Bryant <bagnose@gmail.com>"
parents:
64
diff
changeset
|
29 mLastPosition = event.screenPoint; |
8 | 30 |
31 return true; | |
32 } | |
33 else { | |
34 return false; | |
35 } | |
7 | 36 } |
37 | |
57 | 38 override bool handleScroll(scope IViewport viewport, in ScrollEvent event) { |
48 | 39 if (event.mask.isUnset(Modifier.MIDDLE_BUTTON)) { |
9 | 40 Vector delta; |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
41 |
48 | 42 switch (event.scrollDirection) { |
8 | 43 case ScrollDirection.UP: |
63
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
44 delta = event.mask.isSet(Modifier.SHIFT) ? Vector(-SCROLL_AMOUNT, 0.0) : Vector(0.0, SCROLL_AMOUNT); |
8 | 45 break; |
46 case ScrollDirection.DOWN: | |
63
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
47 delta = event.mask.isSet(Modifier.SHIFT) ? Vector(SCROLL_AMOUNT, 0.0) : Vector(0.0, -SCROLL_AMOUNT); |
8 | 48 break; |
49 case ScrollDirection.LEFT: | |
63
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
50 delta = Vector(-SCROLL_AMOUNT, 0.0); |
8 | 51 break; |
52 case ScrollDirection.RIGHT: | |
63
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
53 delta = Vector(SCROLL_AMOUNT, 0.0); |
8 | 54 break; |
40 | 55 default: |
56 assert(0); | |
8 | 57 } |
58 | |
48 | 59 viewport.panRelative(delta); |
2
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 |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
62 return true; |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
63 } |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
64 |
63
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
65 override bool handleKeyPress(scope IViewport viewport, in KeyEvent event) { |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
66 // Respond to arrow keys and pg-up/pg-down |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
67 |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
68 switch (event.value) { |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
69 case GdkKeysyms.GDK_Up: |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
70 viewport.panRelative(Vector(0.0, ARROW_AMOUNT)); |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
71 return true; |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
72 case GdkKeysyms.GDK_Right: |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
73 viewport.panRelative(Vector(ARROW_AMOUNT, 0.0)); |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
74 return true; |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
75 case GdkKeysyms.GDK_Left: |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
76 viewport.panRelative(Vector(-ARROW_AMOUNT, 0.0)); |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
77 return true; |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
78 case GdkKeysyms.GDK_Down: |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
79 viewport.panRelative(Vector(0.0, -ARROW_AMOUNT)); |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
80 return true; |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
81 case GdkKeysyms.GDK_Page_Up: |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
82 viewport.panRelative(Vector(0.0, PAGE_AMOUNT)); |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
83 return true; |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
84 case GdkKeysyms.GDK_Page_Down: |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
85 viewport.panRelative(Vector(0.0, -PAGE_AMOUNT)); |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
86 return true; |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
87 default: |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
88 // Just a key we don't handle |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
89 return false; |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
90 } |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
91 } |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
92 |
8 | 93 private { |
94 Point mLastPosition; | |
63
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
95 static immutable SCROLL_AMOUNT = 60.0; |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
96 static immutable ARROW_AMOUNT = 30.0; |
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
58
diff
changeset
|
97 static immutable PAGE_AMOUNT = 240.0; |
8 | 98 } |
2
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 |
7 | 101 final class ZoomTool : Tool { |
58
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
102 this() { |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
103 super("Zoom"); |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
104 } |
c63719604adb
Beginnings of creating a rectangle...
"David Bryant <bagnose@gmail.com>"
parents:
57
diff
changeset
|
105 |
57 | 106 override bool handleScroll(scope IViewport viewport, in ScrollEvent event) { |
48 | 107 if (event.mask.isSet(Modifier.CONTROL)) { |
108 if (event.scrollDirection == ScrollDirection.DOWN) { | |
92 | 109 viewport.zoomRelative(1.0 / ZOOM_FACTOR, event.screenPoint); |
9 | 110 return true; |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
111 } |
48 | 112 else if (event.scrollDirection == ScrollDirection.UP) { |
92 | 113 viewport.zoomRelative(ZOOM_FACTOR, event.screenPoint); |
9 | 114 return true; |
115 } | |
116 else { | |
117 return false; | |
118 } | |
2
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 else { |
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
121 return false; |
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 } |
7 | 124 |
9 | 125 private { |
92 | 126 static immutable ZOOM_FACTOR = 2^^0.5; |
9 | 127 } |
2
d6f44347373d
* Switched over to geometry done with structs instead of classes.
David Bryant <daveb@acres.com.au>
parents:
diff
changeset
|
128 } |