Skip to content

Commit

Permalink
Merge pull request #162 from NicksWorld/fix/announcement-size
Browse files Browse the repository at this point in the history
Properly offset announcements based on font size
  • Loading branch information
myk002 authored Jan 25, 2025
2 parents 930db8f + efb5194 commit 54d2048
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
18 changes: 11 additions & 7 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ void draw_textf_border(const ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, f
namespace
{
template<typename T>
constexpr auto get_dimensions = nullptr;
template<> constexpr auto get_dimensions<const char*> = &al_get_text_dimensions;
template<> constexpr auto get_dimensions<const ALLEGRO_USTR*> = &al_get_ustr_dimensions;
constexpr auto get_width = nullptr;
template<> constexpr auto get_width<const char*> = &al_get_text_width;
template<> constexpr auto get_width<const ALLEGRO_USTR*> = &al_get_ustr_width;

template<typename T>
constexpr auto draw_text = nullptr;
Expand All @@ -309,15 +309,19 @@ namespace
void draw_border(const ALLEGRO_FONT* font, ALLEGRO_COLOR color, float x, float y, int flags, auto ustr)
{
using T = decltype(ustr);
int xx, yy, ww, hh;
get_dimensions<T>(font, ustr, &xx, &yy, &ww, &hh);
int xx = 0;
int ww = get_width<T>(font, ustr);
// Prefer the overall font height for consistency,
// even though it may vary depending on ascending/decending characters.
int hh = al_get_font_line_height(font);

if (flags & ALLEGRO_ALIGN_CENTRE) {
xx -= ww / 2;
}
else if (flags & ALLEGRO_ALIGN_RIGHT) {
xx -= ww;
}
al_draw_filled_rectangle(x + xx, y + yy, x + xx + ww, y + yy + hh, al_map_rgba_f(0.0, 0.0, 0.0, 0.75));
al_draw_filled_rectangle(x + xx, y, x + xx + ww, y + hh, al_map_rgba_f(0.0, 0.0, 0.0, 0.75));
draw_text<T>(font, color, x, y, flags, ustr);
}
}
Expand Down Expand Up @@ -904,7 +908,7 @@ void paintboard()

if (ssConfig.show_announcements) {
al_hold_bitmap_drawing(true);
draw_announcements(font, ssState.ScreenW, ssState.ScreenH - 20, ALLEGRO_ALIGN_RIGHT, df::global::world->status.announcements);
draw_announcements(font, ssState.ScreenW, ssState.ScreenH - 10 - al_get_font_line_height(font), ALLEGRO_ALIGN_RIGHT, df::global::world->status.announcements);
al_hold_bitmap_drawing(false);
}
if(ssConfig.show_keybinds){
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Template for new versions:
- `stonesense`: added option ``PIXELPERFECT_ZOOM`` to change the zoom scale to avoid gaps (off by default)

## Fixes
- `stonesense`: fixed announcement text rendering off-screen with larger font sizes
- `stonesense`: screen dimensions are now properly set when overriden by a window manager

## Misc Improvements
Expand Down

0 comments on commit 54d2048

Please sign in to comment.