Browse code

Zoom out while moving a large distance.

From: Marius Gedminas <marius@gedmin.as>

Jose.R.Fonseca authored on 13/07/2008 03:20:45
Showing 1 changed files

  • xdot.py index b414d92..40895fc 100755
... ...
@@ -663,6 +663,30 @@ class MoveToAnimation(LinearAnimation):
663 663
         self.dot_widget.queue_draw()
664 664
 
665 665
 
666
+class ZoomToAnimation(MoveToAnimation):
667
+
668
+    def __init__(self, dot_widget, target_x, target_y):
669
+        MoveToAnimation.__init__(self, dot_widget, target_x, target_y)
670
+        self.source_zoom = dot_widget.zoom_ratio
671
+        self.target_zoom = self.source_zoom
672
+        self.extra_zoom = 0
673
+
674
+        middle_zoom = 0.5 * (self.source_zoom + self.target_zoom)
675
+
676
+        distance = math.hypot(self.source_x - self.target_x,
677
+                              self.source_y - self.target_y)
678
+        rect = self.dot_widget.get_allocation()
679
+        visible = min(rect.width, rect.height) * .9
680
+        if distance > visible:
681
+            desired_middle_zoom = visible / distance
682
+            self.extra_zoom = 4 * (desired_middle_zoom - middle_zoom)
683
+
684
+    def animate(self, t):
685
+        a, b, c = self.source_zoom, self.extra_zoom, self.target_zoom
686
+        self.dot_widget.zoom_ratio = c*t + b*t*(1-t) + a*(1-t)
687
+        MoveToAnimation.animate(self, t)
688
+
689
+
666 690
 class DotWidget(gtk.DrawingArea):
667 691
     """PyGTK widget that draws dot graphs."""
668 692
 
... ...
@@ -850,7 +874,7 @@ class DotWidget(gtk.DrawingArea):
850 874
         return True
851 875
 
852 876
     def animate_to(self, x, y):
853
-        self.animation = MoveToAnimation(self, x, y)
877
+        self.animation = ZoomToAnimation(self, x, y)
854 878
         self.animation.start()
855 879
 
856 880
     def window2graph(self, x, y):