diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp index 20b2ef686b24..7e937de9dcaa 100644 --- a/graphics/macgui/mactext.cpp +++ b/graphics/macgui/mactext.cpp @@ -20,6 +20,7 @@ */ #include "graphics/macgui/mactext.h" +#include "graphics/font.h" namespace Graphics { @@ -27,6 +28,54 @@ MacText::MacText(Common::String s, Graphics::Font *font, int maxWidth) { _str = s; _font = font; _maxWidth = maxWidth; + _interLinear = 2; // 2 pixels by default + + _textMaxWidth = -1; + + splitString(); +} + +void MacText::splitString() { + const char *s = _str.c_str(); + + Common::String tmp; + bool prevCR; + + while (*s) { + if (*s == '\n' && prevCR) { // trean \r\n as one + prevCR = false; + continue; + } + + if (*s == '\r') + prevCR = true; + + if (*s == '\r' || *s == '\n') { + _text.push_back(tmp); + _widths.push_back(_font->getStringWidth(tmp)); + + tmp.clear(); + + continue; + } + + tmp += *s; + } + + calcMaxWidth(); +} + +void MacText::calcMaxWidth() { + int max = -1; + + for (uint i = 0; i < _widths.size(); i++) + if (max < _widths[i]) + max = _widths[i]; + + _textMaxWidth = max; +} + +void MacText::render() { } } // End of namespace Graphics diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h index 694e14e55e78..6f49133d575c 100644 --- a/graphics/macgui/mactext.h +++ b/graphics/macgui/mactext.h @@ -31,10 +31,23 @@ class MacText { public: MacText(Common::String s, Graphics::Font *font, int maxWidth = -1); + void setInterLinear(int interLinear) { _interLinear = interLinear; } + +private: + void splitString(); + void render(); + void calcMaxWidth(); + private: Common::String _str; Graphics::Font *_font; int _maxWidth; + int _interLinear; + + Common::Array _text; + Common::Array _widths; + + int _textMaxWidth; }; } // End of namespace Graphics