def event(self, event): if event.type == graphics.const.MOUSEBUTTONDOWN: self.vx = 0 self.vy = 0 self.start_dragging = event.pos self.start_dragging_abs = event.abs_pos self.was_dragged = False self.canceled_event(event) return ui.LOCK_MOUSE_EVENT elif event.type == graphics.const.MOUSEMOTION: if self.start_dragging: dx, dy = _subpoints(self.start_dragging, event.pos) if (dx*dx+dy*dy) > 16: self.start_dragging = event.pos self.was_dragged = True self.y += dy self.x += dx elif event.type == graphics.const.MOUSEBUTTONUP: if self.was_dragged: dx, dy = _subpoints(self.start_dragging, event.pos) self.vx = _scroll_speed_func(self.vx, dx) self.vy = _scroll_speed_func(self.vy, dy) self.y += dy self.x += dx else: if self.start_dragging: self.post_mouse_event(ui.Event(graphics.const.MOUSEBUTTONDOWN, {'pos': self.start_dragging, 'abs_pos': self.start_dragging_abs})) self.post_mouse_event(event) self.start_dragging = None self.was_dragged = False self.canceled_event(event) else: self.item.event(event)
def event(self, event): if event.type == graphics.const.MOUSEBUTTONDOWN: self.vx = 0 self.vy = 0 self.start_dragging = event.pos self.start_dragging_abs = event.abs_pos self.was_dragged = False self.canceled_event(event) return ui.LOCK_MOUSE_EVENT elif event.type == graphics.const.MOUSEMOTION: if self.start_dragging: dx, dy = _subpoints(self.start_dragging, event.pos) if (dx * dx + dy * dy) > 16: self.start_dragging = event.pos self.was_dragged = True self.y += dy self.x += dx elif event.type == graphics.const.MOUSEBUTTONUP: if self.was_dragged: dx, dy = _subpoints(self.start_dragging, event.pos) self.vx = _scroll_speed_func(self.vx, dx) self.vy = _scroll_speed_func(self.vy, dy) self.y += dy self.x += dx else: if self.start_dragging: self.post_mouse_event( ui.Event( graphics.const.MOUSEBUTTONDOWN, { 'pos': self.start_dragging, 'abs_pos': self.start_dragging_abs })) self.post_mouse_event(event) self.start_dragging = None self.was_dragged = False self.canceled_event(event) else: self.item.event(event) self.normalize()
def event(self, ev): if hasattr(ev, 'pos'): pos = self.get_pos() ev.pos = _subpoints(ev.pos, pos) if ev.pos[0] < 0 or ev.pos[1] < 0: return size = self.item.size if ev.pos[1] > size[1] or ev.pos[0] > size[0]: return result = self.item.event(ev) ev.pos = _addpoints(ev.pos, pos) return result else: self.item.event(ev)