def handle(self, event):
gd.BoardGame.handle(self, event) # send event handling up
if event.type == pygame.MOUSEBUTTONDOWN:
pos = event.pos
column = (pos[0] - self.px_padding) // (self.layout.width)
row = (pos[1] - self.layout.top_margin) // (self.layout.height)
if event.button == 1 and column >= 0 and 2 <= row < self.data[1]:
if self.points_count == 0:
self.new_screen()
elif event.type == pygame.MOUSEBUTTONUP:
pos = event.pos
active = self.board.active_ship
column = (pos[0] - self.px_padding) // (self.layout.width)
row = (pos[1] - self.layout.top_margin) // (self.layout.height)
if active != self.canvas_block.unit_id:
if active == self.poli_btn.unit_id:
self.change_tool(4)
elif active == self.tria_btn.unit_id:
self.change_tool(3)
elif active == self.circle_btn.unit_id:
self.change_tool(2)
elif active == self.next_btn.unit_id and self.next_btn.keyable == True:
self.next_shape()
if event.button == 1 and column >= 0 and 2 <= row < self.data[1]:
if self.points_count < self.max_points:
canvas_pos = self.snap_to_guide(
[pos[0] - self.px_padding, pos[1] - self.layout.top_margin - self.board.scale * 2])
if canvas_pos not in self.points:
self.points.append(canvas_pos)
self.p_current = canvas_pos
self.paint_line(0)
self.paint_line(2)
self.points_count += 1
if self.points_count >= self.max_points:
self.check_drawing()
elif event.type == pygame.MOUSEMOTION and 0 < self.points_count < self.max_points:
active = self.board.active_ship
pos = event.pos
column = (pos[0] - self.px_padding) // (self.layout.width)
row = (pos[1] - self.layout.top_margin) // (self.layout.height)
if column >= 0 and 2 <= row < self.data[1]:
canvas_pos = self.snap_to_guide(
[pos[0] - self.px_padding, pos[1] - self.layout.top_margin - self.board.scale * 2])
self.p_current = canvas_pos[:]
if self.prev_snap is None:
self.prev_snap = canvas_pos[:]
if self.prev_snap != self.p_current:
self.prev_snap = canvas_pos[:]
self.paint_line(1)
评论列表
文章目录