From 08260f05a7fac0e59f7b3c98715e7250e616239e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 21 Apr 2023 21:13:25 +0300 Subject: [PATCH 44/44] gtk: Show extra icon in help browser See osdn #47624 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/helpdlg.c | 30 ++++++++++++++++++++++++++++++ client/gui-gtk-3.22/helpdlg.c | 30 ++++++++++++++++++++++++++++++ client/gui-gtk-4.0/helpdlg.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) diff --git a/client/gui-gtk-3.0/helpdlg.c b/client/gui-gtk-3.0/helpdlg.c index 82cb9c58d8..68af8517a2 100644 --- a/client/gui-gtk-3.0/helpdlg.c +++ b/client/gui-gtk-3.0/helpdlg.c @@ -842,6 +842,34 @@ static void set_help_tile_from_terrain(struct terrain *pterr) cairo_surface_destroy(canvas.surface); } +/**********************************************************************//** + Set sprite to show for current extra. +**************************************************************************/ +static void set_help_tile_from_extra(const struct extra_type *pextra) +{ + struct canvas canvas = FC_STATIC_CANVAS_INIT; + cairo_t *cr; + struct drawn_sprite sprs[80]; + int count; + + canvas.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + tileset_tile_width(tileset), + tileset_tile_height(tileset)); + + cr = cairo_create(canvas.surface); + cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); + cairo_paint(cr); + cairo_destroy(cr); + + count = fill_basic_extra_sprite_array(tileset, sprs, pextra); + + put_drawn_sprites(&canvas, 1.0, 0, 0, count, sprs, FALSE); + + gtk_image_set_from_surface(GTK_IMAGE(help_tile), canvas.surface); + gtk_widget_show(help_tile); + cairo_surface_destroy(canvas.surface); +} + /**********************************************************************//** Display updated help about improvement **************************************************************************/ @@ -1380,6 +1408,8 @@ static void help_update_extra(const struct help_item *pitem, char *title) struct road_type *proad = extra_road_get(pextra); bool is_resource = is_extra_caused_by(pextra, EC_RESOURCE); + set_help_tile_from_extra(pextra); + /* Cost to build */ if (pextra->buildable) { if (pextra->build_time != 0) { diff --git a/client/gui-gtk-3.22/helpdlg.c b/client/gui-gtk-3.22/helpdlg.c index 3169a916ed..4b525ea29f 100644 --- a/client/gui-gtk-3.22/helpdlg.c +++ b/client/gui-gtk-3.22/helpdlg.c @@ -841,6 +841,34 @@ static void set_help_tile_from_terrain(struct terrain *pterr) cairo_surface_destroy(canvas.surface); } +/**********************************************************************//** + Set sprite to show for current extra. +**************************************************************************/ +static void set_help_tile_from_extra(const struct extra_type *pextra) +{ + struct canvas canvas = FC_STATIC_CANVAS_INIT; + cairo_t *cr; + struct drawn_sprite sprs[80]; + int count; + + canvas.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + tileset_tile_width(tileset), + tileset_tile_height(tileset)); + + cr = cairo_create(canvas.surface); + cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); + cairo_paint(cr); + cairo_destroy(cr); + + count = fill_basic_extra_sprite_array(tileset, sprs, pextra); + + put_drawn_sprites(&canvas, 1.0, 0, 0, count, sprs, FALSE); + + gtk_image_set_from_surface(GTK_IMAGE(help_tile), canvas.surface); + gtk_widget_show(help_tile); + cairo_surface_destroy(canvas.surface); +} + /**********************************************************************//** Display updated help about improvement **************************************************************************/ @@ -1380,6 +1408,8 @@ static void help_update_extra(const struct help_item *pitem, char *title) struct road_type *proad = extra_road_get(pextra); bool is_resource = is_extra_caused_by(pextra, EC_RESOURCE); + set_help_tile_from_extra(pextra); + /* Cost to build */ if (pextra->buildable) { if (pextra->build_time != 0) { diff --git a/client/gui-gtk-4.0/helpdlg.c b/client/gui-gtk-4.0/helpdlg.c index 19240c28e9..6b66101cdc 100644 --- a/client/gui-gtk-4.0/helpdlg.c +++ b/client/gui-gtk-4.0/helpdlg.c @@ -866,6 +866,34 @@ static void set_help_tile_from_terrain(struct terrain *pterr) cairo_surface_destroy(canvas.surface); } +/**********************************************************************//** + Set sprite to show for current extra. +**************************************************************************/ +static void set_help_tile_from_extra(const struct extra_type *pextra) +{ + struct canvas canvas = FC_STATIC_CANVAS_INIT; + cairo_t *cr; + struct drawn_sprite sprs[80]; + int count; + + canvas.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + tileset_tile_width(tileset), + tileset_tile_height(tileset)); + + cr = cairo_create(canvas.surface); + cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); + cairo_paint(cr); + cairo_destroy(cr); + + count = fill_basic_extra_sprite_array(tileset, sprs, pextra); + + put_drawn_sprites(&canvas, 1.0, 0, 0, count, sprs, FALSE); + + picture_set_from_surface(GTK_PICTURE(help_tile), canvas.surface); + gtk_widget_show(help_tile); + cairo_surface_destroy(canvas.surface); +} + /**********************************************************************//** Display updated help about improvement **************************************************************************/ @@ -1427,6 +1455,8 @@ static void help_update_extra(const struct help_item *pitem, char *title) struct road_type *proad = extra_road_get(pextra); bool is_resource = is_extra_caused_by(pextra, EC_RESOURCE); + set_help_tile_from_extra(pextra); + /* Cost to build */ if (pextra->buildable) { if (pextra->build_time != 0) { -- 2.39.2