def on_touch_down(self, touch): if self in touch.ud: self.anim_complete(self, self) self.ripple_pos = ripple_pos = (touch.x, touch.y) Animation.cancel_all(self, 'ripple_rad', 'ripple_color') rc = self.ripple_color ripple_rad = self.ripple_rad self.ripple_color = [rc[0], rc[1], rc[2], 1.] anim = Animation( ripple_rad=max(self.width, self.height) * self.ripple_scale, t=self.ripple_func_in, ripple_color=[rc[0], rc[1], rc[2], self.fade_to_alpha], duration=self.ripple_duration_in) anim.start(self) with self.canvas.after: x, y = self.to_window(*self.pos) width, height = self.size #In python 3 the int cast will be unnecessary ScissorPush(x=int(round(x)), y=int(round(y)), width=int(round(width)), height=int(round(height))) self.col_instruction = Color(rgba=self.ripple_color) self.ellipse = Ellipse(size=(ripple_rad, ripple_rad), pos=(ripple_pos[0] - ripple_rad / 2., ripple_pos[1] - ripple_rad / 2.)) ScissorPop() self.bind(ripple_color=self.set_color, ripple_pos=self.set_ellipse, ripple_rad=self.set_ellipse) return super(TouchRippleBehavior, self).on_touch_down(touch)
def ripple_show(self, touch): '''Begin ripple animation on current widget. Expects touch event as argument. ''' Animation.cancel_all(self, 'ripple_rad', 'ripple_color') self._ripple_reset_pane() x, y = self.to_window(*self.pos) width, height = self.size if isinstance(self, RelativeLayout): self.ripple_pos = ripple_pos = (touch.x - x, touch.y - y) else: self.ripple_pos = ripple_pos = (touch.x, touch.y) rc = self.ripple_color ripple_rad = self.ripple_rad self.ripple_color = [rc[0], rc[1], rc[2], self.ripple_fade_from_alpha] with self.ripple_pane: ScissorPush(x=int(round(x)), y=int(round(y)), width=int(round(width)), height=int(round(height))) self.ripple_col_instruction = Color(rgba=self.ripple_color) self.ripple_ellipse = Ellipse( size=(ripple_rad, ripple_rad), pos=(ripple_pos[0] - ripple_rad / 2., ripple_pos[1] - ripple_rad / 2.)) ScissorPop() anim = Animation( ripple_rad=max(width, height) * self.ripple_scale, t=self.ripple_func_in, ripple_color=[rc[0], rc[1], rc[2], self.ripple_fade_to_alpha], duration=self.ripple_duration_in) anim.start(self)
def __init__(self, **kwargs): super(SBView, self).__init__(**kwargs) self._prior_width = None self._prior_height = None self.bind(width=self.width_changed) self.bind(height=self.height_changed) # Set and forget with self.canvas.after: ScissorPop()
def draw(self, *_): self.canvas.clear() with self.canvas: ScissorPush(x=self.pos[0], y=self.pos[1], width=self.size[0], height=self.size[1]) Color(*self.colors['bg']) Translate(self.pos[0], self.pos[1] + self.size[1]) Scale(1 / self.zoom, -1 / self.zoom, 1) Rectangle(pos=(0, 0), size=self.size) Translate(self.camx, self.camy) self.inner_draw() Translate(-self.camx, -self.camy) Scale(self.zoom, self.zoom, 1) Color(0, 0, 0) Scale(1, -1, 1) Translate(-self.pos[0], -self.pos[1] - self.size[1]) ScissorPop()
def ripple_show(self, touch): '''Begin ripple animation on current widget. Expects touch event as argument. ''' Animation.cancel_all(self, 'ripple_rad', 'ripple_bg_color', 'ripple_color') self.execution_index += 1 self._ripple_reset_pane() x, y = self.to_window(*self.pos) ripple_bg_color_fixed = self.ripple_bg_color self.ripple_bg_color = [ ripple_bg_color_fixed[0], ripple_bg_color_fixed[1], ripple_bg_color_fixed[2], self.ripple_fade_from_alpha ] if not self.circular_ripple: with self.ripple_pane_bg.before: self.ripple_bg_color_instruction = Color( rgba=self.ripple_bg_color) self.ripple_rectangle = Rectangle( size=self.size, pos=self.pos, ) width, height = self.size if isinstance(self, RelativeLayout): self.ripple_pos = ripple_pos = (touch.x - x, touch.y - y) else: self.ripple_pos = ripple_pos = (touch.x, touch.y) if self.circular_ripple: self.ripple_pos = ripple_pos = self.ripple_center if self.ripple_center else self.center rc = self.ripple_color ripple_rad = self.ripple_rad self.ripple_color = [rc[0], rc[1], rc[2], self.ripple_fade_from_alpha] with self.ripple_pane.before: if not self.circular_ripple: self.sp = ScissorPush(x=int(round(x)), y=int(round(y)), width=int(round(width)), height=int(round(height))) self.ripple_col_instruction = Color(rgba=self.ripple_color) self.ripple_ellipse = Ellipse( size=(ripple_rad, ripple_rad), pos=(ripple_pos[0] - ripple_rad / 2., ripple_pos[1] - ripple_rad / 2.)) if not self.circular_ripple: ScissorPop() self.ripple_scale = self.circular_ripple if self.circular_ripple else self.ripple_scale anim = Animation( t=self.ripple_func_in, ripple_color=[rc[0], rc[1], rc[2], self.ripple_fade_to_alpha], ripple_bg_color=[ ripple_bg_color_fixed[0], ripple_bg_color_fixed[1], ripple_bg_color_fixed[2], self.ripple_fade_to_alpha ], duration=self.ripple_duration_in, ) ripple_rad = max(width, height) / 1.62 if not self.circular_ripple else max( width, height) * self.ripple_scale radii_animation = Animation( ripple_rad=ripple_rad, t='out_expo', duration=self.ripple_duration_in + self.ripple_duration_out, ) radii_animation.start(self) anim.start(self) ei = self.execution_index fade = lambda s: self.ripple_fade(ei)