[pypy-svn] r7285 - pypy/trunk/src/pypy/translator/tool/pygame

bob at codespeak.net bob at codespeak.net
Tue Nov 16 14:41:12 CET 2004


Author: bob
Date: Tue Nov 16 14:41:11 2004
New Revision: 7285

Modified:
   pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py
   pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py
Log:
ugly hack to clamp panning



Modified: pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py	(original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py	Tue Nov 16 14:41:11 2004
@@ -181,9 +181,9 @@
         scale = max(min(scale, self.SCALEMAX), self.SCALEMIN)
         self.scale = float(scale)
         w, h = self.graphlayout.boundingbox
-        self.margin = int(self.MARGIN*scale)
-        self.width = int((w + 2*self.MARGIN)*scale)
-        self.height = int((h + 2*self.MARGIN)*scale)
+        self.margin = int(self.MARGIN * scale)
+        self.width = int(w * scale) + (2 * self.margin)
+        self.height = int(h * scale) + (2 * self.margin)
         self.bboxh = h
         size = int(15 * (scale-10) / 75)
         self.font = self.getfont(size)
@@ -228,19 +228,37 @@
         newx, newy = self.map(x, y)
         self.shiftoffset(newx - fixx, newy - fixy)
 
+    def reoffset(self, swidth, sheight):
+        offsetx = noffsetx = self.ofsx
+        offsety = noffsety = self.ofsy
+        width = self.width
+        height = self.height
+
+        # if it fits, center it, otherwise clamp
+        if width <= swidth:
+            noffsetx = (width - swidth) // 2
+        else:
+            noffsetx = min(max(0, offsetx), width - swidth)
+
+        if height <= sheight:
+            noffsety = (height - sheight) // 2
+        else:
+            noffsety = min(max(0, offsety), height - sheight)
+
+        self.ofsx = noffsetx
+        self.ofsy = noffsety
+    
     def getboundingbox(self):
         "Get the rectangle where the graph will be rendered."
-        offsetx = - self.margin - self.ofsx
-        offsety = - self.margin - self.ofsy
-        return (offsetx, offsety, self.width, self.height)
+        return (-self.ofsx, -self.ofsy, self.width, self.height)
 
     def map(self, x, y):
-        return (int(x*self.scale) - self.ofsx,
-                int((self.bboxh-y)*self.scale) - self.ofsy)
+        return (int(x*self.scale) - (self.ofsx - self.margin),
+                int((self.bboxh-y)*self.scale) - (self.ofsy - self.margin))
 
     def revmap(self, px, py):
-        return ((px + self.ofsx) / self.scale,
-                self.bboxh - (py + self.ofsy) / self.scale)
+        return ((px + (self.ofsx - self.margin)) / self.scale,
+                self.bboxh - (py + (self.ofsy - self.margin)) / self.scale)
 
     def draw_node_commands(self, node):
         xcenter, ycenter = self.map(node.x, node.y)

Modified: pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py	(original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py	Tue Nov 16 14:41:11 2004
@@ -109,13 +109,13 @@
         self.zoom_to_fit()
 
     def zoom_actual_size(self):
-        self.viewer.shiftscale(self.viewer.SCALEMAX / self.viewer.scale)
+        self.viewer.shiftscale(float(self.viewer.SCALEMAX) / self.viewer.scale)
         self.updated_viewer()
 
     def calculate_zoom_to_fit(self):
         return min(float(self.width) / self.viewer.width,
                 float(self.height - self.status_bar_height) / self.viewer.height,
-                1.0)
+                float(self.viewer.SCALEMAX) / self.viewer.scale)
     
     def zoom_to_fit(self):
         """
@@ -128,14 +128,17 @@
 
         f = self.calculate_zoom_to_fit()
         self.viewer.shiftscale(f)
-        self.viewer.setoffset((self.viewer.width - self.width) // 2,
-                              (self.viewer.height - (self.height - self.status_bar_height)) // 2)
+        #self.viewer.setoffset((self.viewer.width - self.width) // 2,
+        #                      (self.viewer.height - (self.height - self.status_bar_height)) // 2)
         self.updated_viewer()
 
     def zoom(self, scale):
         self.viewer.shiftscale(max(scale, self.calculate_zoom_to_fit()))
         self.updated_viewer()
 
+    def reoffset(self):
+        self.viewer.reoffset(self.width, self.height - self.status_bar_height)
+    
     def pan(self, (x, y)):
         self.viewer.shiftoffset(x * (self.width // 8), y * (self.height // 8))
         self.updated_viewer()
@@ -154,6 +157,7 @@
         self.setstatusbar(info)
     
     def updated_viewer(self):
+        self.reoffset()
         self.sethighlight()
         self.statusbarinfo = None
         self.must_redraw = True
@@ -225,6 +229,7 @@
             newlayout = self.layout.followlink(word)
             if newlayout is not None:
                 self.setlayout(newlayout)
+                self.zoom_to_fit()
                 return
         node = self.viewer.node_at_position(pos)
         if node:



More information about the Pypy-commit mailing list