From 9bfe19fd4bcd37aed5f7e88743b00496658914a1 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 4 Sep 2022 08:25:08 +0300 Subject: [PATCH 64/64] gtk4: Turn left panel indicator icons to GtkPictures See osdn #45568 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/gui_main.c | 18 +++++++++--------- client/gui-gtk-4.0/mapview.c | 14 +++++++------- client/gui-gtk-4.0/sprite.c | 21 +++++++++++++++++++++ client/gui-gtk-4.0/sprite.h | 4 ++++ 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index 45864b39e3..1fe768558b 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -1299,7 +1299,7 @@ static void setup_widgets(void) GtkEventController *controller; spr = i < 5 ? get_tax_sprite(tileset, O_SCIENCE) : get_tax_sprite(tileset, O_GOLD); - econ_label[i] = image_new_from_surface(spr->surface); + econ_label[i] = picture_new_from_surface(spr->surface); g_object_set_data(G_OBJECT(econ_label[i]), "rate_button", GUINT_TO_POINTER(i)); controller = GTK_EVENT_CONTROLLER(gtk_gesture_click_new()); @@ -1312,30 +1312,30 @@ static void setup_widgets(void) /* science, environmental, govt, timeout */ spr = client_research_sprite(); if (spr != NULL) { - bulb_label = image_new_from_surface(spr->surface); + bulb_label = picture_new_from_surface(spr->surface); } else { - bulb_label = gtk_image_new(); + bulb_label = gtk_picture_new(); } spr = client_warming_sprite(); if (spr != NULL) { - sun_label = image_new_from_surface(spr->surface); + sun_label = picture_new_from_surface(spr->surface); } else { - sun_label = gtk_image_new(); + sun_label = gtk_picture_new(); } spr = client_cooling_sprite(); if (spr != NULL) { - flake_label = image_new_from_surface(spr->surface); + flake_label = picture_new_from_surface(spr->surface); } else { - flake_label = gtk_image_new(); + flake_label = gtk_picture_new(); } spr = client_government_sprite(); if (spr != NULL) { - government_label = image_new_from_surface(spr->surface); + government_label = picture_new_from_surface(spr->surface); } else { - government_label = gtk_image_new(); + government_label = gtk_picture_new(); } for (i = 0; i < 4; i++) { diff --git a/client/gui-gtk-4.0/mapview.c b/client/gui-gtk-4.0/mapview.c index 00f7fe4104..0cd6d37378 100644 --- a/client/gui-gtk-4.0/mapview.c +++ b/client/gui-gtk-4.0/mapview.c @@ -181,20 +181,20 @@ void update_info_label(void) for (; d < client.conn.playing->economic.luxury /10; d++) { struct sprite *spr = get_tax_sprite(tileset, O_LUXURY); - image_set_from_surface(GTK_IMAGE(econ_label[d]), spr->surface); + picture_set_from_surface(GTK_PICTURE(econ_label[d]), spr->surface); } for (; d < (client.conn.playing->economic.science + client.conn.playing->economic.luxury) / 10; d++) { struct sprite *spr = get_tax_sprite(tileset, O_SCIENCE); - image_set_from_surface(GTK_IMAGE(econ_label[d]), spr->surface); + picture_set_from_surface(GTK_PICTURE(econ_label[d]), spr->surface); } for (; d < 10; d++) { struct sprite *spr = get_tax_sprite(tileset, O_GOLD); - image_set_from_surface(GTK_IMAGE(econ_label[d]), spr->surface); + picture_set_from_surface(GTK_PICTURE(econ_label[d]), spr->surface); } } @@ -288,10 +288,10 @@ GdkPixbuf *get_thumb_pixbuf(int onoff) void set_indicator_icons(struct sprite *bulb, struct sprite *sol, struct sprite *flake, struct sprite *gov) { - image_set_from_surface(GTK_IMAGE(bulb_label), bulb->surface); - image_set_from_surface(GTK_IMAGE(sun_label), sol->surface); - image_set_from_surface(GTK_IMAGE(flake_label), flake->surface); - image_set_from_surface(GTK_IMAGE(government_label), gov->surface); + picture_set_from_surface(GTK_PICTURE(bulb_label), bulb->surface); + picture_set_from_surface(GTK_PICTURE(sun_label), sol->surface); + picture_set_from_surface(GTK_PICTURE(flake_label), flake->surface); + picture_set_from_surface(GTK_PICTURE(government_label), gov->surface); } /**********************************************************************//** diff --git a/client/gui-gtk-4.0/sprite.c b/client/gui-gtk-4.0/sprite.c index 482cb1ac7f..18d5641594 100644 --- a/client/gui-gtk-4.0/sprite.c +++ b/client/gui-gtk-4.0/sprite.c @@ -511,6 +511,8 @@ GdkPixbuf *create_extra_pixbuf(const struct extra_type *pextra) return pixbuf; } +/* TODO: Remove as unused */ +#if 0 /************************************************************************//** Create a GtkImage from cairo surface. ****************************************************************************/ @@ -543,6 +545,25 @@ void image_set_from_surface(GtkImage *image, cairo_surface_t *surf) gtk_image_set_from_pixbuf(image, pb); g_object_unref(pb); } +#endif /* Unused GtkImage stuff */ + +/************************************************************************//** + Create a GtkPicture from cairo surface. +****************************************************************************/ +GtkWidget *picture_new_from_surface(cairo_surface_t *surf) +{ + GdkPixbuf *pb; + GtkWidget *pic; + + pb = surface_get_pixbuf(surf, + cairo_image_surface_get_width(surf), + cairo_image_surface_get_height(surf)); + + pic = gtk_picture_new_for_pixbuf(pb); + g_object_unref(pb); + + return pic; +} /************************************************************************//** Set a GtkPicture from cairo surface. diff --git a/client/gui-gtk-4.0/sprite.h b/client/gui-gtk-4.0/sprite.h index a0084a64cc..78eb30063d 100644 --- a/client/gui-gtk-4.0/sprite.h +++ b/client/gui-gtk-4.0/sprite.h @@ -36,9 +36,13 @@ GdkPixbuf *surface_get_pixbuf(cairo_surface_t *surf, int width, int height); GdkPixbuf *create_extra_pixbuf(const struct extra_type *pextra); +/* TODO: Remove as unused */ +#if 0 GtkWidget *image_new_from_surface(cairo_surface_t *surf); void image_set_from_surface(GtkImage *image, cairo_surface_t *surf); +#endif +GtkWidget *picture_new_from_surface(cairo_surface_t *surf); void picture_set_from_surface(GtkPicture *image, cairo_surface_t *surf); #endif /* FC__SPRITE_H */ -- 2.35.1