From: Colin Clark Date: Sun, 24 Sep 2023 12:53:14 +0000 (+0100) Subject: GTK4: GdkColor X-Git-Tag: v2.2~85 X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65b40444b3fe2b69ad28a16791edfc631193d63c;p=geeqie.git GTK4: GdkColor GTK4 migration - GdkColor replaced by GdkRGBA - Remaining problems related to gtk_widget_get_style() --- diff --git a/src/cellrenderericon.cc b/src/cellrenderericon.cc index feef60715..492008572 100644 --- a/src/cellrenderericon.cc +++ b/src/cellrenderericon.cc @@ -171,16 +171,16 @@ gqv_cell_renderer_icon_class_init(GQvCellRendererIconClass *icon_class) PROP_BACKGROUND_GDK, g_param_spec_boxed("background_gdk", "Background color", - "Background color as a GdkColor", - GDK_TYPE_COLOR, + "Background color as a GdkRGBA", + GDK_TYPE_RGBA, G_PARAM_READWRITE)); g_object_class_install_property(object_class, PROP_FOREGROUND_GDK, g_param_spec_boxed("foreground_gdk", "Foreground color", - "Foreground color as a GdkColor", - GDK_TYPE_COLOR, + "Foreground color as a GdkRGBA", + GDK_TYPE_RGBA, G_PARAM_READWRITE)); g_object_class_install_property(object_class, @@ -309,22 +309,22 @@ gqv_cell_renderer_icon_get_property(GObject *object, break; case PROP_BACKGROUND_GDK: { - GdkColor color; + GdkRGBA color; - color.red = cellicon->background.red; - color.green = cellicon->background.green; - color.blue = cellicon->background.blue; + color.red = cellicon->background.red / 65535; + color.green = cellicon->background.green / 65535; + color.blue = cellicon->background.blue / 65535; g_value_set_boxed(value, &color); } break; case PROP_FOREGROUND_GDK: { - GdkColor color; + GdkRGBA color; - color.red = cellicon->foreground.red; - color.green = cellicon->foreground.green; - color.blue = cellicon->foreground.blue; + color.red = cellicon->foreground.red / 65535; + color.green = cellicon->foreground.green / 65535; + color.blue = cellicon->foreground.blue / 65535; g_value_set_boxed(value, &color); } @@ -365,9 +365,7 @@ gqv_cell_renderer_icon_get_property(GObject *object, } } -static void -set_bg_color(GQvCellRendererIcon *cellicon, - GdkColor *color) +static void set_bg_color(GQvCellRendererIcon *cellicon, GdkRGBA *color) { if (color) { @@ -377,9 +375,9 @@ set_bg_color(GQvCellRendererIcon *cellicon, g_object_notify(G_OBJECT(cellicon), "background_set"); } - cellicon->background.red = color->red; - cellicon->background.green = color->green; - cellicon->background.blue = color->blue; + cellicon->background.red = color->red * 65535; + cellicon->background.green = color->green * 65535; + cellicon->background.blue = color->blue * 65535; } else { @@ -391,8 +389,7 @@ set_bg_color(GQvCellRendererIcon *cellicon, } } -static void set_fg_color(GQvCellRendererIcon *cellicon, - GdkColor *color) +static void set_fg_color(GQvCellRendererIcon *cellicon, GdkRGBA *color) { if (color) { @@ -401,10 +398,9 @@ static void set_fg_color(GQvCellRendererIcon *cellicon, cellicon->foreground_set = TRUE; g_object_notify(G_OBJECT(cellicon), "foreground_set"); } - - cellicon->foreground.red = color->red; - cellicon->foreground.green = color->green; - cellicon->foreground.blue = color->blue; + cellicon->foreground.red = color->red * 65535; + cellicon->foreground.green = color->green * 65535; + cellicon->foreground.blue = color->blue * 65535; } else { @@ -448,10 +444,10 @@ gqv_cell_renderer_icon_set_property(GObject *object, } break; case PROP_BACKGROUND_GDK: - set_bg_color(cellicon, static_cast(g_value_get_boxed(value))); + set_bg_color(cellicon, static_cast(g_value_get_boxed(value))); break; case PROP_FOREGROUND_GDK: - set_fg_color(cellicon, static_cast(g_value_get_boxed(value))); + set_fg_color(cellicon, static_cast(g_value_get_boxed(value))); break; case PROP_FOCUSED: cellicon->focused = g_value_get_boolean(value); diff --git a/src/collect-table.cc b/src/collect-table.cc index a3ef739ce..4177af4fc 100644 --- a/src/collect-table.cc +++ b/src/collect-table.cc @@ -33,6 +33,7 @@ #include "layout-image.h" #include "menu.h" #include "metadata.h" +#include "misc.h" #include "pixbuf-util.h" #include "print.h" #include "utilops.h" @@ -2480,14 +2481,16 @@ static void collection_table_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer * GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) { auto cd = static_cast(data); - CollectTable *ct; - GtkStyle *style; - GList *list; CollectInfo *info; - GdkColor color_fg; - GdkColor color_bg; - gchar *star_rating = nullptr; + CollectTable *ct; gchar *display_text = nullptr; + gchar *star_rating = nullptr; + GdkRGBA color_bg; + GdkRGBA color_bg_style; + GdkRGBA color_fg; + GdkRGBA color_fg_style; + GList *list; + GtkStyle *style; ct = cd->ct; @@ -2505,13 +2508,22 @@ static void collection_table_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer * style = gtk_widget_get_style(ct->listview); if (info && (info->flag_mask & SELECTION_SELECTED) ) { - memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg)); - memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg)); + convert_gdkcolor_to_gdkrgba(&style->text[GTK_STATE_SELECTED], &color_fg_style); + convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_SELECTED], &color_bg_style); + + memcpy(&color_fg, &color_fg_style, sizeof(color_fg)); + memcpy(&color_bg, &color_bg_style, sizeof(color_bg)); } else { - memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg)); - memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg)); + convert_gdkcolor_to_gdkrgba(&style->text[GTK_STATE_NORMAL], &color_fg_style); + convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_NORMAL], &color_bg_style); + + memcpy(&color_fg, &color_fg_style, sizeof(color_fg)); + memcpy(&color_bg, &color_bg_style, sizeof(color_bg)); + + memcpy(&color_fg, &color_fg_style, sizeof(color_fg)); + memcpy(&color_bg, &color_bg_style, sizeof(color_bg)); } if (info && (info->flag_mask & SELECTION_PRELIGHT)) diff --git a/src/dupe.cc b/src/dupe.cc index 60775af76..d9af89616 100644 --- a/src/dupe.cc +++ b/src/dupe.cc @@ -3994,9 +3994,10 @@ void cell_renderer_height_override(GtkCellRenderer *renderer) } } -static GdkColor *dupe_listview_color_shifted(GtkWidget *widget) +static GdkRGBA *dupe_listview_color_shifted(GtkWidget *widget) { - static GdkColor color; + static GdkRGBA color; + static GdkRGBA color_style; static GtkWidget *done = nullptr; if (done != widget) @@ -4004,7 +4005,9 @@ static GdkColor *dupe_listview_color_shifted(GtkWidget *widget) GtkStyle *style; style = gtk_widget_get_style(widget); - memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); + convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_NORMAL], &color_style); + + memcpy(&color, &color_style, sizeof(color)); shift_color(&color, -1, 0); done = widget; } diff --git a/src/image.cc b/src/image.cc index 6eeb60710..f6baf96de 100644 --- a/src/image.cc +++ b/src/image.cc @@ -1882,15 +1882,15 @@ void image_top_window_set_sync(ImageWindow *imd, gboolean allow_sync) g_object_set(G_OBJECT(imd->pr), "window_fit", allow_sync, NULL); } -void image_background_set_color(ImageWindow *imd, GdkColor *color) +void image_background_set_color(ImageWindow *imd, GdkRGBA *color) { pixbuf_renderer_set_color(reinterpret_cast(imd->pr), color); } void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscreen) { - GdkColor *color = nullptr; - GdkColor theme_color; + GdkRGBA *color = nullptr; + GdkRGBA theme_color; GdkRGBA bg_color; GtkStyleContext *style_context; LayoutWindow *lw = nullptr; @@ -1908,9 +1908,9 @@ void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscre style_context = gtk_widget_get_style_context(lw->window); gtk_style_context_get_background_color(style_context, GTK_STATE_FLAG_NORMAL, &bg_color); - theme_color.red = bg_color.red * 65535; - theme_color.green = bg_color.green * 65535; - theme_color.blue = bg_color.blue * 65535; + theme_color.red = bg_color.red * 1; + theme_color.green = bg_color.green * 1; + theme_color.blue = bg_color.blue * 1; color = &theme_color; } diff --git a/src/image.h b/src/image.h index 9614d45e0..99192fc43 100644 --- a/src/image.h +++ b/src/image.h @@ -230,7 +230,7 @@ void image_auto_refresh_enable(ImageWindow *imd, gboolean enable); void image_top_window_set_sync(ImageWindow *imd, gboolean allow_sync); /* background of image */ -void image_background_set_color(ImageWindow *imd, GdkColor *color); +void image_background_set_color(ImageWindow *imd, GdkRGBA *color); void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscreen); /* color profiles */ diff --git a/src/main.cc b/src/main.cc index e711ed408..7e9bd42aa 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1217,7 +1217,7 @@ static void setup_sig_handler() static void set_theme_bg_color() { GdkRGBA bg_color; - GdkColor theme_color; + GdkRGBA theme_color; GtkStyleContext *style_context; GList *work; LayoutWindow *lw; @@ -1230,9 +1230,9 @@ static void set_theme_bg_color() style_context = gtk_widget_get_style_context(lw->window); gtk_style_context_get_background_color(style_context, GTK_STATE_FLAG_NORMAL, &bg_color); - theme_color.red = bg_color.red * 65535; - theme_color.green = bg_color.green * 65535; - theme_color.blue = bg_color.blue * 65535; + theme_color.red = bg_color.red ; + theme_color.green = bg_color.green ; + theme_color.blue = bg_color.blue ; while (work) { diff --git a/src/misc.cc b/src/misc.cc index 79de86673..838ea4e5c 100644 --- a/src/misc.cc +++ b/src/misc.cc @@ -378,6 +378,23 @@ gint get_cpu_cores() return sysconf(_SC_NPROCESSORS_ONLN); } +#ifdef HAVE_GTK4 +void convert_gdkcolor_to_gdkrgba(gpointer data, GdkRGBA *gdk_rgba) +{ +/* @FIXME GTK4 stub */ +} +#else +void convert_gdkcolor_to_gdkrgba(gpointer data, GdkRGBA *gdk_rgba) +{ + auto gdk_color = static_cast(data); + + gdk_rgba->red = CLAMP((double)gdk_color->red / 65535.0, 0.0, 1.0); + gdk_rgba->green = CLAMP((double)gdk_color->green / 65535.0, 0.0, 1.0); + gdk_rgba->blue = CLAMP((double)gdk_color->blue / 65535.0, 0.0, 1.0); + gdk_rgba->alpha = 1.0; +} +#endif + /* Copied from the libarchive .repo. examples */ #ifndef HAVE_ARCHIVE diff --git a/src/misc.h b/src/misc.h index 8b11ecf18..1a21d02ab 100644 --- a/src/misc.h +++ b/src/misc.h @@ -34,6 +34,13 @@ gchar *date_get_abbreviated_day_name(gint day); gchar *convert_rating_to_stars(gint rating); gchar *get_symbolic_link(const gchar *path_utf8); gint get_cpu_cores(); + +#ifdef HAVE_GTK4 +void convert_gdkcolor_to_gdkrgba(gpointer gdk_color, GdkRGBA *gdk_rgba); +#else +void convert_gdkcolor_to_gdkrgba(gpointer gdk_color, GdkRGBA *gdk_rgba); +#endif + gchar *open_archive(FileData *fd); #endif /* MISC_H */ /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ diff --git a/src/options.cc b/src/options.cc index 02d0e23a2..a744f4277 100644 --- a/src/options.cc +++ b/src/options.cc @@ -92,13 +92,16 @@ ConfOptions *init_options(ConfOptions *options) memset(&options->image.border_color, 0, sizeof(options->image.border_color)); memset(&options->image.alpha_color_1, 0, sizeof(options->image.alpha_color_1)); memset(&options->image.alpha_color_2, 0, sizeof(options->image.alpha_color_2)); + options->image.border_color.red = static_cast(0x009999) / 65535; + options->image.border_color.green = static_cast(0x009999) / 65535; + options->image.border_color.blue = static_cast(0x009999) / 65535; /* alpha channel checkerboard background (same as gimp) */ - options->image.alpha_color_1.red = 0x009999; - options->image.alpha_color_1.green = 0x009999; - options->image.alpha_color_1.blue = 0x009999; - options->image.alpha_color_2.red = 0x006666; - options->image.alpha_color_2.green = 0x006666; - options->image.alpha_color_2.blue = 0x006666; + options->image.alpha_color_1.red = static_cast(0x009999) / 65535; + options->image.alpha_color_1.green = static_cast(0x009999) / 65535; + options->image.alpha_color_1.blue = static_cast(0x009999) / 65535; + options->image.alpha_color_2.red = static_cast(0x006666) / 65535; + options->image.alpha_color_2.green = static_cast(0x006666) / 65535; + options->image.alpha_color_2.blue = static_cast(0x006666) / 65535; options->image.enable_read_ahead = TRUE; options->image.exif_rotate_enable = TRUE; options->image.fit_window_to_image = FALSE; diff --git a/src/options.h b/src/options.h index 35c9134d2..4d1a9404a 100644 --- a/src/options.h +++ b/src/options.h @@ -177,9 +177,9 @@ struct ConfOptions gboolean use_custom_border_color_in_fullscreen; gboolean use_custom_border_color; - GdkColor border_color; - GdkColor alpha_color_1; - GdkColor alpha_color_2; + GdkRGBA border_color; + GdkRGBA alpha_color_1; + GdkRGBA alpha_color_2; gint tile_size; } image; diff --git a/src/pixbuf-renderer.cc b/src/pixbuf-renderer.cc index 05dc4341f..b6716e158 100644 --- a/src/pixbuf-renderer.cc +++ b/src/pixbuf-renderer.cc @@ -918,7 +918,7 @@ static void pr_scroller_stop(PixbufRenderer *pr) *------------------------------------------------------------------- */ -void pixbuf_renderer_set_color(PixbufRenderer *pr, GdkColor *color) +void pixbuf_renderer_set_color(PixbufRenderer *pr, GdkRGBA *color) { g_return_if_fail(IS_PIXBUF_RENDERER(pr)); diff --git a/src/pixbuf-renderer.h b/src/pixbuf-renderer.h index 9d62a5fea..0d548a171 100644 --- a/src/pixbuf-renderer.h +++ b/src/pixbuf-renderer.h @@ -172,7 +172,7 @@ struct PixbufRenderer gint autofit_limit_size; gint enlargement_limit_size; - GdkColor color; + GdkRGBA color; /*< private >*/ gboolean in_drag; @@ -335,7 +335,7 @@ gboolean pixbuf_renderer_get_visible_rect(PixbufRenderer *pr, GdkRectangle *rect * @headerfile pixbuf_renderer_set_color * background color */ -void pixbuf_renderer_set_color(PixbufRenderer *pr, GdkColor *color); +void pixbuf_renderer_set_color(PixbufRenderer *pr, GdkRGBA *color); /* overlay */ diff --git a/src/preferences.cc b/src/preferences.cc index 60673e361..ef0b38d82 100644 --- a/src/preferences.cc +++ b/src/preferences.cc @@ -352,7 +352,7 @@ static void config_window_apply() if (options->image.use_custom_border_color != c_options->image.use_custom_border_color || options->image.use_custom_border_color_in_fullscreen != c_options->image.use_custom_border_color_in_fullscreen - || !gdk_color_equal(&options->image.border_color, &c_options->image.border_color)) + || !gdk_rgba_equal(&options->image.border_color, &c_options->image.border_color)) { options->image.use_custom_border_color_in_fullscreen = c_options->image.use_custom_border_color_in_fullscreen; options->image.use_custom_border_color = c_options->image.use_custom_border_color; @@ -1564,7 +1564,6 @@ static void bg_color_response_cb(GtkDialog *dialog, gint response_id, gpointer) c_options->image_overlay.background_blue = color.blue * 255; c_options->image_overlay.background_alpha = color.alpha * 255; } - gtk_widget_destroy(GTK_WIDGET(dialog)); } diff --git a/src/print.cc b/src/print.cc index 3cb2f3a07..c200afe4b 100644 --- a/src/print.cc +++ b/src/print.cc @@ -119,7 +119,8 @@ static gboolean print_job_render_image(PrintWindow *pw) return TRUE; } - +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-but-set-parameter" static void font_activated_cb(GtkFontChooser *widget, gchar *fontname, gpointer option) { option = g_strdup(fontname); @@ -128,6 +129,7 @@ static void font_activated_cb(GtkFontChooser *widget, gchar *fontname, gpointer gtk_widget_destroy(GTK_WIDGET(widget)); } +#pragma GCC diagnostic pop static void font_response_cb(GtkDialog *dialog, int response_id, gpointer option) { diff --git a/src/rcfile.cc b/src/rcfile.cc index a11d98388..f1cf6d1ea 100644 --- a/src/rcfile.cc +++ b/src/rcfile.cc @@ -99,18 +99,11 @@ gboolean read_char_option(const gchar *option, const gchar *label, const gchar * return TRUE; } -/* Since gdk_color_to_string() is only available since gtk 2.12 - * here is an equivalent stub function. */ -static gchar *color_to_string(GdkColor *color) -{ - return g_strdup_printf("#%04X%04X%04X", color->red, color->green, color->blue); -} - -void write_color_option(GString *str, gint indent, const gchar *label, GdkColor *color) +void write_color_option(GString *str, gint indent, const gchar *label, GdkRGBA *color) { if (color) { - gchar *colorstring = color_to_string(color); + gchar *colorstring = gdk_rgba_to_string(color); write_char_option(str, indent, label, colorstring); g_free(colorstring); @@ -119,13 +112,41 @@ void write_color_option(GString *str, gint indent, const gchar *label, GdkColor write_char_option(str, indent, label, ""); } -gboolean read_color_option(const gchar *option, const gchar *label, const gchar *value, GdkColor *color) +/** + * @brief Read color option + * @param option + * @param label + * @param value + * @param color Returned RGBA value + * @returns + * + * The change from GdkColor to GdkRGBA requires a color format change. + * If the value string starts with #, it is a value stored as GdkColor, + * which is "#666666666666". + * The GdkRGBA style is "rgba(192,97,203,0)" + */ +gboolean read_color_option(const gchar *option, const gchar *label, const gchar *value, GdkRGBA *color) { + guint64 color_from_hex_string; + if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!color) return FALSE; if (!*value) return FALSE; - gdk_color_parse(value, color); + + /* Convert from GTK3 compatible GdkColor to GTK4 compatible GdkRGBA */ + if (g_str_has_prefix(value, "#")) + { + color_from_hex_string = g_ascii_strtoll(value + 1, nullptr, 16); + color->red = (gdouble)((color_from_hex_string & 0xffff00000000) >> 32) / 65535; + color->green = (gdouble)((color_from_hex_string & 0x0000ffff0000) >> 16) / 65535; + color->blue = (gdouble)(color_from_hex_string & 0x00000000ffff) / 65535; + } + else + { + gdk_rgba_parse(color, value); + } + return TRUE; } diff --git a/src/rcfile.h b/src/rcfile.h index be39f747a..dad3ec860 100644 --- a/src/rcfile.h +++ b/src/rcfile.h @@ -28,8 +28,8 @@ void write_indent(GString *str, gint indent); void write_char_option(GString *str, gint indent, const gchar *label, const gchar *text); gboolean read_dummy_option(const gchar *option, const gchar *label, const gchar *message); gboolean read_char_option(const gchar *option, const gchar *label, const gchar *value, gchar **text); -void write_color_option(GString *str, gint indent, const gchar *label, GdkColor *color); -gboolean read_color_option(const gchar *option, const gchar *label, const gchar *value, GdkColor *color); +void write_color_option(GString *str, gint indent, const gchar *label, GdkRGBA *color); +gboolean read_color_option(const gchar *option, const gchar *label, const gchar *value, GdkRGBA *color); void write_int_option(GString *str, gint indent, const gchar *label, gint n); gboolean read_int_option(const gchar *option, const gchar *label, const gchar *value, gint *n); gboolean read_ushort_option(const gchar *option, const gchar *label, const gchar *value, guint16 *n); diff --git a/src/renderer-tiles.cc b/src/renderer-tiles.cc index a3b83a840..dfe4b7f65 100644 --- a/src/renderer-tiles.cc +++ b/src/renderer-tiles.cc @@ -204,7 +204,7 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h) pr->viewport_width, pr->viewport_height, &rx, &ry, &rw, &rh)) { - cairo_set_source_rgb(cr, static_cast(pr->color.red)/65535, static_cast(pr->color.green)/65535, static_cast(pr->color.blue)/65535); + cairo_set_source_rgb(cr, static_cast(pr->color.red), static_cast(pr->color.green), static_cast(pr->color.blue)); cairo_rectangle(cr, rx + rt->stereo_off_x, ry + rt->stereo_off_y, rw, rh); cairo_fill(cr); rt_overlay_draw(rt, rx, ry, rw, rh, nullptr); @@ -221,7 +221,7 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h) pr->x_offset, pr->viewport_height, &rx, &ry, &rw, &rh)) { - cairo_set_source_rgb(cr, static_cast(pr->color.red)/65535, static_cast(pr->color.green)/65535, static_cast(pr->color.blue)/65535); + cairo_set_source_rgb(cr, static_cast(pr->color.red), static_cast(pr->color.green), static_cast(pr->color.blue)); cairo_rectangle(cr, rx + rt->stereo_off_x, ry + rt->stereo_off_y, rw, rh); cairo_fill(cr); rt_overlay_draw(rt, rx, ry, rw, rh, nullptr); @@ -232,7 +232,7 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h) pr->viewport_width - pr->vis_width - pr->x_offset, pr->viewport_height, &rx, &ry, &rw, &rh)) { - cairo_set_source_rgb(cr, static_cast(pr->color.red)/65535, static_cast(pr->color.green)/65535, static_cast(pr->color.blue)/65535); + cairo_set_source_rgb(cr, static_cast(pr->color.red), static_cast(pr->color.green), static_cast(pr->color.blue)); cairo_rectangle(cr, rx + rt->stereo_off_x, ry + rt->stereo_off_y, rw, rh); cairo_fill(cr); rt_overlay_draw(rt, rx, ry, rw, rh, nullptr); @@ -246,7 +246,7 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h) pr->vis_width, pr->y_offset, &rx, &ry, &rw, &rh)) { - cairo_set_source_rgb(cr, static_cast(pr->color.red)/65535, static_cast(pr->color.green)/65535, static_cast(pr->color.blue)/65535); + cairo_set_source_rgb(cr, static_cast(pr->color.red), static_cast(pr->color.green), static_cast(pr->color.blue)); cairo_rectangle(cr, rx + rt->stereo_off_x, ry + rt->stereo_off_y, rw, rh); cairo_fill(cr); rt_overlay_draw(rt, rx, ry, rw, rh, nullptr); @@ -257,7 +257,7 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h) pr->vis_width, pr->viewport_height - pr->vis_height - pr->y_offset, &rx, &ry, &rw, &rh)) { - cairo_set_source_rgb(cr, static_cast(pr->color.red)/65535, static_cast(pr->color.green)/65535, static_cast(pr->color.blue)/65535); + cairo_set_source_rgb(cr, static_cast(pr->color.red), static_cast(pr->color.green), static_cast(pr->color.blue)); cairo_rectangle(cr, rx + rt->stereo_off_x, ry + rt->stereo_off_y, rw, rh); cairo_fill(cr); rt_overlay_draw(rt, rx, ry, rw, rh, nullptr); @@ -1239,6 +1239,14 @@ static void rt_tile_get_region(gboolean has_alpha, gboolean ignore_alpha, gint c; guchar *psrc; guchar *pdst; + guint32 red_1; + guint32 green_1; + guint32 blue_1; + guint32 red_2; + guint32 green_2; + guint32 blue_2; + guint32 alpha_1; + guint32 alpha_2; if (!has_alpha) { @@ -1282,6 +1290,15 @@ static void rt_tile_get_region(gboolean has_alpha, gboolean ignore_alpha, } else { + red_1=static_cast(options->image.alpha_color_1.red * 255) << 16 & 0x00FF0000; + green_1=static_cast(options->image.alpha_color_1.green * 255) << 8 & 0x0000FF00; + blue_1=static_cast(options->image.alpha_color_1.blue * 255) & 0x000000FF; + red_2=static_cast(options->image.alpha_color_2.red * 255) << 16 & 0x00FF0000; + green_2=static_cast(options->image.alpha_color_2.green * 255) << 8 & 0x0000FF00; + blue_2=static_cast(options->image.alpha_color_2.blue * 255) & 0x000000FF; + alpha_1 = red_1 + green_1 + blue_1; + alpha_2 = red_2 + green_2 + blue_2; + if (ignore_alpha) { tmppixbuf = gdk_pixbuf_add_alpha(src, FALSE, 0, 0, 0); @@ -1296,12 +1313,8 @@ static void rt_tile_get_region(gboolean has_alpha, gboolean ignore_alpha, (scale_x == 1.0 && scale_y == 1.0) ? GDK_INTERP_NEAREST : interp_type, 255, check_x, check_y, PR_ALPHA_CHECK_SIZE, - ((options->image.alpha_color_1.red << 8 & 0x00FF0000) + - (options->image.alpha_color_1.green & 0x00FF00) + - (options->image.alpha_color_1.blue >> 8 & 0x00FF)), - ((options->image.alpha_color_2.red << 8 & 0x00FF0000) + - (options->image.alpha_color_2.green & 0x00FF00) + - (options->image.alpha_color_2.blue >> 8 & 0x00FF))); + alpha_1, + alpha_2); g_object_unref(tmppixbuf); } else @@ -1314,12 +1327,8 @@ static void rt_tile_get_region(gboolean has_alpha, gboolean ignore_alpha, (scale_x == 1.0 && scale_y == 1.0) ? GDK_INTERP_NEAREST : interp_type, 255, check_x, check_y, PR_ALPHA_CHECK_SIZE, - ((options->image.alpha_color_1.red << 8 & 0x00FF0000) + - (options->image.alpha_color_1.green & 0x00FF00) + - (options->image.alpha_color_1.blue >> 8 & 0x00FF)), - ((options->image.alpha_color_2.red << 8 & 0x00FF0000) + - (options->image.alpha_color_2.green & 0x00FF00) + - (options->image.alpha_color_2.blue >> 8 & 0x00FF))); + alpha_1, + alpha_2); } } } @@ -2125,7 +2134,7 @@ static gboolean rt_realize_cb(GtkWidget *widget, gpointer data) rt->surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR, gtk_widget_get_allocated_width(widget), gtk_widget_get_allocated_height(widget)); cr = cairo_create(rt->surface); - cairo_set_source_rgb(cr, static_cast(rt->pr->color.red) / 65535, static_cast(rt->pr->color.green) / 65535, static_cast(rt->pr->color.blue) / 65535); + cairo_set_source_rgb(cr, static_cast(rt->pr->color.red), static_cast(rt->pr->color.green), static_cast(rt->pr->color.blue)); cairo_paint(cr); cairo_destroy(cr); } @@ -2146,7 +2155,7 @@ static gboolean rt_size_allocate_cb(GtkWidget *widget, GdkRectangle *allocation cr = cairo_create(rt->surface); - cairo_set_source_rgb(cr, static_cast(options->image.border_color.red) / 65535, static_cast(options->image.border_color.green) / 65535, static_cast(options->image.border_color.blue) / 65535); + cairo_set_source_rgb(cr, static_cast(options->image.border_color.red), static_cast(options->image.border_color.green), static_cast(options->image.border_color.blue)); cairo_paint(cr); cairo_set_source_surface(cr, old_surface, 0, 0); cairo_paint(cr); @@ -2168,7 +2177,7 @@ static gboolean rt_draw_cb(GtkWidget *, cairo_t *cr, gpointer data) if (rt->stereo_mode & (PR_STEREO_HORIZ | PR_STEREO_VERT)) { cairo_push_group(cr); - cairo_set_source_rgb(cr, static_cast(rt->pr->color.red) / 65535, static_cast(rt->pr->color.green) / 65535, static_cast(rt->pr->color.blue) / 65535); + cairo_set_source_rgb(cr, static_cast(rt->pr->color.red), static_cast(rt->pr->color.green), static_cast(rt->pr->color.blue)); if (rt->stereo_mode & PR_STEREO_HORIZ) { diff --git a/src/ui-misc.cc b/src/ui-misc.cc index ef3644fd1..98f4d79d1 100644 --- a/src/ui-misc.cc +++ b/src/ui-misc.cc @@ -1312,20 +1312,18 @@ gboolean pref_list_string_get_unused(const gchar *group, const gchar *key, const void pref_color_button_set_cb(GtkWidget *widget, gpointer data) { - auto color = static_cast(data); + auto color = static_cast(data); - gtk_color_button_get_color(GTK_COLOR_BUTTON(widget), color); + gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), color); } -GtkWidget *pref_color_button_new(GtkWidget *parent_box, - const gchar *title, const GdkColor *color, - GCallback func, gpointer data) +GtkWidget *pref_color_button_new(GtkWidget *parent_box, const gchar *title, GdkRGBA *color, GCallback func, gpointer data) { GtkWidget *button; if (color) { - button = gtk_color_button_new_with_color(color); + button = gtk_color_button_new_with_rgba(color); } else { diff --git a/src/ui-misc.h b/src/ui-misc.h index ff67e6779..a953091ee 100644 --- a/src/ui-misc.h +++ b/src/ui-misc.h @@ -222,7 +222,7 @@ gboolean pref_list_string_get(const gchar *group, const gchar *key, const gchar void pref_color_button_set_cb(GtkWidget *widget, gpointer data); GtkWidget *pref_color_button_new(GtkWidget *parent_box, - const gchar *title, const GdkColor *color, + const gchar *title, GdkRGBA *color, GCallback func, gpointer data); gchar *text_widget_text_pull(GtkWidget *text_widget); diff --git a/src/ui-tree-edit.cc b/src/ui-tree-edit.cc index 79990502c..319eaa421 100644 --- a/src/ui-tree-edit.cc +++ b/src/ui-tree-edit.cc @@ -481,9 +481,9 @@ gint tree_path_to_row_unused(GtkTreePath *tpath) *------------------------------------------------------------------- */ -void shift_color(GdkColor *src, gshort val, gint direction) +void shift_color(GdkRGBA *src, gshort val, gint direction) { - gshort cs; + gdouble cs; if (val == -1) { @@ -493,11 +493,11 @@ void shift_color(GdkColor *src, gshort val, gint direction) { val = CLAMP(val, 1, 100); } - cs = 0xffff / 100 * val; + + cs = 1.0 / 100 * val; /* up or down ? */ - if (direction < 0 || - (direction == 0 &&(static_cast(src->red) + static_cast(src->green) + static_cast(src->blue)) / 3 > 0xffff / 2)) + if (direction < 0 || (direction == 0 &&(static_cast(src->red) + static_cast(src->green) + static_cast(src->blue)) / 3 > 1.0 / 2)) { src->red = MAX(0 , src->red - cs); src->green = MAX(0 , src->green - cs); @@ -505,26 +505,12 @@ void shift_color(GdkColor *src, gshort val, gint direction) } else { - src->red = MIN(0xffff, src->red + cs); - src->green = MIN(0xffff, src->green + cs); - src->blue = MIN(0xffff, src->blue + cs); + src->red = MIN(1.0, src->red + cs); + src->green = MIN(1.0, src->green + cs); + src->blue = MIN(1.0, src->blue + cs); } } -/* darkens or lightens a style's color for given state - * esp. useful for alternating dark/light in (c)lists - */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-function" -void style_shift_color_unused(GtkStyle *style, GtkStateType type, gshort shift_value, gint direction) -{ - if (!style) return; - - shift_color(&style->base[type], shift_value, direction); - shift_color(&style->bg[type], shift_value, direction); -} -#pragma GCC diagnostic pop - /* *------------------------------------------------------------------- * auto scroll by mouse position diff --git a/src/ui-tree-edit.h b/src/ui-tree-edit.h index 20e52eb77..ebfabec3f 100644 --- a/src/ui-tree-edit.h +++ b/src/ui-tree-edit.h @@ -85,11 +85,11 @@ gboolean tree_view_move_cursor_away(GtkTreeView *widget, GtkTreeIter *iter, gboo /** * @headerfile shift_color - * shifts a GdkColor values lighter or darker \n + * shifts a GdkRGBA values lighter or darker \n * val is percent from 1 to 100, or -1 for default (usually 10%) \n * direction is -1 darker, 0 auto, 1 lighter */ -void shift_color(GdkColor *src, gshort val, gint direction); +void shift_color(GdkRGBA *src, gshort val, gint direction); /** * @def STYLE_SHIFT_STANDARD diff --git a/src/view-dir.cc b/src/view-dir.cc index 3899092fa..6ab6aa40e 100644 --- a/src/view-dir.cc +++ b/src/view-dir.cc @@ -1198,20 +1198,28 @@ void vd_activate_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *, vd_select_row(vd, fd); } -static GdkColor *vd_color_shifted(GtkWidget *widget) +static GdkRGBA *vd_color_shifted(GtkWidget *widget) { - static GdkColor color; + static GdkRGBA color; + static GdkRGBA color_style; static GtkWidget *done = nullptr; +#ifdef HAVE_GTK4 +/* @FIXME GTK4 no background color */ +#else if (done != widget) { - GtkStyle *style; + GtkStyleContext *style_context; + + style_context = gtk_widget_get_style_context(widget); + gtk_style_context_get_background_color(style_context, GTK_STATE_FLAG_NORMAL, &color_style); + + memcpy(&color, &color_style, sizeof(color_style)); - style = gtk_widget_get_style(widget); - memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); shift_color(&color, -1, 0); done = widget; } +#endif return &color; } diff --git a/src/view-file/view-file-icon.cc b/src/view-file/view-file-icon.cc index 91e7832a3..78ad98d57 100644 --- a/src/view-file/view-file-icon.cc +++ b/src/view-file/view-file-icon.cc @@ -2057,11 +2057,11 @@ struct ColumnData static void vficon_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) { - GList *list; - FileData *fd; auto cd = static_cast(data); - ViewFile *vf = cd->vf; + FileData *fd; gchar *star_rating; + GList *list; + ViewFile *vf = cd->vf; if (!GQV_IS_CELL_RENDERER_ICON(cell)) return; @@ -2071,12 +2071,14 @@ static void vficon_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer *cell, if (fd) { - GdkColor color_fg; - GdkColor color_bg; - GtkStyle *style; - gchar *name_sidecars = nullptr; const gchar *link; + gchar *name_sidecars = nullptr; + GdkRGBA color_bg; + GdkRGBA color_fg; + GdkRGBA color_bg_style; + GdkRGBA color_fg_style; GtkStateType state = GTK_STATE_NORMAL; + GtkStyle *style; g_assert(fd->magick == FD_MAGICK); @@ -2131,19 +2133,22 @@ static void vficon_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer *cell, state = GTK_STATE_SELECTED; } - memcpy(&color_fg, &style->text[state], sizeof(color_fg)); - memcpy(&color_bg, &style->base[state], sizeof(color_bg)); + convert_gdkcolor_to_gdkrgba(&style->text[state], &color_fg_style); + convert_gdkcolor_to_gdkrgba(&style->base[state], &color_bg_style); + + memcpy(&color_fg, &color_fg_style, sizeof(color_fg)); + memcpy(&color_bg, &color_bg_style, sizeof(color_bg)); if (fd->selected & SELECTION_PRELIGHT) { shift_color(&color_bg, -1, 0); } - g_object_set(cell, "pixbuf", fd->thumb_pixbuf, + g_object_set(cell, "pixbuf", fd->thumb_pixbuf, "text", name_sidecars, "marks", file_data_get_marks(fd), "show_marks", vf->marks_enabled, - "cell-background-gdk", &color_bg, + "cell-background-rgba", &color_bg, "cell-background-set", TRUE, "foreground-gdk", &color_fg, "foreground-set", TRUE, diff --git a/src/view-file/view-file-list.cc b/src/view-file/view-file-list.cc index b036462a3..7e0fee476 100644 --- a/src/view-file/view-file-list.cc +++ b/src/view-file/view-file-list.cc @@ -1952,9 +1952,10 @@ static void cell_renderer_height_override(GtkCellRenderer *renderer) } } -static GdkColor *vflist_listview_color_shifted(GtkWidget *widget) +static GdkRGBA *vflist_listview_color_shifted(GtkWidget *widget) { - static GdkColor color; + static GdkRGBA color; + static GdkRGBA color_style; static GtkWidget *done = nullptr; if (done != widget) @@ -1962,7 +1963,9 @@ static GdkColor *vflist_listview_color_shifted(GtkWidget *widget) GtkStyle *style; style = gtk_widget_get_style(widget); - memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); + convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_NORMAL], &color_style); + + memcpy(&color, &color_style, sizeof(color)); shift_color(&color, -1, 0); done = widget; }