Commit 5d428194 authored by Jehan's avatar Jehan

app: make GimpBucketFillTool a GimpColorTool.

In particular, it allows to easily color pick. This just makes sense as
the bucket fill is definitely what one could call a "color tool", and
being able to easily change color without having to constantly switch to
color picker tool nor open a color chooser dialog is a must.

The fill type option (FG/BG/Pattern) was already mapped to the common
toggle behavior key (Ctrl on Linux), which is commonly used for
switching to color picker on paint tools. So I decided to remap the fill
type switch to GDK_MOD1_MASK (Alt on Linux) to keep consistent with
other tools (at the price of a change for anyone used to this modifier,
though I doubt it was that much used).
I also made possible to combine the 2 modifiers (so you could pick the
foreground or background color with ctrl and ctrl-alt).
parent 744d6793
......@@ -344,7 +344,7 @@ gimp_bucket_fill_options_gui (GimpToolOptions *tool_options)
GtkWidget *combo;
gchar *str;
GdkModifierType extend_mask = gimp_get_extend_selection_mask ();
GdkModifierType toggle_mask = gimp_get_toggle_behavior_mask ();
GdkModifierType toggle_mask = GDK_MOD1_MASK;
/* fill type */
str = g_strdup_printf (_("Fill Type (%s)"),
......
......@@ -39,6 +39,7 @@
#include "core/gimppickable-contiguous-region.h"
#include "core/gimpprogress.h"
#include "core/gimpprojection.h"
#include "core/gimptoolinfo.h"
#include "core/gimpwaitable.h"
#include "gegl/gimp-gegl-nodes.h"
......@@ -52,6 +53,7 @@
#include "gimpbucketfilloptions.h"
#include "gimpbucketfilltool.h"
#include "gimpcoloroptions.h"
#include "gimptoolcontrol.h"
#include "gimp-intl.h"
......@@ -143,7 +145,7 @@ static void gimp_bucket_fill_tool_drawable_painted (GimpDrawable *dr
GimpBucketFillTool *tool);
G_DEFINE_TYPE_WITH_PRIVATE (GimpBucketFillTool, gimp_bucket_fill_tool, GIMP_TYPE_TOOL)
G_DEFINE_TYPE_WITH_PRIVATE (GimpBucketFillTool, gimp_bucket_fill_tool, GIMP_TYPE_COLOR_TOOL)
#define parent_class gimp_bucket_fill_tool_parent_class
......@@ -220,6 +222,9 @@ gimp_bucket_fill_tool_constructed (GObject *object)
gimp_bucket_fill_tool_connect_handlers (tool);
else
g_idle_add (gimp_bucket_fill_tool_connect_handlers, tool);
GIMP_COLOR_TOOL (tool)->pick_target = (options->fill_mode == GIMP_BUCKET_FILL_BG) ?
GIMP_COLOR_PICK_TARGET_BACKGROUND : GIMP_COLOR_PICK_TARGET_FOREGROUND;
}
static void
......@@ -504,6 +509,13 @@ gimp_bucket_fill_tool_button_press (GimpTool *tool,
GimpBucketFillOptions *options = GIMP_BUCKET_FILL_TOOL_GET_OPTIONS (tool);
GimpImage *image = gimp_display_get_image (display);
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
{
GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
press_type, display);
return;
}
if (press_type == GIMP_BUTTON_PRESS_NORMAL &&
gimp_image_coords_in_active_pickable (image, coords,
options->sample_merged, TRUE))
......@@ -564,6 +576,9 @@ gimp_bucket_fill_tool_motion (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, display);
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
return;
if (gimp_image_coords_in_active_pickable (image, coords,
options->sample_merged, TRUE) &&
/* Fill selection only needs to happen once. */
......@@ -612,6 +627,14 @@ gimp_bucket_fill_tool_button_release (GimpTool *tool,
GimpBucketFillTool *bucket_tool = GIMP_BUCKET_FILL_TOOL (tool);
gboolean commit;
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
{
GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time,
state, release_type,
display);
return;
}
commit = (release_type != GIMP_BUTTON_RELEASE_CANCEL);
if (commit)
......@@ -632,7 +655,7 @@ gimp_bucket_fill_tool_modifier_key (GimpTool *tool,
{
GimpBucketFillOptions *options = GIMP_BUCKET_FILL_TOOL_GET_OPTIONS (tool);
if (key == gimp_get_toggle_behavior_mask ())
if (key == GDK_MOD1_MASK)
{
switch (options->fill_mode)
{
......@@ -648,6 +671,38 @@ gimp_bucket_fill_tool_modifier_key (GimpTool *tool,
break;
}
}
else if (key == gimp_get_toggle_behavior_mask ())
{
GimpToolInfo *info = gimp_get_tool_info (display->gimp,
"gimp-color-picker-tool");
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
{
switch (GIMP_COLOR_TOOL (tool)->pick_target)
{
case GIMP_COLOR_PICK_TARGET_BACKGROUND:
gimp_tool_push_status (tool, display,
_("Click in any image to pick the "
"background color"));
break;
case GIMP_COLOR_PICK_TARGET_FOREGROUND:
default:
gimp_tool_push_status (tool, display,
_("Click in any image to pick the "
"foreground color"));
break;
}
GIMP_TOOL (tool)->display = display;
gimp_color_tool_enable (GIMP_COLOR_TOOL (tool),
GIMP_COLOR_OPTIONS (info->tool_options));
}
else
{
gimp_tool_pop_status (tool, display);
gimp_color_tool_disable (GIMP_COLOR_TOOL (tool));
GIMP_TOOL (tool)->display = NULL;
}
}
else if (key == gimp_get_extend_selection_mask ())
{
g_object_set (options, "fill-selection", ! options->fill_selection, NULL);
......@@ -802,6 +857,10 @@ gimp_bucket_fill_tool_connect_handlers (gpointer data)
G_CALLBACK (gimp_bucket_fill_tool_options_notified),
tool);
g_signal_connect (options, "notify::fill-mode",
G_CALLBACK (gimp_bucket_fill_tool_options_notified),
tool);
g_signal_connect (context, "image-changed",
G_CALLBACK (gimp_bucket_fill_tool_image_changed),
tool);
......@@ -825,6 +884,31 @@ gimp_bucket_fill_tool_options_notified (GimpBucketFillOptions *options,
{
gimp_bucket_fill_compute_line_art (tool);
}
else if (! strcmp (pspec->name, "fill-mode"))
{
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
gimp_tool_pop_status (GIMP_TOOL (tool), GIMP_TOOL (tool)->display);
switch (options->fill_mode)
{
case GIMP_BUCKET_FILL_BG:
GIMP_COLOR_TOOL (tool)->pick_target = GIMP_COLOR_PICK_TARGET_BACKGROUND;
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
gimp_tool_push_status (GIMP_TOOL (tool), GIMP_TOOL (tool)->display,
_("Click in any image to pick the "
"background color"));
break;
case GIMP_BUCKET_FILL_FG:
default:
GIMP_COLOR_TOOL (tool)->pick_target = GIMP_COLOR_PICK_TARGET_FOREGROUND;
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
gimp_tool_push_status (GIMP_TOOL (tool), GIMP_TOOL (tool)->display,
_("Click in any image to pick the "
"foreground color"));
break;
}
}
}
static void
......
......@@ -19,7 +19,7 @@
#define __GIMP_BUCKET_FILL_TOOL_H__
#include "gimptool.h"
#include "gimpcolortool.h"
#define GIMP_TYPE_BUCKET_FILL_TOOL (gimp_bucket_fill_tool_get_type ())
......@@ -38,14 +38,14 @@ typedef struct _GimpBucketFillToolPrivate GimpBucketFillToolPrivate;
struct _GimpBucketFillTool
{
GimpTool parent_instance;
GimpColorTool parent_instance;
GimpBucketFillToolPrivate *priv;
};
struct _GimpBucketFillToolClass
{
GimpToolClass parent_class;
GimpColorToolClass parent_class;
};
......
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