app: selection stroke and "Stroke Path" now multi-layer aware.

This includes "select-stroke*" actions and "Stroke Path" feature of the
Vector tool.
This commit is contained in:
Jehan 2020-08-01 13:59:21 +02:00
parent 8237c4c3d9
commit 2ba6ac6286
8 changed files with 55 additions and 38 deletions

View File

@ -53,7 +53,7 @@ static void items_fill_callback (GtkWidget *dialog,
gpointer user_data);
static void items_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GList *drawables,
GimpContext *context,
GimpStrokeOptions *options,
gpointer user_data);
@ -277,18 +277,18 @@ items_stroke_cmd_callback (GimpAction *action,
const gchar *dialog_help_id,
gpointer data)
{
GimpDrawable *drawable;
GList *drawables;
GtkWidget *dialog;
GtkWidget *widget;
return_if_no_widget (widget, data);
drawable = gimp_image_get_active_drawable (image);
drawables = gimp_image_get_selected_drawables (image);
if (! drawable)
if (! drawables)
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("There is no active layer or channel to stroke to."));
_("There are no selected layers or channels to stroke to."));
return;
}
@ -299,7 +299,7 @@ items_stroke_cmd_callback (GimpAction *action,
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
dialog = stroke_dialog_new (item,
drawable,
drawables,
action_data_get_context (data),
dialog_title,
dialog_icon_name,
@ -313,6 +313,7 @@ items_stroke_cmd_callback (GimpAction *action,
}
gtk_window_present (GTK_WINDOW (dialog));
g_list_free (drawables);
}
void
@ -321,25 +322,25 @@ items_stroke_last_vals_cmd_callback (GimpAction *action,
GimpItem *item,
gpointer data)
{
GimpDrawable *drawable;
GList *drawables;
GimpDialogConfig *config;
GtkWidget *widget;
GError *error = NULL;
return_if_no_widget (widget, data);
drawable = gimp_image_get_active_drawable (image);
drawables = gimp_image_get_selected_drawables (image);
if (! drawable)
if (! drawables)
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("There is no active layer or channel to stroke to."));
_("There are no selected layers or channels to stroke to."));
return;
}
config = GIMP_DIALOG_CONFIG (image->gimp->config);
if (! gimp_item_stroke (item, drawable,
if (! gimp_item_stroke (item, drawables,
action_data_get_context (data),
config->stroke_options, NULL,
TRUE, NULL, &error))
@ -352,6 +353,8 @@ items_stroke_last_vals_cmd_callback (GimpAction *action,
{
gimp_image_flush (image);
}
g_list_free (drawables);
}
@ -391,7 +394,7 @@ items_fill_callback (GtkWidget *dialog,
static void
items_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GList *drawables,
GimpContext *context,
GimpStrokeOptions *options,
gpointer data)
@ -403,7 +406,7 @@ items_stroke_callback (GtkWidget *dialog,
gimp_config_sync (G_OBJECT (options),
G_OBJECT (config->stroke_options), 0);
if (! gimp_item_stroke (item, drawable, context, options, NULL,
if (! gimp_item_stroke (item, drawables, context, options, NULL,
TRUE, NULL, &error))
{
gimp_message_literal (context->gimp,

View File

@ -132,7 +132,7 @@ static const GimpActionEntry select_actions[] =
GIMP_HELP_SELECTION_STROKE },
{ "select-stroke-last-values", GIMP_ICON_SELECTION_STROKE,
NC_("select-action", "_Stroke Selection"), NULL,
NC_("select-action", "_Stroke Selection with last values"), NULL,
NC_("select-action", "Stroke the selection with last used values"),
select_stroke_last_vals_cmd_callback,
GIMP_HELP_SELECTION_STROKE }
@ -210,8 +210,8 @@ select_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("select-save", image && !fs);
SET_SENSITIVE ("select-fill", drawables && all_writable && no_groups && sel);
SET_SENSITIVE ("select-fill-last-values", drawables && all_writable && no_groups && sel);
SET_SENSITIVE ("select-stroke", writable && !children && sel);
SET_SENSITIVE ("select-stroke-last-values", writable && !children && sel);
SET_SENSITIVE ("select-stroke", drawables && all_writable && no_groups && sel);
SET_SENSITIVE ("select-stroke-last-values", drawables && all_writable && no_groups && sel);
#undef SET_SENSITIVE

View File

@ -1824,7 +1824,7 @@ gimp_item_fill (GimpItem *item,
gboolean
gimp_item_stroke (GimpItem *item,
GimpDrawable *drawable,
GList *drawables,
GimpContext *context,
GimpStrokeOptions *stroke_options,
GimpPaintOptions *paint_options,
@ -1833,12 +1833,11 @@ gimp_item_stroke (GimpItem *item,
GError **error)
{
GimpItemClass *item_class;
GList *iter;
gboolean retval = FALSE;
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
g_return_val_if_fail (gimp_item_is_attached (item), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
g_return_val_if_fail (GIMP_IS_STROKE_OPTIONS (stroke_options), FALSE);
g_return_val_if_fail (paint_options == NULL ||
@ -1848,6 +1847,12 @@ gimp_item_stroke (GimpItem *item,
item_class = GIMP_ITEM_GET_CLASS (item);
for (iter = drawables; iter; iter = iter->next)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (iter->data), FALSE);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (iter->data)), FALSE);
}
if (item_class->stroke)
{
GimpImage *image = gimp_item_get_image (item);
@ -1858,8 +1863,13 @@ gimp_item_stroke (GimpItem *item,
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_PAINT,
item_class->stroke_desc);
retval = item_class->stroke (item, drawable, stroke_options, push_undo,
progress, error);
for (iter = drawables; iter; iter = iter->next)
{
retval = item_class->stroke (item, iter->data, stroke_options, push_undo,
progress, error);
if (! retval)
break;
}
if (push_undo)
gimp_image_undo_group_end (image);

View File

@ -302,7 +302,7 @@ gboolean gimp_item_fill (GimpItem *item,
GimpProgress *progress,
GError **error);
gboolean gimp_item_stroke (GimpItem *item,
GimpDrawable *drawable,
GList *drawables,
GimpContext *context,
GimpStrokeOptions *stroke_options,
GimpPaintOptions *paint_options,

View File

@ -52,7 +52,7 @@ typedef struct _StrokeDialog StrokeDialog;
struct _StrokeDialog
{
GimpItem *item;
GimpDrawable *drawable;
GList *drawables;
GimpContext *context;
GimpStrokeOptions *options;
GimpStrokeCallback callback;
@ -74,7 +74,7 @@ static void stroke_dialog_response (GtkWidget *dialog,
GtkWidget *
stroke_dialog_new (GimpItem *item,
GimpDrawable *drawable,
GList *drawables,
GimpContext *context,
const gchar *title,
const gchar *icon_name,
@ -95,7 +95,7 @@ stroke_dialog_new (GimpItem *item,
GtkWidget *frame;
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (drawables, NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (icon_name != NULL, NULL);
g_return_val_if_fail (help_id != NULL, NULL);
@ -107,7 +107,7 @@ stroke_dialog_new (GimpItem *item,
private = g_slice_new0 (StrokeDialog);
private->item = item;
private->drawable = drawable;
private->drawables = g_list_copy (drawables);
private->context = context;
private->options = gimp_stroke_options_new (context->gimp, context, TRUE);
private->callback = callback;
@ -255,6 +255,7 @@ static void
stroke_dialog_free (StrokeDialog *private)
{
g_object_unref (private->options);
g_list_free (private->drawables);
g_slice_free (StrokeDialog, private);
}
@ -281,7 +282,7 @@ stroke_dialog_response (GtkWidget *dialog,
case GTK_RESPONSE_OK:
private->callback (dialog,
private->item,
private->drawable,
private->drawables,
private->context,
private->options,
private->user_data);

View File

@ -23,14 +23,14 @@
typedef void (* GimpStrokeCallback) (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GList *drawables,
GimpContext *context,
GimpStrokeOptions *options,
gpointer user_data);
GtkWidget * stroke_dialog_new (GimpItem *item,
GimpDrawable *drawable,
GList *drawables,
GimpContext *context,
const gchar *title,
const gchar *icon_name,

View File

@ -142,7 +142,7 @@ static void gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_
GtkWidget *button);
static void gimp_vector_tool_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GList *drawables,
GimpContext *context,
GimpStrokeOptions *options,
gpointer data);
@ -792,7 +792,7 @@ gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
{
GimpDialogConfig *config;
GimpImage *image;
GimpDrawable *drawable;
GList *drawables;
GtkWidget *dialog;
if (! vector_tool->vectors)
@ -802,18 +802,18 @@ gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
config = GIMP_DIALOG_CONFIG (image->gimp->config);
drawable = gimp_image_get_active_drawable (image);
drawables = gimp_image_get_selected_drawables (image);
if (! drawable)
if (! drawables)
{
gimp_tool_message (GIMP_TOOL (vector_tool),
GIMP_TOOL (vector_tool)->display,
_("There is no active layer or channel to stroke to"));
_("There are no selected layers or channels to stroke to."));
return;
}
dialog = stroke_dialog_new (GIMP_ITEM (vector_tool->vectors),
drawable,
drawables,
GIMP_CONTEXT (GIMP_TOOL_GET_OPTIONS (vector_tool)),
_("Stroke Path"),
GIMP_ICON_PATH_STROKE,
@ -823,12 +823,13 @@ gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
gimp_vector_tool_stroke_callback,
vector_tool);
gtk_widget_show (dialog);
g_list_free (drawables);
}
static void
gimp_vector_tool_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GList *drawables,
GimpContext *context,
GimpStrokeOptions *options,
gpointer data)
@ -840,7 +841,7 @@ gimp_vector_tool_stroke_callback (GtkWidget *dialog,
gimp_config_sync (G_OBJECT (options),
G_OBJECT (config->stroke_options), 0);
if (! gimp_item_stroke (item, drawable, context, options, NULL,
if (! gimp_item_stroke (item, drawables, context, options, NULL,
TRUE, NULL, &error))
{
gimp_message_literal (context->gimp,

View File

@ -339,6 +339,7 @@ HELP
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpStrokeOptions *options;
GimpPaintOptions *paint_options;
GList *drawables = g_list_prepend (NULL, drawable);
options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
@ -347,10 +348,11 @@ HELP
paint_options = gimp_config_duplicate (GIMP_CONFIG (paint_options));
success = gimp_item_stroke (GIMP_ITEM (gimp_image_get_mask (image)),
drawable, context, options, paint_options,
drawables, context, options, paint_options,
TRUE, progress, error);
g_object_unref (paint_options);
g_list_free (drawables);
}
else
success = FALSE;