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