diff standard_tools.d @ 2:d6f44347373d

* Switched over to geometry done with structs instead of classes. * Removed direct access to gtk structs * Refactoring
author David Bryant <daveb@acres.com.au>
date Fri, 10 Jul 2009 15:15:27 +0930
parents
children 7d57cae10805
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/standard_tools.d	Fri Jul 10 15:15:27 2009 +0930
@@ -0,0 +1,56 @@
+module standard_tools;
+
+final class PanTool : Tool {
+    override bool handle_scroll(ICanvas canvas, ScrollEvent event) {
+        const double AMOUNT = 30.0;
+        Vector2 v;
+
+        if (event.mask.query(Modifier.SHIFT)) {
+            // left to right
+            v = new Vector2(AMOUNT, 0.0);
+        }
+        else {
+            // down to up
+            v = new Vector2(0.0, AMOUNT);
+        }
+
+        if (event.scroll_direction == ScrollDirection.UP) {
+            v = -v;
+        }
+
+        canvas.rel_pan(v);
+
+        return true;
+    }
+
+    bool handle_button_press(ICanvas canvas, ButtonEvent event) {
+    }
+
+    bool handle_button_release(ICanvas canvas, ButtonEvent event) {
+    }
+
+    bool handle_motion(ICanvas canvas, MotionEvent event) {
+    }
+}
+
+final class ZoomTool {
+    static invariant double ZOOM = 1.44;
+
+    override bool handle_scroll(ICanvas canvas, ScrollEvent event) {
+        if (event.mask.query(Modifier.CONTROL)) {
+            // Zoom about the pointer
+            double zoom = 1.44;
+
+            if (event.scroll_direction == ScrollDirection.DOWN) {
+                zoom = 1.0 / zoom;
+            }
+
+            canvas.rel_zoom(event.screen_point(), zoom);
+
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
+}