From ffea222f5bfda8383cb52480b48998c9d0093911 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 16 Dec 2016 19:37:33 +0100 Subject: GRAPHICS: Added stubs for pasting text to MacText --- graphics/macgui/mactext.cpp | 31 ++++++++++++++++++++++++------- graphics/macgui/mactext.h | 4 +++- 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'graphics') diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp index fde79f910e..b674532890 100644 --- a/graphics/macgui/mactext.cpp +++ b/graphics/macgui/mactext.cpp @@ -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(_surface.w, x + w), MIN(_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 diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h index 4add3948fa..65e93ca5c3 100644 --- a/graphics/macgui/mactext.h +++ b/graphics/macgui/mactext.h @@ -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; -- cgit v1.2.3