Esempio n. 1
0
 def on_mouse_drag(self, x, y, dx, dy, *etc):
     if not self.callback:
         return
     if not self.dragging:
         self.handle.hilite()
         self.dragging = x, self.handle.position
         ui.start_drag(self)
     orig_x, orig_pos = self.dragging
     pos = orig_pos + (x - orig_x) / self.handle.range
     self.callback(max(0, min(1, pos)))
     return True
Esempio n. 2
0
 def on_mouse_drag(self, x, y, dx, dy, btn, *etc):
     if not self.dragging:
         self.scrolling = (btn == mouse.LEFT) and self.zoom_rect
         self.zooming = (btn == mouse.RIGHT)
         self.dragging = x, y
         ui.start_drag(self)
     if self.scrolling:
         ratio = self.get_zoom_ratio()
         orig_x, orig_y = self.dragging
         new_x = max(self.world_rect.left,
                     min(self.world_rect.right - self.rect.width * ratio,
                         self.scrolling.left - (x - orig_x) * ratio))
         new_y = max(self.world_rect.bottom,
                     min(self.world_rect.top - self.rect.height * ratio,
                         self.scrolling.bottom - (y - orig_y) * ratio))
         self.zoom_rect = ui.rect(new_x, 
                                  new_y, 
                                  self.zoom_rect.width,
                                  self.zoom_rect.height)
     if self.zooming:
         self.drag_end = x, y
     return True