changeset 62:6c3993f4c3eb

Checkpoint
author daveb
date Thu, 12 Aug 2010 11:48:55 +0930
parents 08ffc44fc21a
children 20d6327c4a75
files configure.d doodle/gtk/canvas.d doodle/tk/geometry.d
diffstat 3 files changed, 53 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/configure.d	Wed Aug 11 15:07:58 2010 +0930
+++ b/configure.d	Thu Aug 12 11:48:55 2010 +0930
@@ -73,14 +73,8 @@
 
     // set up scripts
     {
-        auto file = File(targetPath.join("environment"), "w");
-        file.writefln("SOURCE_PATH=%s", sourcePath);
-        file.writefln("TARGET_PATH=%s", targetPath);
-    }
-    {
         auto file = File(targetPath.join("build"), "w");
         file.writefln("#!/bin/bash");
-        file.writefln("source %s", targetPath.join("environment"));
         file.writefln("%s %s %s", binPath.join("builder"), sourcePath, targetPath);
     }
     system("chmod +x " ~ targetPath.join("build"));
--- a/doodle/gtk/canvas.d	Wed Aug 11 15:07:58 2010 +0930
+++ b/doodle/gtk/canvas.d	Thu Aug 12 11:48:55 2010 +0930
@@ -58,9 +58,9 @@
         _ppi = ppi;
 
         /*
-           writefln("Layer bounds: %s", layerBounds);
-           writefln("Canvas bounds: %s", _canvasBounds);
-           writefln("View centre: %s", _viewCentre);
+           trace("Layer bounds: %s", layerBounds);
+           trace("Canvas bounds: %s", _canvasBounds);
+           trace("View centre: %s", _viewCentre);
          */
 
         // Create our child widgets and register callbacks
@@ -136,6 +136,8 @@
                0, 0);
     }
 
+    // IViewport overrides:
+
     override void zoomRelative(in Point pixelDatum, in double factor) {
         // Work out pixel distance from current centre to datum,
         // Do the zoom, then work out the new centre that keeps the
@@ -190,15 +192,7 @@
 
     private {
 
-        void update_bounds() {
-        }
-
-
-        bool onConfigure(GdkEventConfigure * event, Widget widget) {
-            assert(widget is _drawingArea);
-
-            _viewSize = Vector(cast(double)event.width, cast(double)event.height);
-
+        void initialise() {
             Rectangle layerBounds = Rectangle.DEFAULT;
 
             foreach (ref layer; _layers) {
@@ -209,32 +203,53 @@
 
             Rectangle paddedLayerBounds = expand(move(layerBounds, - layerBounds.size), 2.0 * layerBounds.size);
 
-            if (!_hadConfigure) {
-                const double MM_PER_INCH = 25.4;
-                _zoom = 0.25 * _ppi / MM_PER_INCH;
+            //
+
+            const double MM_PER_INCH = 25.4;
+            _zoom = 0.25 * _ppi / MM_PER_INCH;
+
+            _canvasBounds = paddedLayerBounds;
+            _viewCentre = _canvasBounds.centre;
+
+            _grid.zoomChanged(_zoom);
+
+            updateAdjustments;
+            updateRulers;
+        }
+
+        void consolidateBounds() {
+            Rectangle layerBounds = Rectangle.DEFAULT;
+
+            foreach (ref layer; _layers) {
+                layerBounds = layerBounds | layer.bounds;
+            }
 
-                _canvasBounds = paddedLayerBounds;
-                _viewCentre = _canvasBounds.centre;
+            assert(layerBounds.valid);
+
+            Rectangle paddedLayerBounds = expand(move(layerBounds, - layerBounds.size), 2.0 * layerBounds.size);
+
+            Vector z = _viewSize / _zoom;
+            Rectangle r = Rectangle(_viewCentre - z / 2.0, z);
+            _canvasBounds = r | paddedLayerBounds;
 
-                _grid.zoomChanged(_zoom);
+            updateAdjustments;
+            updateRulers;
+        }
 
+        bool onConfigure(GdkEventConfigure * event, Widget widget) {
+            assert(widget is _drawingArea);
+
+            _viewSize = Vector(cast(double)event.width, cast(double)event.height);
+
+
+            if (!_hadConfigure) {
+                initialise;
                 _hadConfigure = true;
             }
             else {
-                // Use configure events as an opportunity
-                // to consolidate the canvas-bounds
-                // XXX nasty code.
-                Vector z = _viewSize / _zoom;
-                Rectangle r = Rectangle(_viewCentre - z / 2.0, z);
-                _canvasBounds = r | paddedLayerBounds;
+                consolidateBounds;
             }
 
-            updateAdjustments;
-            updateRulers;
-
-            //writefln("Canvas bounds: %s", _canvasBounds);
-            //writefln("View centre: %s", _viewCentre);
-
             return true;
         }
 
@@ -245,7 +260,7 @@
 
             int width, height;
             dr.getSize(width, height);
-            //writefln("Got expose %dx%d\n", width, height);
+            trace("Got expose %dx%d\n", width, height);
 
             scope modelCr = new Context(dr);
             scope pixelCr = new Context(dr);
@@ -258,7 +273,7 @@
 
             Rectangle model_damage = pixelToModel(pixel_damage);
 
-            //writefln("Pixel damage: %s, model damage: %s", pixel_damage, model_damage);
+            //trace("Pixel damage: %s, model damage: %s", pixel_damage, model_damage);
 
             modelCr.save; pixelCr.save; {
                 // Setup model context and clip
@@ -304,7 +319,7 @@
 
         bool onButtonPress(GdkEventButton * event, Widget widget) {
             assert(widget is _drawingArea);
-            //writefln("Got button event\n");
+            trace("Got button event\n");
 
             Point pixelPoint = Point(event.x + 0.5, _viewSize.y - (event.y + 0.5));
             Point modelPoint = pixelToModel(pixelPoint);
@@ -324,7 +339,6 @@
 
         bool onButtonRelease(GdkEventButton * event, Widget widget) {
             assert(widget is _drawingArea);
-            //writefln("Got button event\n");
 
             Point pixelPoint = Point(event.x + 0.5, _viewSize.y - (event.y + 0.5));
             Point modelPoint = pixelToModel(pixelPoint);
--- a/doodle/tk/geometry.d	Wed Aug 11 15:07:58 2010 +0930
+++ b/doodle/tk/geometry.d	Thu Aug 12 11:48:55 2010 +0930
@@ -43,7 +43,7 @@
         return Vector(_x - p._x, _y - p._y);
     }
 
-    string toString() const {
+    string toString() {
         return std.string.format("(%f, %f)", _x, _y);
     }
 
@@ -101,7 +101,7 @@
         return sqrt(_x * _x + _y * _y);
     }
 
-    string toString() const {
+    string toString() {
         return std.string.format("[%f, %f]", _x, _y);
     }
 
@@ -212,7 +212,7 @@
 
     Point centre() const { return _position + _size / 2.0; }
 
-    string toString() const {
+    string toString() {
         return std.string.format("{%s, %s}", _position, _size);
     }
 
@@ -327,7 +327,7 @@
     Point point() const { return _point; }
     Vector gradient() const { return _gradient; }
 
-    string toString() const {
+    string toString() {
         return std.string.format("{%s %s}", _point, _gradient);
     }
 
@@ -372,7 +372,7 @@
     Point begin() const { return _begin; }
     Point end() const { return _end; }
 
-    string toString() const {
+    string toString() {
         return std.string.format("{%s %s}", _begin, _end);
     }