Commit 010cb2bc authored by Taddeüs Kroes's avatar Taddeüs Kroes

Hand tracker events are now handled by a fullscreen overlay so that touch points are never 'lost'.

parent 29dd92a4
......@@ -69,5 +69,8 @@ class FullscreenArea(RectangularArea):
def __str__(self):
return '<FullscreenArea size=(%d, %d)>' % self.get_size()
def contains(self, x, y):
return True
def contains_event(self, event):
return True
......@@ -94,6 +94,8 @@ class TransformationTracker(GestureTracker):
supported_gestures = [RotationGesture, PinchGesture, DragGesture,
FlickGesture]
configurable = ['propagate_events']
def __init__(self, area):
super(TransformationTracker, self).__init__(area)
......@@ -105,6 +107,8 @@ class TransformationTracker(GestureTracker):
self.deleted = []
self.propagate_events = False
def update_centroid(self):
if not self.points:
self.centroid = None
......@@ -126,6 +130,8 @@ class TransformationTracker(GestureTracker):
def on_point_down(self, event):
self.points.append(event.point)
self.update_centroid()
if not self.propagate_events:
event.stop_propagation()
def on_point_move(self, event):
......@@ -142,7 +148,9 @@ class TransformationTracker(GestureTracker):
self.points.append(point)
self.update_centroid()
if not self.propagate_events:
event.stop_propagation()
self.invalidate_points()
l = len(self.points)
......@@ -175,6 +183,8 @@ class TransformationTracker(GestureTracker):
self.trigger(FlickGesture(event, self.centroid,
self.centroid.translation()))
self.update_centroid()
if not self.propagate_events:
event.stop_propagation()
......
......@@ -122,12 +122,6 @@ def create_context_window(w, h, callback):
cr = area.window.cairo_create()
draw()
def update_window():
"""Synchronize overlay with GTK window."""
overlay.set_size(*window.get_size())
refresh()
return True
def handle_key(win, event):
"""Handle key event. 'f' toggles fullscreen, 'b' toggles bounding
boxes, 'i' toggles input points, 'q' exits the program."""
......@@ -151,9 +145,9 @@ def create_context_window(w, h, callback):
elif key == 'q':
quit()
# Root area (will be synchronized with GTK window)
global overlay
overlay = mt.RectangularArea(0, 0, w, h)
def update_window():
refresh()
return True
# GTK window
global window, root
......@@ -284,10 +278,16 @@ def on_show(window):
if draw_touch_objects:
refresh()
global screen, overlay
screen = mt.FullscreenArea()
overlay = mt.FullscreenArea()
screen.add_area(root)
screen.add_area(overlay)
overlay.on_finger_down(handle_down)
overlay.on_finger_move(lambda g: draw_touch_objects and refresh())
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):
......@@ -331,7 +331,7 @@ if __name__ == '__main__':
create_context_window(800, 600, on_show)
# Run multi-touch gesture server in separate thread
driver = mt.create_driver(root)
driver = mt.create_driver(screen)
mt_thread = Thread(target=driver.start)
mt_thread.daemon = True
mt_thread.start()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment