|
@@ -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):
|
|
|
|
|
|
|
|
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
|