def on_touch(self, xy, action): if action == "down" and self.local_rect.collidepoint(xy): self.drag_start = True self.drag_origin = xy if self.flicking: self.flick_timer.stop() self.dragging = True self.last_move = [(xy, pygame.time.get_ticks())] self.drag_offset = _xy_add(self.position, self.drag_origin) if action == "move" and self.drag_start: if self.dragging: self.last_move.append((xy, pygame.time.get_ticks())) self.last_move[:] = self.last_move[-5:] if self.hslider: self.set_x(self.drag_offset[0] - xy[0]) if self.vslider: self.set_y(self.drag_offset[1] - xy[1]) action = "drag" else: if self.distance(xy, self.drag_origin) > 15: self.dragging = True self.last_move = [(xy, pygame.time.get_ticks())] self.drag_offset = _xy_add(self.position, self.drag_origin) if action in ("up", "drag_up"): self.drag_start = False if self.dragging: action = "drag_up" self.dragging = False if len(self.last_move) >= 3: try: self.start_flick( self.get_velocity(self.last_move[-1], self.last_move[0])) except ZeroDivisionError: # ignore divide by zero errors pass self.last_move = [] # translate xy positions to account for panel position, and pass on to # the panel for processing self.panel.on_touch(_xy_add(xy, self.position), action)
def on_touch(self, xy, action): if action=="down" and self.local_rect.collidepoint(xy): if self.flicking: self.flick_timer.stop() self.dragging=True self.drag_start=True self.drag_origin = xy if action=="move" and self.drag_start: if self.dragging: self.last_move.append((xy,pygame.time.get_ticks())) self.last_move[:] = self.last_move[-5:] if self.hslider: self.set_x(self.drag_offset[0]-xy[0]) if self.vslider: self.set_y(self.drag_offset[1]-xy[1]) action="drag" else: if self.distance(xy,self.drag_origin)>15: self.dragging=True self.last_move = [(xy,pygame.time.get_ticks())] self.drag_offset = _xy_add(self.position,self.drag_origin) if action in ("up","drag_up"): self.drag_start = False if self.dragging: action="drag_up" self.dragging = False if len(self.last_move)>=3: try: self.start_flick(self.get_velocity(self.last_move[-1],self.last_move[0])) except ZeroDivisionError: # ignore divide by zero errors pass self.last_move = [] # translate xy positions to account for panel position, and pass on to # the panel for processing self.panel.on_touch(_xy_add(xy, self.position), action)
def get_abs_position(self): return _xy_add(self.parent.get_abs_position(), self.xy)