From 40fd251c39e39bb877f420e0178dc8c5a5728bb9 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 9 Dec 2013 22:57:43 -0300 Subject: [PATCH] Add support for vertical text alignment in Graphics::drawStringAlgorithm() --- src/ui/graphics.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ui/graphics.cpp b/src/ui/graphics.cpp index eb40e8999..0581f63c2 100644 --- a/src/ui/graphics.cpp +++ b/src/ui/graphics.cpp @@ -145,13 +145,21 @@ gfx::Size Graphics::fitString(const std::string& str, int maxWidth, int align) gfx::Size Graphics::drawStringAlgorithm(const std::string& str, Color fg, Color bg, const gfx::Rect& rc, int align, bool draw) { + gfx::Point pt(0, rc.y); + + if ((align & (JI_MIDDLE | JI_BOTTOM)) != 0) { + gfx::Size preSize = drawStringAlgorithm(str, ColorNone, ColorNone, rc, 0, false); + if (align & JI_MIDDLE) + pt.y = rc.y + rc.h/2 - preSize.h/2; + else if (align & JI_BOTTOM) + pt.y = rc.y + rc.h - preSize.h; + } + gfx::Size calculatedSize(0, 0); size_t beg, end, new_word_beg, old_end; std::string line; - gfx::Point pt; // Draw line-by-line - pt.y = rc.y; for (beg=end=0; end != std::string::npos; ) { pt.x = rc.x; @@ -215,11 +223,10 @@ gfx::Size Graphics::drawStringAlgorithm(const std::string& str, Color fg, Color } pt.y += lineSize.h; + calculatedSize.h += lineSize.h; beg = end+1; } - calculatedSize.h += pt.y; - // Fill bottom area if (draw) { if (pt.y < rc.y+rc.h)