widgets: Use different color for Histogram borders

GimpHistogramView uses the widget's foreground color
to draw both the histogram and its border. This causes
clipped values to blend into the sides of the border,
preventing the user from seeing them.

This patch gets the luminance value of the foreground
color, then uses that as a threshold to lighten or
darken the border color for contrast.
This commit is contained in:
Alx Sa 2025-03-21 13:25:20 +00:00
parent 25b423d094
commit b1d1699f14

View file

@ -23,6 +23,7 @@
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor-private.h"
#include "libgimpmath/gimpmath.h"
#include "widgets-types.h"
@ -306,6 +307,7 @@ gimp_histogram_view_draw (GtkWidget *widget,
gdouble max = 0.0;
gdouble bg_max = 0.0;
gint xstop;
gfloat lum;
GdkRGBA grid_color;
GdkRGBA color_in;
GdkRGBA color_out;
@ -335,6 +337,25 @@ gimp_histogram_view_draw (GtkWidget *widget,
&grid_color);
gtk_style_context_remove_class (style, "grid");
/* Alter the border so the histogram stands out against it */
if (view->histogram)
{
lum = GIMP_RGB_LUMINANCE (grid_color.red, grid_color.green,
grid_color.blue);
if (lum > 0.5)
{
grid_color.red = CLAMP (grid_color.red - 0.33, 0, 1);
grid_color.green = CLAMP (grid_color.green - 0.33, 0, 1);
grid_color.blue = CLAMP (grid_color.blue - 0.33, 0, 1);
}
else
{
grid_color.red = CLAMP (grid_color.red + 0.33, 0, 1);
grid_color.green = CLAMP (grid_color.green + 0.33, 0, 1);
grid_color.blue = CLAMP (grid_color.blue + 0.33, 0, 1);
}
}
gdk_cairo_set_source_rgba (cr, &grid_color);
cairo_rectangle (cr, border, border, width - 1, height - 1);
cairo_stroke (cr);