Skip to content

Commit

Permalink
GRAPHICS: Further work on MacText class
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Dec 14, 2016
1 parent 34a9c58 commit aecc17e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
49 changes: 49 additions & 0 deletions graphics/macgui/mactext.cpp
Expand Up @@ -20,13 +20,62 @@
*/

#include "graphics/macgui/mactext.h"
#include "graphics/font.h"

namespace Graphics {

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
13 changes: 13 additions & 0 deletions graphics/macgui/mactext.h
Expand Up @@ -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<Common::String> _text;
Common::Array<int> _widths;

int _textMaxWidth;
};

} // End of namespace Graphics
Expand Down

0 comments on commit aecc17e

Please sign in to comment.