comparison tools/area_editor.py @ 411:ddff1f8668d5

Unbreak polygon drawing
author Neil Muller <drnlmuller@gmail.com>
date Sat, 07 Sep 2013 12:38:51 +0200
parents 314ddad2d6d2
children c5a3ed165df9
comparison
equal deleted inserted replaced
410:d7bd9adb105a 411:ddff1f8668d5
179 if move_point_mode and index == self._move_poly: 179 if move_point_mode and index == self._move_poly:
180 pointlist = [p for p in polygon] 180 pointlist = [p for p in polygon]
181 pointlist = [self.point_to_pygame(p) if p != move_point else 181 pointlist = [self.point_to_pygame(p) if p != move_point else
182 mouse_pos for p in pointlist] 182 mouse_pos for p in pointlist]
183 pygame.draw.lines(self._surface, color, False, pointlist, 2) 183 pygame.draw.lines(self._surface, color, False, pointlist, 2)
184 elif len(polygon) > 1: 184 break
185 if len(polygon) > 1:
185 pointlist = [self.point_to_pygame(p) for p in polygon] 186 pointlist = [self.point_to_pygame(p) for p in polygon]
186 pygame.draw.lines(self._surface, color, False, pointlist, 2) 187 pygame.draw.lines(self._surface, color, False, pointlist, 2)
187 elif index == mouse_poly and mouse_pos: 188 if index == mouse_poly and mouse_pos:
188 endpoint = self.fix_poly_angle(index, mouse_pos) 189 endpoint = self.fix_poly_angle(index, mouse_pos)
189 pygame.draw.line(self._surface, color, 190 pygame.draw.line(self._surface, color,
190 self.point_to_pygame(polygon[-1]), 191 self.point_to_pygame(polygon[-1]),
191 self.point_to_pygame(endpoint)) 192 self.point_to_pygame(endpoint))
192 line_found = False # Hack for sane behaviour if lines overlap 193 line_found = False # Hack for sane behaviour if lines overlap
591 self._move_point = None 592 self._move_point = None
592 self.invalidate() 593 self.invalidate()
593 else: 594 else:
594 # find the current point 595 # find the current point
595 self._move_point = self.level.find_vertex(corrected_pos) 596 self._move_point = self.level.find_vertex(corrected_pos)
597 elif self.cur_poly and ev.button == 1:
598 # Add a point
599 self.level.add_point(self.cur_poly,
600 self._level_coordinates(corrected_pos))
596 elif ev.button == 1: 601 elif ev.button == 1:
597 if self._draw_lines: 602 if self._draw_lines:
598 if self._start_pos is None: 603 if self._start_pos is None:
599 self._start_pos = ev.pos 604 self._start_pos = ev.pos
600 else: 605 else:
610 self._move_view((0, 10)) 615 self._move_view((0, 10))
611 elif ev.button == 6: # Scroll left 616 elif ev.button == 6: # Scroll left
612 self._move_view((-10, 0)) 617 self._move_view((-10, 0))
613 elif ev.button == 7: # Scroll right 618 elif ev.button == 7: # Scroll right
614 self._move_view((10, 0)) 619 self._move_view((10, 0))
615 elif self.cur_poly and ev.button == 1:
616 # Add a point
617 self.level.add_point(self.cur_poly,
618 self._level_coordinates(ev.pos))
619 elif ev.button == 3: 620 elif ev.button == 3:
620 self._mouse_drag = True 621 self._mouse_drag = True
621 622
622 def mouse_up(self, ev): 623 def mouse_up(self, ev):
623 if ev.button == 3: 624 if ev.button == 3: