Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-09-03 15:24:33 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-09-04 17:58:47 (GMT)
commit948a681ff8a21a6ab8977bd1a2983b42b13e487c (patch)
treea1b6db6d83abd3dd52d3dc7ee24f666ee49a5965
parent8ee2e7dce0e86d1767f02de605289bc1be574214 (diff)
Do te resize visualy in the canvas
Remove the spinbuttons in the image toolbar, and handle the visual representation in the canvas Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r--Area.py43
-rw-r--r--Desenho.py40
-rw-r--r--toolbox.py90
3 files changed, 59 insertions, 114 deletions
diff --git a/Area.py b/Area.py
index f4c2788..5055c12 100644
--- a/Area.py
+++ b/Area.py
@@ -95,6 +95,7 @@ TARGET_URI = 0
MAX_UNDO_STEPS = 12
RESIZE_ARROW_SIZE = style.GRID_CELL_SIZE / 2
+
class Area(Gtk.DrawingArea):
__gsignals__ = {
@@ -165,6 +166,7 @@ class Area(Gtk.DrawingArea):
self.desenha = False
self._selmove = False
+ self._selresize = False
self.oldx = 0
self.oldy = 0
self.drawing_canvas = None
@@ -288,7 +290,6 @@ class Area(Gtk.DrawingArea):
ctx.restore()
-
def configure_line(self, size):
"""Configure the new line's size.
@@ -396,7 +397,9 @@ class Area(Gtk.DrawingArea):
self.text_in_progress = False
self.activity.textview.hide()
- self.oldx, self.oldy = coords
+ if not self._selresize:
+ # if resizing don't update to remember previous resize
+ self.oldx, self.oldy = coords
# TODO: get_pointer is deprecated
# http://developer.gnome.org/gtk3/3.4/GtkWidget.html#gtk-widget-get-pointer
@@ -433,19 +436,30 @@ class Area(Gtk.DrawingArea):
self.tool['fill'], "motion")
if self.tool['name'] == 'marquee-rectangular':
if self.is_selected():
- xi, yi, width, height = self.get_selection_bounds()
- xf = xi + width
- yf = yi + height
# verify is out of the selected area
- if (coords[0] < xi) or (coords[0] > xf) or \
- (coords[1] < yi) or (coords[1] > yf):
+ sel_x, sel_y, sel_width, sel_height = \
+ self.get_selection_bounds()
+ if self.check_point_in_area(coords[0], coords[1],
+ sel_x, sel_y, sel_width, sel_height):
+ # be sure to have the last coords
+ # because can be older if was resized before
+ self.oldx, self.oldy = coords
+ # inside the selected area
+ self.d.move_selection(widget, coords)
+ self._selmove = True
+ self._selresize = False
+ elif self.check_point_in_area(coords[0], coords[1],
+ sel_x + sel_width, sel_y + sel_height,
+ RESIZE_ARROW_SIZE, RESIZE_ARROW_SIZE):
+ # in de resize area
+ self._selmove = False
+ self._selresize = True
+ else:
self.getout()
self._selmove = False
+ self._selresize = False
design_mode = False
- else:
- # if is inside the selected area move the selection
- self.d.move_selection(widget, coords)
- self._selmove = True
+
else:
self._selmove = False
@@ -537,6 +551,8 @@ class Area(Gtk.DrawingArea):
if self._selmove:
# is inside a selected area, move it
self.d.move_selection(widget, coords)
+ elif self._selresize:
+ self.d.resize_selection(widget, coords)
else:
# create a selected area
if (state & Gdk.ModifierType.CONTROL_MASK) or \
@@ -596,7 +612,6 @@ class Area(Gtk.DrawingArea):
cursor = Gdk.Cursor.new(Gdk.CursorType.CROSS)
self.get_window().set_cursor(cursor)
-
elif self.tool['name'] == 'freeform':
self.desenha = True
self.configure_line(self.tool['line size'])
@@ -610,7 +625,6 @@ class Area(Gtk.DrawingArea):
return not ((x_point < x_min) or (x_point > x_min + width) or \
(y_point < y_min) or (y_point > y_min + height))
-
def mouseup(self, widget, event):
"""Make the Area object (GtkDrawingArea)
recognize that the mouse was released.
@@ -643,7 +657,8 @@ class Area(Gtk.DrawingArea):
elif self.tool['name'] == 'marquee-rectangular':
private_undo = True
- if self.is_selected() and not self._selmove:
+ if self.is_selected() and not self._selmove and \
+ not self._selresize:
self.create_selection_surface()
self.emit('select')
else:
diff --git a/Desenho.py b/Desenho.py
index 35367c0..780fe07 100644
--- a/Desenho.py
+++ b/Desenho.py
@@ -676,26 +676,46 @@ class Desenho:
widget.queue_draw()
- def resizeSelection(self, widget, width_percent, height_percent):
- """Resize the selection.
+ def resize_selection(self, widget, coords):
+ """Move the selection.
@param self -- Desenho.Desenho instance
- @param width_percent -- Percent of x scale
- @param height_percent -- Percent of y scale
+ @param widget -- Area object (GtkDrawingArea)
+ @param coords -- Two value tuple
+ @param mvcopy -- Copy or Move
+ @param pixbuf_copy -- For import image
"""
+ widget.desenha = True
+
+ dx = int(coords[0] - widget.oldx)
+ dy = int(coords[1] - widget.oldy)
+
+ sel_width = widget.selection_surface.get_width()
+ sel_height = widget.selection_surface.get_height()
+
+ if widget.pending_clean_selection_background:
+ # clear the selection background
+ widget.clear_selection_background()
+ widget.pending_clean_selection_background = False
+
+ width_scale = float(sel_width + dx) / float(sel_width)
+ height_scale = float(sel_height + dy) / float(sel_height)
+
+ if width_scale < 0 or height_scale < 0:
+ return
+
# Add a timer for resize or update it if there is one already:
if self._resize_timer is not None:
GObject.source_remove(self._resize_timer)
self._resize_timer = GObject.timeout_add(RESIZE_DELAY,
- self._do_resize, widget, width_percent, height_percent)
+ self._do_resize, widget, width_scale, height_scale)
- def _do_resize(self, widget, width_percent, height_percent):
- """Do the resize calculation.
- """
+ def _do_resize(self, widget, width_scale, height_scale):
+# """Do the resize calculation.
+# """
widget.desenha = True
- widget.resize_selection_surface(float(width_percent),
- float(height_percent))
+ widget.resize_selection_surface(width_scale, height_scale)
widget.queue_draw()
def freeform(self, widget, coords, temp, fill, param=None):
diff --git a/toolbox.py b/toolbox.py
index db373f7..900a6cc 100644
--- a/toolbox.py
+++ b/toolbox.py
@@ -687,28 +687,6 @@ class ImageToolbar(Gtk.Toolbar):
self._mirror_vertical.show()
self._mirror_vertical.set_tooltip(_('Vertical Mirror'))
- self._object_height = ToolButton('object-height')
- self.insert(self._object_height, -1)
- self._object_height.set_tooltip(_('Height'))
-
- self.height_spinButton = self._create_spinButton(self._object_height,
- 'object-height', activity)
-
- item = Gtk.ToolItem()
- item.add(self.height_spinButton)
- self.insert(item, -1)
-
- self._object_width = ToolButton('object-width')
- self.insert(self._object_width, -1)
- self._object_width.set_tooltip(_('Width'))
-
- self.width_spinButton = self._create_spinButton(self._object_width,
- 'object-width', activity)
-
- item = Gtk.ToolItem()
- item.add(self.width_spinButton)
- self.insert(item, -1)
-
separator = Gtk.SeparatorToolItem()
separator.set_draw(True)
self.insert(separator, -1)
@@ -733,12 +711,6 @@ class ImageToolbar(Gtk.Toolbar):
self._mirror_vertical.connect('clicked', self.mirror_vertical)
self._mirror_horizontal.connect('clicked', self.mirror_horizontal)
- self._activity.area.connect('undo', self._on_signal_undo_cb)
- self._activity.area.connect('redo', self._on_signal_redo_cb)
- self._activity.area.connect('select', self._on_signal_select_cb)
- self._activity.area.connect('action-saved',
- self._on_signal_action_saved_cb)
-
self._effect_grayscale.connect('clicked', self.grayscale)
self._effect_rainbow.connect('clicked', self.rainbow)
self._invert_colors.connect('clicked', self.invert_colors)
@@ -757,45 +729,6 @@ class ImageToolbar(Gtk.Toolbar):
def mirror_vertical(self, widget):
self._activity.area.mirror(widget, horizontal=False)
- def resize(self, spinButton, tool, activity):
- if activity.area.tool['name'] == 'marquee-rectangular' and \
- activity.area.is_selected():
- if tool == "object-height":
- self.height_percent = spinButton.get_value_as_int() / 100.
- activity.area.d.resizeSelection(activity.area,
- self.width_percent, self.height_percent)
- elif tool == "object-width":
- self.width_percent = spinButton.get_value_as_int() / 100.
- activity.area.d.resizeSelection(activity.area,
- self.width_percent, self.height_percent)
-
- def _create_spinButton(self, widget, tool, activity):
- """Set palette for a tool - width or height
-
- @param self -- Gtk.Toolbar
- @param widget - the widget which Palette will be set,
- a ToolButton object
- @param tool
- @param activity
- """
- logging.debug('setting a spinButton for %s', tool)
-
- spin = Gtk.SpinButton()
- spin.show()
-
- # This is where we set restrictions for Resizing:
- # Initial value, minimum value, maximum value, step
- initial = float(100)
- adj = Gtk.Adjustment(initial, 10.0, 500.0, 1.0)
- spin.set_adjustment(adj)
- spin.set_numeric(True)
-
- spin.set_sensitive(self._activity.area.is_selected())
-
- spin.connect('value-changed', self.resize, tool, activity)
-
- return spin
-
def insertImage(self, widget, activity):
chooser = ObjectChooser(self._activity, what_filter='Image')
try:
@@ -810,29 +743,6 @@ class ImageToolbar(Gtk.Toolbar):
chooser.destroy()
del chooser
- def _on_signal_undo_cb(self, widget, data=None):
- self._verify_sensitive_buttons()
-
- def _on_signal_redo_cb(self, widget, data=None):
- self._verify_sensitive_buttons()
-
- def _on_signal_select_cb(self, widget, data=None):
- self._verify_sensitive_buttons()
-
- def _on_signal_action_saved_cb(self, widget, data=None):
- self._verify_sensitive_buttons()
-
- def _verify_sensitive_buttons(self):
- is_selected = self._activity.area.is_selected()
- self.width_spinButton.set_sensitive(is_selected)
- self.height_spinButton.set_sensitive(is_selected)
-
- if not is_selected:
- self.width_spinButton.set_value(100)
- self.height_spinButton.set_value(100)
- self.width_percent = 1.
- self.height_percent = 1.
-
##Make the colors be in grayscale
def grayscale(self, widget):
self._activity.area.grayscale(widget)