Mercurial > boomslang
changeset 502:f53aaba58273
Use relative motion for images to remove jumping when combining key & mouse
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Wed, 01 Sep 2010 14:59:07 +0200 |
parents | 096ba5fe8be1 |
children | 65e17aba12c5 |
files | tools/rect_drawer.py |
diffstat | 1 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/rect_drawer.py Tue Aug 31 16:50:38 2010 +0200 +++ b/tools/rect_drawer.py Wed Sep 01 14:59:07 2010 +0200 @@ -91,6 +91,7 @@ self.draw_thing_rects = True self.draw_images = True self.draw_toolbar = True + self.old_mouse_pos = None self.find_existing_intersects() def find_existing_intersects(self): @@ -279,24 +280,31 @@ self.mode = 'image' self.start_pos = None self.end_pos = None + # So we do the right thing for off screen images + self.old_mouse_pos = None def mouse_move(self, e): if self.mode == 'image' and self.current_image: - self.current_image.rect.topleft = e.pos + if self.old_mouse_pos: + delta = (e.pos[0] - self.old_mouse_pos[0], e.pos[1] - self.old_mouse_pos[1]) + self.current_image.rect.center = (self.current_image.rect.center[0] + delta[0], self.current_image.rect.center[1] + delta[1]) + else: + self.current_image.rect.center = e.pos self.invalidate() + self.old_mouse_pos = e.pos def key_down(self, e): if self.mode == 'image' and self.current_image: # Move the image by 1 pixel - cur_pos = self.current_image.rect.topleft + cur_pos = self.current_image.rect.center if e.key == K_LEFT: - self.current_image.rect.topleft = (cur_pos[0] - 1, cur_pos[1]) + self.current_image.rect.center = (cur_pos[0] - 1, cur_pos[1]) elif e.key == K_RIGHT: - self.current_image.rect.topleft = (cur_pos[0] + 1, cur_pos[1]) + self.current_image.rect.center = (cur_pos[0] + 1, cur_pos[1]) elif e.key == K_UP: - self.current_image.rect.topleft = (cur_pos[0], cur_pos[1] - 1) + self.current_image.rect.center = (cur_pos[0], cur_pos[1] - 1) elif e.key == K_DOWN: - self.current_image.rect.topleft = (cur_pos[0], cur_pos[1] + 1) + self.current_image.rect.center = (cur_pos[0], cur_pos[1] + 1) def mouse_down(self, e): if self.mode == 'del': @@ -325,6 +333,7 @@ if self.current_image: self.images.append(self.current_image) self.current_image = None + self.old_mouse_pos = None self.invalidate() else: cand = None @@ -335,7 +344,8 @@ if cand: self.images.remove(cand) self.current_image = cand - self.current_image.topleft = e.pos + # We want to move relative to the current mouse pos, so + self.old_mouse_pos = e.pos self.invalidate() def mouse_up(self, e):