diff options
author | Eugene Sandulenko | 2016-12-15 18:05:27 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2016-12-15 18:07:48 +0100 |
commit | 2f7879d1183cd327219a8a6f1521ed5332db90d9 (patch) | |
tree | 254eb2a9dd71b4df2654499bb93ff12c5c809beb /graphics/macgui | |
parent | 6329f73c9ee3b30e04da89b7ac0b98c581e72c0c (diff) | |
download | scummvm-rg350-2f7879d1183cd327219a8a6f1521ed5332db90d9.tar.gz scummvm-rg350-2f7879d1183cd327219a8a6f1521ed5332db90d9.tar.bz2 scummvm-rg350-2f7879d1183cd327219a8a6f1521ed5332db90d9.zip |
GRAPHICS: Restrinct MacText to designated width
Diffstat (limited to 'graphics/macgui')
-rw-r--r-- | graphics/macgui/mactext.cpp | 27 | ||||
-rw-r--r-- | graphics/macgui/mactext.h | 1 |
2 files changed, 10 insertions, 18 deletions
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp index f7b2ed9b27..4807e19dbb 100644 --- a/graphics/macgui/mactext.cpp +++ b/graphics/macgui/mactext.cpp @@ -33,7 +33,10 @@ MacText::MacText(Common::String s, Graphics::Font *font, int fgcolor, int bgcolo _interLinear = 0; // 0 pixels between the lines by default - _textMaxWidth = -1; + if (_maxWidth == -1) + _textMaxWidth = 1000000; // Some big value + else + _textMaxWidth = -1; splitString(); @@ -46,6 +49,8 @@ void MacText::splitString() { Common::String tmp; bool prevCR; + _text.clear(); + while (*s) { if (*s == '\n' && prevCR) { // trean \r\n as one prevCR = false; @@ -56,8 +61,7 @@ void MacText::splitString() { prevCR = true; if (*s == '\r' || *s == '\n') { - _text.push_back(tmp); - _widths.push_back(_font->getStringWidth(tmp)); + _maxWidth = MIN(_font->wordWrapText(tmp, _maxWidth, _text), _maxWidth); tmp.clear(); @@ -68,24 +72,13 @@ void MacText::splitString() { } if (_text.size()) - _text.push_back(tmp); - - calcMaxWidth(); -} - -void MacText::calcMaxWidth() { - int max = -1; - - for (uint i = 0; i < _widths.size(); i++) - if (max < _widths[i]) - max = _widths[i]; - - _textMaxWidth = max; + _maxWidth = MIN(_font->wordWrapText(tmp, _maxWidth, _text), _maxWidth); } void MacText::render() { if (_fullRefresh) { - _surface.create(_textMaxWidth, _text.size() * (_font->getFontHeight() + _interLinear)); + _surface.create(_maxWidth == -1 ? _textMaxWidth : _maxWidth, + _text.size() * (_font->getFontHeight() + _interLinear)); _surface.clear(_bgcolor); diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h index cf975849b7..7831e65c46 100644 --- a/graphics/macgui/mactext.h +++ b/graphics/macgui/mactext.h @@ -48,7 +48,6 @@ private: int _interLinear; Common::Array<Common::String> _text; - Common::Array<int> _widths; int _textMaxWidth; |