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