From e9f2c6333c2927bd5116f0b913fe9a68e3c0df6f Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Mon, 18 Apr 2011 15:15:29 +0000 Subject: Basic stamp --- diff --git a/Desenho.py b/Desenho.py index cb0a11e..dea4089 100644 --- a/Desenho.py +++ b/Desenho.py @@ -141,7 +141,7 @@ class Desenho: widget.desenha = False # TODO, this is a fake, not stamping at the moment: size = 40 - self._trace(widget, widget.gc_brush, coords, last, size, 'square') + self._trace(widget, widget.gc_brush, coords, last, size, 'stamp') def rainbow(self, widget, coords, last, color, size=5, shape='circle'): """Paint with rainbow. @@ -176,7 +176,7 @@ class Desenho: self._trace(widget, widget.gc_rainbow, coords, last, size, shape) def _trace(self, widget, gc, coords, last, size, shape): - if(shape == 'circle'): + if shape == 'circle': widget.pixmap.draw_arc(gc, True, coords[0] - size / 2, coords[1] - size / 2, size, size, 0, 360 * 64) @@ -187,7 +187,8 @@ class Desenho: last[0], last[1], coords[0], coords[1]) gc.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) - if(shape == 'square'): + + elif shape == 'square': widget.pixmap.draw_rectangle(gc, True, coords[0] - size / 2, coords[1] - size / 2, size, size) if last: @@ -201,7 +202,27 @@ class Desenho: (coords[0] - size / 2, coords[1] + size / 2), (last[0] - size / 2, last[1] + size / 2)] widget.pixmap.draw_polygon(gc, True, points) - + + elif shape == 'stamp': + if widget.is_selected(): + # Change stamp, get it from selection: + size = widget.pixmap_sel.get_size() + self.pixbuf_stamp = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, + 8, size[0], size[1]) + self.pixbuf_stamp.get_from_drawable(widget.pixmap_sel, + gtk.gdk.colormap_get_system(), 0, 0, 0, 0, size[0], size[1]) + + try: + self.pixbuf_stamp + except: + pass + else: + width = self.pixbuf_stamp.get_width() + height = self.pixbuf_stamp.get_height() + # TODO resize stamp to fit brush size + widget.pixmap.draw_pixbuf(gc, self.pixbuf_stamp, + 0, 0, coords[0] - width / 2, coords[1] - height / 2, width, height) + if last: x = min(coords[0], last[0]) width = max(coords[0], last[0]) - x -- cgit v0.9.1