app/tools: Add shortcuts for Paint Select modes
This patch ports the Add/Subtract mode shortcuts from GimpSelectionTool to GimpPaintSelectionTool, implementing the unfinished gimp_paint_select_tool_modifier_key () function. The UI itself is left unchanged.
This commit is contained in:
parent
4b499d0975
commit
94a276973d
3 changed files with 100 additions and 9 deletions
|
|
@ -168,7 +168,11 @@ gimp_paint_select_options_gui (GimpToolOptions *tool_options)
|
|||
GtkWidget *hbox;
|
||||
GtkWidget *button;
|
||||
GtkWidget *frame;
|
||||
GList *children;
|
||||
GList *radio_children;
|
||||
GList *list;
|
||||
GtkWidget *scale;
|
||||
gint i;
|
||||
|
||||
frame = gimp_prop_enum_radio_frame_new (config, "mode", NULL,
|
||||
0, 0);
|
||||
|
|
@ -176,7 +180,39 @@ gimp_paint_select_options_gui (GimpToolOptions *tool_options)
|
|||
|
||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
||||
gtk_widget_show (hbox);
|
||||
gtk_widget_set_visible (hbox, TRUE);
|
||||
|
||||
/* add modifier to tooltips */
|
||||
children = gtk_container_get_children (GTK_CONTAINER (frame));
|
||||
radio_children = gtk_container_get_children (GTK_CONTAINER (children->data));
|
||||
for (list = radio_children, i = 0; list; list = list->next, i++)
|
||||
{
|
||||
GtkWidget *button = list->data;
|
||||
const gchar *modifier = NULL;
|
||||
const gchar *label = NULL;
|
||||
|
||||
if (i == 0)
|
||||
modifier = gimp_get_mod_string (gimp_get_extend_selection_mask ());
|
||||
else if (i == 1)
|
||||
modifier = gimp_get_mod_string (gimp_get_modify_selection_mask ());
|
||||
|
||||
if (! modifier)
|
||||
continue;
|
||||
|
||||
label = gtk_button_get_label (GTK_BUTTON (button));
|
||||
|
||||
if (label)
|
||||
{
|
||||
gchar *tip = g_strdup_printf ("%s <b>%s</b>", label, modifier);
|
||||
|
||||
gimp_help_set_help_data_with_markup (button, tip, NULL);
|
||||
|
||||
g_free (tip);
|
||||
}
|
||||
}
|
||||
g_list_free (children);
|
||||
g_list_free (radio_children);
|
||||
g_list_free (list);
|
||||
|
||||
/* stroke width */
|
||||
scale = gimp_prop_spin_scale_new (config, "stroke-width",
|
||||
|
|
@ -190,7 +226,7 @@ gimp_paint_select_options_gui (GimpToolOptions *tool_options)
|
|||
gtk_image_set_from_icon_name (GTK_IMAGE (gtk_bin_get_child (GTK_BIN (button))),
|
||||
GIMP_ICON_RESET, GTK_ICON_SIZE_MENU);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
|
||||
gtk_widget_show (button);
|
||||
gtk_widget_set_visible (button, TRUE);
|
||||
|
||||
g_signal_connect (button, "clicked",
|
||||
G_CALLBACK (gimp_paint_select_options_reset_stroke_width),
|
||||
|
|
@ -202,7 +238,7 @@ gimp_paint_select_options_gui (GimpToolOptions *tool_options)
|
|||
/* show scribbles */
|
||||
button = gimp_prop_check_button_new (config, "show-scribbles", "Show scribbles");
|
||||
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
||||
gtk_widget_show (button);
|
||||
gtk_widget_set_visible (button, TRUE);
|
||||
|
||||
return vbox;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -420,13 +420,68 @@ gimp_paint_select_tool_key_press (GimpTool *tool,
|
|||
return GIMP_TOOL_CLASS (parent_class)->key_press (tool, kevent, display);
|
||||
}
|
||||
|
||||
/* Based on gimp_selection_tool_modifier_key () */
|
||||
static void
|
||||
gimp_paint_select_tool_modifier_key (GimpTool *tool,
|
||||
GdkModifierType key,
|
||||
gboolean press,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *display)
|
||||
GdkModifierType key,
|
||||
gboolean press,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
GimpPaintSelectTool *ps_tool = GIMP_PAINT_SELECT_TOOL (tool);
|
||||
GimpPaintSelectOptions *options = GIMP_PAINT_SELECT_TOOL_GET_OPTIONS (ps_tool);
|
||||
GdkModifierType extend_mask;
|
||||
GdkModifierType modify_mask;
|
||||
|
||||
extend_mask = gimp_get_extend_selection_mask ();
|
||||
modify_mask = gimp_get_modify_selection_mask ();
|
||||
|
||||
if (key == extend_mask ||
|
||||
key == modify_mask ||
|
||||
key == GDK_MOD1_MASK)
|
||||
{
|
||||
GimpPaintSelectMode button_mode = options->mode;
|
||||
|
||||
state &= extend_mask | modify_mask | GDK_MOD1_MASK;
|
||||
|
||||
if (press)
|
||||
{
|
||||
if (key == state || ! state)
|
||||
ps_tool->saved_mode = options->mode;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! state)
|
||||
button_mode = ps_tool->saved_mode;
|
||||
}
|
||||
|
||||
if (state & GDK_MOD1_MASK)
|
||||
{
|
||||
button_mode = ps_tool->saved_mode;
|
||||
}
|
||||
else if (state & (extend_mask | modify_mask))
|
||||
{
|
||||
GimpChannelOps op = gimp_modifiers_to_channel_op (state);
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case GIMP_CHANNEL_OP_ADD:
|
||||
button_mode = GIMP_PAINT_SELECT_MODE_ADD;
|
||||
break;
|
||||
|
||||
case GIMP_CHANNEL_OP_SUBTRACT:
|
||||
button_mode = GIMP_PAINT_SELECT_MODE_SUBTRACT;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (button_mode != options->mode)
|
||||
g_object_set (options, "mode", button_mode, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -809,7 +864,6 @@ gimp_paint_select_tool_create_graph (GimpPaintSelectTool *ps_tool)
|
|||
GeglNode *d; /* drawable */
|
||||
GeglNode *crop;
|
||||
GeglNode *translate = NULL;
|
||||
|
||||
|
||||
ps_tool->graph = gegl_node_new ();
|
||||
|
||||
|
|
@ -858,7 +912,6 @@ gimp_paint_select_tool_create_graph (GimpPaintSelectTool *ps_tool)
|
|||
"operation", "gegl:buffer-sink",
|
||||
NULL);
|
||||
|
||||
|
||||
gegl_node_link_many (m, ps_tool->threshold_node, crop, NULL);
|
||||
|
||||
if (translate)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ struct _GimpPaintSelectTool
|
|||
{
|
||||
GimpDrawTool parent_instance;
|
||||
|
||||
GimpPaintSelectMode saved_mode; /* saved tool options state */
|
||||
|
||||
GeglBuffer *trimap;
|
||||
GeglBuffer *image_mask;
|
||||
GeglBuffer *drawable;
|
||||
|
|
|
|||
Loading…
Reference in a new issue