I'm working on selecting parts of an image by drawing a rectangle. I want to use the on_touch_down and the on_touch_move events. I took the Simple paint app from the documentation as a starting point. I thought to use on_touch_down to draw a small rectangle; on_touch_move then increases the initial size and should draw a new rectangle with the new size, using the same x, y positions as the initial rectangle. What I've tried so far is this piece of code (it is not a nice piece of code at the moment):
from kivy.uix.widget import Widget
from kivy.graphics import Color, Ellipse, Line, Rectangle
class MyPaintWidget(Widget):
def on_touch_down(self, touch):
with self.canvas:
Color(1, 1, 0)
self.d = 30.
self.dd = self.d
self.xpos = touch.x
self.ypos = touch.y
#self.rect = Rectangle(pos=(touch.x - d/2, touch.y - d/2), size=(self.width, self.height))
Rectangle(pos=(touch.x - self.d / 2, touch.y - self.d / 2), size=(self.d, self.d))
#touch.ud['line'] = Line(points=(touch.x, touch.y))
def on_touch_move(self, touch):
self.dd += 10.
Rectangle(pos=(self.xpos - self.d / 2, self.ypos - self.d / 2), size=(self.dd, self.dd))
#touch.ud['line'].points += [touch.x, touch.y]
class MyPaintApp(App):
def build(self):
return MyPaintWidget()
if __name__ == '__main__':
MyPaintApp().run()
This does not do what I want. I wonder if it is possible to resize a rectangle. Any ideas?