From 5186351345d43801ac45acde8b7e30734eea0349 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Tue, 7 Nov 2017 18:33:03 +0100 Subject: Better unit say. --- src/render.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/render.cpp') diff --git a/src/render.cpp b/src/render.cpp index 80ed2b6..259d898 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -181,6 +181,32 @@ void state_t::render(oriented_sprite_t *sprite, rectf_t bounds, float angle) render(sprite->textures + index, bounds, mirror); } +void state_t::render_text(v2f_t x, float height, const wchar_t *wstr, + text_align_t align, sf::Color color) +{ + sf::Text text(wstr, font, 20); + sf::FloatRect rect; + float scale; + v2f_t offset; + + rect = text.getGlobalBounds(); + scale = height / 20.0f; + + switch (align) { + case ALIGN_CENTER_BOTTOM: + offset[0] = -rect.width / 2; + offset[1] = -rect.height; + break; + } + + offset *= scale; + + text.setScale(scale, scale); + text.setPosition(x + offset); + text.setFillColor(color); + window->draw(text); +} + void state_t::render_hlrect(rectf_t rect, sf::Color color) { sf::Color fill; -- cgit