Commit cd83ef17 authored by Taddeus Kroes's avatar Taddeus Kroes

First attempt to fix pinch (failed).

parent a76d047d
...@@ -44,20 +44,23 @@ def coord(x, y): ...@@ -44,20 +44,23 @@ def coord(x, y):
# Rotated rectangle # Rotated rectangle
angle = 0 angle = 0
scale = 1 scale = 1
w, h = W, H
def update(): def update():
global rotations global rotations, w, h, scale
cx, cy = coord(*listener.centroid) cx, cy = coord(*listener.centroid)
# Clear previous frame # Clear previous frame
screen.fill(BG_COLOR) screen.fill(BG_COLOR)
# Apply rotation to rectangle canvas # Apply rotation to rectangle canvas
canvas = pygame.Surface((W, H)) canvas = pygame.Surface((w, h))
canvas.fill(BG_COLOR) canvas.fill(BG_COLOR)
pygame.draw.rect(canvas, RECT_COLOR, RECT_POS + RECT_SIZE) pygame.draw.rect(canvas, RECT_COLOR, RECT_POS + RECT_SIZE)
w, h = int(round(scale * w)), int(round(scale * h))
scale = 1
scaled_canvas = pygame.transform.scale(canvas, coord(scale, scale)) scaled_canvas = pygame.transform.scale(canvas, (w, h))
rotated_canvas = pygame.transform.rotate(scaled_canvas, degrees(angle)) rotated_canvas = pygame.transform.rotate(scaled_canvas, degrees(angle))
rect = rotated_canvas.get_rect() rect = rotated_canvas.get_rect()
rect.center = W / 2, H / 2 rect.center = W / 2, H / 2
...@@ -85,7 +88,7 @@ def rotate(event): ...@@ -85,7 +88,7 @@ def rotate(event):
def pinch(event): def pinch(event):
global scale global scale
scale += event.amount scale = event.amount
# Start touch event listener in separate thread # Start touch event listener in separate thread
......
...@@ -88,7 +88,7 @@ class PinchEvent(GestureEvent): ...@@ -88,7 +88,7 @@ class PinchEvent(GestureEvent):
_name = 'pinch' _name = 'pinch'
def __init__(self, cx, cy, amount, n): def __init__(self, cx, cy, amount, n):
super(RotateEvent, self).__init__(cx, cy) super(PinchEvent, self).__init__(cx, cy)
self.amount = amount self.amount = amount
self.n = n self.n = n
......
...@@ -270,9 +270,19 @@ class MultiTouchListener(Logger): ...@@ -270,9 +270,19 @@ class MultiTouchListener(Logger):
p.update(x, y) p.update(x, y)
self.update_centroid(moving=p) self.update_centroid(moving=p)
self.trigger(MoveEvent(p)) self.trigger(MoveEvent(p))
self.detect_pinch(p)
# TODO: Detect pan # TODO: Detect pan
def detect_pinch(self, moved):
cx, cy = self.centroid
dist = moved.distance_to(cx, cy)
old_dist = distance((moved.px, moved.py), self.centroid)
if abs(dist - old_dist) > DIST_THRESHOLD:
self.trigger(PinchEvent(cx, cy, dist / old_dist,
len(self.points)))
def stop(self): def stop(self):
self.log('Stopping event loop') self.log('Stopping event loop')
......
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