Commit a5b03ddf authored by Ell's avatar Ell

app: add gimp_filter_tool_{enable,disable}_color_picking()

Subclasses of GimpFilterTool should use these functions to control
picking, instead of using gimp_color_tool_{enable,disable}()
directly.  This makes sure that the tool's picking state is
consistent, and allows the caller to control the pick identifier,
and use abyss picking (not currently needed by any subclass, but
maybe in the future, who knows.)
parent 2e6b3853
......@@ -343,9 +343,7 @@ gimp_filter_tool_initialize (GimpTool *tool,
return FALSE;
}
if (filter_tool->active_picker)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (filter_tool->active_picker),
FALSE);
gimp_filter_tool_disable_color_picking (filter_tool);
/* set display so the dialog can be hidden on display destruction */
tool->display = display;
......@@ -802,16 +800,11 @@ gimp_filter_tool_can_pick_color (GimpColorTool *color_tool,
{
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (color_tool);
GimpImage *image = gimp_display_get_image (display);
gboolean pick_abyss;
if (gimp_image_get_active_drawable (image) != filter_tool->drawable)
return FALSE;
pick_abyss =
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (filter_tool->active_picker),
"picker-pick-abyss"));
return pick_abyss ||
return filter_tool->pick_abyss ||
GIMP_COLOR_TOOL_CLASS (parent_class)->can_pick (color_tool,
coords, display);
}
......@@ -825,14 +818,9 @@ gimp_filter_tool_pick_color (GimpColorTool *color_tool,
GimpRGB *color)
{
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (color_tool);
gboolean pick_abyss;
gint off_x, off_y;
gboolean picked;
pick_abyss =
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (filter_tool->active_picker),
"picker-pick-abyss"));
gimp_item_get_offset (GIMP_ITEM (filter_tool->drawable), &off_x, &off_y);
*sample_format = gimp_drawable_get_format (filter_tool->drawable);
......@@ -844,7 +832,7 @@ gimp_filter_tool_pick_color (GimpColorTool *color_tool,
color_tool->options->average_radius,
pixel, color);
if (! picked && pick_abyss)
if (! picked && filter_tool->pick_abyss)
{
color->r = 0.0;
color->g = 0.0;
......@@ -867,18 +855,12 @@ gimp_filter_tool_color_picked (GimpColorTool *color_tool,
const GimpRGB *color)
{
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (color_tool);
gpointer identifier;
g_return_if_fail (GTK_IS_WIDGET (filter_tool->active_picker));
identifier = g_object_get_data (G_OBJECT (filter_tool->active_picker),
"picker-identifier");
GIMP_FILTER_TOOL_GET_CLASS (filter_tool)->color_picked (filter_tool,
identifier,
x, y,
sample_format,
color);
GIMP_FILTER_TOOL_GET_CLASS (filter_tool)->color_picked (
filter_tool,
filter_tool->pick_identifier,
x, y,
sample_format, color);
}
static void
......@@ -989,9 +971,7 @@ static void
gimp_filter_tool_dialog_unmap (GtkWidget *dialog,
GimpFilterTool *filter_tool)
{
if (filter_tool->active_picker)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (filter_tool->active_picker),
FALSE);
gimp_filter_tool_disable_color_picking (filter_tool);
}
static void
......@@ -1570,28 +1550,68 @@ gimp_filter_tool_dialog_get_vbox (GimpFilterTool *filter_tool)
return gimp_tool_gui_get_vbox (filter_tool->gui);
}
void
gimp_filter_tool_enable_color_picking (GimpFilterTool *filter_tool,
gpointer identifier,
gboolean pick_abyss)
{
g_return_if_fail (GIMP_IS_FILTER_TOOL (filter_tool));
gimp_filter_tool_disable_color_picking (filter_tool);
/* note that ownership over `identifier` is not transferred, and its lifetime
* should be managed by the caller.
*/
filter_tool->pick_identifier = identifier;
filter_tool->pick_abyss = pick_abyss;
gimp_color_tool_enable (GIMP_COLOR_TOOL (filter_tool),
GIMP_COLOR_TOOL_GET_OPTIONS (filter_tool));
}
void
gimp_filter_tool_disable_color_picking (GimpFilterTool *filter_tool)
{
g_return_if_fail (GIMP_IS_FILTER_TOOL (filter_tool));
if (filter_tool->active_picker)
{
GtkToggleButton *toggle = GTK_TOGGLE_BUTTON (filter_tool->active_picker);
filter_tool->active_picker = NULL;
gtk_toggle_button_set_active (toggle, FALSE);
}
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (filter_tool)))
gimp_color_tool_disable (GIMP_COLOR_TOOL (filter_tool));
}
static void
gimp_filter_tool_color_picker_toggled (GtkWidget *widget,
GimpFilterTool *filter_tool)
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
{
gpointer identifier;
gboolean pick_abyss;
if (filter_tool->active_picker == widget)
return;
if (filter_tool->active_picker)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (filter_tool->active_picker),
FALSE);
identifier = g_object_get_data (G_OBJECT (widget),
"picker-identifier");
pick_abyss = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
"picker-pick-abyss"));
filter_tool->active_picker = widget;
gimp_filter_tool_enable_color_picking (filter_tool,
identifier, pick_abyss);
gimp_color_tool_enable (GIMP_COLOR_TOOL (filter_tool),
GIMP_COLOR_TOOL_GET_OPTIONS (filter_tool));
filter_tool->active_picker = widget;
}
else if (filter_tool->active_picker == widget)
{
filter_tool->active_picker = NULL;
gimp_color_tool_disable (GIMP_COLOR_TOOL (filter_tool));
gimp_filter_tool_disable_color_picking (filter_tool);
}
}
......
......@@ -60,6 +60,9 @@ struct _GimpFilterTool
GimpGuide *preview_guide;
gpointer pick_identifier;
gboolean pick_abyss;
/* dialog */
gboolean overlay;
GimpToolGui *gui;
......@@ -104,31 +107,35 @@ struct _GimpFilterToolClass
};
GType gimp_filter_tool_get_type (void) G_GNUC_CONST;
GType gimp_filter_tool_get_type (void) G_GNUC_CONST;
void gimp_filter_tool_get_operation (GimpFilterTool *filter_tool);
void gimp_filter_tool_get_operation (GimpFilterTool *filter_tool);
void gimp_filter_tool_set_has_settings (GimpFilterTool *filter_tool,
gboolean has_settings);
void gimp_filter_tool_set_has_settings (GimpFilterTool *filter_tool,
gboolean has_settings);
void gimp_filter_tool_set_config (GimpFilterTool *filter_tool,
GimpConfig *config);
void gimp_filter_tool_set_config (GimpFilterTool *filter_tool,
GimpConfig *config);
void gimp_filter_tool_edit_as (GimpFilterTool *filter_tool,
const gchar *new_tool_id,
GimpConfig *config);
void gimp_filter_tool_edit_as (GimpFilterTool *filter_tool,
const gchar *new_tool_id,
GimpConfig *config);
gboolean gimp_filter_tool_on_guide (GimpFilterTool *filter_tool,
const GimpCoords *coords,
GimpDisplay *display);
gboolean gimp_filter_tool_on_guide (GimpFilterTool *filter_tool,
const GimpCoords *coords,
GimpDisplay *display);
GtkWidget * gimp_filter_tool_dialog_get_vbox (GimpFilterTool *filter_tool);
GtkWidget * gimp_filter_tool_dialog_get_vbox (GimpFilterTool *filter_tool);
GtkWidget * gimp_filter_tool_add_color_picker (GimpFilterTool *filter_tool,
gpointer identifier,
const gchar *icon_name,
const gchar *tooltip,
gboolean pick_abyss);
void gimp_filter_tool_enable_color_picking (GimpFilterTool *filter_tool,
gpointer identifier,
gboolean pick_abyss);
void gimp_filter_tool_disable_color_picking (GimpFilterTool *filter_tool);
GtkWidget * gimp_filter_tool_add_color_picker (GimpFilterTool *filter_tool,
gpointer identifier,
const gchar *icon_name,
const gchar *tooltip,
gboolean pick_abyss);
#endif /* __GIMP_FILTER_TOOL_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment