widgets, plug-ins: GeglColor port and fix

The border-drawing code for Layer icons
has been ported to GeglColor. Note that
GimpViewRenderer still uses GimpRGB for
gimp_cairo_checkerboard_create (), which
will be fixed in a larger commit.

In 9bee3bed, Border Average's return
value was set to NULL rather than a valid
GeglColor when the procedure was
created, which caused a warning on
launch. This has been fixed.
This commit is contained in:
Alx Sa 2024-03-28 13:51:55 +00:00
parent 202d358991
commit 6a981012be
3 changed files with 24 additions and 23 deletions

View File

@ -121,11 +121,6 @@ G_DEFINE_TYPE_WITH_PRIVATE (GimpViewRenderer, gimp_view_renderer, G_TYPE_OBJECT)
static guint renderer_signals[LAST_SIGNAL] = { 0 }; static guint renderer_signals[LAST_SIGNAL] = { 0 };
static GimpRGB black_color;
static GimpRGB white_color;
static GimpRGB green_color;
static GimpRGB red_color;
static void static void
gimp_view_renderer_class_init (GimpViewRendererClass *klass) gimp_view_renderer_class_init (GimpViewRendererClass *klass)
@ -154,11 +149,6 @@ gimp_view_renderer_class_init (GimpViewRendererClass *klass)
klass->frame_right = 0; klass->frame_right = 0;
klass->frame_top = 0; klass->frame_top = 0;
klass->frame_bottom = 0; klass->frame_bottom = 0;
gimp_rgba_set (&black_color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
gimp_rgba_set (&white_color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
gimp_rgba_set (&green_color, 0.0, 0.94, 0.0, GIMP_OPACITY_OPAQUE);
gimp_rgba_set (&red_color, 1.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
} }
static void static void
@ -171,7 +161,7 @@ gimp_view_renderer_init (GimpViewRenderer *renderer)
renderer->dot_for_dot = TRUE; renderer->dot_for_dot = TRUE;
renderer->border_type = GIMP_VIEW_BORDER_BLACK; renderer->border_type = GIMP_VIEW_BORDER_BLACK;
renderer->border_color = black_color; renderer->border_color = gegl_color_new ("black");
renderer->size = -1; renderer->size = -1;
@ -183,6 +173,7 @@ gimp_view_renderer_dispose (GObject *object)
{ {
GimpViewRenderer *renderer = GIMP_VIEW_RENDERER (object); GimpViewRenderer *renderer = GIMP_VIEW_RENDERER (object);
g_clear_object (&renderer->border_color);
if (renderer->viewable) if (renderer->viewable)
gimp_view_renderer_set_viewable (renderer, NULL); gimp_view_renderer_set_viewable (renderer, NULL);
@ -470,7 +461,7 @@ void
gimp_view_renderer_set_border_type (GimpViewRenderer *renderer, gimp_view_renderer_set_border_type (GimpViewRenderer *renderer,
GimpViewBorderType border_type) GimpViewBorderType border_type)
{ {
GimpRGB *border_color = &black_color; GeglColor *border_color = NULL;
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer)); g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
@ -479,32 +470,36 @@ gimp_view_renderer_set_border_type (GimpViewRenderer *renderer,
switch (border_type) switch (border_type)
{ {
case GIMP_VIEW_BORDER_BLACK: case GIMP_VIEW_BORDER_BLACK:
border_color = &black_color; border_color = gegl_color_new ("black");
break; break;
case GIMP_VIEW_BORDER_WHITE: case GIMP_VIEW_BORDER_WHITE:
border_color = &white_color; border_color = gegl_color_new ("white");
break; break;
case GIMP_VIEW_BORDER_GREEN: case GIMP_VIEW_BORDER_GREEN:
border_color = &green_color; border_color = gegl_color_new ("green");
gegl_color_set_rgba (border_color, 0.0, 0.94, 0.0, 1.0);
break; break;
case GIMP_VIEW_BORDER_RED: case GIMP_VIEW_BORDER_RED:
border_color = &red_color; border_color = gegl_color_new ("red");
break; break;
} }
gimp_view_renderer_set_border_color (renderer, border_color); gimp_view_renderer_set_border_color (renderer, border_color);
if (border_color)
g_object_unref (border_color);
} }
void void
gimp_view_renderer_set_border_color (GimpViewRenderer *renderer, gimp_view_renderer_set_border_color (GimpViewRenderer *renderer,
const GimpRGB *color) GeglColor *color)
{ {
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer)); g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
g_return_if_fail (color != NULL); g_return_if_fail (color != NULL);
if (gimp_rgb_distance (&renderer->border_color, color) > RGB_EPSILON) if (! gimp_color_is_perceptually_identical (renderer->border_color, color))
{ {
renderer->border_color = *color; g_clear_object (&renderer->border_color);
renderer->border_color = gegl_color_duplicate (color);
gimp_view_renderer_update_idle (renderer); gimp_view_renderer_update_idle (renderer);
} }
@ -670,7 +665,8 @@ gimp_view_renderer_draw (GimpViewRenderer *renderer,
cairo_set_line_width (cr, renderer->border_width); cairo_set_line_width (cr, renderer->border_width);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
gimp_cairo_set_source_rgb (cr, &renderer->border_color); gimp_cairo_set_source_color (cr, renderer->border_color, NULL, FALSE,
widget);
x = (available_width - width) / 2.0; x = (available_width - width) / 2.0;
y = (available_height - height) / 2.0; y = (available_height - height) / 2.0;

View File

@ -52,7 +52,7 @@ struct _GimpViewRenderer
guint is_popup : 1; guint is_popup : 1;
GimpViewBorderType border_type; GimpViewBorderType border_type;
GimpRGB border_color; GeglColor *border_color;
/*< protected >*/ /*< protected >*/
cairo_surface_t *surface; cairo_surface_t *surface;
@ -120,7 +120,7 @@ void gimp_view_renderer_set_dot_for_dot (GimpViewRenderer *renderer,
void gimp_view_renderer_set_border_type (GimpViewRenderer *renderer, void gimp_view_renderer_set_border_type (GimpViewRenderer *renderer,
GimpViewBorderType border_type); GimpViewBorderType border_type);
void gimp_view_renderer_set_border_color (GimpViewRenderer *renderer, void gimp_view_renderer_set_border_color (GimpViewRenderer *renderer,
const GimpRGB *border_color); GeglColor *border_color);
void gimp_view_renderer_set_background (GimpViewRenderer *renderer, void gimp_view_renderer_set_background (GimpViewRenderer *renderer,
const gchar *icon_name); const gchar *icon_name);
void gimp_view_renderer_set_color_config (GimpViewRenderer *renderer, void gimp_view_renderer_set_color_config (GimpViewRenderer *renderer,

View File

@ -110,6 +110,10 @@ border_average_create_procedure (GimpPlugIn *plug_in,
const gchar *name) const gchar *name)
{ {
GimpProcedure *procedure = NULL; GimpProcedure *procedure = NULL;
GeglColor *default_return_color;
gegl_init (NULL, NULL);
default_return_color = gegl_color_new ("none");
if (! strcmp (name, PLUG_IN_PROC)) if (! strcmp (name, PLUG_IN_PROC))
{ {
@ -152,9 +156,10 @@ border_average_create_procedure (GimpPlugIn *plug_in,
GIMP_PROC_VAL_COLOR (procedure, "borderaverage", GIMP_PROC_VAL_COLOR (procedure, "borderaverage",
_("The average color of the specified border."), _("The average color of the specified border."),
_("The average color of the specified border."), _("The average color of the specified border."),
TRUE, NULL, TRUE, default_return_color,
G_PARAM_READWRITE); G_PARAM_READWRITE);
} }
g_object_unref (default_return_color);
return procedure; return procedure;
} }