diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-07-30 14:14:44 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-08-10 13:49:30 (GMT) |
commit | e4edef2c1c2decc4c48453ac621c1e71dc3cf8e8 (patch) | |
tree | b48821f17a74ac42fc4addda72dae99e0871c9d4 /Area.py | |
parent | 8816613106bf02a30dce4f9b92274c1ee36d8e5e (diff) |
Use cairo surfaces instead of pixbuf to undo/redo
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'Area.py')
-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') |