diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c index 88130c216c..9bb744e5eb 100644 --- a/app/tools/gimpcurvestool.c +++ b/app/tools/gimpcurvestool.c @@ -324,42 +324,48 @@ gimp_curves_tool_oper_update (GimpTool *tool, gboolean proximity, GimpDisplay *display) { - GimpColorPickMode mode; - gchar *status = NULL; - GdkModifierType extend_mask = gimp_get_extend_selection_mask (); - GdkModifierType toggle_mask = gimp_get_toggle_behavior_mask (); - - GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity, - display); - - gimp_tool_pop_status (tool, display); - - if (state & extend_mask) + if (gimp_image_map_tool_on_guide (GIMP_IMAGE_MAP_TOOL (tool), + coords, display)) { - mode = GIMP_COLOR_PICK_MODE_PALETTE; - status = g_strdup (_("Click to add a control point")); - } - else if (state & toggle_mask) - { - mode = GIMP_COLOR_PICK_MODE_PALETTE; - status = g_strdup (_("Click to add control points to all channels")); + GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity, + display); } else { - mode = GIMP_COLOR_PICK_MODE_NONE; - status = gimp_suggest_modifiers (_("Click to locate on curve"), - (extend_mask | toggle_mask) & ~state, - _("%s: add control point"), - _("%s: add control points to all channels"), - NULL); + GimpColorPickMode mode; + gchar *status = NULL; + GdkModifierType extend_mask = gimp_get_extend_selection_mask (); + GdkModifierType toggle_mask = gimp_get_toggle_behavior_mask (); + + gimp_tool_pop_status (tool, display); + + if (state & extend_mask) + { + mode = GIMP_COLOR_PICK_MODE_PALETTE; + status = g_strdup (_("Click to add a control point")); + } + else if (state & toggle_mask) + { + mode = GIMP_COLOR_PICK_MODE_PALETTE; + status = g_strdup (_("Click to add control points to all channels")); + } + else + { + mode = GIMP_COLOR_PICK_MODE_NONE; + status = gimp_suggest_modifiers (_("Click to locate on curve"), + (extend_mask | toggle_mask) & ~state, + _("%s: add control point"), + _("%s: add control points to all channels"), + NULL); + } + + GIMP_COLOR_TOOL (tool)->pick_mode = mode; + + if (proximity) + gimp_tool_push_status (tool, display, "%s", status); + + g_free (status); } - - GIMP_COLOR_TOOL (tool)->pick_mode = mode; - - if (proximity) - gimp_tool_push_status (tool, display, "%s", status); - - g_free (status); } static void diff --git a/app/tools/gimpimagemaptool.c b/app/tools/gimpimagemaptool.c index 961878ff2b..c77afdfab9 100644 --- a/app/tools/gimpimagemaptool.c +++ b/app/tools/gimpimagemaptool.c @@ -143,9 +143,6 @@ static void gimp_image_map_tool_config_notify (GObject *objec static void gimp_image_map_tool_add_guide (GimpImageMapTool *im_tool); static void gimp_image_map_tool_remove_guide (GimpImageMapTool *im_tool); static void gimp_image_map_tool_move_guide (GimpImageMapTool *im_tool); -static gboolean gimp_image_map_tool_on_guide (GimpImageMapTool *im_tool, - const GimpCoords *coords, - GimpDisplay *display); static void gimp_image_map_tool_guide_removed (GimpGuide *guide, GimpImageMapTool *im_tool); static void gimp_image_map_tool_guide_moved (GimpGuide *guide, @@ -521,74 +518,72 @@ gimp_image_map_tool_button_press (GimpTool *tool, GimpButtonPressType press_type, GimpDisplay *display) { - GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, - press_type, display); + GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool); - if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) + if (! gimp_image_map_tool_on_guide (im_tool, coords, display)) + { + GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, + press_type, display); + } + else { - GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool); GimpImageMapOptions *options = GIMP_IMAGE_MAP_TOOL_GET_OPTIONS (tool); - if (gimp_image_map_tool_on_guide (im_tool, coords, display)) + if (state & gimp_get_extend_selection_mask ()) { - gimp_tool_control_halt (tool->control); + GimpAlignmentType alignment; - if (state & gimp_get_extend_selection_mask ()) + /* switch side */ + switch (options->preview_alignment) { - GimpAlignmentType alignment; - - /* switch side */ - switch (options->preview_alignment) - { - case GIMP_ALIGN_LEFT: alignment = GIMP_ALIGN_RIGHT; break; - case GIMP_ALIGN_RIGHT: alignment = GIMP_ALIGN_LEFT; break; - case GIMP_ALIGN_TOP: alignment = GIMP_ALIGN_BOTTOM; break; - case GIMP_ALIGN_BOTTOM: alignment = GIMP_ALIGN_TOP; break; - default: - g_return_if_reached (); - } - - g_object_set (options, "preview-alignment", alignment, NULL); + case GIMP_ALIGN_LEFT: alignment = GIMP_ALIGN_RIGHT; break; + case GIMP_ALIGN_RIGHT: alignment = GIMP_ALIGN_LEFT; break; + case GIMP_ALIGN_TOP: alignment = GIMP_ALIGN_BOTTOM; break; + case GIMP_ALIGN_BOTTOM: alignment = GIMP_ALIGN_TOP; break; + default: + g_return_if_reached (); } - else if (state & gimp_get_toggle_behavior_mask ()) + + g_object_set (options, "preview-alignment", alignment, NULL); + } + else if (state & gimp_get_toggle_behavior_mask ()) + { + GimpItem *item = GIMP_ITEM (im_tool->drawable); + GimpAlignmentType alignment; + gdouble position; + + /* switch orientation */ + switch (options->preview_alignment) { - GimpItem *item = GIMP_ITEM (im_tool->drawable); - GimpAlignmentType alignment; - gdouble position; + case GIMP_ALIGN_LEFT: alignment = GIMP_ALIGN_TOP; break; + case GIMP_ALIGN_RIGHT: alignment = GIMP_ALIGN_BOTTOM; break; + case GIMP_ALIGN_TOP: alignment = GIMP_ALIGN_LEFT; break; + case GIMP_ALIGN_BOTTOM: alignment = GIMP_ALIGN_RIGHT; break; + default: + g_return_if_reached (); + } - /* switch orientation */ - switch (options->preview_alignment) - { - case GIMP_ALIGN_LEFT: alignment = GIMP_ALIGN_TOP; break; - case GIMP_ALIGN_RIGHT: alignment = GIMP_ALIGN_BOTTOM; break; - case GIMP_ALIGN_TOP: alignment = GIMP_ALIGN_LEFT; break; - case GIMP_ALIGN_BOTTOM: alignment = GIMP_ALIGN_RIGHT; break; - default: - g_return_if_reached (); - } - - if (alignment == GIMP_ALIGN_LEFT || - alignment == GIMP_ALIGN_RIGHT) - { - position = ((coords->x - gimp_item_get_offset_x (item)) / - gimp_item_get_width (item)); - } - else - { - position = ((coords->y - gimp_item_get_offset_y (item)) / - gimp_item_get_height (item)); - } - - g_object_set (options, - "preview-alignment", alignment, - "preview-position", CLAMP (position, 0.0, 1.0), - NULL); + if (alignment == GIMP_ALIGN_LEFT || + alignment == GIMP_ALIGN_RIGHT) + { + position = ((coords->x - gimp_item_get_offset_x (item)) / + gimp_item_get_width (item)); } else { - gimp_guide_tool_start_edit (tool, display, - im_tool->percent_guide); + position = ((coords->y - gimp_item_get_offset_y (item)) / + gimp_item_get_height (item)); } + + g_object_set (options, + "preview-alignment", alignment, + "preview-position", CLAMP (position, 0.0, 1.0), + NULL); + } + else + { + gimp_guide_tool_start_edit (tool, display, + im_tool->percent_guide); } } } @@ -636,43 +631,42 @@ gimp_image_map_tool_oper_update (GimpTool *tool, gboolean proximity, GimpDisplay *display) { - GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, - display); + GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool); - if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) + gimp_tool_pop_status (tool, display); + + if (! gimp_image_map_tool_on_guide (im_tool, coords, display)) { - GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool); + GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, + proximity, display); + } + else + { + GdkModifierType extend_mask = gimp_get_extend_selection_mask (); + GdkModifierType toggle_mask = gimp_get_toggle_behavior_mask (); + gchar *status = NULL; - gimp_tool_pop_status (tool, display); - - if (gimp_image_map_tool_on_guide (im_tool, coords, display)) + if (state & extend_mask) { - GdkModifierType extend_mask = gimp_get_extend_selection_mask (); - GdkModifierType toggle_mask = gimp_get_toggle_behavior_mask (); - gchar *status = NULL; - - if (state & extend_mask) - { - status = g_strdup (_("Click to switch the original and filtered sides")); - } - else if (state & toggle_mask) - { - status = g_strdup (_("Click to switch between vertical and horizontal")); - } - else - { - status = gimp_suggest_modifiers (_("Click to move the split guide"), - (extend_mask | toggle_mask) & ~state, - _("%s: switch original and filtered"), - _("%s: switch horizontal and vertical"), - NULL); - } - - if (proximity) - gimp_tool_push_status (tool, display, "%s", status); - - g_free (status); + status = g_strdup (_("Click to switch the original and filtered sides")); } + else if (state & toggle_mask) + { + status = g_strdup (_("Click to switch between vertical and horizontal")); + } + else + { + status = gimp_suggest_modifiers (_("Click to move the split guide"), + (extend_mask | toggle_mask) & ~state, + _("%s: switch original and filtered"), + _("%s: switch horizontal and vertical"), + NULL); + } + + if (proximity) + gimp_tool_push_status (tool, display, "%s", status); + + g_free (status); } } @@ -682,20 +676,19 @@ gimp_image_map_tool_cursor_update (GimpTool *tool, GdkModifierType state, GimpDisplay *display) { - GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, - display); + GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool); - if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) + if (! gimp_image_map_tool_on_guide (im_tool, coords, display)) { - GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool); - - if (gimp_image_map_tool_on_guide (im_tool, coords, display)) - { - gimp_tool_set_cursor (tool, display, - GIMP_CURSOR_MOUSE, - GIMP_TOOL_CURSOR_HAND, - GIMP_CURSOR_MODIFIER_MOVE); - } + GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, + display); + } + else + { + gimp_tool_set_cursor (tool, display, + GIMP_CURSOR_MOUSE, + GIMP_TOOL_CURSOR_HAND, + GIMP_CURSOR_MODIFIER_MOVE); } } @@ -1127,39 +1120,6 @@ gimp_image_map_tool_move_guide (GimpImageMapTool *im_tool) } } -static gboolean -gimp_image_map_tool_on_guide (GimpImageMapTool *im_tool, - const GimpCoords *coords, - GimpDisplay *display) -{ - GimpDisplayShell *shell = gimp_display_get_shell (display); - - if (im_tool->image_map && - im_tool->percent_guide && - gimp_display_shell_get_show_guides (shell)) - { - const gint snap_distance = display->config->snap_distance; - GimpOrientationType orientation; - gint position; - - orientation = gimp_guide_get_orientation (im_tool->percent_guide); - position = gimp_guide_get_position (im_tool->percent_guide); - - if (orientation == GIMP_ORIENTATION_HORIZONTAL) - { - if (fabs (coords->y - position) <= FUNSCALEY (shell, snap_distance)) - return TRUE; - } - else - { - if (fabs (coords->x - position) <= FUNSCALEX (shell, snap_distance)) - return TRUE; - } - } - - return FALSE; -} - static void gimp_image_map_tool_guide_removed (GimpGuide *guide, GimpImageMapTool *im_tool) @@ -1233,6 +1193,9 @@ gimp_image_map_tool_response (GimpToolGui *gui, } } + +/* public functions */ + void gimp_image_map_tool_get_operation (GimpImageMapTool *im_tool) { @@ -1434,6 +1397,45 @@ gimp_image_map_tool_edit_as (GimpImageMapTool *im_tool, gimp_image_map_tool_reset (GIMP_IMAGE_MAP_TOOL (new_tool)); } +gboolean +gimp_image_map_tool_on_guide (GimpImageMapTool *im_tool, + const GimpCoords *coords, + GimpDisplay *display) +{ + GimpDisplayShell *shell; + + g_return_val_if_fail (GIMP_IS_IMAGE_MAP_TOOL (im_tool), FALSE); + g_return_val_if_fail (coords != NULL, FALSE); + g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE); + + shell = gimp_display_get_shell (display); + + if (im_tool->image_map && + im_tool->percent_guide && + gimp_display_shell_get_show_guides (shell)) + { + const gint snap_distance = display->config->snap_distance; + GimpOrientationType orientation; + gint position; + + orientation = gimp_guide_get_orientation (im_tool->percent_guide); + position = gimp_guide_get_position (im_tool->percent_guide); + + if (orientation == GIMP_ORIENTATION_HORIZONTAL) + { + if (fabs (coords->y - position) <= FUNSCALEY (shell, snap_distance)) + return TRUE; + } + else + { + if (fabs (coords->x - position) <= FUNSCALEX (shell, snap_distance)) + return TRUE; + } + } + + return FALSE; +} + GtkWidget * gimp_image_map_tool_dialog_get_vbox (GimpImageMapTool *im_tool) { diff --git a/app/tools/gimpimagemaptool.h b/app/tools/gimpimagemaptool.h index a103c52ed4..969e8edd63 100644 --- a/app/tools/gimpimagemaptool.h +++ b/app/tools/gimpimagemaptool.h @@ -107,15 +107,17 @@ struct _GimpImageMapToolClass GType gimp_image_map_tool_get_type (void) G_GNUC_CONST; -void gimp_image_map_tool_preview (GimpImageMapTool *im_tool); - void gimp_image_map_tool_get_operation (GimpImageMapTool *im_tool); +void gimp_image_map_tool_preview (GimpImageMapTool *im_tool); void gimp_image_map_tool_edit_as (GimpImageMapTool *im_tool, const gchar *new_tool_id, GimpConfig *config); -/* accessors for derived classes */ +gboolean gimp_image_map_tool_on_guide (GimpImageMapTool *im_tool, + const GimpCoords *coords, + GimpDisplay *display); + GtkWidget * gimp_image_map_tool_dialog_get_vbox (GimpImageMapTool *im_tool); GtkWidget * gimp_image_map_tool_add_color_picker (GimpImageMapTool *im_tool,