def on_update(self): super(MTVKeyboard, self).on_update() self._update() if not len(self._last_key_down): return self._last_key_repeat_timeout -= getFrameDt() if self._last_key_repeat_timeout < 0: self._last_key_repeat -= getFrameDt() if self._last_key_repeat > 0: return self._last_key_repeat = self.repeat key = self._last_key_down[-1] self.dispatch_event('on_key_down', key, True) self.dispatch_event('on_key_up', key, True)
def on_draw(self): super(MTScreenLayout, self).on_draw() if self._switch_t < 1.0: if self.duration == 0: self._switch_t = 1. else: self._switch_t += getFrameDt() / self.duration self.draw_transition(self._switch_t)
def process_kinetic(self): dt = getFrameDt() friction = self.friction container = self.container cw = container.width - self.width ch = container.height - self.height cx = self.content_x cy = self.content_y vx = self._vx vy = self._vy # prevent too much calculation at idle state if abs(vx) < 0.01: vx = 0 if abs(vy) < 0.01: vy = 0 # apply friction for movement if vx or vy: vx /= 1 + (friction * dt) vy /= 1 + (friction * dt) if self._is_controled is False: cx -= vx * self.do_x cy -= vy * self.do_y if self._is_controled is False: # make the content back to origin if it's out of bounds # don't go back to the initial bound, but use friction to do it in a # smooth way. # # if the container is smaller than our width, always align to left # XXX should be customizable. # f = 1 + self.friction_bound * dt smaller = self.width > container.width if cx > 0 or smaller: cx /= f vx = 0 elif cx < -cw and not smaller: a = (cw + cx) / f cx = -cw + a vx = 0 smaller = self.height > container.height if cy > 0 or smaller: cy /= f vy = 0 elif cy < -ch and not smaller: a = (ch + cy) / f cy = -ch + a vy = 0 # update our values self.content_x = container.content_x = cx self.content_y = container.content_y = cy container.pos = self.pos self._vx = vx self._vy = vy
def process_kinetic(self): '''Apply kinetic movement to all the items''' dt = getFrameDt() self.vx /= 1 + (self.friction * dt) self.vy /= 1 + (self.friction * dt) self.xoffset += self.vx * self.do_x self.yoffset += self.vy * self.do_y self.ensure_bounding()
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 on_update(self): self.cursor_fade = (self.cursor_fade + getFrameDt() * 2) % 2
def on_update(self): super(MTTextArea, self).on_update() self.cursor_fade = (self.cursor_fade + getFrameDt() * 2) % 2