Commit 7d33a30f authored by Taddeus Kroes's avatar Taddeus Kroes

Merge branch 'master' of kompiler.org:uva-multitouch

parents 2967cab6 e4cb52c8
...@@ -2,14 +2,13 @@ Code: ...@@ -2,14 +2,13 @@ Code:
- Rotation has a 'bump' at angle = 0. - Rotation has a 'bump' at angle = 0.
- Try to get rid of relative imports. - Try to get rid of relative imports.
- Join event server with event driver. - Join event server with event driver.
- Debug offset positions in transformation tracker.
Tests: Tests:
- draw.py: pygame -> gtk + cairo.
- Nested widgets with rotation. - Nested widgets with rotation.
- Draggable shapes. - Draggable shapes.
Report: Report:
- Cited to VTK book, is this ok if I didn't read it?
- Normalize coordinates between (0.0, 0.0) and (1.0, 1.0)? - Normalize coordinates between (0.0, 0.0) and (1.0, 1.0)?
- Experiment met Processing-Python code port nog wel beschrijven of uberhaupt - Experiment met Processing-Python code port nog wel beschrijven of uberhaupt
weglaten? weglaten?
......
...@@ -50,14 +50,17 @@ class DragGesture(Gesture, Positionable): ...@@ -50,14 +50,17 @@ class DragGesture(Gesture, Positionable):
""" """
_type = 'drag' _type = 'drag'
def __init__(self, event, initial_position, translation): def __init__(self, event, initial_position, translation, n=1):
Gesture.__init__(self, event) Gesture.__init__(self, event)
Positionable.__init__(self, *initial_position.get_position()) Positionable.__init__(self, *initial_position.get_position())
self.translation = translation self.translation = translation
self.n = n
def __str__(self): def __str__(self):
return '<DragGesture at (%s, %s) translation=(%s, %s)>' \ x, y = self
% (self.get_position() + self.translation.get_position()) tx, ty = self.translation
return '<DragGesture at (%s, %s) translation=(%s, %s) n=%d>' \
% (x, y, tx, ty, self.n)
def get_translation(self): def get_translation(self):
return self.translation return self.translation
...@@ -99,12 +102,19 @@ class TransformationTracker(GestureTracker): ...@@ -99,12 +102,19 @@ class TransformationTracker(GestureTracker):
else: else:
self.centroid = MovingPositionable(x, y) self.centroid = MovingPositionable(x, y)
#wx, wy = self.widget.get_screen_offset()
#self.centroid.translate(-wx, -wy)
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()
def on_point_move(self, event): def on_point_move(self, event):
point = event.point point = event.point
if point not in self.points:
return
l = len(self.points) l = len(self.points)
if l > 1: if l > 1:
...@@ -119,17 +129,19 @@ class TransformationTracker(GestureTracker): ...@@ -119,17 +129,19 @@ class TransformationTracker(GestureTracker):
scale = dist / prev scale = dist / prev
self.trigger(PinchGesture(event, self.centroid, scale)) self.trigger(PinchGesture(event, self.centroid, scale))
# Update centroid before movement can be detected
self.update_centroid()
# Movement using multiple touch points # Movement using multiple touch points
self.trigger(DragGesture(event, self.centroid, self.trigger(DragGesture(event, self.centroid,
self.centroid.translation())) self.centroid.translation(), l))
else: else:
# Movement using one touch point # Movement using one touch point
self.trigger(DragGesture(event, event.point, self.trigger(DragGesture(event, point, point.translation()))
event.point.translation()))
# Update centroid before movement can be detected
self.update_centroid()
def on_point_up(self, event): def on_point_up(self, event):
if event.point not in self.points:
return
self.points.remove(event.point) self.points.remove(event.point)
self.update_centroid() self.update_centroid()
...@@ -8,9 +8,8 @@ class PointGesture(Gesture, Positionable): ...@@ -8,9 +8,8 @@ class PointGesture(Gesture, Positionable):
point. point.
""" """
def __init__(self, event, point=None): def __init__(self, event, point=None):
Gesture.__init__(self, event)
if not point: if not point:
point = event.get_touch_object() point = event
Positionable.__init__(self, *point.get_position()) Gesture.__init__(self, event)
Positionable.__init__(self, *point)
...@@ -208,12 +208,7 @@ class Widget(Positionable, Logger): ...@@ -208,12 +208,7 @@ class Widget(Positionable, Logger):
def handle_gesture(self, gesture): def handle_gesture(self, gesture):
""" """
Handle a gesture that is triggered by a gesture tracker. First, all Handle a gesture that is triggered by a gesture tracker. First, all
handlers bound to the gesture type are called. Second, if the gesture's handlers bound to the gesture type are called.
propagation has not been stopped by a handler, the gesture is
propagated to the parent widget.
""" """
for handler in self.handlers.get(gesture.get_type(), ()): for handler in self.handlers.get(gesture.get_type(), ()):
handler(gesture) handler(gesture)
#if self.parent and not gesture.is_propagation_stopped():
# self.parent.handle_gesture(gesture)
...@@ -15,23 +15,35 @@ def quit(*args): ...@@ -15,23 +15,35 @@ def quit(*args):
class Rectangle(mt.RectangularWidget): class Rectangle(mt.RectangularWidget):
def __init__(self, x, y, width, height, color=(1, 0, 0)): def __init__(self, x, y, width, height, color=(1, 0, 0)):
super(Rectangle, self).__init__(x, y, width, height) super(Rectangle, self).__init__(x, y, width, height)
self.angle = 0 self.angle = 1.0
self.scale = 1
self.color = color self.color = color
self.t = cairo.Matrix()
self.t.translate(*self)
self.on_drag(self.move) self.on_drag(self.move)
self.on_pinch(self.resize)
#self.on_rotate(self.rotate)
def move(self, g): def move(self, g):
print 'drag rectangle', g.get_translation()
self.translate(*g.get_translation()) self.translate(*g.get_translation())
print self print 'drag rectangle', self
refresh() refresh()
def scale(self, angle): def resize(self, g):
self.scale *= scale print 'resize:', g.get_scale()
self.t.scale(g.get_scale(), g.get_scale())
refresh()
def rotate(self, angle): def rotate(self, g):
self.angle += angle w, h = self.get_size()
#self.t.translate(-w / 2, -h / 2)
self.t.rotate(-g.get_angle())
#self.t.translate(w / 2, h / 2)
print tuple(g)
x, y = g * .01
print x, y
#self.rot.translate(-x, -y)
refresh()
def get_transformation_matrix(self): def get_transformation_matrix(self):
t = cairo.Matrix() t = cairo.Matrix()
...@@ -41,9 +53,9 @@ class Rectangle(mt.RectangularWidget): ...@@ -41,9 +53,9 @@ class Rectangle(mt.RectangularWidget):
return t return t
def draw(self, cr): def draw(self, cr):
cr.transform(self.get_transformation_matrix())
w, h = self.get_size() w, h = self.get_size()
cr.rectangle(-w / 2, -h / 2, w, h) cr.transform(self.t)
cr.rectangle(0, 0, w, h)
cr.set_source_rgb(*self.color) cr.set_source_rgb(*self.color)
cr.fill() cr.fill()
...@@ -54,7 +66,7 @@ W, H = mt.screen.screen_size ...@@ -54,7 +66,7 @@ W, H = mt.screen.screen_size
def create_context_window(w, h, callback): def create_context_window(w, h, callback):
def create_context(area, event): def create_context(area, event):
"""Add Cairo context to GTK window and draw initial state.""" """Add Cairo context to GTK window and draw state."""
global cr global cr
cr = area.window.cairo_create() cr = area.window.cairo_create()
draw() draw()
......
...@@ -73,7 +73,7 @@ def update(): ...@@ -73,7 +73,7 @@ def update():
# Draw touch points # Draw touch points
if transform and transform.centroid: if transform and transform.centroid:
c = coord(*transform.centroid.xy) c = coord(*transform.centroid)
for p in points: for p in points:
xy = coord(p.x, p.y) xy = coord(p.x, p.y)
...@@ -151,9 +151,9 @@ server = EventServer(widget) ...@@ -151,9 +151,9 @@ server = EventServer(widget)
widget.on_rotate(rotate) widget.on_rotate(rotate)
widget.on_pinch(pinch) widget.on_pinch(pinch)
widget.on_tap(lambda g: taps.append([coord(*g.xy), FINGER_RADIUS])) widget.on_tap(lambda g: taps.append([coord(*g), FINGER_RADIUS]))
widget.on_single_tap(lambda g: dtaps.append(list(coord(*g.xy)) + [1])) widget.on_single_tap(lambda g: dtaps.append(list(coord(*g)) + [1]))
widget.on_double_tap(lambda g: dtaps.append(list(coord(*g.xy)) + [0])) widget.on_double_tap(lambda g: dtaps.append(list(coord(*g)) + [0]))
widget.on_point_down(lambda g: points.append(g.get_event().point)) widget.on_point_down(lambda g: points.append(g.get_event().point))
widget.on_point_up(lambda g: points.remove(g.get_event().point)) widget.on_point_up(lambda g: points.remove(g.get_event().point))
......
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