From d174c6135c25e0552342cd8debaa7d7061ce8cfc Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 27 Jun 2022 19:53:25 +0300 Subject: [PATCH 23/23] sdl/2: Scale units down to icons by more accurate amount Citydlg icons were often scaled down far too much. See osdn #44891 Signed-off-by: Marko Lindqvist --- client/gui-sdl/citydlg.c | 16 +++++++++++----- client/gui-sdl2/citydlg.c | 11 ++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/client/gui-sdl/citydlg.c b/client/gui-sdl/citydlg.c index b1bc458f29..7bcc2c6e80 100644 --- a/client/gui-sdl/citydlg.c +++ b/client/gui-sdl/citydlg.c @@ -591,13 +591,13 @@ static int units_orders_city_dlg_callback(struct widget *pButton) /* ======================================================================= */ /************************************************************************** - create unit icon with support icons. + Create unit icon with support icons. **************************************************************************/ static SDL_Surface *create_unit_surface(struct unit *punit, bool support, int w, int h) { int i, step; - SDL_Rect src_rect, dest; + SDL_Rect src_rect; SDL_Surface *psurf; struct canvas *destcanvas; @@ -605,14 +605,20 @@ static SDL_Surface *create_unit_surface(struct unit *punit, bool support, tileset_unit_with_small_upkeep_height(tileset)); put_unit(punit, destcanvas, 1.0, 0, 0); - /* Get unit sprite width, but do not limit height by it */ + /* Get unit sprite width, and crop top. Bottom might get restored in 'support' + * case below. */ src_rect = get_smaller_surface_rect(destcanvas->surf); - src_rect.y = 0; - src_rect.h = destcanvas->surf->h; if (support) { int free_unhappy; int happy_cost; + SDL_Rect dest; + int offset = tileset_unit_layout_small_offset_y(tileset); + + /* Support also layouts placing support icons higher than unit. */ + src_rect.y = MIN(src_rect.y, offset); + /* Restore bottom space when needed for support icons. */ + src_rect.h = destcanvas->surf->h - src_rect.y; free_unhappy = get_city_bonus(pCityDlg->pCity, EFT_MAKE_CONTENT_MIL); happy_cost = city_unit_unhappiness(punit, &free_unhappy); diff --git a/client/gui-sdl2/citydlg.c b/client/gui-sdl2/citydlg.c index 8abb800f34..515d6e9617 100644 --- a/client/gui-sdl2/citydlg.c +++ b/client/gui-sdl2/citydlg.c @@ -606,16 +606,21 @@ static SDL_Surface *create_unit_surface(struct unit *punit, bool support, put_unit(punit, destcanvas, 1.0, 0, 0); - /* Get unit sprite width, but do not limit height by it */ + /* Get unit sprite width, and crop top. Bottom might get restored in 'support' + * case below. */ src_rect = get_smaller_surface_rect(destcanvas->surf); - src_rect.y = 0; - src_rect.h = destcanvas->surf->h; if (support) { int i, step; int free_unhappy; int happy_cost; SDL_Rect dest; + int offset = tileset_unit_layout_small_offset_y(tileset); + + /* Support also layouts placing support icons higher than unit. */ + src_rect.y = MIN(src_rect.y, offset); + /* Restore bottom space when needed for support icons. */ + src_rect.h = destcanvas->surf->h - src_rect.y; free_unhappy = get_city_bonus(pCityDlg->pCity, EFT_MAKE_CONTENT_MIL); happy_cost = city_unit_unhappiness(punit, &free_unhappy); -- 2.35.1