diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-07-24 18:21:43 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-07-24 18:21:43 (GMT) |
commit | 04dbf8ae9727ead8ef4e645f8d807d477db522c0 (patch) | |
tree | ddb0a41c39b7b67e3cc821099f8c33bc64db4ec1 | |
parent | 5798ecd088f969fe36b57387cecc236f0198844b (diff) |
Implement stamp tool with cairo
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | Area.py | 11 | ||||
-rw-r--r-- | Desenho.py | 12 | ||||
-rw-r--r-- | widgets.py | 7 |
3 files changed, 20 insertions, 10 deletions
@@ -732,11 +732,12 @@ class Area(gtk.DrawingArea): """ if self.is_selected(): # Change stamp, get it from selection: - _x, _y, width, height = self.get_selection_bounds() - self.pixbuf_stamp = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, - 8, width, height) - self.pixbuf_stamp.get_from_drawable(self.pixmap_sel, - gtk.gdk.colormap_get_system(), 0, 0, 0, 0, width, height) + pixbuf_data = StringIO.StringIO() + self.get_selection().write_to_png(pixbuf_data) + pxb_loader = gtk.gdk.PixbufLoader(image_type='png') + pxb_loader.write(pixbuf_data.getvalue()) + + self.pixbuf_stamp = pxb_loader.get_pixbuf() self.stamp_size = 0 # Set white color as transparent: stamp_alpha = self.pixbuf_stamp.add_alpha(True, 255, 255, 255) @@ -164,15 +164,21 @@ class Desenho: @param stamp_size -- integer (default 20) """ + widget.desenha = False - gc = widget.gc_brush width = widget.resized_stamp.get_width() height = widget.resized_stamp.get_height() dx = coords[0] - width / 2 dy = coords[1] - height / 2 - widget.pixmap.draw_pixbuf(gc, widget.resized_stamp, - 0, 0, dx, dy, width, height) + + widget.drawing_ctx.save() + widget.drawing_ctx.translate(dx, dy) + widget.drawing_ctx.rectangle(dx, dy, width, height) + temp_ctx = gtk.gdk.CairoContext(widget.drawing_ctx) + temp_ctx.set_source_pixbuf(widget.resized_stamp, 0, 0) + widget.drawing_ctx.paint() + widget.drawing_ctx.restore() widget.queue_draw() @@ -123,8 +123,11 @@ class BrushButton(_ColorButton): height = self._resized_stamp.get_height() dx = center - width / 2 dy = center - height / 2 - self.pixmap.draw_pixbuf(self._gc, self._resized_stamp, - 0, 0, dx, dy, width, height) + + self._ctx.rectangle(dx, dy, width, height) + temp_ctx = gtk.gdk.CairoContext(self._ctx) + temp_ctx.set_source_pixbuf(self._resized_stamp, 0, 0) + self._ctx.paint() else: red = float(self._color.red) / 65535.0 |