Fix Bug with Zoom in Viewer
authorgreg
Tue, 02 Jun 2009 17:35:22 +0200
changeset 363 5eb9c5536334
parent 362 f56181aa99ea
child 364 deee68313770
Fix Bug with Zoom in Viewer
Viewer.py
--- a/Viewer.py	Sat May 30 17:16:11 2009 +0200
+++ b/Viewer.py	Tue Jun 02 17:35:22 2009 +0200
@@ -450,10 +450,10 @@
         self.Flush()
         self.ResetView()
     
-    def SetScale(self, scale_number):
+    def SetScale(self, scale_number, refresh=True):
         self.CurrentScale = max(0, min(scale_number, len(ZOOM_FACTORS) - 1))
         self.ViewScale = (ZOOM_FACTORS[self.CurrentScale], ZOOM_FACTORS[self.CurrentScale])
-        self.RefreshScaling()
+        self.RefreshScaling(refresh)
 
     def GetScale(self):
         return self.CurrentScale
@@ -642,6 +642,7 @@
             self.PageSize = None
             self.PagePen = wx.TRANSPARENT_PEN
         if refresh:
+            self.RefreshVisibleElements()
             self.Refresh(False)
         
         
@@ -2808,14 +2809,23 @@
                 self.Scroll(xp, y)
             elif event.ControlDown():
                 dc = self.GetLogicalDC()
+                self.Freeze()
                 pos = event.GetLogicalPosition(dc)
                 mouse_pos = event.GetPosition()
-                self.SetScale(self.CurrentScale + rotation)
-                self.Scroll(round(pos.x * self.ViewScale[0] - mouse_pos.x) / SCROLLBAR_UNIT,
-                            round(pos.y * self.ViewScale[1] - mouse_pos.y) / SCROLLBAR_UNIT)
-                self.RefreshScrollBars()
+                self.SetScale(self.CurrentScale + rotation, False)
+                xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
+                ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
+                scrollx = max(0, round(pos.x * self.ViewScale[0] - mouse_pos.x) / SCROLLBAR_UNIT)
+                scrolly = max(0, round(pos.y * self.ViewScale[1] - mouse_pos.y) / SCROLLBAR_UNIT)
+                if scrollx > xmax or scrolly > ymax:
+                    self.RefreshScrollBars(max(0, scrollx - xmax), max(0, scrolly - ymax))
+                    self.Scroll(scrollx, scrolly)
+                else:
+                    self.Scroll(scrollx, scrolly)
+                    self.RefreshScrollBars()
                 self.RefreshVisibleElements()
                 self.Refresh()
+                self.Thaw()
                 self.ParentWindow.RefreshDisplayMenu()
             else:
                 x, y = self.GetViewStart()