app: layers-blend-space-* & layers-composite-space|mode-* multi-layer…

… aware.
This commit is contained in:
Jehan 2020-05-20 23:37:42 +02:00
parent 338ac504df
commit 5c221df99f
4 changed files with 120 additions and 42 deletions

View File

@ -778,9 +778,9 @@ layers_actions_update (GimpActionGroup *group,
gboolean writable = FALSE; gboolean writable = FALSE;
gboolean movable = FALSE; gboolean movable = FALSE;
gboolean children = FALSE; gboolean children = FALSE;
gboolean bs_mutable = FALSE; gboolean bs_mutable = FALSE; /* At least 1 selected layers' blend space is mutable. */
gboolean cs_mutable = FALSE; gboolean cs_mutable = FALSE; /* At least 1 selected layers' composite space is mutable. */
gboolean cm_mutable = FALSE; gboolean cm_mutable = FALSE; /* At least 1 selected layers' composite mode is mutable. */
GList *next_visible = NULL; GList *next_visible = NULL;
gboolean next_mode = TRUE; gboolean next_mode = TRUE;
gboolean prev_mode = TRUE; gboolean prev_mode = TRUE;
@ -879,26 +879,32 @@ layers_actions_update (GimpActionGroup *group,
have_next = TRUE; have_next = TRUE;
} }
if (gimp_layer_mode_is_blend_space_mutable (mode))
bs_mutable = TRUE;
if (gimp_layer_mode_is_composite_space_mutable (mode))
cs_mutable = TRUE;
if (gimp_layer_mode_is_composite_mode_mutable (mode))
cm_mutable = TRUE;
if (have_masks && have_no_masks && if (have_masks && have_no_masks &&
have_groups && have_no_groups && have_groups && have_no_groups &&
have_writable && ! all_masks_shown && have_writable && ! all_masks_shown &&
! all_masks_disabled && ! all_masks_disabled &&
! lock_alpha && can_lock_alpha && ! lock_alpha && can_lock_alpha &&
! prev_mode && ! next_mode && ! prev_mode && ! next_mode &&
have_prev && have_next) have_prev && have_next &&
bs_mutable && cs_mutable && cm_mutable)
break; break;
} }
if (n_layers == 1) if (n_layers == 1)
{ {
/* Special unique layer case. */ /* Special unique layer case. */
GimpLayerMode mode;
const gchar *action = NULL; const gchar *action = NULL;
GList *layer_list; GList *layer_list;
GList *list; GList *list;
layer = layers->data; layer = layers->data;
mode = gimp_layer_get_mode (layer);
switch (gimp_layer_get_blend_space (layer)) switch (gimp_layer_get_blend_space (layer))
{ {
case GIMP_LAYER_COLOR_SPACE_AUTO: case GIMP_LAYER_COLOR_SPACE_AUTO:
@ -945,10 +951,6 @@ layers_actions_update (GimpActionGroup *group,
gimp_action_group_set_action_active (group, action, TRUE); gimp_action_group_set_action_active (group, action, TRUE);
bs_mutable = gimp_layer_mode_is_blend_space_mutable (mode);
cs_mutable = gimp_layer_mode_is_composite_space_mutable (mode);
cm_mutable = gimp_layer_mode_is_composite_mode_mutable (mode);
mask = gimp_layer_get_mask (layer); mask = gimp_layer_get_mask (layer);
alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)); alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
visible = gimp_item_get_visible (GIMP_ITEM (layer)); visible = gimp_item_get_visible (GIMP_ITEM (layer));
@ -1060,19 +1062,19 @@ layers_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("layers-lock-alpha", can_lock_alpha); SET_SENSITIVE ("layers-lock-alpha", can_lock_alpha);
SET_ACTIVE ("layers-lock-alpha", lock_alpha); SET_ACTIVE ("layers-lock-alpha", lock_alpha);
SET_SENSITIVE ("layers-blend-space-auto", layer && bs_mutable); SET_SENSITIVE ("layers-blend-space-auto", n_layers && bs_mutable);
SET_SENSITIVE ("layers-blend-space-rgb-linear", layer && bs_mutable); SET_SENSITIVE ("layers-blend-space-rgb-linear", n_layers && bs_mutable);
SET_SENSITIVE ("layers-blend-space-rgb-perceptual", layer && bs_mutable); SET_SENSITIVE ("layers-blend-space-rgb-perceptual", n_layers && bs_mutable);
SET_SENSITIVE ("layers-composite-space-auto", layer && cs_mutable); SET_SENSITIVE ("layers-composite-space-auto", n_layers && cs_mutable);
SET_SENSITIVE ("layers-composite-space-rgb-linear", layer && cs_mutable); SET_SENSITIVE ("layers-composite-space-rgb-linear", n_layers && cs_mutable);
SET_SENSITIVE ("layers-composite-space-rgb-perceptual", layer && cs_mutable); SET_SENSITIVE ("layers-composite-space-rgb-perceptual", n_layers && cs_mutable);
SET_SENSITIVE ("layers-composite-mode-auto", layer && cm_mutable); SET_SENSITIVE ("layers-composite-mode-auto", n_layers && cm_mutable);
SET_SENSITIVE ("layers-composite-mode-union", layer && cm_mutable); SET_SENSITIVE ("layers-composite-mode-union", n_layers && cm_mutable);
SET_SENSITIVE ("layers-composite-mode-clip-to-backdrop", layer && cm_mutable); SET_SENSITIVE ("layers-composite-mode-clip-to-backdrop", n_layers && cm_mutable);
SET_SENSITIVE ("layers-composite-mode-clip-to-layer", layer && cm_mutable); SET_SENSITIVE ("layers-composite-mode-clip-to-layer", n_layers && cm_mutable);
SET_SENSITIVE ("layers-composite-mode-intersection", layer && cm_mutable); SET_SENSITIVE ("layers-composite-mode-intersection", n_layers && cm_mutable);
SET_SENSITIVE ("layers-mask-add", n_layers > 0 && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-add", n_layers > 0 && !fs && !ac && mask);
SET_SENSITIVE ("layers-mask-add-button", n_layers > 0 && !fs && !ac); SET_SENSITIVE ("layers-mask-add-button", n_layers > 0 && !fs && !ac);

View File

@ -1717,24 +1717,49 @@ layers_blend_space_cmd_callback (GimpAction *action,
gpointer data) gpointer data)
{ {
GimpImage *image; GimpImage *image;
GimpLayer *layer; GList *layers;
GList *update_layers = NULL;
GList *iter;
GimpLayerColorSpace blend_space; GimpLayerColorSpace blend_space;
return_if_no_layer (image, layer, data); gboolean push_undo = TRUE;
return_if_no_layers (image, layers, data);
blend_space = (GimpLayerColorSpace) g_variant_get_int32 (value); blend_space = (GimpLayerColorSpace) g_variant_get_int32 (value);
if (blend_space != gimp_layer_get_blend_space (layer)) for (iter = layers; iter; iter = iter->next)
{
GimpLayerMode mode;
mode = gimp_layer_get_mode (iter->data);
if (gimp_layer_mode_is_blend_space_mutable (mode) &&
blend_space != gimp_layer_get_blend_space (iter->data))
update_layers = g_list_prepend (update_layers, iter->data);
}
if (g_list_length (update_layers) == 1)
{ {
GimpUndo *undo; GimpUndo *undo;
gboolean push_undo = TRUE;
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_LAYER_PROP_UNDO, undo = gimp_image_undo_can_compress (image, GIMP_TYPE_LAYER_PROP_UNDO,
GIMP_UNDO_LAYER_MODE); GIMP_UNDO_LAYER_MODE);
if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (layer)) if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (update_layers->data))
push_undo = FALSE; push_undo = FALSE;
}
gimp_layer_set_blend_space (layer, blend_space, push_undo); if (update_layers)
{
if (g_list_length (update_layers) > 1)
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_LAYER_MODE,
_("Set layers' blend space"));
for (iter = update_layers; iter; iter = iter->next)
gimp_layer_set_blend_space (iter->data, blend_space, push_undo);
if (g_list_length (update_layers) > 1)
gimp_image_undo_group_end (image);
g_list_free (update_layers);
gimp_image_flush (image); gimp_image_flush (image);
} }
} }
@ -1745,24 +1770,49 @@ layers_composite_space_cmd_callback (GimpAction *action,
gpointer data) gpointer data)
{ {
GimpImage *image; GimpImage *image;
GimpLayer *layer; GList *layers;
GList *update_layers = NULL;
GList *iter;
GimpLayerColorSpace composite_space; GimpLayerColorSpace composite_space;
return_if_no_layer (image, layer, data); gboolean push_undo = TRUE;
return_if_no_layers (image, layers, data);
composite_space = (GimpLayerColorSpace) g_variant_get_int32 (value); composite_space = (GimpLayerColorSpace) g_variant_get_int32 (value);
if (composite_space != gimp_layer_get_composite_space (layer)) for (iter = layers; iter; iter = iter->next)
{
GimpLayerMode mode;
mode = gimp_layer_get_mode (iter->data);
if (gimp_layer_mode_is_composite_space_mutable (mode) &&
composite_space != gimp_layer_get_composite_space (iter->data))
update_layers = g_list_prepend (update_layers, iter->data);
}
if (g_list_length (update_layers) == 1)
{ {
GimpUndo *undo; GimpUndo *undo;
gboolean push_undo = TRUE;
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_LAYER_PROP_UNDO, undo = gimp_image_undo_can_compress (image, GIMP_TYPE_LAYER_PROP_UNDO,
GIMP_UNDO_LAYER_MODE); GIMP_UNDO_LAYER_MODE);
if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (layer)) if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (update_layers->data))
push_undo = FALSE; push_undo = FALSE;
}
gimp_layer_set_composite_space (layer, composite_space, push_undo); if (update_layers)
{
if (g_list_length (update_layers) > 1)
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_LAYER_MODE,
_("Set layers' composite space"));
for (iter = update_layers; iter; iter = iter->next)
gimp_layer_set_composite_space (iter->data, composite_space, push_undo);
if (g_list_length (update_layers) > 1)
gimp_image_undo_group_end (image);
g_list_free (update_layers);
gimp_image_flush (image); gimp_image_flush (image);
} }
} }
@ -1773,24 +1823,49 @@ layers_composite_mode_cmd_callback (GimpAction *action,
gpointer data) gpointer data)
{ {
GimpImage *image; GimpImage *image;
GimpLayer *layer; GList *layers;
GList *update_layers = NULL;
GList *iter;
GimpLayerCompositeMode composite_mode; GimpLayerCompositeMode composite_mode;
return_if_no_layer (image, layer, data); gboolean push_undo = TRUE;
return_if_no_layers (image, layers, data);
composite_mode = (GimpLayerCompositeMode) g_variant_get_int32 (value); composite_mode = (GimpLayerCompositeMode) g_variant_get_int32 (value);
if (composite_mode != gimp_layer_get_composite_mode (layer)) for (iter = layers; iter; iter = iter->next)
{
GimpLayerMode mode;
mode = gimp_layer_get_mode (iter->data);
if (gimp_layer_mode_is_composite_mode_mutable (mode) &&
composite_mode != gimp_layer_get_composite_mode (iter->data))
update_layers = g_list_prepend (update_layers, iter->data);
}
if (g_list_length (update_layers) == 1)
{ {
GimpUndo *undo; GimpUndo *undo;
gboolean push_undo = TRUE;
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_LAYER_PROP_UNDO, undo = gimp_image_undo_can_compress (image, GIMP_TYPE_LAYER_PROP_UNDO,
GIMP_UNDO_LAYER_MODE); GIMP_UNDO_LAYER_MODE);
if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (layer)) if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (update_layers->data))
push_undo = FALSE; push_undo = FALSE;
}
gimp_layer_set_composite_mode (layer, composite_mode, push_undo); if (update_layers)
{
if (g_list_length (update_layers) > 1)
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_LAYER_MODE,
_("Set layers' composite mode"));
for (iter = update_layers; iter; iter = iter->next)
gimp_layer_set_composite_mode (iter->data, composite_mode, push_undo);
if (g_list_length (update_layers) > 1)
gimp_image_undo_group_end (image);
g_list_free (update_layers);
gimp_image_flush (image); gimp_image_flush (image);
} }
} }

