diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-07-30 14:14:44 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-07-30 14:14:44 (GMT) |
commit | c6e05b35a0fe06301986e7f705883234e79e6363 (patch) | |
tree | c7f05e73d77844d1c0a49444fe1341b862d9d396 | |
parent | 86323d0e2072c5198ae45faad7473949e6a2844a (diff) |
Use cairo surfaces instead of pixbuf to undo/redo
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | Area.py | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -815,8 +815,10 @@ class Area(gtk.DrawingArea): if self._undo_index > 0: self._undo_index -= 1 - undo_pix = self._undo_list[self._undo_index] - self._pixbuf_to_context(undo_pix, self.drawing_ctx) + undo_surface = self._undo_list[self._undo_index] + self.drawing_ctx.set_source_surface(undo_surface, 0, 0) + self.drawing_ctx.set_operator(cairo.OPERATOR_SOURCE) + self.drawing_ctx.paint() self.queue_draw() self.emit('undo') @@ -835,8 +837,10 @@ class Area(gtk.DrawingArea): if self._undo_index < len(self._undo_list) - 1: self._undo_index += 1 - undo_pix = self._undo_list[self._undo_index] - self._pixbuf_to_context(undo_pix, self.drawing_ctx) + undo_surface = self._undo_list[self._undo_index] + self.drawing_ctx.set_source_surface(undo_surface, 0, 0) + self.drawing_ctx.set_operator(cairo.OPERATOR_SOURCE) + self.drawing_ctx.paint() self.queue_draw() self.emit('redo') @@ -862,9 +866,17 @@ class Area(gtk.DrawingArea): if overrite and self._undo_index != 0: self._undo_index -= 1 - undo_pix = temp_pix = self._surface_to_pixbuf(self.drawing_canvas) - - self._undo_list.append(undo_pix) + # copy the drawing surface in a new surface + width = self.drawing_canvas.get_width() + height = self.drawing_canvas.get_height() + undo_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) + undo_ctx = cairo.Context(undo_surface) + undo_ctx.set_source_surface(self.drawing_canvas, 0, 0) + undo_ctx.set_operator(cairo.OPERATOR_SOURCE) + undo_ctx.paint() + undo_surface.flush() + + self._undo_list.append(undo_surface) self.emit('action-saved') |