From 8a99b79985995d2e796f655dc0984f8e8b7afbbe Mon Sep 17 00:00:00 2001 From: Ayush Goyal Date: Wed, 20 Oct 2010 14:02:32 +0000 Subject: Implemented Mirroring Effect in Paint Activity (SL#2463) Two mirror effects 'Mirror Horizontal' and 'Mirror Vertical' have been added. Mirror horizontal tool flips the entire image or selected area horizontally. Mirror vertical tool does the same vertically. Signed-off-by: Ayush Goyal --- diff --git a/Area.py b/Area.py index a4f744f..eef8d99 100644 --- a/Area.py +++ b/Area.py @@ -966,6 +966,53 @@ class Area(gtk.DrawingArea): if not self.selmove: self.enableUndo(widget) + def mirror(self, widget, horizontal=True): + """Apply mirror horizontal/vertical effect. + + @param self -- the Area object (GtkDrawingArea) + @param widget -- the Area object (GtkDrawingArea) + @param horizontal -- If true sets flip as horizontal else vertical + + """ + + width, height = self.window.get_size() + + if self.selmove: + size = self.pixmap_sel.get_size() + pix = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, + size[0], size[1]) + pix.get_from_drawable(self.pixmap_sel, + gtk.gdk.colormap_get_system(), 0, 0, 0, 0, size[0], size[1]) + else: + pix = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, + width, height) + pix.get_from_drawable(self.pixmap, gtk.gdk.colormap_get_system(), + 0, 0, 0, 0, width, height) + + pix = pix.flip(horizontal) + + if self.selmove: + self.pixmap_sel.draw_pixbuf(self.gc, pix, 0, 0, 0, 0, + size[0], size[1], dither=gtk.gdk.RGB_DITHER_NORMAL, + x_dither=0, y_dither=0) + + self.pixmap_temp.draw_drawable(self.gc, self.pixmap, 0, 0, 0, 0, + width, height) + self.pixmap_temp.draw_drawable(self.gc, self.pixmap_sel, + 0, 0, self.orig_x, self.orig_y, size[0], size[1]) + self.pixmap_temp.draw_rectangle(self.gc_selection, False, + self.orig_x, self.orig_y, size[0], size[1]) + self.pixmap_temp.draw_rectangle(self.gc_selection1, False, + self.orig_x - 1, self.orig_y - 1, size[0] + 2, size[1] + 2) + + else: + self.pixmap.draw_pixbuf(self.gc, pix, 0, 0, 0, 0, width, height, + dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0) + + self.queue_draw() + if not self.selmove: + self.enableUndo(widget) + def _pixbuf2Image(self, pb): """change a pixbuf to RGB image diff --git a/icons/mirror-horizontal.svg b/icons/mirror-horizontal.svg new file mode 100644 index 0000000..2554356 --- /dev/null +++ b/icons/mirror-horizontal.svg @@ -0,0 +1,272 @@ + +image/svg+xml \ No newline at end of file diff --git a/icons/mirror-vertical.svg b/icons/mirror-vertical.svg new file mode 100644 index 0000000..0bfd72b --- /dev/null +++ b/icons/mirror-vertical.svg @@ -0,0 +1,272 @@ + +image/svg+xml \ No newline at end of file diff --git a/toolbox.py b/toolbox.py index 1ff4e6f..d8b75ee 100644 --- a/toolbox.py +++ b/toolbox.py @@ -1276,6 +1276,16 @@ class EffectsToolbar(gtk.Toolbar): separator = gtk.SeparatorToolItem() self.insert(separator, -1) + self._mirror_horizontal = ToolButton('mirror-horizontal') + self.insert(self._mirror_horizontal, -1) + self._mirror_horizontal.show() + self._mirror_horizontal.set_tooltip(_('Mirror Horizontal')) + + self._mirror_vertical = ToolButton('mirror-vertical') + self.insert(self._mirror_vertical, -1) + self._mirror_vertical.show() + self._mirror_vertical.set_tooltip(_('Mirror Vertical')) + """ #FIXME: Must be implemented self._black_and_white = ToolButton('black_and_white') @@ -1290,6 +1300,8 @@ class EffectsToolbar(gtk.Toolbar): self._effect_grayscale.connect('clicked', self.grayscale) self._effect_rainbow.connect('clicked', self.rainbow) self._invert_colors.connect('clicked', self.invert_colors) + self._mirror_vertical.connect('clicked', self.mirror_vertical) + self._mirror_horizontal.connect('clicked', self.mirror_horizontal) ##Make the colors be in grayscale def grayscale(self, widget): @@ -1302,6 +1314,12 @@ class EffectsToolbar(gtk.Toolbar): def invert_colors(self, widget): self._activity.area.invert_colors(widget) + def mirror_horizontal(self, widget): + self._activity.area.mirror(widget) + + def mirror_vertical(self, widget): + self._activity.area.mirror(widget, horizontal=False) + # setting cursor: moved to Area def _configure_palette(self, button, tool=None): -- cgit v0.9.1