def on_touch_down(self, touch): kt = KineticTouch(touch.device) kt.kinetic(touch) self.touch[touch.uid] = kt # grab the touch for not lost it ! touch.grab(self) getCurrentTouches().append(kt) # and dispatch ! return super(MTKinetic, self).on_touch_down(kt)
def on_touch_down(self, touch): # do a copy of the touch for kinetic if 'mov' in touch.profile: args = (touch.x, touch.y, touch.X, touch.Y) ktouch = KineticTouchXY(touch.device, args) else: args = (touch.x, touch.y) ktouch = KineticTouch(touch.device, args) ktouch.userdata = touch.userdata ktouch.is_double_tap = touch.is_double_tap self.touch[touch.uid] = ktouch # grab the touch for not lost it ! touch.grab(self) getCurrentTouches().append(ktouch) # and dispatch ! return super(MTKinetic, self).on_touch_down(ktouch)
def test_activity(self): if not self.disable_on_activity: return False # trying to get if we currently have other touch than us # discard touches generated from kinetic touches = getCurrentTouches() for touch in touches: # discard all kinetic touch if touch.__class__.__name__ == 'KineticTouch': continue # not our instance, stop mouse if touch.__class__ != MouseTouch: return True return False
def draw(self): """Draw a circle under every touches""" set_color(*self.touch_color) for touch in getCurrentTouches(): drawCircle(pos=(touch.x, touch.y), radius=self.radius)
def draw_mouse_touch(self): """Compatibility for MouseTouch, drawing a little red circle around under each mouse touches.""" set_color(0.8, 0.2, 0.2, 0.7) for t in [x for x in getCurrentTouches() if x.device == "mouse"]: drawCircle(pos=(t.x, t.y), radius=10)
def process_kinetic(self): '''Processing of kinetic, called in draw time.''' dt = getFrameDt() todelete = [] acceleration = self.max_acceleration for touchID in self.touch: ktouch = self.touch[touchID] if abs(ktouch.X) < 0.01: ktouch.X = 0 else: ktouch.X /= 1 + (self.friction * dt) ktouch.X = boundary(ktouch.X, -acceleration, acceleration) if abs(ktouch.Y) < 0.01: ktouch.Y = 0 else: ktouch.Y /= 1 + (self.friction * dt) ktouch.Y = boundary(ktouch.Y, -acceleration, acceleration) if ktouch.mode != 'spinning': continue # process kinetic event = '' ktouch.dxpos = ktouch.x ktouch.dypos = ktouch.y ktouch.x += ktouch.X ktouch.y += ktouch.Y if Vector(ktouch.X, ktouch.Y).length() < self.velstop: # simulation finished event = 'up' getCurrentTouches().remove(ktouch) super(MTKinetic, self).on_touch_up(ktouch) todelete.append(touchID) else: # simulation in progress event = 'move' super(MTKinetic, self).on_touch_move(ktouch) # dispatch ktouch also in grab mode for _wid in ktouch.grab_list[:]: wid = _wid() if wid is None: ktouch.grab_list.remove(_wid) continue ktouch.push() ktouch.x, ktouch.y = self.to_window(*ktouch.pos) ktouch.dxpos, ktouch.dypos = self.to_window(*ktouch.dpos) if wid.parent: ktouch.x, ktouch.y = wid.parent.to_widget( ktouch.x, ktouch.y) ktouch.dxpos, ktouch.dypos = wid.parent.to_widget( ktouch.dxpos, ktouch.dypos) else: ktouch.x, ktouch.y = wid.to_parent( *wid.to_widget(ktouch.x, ktouch.y)) ktouch.dxpos, ktouch.dypos = wid.to_parent( *wid.to_widget(ktouch.dxpos, ktouch.dypos)) ktouch.grab_current = wid ktouch.grab_state = True if event == 'move': wid.dispatch_event('on_touch_move', ktouch) else: # if the widget is not visible, the on_touch_up may have # disabled wid.register_event_type('on_touch_up') wid.dispatch_event('on_touch_up', ktouch) ktouch.grab_state = False ktouch.grab_current = None ktouch.pop() # remove finished event for touchID in todelete: del self.touch[touchID]
def draw(self): '''Draw a circle under every touches''' set_color(*self.touch_color) for touch in getCurrentTouches(): drawCircle(pos=(touch.x, touch.y), radius=self.radius)
def draw_mouse_touch(self): '''Compatibility for MouseTouch, drawing a little red circle around under each mouse touches.''' set_color(0.8, 0.2, 0.2, 0.7) for t in [x for x in getCurrentTouches() if x.device == 'mouse']: drawCircle(pos=(t.x, t.y), radius=10)