[gimp] app: make gimp_selection_tool_start_edit() much easier to use correctly
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: make gimp_selection_tool_start_edit() much easier to use correctly
- Date: Fri, 3 Jun 2011 08:42:55 +0000 (UTC)
commit d27b7a985c3a09bedf6a87394406829d75546773
Author: Michael Natterer <mitch gimp org>
Date: Fri Jun 3 09:46:10 2011 +0200
app: make gimp_selection_tool_start_edit() much easier to use correctly
- Add a "display" parameter and ignore tool->display
- Require the tool to be inactive, not active when calling it
This exactly matches all its use cases, which is "delegate to
GimpEditSelection tool if we are not doing anything ourselves", and
enables removing all delegate_button_press() functions because they
became one-liners after adapting to this change.
app/tools/gimpfreeselecttool.c | 92 ++++++++--------------------------
app/tools/gimprectangleselecttool.c | 26 +---------
app/tools/gimpregionselecttool.c | 9 ++-
app/tools/gimpselectiontool.c | 12 +++--
app/tools/gimpselectiontool.h | 1 +
5 files changed, 38 insertions(+), 102 deletions(-)
---
diff --git a/app/tools/gimpfreeselecttool.c b/app/tools/gimpfreeselecttool.c
index e54d334..c151b52 100644
--- a/app/tools/gimpfreeselecttool.c
+++ b/app/tools/gimpfreeselecttool.c
@@ -516,32 +516,6 @@ gimp_free_select_tool_is_point_grabbed (GimpFreeSelectTool *fst)
}
static void
-gimp_free_select_tool_start (GimpFreeSelectTool *fst,
- const GimpCoords *coords,
- GimpDisplay *display)
-{
- GimpTool *tool = GIMP_TOOL (fst);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
- GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (fst);
- GimpFreeSelectToolPrivate *priv = GET_PRIVATE (fst);
-
- gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
-
- gimp_tool_control_activate (tool->control);
-
- tool->display = display;
-
- gimp_draw_tool_start (draw_tool, display);
-
- /* We want to apply the selection operation that was current when
- * the tool was started, so we save this information */
- priv->operation_at_start = options->operation;
-
- gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (fst),
- coords);
-}
-
-static void
gimp_free_select_tool_fit_segment (GimpFreeSelectTool *fst,
GimpVector2 *dest_points,
GimpVector2 dest_start_target,
@@ -963,36 +937,6 @@ gimp_free_select_tool_prepare_for_move (GimpFreeSelectTool *fst)
}
}
-static gboolean
-gimp_free_select_tool_delegate_button_press (GimpFreeSelectTool *fst,
- const GimpCoords *coords,
- GimpDisplay *display)
-{
- GimpTool *tool = GIMP_TOOL (fst);
- gboolean button_press_delegated = FALSE;
-
- /* Only consider delegating if the tool is not active */
- if (tool->display == NULL)
- {
- tool->display = display;
- gimp_tool_control_activate (tool->control);
-
- button_press_delegated =
- gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (fst), coords);
-
- if (! button_press_delegated)
- {
- /* Nope, the selection mask edit stuff was not interested, reset
- * the situation
- */
- gimp_tool_control_halt (tool->control);
- tool->display = NULL;
- }
- }
-
- return button_press_delegated;
-}
-
static void
gimp_free_select_tool_update_motion (GimpFreeSelectTool *fst,
gdouble new_x,
@@ -1259,28 +1203,36 @@ gimp_free_select_tool_button_press (GimpTool *tool,
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
GimpFreeSelectTool *fst = GIMP_FREE_SELECT_TOOL (tool);
GimpFreeSelectToolPrivate *priv = GET_PRIVATE (fst);
+ GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (tool);
- /* First of all handle delegation to the selection mask edit logic
- * if appropriate
- */
- if (gimp_free_select_tool_delegate_button_press (fst,
- coords,
- display))
+ if (tool->display && tool->display != display)
+ gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
+
+ if (tool->display == NULL)
{
- return;
+ /* First of all handle delegation to the selection mask edit logic
+ * if appropriate.
+ */
+ if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (fst),
+ display, coords))
+ {
+ return;
+ }
+
+ tool->display = display;
+
+ gimp_draw_tool_start (draw_tool, display);
+
+ /* We want to apply the selection operation that was current when
+ * the tool was started, so we save this information
+ */
+ priv->operation_at_start = options->operation;
}
gimp_tool_control_activate (tool->control);
gimp_draw_tool_pause (draw_tool);
- if (display != tool->display)
- {
- gimp_free_select_tool_start (fst,
- coords,
- display);
- }
-
if (gimp_free_select_tool_is_point_grabbed (fst))
{
gimp_free_select_tool_prepare_for_move (fst);
diff --git a/app/tools/gimprectangleselecttool.c b/app/tools/gimprectangleselecttool.c
index 4d7c087..2d2ad11 100644
--- a/app/tools/gimprectangleselecttool.c
+++ b/app/tools/gimprectangleselecttool.c
@@ -343,27 +343,6 @@ gimp_rectangle_select_tool_draw (GimpDrawTool *draw_tool)
gimp_rectangle_tool_draw (draw_tool, stroke_group);
}
-static gboolean
-gimp_rectangle_select_tool_delegate_button_press (GimpRectangleSelectTool *rect_sel_tool,
- const GimpCoords *coords,
- GimpDisplay *display)
-{
- GimpTool *tool = GIMP_TOOL (rect_sel_tool);
- gboolean button_press_delegated = FALSE;
- GimpDisplay *old_display = tool->display;
-
- tool->display = display;
- gimp_tool_control_activate (tool->control);
-
- button_press_delegated =
- gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (tool), coords);
-
- gimp_tool_control_halt (tool->control);
- tool->display = old_display;
-
- return button_press_delegated;
-}
-
static void
gimp_rectangle_select_tool_button_press (GimpTool *tool,
const GimpCoords *coords,
@@ -388,9 +367,8 @@ gimp_rectangle_select_tool_button_press (GimpTool *tool,
gimp_rectangle_tool_cancel (GIMP_RECTANGLE_TOOL (tool));
}
- if (gimp_rectangle_select_tool_delegate_button_press (rect_sel_tool,
- coords,
- display))
+ if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (tool),
+ display, coords))
{
/* In some cases we want to finish the rectangle select tool
* and hand over responsability to the selection tool
diff --git a/app/tools/gimpregionselecttool.c b/app/tools/gimpregionselecttool.c
index 418a4e7..12af209 100644
--- a/app/tools/gimpregionselecttool.c
+++ b/app/tools/gimpregionselecttool.c
@@ -152,12 +152,15 @@ gimp_region_select_tool_button_press (GimpTool *tool,
region_sel->y = coords->y;
region_sel->saved_threshold = options->threshold;
+ if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (region_sel),
+ display, coords))
+ {
+ return;
+ }
+
gimp_tool_control_activate (tool->control);
tool->display = display;
- if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (region_sel), coords))
- return;
-
gimp_tool_push_status (tool, display,
_("Move the mouse to change threshold"));
diff --git a/app/tools/gimpselectiontool.c b/app/tools/gimpselectiontool.c
index e9b4696..0f5fbf4 100644
--- a/app/tools/gimpselectiontool.c
+++ b/app/tools/gimpselectiontool.c
@@ -391,32 +391,34 @@ gimp_selection_tool_cursor_update (GimpTool *tool,
gboolean
gimp_selection_tool_start_edit (GimpSelectionTool *sel_tool,
+ GimpDisplay *display,
const GimpCoords *coords)
{
GimpTool *tool;
g_return_val_if_fail (GIMP_IS_SELECTION_TOOL (sel_tool), FALSE);
+ g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
g_return_val_if_fail (coords != NULL, FALSE);
tool = GIMP_TOOL (sel_tool);
- g_return_val_if_fail (GIMP_IS_DISPLAY (tool->display), FALSE);
- g_return_val_if_fail (gimp_tool_control_is_active (tool->control), FALSE);
+ g_return_val_if_fail (gimp_tool_control_is_active (tool->control) == FALSE,
+ FALSE);
switch (sel_tool->function)
{
case SELECTION_MOVE_MASK:
- gimp_edit_selection_tool_start (tool, tool->display, coords,
+ gimp_edit_selection_tool_start (tool, display, coords,
GIMP_TRANSLATE_MODE_MASK, FALSE);
return TRUE;
case SELECTION_MOVE:
- gimp_edit_selection_tool_start (tool, tool->display, coords,
+ gimp_edit_selection_tool_start (tool, display, coords,
GIMP_TRANSLATE_MODE_MASK_TO_LAYER, FALSE);
return TRUE;
case SELECTION_MOVE_COPY:
- gimp_edit_selection_tool_start (tool, tool->display, coords,
+ gimp_edit_selection_tool_start (tool, display, coords,
GIMP_TRANSLATE_MODE_MASK_COPY_TO_LAYER,
FALSE);
return TRUE;
diff --git a/app/tools/gimpselectiontool.h b/app/tools/gimpselectiontool.h
index bbb5a45..c6eee63 100644
--- a/app/tools/gimpselectiontool.h
+++ b/app/tools/gimpselectiontool.h
@@ -55,6 +55,7 @@ GType gimp_selection_tool_get_type (void) G_GNUC_CONST;
/* protected function */
gboolean gimp_selection_tool_start_edit (GimpSelectionTool *sel_tool,
+ GimpDisplay *display,
const GimpCoords *coords);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]