def events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.exit()
if hasattr(event, "pos"):
ix, iy = event.pos
self.mouse_inmenu = ix <= self.size[1] * MENU_BORDER / 100.0
fx = min(max(0, (ix - self.proj[0]) / float(self.proj[2])), 1)
fy = min(max(0, (iy - self.proj[1]) / float(self.proj[3])), 1)
if self.rotation == 0:
x = fx
y = fy
if self.rotation == 90:
x = 1.0 - fy
y = fx
if self.rotation == 180:
x = 1.0 - fx
y = 1.0 - fy
if self.rotation == 270:
x = fy
y = 1.0 - fx
if hasattr(event, "button"):
if event.button is not 1:
continue
if event.type == pygame.MOUSEBUTTONDOWN:
if ix < self.menu_w and self.show_menu:
self.menu_action(iy / (self.size[1] / 3))
elif ix > self.size[0] - self.nav_w and self.show_nav:
self.nav_action(iy / (self.size[1] / 3))
else:
self.touch.write(["down", x, y])
self.mouse_down = True
self.mouse_time = time()
if event.type == pygame.MOUSEBUTTONUP:
self.touch.write(["up"])
self.mouse_down = False
if event.type == pygame.MOUSEMOTION:
if self.mouse_down:
self.touch.write(["move", x, y])
评论列表
文章目录