X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fvideo%2Ffont.cpp;h=f132ec63568aec476b84b94488e3da9f658a8180;hb=ca65a4babe2341f4c9b8952cfd516df8d74575e4;hp=f0bdaffc64ab2e93616e007ced5071859377e47c;hpb=5a69e137b5dd05607a5a359d0cc56f51aeb9ed0f;p=supertux.git diff --git a/lib/video/font.cpp b/lib/video/font.cpp index f0bdaffc6..f132ec635 100644 --- a/lib/video/font.cpp +++ b/lib/video/font.cpp @@ -71,29 +71,60 @@ Font::~Font() } float -Font::get_height() const +Font::get_text_width(const std::string& text) const { - return h; + /** Let's calculate the size of the biggest paragraph */ + int l, hl; + hl = 0; l = -1; + while(true) + { + l = text.find("\n", l+1); + if(l == (int)std::string::npos) + break; + if(hl < l) + hl = l; + } + if(hl == 0) + hl = text.size(); + + return hl * w; } float -Font::get_text_width(const std::string& text) const +Font::get_text_height(const std::string& text) const +{ + /** Let's calculate height of the text */ + int l, hh; + hh = h; l = -1; + while(true) + { + l = text.find("\n", l+1); + if(l == (int)std::string::npos) + break; + hh += h + 2; + } + + return hh; +} + +float +Font::get_height() const { - return text.size() * w; + return h; } void -Font::draw(const std::string& text, const Vector& pos, Uint32 drawing_effect) +Font::draw(const std::string& text, const Vector& pos, Uint32 drawing_effect, int alpha) { if(shadowsize > 0) draw_chars(shadow_chars, text, pos + Vector(shadowsize, shadowsize), - drawing_effect); + drawing_effect, alpha); - draw_chars(chars, text, pos, drawing_effect); + draw_chars(chars, text, pos, drawing_effect, alpha); } void -Font::draw_center(const std::string& text, const Vector& pos, Uint32 drawing_effect) +Font::draw_center(const std::string& text, const Vector& pos, Uint32 drawing_effect, int alpha) { /* Cut lines changes into seperate strings, needed to support centering text with break lines. @@ -109,12 +140,12 @@ Font::draw_center(const std::string& text, const Vector& pos, Uint32 drawing_eff { temp[text.copy(temp, text.size() - i, i)] = '\0'; draw(temp, Vector(screen->w/2 - get_text_width(temp)/2 + pos.x, pos.y + y), - drawing_effect); + drawing_effect, alpha); break; } temp[text.copy(temp, l - i, i)] = '\0'; draw(temp, Vector(screen->w/2 - get_text_width(temp)/2 + pos.x, pos.y + y), - drawing_effect); + drawing_effect, alpha); i = l+1; y += h + 2; @@ -123,7 +154,7 @@ Font::draw_center(const std::string& text, const Vector& pos, Uint32 drawing_eff void Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos, - Uint32 drawing_effect) + Uint32 drawing_effect, int alpha) { SurfaceImpl* impl = pchars->impl; @@ -148,7 +179,7 @@ Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos, int source_x = (index % 16) * w; int source_y = (index / 16) * h; - impl->draw_part(source_x, source_y, p.x, p.y, w, h, 255, drawing_effect); + impl->draw_part(source_x, source_y, p.x, p.y, w, h, alpha, drawing_effect); p.x += w; } }