diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-10-02 19:05:25 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-10-02 20:52:49 (GMT) |
commit | 11bc8539259784238897e4e42f9e3c0ffd70297c (patch) | |
tree | f22d364d703873551c7b3d4b77a4e4bfd18ed56f /Area.py | |
parent | e11f26aef3761123348f032ae0b43f72f28152f4 (diff) |
Rotate using cairo
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'Area.py')
-rw-r--r-- | Area.py | 44 |
1 files changed, 31 insertions, 13 deletions
@@ -1272,7 +1272,7 @@ class Area(Gtk.DrawingArea): @param widget -- the Area object (GtkDrawingArea) """ self.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH)) - GObject.idle_add(self._rotate, widget, 90) + GObject.idle_add(self._rotate, widget, 270) def rotate_right(self, widget): """Rotate the image. @@ -1281,7 +1281,7 @@ class Area(Gtk.DrawingArea): @param widget -- the Area object (GtkDrawingArea) """ self.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH)) - GObject.idle_add(self._rotate, widget, 270) + GObject.idle_add(self._rotate, widget, 90) def _rotate(self, widget, angle): """Rotate the image. @@ -1299,9 +1299,20 @@ class Area(Gtk.DrawingArea): width, height = self.get_size() surface = self.drawing_canvas - temp_pix = self._surface_to_pixbuf(surface) + # create a surface and paste the image rotated + logging.error('create rotate surface') + rotate_surface = surface.create_similar(cairo.CONTENT_COLOR_ALPHA, + height, width) + rotate_ctx = cairo.Context(rotate_surface) + radians_angle = math.pi * float(angle) / 180.0 + rotate_ctx.rotate(radians_angle) + if radians_angle > math.pi: + rotate_ctx.translate(-width, 0) + else: + rotate_ctx.translate(0, -height) - temp_pix = temp_pix.rotate_simple(angle) + rotate_ctx.set_source_surface(surface) + rotate_ctx.paint() # copy from the pixbuf to the drawing context @@ -1310,18 +1321,25 @@ class Area(Gtk.DrawingArea): self.clear_selection_background() self.clear_selection_background(temp_canvas=True) self.set_selection_bounds(x, y, height, width) - else: - # create a new canvas with permuted dimensions - self.drawing_canvas = None - self.setup(height, width) - if self.is_selected(): - self._pixbuf_to_context(temp_pix, self.temp_ctx, x, y) + self.temp_ctx.save() + self.temp_ctx.translate(x, y) + self.temp_ctx.set_source_surface(rotate_surface) + self.temp_ctx.paint() + self.temp_ctx.restore() + self.create_selection_surface(temp_canvas=True) - else: - self._pixbuf_to_context(temp_pix, self.drawing_ctx, x, y) - del temp_pix + else: + # create a new canvas with permuted dimensions + self.drawing_canvas_data = surface.create_similar( + cairo.CONTENT_COLOR_ALPHA, height, width) + ctx = cairo.Context(self.drawing_canvas_data) + ctx.save() + ctx.set_source_surface(rotate_surface) + ctx.paint() + ctx.restore() + self.setup(height, width) self.queue_draw() if not self.is_selected(): |