diff options
author | Peter Froehlich <peter.hans.froehlich@gmail.com> | 2010-06-13 02:46:05 (GMT) |
---|---|---|
committer | Peter Froehlich <peter.hans.froehlich@gmail.com> | 2010-06-13 02:46:05 (GMT) |
commit | 9033ea1dc2c10842ab34397ef1abe755a19d7c7e (patch) | |
tree | 1a6e95bee455596126d2653904beb8fae3860cca /tools.py | |
parent | 7e2a5fa9f51d0e94c75791c1900edaf1a1e90f7b (diff) |
Grab now works even if the simulation is paused.
Diffstat (limited to 'tools.py')
-rw-r--r-- | tools.py | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -312,19 +312,35 @@ class GrabTool(Tool): def handleEvents(self,event): #look for default events, and if none are handled then try the custom events if not super(GrabTool,self).handleEvents(event): + # we handle two types of "grab" depending on simulation running or not if event.type == MOUSEBUTTONDOWN: if event.button == 1: # grab the first object at the mouse pointer bodylist = self.game.world.get_bodies_at_pos(event.pos, include_static=False) if bodylist and len(bodylist) > 0: - self.game.world.add.mouseJoint(bodylist[0], event.pos) + if self.game.world.run_physics: + self.game.world.add.mouseJoint(bodylist[0], event.pos) + else: + self._current_body = bodylist[0] elif event.type == MOUSEBUTTONUP: # let it go if event.button == 1: - self.game.world.add.remove_mouseJoint() - # use box2D mouse motion + if self.game.world.run_physics: + self.game.world.add.remove_mouseJoint() + else: + self._current_body = None elif event.type == MOUSEMOTION and event.buttons[0]: - self.game.world.mouse_move(event.pos) + # move it around + if self.game.world.run_physics: + # use box2D mouse motion + self.game.world.mouse_move(event.pos) + else: + # position directly (if we have a current body) + if self._current_body is not None: + x, y = self.game.world.to_world(event.pos) + x /= self.game.world.ppm + y /= self.game.world.ppm + self._current_body.position = (x, y) def cancel(self): self.game.world.add.remove_mouseJoint() |