From 41323926c01839679a23e44fd3424c1a5f11b3fe Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 15 May 2021 12:16:34 +0300 Subject: [PATCH 23/23] gtk3: Use proper overlays for units in citydlg present units area See osdn #42284 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/citydlg.c | 2 +- client/gui-gtk-3.0/gui_main.c | 2 +- client/gui-gtk-3.0/mapview.c | 22 ++++++++++++++++++---- client/gui-gtk-3.0/mapview.h | 2 +- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/client/gui-gtk-3.0/citydlg.c b/client/gui-gtk-3.0/citydlg.c index d4035cbac9..655c61b91f 100644 --- a/client/gui-gtk-3.0/citydlg.c +++ b/client/gui-gtk-3.0/citydlg.c @@ -2260,7 +2260,7 @@ static void city_dialog_update_present_units(struct city_dialog *pdialog) cmd = pnode->cmd; pix = pnode->pix; - put_unit_image(punit, GTK_IMAGE(pix)); + put_unit_image(punit, GTK_IMAGE(pix), pnode->height); g_signal_handlers_disconnect_matched(cmd, G_SIGNAL_MATCH_FUNC, diff --git a/client/gui-gtk-3.0/gui_main.c b/client/gui-gtk-3.0/gui_main.c index 50f800436b..ec31ede8cb 100644 --- a/client/gui-gtk-3.0/gui_main.c +++ b/client/gui-gtk-3.0/gui_main.c @@ -1913,7 +1913,7 @@ void set_unit_icon(int idx, struct unit *punit) } if (punit) { - put_unit_image(punit, GTK_IMAGE(w)); + put_unit_image(punit, GTK_IMAGE(w), -1); } else { gtk_image_clear(GTK_IMAGE(w)); } diff --git a/client/gui-gtk-3.0/mapview.c b/client/gui-gtk-3.0/mapview.c index 81a63a22fd..e00b4cf4a9 100644 --- a/client/gui-gtk-3.0/mapview.c +++ b/client/gui-gtk-3.0/mapview.c @@ -486,16 +486,30 @@ void update_city_descriptions(void) /************************************************************************** Fill image with unit gfx **************************************************************************/ -void put_unit_image(struct unit *punit, GtkImage *p) +void put_unit_image(struct unit *punit, GtkImage *p, int height) { GdkPixbuf *pixbuf; - struct sprite *spr; + struct canvas store = FC_STATIC_CANVAS_INIT; + int width; + + if (height <= 0) { + struct sprite *spr; + + spr = get_unittype_sprite(tileset, unit_type_get(punit), punit->facing, FALSE); + get_sprite_dimensions(spr, &width, &height); + } else { + width = tileset_full_tile_width(tileset); + } - spr = get_unittype_sprite(tileset, unit_type_get(punit), punit->facing, FALSE); - pixbuf = sprite_get_pixbuf(spr); + store.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + width, height); + put_unit(punit, &store, 1.0, 0, 0); + + pixbuf = surface_get_pixbuf(store.surface, width, height); gtk_image_set_from_pixbuf(p, pixbuf); g_object_unref(pixbuf); + cairo_surface_destroy(store.surface); } /************************************************************************** diff --git a/client/gui-gtk-3.0/mapview.h b/client/gui-gtk-3.0/mapview.h index 5968c47981..503cda3137 100644 --- a/client/gui-gtk-3.0/mapview.h +++ b/client/gui-gtk-3.0/mapview.h @@ -36,7 +36,7 @@ gboolean map_canvas_draw(GtkWidget *w, cairo_t *cr, gpointer data); gboolean map_canvas_configure(GtkWidget *w, GdkEventConfigure *ev, gpointer data); -void put_unit_image(struct unit *punit, GtkImage *p); +void put_unit_image(struct unit *punit, GtkImage *p, int height); void put_unit_image_city_overlays(struct unit *punit, GtkImage *p, int height, int *upkeep_cost, int happy_cost); -- 2.30.2