Author: cazfi Date: Sun Nov 1 23:25:57 2015 New Revision: 30369 URL: http://svn.gna.org/viewcvs/freeciv?rev=30369&view=rev Log: Fixed the size of "unit with upkeep" -icon canvases, affecting especially overhead tilesets, in gtk-clients.
Reported by mir3x <mir3x> See bug #23954 Modified: branches/S2_6/client/gui-gtk-2.0/citydlg.c branches/S2_6/client/gui-gtk-2.0/mapview.c branches/S2_6/client/gui-gtk-3.0/citydlg.c branches/S2_6/client/gui-gtk-3.0/mapview.c branches/S2_6/client/mapview_common.c branches/S2_6/client/tilespec.c branches/S2_6/client/tilespec.h Modified: branches/S2_6/client/gui-gtk-2.0/citydlg.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/citydlg.c?rev=30369&r1=30368&r2=30369&view=diff ============================================================================== --- branches/S2_6/client/gui-gtk-2.0/citydlg.c (original) +++ branches/S2_6/client/gui-gtk-2.0/citydlg.c Sun Nov 1 23:25:57 2015 @@ -762,7 +762,7 @@ GtkListStore *production_store; /* TRANS: Overview tab in city dialog */ const char *tab_title = _("_Overview"); - int unit_height = tileset_tile_height(tileset) * 3 / 2; + int unit_height = tileset_unit_with_upkeep_height(tileset); /* main page */ page = gtk_vbox_new(FALSE, 0); @@ -1852,7 +1852,7 @@ for (i = m; i < n; i++) { GtkWidget *cmd, *pix; struct unit_node node; - int unit_height = tileset_tile_height(tileset) * 3 / 2; + int unit_height = tileset_unit_with_upkeep_height(tileset); cmd = gtk_button_new(); node.cmd = cmd; Modified: branches/S2_6/client/gui-gtk-2.0/mapview.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/mapview.c?rev=30369&r1=30368&r2=30369&view=diff ============================================================================== --- branches/S2_6/client/gui-gtk-2.0/mapview.c (original) +++ branches/S2_6/client/gui-gtk-2.0/mapview.c Sun Nov 1 23:25:57 2015 @@ -546,7 +546,8 @@ gtk_pixcomm_freeze(p); - put_unit_city_overlays(punit, &store, 0, tileset_tile_height(tileset), + put_unit_city_overlays(punit, &store, 0, + tileset_unit_layout_offset_y(tileset), upkeep_cost, happy_cost); gtk_pixcomm_thaw(p); Modified: branches/S2_6/client/gui-gtk-3.0/citydlg.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/citydlg.c?rev=30369&r1=30368&r2=30369&view=diff ============================================================================== --- branches/S2_6/client/gui-gtk-3.0/citydlg.c (original) +++ branches/S2_6/client/gui-gtk-3.0/citydlg.c Sun Nov 1 23:25:57 2015 @@ -880,7 +880,7 @@ GtkListStore *production_store; /* TRANS: Overview tab in city dialog */ const char *tab_title = _("_Overview"); - int unit_height = tileset_unit_height(tileset); + int unit_height = tileset_unit_with_upkeep_height(tileset); /* main page */ page = gtk_grid_new(); @@ -2025,7 +2025,7 @@ for (i = m; i < n; i++) { GtkWidget *cmd, *pix; struct unit_node node; - int unit_height = tileset_tile_height(tileset) * 3 / 2; + int unit_height = tileset_unit_with_upkeep_height(tileset); cmd = gtk_button_new(); node.cmd = cmd; Modified: branches/S2_6/client/gui-gtk-3.0/mapview.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/mapview.c?rev=30369&r1=30368&r2=30369&view=diff ============================================================================== --- branches/S2_6/client/gui-gtk-3.0/mapview.c (original) +++ branches/S2_6/client/gui-gtk-3.0/mapview.c Sun Nov 1 23:25:57 2015 @@ -488,7 +488,7 @@ store.surface = gtk_pixcomm_get_surface(p); - put_unit_city_overlays(punit, &store, 0, tileset_tile_height(tileset), + put_unit_city_overlays(punit, &store, 0, tileset_unit_layout_offset_y(tileset), upkeep_cost, happy_cost); } Modified: branches/S2_6/client/mapview_common.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/mapview_common.c?rev=30369&r1=30368&r2=30369&view=diff ============================================================================== --- branches/S2_6/client/mapview_common.c (original) +++ branches/S2_6/client/mapview_common.c Sun Nov 1 23:25:57 2015 @@ -1071,8 +1071,8 @@ sprites (limiting the number of combinations). ****************************************************************************/ void put_unit_city_overlays(struct unit *punit, - struct canvas *pcanvas, - int canvas_x, int canvas_y, int *upkeep_cost, + struct canvas *pcanvas, + int canvas_x, int canvas_y, int *upkeep_cost, int happy_cost) { struct sprite *sprite; Modified: branches/S2_6/client/tilespec.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/tilespec.c?rev=30369&r1=30368&r2=30369&view=diff ============================================================================== --- branches/S2_6/client/tilespec.c (original) +++ branches/S2_6/client/tilespec.c Sun Nov 1 23:25:57 2015 @@ -470,6 +470,8 @@ int unit_tile_width, unit_tile_height; int small_sprite_width, small_sprite_height; + int max_upkeep_height; + char *main_intro_filename; char *minimap_intro_filename; @@ -733,6 +735,68 @@ int tileset_unit_height(const struct tileset *t) { return t->unit_tile_height; +} + +/**************************************************************************** + Calculate the height of a unit upkeep icons. +****************************************************************************/ +static int calculate_max_upkeep_height(const struct tileset *t) +{ + int i; + int max = 0; + + for (i = 0; i < MAX_NUM_UPKEEP_SPRITES; i++) { + if (t->sprites.upkeep.unhappy[i] != NULL) { + int width, height; + + /* TODO: We want only height, getting the width might waste CPU + * depending on gui-specific implementation. */ + get_sprite_dimensions(t->sprites.upkeep.unhappy[i], &width, &height); + + max = MAX(max, height); + } + } + + output_type_iterate(o) { + for (i = 0; i < MAX_NUM_UPKEEP_SPRITES; i++) { + if (t->sprites.upkeep.output[o][i] != NULL) { + int width, height; + + /* TODO: We want only height, getting the width might waste CPU + * depending on gui-specific implementation. */ + get_sprite_dimensions(t->sprites.upkeep.output[o][i], &width, &height); + + max = MAX(max, height); + } + } + } output_type_iterate_end; + + return max; +} + +/**************************************************************************** + Get the height of a unit upkeep icons. +****************************************************************************/ +static int tileset_upkeep_height(const struct tileset *t) +{ + /* Return cached value */ + return t->max_upkeep_height; +} + +/**************************************************************************** + Suitable canvas height for a unit icon that includes upkeep sprites. +****************************************************************************/ +int tileset_unit_with_upkeep_height(const struct tileset *t) +{ + return tileset_unit_layout_offset_y(tileset) + tileset_upkeep_height(tileset); +} + +/**************************************************************************** + Offset to layout extra unit sprites, such as upkeep. +****************************************************************************/ +int tileset_unit_layout_offset_y(const struct tileset *t) +{ + return tileset_tile_height(tileset); } /**************************************************************************** @@ -2728,7 +2792,9 @@ } } } output_type_iterate_end; - + + t->max_upkeep_height = calculate_max_upkeep_height(t); + SET_SPRITE(user.attention, "user.attention"); SET_SPRITE_OPT(path.s[GTS_MP_LEFT].specific, "path.normal"); if (t->sprites.path.s[GTS_TURN_STEP].turns[0] @@ -6000,8 +6066,8 @@ May return NULL if there's no unhappiness. ****************************************************************************/ struct sprite *get_unit_unhappy_sprite(const struct tileset *t, - const struct unit *punit, - int happy_cost) + const struct unit *punit, + int happy_cost) { const int unhappy = CLIP(0, happy_cost, MAX_NUM_UPKEEP_SPRITES+1); @@ -6016,14 +6082,14 @@ Return a sprite for the upkeep of the unit - to be shown as an overlay on the unit in the city support dialog, for instance. - May return NULL if there's no unhappiness. + May return NULL if there's no upkeep of the kind. ****************************************************************************/ struct sprite *get_unit_upkeep_sprite(const struct tileset *t, - Output_type_id otype, - const struct unit *punit, - const int *upkeep_cost) -{ - const int upkeep = CLIP(0, upkeep_cost[otype], MAX_NUM_UPKEEP_SPRITES+1); + Output_type_id otype, + const struct unit *punit, + const int *upkeep_cost) +{ + const int upkeep = CLIP(0, upkeep_cost[otype], MAX_NUM_UPKEEP_SPRITES + 1); if (upkeep > 0) { return t->sprites.upkeep.output[otype][upkeep - 1]; @@ -6136,6 +6202,8 @@ t->sprites.player[id].color = NULL; t->sprites.player[id].background = NULL; } player_slots_iterate_end; + + t->max_upkeep_height = 0; } /**************************************************************************** Modified: branches/S2_6/client/tilespec.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/tilespec.h?rev=30369&r1=30368&r2=30369&view=diff ============================================================================== --- branches/S2_6/client/tilespec.h (original) +++ branches/S2_6/client/tilespec.h Sun Nov 1 23:25:57 2015 @@ -381,6 +381,8 @@ int tileset_full_tile_height(const struct tileset *t); int tileset_unit_width(const struct tileset *t); int tileset_unit_height(const struct tileset *t); +int tileset_unit_with_upkeep_height(const struct tileset *t); +int tileset_unit_layout_offset_y(const struct tileset *t); int tileset_small_sprite_width(const struct tileset *t); int tileset_small_sprite_height(const struct tileset *t); int tileset_citybar_offset_y(const struct tileset *t); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits