From b28a4a8c3d4175d90b444cbc0a51508f6f8cc753 Mon Sep 17 00:00:00 2001 From: VelocityRa Date: Fri, 31 Mar 2017 01:02:01 +0200 Subject: GRAPHICS: Fix MacText::appendText by resizing _textLines Also fix an off-by-one error --- graphics/macgui/mactext.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'graphics') diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp index 0f9c120758..672d1f5b6e 100644 --- a/graphics/macgui/mactext.cpp +++ b/graphics/macgui/mactext.cpp @@ -307,8 +307,8 @@ int MacText::getLineHeight(int line) { return _textLines[line].height; } -void MacText::setInterLinear(int interLinear) { - _interLinear = interLinear; +void MacText::setInterLinear(int interLinear) { + _interLinear = interLinear; recalcDims(); } @@ -339,14 +339,27 @@ void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int } void MacText::appendText(Common::String str) { - int oldLen = _textLines.size(); + uint oldLen = _textLines.size(); + uint newLines = 1; + + // Calc newline characters in str + Common::String::iterator p = str.begin(); + while (*p) { + if (*p == '\n') + newLines++; + p++; + } - // TODO: Recalc length + // Resize _textLines appropriately + for (int curLine = 0; curLine < newLines; ++curLine) { + _textLines.resize(oldLen + newLines); + _textLines[oldLen + curLine].chunks.push_back(_currentFormatting); + } splitString(str); recalcDims(); - render(oldLen + 1, _textLines.size()); + render(oldLen, _textLines.size()); } void MacText::replaceLastLine(Common::String str) { -- cgit v1.2.3