diff doodle/tk/pixel_model.d @ 79:535bae7a7305

Checkpoint
author "David Bryant <bagnose@gmail.com>"
date Sun, 15 Aug 2010 23:18:05 +0930
parents 024a5608087f
children
line wrap: on
line diff
--- a/doodle/tk/pixel_model.d	Sun Aug 15 15:19:14 2010 +0930
+++ b/doodle/tk/pixel_model.d	Sun Aug 15 23:18:05 2010 +0930
@@ -24,13 +24,8 @@
         _viewCentreModel = _canvasBoundsModel.centre;
     }
 
-    void consolidateCanvasBounds(in Rectangle requiredCanvasBounds) {
-        _canvasBoundsModel = screenToModel(_viewBoundsScreen) | requiredCanvasBounds;
-    }
-
-    void canvasAccommodate(in Rectangle bounds) {
-        _canvasBoundsModel = _canvasBoundsModel | bounds;
-    }
+    void consolidateCanvasBounds(in Rectangle requiredCanvasBounds) { _canvasBoundsModel = screenToModel(_viewBoundsScreen) | requiredCanvasBounds; }
+    void canvasAccommodate(in Rectangle bounds) { _canvasBoundsModel = _canvasBoundsModel | bounds; }
 
     void zoomRelative(in double factor, in Point screenDatum) {
         // Work out screen distance from current centre to datum,
@@ -46,12 +41,13 @@
     void panRelativeScreen(in Vector screenDisplacement) { _viewCentreModel = _viewCentreModel + screenToModel(screenDisplacement); }
     void panRelativeModel(in Vector modelDisplacement) { _viewCentreModel = _viewCentreModel + modelDisplacement; }
 
-    // For userZoom 1.0 -> 100% means the presentation on the screen is
-    // one-to-one with real-life
-    double userZoom(in double screensPerMillimetre) const { return _zoom / screensPerMillimetre; }
+    // For userZoom 1.0 -> 100% means the presentation on the screen is one-to-one with real-life
+    double userZoom(in double pixelsPerMillimetre) const { return _zoom / pixelsPerMillimetre; }
     double zoom() const { return _zoom; }
     Rectangle viewBoundsScreen() const { return _viewBoundsScreen; }
+    Rectangle viewBoundsModel() const { return screenToModel(_viewBoundsScreen); }
     Rectangle canvasBoundsModel() const { return _canvasBoundsModel; }
+    Rectangle canvasBoundsScreen() const { return modelToScreen(_canvasBoundsModel); }
 
     Point modelToScreen(in Point model) const { return _viewBoundsScreen.centre + _zoom * (model - _viewCentreModel); }
     Point screenToModel(in Point screen) const { return _viewCentreModel + (screen - _viewBoundsScreen.centre) / _zoom; }
@@ -61,7 +57,7 @@
     Rectangle screenToModel(in Rectangle model) const { return Rectangle(screenToModel(model.position), screenToModel(model.size)); }
 
     private {
-        static double clampZoom(in double zoom) { return clamp(zoom, 0.1, 10.0); }
+        static double clampZoom(in double zoom) { return clamp(zoom, 1e-1, 1e2); }
 
         // Screen units are pixels
         // Model units are millimetres