[gimp] app: allow "Lock alpha" to be set on layer groups.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: allow "Lock alpha" to be set on layer groups.
- Date: Tue, 15 Feb 2022 21:08:36 +0000 (UTC)
commit 2e64bfc61b2a5d5d84e51fd46654a43afd9f3bcc
Author: Jehan <jehan girinstud io>
Date: Tue Feb 15 20:13:10 2022 +0100
app: allow "Lock alpha" to be set on layer groups.
It can be argued that layer groups can't be painted on, and that's
probably the original reason, but it's really just the same as "Lock
pixels". It is interesting to be able to lock alpha channels on a layer
group to simply lock all its contents alpha channels.
app/actions/edit-commands.c | 6 ++++--
app/core/gimplayer.c | 40 +++++++++++++++++++++++++++++++++++-----
app/core/gimplayer.h | 5 +++++
app/tools/gimppainttool.c | 11 +++++++----
4 files changed, 51 insertions(+), 11 deletions(-)
---
diff --git a/app/actions/edit-commands.c b/app/actions/edit-commands.c
index 0f5381fb12..fc6734b001 100644
--- a/app/actions/edit-commands.c
+++ b/app/actions/edit-commands.c
@@ -568,9 +568,11 @@ static gboolean
check_drawable_alpha (GimpDrawable *drawable,
gpointer data)
{
+ GimpLayer *locked_layer = NULL;
+
if (gimp_drawable_has_alpha (drawable) &&
GIMP_IS_LAYER (drawable) &&
- gimp_layer_get_lock_alpha (GIMP_LAYER (drawable)))
+ gimp_layer_is_alpha_locked (GIMP_LAYER (drawable), &locked_layer))
{
Gimp *gimp = action_data_get_gimp (data);
GimpDisplay *display = action_data_get_display (data);
@@ -581,7 +583,7 @@ check_drawable_alpha (GimpDrawable *drawable,
gimp, G_OBJECT (display), GIMP_MESSAGE_WARNING,
_("A selected layer's alpha channel is locked."));
- gimp_tools_blink_lock_box (gimp, GIMP_ITEM (drawable));
+ gimp_tools_blink_lock_box (gimp, GIMP_ITEM (locked_layer));
}
return FALSE;
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 19344e91b5..257b71194e 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -220,6 +220,8 @@ static void gimp_layer_srgb_to_pixel (GimpPickable *pickable,
const Babl *format,
gpointer pixel);
+static gboolean gimp_layer_real_is_alpha_locked (GimpLayer *layer,
+ GimpLayer **locked_layer);
static void gimp_layer_real_translate (GimpLayer *layer,
gint offset_x,
gint offset_y);
@@ -468,6 +470,7 @@ gimp_layer_class_init (GimpLayerClass *klass)
klass->apply_mask_changed = NULL;
klass->edit_mask_changed = NULL;
klass->show_mask_changed = NULL;
+ klass->is_alpha_locked = gimp_layer_real_is_alpha_locked;
klass->translate = gimp_layer_real_translate;
klass->scale = gimp_layer_real_scale;
klass->resize = gimp_layer_real_resize;
@@ -1488,7 +1491,8 @@ gimp_layer_get_active_components (GimpDrawable *drawable,
/* first copy the image active channels */
gimp_image_get_active_array (image, active);
- if (gimp_drawable_has_alpha (drawable) && layer->lock_alpha)
+ if (gimp_drawable_has_alpha (drawable) &&
+ gimp_layer_is_alpha_locked (layer, NULL))
active[babl_format_get_n_components (format) - 1] = FALSE;
}
@@ -1499,7 +1503,8 @@ gimp_layer_get_active_mask (GimpDrawable *drawable)
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpComponentMask mask = gimp_image_get_active_mask (image);
- if (gimp_drawable_has_alpha (drawable) && layer->lock_alpha)
+ if (gimp_drawable_has_alpha (drawable) &&
+ gimp_layer_is_alpha_locked (layer, NULL))
mask &= ~GIMP_COMPONENT_MASK_ALPHA;
return mask;
@@ -1627,6 +1632,26 @@ gimp_layer_srgb_to_pixel (GimpPickable *pickable,
gimp_pickable_srgb_to_pixel (GIMP_PICKABLE (image), color, format, pixel);
}
+static gboolean
+gimp_layer_real_is_alpha_locked (GimpLayer *layer,
+ GimpLayer **locked_layer)
+{
+ GimpItem *parent = gimp_item_get_parent (GIMP_ITEM (layer));
+
+ if (layer->lock_alpha)
+ {
+ if (locked_layer)
+ *locked_layer = layer;
+ }
+ else if (parent &&
+ gimp_layer_is_alpha_locked (GIMP_LAYER (parent), locked_layer))
+ {
+ return TRUE;
+ }
+
+ return layer->lock_alpha;
+}
+
static void
gimp_layer_real_translate (GimpLayer *layer,
gint offset_x,
@@ -2899,12 +2924,17 @@ gimp_layer_can_lock_alpha (GimpLayer *layer)
{
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
- if (gimp_viewable_get_children (GIMP_VIEWABLE (layer)))
- return FALSE;
-
return TRUE;
}
+gboolean
+gimp_layer_is_alpha_locked (GimpLayer *layer,
+ GimpLayer **locked_layer)
+{
+ g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
+
+ return GIMP_LAYER_GET_CLASS (layer)->is_alpha_locked (layer, locked_layer);
+}
/* protected functions */
diff --git a/app/core/gimplayer.h b/app/core/gimplayer.h
index 1dde40d514..df58355bb7 100644
--- a/app/core/gimplayer.h
+++ b/app/core/gimplayer.h
@@ -87,6 +87,9 @@ struct _GimpLayerClass
void (* show_mask_changed) (GimpLayer *layer);
/* virtual functions */
+ gboolean (* is_alpha_locked) (GimpLayer *layer,
+ GimpLayer **locked_layer);
+
void (* translate) (GimpLayer *layer,
gint offset_x,
gint offset_y);
@@ -237,6 +240,8 @@ void gimp_layer_set_lock_alpha (GimpLayer *layer,
gboolean push_undo);
gboolean gimp_layer_get_lock_alpha (GimpLayer *layer);
gboolean gimp_layer_can_lock_alpha (GimpLayer *layer);
+gboolean gimp_layer_is_alpha_locked (GimpLayer *layer,
+ GimpLayer **locked_layer);
/* protected */
diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c
index e6092704f4..7497d69207 100644
--- a/app/tools/gimppainttool.c
+++ b/app/tools/gimppainttool.c
@@ -915,24 +915,27 @@ gimp_paint_tool_check_alpha (GimpPaintTool *paint_tool,
if (klass->is_alpha_only && klass->is_alpha_only (paint_tool, drawable))
{
+ GimpLayer *locked_layer = NULL;
+
if (! gimp_drawable_has_alpha (drawable))
{
g_set_error_literal (
error, GIMP_ERROR, GIMP_FAILED,
- _("The active layer does not have an alpha channel."));
+ _("The selected drawable does not have an alpha channel."));
return FALSE;
}
if (GIMP_IS_LAYER (drawable) &&
- gimp_layer_get_lock_alpha (GIMP_LAYER (drawable)))
+ gimp_layer_is_alpha_locked (GIMP_LAYER (drawable),
+ &locked_layer))
{
g_set_error_literal (
error, GIMP_ERROR, GIMP_FAILED,
- _("The active layer's alpha channel is locked."));
+ _("The selected layer's alpha channel is locked."));
if (error)
- gimp_tools_blink_lock_box (display->gimp, GIMP_ITEM (drawable));
+ gimp_tools_blink_lock_box (display->gimp, GIMP_ITEM (locked_layer));
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]