units: Limit energy bar sizes to the game tile size

Because of the move to hardware rendering in commit
afd6baa7cf, some relevant info
was lost that was previously used to limit bar height in
particular.

This patch re-adds a dimension check and additionally ensures
that the bar width doesn't exceed the tile size either.

Fixes #7171.
This commit is contained in:
Iris Morelle 2023-01-19 20:51:35 -03:00 committed by Steve Cotton
parent 0b483953e9
commit 3e3cd06121
2 changed files with 9 additions and 1 deletions

View file

@ -0,0 +1,2 @@
### Rendering Engine
* Fixed a regression in 1.17.x resulting in overlarge unit HP and XP bars in some cases (issue #7171).

View file

@ -101,13 +101,19 @@ void draw_bar(int xpos, int ypos, int bar_height, double filled, const color_t&
const point offset = display::scaled_to_zoom(point{19, 13});
// Full bar dimensions.
const rect bar_rect = display::scaled_to_zoom({
rect bar_rect = display::scaled_to_zoom({
xpos + offset.x,
ypos + offset.y,
bar_width,
bar_height
});
// Bar dimensions should not overflow 80% of the scaled hex dimensions.
// The 80% comes from an approximation of the length of a segment drawn
// inside a regular hexagon that runs parallel to its outer left side.
bar_rect.w = std::clamp<int>(bar_rect.w, 0, display::hex_size() * 0.80 - offset.x);
bar_rect.h = std::clamp<int>(bar_rect.h, 0, display::hex_size() * 0.80 - offset.y);
filled = std::clamp<double>(filled, 0.0, 1.0);
const int unfilled = static_cast<std::size_t>(bar_rect.h * (1.0 - filled));