diff options
author | Manuel QuiƱones <manuel.por.aca@gmail.com> | 2011-04-20 20:40:40 (GMT) |
---|---|---|
committer | Manuel QuiƱones <manuel.por.aca@gmail.com> | 2011-04-20 20:40:40 (GMT) |
commit | b66d0f4fa4230fea32dbee8aedfeb213f75c1cf6 (patch) | |
tree | 244da2d8a6ea287a1aae9993bd2fffaf1d913df8 /Area.py | |
parent | 8ccccdaf7ce7dae362e63ec18392becc5ca3dd7d (diff) |
Brush button shows stamp
Diffstat (limited to 'Area.py')
-rw-r--r-- | Area.py | 43 |
1 files changed, 41 insertions, 2 deletions
@@ -630,7 +630,7 @@ class Area(gtk.DrawingArea): self.d.heart(widget, coords, False, self.tool['fill']) self.enableUndo(widget) - if self.tool['name'] in ['brush', 'eraser', 'rainbow', 'pencil']: + if self.tool['name'] in ['brush', 'eraser', 'stamp', 'rainbow', 'pencil']: self.last = [] widget.queue_draw() self.enableUndo(widget) @@ -651,6 +651,44 @@ class Area(gtk.DrawingArea): widget.queue_draw_area(self.x_cursor - size, self.y_cursor - size, size * 2, size * 2) + def setupStamp(self): + """Prepare for stamping from the selected area. + + @param self -- the Area object (GtkDrawingArea) + """ + logging.debug('Area.setupStamp(self)') + + if self.is_selected(): + # Change stamp, get it from selection: + width, height = self.pixmap_sel.get_size() + 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) + self.stamp_size = 0 + + self.resizeStamp(self.tool['line size']) + return self.pixbuf_stamp + + def resizeStamp(self, size): + """Change stamping pixbuffer from the given size. + + @param self -- the Area object (GtkDrawingArea) + """ + try: + self.pixbuf_stamp + except: + logging.error('Area.resizeStamp(self) needs Area.setupStamp called first.') + return + + # Resize stamp to fit brush size as the width: + if self.stamp_size != size: + 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) + def undo(self): """Undo the last drawing change. @@ -1256,7 +1294,8 @@ class Area(gtk.DrawingArea): cursors = {'pencil': 'pencil', 'brush': 'paintbrush', 'eraser': 'eraser', - 'bucket': 'paint-bucket'} + 'bucket': 'paint-bucket', + 'stamp': 'pencil'} display = gtk.gdk.display_get_default() if self.tool['name'] in cursors: |