From 36ad725f12467ab7b9dd56827b37d1f267f7ef6f Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Tue, 03 May 2011 03:38:15 +0000 Subject: Stamp refactor and brush square shape fix --- diff --git a/Area.py b/Area.py index 8d2ea96..a668837 100644 --- a/Area.py +++ b/Area.py @@ -292,14 +292,11 @@ class Area(gtk.DrawingArea): if not self.drawing: # draw stamp border in widget.window if self.tool['name'] == 'stamp': - size = self.tool['stamp size'] - w = self.pixbuf_stamp.get_width() - h = self.pixbuf_stamp.get_height() - wr, hr = size, int(size * h * 1.0 / w) + wr, hr = self.stamp_dimentions widget.window.draw_rectangle(self.gc_brush, False, self.x_cursor - wr / 2, self.y_cursor - hr / 2, wr, hr) - + # draw shape of the brush, square or circle elif self.tool['line shape'] == 'circle': size = self.tool['line size'] @@ -431,7 +428,7 @@ class Area(gtk.DrawingArea): if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None: if self.tool['name'] == 'pencil': self.d.brush(widget, coords, self.last, - self.tool['line size'], 'circle') + self.tool['line size'], self.tool['line shape']) self.last = coords elif self.tool['name'] == 'eraser': @@ -677,8 +674,7 @@ class Area(gtk.DrawingArea): self.stamp_size = 0 self.pixbuf_stamp = self.pixbuf_stamp.add_alpha(True, 255, 255, 255) - self.resizeStamp(self.tool['stamp size']) - return self.pixbuf_stamp + return self.resizeStamp(self.tool['stamp size']) def resizeStamp(self, stamp_size): """Change stamping pixbuffer from the given size. @@ -691,13 +687,17 @@ class Area(gtk.DrawingArea): logging.error('Area.resizeStamp(self) needs Area.setupStamp called first.') return - # Resize stamp to fit brush size as the width: - if self.stamp_size != stamp_size: - self.stamp_size = stamp_size - w = self.pixbuf_stamp.get_width() - h = self.pixbuf_stamp.get_height() + self.stamp_size = stamp_size + w = self.pixbuf_stamp.get_width() + h = self.pixbuf_stamp.get_height() + if w >= h: wr, hr = stamp_size, int(stamp_size * h * 1.0 / w) - self.resized_stamp = self.pixbuf_stamp.scale_simple(wr, hr, gtk.gdk.INTERP_HYPER) + else: + wr, hr = int(stamp_size * w * 1.0 / h), stamp_size + self.stamp_dimentions = wr, hr + self.resized_stamp = self.pixbuf_stamp.scale_simple(wr, hr, gtk.gdk.INTERP_HYPER) + + return self.resized_stamp def undo(self): """Undo the last drawing change. diff --git a/Desenho.py b/Desenho.py index b0233f9..20d5bf0 100644 --- a/Desenho.py +++ b/Desenho.py @@ -176,9 +176,6 @@ class Desenho: def _trace(self, widget, gc, coords, last, size, shape='circle', stamping=False): if stamping: - # TODO call this as a signal when size changes - widget.resizeStamp(size) - width = widget.resized_stamp.get_width() height = widget.resized_stamp.get_height() widget.pixmap.draw_pixbuf(gc, widget.resized_stamp, diff --git a/toolbox.py b/toolbox.py index 9ba90ce..73930e3 100644 --- a/toolbox.py +++ b/toolbox.py @@ -311,12 +311,11 @@ class ToolsToolbarBuilder(): @param tool_name --The name of the selected tool """ if tool_name == 'stamp': - pixbuf = self._activity.area.setupStamp() - # Put stamp in menu widget: - self._stroke_color.color_button._pixbuf_stamp = pixbuf - self._stroke_color.set_stamping(True) + resized_stamp = self._activity.area.setupStamp() + self._stroke_color.color_button.set_resized_stamp(resized_stamp) else: - self._stroke_color.set_stamping(False) + self._stroke_color.color_button.stop_stamping() + self._stroke_color.update_stamping() self.properties['name'] = tool_name self._activity.area.set_tool(self.properties) diff --git a/widgets.py b/widgets.py index 50be573..36d5327 100644 --- a/widgets.py +++ b/widgets.py @@ -30,8 +30,7 @@ class BrushButton(_ColorButton): self._brush_size = 2 self._stamp_size = 20 self._brush_shape = 'circle' - self._stamping = False - self._pixbuf_stamp = None + self._resized_stamp = None self._preview = gtk.DrawingArea() self._preview.set_size_request(style.STANDARD_ICON_SIZE, style.STANDARD_ICON_SIZE) @@ -96,13 +95,15 @@ class BrushButton(_ColorButton): stamp_size = gobject.property(type=int, getter=get_stamp_size, setter=set_stamp_size) - def set_stamping(self, stamping): - # receive True or False - self._stamping = stamping + def set_resized_stamp(self, resized_stamp): + self._resized_stamp = resized_stamp + + def stop_stamping(self): + self._resized_stamp = None self._preview.queue_draw() def is_stamping(self): - return self._stamping + return self._resized_stamp != None def expose(self, widget, event): if self._gc is None: @@ -114,15 +115,10 @@ class BrushButton(_ColorButton): True, 0, 0, style.STANDARD_ICON_SIZE, style.STANDARD_ICON_SIZE) self._gc.set_foreground(self._color) - if self._stamping: - w = self._pixbuf_stamp.get_width() - h = self._pixbuf_stamp.get_height() - wr, hr = self._stamp_size, int(self._stamp_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, + if self.is_stamping(): + width = self._resized_stamp.get_width() + height = self._resized_stamp.get_height() + self.pixmap.draw_pixbuf(self._gc, self._resized_stamp, 0, 0, center - width / 2, center - height / 2, width, height) else: @@ -178,12 +174,6 @@ class ButtonStrokeColor(gtk.ToolItem): def __init__(self, activity, **kwargs): self._activity = activity self.properties = self._activity.area.tool - - # This determines if the stamping tool is in use, if True the - # size changes the stamping size, else it changes the brush - # size: - self._stamping = False - self._accelerator = None self._tooltip = None self._palette_invoker = ToolInvoker() @@ -272,12 +262,12 @@ class ButtonStrokeColor(gtk.ToolItem): style.SMALL_ICON_SIZE) image2.set_from_pixbuf(pixbuf2) item2.set_image(image2) - + item1.connect('toggled', self._on_toggled, self.properties, 'circle') item2.connect('toggled', self._on_toggled, self.properties, 'square') - + label = gtk.Label(_('Shape')) - + self.vbox_brush_options.pack_start(label) self.vbox_brush_options.pack_start(item1) self.vbox_brush_options.pack_start(item2) @@ -301,7 +291,7 @@ class ButtonStrokeColor(gtk.ToolItem): def _update_palette(self): palette_children = self._palette._picker_hbox.get_children() - if self._stamping: + if self.color_button.is_stamping(): # Hide palette color widgets: for ch in palette_children[:4]: ch.hide_all() @@ -321,22 +311,19 @@ class ButtonStrokeColor(gtk.ToolItem): self._palette._picker_hbox.resize_children() self._palette._picker_hbox.queue_draw() - def set_stamping(self, stamping): - self._stamping = stamping - self.color_button.set_stamping(stamping) - if stamping: + def update_stamping(self): + if self.color_button.is_stamping(): self.size_spinbutton.set_value(self.color_button.stamp_size) else: self.size_spinbutton.set_value(self.color_button.brush_size) self._update_palette() - def is_stamping(self): - return self._stamping - def _on_value_changed(self, spinbutton): size = spinbutton.get_value_as_int() - if self.is_stamping(): + if self.color_button.is_stamping(): self.properties['stamp size'] = size + resized_stamp = self._activity.area.resizeStamp(size) + self.color_button.set_resized_stamp(resized_stamp) self.color_button.set_stamp_size(self.properties['stamp size']) else: self.properties['line size'] = size -- cgit v0.9.1