GRAPHICS: Added stubs for pasting text to MacText

This commit is contained in:
Eugene Sandulenko 2016-12-16 19:37:33 +01:00
parent 5f46bbff72
commit ffea222f5b
2 changed files with 27 additions and 8 deletions

View file

@ -38,19 +38,17 @@ MacText::MacText(Common::String s, Graphics::Font *font, int fgcolor, int bgcolo
else
_textMaxWidth = -1;
splitString();
splitString(_str);
_fullRefresh = true;
}
void MacText::splitString() {
const char *s = _str.c_str();
void MacText::splitString(Common::String &str) {
const char *s = str.c_str();
Common::String tmp;
bool prevCR;
_text.clear();
while (*s) {
if (*s == '\n' && prevCR) { // trean \r\n as one
prevCR = false;
@ -75,10 +73,19 @@ void MacText::splitString() {
_maxWidth = MIN(_font->wordWrapText(tmp, _maxWidth, _text), _maxWidth);
}
void MacText::reallocSurface() {
int lineHeight = _font->getFontHeight() + _interLinear;
int requiredHeight = (_text.size() + (_text.size() * 10 + 9) / 10) * lineHeight;
if (_surface.w < requiredHeight) {
// realloc surface
_surface.create(_maxWidth == -1 ? _textMaxWidth : _maxWidth, requiredHeight);
}
}
void MacText::render() {
if (_fullRefresh) {
_surface.create(_maxWidth == -1 ? _textMaxWidth : _maxWidth,
_text.size() * (_font->getFontHeight() + _interLinear));
reallocSurface();
_surface.clear(_bgcolor);
@ -105,4 +112,14 @@ void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int
MIN<int>(_surface.w, x + w), MIN<int>(_surface.w, y + w)), Common::Point(xoff, yoff));
}
void MacText::appendText(Common::String str) {
//int oldLen = _text.size();
splitString(str);
reallocSurface();
//render(oldLen + 1, _text.size());
}
} // End of namespace Graphics

View file

@ -35,12 +35,14 @@ public:
void setInterLinear(int interLinear) { _interLinear = interLinear; }
void draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff);
void appendText(Common::String str);
private:
void splitString();
void splitString(Common::String &s);
void render();
void calcMaxWidth();
void reallocSurface();
private:
Common::String _str;