View File

@ -530,6 +530,7 @@ typedef enum /*< pdb-skip >*/
GIMP_UNDO_GROUP_LAYER_APPLY_MASK, /*< desc="Apply layer mask" >*/ GIMP_UNDO_GROUP_LAYER_APPLY_MASK, /*< desc="Apply layer mask" >*/
GIMP_UNDO_GROUP_LAYER_LOCK_ALPHA, /*< desc="Lock/Unlock alpha channels" >*/ GIMP_UNDO_GROUP_LAYER_LOCK_ALPHA, /*< desc="Lock/Unlock alpha channels" >*/
GIMP_UNDO_GROUP_LAYER_OPACITY, /*< desc="Set layers opacity" >*/ GIMP_UNDO_GROUP_LAYER_OPACITY, /*< desc="Set layers opacity" >*/
GIMP_UNDO_GROUP_LAYER_MODE, /*< desc="Set layers mode" >*/
GIMP_UNDO_GROUP_FS_TO_LAYER, /*< desc="Floating selection to layer" >*/ GIMP_UNDO_GROUP_FS_TO_LAYER, /*< desc="Floating selection to layer" >*/
GIMP_UNDO_GROUP_FS_FLOAT, /*< desc="Float selection" >*/ GIMP_UNDO_GROUP_FS_FLOAT, /*< desc="Float selection" >*/
GIMP_UNDO_GROUP_FS_ANCHOR, /*< desc="Anchor floating selection" >*/ GIMP_UNDO_GROUP_FS_ANCHOR, /*< desc="Anchor floating selection" >*/

View File

@ -2712,7 +2712,7 @@ gimp_layer_set_blend_space (GimpLayer *layer,
{ {
GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer)); GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
gimp_image_undo_push_layer_mode (image, NULL, layer); gimp_image_undo_push_layer_mode (image, _("Set layer's blend space"), layer);
} }
layer->blend_space = blend_space; layer->blend_space = blend_space;
@ -2759,7 +2759,7 @@ gimp_layer_set_composite_space (GimpLayer *layer,
{ {
GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer)); GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
gimp_image_undo_push_layer_mode (image, NULL, layer); gimp_image_undo_push_layer_mode (image, _("Set layer's composite space"), layer);
} }
layer->composite_space = composite_space; layer->composite_space = composite_space;
@ -2806,7 +2806,7 @@ gimp_layer_set_composite_mode (GimpLayer *layer,
{ {
GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer)); GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
gimp_image_undo_push_layer_mode (image, NULL, layer); gimp_image_undo_push_layer_mode (image, _("Set layer's composite mode"), layer);
} }
layer->composite_mode = composite_mode; layer->composite_mode = composite_mode;