From 59685ce6212835822abc547bf88fed2d472b9cb8 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Mon, 20 Jan 2025 05:41:25 +0000 Subject: [PATCH] widgets: Adapt brush previews to theme We now check the current theme and draw the brush preview color and background to match. --- app/core/gimpbrush.c | 18 +++++++++++++++--- app/widgets/gimpbrusheditor.c | 3 +++ app/widgets/gimpview.c | 2 ++ app/widgets/gimpviewrenderer.c | 27 +++++++++++++++++++++++++++ app/widgets/gimpviewrendererbrush.c | 12 ++++++------ app/widgets/widgets-enums.h | 3 ++- themes/Default/common.css | 5 +++++ 7 files changed, 60 insertions(+), 10 deletions(-) diff --git a/app/core/gimpbrush.c b/app/core/gimpbrush.c index d758c43628..1d04c88be6 100644 --- a/app/core/gimpbrush.c +++ b/app/core/gimpbrush.c @@ -26,6 +26,9 @@ #include "core-types.h" +#include "config/gimpguiconfig.h" + +#include "gimp.h" #include "gimpbezierdesc.h" #include "gimpbrush.h" #include "gimpbrush-boundary.h" @@ -37,6 +40,7 @@ #include "gimpbrushcache.h" #include "gimpbrushgenerated.h" #include "gimpbrushpipe.h" +#include "gimpcontext.h" #include "gimptagged.h" #include "gimptempbuf.h" @@ -366,13 +370,21 @@ gimp_brush_get_new_preview (GimpViewable *viewable, } else { + GimpGuiConfig *config; + guint8 rgb[3] = {0, 0, 0}; + + config = GIMP_GUI_CONFIG (context->gimp->config); + + if (config->theme_scheme == GIMP_THEME_DARK) + rgb[0] = rgb[1] = rgb[2] = 255; + for (y = 0; y < mask_height; y++) { for (x = 0; x < mask_width ; x++) { - *buf++ = 0; - *buf++ = 0; - *buf++ = 0; + *buf++ = rgb[0]; + *buf++ = rgb[1]; + *buf++ = rgb[2]; *buf++ = *mask++; } } diff --git a/app/widgets/gimpbrusheditor.c b/app/widgets/gimpbrusheditor.c index 495dde647a..f031e21d99 100644 --- a/app/widgets/gimpbrusheditor.c +++ b/app/widgets/gimpbrusheditor.c @@ -81,11 +81,14 @@ gimp_brush_editor_class_init (GimpBrushEditorClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GimpDataEditorClass *editor_class = GIMP_DATA_EDITOR_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); object_class->constructed = gimp_brush_editor_constructed; editor_class->set_data = gimp_brush_editor_set_data; editor_class->title = _("Brush Editor"); + + gtk_widget_class_set_css_name (widget_class, "GimpBrushEditor"); } static void diff --git a/app/widgets/gimpview.c b/app/widgets/gimpview.c index 0cd67ea504..2ac29003cb 100644 --- a/app/widgets/gimpview.c +++ b/app/widgets/gimpview.c @@ -164,6 +164,8 @@ gimp_view_class_init (GimpViewClass *klass) klass->clicked = NULL; klass->double_clicked = NULL; klass->context = NULL; + + gtk_widget_class_set_css_name (widget_class, "GimpView"); } static void diff --git a/app/widgets/gimpviewrenderer.c b/app/widgets/gimpviewrenderer.c index 5e7f09e349..de18de6cf5 100644 --- a/app/widgets/gimpviewrenderer.c +++ b/app/widgets/gimpviewrenderer.c @@ -1176,6 +1176,29 @@ gimp_view_render_temp_buf_to_surface (GimpViewRenderer *renderer, case GIMP_VIEW_BG_WHITE: cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); break; + + case GIMP_VIEW_BG_USE_STYLE: + { + GtkStyleContext *style; + GdkRGBA *color = NULL; + + style = gtk_widget_get_style_context (widget); + gtk_style_context_get (style, gtk_style_context_get_state (style), + GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &color, + NULL); + + if (color) + { + cairo_set_source_rgb (cr, color->red, color->green, color->blue); + + gdk_rgba_free (color); + } + else + { + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); + } + } + break; } cairo_paint (cr); @@ -1205,6 +1228,10 @@ gimp_view_render_temp_buf_to_surface (GimpViewRenderer *renderer, case GIMP_VIEW_BG_WHITE: cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); break; + + case GIMP_VIEW_BG_USE_STYLE: + default: + break; } cairo_fill (cr); diff --git a/app/widgets/gimpviewrendererbrush.c b/app/widgets/gimpviewrendererbrush.c index 0bf0116b3b..22c8c5d675 100644 --- a/app/widgets/gimpviewrendererbrush.c +++ b/app/widgets/gimpviewrendererbrush.c @@ -119,8 +119,8 @@ gimp_view_renderer_brush_render (GimpViewRenderer *renderer, gimp_view_renderer_render_temp_buf (renderer, widget, temp_buf, temp_buf_x, temp_buf_y, -1, - GIMP_VIEW_BG_WHITE, - GIMP_VIEW_BG_WHITE); + GIMP_VIEW_BG_USE_STYLE, + GIMP_VIEW_BG_USE_STYLE); gimp_temp_buf_unref (temp_buf); @@ -139,8 +139,8 @@ gimp_view_renderer_brush_render (GimpViewRenderer *renderer, gimp_view_renderer_render_temp_buf (renderer, widget, temp_buf, temp_buf_x, temp_buf_y, -1, - GIMP_VIEW_BG_WHITE, - GIMP_VIEW_BG_WHITE); + GIMP_VIEW_BG_USE_STYLE, + GIMP_VIEW_BG_USE_STYLE); gimp_temp_buf_unref (temp_buf); } @@ -193,8 +193,8 @@ gimp_view_renderer_brush_render_timeout (gpointer data) gimp_view_renderer_render_temp_buf (renderer, renderbrush->widget, temp_buf, temp_buf_x, temp_buf_y, -1, - GIMP_VIEW_BG_WHITE, - GIMP_VIEW_BG_WHITE); + GIMP_VIEW_BG_USE_STYLE, + GIMP_VIEW_BG_USE_STYLE); gimp_temp_buf_unref (temp_buf); diff --git a/app/widgets/widgets-enums.h b/app/widgets/widgets-enums.h index 3ba1c6e5c8..843377ba34 100644 --- a/app/widgets/widgets-enums.h +++ b/app/widgets/widgets-enums.h @@ -128,7 +128,8 @@ typedef enum typedef enum /*< skip >*/ { GIMP_VIEW_BG_CHECKS, - GIMP_VIEW_BG_WHITE + GIMP_VIEW_BG_WHITE, + GIMP_VIEW_BG_USE_STYLE } GimpViewBG; typedef enum /*< skip >*/ diff --git a/themes/Default/common.css b/themes/Default/common.css index b93fe43747..63262fed80 100644 --- a/themes/Default/common.css +++ b/themes/Default/common.css @@ -67,6 +67,11 @@ GimpDock .view:drop(active) { border-top-color: @dimmed-fg-color; } +/* Widget for various previews and icon tabs */ +GimpView { + background-color: @extreme-bg-color; +} + /* Define the mouse-over color for the path * buttons in the various file dialogs. */