I'm creating a simple drawing application and in it, i'd like to add an undo button. What I have tried so far is this:
class DrawScreen(Screen):
r = NumericProperty(0)
g = NumericProperty(0)
b = NumericProperty(0)
brush_width = NumericProperty(2)
def on_touch_down(self, touch):
self.slider = self.ids.slider
if self.slider.collide_point(touch.x, touch.y):
self.brush_width = self.slider.value
else:
self.undo = [touch.x, touch.y]
with self.canvas.before:
Color(self.r, self.g, self.b)
touch.ud["line"] = Line(points=self.undo, width=self.brush_width)
return super(DrawScreen, self).on_touch_down(touch)
def on_touch_move(self, touch):
if self.slider.collide_point(touch.x, touch.y):
self.brush_width = self.slider.value
else:
try:
self.undo += [touch.x, touch.y]
touch.ud["line"].points = self.undo
except:
pass
return super(DrawScreen, self).on_touch_move(touch)
def color(self, r, g, b):
self.r = r
self.g = g
self.b = b
def undo_draw(self):
self.undo = []
This undo button clears the list but it doesn't affect the canvas in any way and doesn't remove any lines at all. What would be the appropriate way to go about this?