diff doodle/tk/pixel_model.d @ 72:5cc2de64f6d0

Cautious Saturday night commits
author "David Bryant <bagnose@gmail.com>"
date Sun, 15 Aug 2010 00:30:03 +0930
parents 0f7cf6c6f206
children 15ca7d5cd1ed
line wrap: on
line diff
--- a/doodle/tk/pixel_model.d	Sat Aug 14 20:48:41 2010 +0930
+++ b/doodle/tk/pixel_model.d	Sun Aug 15 00:30:03 2010 +0930
@@ -18,20 +18,19 @@
 class PixelModel {
     this(in double zoom, in Rectangle canvasBounds, in Rectangle viewBounds) {
         _zoom = zoom;
-        _viewBounds = viewBounds;
-        _canvasBounds = canvasBounds;
+        _viewBoundsScreen = viewBounds;
+        _canvasBoundsModel = canvasBounds;
 
         // Choose the centre of the canvas as the centre of the view
-        _viewCentre = _canvasBounds.centre;
+        _viewCentreModel = _canvasBoundsModel.centre;
     }
 
     void consolidateCanvasBounds(in Rectangle requiredCanvasBounds) {
-        Rectangle r = pixelToModel(_viewBounds);
-        _canvasBounds = r | requiredCanvasBounds;
+        _canvasBoundsModel = pixelToModel(_viewBoundsScreen) | requiredCanvasBounds;
     }
 
     void canvasAccommodate(in Rectangle bounds) {
-        _canvasBounds = _canvasBounds | bounds;
+        _canvasBoundsModel = _canvasBoundsModel | bounds;
     }
 
     void zoomRelative(in double factor, in Point pixelDatum) {
@@ -40,28 +39,23 @@
         // pixel distance the same
 
         Point oldModelDatum = pixelToModel(pixelDatum);
-        Vector pixelDistance = modelToPixel(oldModelDatum - _viewCentre);
+        Vector pixelDistance = modelToPixel(oldModelDatum - _viewCentreModel);
         _zoom = clampZoom(zoom * factor);
-        _viewCentre = oldModelDatum - pixelToModel(pixelDistance);
+        _viewCentreModel = oldModelDatum - pixelToModel(pixelDistance);
     }
 
-    void panRelativePixel(in Vector pixelDisplacement) {
-        _viewCentre = _viewCentre + pixelToModel(pixelDisplacement);
-    }
-
-    void panRelativeModel(in Vector modelDisplacement) {
-        _viewCentre = _viewCentre + modelDisplacement;
-    }
+    void panRelativePixel(in Vector pixelDisplacement) { _viewCentreModel = _viewCentreModel + pixelToModel(pixelDisplacement); }
+    void panRelativeModel(in Vector modelDisplacement) { _viewCentreModel = _viewCentreModel + modelDisplacement; }
 
     // For normalZoom 1.0 -> 100% means the presentation on the screen is
     // one-to-one with real-life
     double normalZoom(in double pixelsPerMillimetre) const { return _zoom / pixelsPerMillimetre; }
     double zoom() const { return _zoom; }
-    Rectangle viewBounds() const { return _viewBounds; }
-    Rectangle canvasBounds() const { return _canvasBounds; }
+    Rectangle viewBounds() const { return _viewBoundsScreen; }
+    Rectangle canvasBounds() const { return _canvasBoundsModel; }
 
-    Point modelToPixel(in Point model) const { return _viewBounds.centre + _zoom * (model - _viewCentre); }
-    Point pixelToModel(in Point pixel) const { return _viewCentre + (pixel - _viewBounds.centre) / _zoom; }
+    Point modelToPixel(in Point model) const { return _viewBoundsScreen.centre + _zoom * (model - _viewCentreModel); }
+    Point pixelToModel(in Point pixel) const { return _viewCentreModel + (pixel - _viewBoundsScreen.centre) / _zoom; }
     Vector modelToPixel(in Vector model) const { return _zoom * model; }
     Vector pixelToModel(in Vector pixel) const { return pixel / _zoom; }
     Rectangle modelToPixel(in Rectangle model) const { return Rectangle(modelToPixel(model.position), modelToPixel(model.size)); }
@@ -72,9 +66,9 @@
 
         // Screen units are pixels
         // Model units are millimetres
-        double _zoom;               // pixels-per-millimetre
-        Rectangle _viewBounds;      // pixel: bounds of the viewport in pixels
-        Point _viewCentre;          // model: where in the model is the centre of our view
-        Rectangle _canvasBounds;    // model: the bounds of the canvas in millimetres
+        double    _zoom;                // pixels-per-millimetre
+        Rectangle _viewBoundsScreen;    // bounds of the viewport in pixels
+        Point     _viewCentreModel;     // where in the model is the centre of our view
+        Rectangle _canvasBoundsModel;   // the bounds of the canvas in millimetres
     }
 }