From 1aac389b534644b3b3d417eaefef3481fff6bb80 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Wed, 30 Jul 2014 22:19:13 +0100 Subject: [PATCH 1/4] Added canvas texture example (tex_coords, wrap) --- examples/canvas/texture.py | 126 +++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 examples/canvas/texture.py diff --git a/examples/canvas/texture.py b/examples/canvas/texture.py new file mode 100644 index 000000000..919caa817 --- /dev/null +++ b/examples/canvas/texture.py @@ -0,0 +1,126 @@ +''' +Example of changing texture properties and the properties +of its containing rectangle. +''' + + +from kivy.uix.widget import Widget +from kivy.properties import ObjectProperty, ListProperty, StringProperty +from kivy.lang import Builder +from kivy.clock import Clock +from kivy.base import runTouchApp + + +class TextureAccessibleWidget(Widget): + texture = ObjectProperty(None) + tex_coords = ListProperty([0, 0, 1, 0, 1, 1, 0, 1]) + texture_wrap = StringProperty('clamp_to_edge') + + def __init__(self, **kwargs): + super(TextureAccessibleWidget, self).__init__(**kwargs) + print 'children', self.canvas.children + # self.texture = self.canvas.children[-1].texture + # self.texture.wrap = 'repeat' + + def update(self, dt): + tcs = self.tex_coords + for i in range(0, 8, 2): + self.tex_coords[i] += dt/3. + + +root = Builder.load_string(''' +: + canvas: + Rectangle: + pos: self.pos + size: self.size + source: 'colours2.png' + tex_coords: root.tex_coords + +: + min: 0.0 + max: 1.0 + value: slider.value + Slider: + id: slider + orientation: root.orientation + min: root.min + max: root.max + value: 1.0 + Label: + size_hint: None, None + size: min(root.size), min(root.size) + text: str(slider.value)[:4] + +BoxLayout: + orientation: 'vertical' + BoxLayout: + SliderWithValue: + orientation: 'vertical' + size_hint_x: None + width: dp(40) + min: 0 + max: 5 + value: 1 + on_value: taw.tex_coords[5] = self.value + on_value: taw.tex_coords[7] = self.value + SliderWithValue: + orientation: 'vertical' + size_hint_x: None + width: dp(40) + min: 0 + max: taw_container.height + value: 0.5*taw_container.height + on_value: taw.height = self.value + AnchorLayout: + id: taw_container + anchor_x: 'left' + anchor_y: 'bottom' + TextureAccessibleWidget: + id: taw + size_hint: None, None + BoxLayout: + size_hint_y: None + height: dp(80) + BoxLayout: + orientation: 'vertical' + size_hint_x: None + width: dp(80) + Label: + text: 'size' + text_size: self.size + halign: 'right' + Label: + text: 'tex_coords' + text_size: self.size + halign: 'left' + BoxLayout: + orientation: 'vertical' + SliderWithValue: + min: 0 + max: taw_container.width + value: 0.5*taw_container.width + on_value: taw.width = self.value + SliderWithValue: + min: 0. + max: 5. + value: 1. + on_value: taw.tex_coords[2] = self.value + on_value: taw.tex_coords[4] = self.value + + BoxLayout: + size_hint_y: None + height: dp(50) + Button: + text: 'clamp_to_edge' + on_press: taw.texture_wrap = 'clamp_to_edge' + Button: + text: 'repeat' + on_press: taw.texture_wrap = 'repeat' + Button: + text: 'mirrored_repeat' + on_press: taw.texture_wrap = 'mirrored_repeat' + +''') + +runTouchApp(root) From 8fc1c193edac22d5c2500df60adae20ceedb2457 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Wed, 30 Jul 2014 22:23:36 +0100 Subject: [PATCH 2/4] Fixed texture example bug with finding texture --- examples/canvas/texture.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/canvas/texture.py b/examples/canvas/texture.py index 919caa817..b320009e6 100644 --- a/examples/canvas/texture.py +++ b/examples/canvas/texture.py @@ -18,18 +18,18 @@ class TextureAccessibleWidget(Widget): def __init__(self, **kwargs): super(TextureAccessibleWidget, self).__init__(**kwargs) - print 'children', self.canvas.children - # self.texture = self.canvas.children[-1].texture - # self.texture.wrap = 'repeat' + Clock.schedule_once(self.texture_init, 0) - def update(self, dt): - tcs = self.tex_coords - for i in range(0, 8, 2): - self.tex_coords[i] += dt/3. + def texture_init(self, *args): + self.texture = self.canvas.children[-1].texture + + def on_texture_wrap(self, instance, value): + self.texture.wrap = value root = Builder.load_string(''' : + on_touch_down: print self.canvas.children canvas: Rectangle: pos: self.pos @@ -90,10 +90,12 @@ BoxLayout: text: 'size' text_size: self.size halign: 'right' + valign: 'middle' Label: text: 'tex_coords' text_size: self.size halign: 'left' + valign: 'middle' BoxLayout: orientation: 'vertical' SliderWithValue: From 92b0b544827b81440e5cdf8c08af861bf7e775f4 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Wed, 30 Jul 2014 22:27:22 +0100 Subject: [PATCH 3/4] Changed texture example ui to be clearer --- examples/canvas/texture.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/canvas/texture.py b/examples/canvas/texture.py index b320009e6..3ad4ed2c0 100644 --- a/examples/canvas/texture.py +++ b/examples/canvas/texture.py @@ -113,6 +113,11 @@ BoxLayout: BoxLayout: size_hint_y: None height: dp(50) + Label: + text: 'texture wrap:' + text_size: self.size + valign: 'middle' + halign: 'center' Button: text: 'clamp_to_edge' on_press: taw.texture_wrap = 'clamp_to_edge' From 256a9373b579f7a22df660b4defe7fc4a62162fd Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Wed, 30 Jul 2014 22:33:53 +0100 Subject: [PATCH 4/4] Added image for texture example --- examples/canvas/texture.py | 4 +--- examples/canvas/texture_example_image.png | Bin 0 -> 5463 bytes 2 files changed, 1 insertion(+), 3 deletions(-) create mode 100644 examples/canvas/texture_example_image.png diff --git a/examples/canvas/texture.py b/examples/canvas/texture.py index 3ad4ed2c0..396d44faf 100644 --- a/examples/canvas/texture.py +++ b/examples/canvas/texture.py @@ -26,7 +26,6 @@ class TextureAccessibleWidget(Widget): def on_texture_wrap(self, instance, value): self.texture.wrap = value - root = Builder.load_string(''' : on_touch_down: print self.canvas.children @@ -34,7 +33,7 @@ root = Builder.load_string(''' Rectangle: pos: self.pos size: self.size - source: 'colours2.png' + source: 'texture_example_image.png' tex_coords: root.tex_coords : @@ -127,7 +126,6 @@ BoxLayout: Button: text: 'mirrored_repeat' on_press: taw.texture_wrap = 'mirrored_repeat' - ''') runTouchApp(root) diff --git a/examples/canvas/texture_example_image.png b/examples/canvas/texture_example_image.png new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