Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'widgets.py')
-rw-r--r--widgets.py47
1 files changed, 34 insertions, 13 deletions
diff --git a/widgets.py b/widgets.py
index 832649b..32734fa 100644
--- a/widgets.py
+++ b/widgets.py
@@ -29,6 +29,8 @@ class BrushButton(_ColorButton):
self._accept_drag = True
self._brush_size = 2
self._brush_shape = 'circle'
+ self._stamping = False
+ self._pixbuf_stamp = None
self._preview = gtk.DrawingArea()
self._preview.set_size_request(style.STANDARD_ICON_SIZE,
style.STANDARD_ICON_SIZE)
@@ -82,7 +84,12 @@ class BrushButton(_ColorButton):
# receive gtk.gdk.Color
self._color = color
self._preview.queue_draw()
-
+
+ def set_stamping(self, stamping):
+ # receive True or False
+ self._stamping = stamping
+ self._preview.queue_draw()
+
def expose(self, widget, event):
if self._gc is None:
self._setup()
@@ -92,18 +99,32 @@ class BrushButton(_ColorButton):
self.pixmap.draw_rectangle(self._preview.get_style().white_gc,
True, 0, 0, style.STANDARD_ICON_SIZE, style.STANDARD_ICON_SIZE)
self._gc.set_foreground(self._color)
-
- if(self._brush_shape == 'circle'):
- self.pixmap.draw_arc(self._gc, True,
- center - self._brush_size / 2,
- center - self._brush_size / 2,
- self._brush_size, self._brush_size, 0, 360 * 64)
- if(self._brush_shape == 'square'):
- self.pixmap.draw_rectangle(self._gc, True,
- center - self._brush_size / 2,
- center - self._brush_size / 2,
- self._brush_size, self._brush_size)
-
+
+ if self._stamping:
+ size = self._brush_size
+ w = self._pixbuf_stamp.get_width()
+ h = self._pixbuf_stamp.get_height()
+ wr, hr = size, int(size * h * 1.0 / w)
+ resized_stamp = self._pixbuf_stamp.scale_simple(wr, hr, gtk.gdk.INTERP_HYPER)
+
+ width = resized_stamp.get_width()
+ height = resized_stamp.get_height()
+ self.pixmap.draw_pixbuf(self._gc, resized_stamp,
+ 0, 0, center - width / 2, center - height / 2, width, height)
+
+ else:
+ if self._brush_shape == 'circle':
+ self.pixmap.draw_arc(self._gc, True,
+ center - self._brush_size / 2,
+ center - self._brush_size / 2,
+ self._brush_size, self._brush_size, 0, 360 * 64)
+
+ elif self._brush_shape == 'square':
+ self.pixmap.draw_rectangle(self._gc, True,
+ center - self._brush_size / 2,
+ center - self._brush_size / 2,
+ self._brush_size, self._brush_size)
+
area = event.area
widget.window.draw_drawable(self._gc, self.pixmap,
area[0], area[1], area[0], area[1], area[2], area[3])