Hi folks,

I got this note from a user, and thought I'd post it here, to capture
the conversation for posterity...

Stay tuned for follow-up messages...

-Chris


---------- Forwarded message ----------
From: Ralf Werner <[email protected]>
Date: Tue, Mar 19, 2013 at 10:45 AM
Subject: ZoomToPoint Patch for Floatcanvas
To: [email protected]


Hello Chris,

im implemented a new Zoom method for Floatcanvas. I call
it ZoomToPoint. Its a Google Map style zoom.
I hope i broke nothing else and it is usefull for others.

Contributing code is a bit difficult for me. I use git. Git force
me do download the complete wxwidgets archive. This takes
forever. Im have it not done until now.

gruß ralf


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected]
diff --git a/floatcanvas/FloatCanvas.py b/floatcanvas/FloatCanvas.py
index 58cecc7..78650ca 100644
--- a/floatcanvas/FloatCanvas.py
+++ b/floatcanvas/FloatCanvas.py
@@ -303,7 +303,7 @@
             self.Pen = wx.TRANSPARENT_PEN
             self.LineStyle = 'Transparent'
         else:
-             self.Pen = self.PenList.setdefault( (LineColor,LineStyle,LineWidth),  wx.Pen(LineColor,LineWidth,self.LineStyleList[LineStyle]) )
+            self.Pen = self.PenList.setdefault( (LineColor,LineStyle,LineWidth),  wx.Pen(LineColor,LineWidth,self.LineStyleList[LineStyle]) )
 
     def SetHitBrush(self,HitColor):
         if not self.HitFill:
@@ -2951,6 +2951,31 @@
                 center = N.array(center,N.float)
             self.ViewPortCenter = center
         self.SetToNewScale()
+    
+    def ZoomToPoint(self, factor, point, coordType = "pixel"):
+
+        """
+        Zoom (factor) changes the amount of zoom of the image by factor.
+        If factor is greater than one, the image gets larger.
+        If factor is less than one, the image gets smaller.       
+        
+        point is a tuple of (x, y) coordinates from the center of the zoom
+        
+        coordType is a flag indicating whether the point given is in pixel or world
+        coordType Options are: "world" or "pixel" 
+        """
+        if coordType == "pixel":
+            oldpoint = self.PixelToWorld( point )
+        else:
+            oldpoint = N.array(point,N.float)
+        self.Scale = self.Scale*factor        
+        self.SetToNewScale(False)
+        if coordType == "pixel":
+            newpoint = self.PixelToWorld( point )
+        else:
+            newpoint = N.array(point,N.float)
+        delta = (newpoint - oldpoint)
+        self.MoveImage(-delta, 'World')        
 
     def ZoomToBB(self, NewBB=None, DrawFlag=True):
 
diff --git a/floatcanvas/GUIMode.py b/floatcanvas/GUIMode.py
index 13fae96..5d194cb 100644
--- a/floatcanvas/GUIMode.py
+++ b/floatcanvas/GUIMode.py
@@ -161,6 +161,10 @@
             self.Canvas._RaiseMouseEvent(event, EventType)
 
     def OnWheel(self, event):
+        if event.GetWheelRotation() < 0:
+            self.Canvas.ZoomToPoint(0.9, event.GetPosition())
+        else:
+            self.Canvas.ZoomToPoint(1.1, event.GetPosition())
         EventType = FloatCanvas.EVT_FC_MOUSEWHEEL
         self.Canvas._RaiseMouseEvent(event, EventType)
 
@@ -212,7 +216,8 @@
             self.MoveTimer.Start(30, oneShot=True)
 
     def OnMoveTimer(self, event=None):
-        self.Canvas.Draw()
+        #self.Canvas.Draw()
+        pass
 
     def UpdateScreen(self):
         ## The screen has been re-drawn, so StartMove needs to be reset.
@@ -283,9 +288,9 @@
            By default, zoom in/out by a 0.1 factor per Wheel event.
         """
         if event.GetWheelRotation() < 0:
-            self.Canvas.Zoom(0.9)
+            self.Canvas.ZoomToPoint(0.9, event.GetPosition())
         else:
-            self.Canvas.Zoom(1.1)
+            self.Canvas.ZoomToPoint(1.1, event.GetPosition())
 
 class GUIZoomIn(GUIBase):
  
_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to