Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel QuiƱones <manuel.por.aca@gmail.com>2011-04-29 00:50:21 (GMT)
committer Manuel QuiƱones <manuel.por.aca@gmail.com>2011-04-29 00:50:21 (GMT)
commit7c6acbc9380e5e4136e11735600e58eba7cde29e (patch)
tree408baffa9d991a32c6fa82cb3203b276fd1a7995
parentb2f2d7e2c519504682236eba4cafa8287a777c59 (diff)
Stamp size different than brush size
-rw-r--r--Area.py25
-rw-r--r--Desenho.py6
-rw-r--r--toolbox.py8
-rw-r--r--widgets.py61
4 files changed, 71 insertions, 29 deletions
diff --git a/Area.py b/Area.py
index 7f49a63..2d14f7b 100644
--- a/Area.py
+++ b/Area.py
@@ -131,6 +131,7 @@ class Area(gtk.DrawingArea):
## with the following keys:
## - 'name' : a string
## - 'line size' : a integer
+ ## - 'stamp size' : a integer
## - 'fill color' : a gtk.gdk.Color object
## - 'stroke color' : a gtk.gdk.Color object
## - 'line shape' : a string - 'circle' or 'square', for now
@@ -140,6 +141,7 @@ class Area(gtk.DrawingArea):
self.tool = {
'name': 'pencil',
'line size': 4,
+ 'stamp size': 20,
'fill color': None,
'stroke color': None,
'line shape': 'circle',
@@ -288,10 +290,9 @@ class Area(gtk.DrawingArea):
"""
if self.tool['name'] in ['pencil', 'eraser', 'brush', 'rainbow', 'stamp']:
if not self.drawing:
- size = self.tool['line size']
-
# 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)
@@ -299,11 +300,14 @@ class Area(gtk.DrawingArea):
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']
widget.window.draw_arc(self.gc_brush, False,
self.x_cursor - size / 2, self.y_cursor - size / 2,
size, size, 0, 360 * 64)
else:
+ size = self.tool['line size']
widget.window.draw_rectangle(self.gc_brush, False,
self.x_cursor - size / 2, self.y_cursor - size / 2,
size, size)
@@ -367,7 +371,7 @@ class Area(gtk.DrawingArea):
self.drawing = True
elif self.tool['name'] == 'stamp':
self.last = []
- self.d.stamp(widget, coords, self.last, self.tool['line size'])
+ self.d.stamp(widget, coords, self.last, self.tool['stamp size'])
self.last = coords
self.drawing = True
elif self.tool['name'] == 'rainbow':
@@ -441,7 +445,7 @@ class Area(gtk.DrawingArea):
self.last = coords
elif self.tool['name'] == 'stamp':
- self.d.stamp(widget, coords, self.last, self.tool['line size'])
+ self.d.stamp(widget, coords, self.last, self.tool['stamp size'])
self.last = coords
elif self.tool['name'] == 'rainbow':
@@ -672,10 +676,10 @@ class Area(gtk.DrawingArea):
gtk.gdk.colormap_get_system(), 0, 0, 0, 0, width, height)
self.stamp_size = 0
- self.resizeStamp(self.tool['line size'])
+ self.resizeStamp(self.tool['stamp size'])
return self.pixbuf_stamp
- def resizeStamp(self, size):
+ def resizeStamp(self, stamp_size):
"""Change stamping pixbuffer from the given size.
@param self -- the Area object (GtkDrawingArea)
@@ -687,11 +691,11 @@ class Area(gtk.DrawingArea):
return
# Resize stamp to fit brush size as the width:
- if self.stamp_size != size:
- self.stamp_size = size
+ if self.stamp_size != stamp_size:
+ self.stamp_size = 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 = stamp_size, int(stamp_size * h * 1.0 / w)
self.resized_stamp = self.pixbuf_stamp.scale_simple(wr, hr, gtk.gdk.INTERP_HYPER)
def undo(self):
@@ -1387,6 +1391,7 @@ class Area(gtk.DrawingArea):
self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.CROSS))
widget.queue_draw()
+ # TODO: unused method?
def change_line_size(self, delta):
if self.tool['name'] in ['pencil', 'eraser', 'brush', 'rainbow', 'stamp']:
size = self.tool['line size'] + delta
@@ -1395,7 +1400,7 @@ class Area(gtk.DrawingArea):
self.tool['line size'] = size
self.configure_line(size)
self.queue_draw()
-
+
def _keep_selection_ratio(self, coords):
def sign(x):
diff --git a/Desenho.py b/Desenho.py
index a530316..b0233f9 100644
--- a/Desenho.py
+++ b/Desenho.py
@@ -128,18 +128,18 @@ class Desenho:
widget.desenha = False
self._trace(widget, widget.gc_brush, coords, last, size, shape)
- def stamp(self, widget, coords, last, size=5):
+ def stamp(self, widget, coords, last, stamp_size=20):
"""Paint with stamp.
@param self -- Desenho.Desenho instance
@param last -- last of oldx
@param widget -- Area object (GtkDrawingArea)
@param coords -- Two value tuple
- @param size -- integer (default 30)
+ @param size -- integer (default 20)
"""
widget.desenha = False
- self._trace(widget, widget.gc_brush, coords, last, size, stamping=True)
+ self._trace(widget, widget.gc_brush, coords, last, stamp_size, stamping=True)
def rainbow(self, widget, coords, last, color, size=5, shape='circle'):
"""Paint with rainbow.
diff --git a/toolbox.py b/toolbox.py
index 2c96c41..9ba90ce 100644
--- a/toolbox.py
+++ b/toolbox.py
@@ -137,6 +137,7 @@ class DrawToolbarBox(ToolbarBox):
brush_button = tools_builder._stroke_color.color_button
brush_button.set_brush_shape(self._activity.area.tool['line shape'])
brush_button.set_brush_size(self._activity.area.tool['line size'])
+ brush_button.set_stamp_size(self._activity.area.tool['stamp size'])
if self._activity.area.tool['stroke color'] is not None:
brush_button.set_color(self._activity.area.tool['stroke color'])
@@ -311,12 +312,11 @@ class ToolsToolbarBuilder():
"""
if tool_name == 'stamp':
pixbuf = self._activity.area.setupStamp()
- # Put stamp in ButtonStrokeColor widget:
- # TODO use signals?
+ # Put stamp in menu widget:
self._stroke_color.color_button._pixbuf_stamp = pixbuf
- self._stroke_color.color_button.set_stamping(True)
+ self._stroke_color.set_stamping(True)
else:
- self._stroke_color.color_button.set_stamping(False)
+ self._stroke_color.set_stamping(False)
self.properties['name'] = tool_name
self._activity.area.set_tool(self.properties)
diff --git a/widgets.py b/widgets.py
index 32734fa..f434ec7 100644
--- a/widgets.py
+++ b/widgets.py
@@ -28,6 +28,7 @@ class BrushButton(_ColorButton):
self._palette = None
self._accept_drag = True
self._brush_size = 2
+ self._stamp_size = 20
self._brush_shape = 'circle'
self._stamping = False
self._pixbuf_stamp = None
@@ -85,11 +86,24 @@ class BrushButton(_ColorButton):
self._color = color
self._preview.queue_draw()
+ def get_stamp_size(self):
+ return self._stamp_size
+
+ def set_stamp_size(self, stamp_size):
+ self._stamp_size = stamp_size
+ self._preview.queue_draw()
+
+ 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
self._preview.queue_draw()
+ def is_stamping(self):
+ return self._stamping
+
def expose(self, widget, event):
if self._gc is None:
self._setup()
@@ -101,10 +115,9 @@ class BrushButton(_ColorButton):
self._gc.set_foreground(self._color)
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)
+ 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()
@@ -165,6 +178,12 @@ 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()
@@ -178,6 +197,7 @@ class ButtonStrokeColor(gtk.ToolItem):
self.add(self.color_button)
self.color_button.set_brush_size(2)
self.color_button.set_brush_shape('circle')
+ self.color_button.set_stamp_size(20)
# The following is so that the behaviour on the toolbar is correct.
self.color_button.set_relief(gtk.RELIEF_NONE)
@@ -191,7 +211,9 @@ class ButtonStrokeColor(gtk.ToolItem):
self.color_button.connect('notify::title', self.__notify_change)
self.color_button.connect('can-activate-accel',
self.__button_can_activate_accel_cb)
-
+
+ self.create_palette()
+
def __button_can_activate_accel_cb(self, button, signal_id):
# Accept activation via accelerators regardless of this widget's state
return True
@@ -214,20 +236,20 @@ class ButtonStrokeColor(gtk.ToolItem):
color_palette_hbox = self._palette._picker_hbox
content_box = gtk.VBox()
- size_spinbutton = gtk.SpinButton()
+ self.size_spinbutton = gtk.SpinButton()
# This is where we set restrictions for size:
# Initial value, minimum value, maximum value, step
adj = gtk.Adjustment(self.properties['line size'], 1.0, 100.0, 1.0)
- size_spinbutton.set_adjustment(adj)
- size_spinbutton.set_numeric(True)
+ self.size_spinbutton.set_adjustment(adj)
+ self.size_spinbutton.set_numeric(True)
label = gtk.Label(_('Size: '))
hbox = gtk.HBox()
content_box.pack_start(hbox)
hbox.pack_start(label)
- hbox.pack_start(size_spinbutton)
- size_spinbutton.connect('value-changed', self._on_value_changed)
+ hbox.pack_start(self.size_spinbutton)
+ self.size_spinbutton.connect('value-changed', self._on_value_changed)
# User is able to choose Shapes for 'Brush' and 'Eraser'
item1 = gtk.RadioButton(None, _('Circle'))
@@ -273,18 +295,33 @@ class ButtonStrokeColor(gtk.ToolItem):
def _keep_aspect_checkbutton_toggled(self, checkbutton):
self._activity.area.keep_aspect_ratio = checkbutton.get_active()
-
+
+ def set_stamping(self, stamping):
+ self._stamping = stamping
+ self.color_button.set_stamping(stamping)
+ if stamping:
+ self.size_spinbutton.set_value(self.color_button.stamp_size)
+ else:
+ self.size_spinbutton.set_value(self.color_button.brush_size)
+
+ def is_stamping(self):
+ return self._stamping
+
def _on_value_changed(self, spinbutton):
size = spinbutton.get_value_as_int()
- self.properties['line size'] = size
+ if self.is_stamping():
+ self.properties['stamp size'] = size
+ self.color_button.set_stamp_size(self.properties['stamp size'])
+ else:
+ self.properties['line size'] = size
+ self.color_button.set_brush_size(self.properties['line size'])
self._activity.area.set_tool(self.properties)
- self.color_button.set_brush_size(self.properties['line size'])
def _on_toggled(self, radiobutton, tool, shape):
if radiobutton.get_active():
self.properties['line shape'] = shape
self.color_button.set_brush_shape(shape)
- self.color_button.set_brush_size(self.properties['line size'])
+ self.color_button.set_brush_size(self.properties['line size'])
def get_palette_invoker(self):
return self._palette_invoker