OSDN Git Service

brusheditor: don't undo non-strokes for live update
authorMartin Renold <martinxyz@gmx.ch>
Tue, 30 Aug 2011 17:49:22 +0000 (19:49 +0200)
committerMartin Renold <martinxyz@gmx.ch>
Tue, 30 Aug 2011 17:55:23 +0000 (19:55 +0200)
https://gna.org/bugs/?18581
And move some code closer to where it belongs.

gui/brushsettingswindow.py
lib/document.py

index 3e169b9..7421d82 100644 (file)
@@ -210,16 +210,6 @@ class Window(windowing.SubWindow):
         def do_update():
             self.live_update_queued = False
             doc = self.app.doc.model
-            cmd = 'something'
-            while cmd:
-                cmd = doc.undo()
-                if isinstance(cmd, command.Stroke):
-                    # found it
-                    # bad design that we need to touch internals document.py here...
-                    new_stroke = cmd.stroke.copy_using_different_brush(self.app.brush)
-                    snapshot_before = doc.layer.save_snapshot()
-                    new_stroke.render(doc.layer.surface)
-                    doc.do(command.Stroke(doc, new_stroke, snapshot_before))
-                    break
+            doc.redo_last_stroke_with_different_brush(self.app.brush)
         gobject.idle_add(do_update)
 
index bec8b32..353d605 100644 (file)
@@ -178,6 +178,17 @@ class Document():
         if split:
             self.split_stroke()
 
+    def redo_last_stroke_with_different_brush(self, brush):
+        cmd = self.get_last_command()
+        if not isinstance(cmd, command.Stroke):
+            return
+        cmd = self.undo()
+        assert isinstance(cmd, command.Stroke)
+        new_stroke = cmd.stroke.copy_using_different_brush(brush)
+        snapshot_before = self.layer.save_snapshot()
+        new_stroke.render(self.layer.surface)
+        self.do(command.Stroke(self, new_stroke, snapshot_before))
+
     def straight_line(self, src, dst):
         self.split_stroke()
         self.brush.reset() # reset dynamic states (eg. filtered velocity)