|
|
@@ -88,7 +88,7 @@ class Polygon(BoundingBoxArea):
|
|
|
|
|
|
|
|
|
fullscreen = False
|
|
|
-draw_bounding_boxes = draw_touch_points = True
|
|
|
+draw_bounding_boxes = draw_touch_objects = True
|
|
|
W, H = mt.screen.screen_size
|
|
|
|
|
|
|
|
|
@@ -107,8 +107,8 @@ def create_context_window(w, h, callback):
|
|
|
refresh()
|
|
|
|
|
|
def handle_key(win, event):
|
|
|
- """Handle key event. 'f' toggles fullscreen, 'q' exits the program, 'b'
|
|
|
- toggles bounding boxes, 'p' toggles touch points."""
|
|
|
+ """Handle key event. 'f' toggles fullscreen, 'b' toggles bounding
|
|
|
+ boxes, 'i' toggles input points, 'q' exits the program."""
|
|
|
if event.keyval >= 256:
|
|
|
return
|
|
|
|
|
|
@@ -118,16 +118,16 @@ def create_context_window(w, h, callback):
|
|
|
global fullscreen
|
|
|
(win.unfullscreen if fullscreen else win.fullscreen)()
|
|
|
fullscreen = not fullscreen
|
|
|
- elif key == 'q':
|
|
|
- quit()
|
|
|
elif key == 'b':
|
|
|
global draw_bounding_boxes
|
|
|
draw_bounding_boxes = not draw_bounding_boxes
|
|
|
refresh()
|
|
|
- elif key == 'p':
|
|
|
- global draw_touch_points
|
|
|
- draw_touch_points = not draw_touch_points
|
|
|
+ elif key == 'i':
|
|
|
+ global draw_touch_objects
|
|
|
+ draw_touch_objects = not draw_touch_objects
|
|
|
refresh()
|
|
|
+ elif key == 'q':
|
|
|
+ quit()
|
|
|
|
|
|
# Root area (will be synchronized with GTK window)
|
|
|
global root, overlay
|
|
|
@@ -156,7 +156,7 @@ def create_context_window(w, h, callback):
|
|
|
window.show()
|
|
|
|
|
|
|
|
|
-def draw(*args):
|
|
|
+def draw():
|
|
|
if not cr:
|
|
|
return
|
|
|
|
|
|
@@ -171,26 +171,44 @@ def draw(*args):
|
|
|
obj.draw(cr)
|
|
|
cr.restore()
|
|
|
|
|
|
- if draw_touch_points:
|
|
|
+ if draw_touch_objects:
|
|
|
ox, oy = root.get_position()
|
|
|
cr.set_source_rgb(*WHITE)
|
|
|
|
|
|
- for x, y in touch_points.itervalues():
|
|
|
- x -= ox
|
|
|
- y -= oy
|
|
|
+ for hand in touch_hands:
|
|
|
+ cx, cy = hand.get_centroid()
|
|
|
|
|
|
- cr.set_line_width(3)
|
|
|
- cr.arc(x, y, 20, 0, 2 * pi)
|
|
|
- cr.stroke()
|
|
|
+ # Filled centroid circle
|
|
|
+ if len(hand) > 1:
|
|
|
+ cr.arc(cx - ox, cy - oy, 20, 0, 2 * pi)
|
|
|
+ cr.fill()
|
|
|
+
|
|
|
+ for x, y in hand:
|
|
|
+ x -= ox
|
|
|
+ y -= oy
|
|
|
+
|
|
|
+ # Circle outline
|
|
|
+ cr.set_line_width(3)
|
|
|
+ cr.arc(x, y, 20, 0, 2 * pi)
|
|
|
+ cr.stroke()
|
|
|
+
|
|
|
+ # Line to centroid
|
|
|
+ if len(hand) > 1:
|
|
|
+ cr.move_to(x, y)
|
|
|
+ cr.line_to(cx - ox, cy - oy)
|
|
|
+ cr.set_line_width(2)
|
|
|
+ cr.stroke()
|
|
|
+
|
|
|
+ # Cross
|
|
|
+ cr.set_line_width(1)
|
|
|
+ cr.move_to(x - 8, y)
|
|
|
+ cr.line_to(x + 8, y)
|
|
|
+ cr.move_to(x, y - 8)
|
|
|
+ cr.line_to(x, y + 8)
|
|
|
+ cr.stroke()
|
|
|
|
|
|
- cr.set_line_width(1)
|
|
|
- cr.move_to(x - 8, y)
|
|
|
- cr.line_to(x + 8, y)
|
|
|
- cr.move_to(x, y - 8)
|
|
|
- cr.line_to(x, y + 8)
|
|
|
- cr.stroke()
|
|
|
|
|
|
-def refresh():
|
|
|
+def refresh(*args):
|
|
|
window.queue_draw()
|
|
|
|
|
|
|
|
|
@@ -198,10 +216,10 @@ def quit(*args):
|
|
|
gtk.main_quit()
|
|
|
|
|
|
|
|
|
-# Initialization
|
|
|
+# Global variables
|
|
|
window = cr = root = overlay = None
|
|
|
draw_objects = []
|
|
|
-touch_points = {}
|
|
|
+touch_hands = []
|
|
|
|
|
|
|
|
|
def triangle_height(width):
|
|
|
@@ -231,22 +249,22 @@ def on_show(window):
|
|
|
|
|
|
# Overlay catches basic events
|
|
|
def handle_down(gesture):
|
|
|
- point = gesture.get_event().get_touch_object()
|
|
|
- touch_points[point.get_id()] = point.get_position()
|
|
|
+ if gesture.is_first():
|
|
|
+ touch_hands.append(gesture.get_hand())
|
|
|
|
|
|
- if draw_touch_points:
|
|
|
+ if draw_touch_objects:
|
|
|
refresh()
|
|
|
|
|
|
def handle_up(gesture):
|
|
|
- point = gesture.get_event().get_touch_object()
|
|
|
- del touch_points[point.get_id()]
|
|
|
+ if gesture.is_last():
|
|
|
+ touch_hands.remove(gesture.get_hand())
|
|
|
|
|
|
- if draw_touch_points:
|
|
|
+ if draw_touch_objects:
|
|
|
refresh()
|
|
|
|
|
|
- overlay.on_point_down(handle_down)
|
|
|
- overlay.on_point_move(handle_down)
|
|
|
- overlay.on_point_up(handle_up)
|
|
|
+ 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)
|
|
|
|
|
|
|