|
@@ -5,7 +5,7 @@ from threading import Thread
|
|
|
from math import pi, tan
|
|
from math import pi, tan
|
|
|
|
|
|
|
|
import src as mt
|
|
import src as mt
|
|
|
-from utils import BoundingBoxArea
|
|
|
|
|
|
|
+from utils import BoundingBoxArea, Flick, FlickThread
|
|
|
|
|
|
|
|
|
|
|
|
|
RED = 1, 0, 0
|
|
RED = 1, 0, 0
|
|
@@ -42,6 +42,20 @@ class Polygon(BoundingBoxArea):
|
|
|
self.on_drag(self.handle_drag)
|
|
self.on_drag(self.handle_drag)
|
|
|
self.on_pinch(self.handle_pinch)
|
|
self.on_pinch(self.handle_pinch)
|
|
|
self.on_rotate(self.handle_rotate)
|
|
self.on_rotate(self.handle_rotate)
|
|
|
|
|
+ self.on_flick(self.handle_flick)
|
|
|
|
|
+
|
|
|
|
|
+ def flick_drag(self, amt):
|
|
|
|
|
+ tx, ty = self.flick_direction
|
|
|
|
|
+ self.translate(tx * amt, ty * amt)
|
|
|
|
|
+ refresh()
|
|
|
|
|
+
|
|
|
|
|
+ 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))
|
|
|
|
|
|
|
|
def handle_drag(self, g):
|
|
def handle_drag(self, g):
|
|
|
tx, ty = g.get_translation()
|
|
tx, ty = g.get_translation()
|
|
@@ -217,7 +231,7 @@ def quit(*args):
|
|
|
|
|
|
|
|
|
|
|
|
|
# Global variables
|
|
# Global variables
|
|
|
-window = cr = root = overlay = None
|
|
|
|
|
|
|
+window = cr = root = overlay = flicks = None
|
|
|
draw_objects = []
|
|
draw_objects = []
|
|
|
touch_hands = []
|
|
touch_hands = []
|
|
|
|
|
|
|
@@ -247,7 +261,7 @@ def on_show(window):
|
|
|
draw_objects.append(triangle)
|
|
draw_objects.append(triangle)
|
|
|
root.add_area(triangle)
|
|
root.add_area(triangle)
|
|
|
|
|
|
|
|
- # Overlay catches basic events
|
|
|
|
|
|
|
+ # Overlay catches finger events to be able to draw touch points
|
|
|
def handle_down(gesture):
|
|
def handle_down(gesture):
|
|
|
if gesture.is_first():
|
|
if gesture.is_first():
|
|
|
touch_hands.append(gesture.get_hand())
|
|
touch_hands.append(gesture.get_hand())
|
|
@@ -279,7 +293,6 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
fullscreen = args.fullscreen
|
|
fullscreen = args.fullscreen
|
|
|
|
|
|
|
|
-
|
|
|
|
|
# Create a window with a Cairo context in it and a multi-touch area
|
|
# Create a window with a Cairo context in it and a multi-touch area
|
|
|
# syncronized with it
|
|
# syncronized with it
|
|
|
create_context_window(800, 600, on_show)
|
|
create_context_window(800, 600, on_show)
|
|
@@ -290,6 +303,11 @@ if __name__ == '__main__':
|
|
|
mt_thread.daemon = True
|
|
mt_thread.daemon = True
|
|
|
mt_thread.start()
|
|
mt_thread.start()
|
|
|
|
|
|
|
|
|
|
+ # Flick movement is also handled in a separate thread
|
|
|
|
|
+ flicks = FlickThread()
|
|
|
|
|
+ flicks.daemon = True
|
|
|
|
|
+ flicks.start()
|
|
|
|
|
+
|
|
|
# Initialize threads in GTK so that the thread started above will work
|
|
# Initialize threads in GTK so that the thread started above will work
|
|
|
gtk.gdk.threads_init()
|
|
gtk.gdk.threads_init()
|
|
|
|
|
|