diff options
Diffstat (limited to 'Desenho.py')
-rw-r--r-- | Desenho.py | 90 |
1 files changed, 36 insertions, 54 deletions
@@ -139,7 +139,7 @@ class Desenho: """ widget.desenha = False - self._trace(widget, widget.gc_brush, coords, last, size, 'stamp') + self._trace(widget, widget.gc_brush, coords, last, size, stamping=True) def rainbow(self, widget, coords, last, color, size=5, shape='circle'): """Paint with rainbow. @@ -173,61 +173,43 @@ class Desenho: widget.desenha = False self._trace(widget, widget.gc_rainbow, coords, last, size, shape) - def _trace(self, widget, gc, coords, last, size, shape): - if shape == 'circle': - widget.pixmap.draw_arc(gc, True, - coords[0] - size / 2, coords[1] - size / 2, - size, size, 0, 360 * 64) - if last: - gc.set_line_attributes(size, gtk.gdk.LINE_SOLID, - gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) - widget.pixmap.draw_line(gc, - 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) + def _trace(self, widget, gc, coords, last, size, shape='circle', stamping=False): - elif shape == 'square': - widget.pixmap.draw_rectangle(gc, True, - coords[0] - size / 2, coords[1] - size / 2, size, size) - if last: - points = [(last[0] - size / 2, last[1] - size / 2), - (coords[0] - size / 2, coords[1] - size / 2), - (coords[0] + size / 2, coords[1] + size / 2), - (last[0] + size / 2, last[1] + size / 2)] - widget.pixmap.draw_polygon(gc, True, points) - points = [(last[0] + size / 2, last[1] - size / 2), - (coords[0] + size / 2, coords[1] - size / 2), - (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: - width, height = widget.pixmap_sel.get_size() - self.pixbuf_stamp = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, - 8, width, height) - self.pixbuf_stamp.get_from_drawable(widget.pixmap_sel, - gtk.gdk.colormap_get_system(), 0, 0, 0, 0, width, height) - self.stamp_size = 0 + if stamping: + # TODO call this as a signal when size changes + widget.resizeStamp(size) - try: - self.pixbuf_stamp - except: - pass - else: - if self.stamp_size != size: - # Resize stamp to fit brush size as the width: - self.stamp_size = size - w = self.pixbuf_stamp.get_width() - h = self.pixbuf_stamp.get_height() - wr, hr = size, int(size * h * 1.0 / w) - self.resized_stamp = self.pixbuf_stamp.scale_simple(wr, hr, gtk.gdk.INTERP_HYPER) - - width = self.resized_stamp.get_width() - height = self.resized_stamp.get_height() - widget.pixmap.draw_pixbuf(gc, self.resized_stamp, - 0, 0, coords[0] - width / 2, coords[1] - height / 2, width, height) + width = widget.resized_stamp.get_width() + height = widget.resized_stamp.get_height() + widget.pixmap.draw_pixbuf(gc, widget.resized_stamp, + 0, 0, coords[0] - width / 2, coords[1] - height / 2, width, height) + else: + if shape == 'circle': + widget.pixmap.draw_arc(gc, True, + coords[0] - size / 2, coords[1] - size / 2, + size, size, 0, 360 * 64) + if last: + gc.set_line_attributes(size, gtk.gdk.LINE_SOLID, + gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) + widget.pixmap.draw_line(gc, + 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) + + elif shape == 'square': + widget.pixmap.draw_rectangle(gc, True, + coords[0] - size / 2, coords[1] - size / 2, size, size) + if last: + points = [(last[0] - size / 2, last[1] - size / 2), + (coords[0] - size / 2, coords[1] - size / 2), + (coords[0] + size / 2, coords[1] + size / 2), + (last[0] + size / 2, last[1] + size / 2)] + widget.pixmap.draw_polygon(gc, True, points) + points = [(last[0] + size / 2, last[1] - size / 2), + (coords[0] + size / 2, coords[1] - size / 2), + (coords[0] - size / 2, coords[1] + size / 2), + (last[0] - size / 2, last[1] + size / 2)] + widget.pixmap.draw_polygon(gc, True, points) if last: x = min(coords[0], last[0]) |