changeset 36:188397ef9a12

Late night tinkering
author David Bryant <bagnose@gmail.com>
date Sun, 30 Aug 2009 23:36:31 +0930
parents 3f6bb0bb22dc
children bc0035393a81
files doodle/common/undo.d doodle/dia/grid_layer.d doodle/dia/icanvas.d doodle/dia/page_layer.d doodle/dia/standard_tools.d doodle/dia/tool_layer.d
diffstat 6 files changed, 57 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/doodle/common/undo.d	Sun Aug 30 22:14:01 2009 +0930
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-module doodle.common.undo;
-
-abstract class Action {
-    void undo();
-    void redo();
-}
-
-interface IUndoObserver {
-    void canUndo(in bool value, in string description);
-    void canRedo(in bool value, in string description);
-}
-
-interface IUndoManager {
-    void addAction(Action action);
-}
--- a/doodle/dia/grid_layer.d	Sun Aug 30 22:14:01 2009 +0930
+++ b/doodle/dia/grid_layer.d	Sun Aug 30 23:36:31 2009 +0930
@@ -22,6 +22,7 @@
 
     this(in string name) {
         super(name);
+        mZoomValid = false;
     }
 
     // Layer overrides:
@@ -36,8 +37,12 @@
                        in Rectangle model_damage, scope Context model_cr) const {
         assert(mZoomValid);
 
+        double xx = 1.0, yy = 1.0;
+        model_cr.userToDeviceDistance(xx, yy);
+
         model_cr.save(); {
-            model_cr.setLineWidth(1.0);
+            model_cr.setSourceRgba(0.0, 0.0, 0.0, 0.3);
+            model_cr.setLineWidth(0.5);
 
             {
                 // vertical grid lines
@@ -47,7 +52,13 @@
 
                 for (;;) {
                     line(model_cr, x, y0, x, y1);
-                    model_cr.stroke();
+
+                    // Ensure 1 pixel wide FIXME is this naughty? We are sneaking
+                    // through cairo to mix model and pixel coordinates...
+                    model_cr.save(); {
+                        model_cr.scale(1.0 / xx, 1.0 / yy);
+                        model_cr.stroke();
+                    } model_cr.restore();
 
                     if (x > model_damage.max_corner.x) {
                         break;
@@ -65,7 +76,11 @@
 
                 for (;;) {
                     line(model_cr, x0, y, x1, y);
-                    model_cr.stroke();
+
+                    model_cr.save(); {
+                        model_cr.scale(1.0 / xx, 1.0 / yy);
+                        model_cr.stroke();
+                    } model_cr.restore();
 
                     if (y > model_damage.max_corner.y) {
                         break;
@@ -75,20 +90,20 @@
                 }
             }
         } model_cr.restore();
-
-
-        //double start_x = modf(damage.min_corner.x, zoom);
     }
 
     // Grid overrides:
 
-    void zoom_changed(double zoom) {
+    override void zoom_changed(double zoom) {
         mZoom = zoom;
         mZoomValid = true;
-        mSpacing = 20.0;        // mm
+
+        // FIXME compute spacing properly
+        mSpacing = 10.0 / mZoom;        // mm
     }
 
-    bool snap(in Point a, out Point b) const {
+    // FIXME use inout parameter?
+    override bool snap(in Point a, out Point b) const {
         b = a;
         return false;
     }
--- a/doodle/dia/icanvas.d	Sun Aug 30 22:14:01 2009 +0930
+++ b/doodle/dia/icanvas.d	Sun Aug 30 23:36:31 2009 +0930
@@ -52,10 +52,14 @@
 interface Grid {
     void zoom_changed(double zoom);
 
-    // TODO 
+    // TODO  inout?
     bool snap(in Point a, out Point b) const;
 }
 
+interface Page {
+    // TODO
+}
+
 abstract class Layer {
     this(in string name) {
         mName = name;
--- a/doodle/dia/page_layer.d	Sun Aug 30 22:14:01 2009 +0930
+++ b/doodle/dia/page_layer.d	Sun Aug 30 23:36:31 2009 +0930
@@ -1,14 +1,11 @@
 module doodle.dia.page_layer;
 
-private {
-    import doodle.cairo.routines;
-}
-
 public {
     import doodle.dia.icanvas;
 }
 
-interface Page {
+private {
+    import doodle.cairo.routines;
 }
 
 class PageLayer : Layer, Page {
@@ -18,6 +15,8 @@
         //mPageGeometry = Rectangle(Point.DEFAULT, Vector(100.0, 100.0));
     }
 
+    // Layer overrides:
+
     override Rectangle bounds() const {
         return mPageGeometry;
     }
@@ -40,6 +39,8 @@
         } model_cr.restore;
     }
 
+    // Page overrides:
+
     private {
         Rectangle mPageGeometry;
     }
--- a/doodle/dia/standard_tools.d	Sun Aug 30 22:14:01 2009 +0930
+++ b/doodle/dia/standard_tools.d	Sun Aug 30 23:36:31 2009 +0930
@@ -89,7 +89,7 @@
     }
 }
 
-final class LassoTool : Tool {
+final class LassoTool : Tool {      // TODO convert to SelectTool
     override bool handle_button_press(scope Viewport viewport, in ButtonEvent event) {
         if (event.button_name == ButtonName.LEFT) {
             mActive = true;
--- a/doodle/dia/tool_layer.d	Sun Aug 30 22:14:01 2009 +0930
+++ b/doodle/dia/tool_layer.d	Sun Aug 30 23:36:31 2009 +0930
@@ -1,20 +1,37 @@
 module doodle.dia.tool_layer;
 
+public {
+    import doodle.dia.tool;
+}
+
 private {
     import std.stdio;
     import doodle.cairo.routines;
 }
 
-public {
-    import doodle.dia.tool;
-}
-
 class ToolLayer : Layer, EventHandler {
     this(in Tool[] tools, in string name) {
         super(name);
         mTools = tools.dup;
     }
 
+    // Layer overrides:
+
+    override Rectangle bounds() const {
+        return Rectangle();
+    }
+
+    override void draw(const Viewport viewport,
+                       in Rectangle pixel_damage, scope Context pixel_cr,
+                       in Rectangle model_damage, scope Context model_cr) const {
+        // FIXME this isn't how we will really draw the tools...
+        foreach (const Tool tool; mTools) {
+            tool.draw(viewport, pixel_damage, pixel_cr, model_damage, model_cr);
+        }
+    }
+
+    // EventHandler overrides:
+
     override bool handle_button_press(scope Viewport viewport, in ButtonEvent event) {
         // writefln("%s", event);
 
@@ -94,19 +111,6 @@
         return true;
     }
 
-    override Rectangle bounds() const {
-        return Rectangle();
-    }
-
-    override void draw(const Viewport viewport,
-                       in Rectangle pixel_damage, scope Context pixel_cr,
-                       in Rectangle model_damage, scope Context model_cr) const {
-        // FIXME this isn't how we will really draw the tools...
-        foreach (const Tool tool; mTools) {
-            tool.draw(viewport, pixel_damage, pixel_cr, model_damage, model_cr);
-        }
-    }
-
     /*
     override void push(Tool tool) {
     }