app: remaining drawable actions are now multi-layer aware.

This commit is contained in:
Jehan 2022-10-18 22:19:44 +02:00
parent 85adfb46c8
commit 6eb78ca11f
2 changed files with 134 additions and 77 deletions

View File

@ -151,18 +151,18 @@ void
drawable_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpImage *image;
GList *drawables = NULL;
gboolean has_visible = FALSE;
gboolean is_rgb = FALSE;
gboolean locked = TRUE;
gboolean can_lock = FALSE;
gboolean locked_pos = TRUE;
gboolean can_lock_pos = FALSE;
gboolean writable = FALSE;
gboolean movable = FALSE;
gboolean children = FALSE;
GList *iter;
GimpImage *image;
GList *drawables = NULL;
GList *iter;
gboolean has_visible = FALSE;
gboolean locked = TRUE;
gboolean can_lock = FALSE;
gboolean locked_pos = TRUE;
gboolean can_lock_pos = FALSE;
gboolean all_rgb = TRUE;
gboolean all_writable = TRUE;
gboolean all_movable = TRUE;
gboolean none_children = TRUE;
image = action_data_get_image (data);
@ -172,6 +172,8 @@ drawable_actions_update (GimpActionGroup *group,
for (iter = drawables; iter; iter = iter->next)
{
GimpItem *item;
if (gimp_item_get_visible (iter->data))
has_visible = TRUE;
@ -189,27 +191,27 @@ drawable_actions_update (GimpActionGroup *group,
can_lock_pos = TRUE;
}
if (has_visible && ! locked && ! locked_pos)
break;
}
if (gimp_viewable_get_children (GIMP_VIEWABLE (iter->data)))
none_children = FALSE;
if (g_list_length (drawables) == 1)
{
GimpDrawable *drawable = drawables->data;
GimpItem *item;
if (! gimp_drawable_is_rgb (iter->data))
all_rgb = FALSE;
is_rgb = gimp_drawable_is_rgb (drawable);
if (GIMP_IS_LAYER_MASK (drawable))
item = GIMP_ITEM (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)));
if (GIMP_IS_LAYER_MASK (iter->data))
item = GIMP_ITEM (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (iter->data)));
else
item = GIMP_ITEM (drawable);
item = GIMP_ITEM (iter->data);
writable = ! gimp_item_is_content_locked (item, NULL);
movable = ! gimp_item_is_position_locked (item, NULL);
if (gimp_item_is_content_locked (item, NULL))
all_writable = FALSE;
if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
children = TRUE;
if (gimp_item_is_position_locked (item, NULL))
all_movable = FALSE;
if (has_visible && ! locked && ! locked_pos &&
! none_children && ! all_rgb &&
! all_writable && ! all_movable)
break;
}
}
@ -218,8 +220,8 @@ drawable_actions_update (GimpActionGroup *group,
#define SET_ACTIVE(action,condition) \
gimp_action_group_set_action_active (group, action, (condition) != 0)
SET_SENSITIVE ("drawable-equalize", writable && !children);
SET_SENSITIVE ("drawable-levels-stretch", writable && !children && is_rgb);
SET_SENSITIVE ("drawable-equalize", drawables && all_writable && none_children);
SET_SENSITIVE ("drawable-levels-stretch", drawables && all_writable && none_children && all_rgb);
SET_SENSITIVE ("drawable-visible", drawables);
SET_SENSITIVE ("drawable-lock-content", can_lock);
@ -229,12 +231,12 @@ drawable_actions_update (GimpActionGroup *group,
SET_ACTIVE ("drawable-lock-content", locked);
SET_ACTIVE ("drawable-lock-position", locked_pos);
SET_SENSITIVE ("drawable-flip-horizontal", writable && movable);
SET_SENSITIVE ("drawable-flip-vertical", writable && movable);
SET_SENSITIVE ("drawable-flip-horizontal", drawables && all_writable && all_movable);
SET_SENSITIVE ("drawable-flip-vertical", drawables && all_writable && all_movable);
SET_SENSITIVE ("drawable-rotate-90", writable && movable);
SET_SENSITIVE ("drawable-rotate-180", writable && movable);
SET_SENSITIVE ("drawable-rotate-270", writable && movable);
SET_SENSITIVE ("drawable-rotate-90", drawables && all_writable && all_movable);
SET_SENSITIVE ("drawable-rotate-180", drawables && all_writable && all_movable);
SET_SENSITIVE ("drawable-rotate-270", drawables && all_writable && all_movable);
#undef SET_SENSITIVE
#undef SET_ACTIVE

View File

@ -49,11 +49,23 @@ drawable_equalize_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpImage *image;
GimpDrawable *drawable;
return_if_no_drawable (image, drawable, data);
GimpImage *image;
GList *drawables;
GList *iter;
return_if_no_drawables (image, drawables, data);
if (g_list_length (drawables) > 1)
gimp_image_undo_group_start (image,
GIMP_UNDO_GROUP_DRAWABLE_MOD,
_("Equalize"));
for (iter = drawables; iter; iter = iter->next)
gimp_drawable_equalize (iter->data, TRUE);
if (g_list_length (drawables) > 1)
gimp_image_undo_group_end (image);
gimp_drawable_equalize (drawable, TRUE);
gimp_image_flush (image);
}
@ -63,23 +75,38 @@ drawable_levels_stretch_cmd_callback (GimpAction *action,
gpointer data)
{
GimpImage *image;
GimpDrawable *drawable;
GList *drawables;
GList *iter;
GimpDisplay *display;
GtkWidget *widget;
return_if_no_drawable (image, drawable, data);
return_if_no_drawables (image, drawables, data);
return_if_no_display (display, data);
return_if_no_widget (widget, data);
if (! gimp_drawable_is_rgb (drawable))
for (iter = drawables; iter; iter = iter->next)
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("White Balance operates only on RGB color "
"layers."));
return;
if (! gimp_drawable_is_rgb (iter->data))
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("White Balance operates only on RGB color "
"layers."));
return;
}
}
gimp_drawable_levels_stretch (drawable, GIMP_PROGRESS (display));
if (g_list_length (drawables) > 1)
gimp_image_undo_group_start (image,
GIMP_UNDO_GROUP_DRAWABLE_MOD,
_("Levels"));
for (iter = drawables; iter; iter = iter->next)
gimp_drawable_levels_stretch (iter->data, GIMP_PROGRESS (display));
if (g_list_length (drawables) > 1)
gimp_image_undo_group_end (image);
gimp_image_flush (image);
}
@ -298,37 +325,51 @@ drawable_flip_cmd_callback (GimpAction *action,
gpointer data)
{
GimpImage *image;
GimpDrawable *drawable;
GimpItem *item;
GList *drawables;
GList *iter;
GimpContext *context;
gint off_x, off_y;
gdouble axis = 0.0;
GimpOrientationType orientation;
return_if_no_drawable (image, drawable, data);
return_if_no_drawables (image, drawables, data);
return_if_no_context (context, data);
orientation = (GimpOrientationType) g_variant_get_int32 (value);
item = GIMP_ITEM (drawable);
if (g_list_length (drawables) > 1)
gimp_image_undo_group_start (image,
GIMP_UNDO_GROUP_DRAWABLE_MOD,
_("Flip Drawables"));
gimp_item_get_offset (item, &off_x, &off_y);
switch (orientation)
for (iter = drawables; iter; iter = iter->next)
{
case GIMP_ORIENTATION_HORIZONTAL:
axis = ((gdouble) off_x + (gdouble) gimp_item_get_width (item) / 2.0);
break;
GimpItem *item;
case GIMP_ORIENTATION_VERTICAL:
axis = ((gdouble) off_y + (gdouble) gimp_item_get_height (item) / 2.0);
break;
item = GIMP_ITEM (iter->data);
default:
break;
gimp_item_get_offset (item, &off_x, &off_y);
switch (orientation)
{
case GIMP_ORIENTATION_HORIZONTAL:
axis = ((gdouble) off_x + (gdouble) gimp_item_get_width (item) / 2.0);
break;
case GIMP_ORIENTATION_VERTICAL:
axis = ((gdouble) off_y + (gdouble) gimp_item_get_height (item) / 2.0);
break;
default:
break;
}
gimp_item_flip (item, context, orientation, axis,
gimp_item_get_clip (item, FALSE));
}
gimp_item_flip (item, context, orientation, axis,
gimp_item_get_clip (item, FALSE));
if (g_list_length (drawables) > 1)
gimp_image_undo_group_end (image);
gimp_image_flush (image);
}
@ -339,27 +380,41 @@ drawable_rotate_cmd_callback (GimpAction *action,
gpointer data)
{
GimpImage *image;
GimpDrawable *drawable;
GList *drawables;
GList *iter;
GimpContext *context;
GimpItem *item;
gint off_x, off_y;
gdouble center_x, center_y;
GimpRotationType rotation_type;
return_if_no_drawable (image, drawable, data);
return_if_no_drawables (image, drawables, data);
return_if_no_context (context, data);
rotation_type = (GimpRotationType) g_variant_get_int32 (value);
item = GIMP_ITEM (drawable);
if (g_list_length (drawables) > 1)
gimp_image_undo_group_start (image,
GIMP_UNDO_GROUP_DRAWABLE_MOD,
_("Rotate Drawables"));
gimp_item_get_offset (item, &off_x, &off_y);
for (iter = drawables; iter; iter = iter->next)
{
GimpItem *item;
gint off_x, off_y;
gdouble center_x, center_y;
center_x = ((gdouble) off_x + (gdouble) gimp_item_get_width (item) / 2.0);
center_y = ((gdouble) off_y + (gdouble) gimp_item_get_height (item) / 2.0);
item = GIMP_ITEM (iter->data);
gimp_item_rotate (item, context,
rotation_type, center_x, center_y,
gimp_item_get_clip (item, FALSE));
gimp_item_get_offset (item, &off_x, &off_y);
center_x = ((gdouble) off_x + (gdouble) gimp_item_get_width (item) / 2.0);
center_y = ((gdouble) off_y + (gdouble) gimp_item_get_height (item) / 2.0);
gimp_item_rotate (item, context,
rotation_type, center_x, center_y,
gimp_item_get_clip (item, FALSE));
}
if (g_list_length (drawables) > 1)
gimp_image_undo_group_end (image);
gimp_image_flush (image);
}