-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathts_to_mouse.py
More file actions
43 lines (35 loc) · 1022 Bytes
/
ts_to_mouse.py
File metadata and controls
43 lines (35 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pygame
EVENT_MAPPINGS = {
pygame.FINGERDOWN: pygame.MOUSEBUTTONDOWN,
pygame.FINGERMOTION: pygame.MOUSEMOTION,
pygame.FINGERUP: pygame.MOUSEBUTTONUP
}
class TouchEventAdaptor():
def __init__(self, screen_dim, angle):
self.screen_dim = screen_dim
self.angle = angle
def convert(self, e):
if e.type not in (pygame.FINGERDOWN, pygame.FINGERMOTION, pygame.FINGERUP):
return False
x = e.x
y = e.y
# rotate touches if screen rotated
if self.angle == -90:
x,y = y,x
y = 1.0 - y
elif self.angle == 90:
x,y = y,x
x = 1.0 - x
elif self.angle == 180:
x = 1.0 - x
y = 1.0 - y
event = pygame.event.Event(
EVENT_MAPPINGS[e.type],
pos=(
x * self.screen_dim[0],
y * self.screen_dim[1]
),
button=1
)
pygame.event.post(event)
return True