Created
November 24, 2016 14:57
-
-
Save s-light/e4d904dddc2a09cc8425e6f96da9dc4e to your computer and use it in GitHub Desktop.
Kivy test for Rotation and collide_point in on_touch_move
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# coding=utf-8 | |
""" | |
Basic Kivy Rotation Test. | |
minimal setup to test collide_point and rotation behavior | |
""" | |
import kivy | |
from kivy.app import App | |
from kivy.uix.widget import Widget | |
from kivy.vector import Vector | |
from kivy.clock import Clock | |
from kivy.properties import ( | |
NumericProperty, | |
ReferenceListProperty, | |
ObjectProperty | |
) | |
kivy.require('1.9.0') | |
########################################## | |
########################################## | |
class SliderTrack(Widget): | |
""" | |
A Track. | |
could change color according to value.. | |
""" | |
pass | |
class SliderHandle(Widget): | |
"""A Handle.""" | |
def on_touch_move(self, touch): | |
"""Move Handle with touch.""" | |
# print(self) | |
# print(touch) | |
if self.collide_point(touch.x, touch.y): | |
# TODO: touch point is not center.. | |
# calculate realtive movement based on touch pos... | |
center_y_new = touch.y | |
if ( | |
(touch.y + (self.height/2) < self.parent.top) and | |
(touch.y - (self.height/2) > self.parent.y) | |
): | |
self.center_y = center_y_new | |
return True | |
class MySlider(Widget): | |
"""A Slider.""" | |
test = NumericProperty(0) | |
########################################## | |
class TestGui(Widget): | |
"""The Gui.""" | |
pass | |
########################################## | |
class RotationTestApp(App): | |
"""My first Pong App.""" | |
def build(self): | |
"""Kivy entry point.""" | |
testgui = TestGui() | |
return testgui | |
########################################## | |
if __name__ == '__main__': | |
RotationTestApp().run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#:kivy 1.9.0 | |
<SliderTrack>: | |
size: 1, (self.parent.height-2) | |
canvas: | |
Color: | |
rgb: (0, 0, 1) | |
Rectangle: | |
pos:self.pos | |
size:self.size | |
<SliderHandle>: | |
size: 50, 200 | |
canvas: | |
Color: | |
rgb: (0.7, 0.5, 1) | |
Rectangle: | |
pos:self.pos | |
size:self.size | |
<MySlider>: | |
handle: slider_handle | |
track: slider_track | |
size: 200, 500 | |
angle: 0 | |
canvas.before: | |
PushMatrix | |
Rotate: | |
angle: self.angle | |
axis: 0, 0, 1 | |
origin: self.center | |
canvas: | |
Color: | |
rgb: (1, 1, 0) | |
Rectangle: | |
pos: self.pos | |
size: self.size | |
canvas.after: | |
PopMatrix | |
Label: | |
font_size: 70 | |
center: self.parent.center | |
# center_x: self.parent.width/2 | |
# center_y: (self.parent.height/2) + (self.height / 2) | |
text: str(self.parent.test) | |
SliderTrack: | |
id: slider_track | |
center_x: slider_handle.center_x | |
center_y: self.parent.center_y | |
SliderHandle: | |
id: slider_handle | |
x: self.parent.x | |
center_y: self.parent.center_y | |
<TestGui>: | |
slider1: slider_1 | |
slider2: slider_2 | |
canvas: | |
Color: | |
rgb: (0.5, 0.5, 0.5) | |
Rectangle: | |
pos: self.center_x - 5, 0 | |
size: 4, self.height | |
MySlider: | |
id: slider_1 | |
x: root.x | |
center_y: root.center_y | |
angle: 0 | |
MySlider: | |
id: slider_2 | |
x: root.width-self.width | |
center_y: root.center_y | |
angle: 45 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment