From da07cde3f683a2e52528d48ed4632b8ceff85744 Mon Sep 17 00:00:00 2001 From: Gary Martin Date: Sun, 23 Aug 2009 16:26:53 +0000 Subject: Poly tool now supports single click clones but with slight behaviour change. Poly tool needed a slight behaviour tool if it was to support single click duplicates of the previous shape created (just like all other shape tools) as the behaviour previoulsy allowed a single click to place the first point. Poly tool now needs a hold and drag operation to start it off. Not 100% in favour of this but it is now consistant with other tools and has the ability to duplicate. --- diff --git a/tools.py b/tools.py index cac982e..136896b 100644 --- a/tools.py +++ b/tools.py @@ -195,21 +195,34 @@ class PolygonTool(Tool): def handleEvents(self,event): #look for default events, and if none are handled then try the custom events if not super(PolygonTool,self).handleEvents(event): - if event.type == MOUSEBUTTONDOWN: - if event.button == 1: - if not self.vertices: - self.vertices=[event.pos] - self.safe = False - elif distance(event.pos,self.vertices[0]) < 15 and self.safe: - self.vertices.append(self.vertices[0]) #connect the polygon - self.game.world.add.complexPoly(self.vertices, dynamic=True, density=1.0, restitution=0.16, friction=0.5) - self.vertices = None - elif distance(event.pos,self.vertices[0]) < 15: - self.vertices = None - else: - self.vertices.append(event.pos) - if distance(event.pos,self.vertices[0]) >= 55 and self.vertices: - self.safe = True + if event.type == MOUSEBUTTONDOWN and event.button == 1 and self.vertices is None: + self.vertices = [event.pos] + self.safe = False + if event.type == MOUSEBUTTONUP and event.button == 1 and self.vertices is not None and len(self.vertices) == 1 and event.pos[0] == self.vertices[0][0] and event.pos[1] == self.vertices[0][1]: + if self.previous_vertices is not None: + last_x_y = self.previous_vertices[-1] + delta_x = last_x_y[0] - event.pos[0] + delta_y = last_x_y[1] - event.pos[1] + self.vertices = [[i[0] - delta_x, i[1] - delta_y] + for i in self.previous_vertices] + self.safe = True + self.game.world.add.complexPoly(self.vertices, dynamic=True, density=1.0, restitution=0.16, friction=0.5) + self.vertices = None + elif (event.type == MOUSEBUTTONUP or event.type == MOUSEBUTTONDOWN) and event.button == 1: + if self.vertices is None or (event.pos[0] == self.vertices[-1][0] and event.pos[1] == self.vertices[-1][1]): + # Skip if coordinate is same as last one + return + if distance(event.pos,self.vertices[0]) < 15 and self.safe: + self.vertices.append(self.vertices[0]) #connect the polygon + self.game.world.add.complexPoly(self.vertices, dynamic=True, density=1.0, restitution=0.16, friction=0.5) + self.previous_vertices = self.vertices[:] + self.vertices = None + elif distance(event.pos,self.vertices[0]) < 15: + self.vertices = None + else: + self.vertices.append(event.pos) + if distance(event.pos,self.vertices[0]) >= 55 and self.vertices: + self.safe = True def draw(self): # draw the poly being created -- cgit v0.9.1