libgimp: Respect alpha setting in color widgets

When creating a color widget in GimpProcedureDialog, we
were not taking into account whether the parameter's
has_alpha boolean was set to FALSE. As a result, all color
widgets allowed for transparency.

This patch checks if the GimpColor's GParamSpec has_alpha value
is FALSE, and if so, sets the color widget's type to
GIMP_COLOR_AREA_FLAT to enforce no transparency for that color.
This commit is contained in:
Alx Sa
2025-01-12 19:10:27 +00:00
parent 2dd55d117c
commit 54405ddd0f

View File

@ -796,16 +796,33 @@ gimp_procedure_dialog_get_widget (GimpProcedureDialog *dialog,
else if (G_PARAM_SPEC_TYPE (pspec) == GIMP_TYPE_PARAM_COLOR ||
G_PARAM_SPEC_TYPE (pspec) == GEGL_TYPE_PARAM_COLOR)
{
gboolean has_alpha = TRUE;
if (G_PARAM_SPEC_TYPE (pspec) == GIMP_TYPE_PARAM_COLOR)
has_alpha = gimp_param_spec_color_has_alpha (pspec);
if (widget_type == G_TYPE_NONE || widget_type == GIMP_TYPE_LABEL_COLOR)
{
widget = gimp_prop_label_color_new (G_OBJECT (priv->config),
property, TRUE);
if (! has_alpha)
{
GtkWidget *color_button;
color_button =
gimp_label_color_get_color_widget (GIMP_LABEL_COLOR (widget));
gimp_color_button_set_type (GIMP_COLOR_BUTTON (color_button),
GIMP_COLOR_AREA_FLAT);
}
}
else if (widget_type == GIMP_TYPE_COLOR_AREA)
{
widget = gimp_prop_color_area_new (G_OBJECT (priv->config),
property, 20, 20,
GIMP_COLOR_AREA_SMALL_CHECKS);
has_alpha ?
GIMP_COLOR_AREA_SMALL_CHECKS :
GIMP_COLOR_AREA_FLAT);
gtk_widget_set_vexpand (widget, FALSE);
gtk_widget_set_hexpand (widget, FALSE);
}
@ -813,7 +830,9 @@ gimp_procedure_dialog_get_widget (GimpProcedureDialog *dialog,
{
widget = gimp_prop_color_select_new (G_OBJECT (priv->config),
property, 20, 20,
GIMP_COLOR_AREA_SMALL_CHECKS);
has_alpha ?
GIMP_COLOR_AREA_SMALL_CHECKS :
GIMP_COLOR_AREA_FLAT);
gtk_widget_set_vexpand (widget, FALSE);
gtk_widget_set_hexpand (widget, FALSE);
}
@ -972,8 +991,9 @@ gimp_procedure_dialog_get_color_widget (GimpProcedureDialog *dialog,
GimpColorAreaType type)
{
GimpProcedureDialogPrivate *priv;
GtkWidget *widget = NULL;
GtkWidget *widget = NULL;
GParamSpec *pspec;
gboolean has_alpha = TRUE;
g_return_val_if_fail (property != NULL, NULL);
@ -994,6 +1014,9 @@ gimp_procedure_dialog_get_color_widget (GimpProcedureDialog *dialog,
return NULL;
}
if (G_PARAM_SPEC_TYPE (pspec) == GIMP_TYPE_PARAM_COLOR)
has_alpha = gimp_param_spec_color_has_alpha (pspec);
if (G_PARAM_SPEC_TYPE (pspec) == GIMP_TYPE_PARAM_COLOR ||
G_PARAM_SPEC_TYPE (pspec) == GEGL_TYPE_PARAM_COLOR)
{
@ -1020,6 +1043,16 @@ gimp_procedure_dialog_get_color_widget (GimpProcedureDialog *dialog,
gimp_help_set_help_data (label, tooltip, NULL);
}
if (! has_alpha)
{
GtkWidget *color_button;
color_button =
gimp_label_color_get_color_widget (GIMP_LABEL_COLOR (widget));
gimp_color_button_set_type (GIMP_COLOR_BUTTON (color_button),
GIMP_COLOR_AREA_FLAT);
}
gimp_procedure_dialog_check_mnemonic (dialog, widget, property, NULL);
g_hash_table_insert (priv->widgets, g_strdup (property), widget);
if (g_object_is_floating (widget))