Explorar o código

Polygons can now be transformes at the same time by a single gesture on the root window.

Taddeus Kroes %!s(int64=13) %!d(string=hai) anos
pai
achega
29dd92a4f3
Modificáronse 1 ficheiros con 25 adicións e 1 borrados
  1. 25 1
      tests/testapp.py

+ 25 - 1
tests/testapp.py

@@ -55,7 +55,6 @@ class Polygon(BoundingBoxArea):
     def handle_flick(self, g):
         trans = g.get_translation()
 
-        print trans.distance_to((0, 0))
         if trans.distance_to((0, 0)) > 10:
             self.flick_direction = trans
             flicks.add(Flick(self.flick_drag, 0.7, 0.4))
@@ -290,6 +289,31 @@ def on_show(window):
     overlay.on_finger_up(handle_up)
     root.add_area(overlay)
 
+    # Root area rotation leads to rotation of all polygons around the centroid
+    def move_to_polygons(g):
+        gx, gy = g.get_position()
+
+        for obj in draw_objects:
+            x, y = obj.get_position()
+            g.set_position(gx - x, gy - y)
+            yield obj, g
+
+    def rotate_root(g):
+        for obj, gesture in move_to_polygons(g):
+            obj.handle_rotate(gesture)
+
+    def scale_root(g):
+        for obj, gesture in move_to_polygons(g):
+            obj.handle_pinch(gesture)
+
+    def drag_root(g):
+        for obj, gesture in move_to_polygons(g):
+            obj.handle_drag(gesture)
+
+    root.on_rotate(rotate_root)
+    root.on_pinch(scale_root)
+    root.on_drag(drag_root)
+
 
 if __name__ == '__main__':
     from parse_arguments import create_parser, parse_args