[Scummvm-git-logs] scummvm master -> 0485f4a593b307bfc90b69bd625058c01ea9df8a
sev-
noreply at scummvm.org
Sun Oct 8 22:23:47 UTC 2023
This automated email contains information about 7 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
382a1acfa7 GRAPHICS: MACGUI: Encapsulate text details in MacTextCanvas
b2fb4dcb3b GRAPHUCS: MACGUI: Moved more variables to MacTextCanvas
74910523c3 GRAPHICS: MACGUI: Turned MacTextCanvas into a class
6004d955ea GRAPHICS: MACGUI: Moved several methods to MacTextCanvas
b2a7bad618 GRAPHICS: MACGUI: Moved more methods int MacTextCanvas
4fba78c13d GRAPHICS: MACGUI: Render table cells in MacText
0485f4a593 SDL: Added (disabled) Markdown table to the Keyboard help
Commit: 382a1acfa79897b143c7d8d03eee710f851b014c
https://github.com/scummvm/scummvm/commit/382a1acfa79897b143c7d8d03eee710f851b014c
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-09T00:22:14+02:00
Commit Message:
GRAPHICS: MACGUI: Encapsulate text details in MacTextCanvas
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 1b8cea646a7..620d2d608d6 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -287,12 +287,12 @@ MacText::~MacText() {
// this func returns the fg color of the first character we met in text
MacFontRun MacText::getFgColor() {
- if (_textLines.empty())
+ if (_canvas.text.empty())
return MacFontRun();
- for (uint i = 0; i < _textLines.size(); i++) {
- for (uint j = 0; j < _textLines[i].chunks.size(); j++) {
- if (!_textLines[i].chunks[j].text.empty())
- return _textLines[i].chunks[j];
+ for (uint i = 0; i < _canvas.text.size(); i++) {
+ for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
+ if (!_canvas.text[i].chunks[j].text.empty())
+ return _canvas.text[i].chunks[j];
}
}
return MacFontRun();
@@ -352,7 +352,7 @@ void MacText::setMaxWidth(int maxWidth) {
ppos += _cursorCol;
_maxWidth = maxWidth;
- _textLines.clear();
+ _canvas.text.clear();
splitString(str);
@@ -379,7 +379,7 @@ void MacText::setColors(uint32 fg, uint32 bg) {
_fgcolor = fg;
// also set the cursor color
_cursorSurface->clear(_fgcolor);
- for (uint i = 0; i < _textLines.size(); i++)
+ for (uint i = 0; i < _canvas.text.size(); i++)
setTextColor(fg, i);
_fullRefresh = true;
@@ -388,9 +388,9 @@ void MacText::setColors(uint32 fg, uint32 bg) {
}
void MacText::enforceTextFont(uint16 fontId) {
- for (uint i = 0; i < _textLines.size(); i++) {
- for (uint j = 0; j < _textLines[i].chunks.size(); j++) {
- _textLines[i].chunks[j].fontId = fontId;
+ for (uint i = 0; i < _canvas.text.size(); i++) {
+ for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
+ _canvas.text[i].chunks[j].fontId = fontId;
}
}
@@ -400,9 +400,9 @@ void MacText::enforceTextFont(uint16 fontId) {
}
void MacText::setTextSize(int textSize) {
- for (uint i = 0; i < _textLines.size(); i++) {
- for (uint j = 0; j < _textLines[i].chunks.size(); j++) {
- _textLines[i].chunks[j].fontSize = textSize;
+ for (uint i = 0; i < _canvas.text.size(); i++) {
+ for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
+ _canvas.text[i].chunks[j].fontSize = textSize;
}
}
@@ -412,36 +412,36 @@ void MacText::setTextSize(int textSize) {
}
void MacText::setTextColor(uint32 color, uint32 line) {
- if (line >= _textLines.size()) {
+ if (line >= _canvas.text.size()) {
warning("MacText::setTextColor(): line %d is out of bounds", line);
return;
}
uint32 fgcol = _wm->findBestColor(color);
- for (uint j = 0; j < _textLines[line].chunks.size(); j++) {
- _textLines[line].chunks[j].fgcolor = fgcol;
+ for (uint j = 0; j < _canvas.text[line].chunks.size(); j++) {
+ _canvas.text[line].chunks[j].fgcolor = fgcol;
}
// if we are calling this func separately, then here need a refresh
}
void MacText::getChunkPosFromIndex(int index, uint &lineNum, uint &chunkNum, uint &offset) {
- if (_textLines.empty()) {
+ if (_canvas.text.empty()) {
lineNum = chunkNum = offset = 0;
return;
}
- for (uint i = 0; i < _textLines.size(); i++) {
+ for (uint i = 0; i < _canvas.text.size(); i++) {
if (getLineCharWidth(i) <= index) {
index -= getLineCharWidth(i);
} else {
lineNum = i;
- chunkNum = _textLines[i].getChunkNum(&index);
+ chunkNum = _canvas.text[i].getChunkNum(&index);
offset = index;
return;
}
}
- lineNum = _textLines.size() - 1;
- chunkNum = _textLines[lineNum].chunks.size() - 1;
+ lineNum = _canvas.text.size() - 1;
+ chunkNum = _canvas.text[lineNum].chunks.size() - 1;
offset = 0;
}
@@ -463,7 +463,7 @@ void MacText::setTextSize(int textSize, int start, int end) {
}
void MacText::setTextChunks(int start, int end, int param, void (*callback)(MacFontRun &, int)) {
- if (_textLines.empty())
+ if (_canvas.text.empty())
return;
if (start > end)
SWAP(start, end);
@@ -475,21 +475,21 @@ void MacText::setTextChunks(int start, int end, int param, void (*callback)(MacF
getChunkPosFromIndex(start, startRow, startCol, offset);
// if offset != 0, then we need to split the chunk
if (offset != 0) {
- uint textSize = _textLines[startRow].chunks[startCol].text.size();
- MacFontRun newChunk = _textLines[startRow].chunks[startCol];
+ uint textSize = _canvas.text[startRow].chunks[startCol].text.size();
+ MacFontRun newChunk = _canvas.text[startRow].chunks[startCol];
newChunk.text = newChunk.text.substr(offset, textSize - offset);
- _textLines[startRow].chunks[startCol].text = _textLines[startRow].chunks[startCol].text.substr(0, offset);
- _textLines[startRow].chunks.insert_at(startCol + 1, newChunk);
+ _canvas.text[startRow].chunks[startCol].text = _canvas.text[startRow].chunks[startCol].text.substr(0, offset);
+ _canvas.text[startRow].chunks.insert_at(startCol + 1, newChunk);
startCol++;
}
getChunkPosFromIndex(end, endRow, endCol, offset);
if (offset != 0) {
- uint textSize = _textLines[endRow].chunks[endCol].text.size();
- MacFontRun newChunk = _textLines[endRow].chunks[endCol];
+ uint textSize = _canvas.text[endRow].chunks[endCol].text.size();
+ MacFontRun newChunk = _canvas.text[endRow].chunks[endCol];
newChunk.text = newChunk.text.substr(offset, textSize - offset);
- _textLines[endRow].chunks[endCol].text = _textLines[endRow].chunks[endCol].text.substr(0, offset);
- _textLines[endRow].chunks.insert_at(endCol + 1, newChunk);
+ _canvas.text[endRow].chunks[endCol].text = _canvas.text[endRow].chunks[endCol].text.substr(0, offset);
+ _canvas.text[endRow].chunks.insert_at(endCol + 1, newChunk);
endCol++;
}
@@ -500,16 +500,16 @@ void MacText::setTextChunks(int start, int end, int param, void (*callback)(MacF
to = endCol;
} else if (i == startRow) {
from = startCol;
- to = _textLines[startRow].chunks.size();
+ to = _canvas.text[startRow].chunks.size();
} else if (i == endRow) {
from = 0;
to = endCol;
} else {
from = 0;
- to = _textLines[i].chunks.size();
+ to = _canvas.text[i].chunks.size();
}
for (uint j = from; j < to; j++) {
- callback(_textLines[i].chunks[j], param);
+ callback(_canvas.text[i].chunks[j], param);
}
}
@@ -535,12 +535,12 @@ void MacText::setTextSlant(int textSlant, int start, int end) {
}
void MacText::enforceTextSlant(int textSlant) {
- for (uint i = 0; i < _textLines.size(); i++) {
- for (uint j = 0; j < _textLines[i].chunks.size(); j++) {
+ for (uint i = 0; i < _canvas.text.size(); i++) {
+ for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
if (textSlant) {
- _textLines[i].chunks[j].textSlant |= textSlant;
+ _canvas.text[i].chunks[j].textSlant |= textSlant;
} else {
- _textLines[i].chunks[j].textSlant = textSlant;
+ _canvas.text[i].chunks[j].textSlant = textSlant;
}
}
}
@@ -570,7 +570,7 @@ int MacText::getTextSlant(int start, int end) {
// only getting the first chunk for the selected area
MacFontRun MacText::getTextChunks(int start, int end) {
- if (_textLines.empty())
+ if (_canvas.text.empty())
return _defaultFormatting;
if (start > end)
SWAP(start, end);
@@ -579,7 +579,7 @@ MacFontRun MacText::getTextChunks(int start, int end) {
uint offset;
getChunkPosFromIndex(start, startRow, startCol, offset);
- return _textLines[startRow].chunks[startCol];
+ return _canvas.text[startRow].chunks[startCol];
}
void MacText::setDefaultFormatting(uint16 fontId, byte textSlant, uint16 fontSize,
@@ -600,14 +600,14 @@ void MacText::chopChunk(const Common::U32String &str, int *curLinePtr, int inden
MacFontRun *chunk;
if (!_inTable) {
- curChunk = _textLines[curLine].chunks.size() - 1;
- chunk = &_textLines[curLine].chunks[curChunk];
+ curChunk = _canvas.text[curLine].chunks.size() - 1;
+ chunk = &_canvas.text[curLine].chunks[curChunk];
} else {
if (str.empty())
return;
- curChunk = _textLines[curLine].table->back().cells.back().text.back().chunks.size() - 1;
- chunk = &_textLines[curLine].table->back().cells.back().text.back().chunks[curChunk];
+ curChunk = _canvas.text[curLine].table->back().cells.back().text.back().chunks.size() - 1;
+ chunk = &_canvas.text[curLine].table->back().cells.back().text.back().chunks[curChunk];
}
// Check if there is nothing to add, then remove the last chunk
@@ -616,7 +616,7 @@ void MacText::chopChunk(const Common::U32String &str, int *curLinePtr, int inden
if (chunk->text.empty() && str.empty()) {
D(9, "** chopChunk, replaced formatting, line %d", curLine);
- _textLines[curLine].chunks.pop_back();
+ _canvas.text[curLine].chunks.pop_back();
return;
}
@@ -657,19 +657,19 @@ void MacText::chopChunk(const Common::U32String &str, int *curLinePtr, int inden
return;
// Now add rest of the chunks
- MacFontRun newchunk = _textLines[curLine].chunks[curChunk];
+ MacFontRun newchunk = _canvas.text[curLine].chunks[curChunk];
for (uint i = 1; i < text.size(); i++) {
newchunk.text = text[i];
if (!_inTable) {
curLine++;
- _textLines.insert_at(curLine, MacTextLine());
- _textLines[curLine].chunks.push_back(newchunk);
- _textLines[curLine].indent = indent;
+ _canvas.text.insert_at(curLine, MacTextLine());
+ _canvas.text[curLine].chunks.push_back(newchunk);
+ _canvas.text[curLine].indent = indent;
} else {
- _textLines[curLine].table->back().cells.back().text.push_back(MacTextLine());
- _textLines[curLine].table->back().cells.back().text.back().chunks.push_back(newchunk);
+ _canvas.text[curLine].table->back().cells.back().text.push_back(MacTextLine());
+ _canvas.text[curLine].table->back().cells.back().text.back().chunks.push_back(newchunk);
}
D(9, "** chopChunk, added line: \"%s\"", toPrintable(text[i].encode()).c_str());
@@ -683,12 +683,12 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
D(9, "** splitString(\"%s\")", toPrintable(str.encode()).c_str());
- if (_textLines.empty()) {
- _textLines.resize(1);
- _textLines[0].chunks.push_back(_defaultFormatting);
+ if (_canvas.text.empty()) {
+ _canvas.text.resize(1);
+ _canvas.text[0].chunks.push_back(_defaultFormatting);
D(9, "** splitString, added default formatting");
} else {
- D(9, "** splitString, continuing, %d lines", _textLines.size());
+ D(9, "** splitString, continuing, %d lines", _canvas.text.size());
}
if (str.empty()) {
@@ -699,10 +699,10 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
Common::U32String paragraph, tmp;
if (curLine == -1)
- curLine = _textLines.size() - 1;
+ curLine = _canvas.text.size() - 1;
- int curChunk = _textLines[curLine].chunks.size() - 1;
- MacFontRun chunk = _textLines[curLine].chunks[curChunk];
+ int curChunk = _canvas.text[curLine].chunks.size() - 1;
+ MacFontRun chunk = _canvas.text[curLine].chunks[curChunk];
int indentSize = 0;
int firstLineIndent = 0;
@@ -735,7 +735,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
tmp.clear();
- MacTextLine *curTextLine = &_textLines[curLine];
+ MacTextLine *curTextLine = &_canvas.text[curLine];
while (*s) {
// Scan till next font change or end of line
@@ -761,7 +761,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
// chunk definition. That means, that we have to store the previous chunk
chopChunk(tmp, &curLine, indentSize, _inTable ? -1 : _maxWidth);
- curTextLine = &_textLines[curLine];
+ curTextLine = &_canvas.text[curLine];
tmp.clear();
@@ -880,23 +880,23 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
uint16 len;
- s = readHex(&_textLines[curLine].picpercent, s, 2);
+ s = readHex(&_canvas.text[curLine].picpercent, s, 2);
s = readHex(&len, s, 2);
- _textLines[curLine].picfname = Common::U32String(s, len).encode();
+ _canvas.text[curLine].picfname = Common::U32String(s, len).encode();
s += len;
s = readHex(&len, s, 2);
- _textLines[curLine].picalt = Common::U32String(s, len);
+ _canvas.text[curLine].picalt = Common::U32String(s, len);
s += len;
s = readHex(&len, s, 2);
- _textLines[curLine].pictitle = Common::U32String(s, len);
+ _canvas.text[curLine].pictitle = Common::U32String(s, len);
s += len;
D(9, "** splitString[i]: %d%% fname: '%s' alt: '%s' title: '%s'",
- _textLines[curLine].picpercent,
- _textLines[curLine].picfname.c_str(), _textLines[curLine].picalt.c_str(),
- _textLines[curLine].pictitle.c_str());
+ _canvas.text[curLine].picpercent,
+ _canvas.text[curLine].picfname.c_str(), _canvas.text[curLine].picalt.c_str(),
+ _canvas.text[curLine].pictitle.c_str());
break;
}
@@ -943,7 +943,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
processTable(curLine);
- curTextLine = &_textLines[curLine];
+ curTextLine = &_canvas.text[curLine];
} else if (cmd == 'r') { // Row
curTextLine->table->push_back(MacTextTableRow());
continue;
@@ -951,7 +951,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
uint16 flags;
s = readHex(&flags, s, 2);
- curTextLine->table->back().cells.push_back(MacTextTableCell());
+ curTextLine->table->back().cells.push_back(MacTextCanvas());
curTextLine->table->back().cells.back().flags = flags;
curTextLine->table->back().cells.back().text.resize(1);
@@ -1011,19 +1011,19 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
if (!_inTable) {
curLine++;
- _textLines.insert_at(curLine, MacTextLine());
- _textLines[curLine].chunks.push_back(chunk);
+ _canvas.text.insert_at(curLine, MacTextLine());
+ _canvas.text[curLine].chunks.push_back(chunk);
- curTextLine = &_textLines[curLine];
+ curTextLine = &_canvas.text[curLine];
}
}
#if DEBUG
- for (uint i = 0; i < _textLines.size(); i++) {
+ for (uint i = 0; i < _canvas.text.size(); i++) {
debugN(9, "** splitString: %2d ", i);
- for (uint j = 0; j < _textLines[i].chunks.size(); j++)
- debugN(9, "[%d] \"%s\"", _textLines[i].chunks[j].text.size(), Common::toPrintable(_textLines[i].chunks[j].text.encode()).c_str());
+ for (uint j = 0; j < _canvas.text[i].chunks.size(); j++)
+ debugN(9, "[%d] \"%s\"", _canvas.text[i].chunks[j].text.size(), Common::toPrintable(_canvas.text[i].chunks[j].text.encode()).c_str());
debugN(9, "\n");
}
@@ -1073,7 +1073,7 @@ void MacText::render() {
if (_textShadow)
_shadowSurface->clear(_bgcolor);
- render(0, _textLines.size());
+ render(0, _canvas.text.size());
_fullRefresh = false;
@@ -1101,11 +1101,11 @@ void MacText::render(int from, int to, int shadow) {
}
for (int i = myFrom; i != myTo; i += delta) {
- if (!_textLines[i].picfname.empty()) {
- const Surface *image = getImageSurface(_textLines[i].picfname);
+ if (!_canvas.text[i].picfname.empty()) {
+ const Surface *image = getImageSurface(_canvas.text[i].picfname);
- int xOffset = (_textLines[i].width - _textLines[i].charwidth) / 2;
- Common::Rect bbox(xOffset, _textLines[i].y, xOffset + _textLines[i].charwidth, _textLines[i].y + _textLines[i].height);
+ int xOffset = (_canvas.text[i].width - _canvas.text[i].charwidth) / 2;
+ Common::Rect bbox(xOffset, _canvas.text[i].y, xOffset + _canvas.text[i].charwidth, _canvas.text[i].y + _canvas.text[i].height);
if (image)
surface->blitFrom(image, Common::Rect(0, 0, image->w, image->h), bbox);
@@ -1113,62 +1113,62 @@ void MacText::render(int from, int to, int shadow) {
continue;
}
- int xOffset = getAlignOffset(i) + _textLines[i].indent + _textLines[i].firstLineIndent;
+ int xOffset = getAlignOffset(i) + _canvas.text[i].indent + _canvas.text[i].firstLineIndent;
xOffset++;
- int start = 0, end = _textLines[i].chunks.size();
+ int start = 0, end = _canvas.text[i].chunks.size();
if (_wm->_language == Common::HE_ISR) {
- start = _textLines[i].chunks.size() - 1;
+ start = _canvas.text[i].chunks.size() - 1;
end = -1;
}
int maxAscentForRow = 0;
for (int j = start; j != end; j += delta) {
- if (_textLines[i].chunks[j].font->getFontAscent() > maxAscentForRow)
- maxAscentForRow = _textLines[i].chunks[j].font->getFontAscent();
+ if (_canvas.text[i].chunks[j].font->getFontAscent() > maxAscentForRow)
+ maxAscentForRow = _canvas.text[i].chunks[j].font->getFontAscent();
}
// TODO: _textMaxWidth, when -1, was not rendering ANY text.
for (int j = start; j != end; j += delta) {
debug(9, "MacText::render: line %d[%d] h:%d at %d,%d (%s) fontid: %d fontsize: %d on %dx%d, fgcolor: %08x bgcolor: %08x, font: %p",
- i, j, _textLines[i].height, xOffset, _textLines[i].y, _textLines[i].chunks[j].text.encode().c_str(),
- _textLines[i].chunks[j].fontId, _textLines[i].chunks[j].fontSize, _surface->w, _surface->h, _textLines[i].chunks[j].fgcolor, _bgcolor,
- (const void *)_textLines[i].chunks[j].getFont());
+ i, j, _canvas.text[i].height, xOffset, _canvas.text[i].y, _canvas.text[i].chunks[j].text.encode().c_str(),
+ _canvas.text[i].chunks[j].fontId, _canvas.text[i].chunks[j].fontSize, _surface->w, _surface->h, _canvas.text[i].chunks[j].fgcolor, _bgcolor,
+ (const void *)_canvas.text[i].chunks[j].getFont());
- if (_textLines[i].chunks[j].text.empty())
+ if (_canvas.text[i].chunks[j].text.empty())
continue;
int yOffset = 0;
- if (_textLines[i].chunks[j].font->getFontAscent() < maxAscentForRow) {
- yOffset = maxAscentForRow - _textLines[i].chunks[j].font->getFontAscent();
+ if (_canvas.text[i].chunks[j].font->getFontAscent() < maxAscentForRow) {
+ yOffset = maxAscentForRow - _canvas.text[i].chunks[j].font->getFontAscent();
}
- if (_textLines[i].chunks[j].plainByteMode()) {
- Common::String str = _textLines[i].chunks[j].getEncodedText();
- _textLines[i].chunks[j].getFont()->drawString(surface, str, xOffset, _textLines[i].y + yOffset, w, shadow ? _wm->_colorBlack : _textLines[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
- xOffset += _textLines[i].chunks[j].getFont()->getStringWidth(str);
+ if (_canvas.text[i].chunks[j].plainByteMode()) {
+ Common::String str = _canvas.text[i].chunks[j].getEncodedText();
+ _canvas.text[i].chunks[j].getFont()->drawString(surface, str, xOffset, _canvas.text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas.text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
+ xOffset += _canvas.text[i].chunks[j].getFont()->getStringWidth(str);
} else {
if (_wm->_language == Common::HE_ISR)
- _textLines[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_textLines[i].chunks[j].text, Common::BIDI_PAR_RTL), xOffset, _textLines[i].y + yOffset, w, shadow ? _wm->_colorBlack : _textLines[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
+ _canvas.text[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_canvas.text[i].chunks[j].text, Common::BIDI_PAR_RTL), xOffset, _canvas.text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas.text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
else
- _textLines[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_textLines[i].chunks[j].text), xOffset, _textLines[i].y + yOffset, w, shadow ? _wm->_colorBlack : _textLines[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
- xOffset += _textLines[i].chunks[j].getFont()->getStringWidth(_textLines[i].chunks[j].text);
+ _canvas.text[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_canvas.text[i].chunks[j].text), xOffset, _canvas.text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas.text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
+ xOffset += _canvas.text[i].chunks[j].getFont()->getStringWidth(_canvas.text[i].chunks[j].text);
}
}
}
}
void MacText::render(int from, int to) {
- if (_textLines.empty())
+ if (_canvas.text.empty())
return;
reallocSurface();
from = MAX<int>(0, from);
- to = MIN<int>(to, _textLines.size() - 1);
+ to = MIN<int>(to, _canvas.text.size() - 1);
// Clear the screen
- _surface->fillRect(Common::Rect(0, _textLines[from].y, _surface->w, _textLines[to].y + getLineHeight(to)), _bgcolor);
+ _surface->fillRect(Common::Rect(0, _canvas.text[from].y, _surface->w, _canvas.text[to].y + getLineHeight(to)), _bgcolor);
// render the shadow surface;
if (_textShadow)
@@ -1176,21 +1176,21 @@ void MacText::render(int from, int to) {
render(from, to, 0);
- for (uint i = 0; i < _textLines.size(); i++) {
+ for (uint i = 0; i < _canvas.text.size(); i++) {
debugN(9, "MacText::render: %2d ", i);
- for (uint j = 0; j < _textLines[i].chunks.size(); j++)
- debugN(9, "[%d (%d)] \"%s\" ", _textLines[i].chunks[j].fontId, _textLines[i].chunks[j].textSlant, _textLines[i].chunks[j].text.encode().c_str());
+ for (uint j = 0; j < _canvas.text[i].chunks.size(); j++)
+ debugN(9, "[%d (%d)] \"%s\" ", _canvas.text[i].chunks[j].fontId, _canvas.text[i].chunks[j].textSlant, _canvas.text[i].chunks[j].text.encode().c_str());
debug(9, "%s", "");
}
}
int MacText::getLineWidth(int line, bool enforce, int col) {
- if ((uint)line >= _textLines.size())
+ if ((uint)line >= _canvas.text.size())
return 0;
- return getLineWidth(&_textLines[line], enforce, col);
+ return getLineWidth(&_canvas.text[line], enforce, col);
}
int MacText::getLineWidth(MacTextLine *line, bool enforce, int col) {
@@ -1263,38 +1263,38 @@ int MacText::getLineWidth(MacTextLine *line, bool enforce, int col) {
}
int MacText::getLineCharWidth(int line, bool enforce) {
- if ((uint)line >= _textLines.size())
+ if ((uint)line >= _canvas.text.size())
return 0;
- if (_textLines[line].charwidth != -1 && !enforce)
- return _textLines[line].charwidth;
+ if (_canvas.text[line].charwidth != -1 && !enforce)
+ return _canvas.text[line].charwidth;
int width = 0;
- for (uint i = 0; i < _textLines[line].chunks.size(); i++) {
- if (!_textLines[line].chunks[i].text.empty())
- width += _textLines[line].chunks[i].text.size();
+ for (uint i = 0; i < _canvas.text[line].chunks.size(); i++) {
+ if (!_canvas.text[line].chunks[i].text.empty())
+ width += _canvas.text[line].chunks[i].text.size();
}
- _textLines[line].charwidth = width;
+ _canvas.text[line].charwidth = width;
return width;
}
int MacText::getLastLineWidth() {
- if (_textLines.size() == 0)
+ if (_canvas.text.size() == 0)
return 0;
- return getLineWidth(_textLines.size() - 1, true);
+ return getLineWidth(_canvas.text.size() - 1, true);
}
int MacText::getLineHeight(int line) {
- if ((uint)line >= _textLines.size())
+ if ((uint)line >= _canvas.text.size())
return 0;
getLineWidth(line); // This calculates height also
- return _textLines[line].height;
+ return _canvas.text[line].height;
}
void MacText::setInterLinear(int interLinear) {
@@ -1307,14 +1307,14 @@ void MacText::setInterLinear(int interLinear) {
}
void MacText::recalcDims() {
- if (_textLines.empty())
+ if (_canvas.text.empty())
return;
int y = 0;
_textMaxWidth = 0;
- for (uint i = 0; i < _textLines.size(); i++) {
- _textLines[i].y = y;
+ for (uint i = 0; i < _canvas.text.size(); i++) {
+ _canvas.text[i].y = y;
// We must calculate width first, because it enforces
// the computation. Calling Height() will return cached value!
@@ -1429,17 +1429,17 @@ void MacText::appendText(const Common::U32String &str, int fontId, int fontSize,
}
void MacText::appendText(const Common::U32String &str, int fontId, int fontSize, int fontSlant, uint16 r, uint16 g, uint16 b, bool skipAdd) {
- uint oldLen = _textLines.size();
+ uint oldLen = _canvas.text.size();
MacFontRun fontRun = MacFontRun(_wm, fontId, fontSlant, fontSize, r, g, b);
_currentFormatting = fontRun;
- // we check _str here, if _str is empty but _textLines is not empty, and they are not the end of paragraph
+ // we check _str here, if _str is empty but _canvas.text is not empty, and they are not the end of paragraph
// then we remove those empty lines
// too many special check may cause some strange problem in the future
if (_str.empty()) {
- while (!_textLines.empty() && !_textLines.back().paragraphEnd)
+ while (!_canvas.text.empty() && !_canvas.text.back().paragraphEnd)
removeLastLine();
}
@@ -1453,14 +1453,14 @@ void MacText::appendText(const Common::U32String &str, int fontId, int fontSize,
}
void MacText::appendText(const Common::U32String &str, const Font *font, uint16 r, uint16 g, uint16 b, bool skipAdd) {
- uint oldLen = _textLines.size();
+ uint oldLen = _canvas.text.size();
MacFontRun fontRun = MacFontRun(_wm, font, 0, font->getFontHeight(), r, g, b);
_currentFormatting = fontRun;
if (_str.empty()) {
- while (!_textLines.empty() && !_textLines.back().paragraphEnd)
+ while (!_canvas.text.empty() && !_canvas.text.back().paragraphEnd)
removeLastLine();
}
@@ -1476,7 +1476,7 @@ void MacText::appendText_(const Common::U32String &strWithFont, uint oldLen) {
splitString(strWithFont);
recalcDims();
- render(oldLen - 1, _textLines.size());
+ render(oldLen - 1, _canvas.text.size());
_contentIsDirty = true;
@@ -1491,7 +1491,7 @@ void MacText::appendText_(const Common::U32String &strWithFont, uint oldLen) {
}
void MacText::appendTextDefault(const Common::U32String &str, bool skipAdd) {
- uint oldLen = _textLines.size();
+ uint oldLen = _canvas.text.size();
_currentFormatting = _defaultFormatting;
Common::U32String strWithFont = Common::U32String(_defaultFormatting.toString()) + str;
@@ -1502,7 +1502,7 @@ void MacText::appendTextDefault(const Common::U32String &str, bool skipAdd) {
splitString(strWithFont);
recalcDims();
- render(oldLen - 1, _textLines.size());
+ render(oldLen - 1, _canvas.text.size());
}
void MacText::appendTextDefault(const Common::String &str, bool skipAdd) {
@@ -1511,7 +1511,7 @@ void MacText::appendTextDefault(const Common::String &str, bool skipAdd) {
void MacText::clearText() {
_contentIsDirty = true;
- _textLines.clear();
+ _canvas.text.clear();
_str.clear();
if (_surface)
@@ -1524,19 +1524,19 @@ void MacText::clearText() {
}
void MacText::removeLastLine() {
- if (!_textLines.size())
+ if (!_canvas.text.size())
return;
- int h = getLineHeight(_textLines.size() - 1) + _interLinear;
+ int h = getLineHeight(_canvas.text.size() - 1) + _interLinear;
_surface->fillRect(Common::Rect(0, _textMaxHeight - h, _surface->w, _textMaxHeight), _bgcolor);
- _textLines.pop_back();
+ _canvas.text.pop_back();
_textMaxHeight -= h;
}
void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff) {
- if (_textLines.empty())
+ if (_canvas.text.empty())
return;
render();
@@ -1615,7 +1615,7 @@ bool MacText::draw(ManagedSurface *g, bool forceRedraw) {
}
void MacText::drawToPoint(ManagedSurface *g, Common::Rect srcRect, Common::Point dstPoint) {
- if (_textLines.empty())
+ if (_canvas.text.empty())
return;
render();
@@ -1629,7 +1629,7 @@ void MacText::drawToPoint(ManagedSurface *g, Common::Rect srcRect, Common::Point
}
void MacText::drawToPoint(ManagedSurface *g, Common::Point dstPoint) {
- if (_textLines.empty())
+ if (_canvas.text.empty())
return;
render();
@@ -1695,7 +1695,7 @@ void MacText::drawSelection(int xoff, int yoff) {
end = MIN((int)maxSelectionHeight, end);
// if we are selecting all text, then we invert the whole area
- if ((uint)s.endRow == _textLines.size() - 1)
+ if ((uint)s.endRow == _canvas.text.size() - 1)
end = maxSelectionHeight;
int numLines = 0;
@@ -1730,7 +1730,7 @@ void MacText::drawSelection(int xoff, int yoff) {
end = MIN(end, maxSelectionHeight - yoff);
for (int y = start; y < end; y++) {
- if (!numLines && (uint)row < _textLines.size()) {
+ if (!numLines && (uint)row < _canvas.text.size()) {
x1 = 0;
x2 = maxSelectionWidth;
@@ -1815,16 +1815,16 @@ void MacText::setSelection(int pos, bool start) {
if (pos > 0) {
while (pos > 0) {
if (pos < getLineCharWidth(row)) {
- for (uint i = 0; i < _textLines[row].chunks.size(); i++) {
- if ((uint)pos < _textLines[row].chunks[i].text.size()) {
- colX += getStringWidth(_textLines[row].chunks[i], _textLines[row].chunks[i].text.substr(0, pos));
+ for (uint i = 0; i < _canvas.text[row].chunks.size(); i++) {
+ if ((uint)pos < _canvas.text[row].chunks[i].text.size()) {
+ colX += getStringWidth(_canvas.text[row].chunks[i], _canvas.text[row].chunks[i].text.substr(0, pos));
col += pos;
pos = 0;
break;
} else {
- colX += getStringWidth(_textLines[row].chunks[i], _textLines[row].chunks[i].text);
- pos -= _textLines[row].chunks[i].text.size();
- col += _textLines[row].chunks[i].text.size();
+ colX += getStringWidth(_canvas.text[row].chunks[i], _canvas.text[row].chunks[i].text);
+ pos -= _canvas.text[row].chunks[i].text.size();
+ col += _canvas.text[row].chunks[i].text.size();
}
}
break;
@@ -1833,8 +1833,8 @@ void MacText::setSelection(int pos, bool start) {
}
row++;
- if ((uint)row >= _textLines.size()) {
- row = _textLines.size() - 1;
+ if ((uint)row >= _canvas.text.size()) {
+ row = _canvas.text.size() - 1;
colX = _surface->w;
col = getLineCharWidth(row);
@@ -1844,7 +1844,7 @@ void MacText::setSelection(int pos, bool start) {
} else if (pos == 0) {
colX = col = row = 0;
} else {
- row = _textLines.size() - 1;
+ row = _canvas.text.size() - 1;
col = getLineCharWidth(row);
// if we don't have any text, then we won't select the whole area.
if (_textMaxWidth == 0)
@@ -1853,7 +1853,7 @@ void MacText::setSelection(int pos, bool start) {
colX = _textMaxWidth;
}
- int rowY = _textLines[row].y;
+ int rowY = _canvas.text[row].y;
if (start) {
_selectedText.startX = colX;
@@ -1884,9 +1884,9 @@ Common::U32String MacText::getEditedString() {
Common::U32String MacText::getPlainText() {
Common::U32String res;
- for (uint i = 0; i < _textLines.size(); i++) {
- for (uint j = 0; j < _textLines[i].chunks.size(); j++) {
- res += _textLines[i].chunks[j].text;
+ for (uint i = 0; i < _canvas.text.size(); i++) {
+ for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
+ res += _canvas.text[i].chunks[j].text;
}
}
@@ -1995,7 +1995,7 @@ bool MacText::processEvent(Common::Event &event) {
_cursorRow--;
- getRowCol(_cursorX, _textLines[_cursorRow].y, nullptr, nullptr, &_cursorRow, &_cursorCol);
+ getRowCol(_cursorX, _canvas.text[_cursorRow].y, nullptr, nullptr, &_cursorRow, &_cursorCol);
updateCursorPos();
return true;
@@ -2006,7 +2006,7 @@ bool MacText::processEvent(Common::Event &event) {
_cursorRow++;
- getRowCol(_cursorX, _textLines[_cursorRow].y, nullptr, nullptr, &_cursorRow, &_cursorCol);
+ getRowCol(_cursorX, _canvas.text[_cursorRow].y, nullptr, nullptr, &_cursorRow, &_cursorCol);
updateCursorPos();
return true;
@@ -2138,7 +2138,7 @@ void MacText::scroll(int delta) {
}
void MacText::startMarking(int x, int y) {
- if (_textLines.size() == 0)
+ if (_canvas.text.size() == 0)
return;
Common::Point offset = calculateOffset();
@@ -2198,21 +2198,21 @@ int MacText::getMouseWord(int x, int y) {
int index = 0;
for (int i = 0; i < row; i++) {
- for (uint j = 0; j < _textLines[i].chunks.size(); j++) {
- if (_textLines[i].chunks[j].text.empty())
+ for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
+ if (_canvas.text[i].chunks[j].text.empty())
continue;
index++;
}
}
int cur = 0;
- for (uint j = 0; j < _textLines[row].chunks.size(); j++) {
- if (_textLines[row].chunks[j].text.empty())
+ for (uint j = 0; j < _canvas.text[row].chunks.size(); j++) {
+ if (_canvas.text[row].chunks[j].text.empty())
continue;
- cur += _textLines[row].chunks[j].text.size();
+ cur += _canvas.text[row].chunks[j].text.size();
// Avoid overflowing the word index if we run out of line;
// it should count as part of the last chunk
- if ((cur <= col) && (j < _textLines[row].chunks.size() - 1))
+ if ((cur <= col) && (j < _canvas.text[row].chunks.size() - 1))
index++;
else
break;
@@ -2232,24 +2232,24 @@ int MacText::getMouseItem(int x, int y) {
int index = 0;
for (int i = 0; i < row; i++) {
- for (uint j = 0; j < _textLines[i].chunks.size(); j++) {
- if (_textLines[i].chunks[j].text.empty())
+ for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
+ if (_canvas.text[i].chunks[j].text.empty())
continue;
- if (_textLines[i].chunks[j].getEncodedText().contains(','))
+ if (_canvas.text[i].chunks[j].getEncodedText().contains(','))
index++;
}
}
int cur = 0;
- for (uint i = 0; i < _textLines[row].chunks.size(); i++) {
- if (_textLines[row].chunks[i].text.empty())
+ for (uint i = 0; i < _canvas.text[row].chunks.size(); i++) {
+ if (_canvas.text[row].chunks[i].text.empty())
continue;
- for (uint j = 0; j < _textLines[row].chunks[i].text.size(); j++) {
+ for (uint j = 0; j < _canvas.text[row].chunks[i].text.size(); j++) {
cur++;
if (cur > col)
break;
- if (_textLines[row].chunks[i].text[j] == ',')
+ if (_canvas.text[row].chunks[i].text[j] == ',')
index++;
}
@@ -2284,11 +2284,11 @@ Common::U32String MacText::getMouseLink(int x, int y) {
if (chunk < 0)
return Common::U32String();
- if (!_textLines[row].picfname.empty())
- return _textLines[row].pictitle;
+ if (!_canvas.text[row].picfname.empty())
+ return _canvas.text[row].pictitle;
- if (!_textLines[row].chunks[chunk].link.empty())
- return _textLines[row].chunks[chunk].link;
+ if (!_canvas.text[row].chunks[chunk].link.empty())
+ return _canvas.text[row].chunks[chunk].link;
return Common::U32String();
}
@@ -2311,12 +2311,12 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col, int
y = CLIP(y, 0, _textMaxHeight);
- nrow = _textLines.size();
+ nrow = _canvas.text.size();
// use [lb, ub) bsearch here, final answer would be lb
int lb = 0, ub = nrow;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
- if (_textLines[mid].y <= y) {
+ if (_canvas.text[mid].y <= y) {
lb = mid;
} else {
ub = mid;
@@ -2324,40 +2324,40 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col, int
}
nrow = lb;
- nsy = _textLines[nrow].y;
+ nsy = _canvas.text[nrow].y;
int chunk = -1;
- if (_textLines[nrow].chunks.size() > 0) {
- int alignOffset = getAlignOffset(nrow) + _textLines[nrow].indent + _textLines[nrow].firstLineIndent;;
+ if (_canvas.text[nrow].chunks.size() > 0) {
+ int alignOffset = getAlignOffset(nrow) + _canvas.text[nrow].indent + _canvas.text[nrow].firstLineIndent;;
int width = 0, pwidth = 0;
int mcol = 0, pmcol = 0;
- for (chunk = 0; chunk < (int)_textLines[nrow].chunks.size(); chunk++) {
+ for (chunk = 0; chunk < (int)_canvas.text[nrow].chunks.size(); chunk++) {
pwidth = width;
pmcol = mcol;
- if (!_textLines[nrow].chunks[chunk].text.empty()) {
- width += getStringWidth(_textLines[nrow].chunks[chunk], _textLines[nrow].chunks[chunk].text);
- mcol += _textLines[nrow].chunks[chunk].text.size();
+ if (!_canvas.text[nrow].chunks[chunk].text.empty()) {
+ width += getStringWidth(_canvas.text[nrow].chunks[chunk], _canvas.text[nrow].chunks[chunk].text);
+ mcol += _canvas.text[nrow].chunks[chunk].text.size();
}
if (width + alignOffset > x)
break;
}
- if (chunk >= (int)_textLines[nrow].chunks.size())
- chunk = _textLines[nrow].chunks.size() - 1;
+ if (chunk >= (int)_canvas.text[nrow].chunks.size())
+ chunk = _canvas.text[nrow].chunks.size() - 1;
if (chunk_)
*chunk_ = (int)chunk;
- Common::U32String str = _textLines[nrow].chunks[chunk].text;
+ Common::U32String str = _canvas.text[nrow].chunks[chunk].text;
ncol = mcol;
nsx = pwidth;
for (int i = str.size(); i >= 0; i--) {
- int strw = getStringWidth(_textLines[nrow].chunks[chunk], str);
+ int strw = getStringWidth(_canvas.text[nrow].chunks[chunk], str);
if (strw + pwidth + alignOffset <= x) {
ncol = pmcol + i;
nsx = strw + pwidth;
@@ -2384,7 +2384,7 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col, int
// This happens when a long paragraph is split into several lines
#define ADDFORMATTING() \
if (formatted) { \
- formatting = Common::U32String(_textLines[i].chunks[chunk].toString()); \
+ formatting = Common::U32String(_canvas.text[i].chunks[chunk].toString()); \
if (formatting != prevformatting) { \
res += formatting; \
prevformatting = formatting; \
@@ -2395,24 +2395,24 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
Common::U32String res("");
if (endRow == -1)
- endRow = _textLines.size() - 1;
+ endRow = _canvas.text.size() - 1;
if (endCol == -1)
endCol = getLineCharWidth(endRow);
- if (_textLines.empty()) {
+ if (_canvas.text.empty()) {
return res;
}
- startRow = CLIP(startRow, 0, (int)_textLines.size() - 1);
- endRow = CLIP(endRow, 0, (int)_textLines.size() - 1);
+ startRow = CLIP(startRow, 0, (int)_canvas.text.size() - 1);
+ endRow = CLIP(endRow, 0, (int)_canvas.text.size() - 1);
Common::U32String formatting(""), prevformatting("");
for (int i = startRow; i <= endRow; i++) {
// We requested only part of one line
if (i == startRow && i == endRow) {
- for (uint chunk = 0; chunk < _textLines[i].chunks.size(); chunk++) {
- if (_textLines[i].chunks[chunk].text.empty()) {
+ for (uint chunk = 0; chunk < _canvas.text[i].chunks.size(); chunk++) {
+ if (_canvas.text[i].chunks[chunk].text.empty()) {
// skip empty chunks, but keep them formatted,
// a text input box needs to keep the formatting even when all text is removed.
ADDFORMATTING();
@@ -2422,68 +2422,68 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
if (startCol <= 0) {
ADDFORMATTING();
- if (endCol >= (int)_textLines[i].chunks[chunk].text.size())
- res += _textLines[i].chunks[chunk].text;
+ if (endCol >= (int)_canvas.text[i].chunks[chunk].text.size())
+ res += _canvas.text[i].chunks[chunk].text;
else
- res += _textLines[i].chunks[chunk].text.substr(0, endCol);
- } else if ((int)_textLines[i].chunks[chunk].text.size() > startCol) {
+ res += _canvas.text[i].chunks[chunk].text.substr(0, endCol);
+ } else if ((int)_canvas.text[i].chunks[chunk].text.size() > startCol) {
ADDFORMATTING();
- res += _textLines[i].chunks[chunk].text.substr(startCol, endCol - startCol);
+ res += _canvas.text[i].chunks[chunk].text.substr(startCol, endCol - startCol);
}
- startCol -= _textLines[i].chunks[chunk].text.size();
- endCol -= _textLines[i].chunks[chunk].text.size();
+ startCol -= _canvas.text[i].chunks[chunk].text.size();
+ endCol -= _canvas.text[i].chunks[chunk].text.size();
if (endCol <= 0)
break;
}
// We are at the top line and it is not completely requested
} else if (i == startRow && startCol != 0) {
- for (uint chunk = 0; chunk < _textLines[i].chunks.size(); chunk++) {
- if (_textLines[i].chunks[chunk].text.empty()) // skip empty chunks
+ for (uint chunk = 0; chunk < _canvas.text[i].chunks.size(); chunk++) {
+ if (_canvas.text[i].chunks[chunk].text.empty()) // skip empty chunks
continue;
if (startCol <= 0) {
ADDFORMATTING();
- res += _textLines[i].chunks[chunk].text;
- } else if ((int)_textLines[i].chunks[chunk].text.size() > startCol) {
+ res += _canvas.text[i].chunks[chunk].text;
+ } else if ((int)_canvas.text[i].chunks[chunk].text.size() > startCol) {
ADDFORMATTING();
- res += _textLines[i].chunks[chunk].text.substr(startCol);
+ res += _canvas.text[i].chunks[chunk].text.substr(startCol);
}
- startCol -= _textLines[i].chunks[chunk].text.size();
+ startCol -= _canvas.text[i].chunks[chunk].text.size();
}
- if (newlines && _textLines[i].paragraphEnd)
+ if (newlines && _canvas.text[i].paragraphEnd)
res += '\n';
// We are at the end row, and it could be not completely requested
} else if (i == endRow) {
- for (uint chunk = 0; chunk < _textLines[i].chunks.size(); chunk++) {
- if (_textLines[i].chunks[chunk].text.empty()) // skip empty chunks
+ for (uint chunk = 0; chunk < _canvas.text[i].chunks.size(); chunk++) {
+ if (_canvas.text[i].chunks[chunk].text.empty()) // skip empty chunks
continue;
ADDFORMATTING();
- if (endCol >= (int)_textLines[i].chunks[chunk].text.size())
- res += _textLines[i].chunks[chunk].text;
+ if (endCol >= (int)_canvas.text[i].chunks[chunk].text.size())
+ res += _canvas.text[i].chunks[chunk].text;
else
- res += _textLines[i].chunks[chunk].text.substr(0, endCol);
+ res += _canvas.text[i].chunks[chunk].text.substr(0, endCol);
- endCol -= _textLines[i].chunks[chunk].text.size();
+ endCol -= _canvas.text[i].chunks[chunk].text.size();
if (endCol <= 0)
break;
}
// We are in the middle of requested range, pass whole line
} else {
- for (uint chunk = 0; chunk < _textLines[i].chunks.size(); chunk++) {
- if (_textLines[i].chunks[chunk].text.empty()) // skip empty chunks
+ for (uint chunk = 0; chunk < _canvas.text[i].chunks.size(); chunk++) {
+ if (_canvas.text[i].chunks[chunk].text.empty()) // skip empty chunks
continue;
ADDFORMATTING();
- res += _textLines[i].chunks[chunk].text;
+ res += _canvas.text[i].chunks[chunk].text;
}
- if (newlines && _textLines[i].paragraphEnd)
+ if (newlines && _canvas.text[i].paragraphEnd)
res += '\n';
}
}
@@ -2496,15 +2496,15 @@ void MacText::insertTextFromClipboard() {
int ppos = 0;
Common::U32String str = _wm->getTextFromClipboard(Common::U32String(_defaultFormatting.toString()), &ppos);
- if (_textLines.empty()) {
+ if (_canvas.text.empty()) {
splitString(str, 0);
} else {
int start = _cursorRow, end = _cursorRow;
- while (start && !_textLines[start - 1].paragraphEnd)
+ while (start && !_canvas.text[start - 1].paragraphEnd)
start--;
- while (end < (int)_textLines.size() - 1 && !_textLines[end].paragraphEnd)
+ while (end < (int)_canvas.text.size() - 1 && !_canvas.text[end].paragraphEnd)
end++;
for (int i = start; i < _cursorRow; i++)
@@ -2516,7 +2516,7 @@ void MacText::insertTextFromClipboard() {
// Remove it from the text
for (int i = start; i <= end; i++) {
- _textLines.remove_at(start);
+ _canvas.text.remove_at(start);
}
splitString(pre_str + str + sub_str, start);
@@ -2536,7 +2536,7 @@ void MacText::insertTextFromClipboard() {
void MacText::setText(const Common::U32String &str) {
_str = str;
- _textLines.clear();
+ _canvas.text.clear();
splitString(_str);
_cursorRow = _cursorCol = 0;
@@ -2556,14 +2556,14 @@ void MacText::setText(const Common::U32String &str) {
//////////////////
// Text editing
void MacText::insertChar(byte c, int *row, int *col) {
- if (_textLines.empty()) {
+ if (_canvas.text.empty()) {
appendTextDefault(Common::String(c));
(*col)++;
return;
}
- MacTextLine *line = &_textLines[*row];
+ MacTextLine *line = &_canvas.text[*row];
int pos = *col;
uint ch = line->getChunkNum(&pos);
@@ -2590,10 +2590,10 @@ void MacText::insertChar(byte c, int *row, int *col) {
recalcDims();
render(*row, *row);
}
- for (int i = 0; i < (int)_textLines.size(); i++) {
- D(9, "**insertChar line %d isEnd %d", i, _textLines[i].paragraphEnd);
- for (int j = 0; j < (int)_textLines[i].chunks.size(); j++) {
- D(9, "[%d] \"%s\"",_textLines[i].chunks[j].text.size(), Common::toPrintable(_textLines[i].chunks[j].text.encode()).c_str());
+ for (int i = 0; i < (int)_canvas.text.size(); i++) {
+ D(9, "**insertChar line %d isEnd %d", i, _canvas.text[i].paragraphEnd);
+ for (int j = 0; j < (int)_canvas.text[i].chunks.size(); j++) {
+ D(9, "[%d] \"%s\"",_canvas.text[i].chunks[j].text.size(), Common::toPrintable(_canvas.text[i].chunks[j].text.encode()).c_str());
}
}
D(9, "**insertChar cursor row %d col %d", _cursorRow, _cursorCol);
@@ -2640,33 +2640,33 @@ void MacText::deletePreviousCharInternal(int *row, int *col) {
(*row)--;
// formatting matches, glue texts as normal
- if (_textLines[*row].lastChunk().equals(_textLines[*row + 1].firstChunk())) {
- _textLines[*row].lastChunk().text += _textLines[*row + 1].firstChunk().text;
- _textLines[*row + 1].firstChunk().text.clear();
+ if (_canvas.text[*row].lastChunk().equals(_canvas.text[*row + 1].firstChunk())) {
+ _canvas.text[*row].lastChunk().text += _canvas.text[*row + 1].firstChunk().text;
+ _canvas.text[*row + 1].firstChunk().text.clear();
} else {
// formatting doesn't match, move whole chunk
- _textLines[*row].chunks.push_back(MacFontRun(_textLines[*row + 1].firstChunk()));
- _textLines[*row].firstChunk().text.clear();
+ _canvas.text[*row].chunks.push_back(MacFontRun(_canvas.text[*row + 1].firstChunk()));
+ _canvas.text[*row].firstChunk().text.clear();
}
- _textLines[*row].paragraphEnd = false;
+ _canvas.text[*row].paragraphEnd = false;
- for (uint i = 1; i < _textLines[*row + 1].chunks.size(); i++)
- _textLines[*row].chunks.push_back(MacFontRun(_textLines[*row + 1].chunks[i]));
+ for (uint i = 1; i < _canvas.text[*row + 1].chunks.size(); i++)
+ _canvas.text[*row].chunks.push_back(MacFontRun(_canvas.text[*row + 1].chunks[i]));
- _textLines.remove_at(*row + 1);
+ _canvas.text.remove_at(*row + 1);
} else {
int pos = *col - 1;
- uint ch = _textLines[*row].getChunkNum(&pos);
+ uint ch = _canvas.text[*row].getChunkNum(&pos);
- if (pos == (int)_textLines[*row].chunks[ch].text.size())
+ if (pos == (int)_canvas.text[*row].chunks[ch].text.size())
pos--;
- _textLines[*row].chunks[ch].text.deleteChar(pos);
+ _canvas.text[*row].chunks[ch].text.deleteChar(pos);
(*col)--;
}
- _textLines[*row].width = -1; // flush the cache
+ _canvas.text[*row].width = -1; // flush the cache
}
void MacText::deletePreviousChar(int *row, int *col) {
@@ -2674,10 +2674,10 @@ void MacText::deletePreviousChar(int *row, int *col) {
return;
deletePreviousCharInternal(row, col);
- for (int i = 0; i < (int)_textLines.size(); i++) {
+ for (int i = 0; i < (int)_canvas.text.size(); i++) {
D(9, "**deleteChar line %d", i);
- for (int j = 0; j < (int)_textLines[i].chunks.size(); j++) {
- D(9, "[%d] \"%s\"",_textLines[i].chunks[j].text.size(), Common::toPrintable(_textLines[i].chunks[j].text.encode()).c_str());
+ for (int j = 0; j < (int)_canvas.text[i].chunks.size(); j++) {
+ D(9, "[%d] \"%s\"",_canvas.text[i].chunks[j].text.size(), Common::toPrintable(_canvas.text[i].chunks[j].text.encode()).c_str());
}
}
D(9, "**deleteChar cursor row %d col %d", _cursorRow, _cursorCol);
@@ -2690,14 +2690,14 @@ void MacText::deletePreviousChar(int *row, int *col) {
}
void MacText::addNewLine(int *row, int *col) {
- if (_textLines.empty()) {
+ if (_canvas.text.empty()) {
appendTextDefault(Common::String("\n"));
(*row)++;
return;
}
- MacTextLine *line = &_textLines[*row];
+ MacTextLine *line = &_canvas.text[*row];
int pos = *col;
uint ch = line->getChunkNum(&pos);
MacFontRun newchunk = line->chunks[ch];
@@ -2719,19 +2719,19 @@ void MacText::addNewLine(int *row, int *col) {
}
line->width = -1; // Drop cache
- _textLines[*row].width = -1; // flush the cache
+ _canvas.text[*row].width = -1; // flush the cache
- _textLines.insert_at(*row + 1, newline);
+ _canvas.text.insert_at(*row + 1, newline);
(*row)++;
*col = 0;
reshuffleParagraph(row, col);
- for (int i = 0; i < (int)_textLines.size(); i++) {
+ for (int i = 0; i < (int)_canvas.text.size(); i++) {
D(9, "** addNewLine line %d", i);
- for (int j = 0; j < (int)_textLines[i].chunks.size(); j++) {
- D(9, "[%d] \"%s\"",_textLines[i].chunks[j].text.size(), Common::toPrintable(_textLines[i].chunks[j].text.encode()).c_str());
+ for (int j = 0; j < (int)_canvas.text[i].chunks.size(); j++) {
+ D(9, "[%d] \"%s\"",_canvas.text[i].chunks[j].text.size(), Common::toPrintable(_canvas.text[i].chunks[j].text.encode()).c_str());
}
}
D(9, "** addNewLine cursor row %d col %d", _cursorRow, _cursorCol);
@@ -2745,10 +2745,10 @@ void MacText::reshuffleParagraph(int *row, int *col) {
// First, we looking for the paragraph start and end
int start = *row, end = *row;
- while (start && !_textLines[start - 1].paragraphEnd)
+ while (start && !_canvas.text[start - 1].paragraphEnd)
start--;
- while (end < (int)_textLines.size() - 1 && !_textLines[end].paragraphEnd) // stop at last line
+ while (end < (int)_canvas.text.size() - 1 && !_canvas.text[end].paragraphEnd) // stop at last line
end++;
// Get character pos within paragraph
@@ -2764,7 +2764,7 @@ void MacText::reshuffleParagraph(int *row, int *col) {
// Remove it from the text
for (int i = start; i <= end; i++) {
- _textLines.remove_at(start);
+ _canvas.text.remove_at(start);
}
// And now read it
@@ -2793,16 +2793,16 @@ static void cursorTimerHandler(void *refCon) {
}
void MacText::updateCursorPos() {
- if (_textLines.empty()) {
+ if (_canvas.text.empty()) {
_cursorX = _cursorY = 0;
} else {
undrawCursor();
- _cursorRow = MIN<int>(_cursorRow, _textLines.size() - 1);
+ _cursorRow = MIN<int>(_cursorRow, _canvas.text.size() - 1);
int alignOffset = getAlignOffset(_cursorRow);
- _cursorY = _textLines[_cursorRow].y - _scrollPos;
+ _cursorY = _canvas.text[_cursorRow].y - _scrollPos;
_cursorX = getLineWidth(_cursorRow, false, _cursorCol) + alignOffset;
}
@@ -2869,7 +2869,7 @@ const Surface *MacText::getImageSurface(Common::String &fname) {
}
void MacText::processTable(int line) {
- Common::Array<MacTextTableRow> *table = _textLines[line].table;
+ Common::Array<MacTextTableRow> *table = _canvas.text[line].table;
uint numCols = table->front().cells.size();
Common::Array<int> maxW(numCols), maxL(numCols), colW(numCols);
Common::Array<bool> flex(numCols), wrap(numCols);
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 50073f3ae35..81b0c1dd00e 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -119,15 +119,16 @@ struct MacFontRun {
struct MacTextLine;
-struct MacTextTableCell {
+struct MacTextCanvas {
Common::Array<MacTextLine> text;
uint16 flags = 0;
- ManagedSurface surf;
+ ManagedSurface *surface = nullptr, *shadowSurface = nullptr;
int textWidth = -1;
+ int textMaxHeigh = 0;
};
struct MacTextTableRow {
- Common::Array<MacTextTableCell> cells;
+ Common::Array<MacTextCanvas> cells;
int heght = -1;
};
@@ -273,7 +274,7 @@ public:
void appendTextDefault(const Common::String &str, bool skipAdd = false);
void clearText();
void removeLastLine();
- int getLineCount() { return _textLines.size(); }
+ int getLineCount() { return _canvas.text.size(); }
int getLineCharWidth(int line, bool enforce = false);
int getLastLineWidth();
int getTextHeight() { return _textMaxHeight; }
@@ -399,7 +400,8 @@ protected:
TextAlign _textAlignment;
- Common::Array<MacTextLine> _textLines;
+ MacTextCanvas _canvas;
+
MacFontRun _defaultFormatting;
MacFontRun _currentFormatting;
Commit: b2fb4dcb3bc9c896ad4d94d3d888ce96955d79be
https://github.com/scummvm/scummvm/commit/b2fb4dcb3bc9c896ad4d94d3d888ce96955d79be
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-09T00:22:14+02:00
Commit Message:
GRAPHUCS: MACGUI: Moved more variables to MacTextCanvas
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 620d2d608d6..cfac74d37a6 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -119,7 +119,7 @@ uint MacTextLine::getChunkNum(int *col) {
MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::U32String &s, const MacFont *macFont, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, uint16 border, uint16 gutter, uint16 boxShadow, uint16 textShadow, bool fixedDims) :
MacWidget(parent, x, y, w, h, wm, true, border, gutter, boxShadow),
- _macFont(macFont), _maxWidth(maxWidth), _textAlignment(textAlignment), _interLinear(interlinear) {
+ _macFont(macFont), _textAlignment(textAlignment), _interLinear(interlinear) {
D(6, "MacText::MacText(): fgcolor: %d, bgcolor: %d s: \"%s\"", fgcolor, bgcolor, Common::toPrintable(s.encode()).c_str());
@@ -133,6 +133,8 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
_textShadow = textShadow;
_macFontMode = true;
+ _canvas.maxWidth = maxWidth;
+
if (macFont) {
_defaultFormatting = MacFontRun(_wm);
_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
@@ -149,7 +151,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
// NOTE: This constructor and the one afterward are for MacText engines that don't use widgets. This is the classic was MacText was constructed.
MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont *macFont, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, bool fixedDims) :
MacWidget(nullptr, 0, 0, 0, 0, wm, false, 0, 0, 0),
- _macFont(macFont), _maxWidth(maxWidth), _textAlignment(textAlignment), _interLinear(interlinear) {
+ _macFont(macFont), _textAlignment(textAlignment), _interLinear(interlinear) {
_str = s;
@@ -160,6 +162,8 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
_textShadow = 0;
_macFontMode = true;
+ _canvas.maxWidth = maxWidth;
+
if (macFont) {
_defaultFormatting = MacFontRun(_wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
@@ -176,7 +180,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
// Working with plain Font
MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *font, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, bool fixedDims) :
MacWidget(nullptr, 0, 0, 0, 0, wm, false, 0, 0, 0),
- _macFont(nullptr), _maxWidth(maxWidth), _textAlignment(textAlignment), _interLinear(interlinear) {
+ _macFont(nullptr), _textAlignment(textAlignment), _interLinear(interlinear) {
_str = s;
@@ -187,6 +191,8 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *f
_textShadow = 0;
_macFontMode = false;
+ _canvas.maxWidth = maxWidth;
+
if (font) {
_defaultFormatting = MacFontRun(_wm, font, 0, font->getFontHeight(), 0, 0, 0);
_defaultFormatting.font = font;
@@ -200,14 +206,14 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *f
void MacText::init() {
_fullRefresh = true;
- _textMaxWidth = 0;
- _textMaxHeight = 0;
- _surface = nullptr;
- _shadowSurface = nullptr;
+ _canvas.textMaxWidth = 0;
+ _canvas.textMaxHeight = 0;
+ _canvas.surface = nullptr;
+ _canvas.shadowSurface = nullptr;
if (!_fixedDims) {
int right = _dims.right;
- _dims.right = MAX<int>(_dims.right, _dims.left + _maxWidth + (2 * _border) + (2 * _gutter) + _shadow);
+ _dims.right = MAX<int>(_dims.right, _dims.left + _canvas.maxWidth + (2 * _border) + (2 * _gutter) + _shadow);
if (right != _dims.right) {
delete _composeSurface;
_composeSurface = new ManagedSurface(_dims.width(), _dims.height(), _wm->_pixelformat);
@@ -272,8 +278,6 @@ MacText::~MacText() {
_wm->setActiveWidget(nullptr);
delete _cursorRect;
- delete _surface;
- delete _shadowSurface;
delete _cursorSurface;
delete _cursorSurface2;
@@ -335,7 +339,7 @@ int MacText::getStringMaxWordWidth(MacFontRun &format, const Common::U32String &
void MacText::setMaxWidth(int maxWidth) {
- if (maxWidth == _maxWidth)
+ if (maxWidth == _canvas.maxWidth)
return;
if (maxWidth < 0) {
@@ -351,7 +355,7 @@ void MacText::setMaxWidth(int maxWidth) {
ppos += getLineCharWidth(i);
ppos += _cursorCol;
- _maxWidth = maxWidth;
+ _canvas.maxWidth = maxWidth;
_canvas.text.clear();
splitString(str);
@@ -592,7 +596,7 @@ void MacText::setDefaultFormatting(uint16 fontId, byte textSlant, uint16 fontSiz
}
// Adds the given string to the end of the last line/chunk
-// while observing the _maxWidth and keeping this chunk's
+// while observing the _canvas.maxWidth and keeping this chunk's
// formatting
void MacText::chopChunk(const Common::U32String &str, int *curLinePtr, int indent, int maxWidth) {
int curLine = *curLinePtr;
@@ -759,7 +763,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
// Okay, now we are either at the end of the line, or in the next
// chunk definition. That means, that we have to store the previous chunk
- chopChunk(tmp, &curLine, indentSize, _inTable ? -1 : _maxWidth);
+ chopChunk(tmp, &curLine, indentSize, _inTable ? -1 : _canvas.maxWidth);
curTextLine = &_canvas.text[curLine];
@@ -1037,41 +1041,41 @@ void MacText::reallocSurface() {
//TODO: work out why this rounding doesn't correctly fill the entire width
//int requiredH = (_text.size() + (_text.size() * 10 + 9) / 10) * lineH
- if (!_surface) {
- _surface = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
+ if (!_canvas.surface) {
+ _canvas.surface = new ManagedSurface(_canvas.maxWidth, _canvas.textMaxHeight, _wm->_pixelformat);
if (_textShadow)
- _shadowSurface = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
+ _canvas.shadowSurface = new ManagedSurface(_canvas.maxWidth, _canvas.textMaxHeight, _wm->_pixelformat);
return;
}
- if (_surface->w < _maxWidth || _surface->h < _textMaxHeight) {
+ if (_canvas.surface->w < _canvas.maxWidth || _canvas.surface->h < _canvas.textMaxHeight) {
// realloc surface and copy old content
- ManagedSurface *n = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
+ ManagedSurface *n = new ManagedSurface(_canvas.maxWidth, _canvas.textMaxHeight, _wm->_pixelformat);
n->clear(_bgcolor);
- n->blitFrom(*_surface, Common::Point(0, 0));
+ n->blitFrom(*_canvas.surface, Common::Point(0, 0));
- delete _surface;
- _surface = n;
+ delete _canvas.surface;
+ _canvas.surface = n;
// same as shadow surface
if (_textShadow) {
- ManagedSurface *newShadowSurface = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
+ ManagedSurface *newShadowSurface = new ManagedSurface(_canvas.maxWidth, _canvas.textMaxHeight, _wm->_pixelformat);
newShadowSurface->clear(_bgcolor);
- newShadowSurface->blitFrom(*_shadowSurface, Common::Point(0, 0));
+ newShadowSurface->blitFrom(*_canvas.shadowSurface, Common::Point(0, 0));
- delete _shadowSurface;
- _shadowSurface = newShadowSurface;
+ delete _canvas.shadowSurface;
+ _canvas.shadowSurface = newShadowSurface;
}
}
}
void MacText::render() {
if (_fullRefresh) {
- _surface->clear(_bgcolor);
+ _canvas.surface->clear(_bgcolor);
if (_textShadow)
- _shadowSurface->clear(_bgcolor);
+ _canvas.shadowSurface->clear(_bgcolor);
render(0, _canvas.text.size());
@@ -1082,15 +1086,15 @@ void MacText::render() {
Common::String filename = Common::String::format("z-%p.png", (void *)this);
if (out.open(filename)) {
warning("Wrote: %s", filename.c_str());
- Image::writePNG(out, _surface->rawSurface());
+ Image::writePNG(out, _canvas.surface->rawSurface());
}
#endif
}
}
void MacText::render(int from, int to, int shadow) {
- int w = MIN(_maxWidth, _textMaxWidth);
- ManagedSurface *surface = shadow ? _shadowSurface : _surface;
+ int w = MIN(_canvas.maxWidth, _canvas.textMaxWidth);
+ ManagedSurface *surface = shadow ? _canvas.shadowSurface : _canvas.surface;
int myFrom = from, myTo = to + 1, delta = 1;
@@ -1128,11 +1132,11 @@ void MacText::render(int from, int to, int shadow) {
maxAscentForRow = _canvas.text[i].chunks[j].font->getFontAscent();
}
- // TODO: _textMaxWidth, when -1, was not rendering ANY text.
+ // TODO: _canvas.textMaxWidth, when -1, was not rendering ANY text.
for (int j = start; j != end; j += delta) {
debug(9, "MacText::render: line %d[%d] h:%d at %d,%d (%s) fontid: %d fontsize: %d on %dx%d, fgcolor: %08x bgcolor: %08x, font: %p",
i, j, _canvas.text[i].height, xOffset, _canvas.text[i].y, _canvas.text[i].chunks[j].text.encode().c_str(),
- _canvas.text[i].chunks[j].fontId, _canvas.text[i].chunks[j].fontSize, _surface->w, _surface->h, _canvas.text[i].chunks[j].fgcolor, _bgcolor,
+ _canvas.text[i].chunks[j].fontId, _canvas.text[i].chunks[j].fontSize, _canvas.surface->w, _canvas.surface->h, _canvas.text[i].chunks[j].fgcolor, _bgcolor,
(const void *)_canvas.text[i].chunks[j].getFont());
if (_canvas.text[i].chunks[j].text.empty())
@@ -1168,7 +1172,7 @@ void MacText::render(int from, int to) {
to = MIN<int>(to, _canvas.text.size() - 1);
// Clear the screen
- _surface->fillRect(Common::Rect(0, _canvas.text[from].y, _surface->w, _canvas.text[to].y + getLineHeight(to)), _bgcolor);
+ _canvas.surface->fillRect(Common::Rect(0, _canvas.text[from].y, _canvas.surface->w, _canvas.text[to].y + getLineHeight(to)), _bgcolor);
// render the shadow surface;
if (_textShadow)
@@ -1201,12 +1205,12 @@ int MacText::getLineWidth(MacTextLine *line, bool enforce, int col) {
const Surface *image = getImageSurface(line->picfname);
if (image) {
- float ratio = _maxWidth * line->picpercent / 100.0 / (float)image->w;
- line->width = _maxWidth;
+ float ratio = _canvas.maxWidth * line->picpercent / 100.0 / (float)image->w;
+ line->width = _canvas.maxWidth;
line->height = image->h * ratio;
line->charwidth = image->w * ratio;
} else {
- line->width = _maxWidth;
+ line->width = _canvas.maxWidth;
line->height = 1;
line->charwidth = 1;
}
@@ -1311,21 +1315,21 @@ void MacText::recalcDims() {
return;
int y = 0;
- _textMaxWidth = 0;
+ _canvas.textMaxWidth = 0;
for (uint i = 0; i < _canvas.text.size(); i++) {
_canvas.text[i].y = y;
// We must calculate width first, because it enforces
// the computation. Calling Height() will return cached value!
- _textMaxWidth = MAX(_textMaxWidth, getLineWidth(i, true));
+ _canvas.textMaxWidth = MAX(_canvas.textMaxWidth, getLineWidth(i, true));
y += MAX(getLineHeight(i), _interLinear);
}
- _textMaxHeight = y;
+ _canvas.textMaxHeight = y;
if (!_fixedDims) {
- int newBottom = _dims.top + _textMaxHeight + (2 * _border) + _gutter + _shadow;
+ int newBottom = _dims.top + _canvas.textMaxHeight + (2 * _border) + _gutter + _shadow;
if (newBottom > _dims.bottom) {
_dims.bottom = newBottom;
delete _composeSurface;
@@ -1409,7 +1413,7 @@ void MacText::setEditable(bool editable) {
}
void MacText::resize(int w, int h) {
- if (_surface->w == w && _surface->h == h)
+ if (_canvas.surface->w == w && _canvas.surface->h == h)
return;
setMaxWidth(w);
@@ -1514,8 +1518,8 @@ void MacText::clearText() {
_canvas.text.clear();
_str.clear();
- if (_surface)
- _surface->clear(_bgcolor);
+ if (_canvas.surface)
+ _canvas.surface->clear(_bgcolor);
recalcDims();
@@ -1529,10 +1533,10 @@ void MacText::removeLastLine() {
int h = getLineHeight(_canvas.text.size() - 1) + _interLinear;
- _surface->fillRect(Common::Rect(0, _textMaxHeight - h, _surface->w, _textMaxHeight), _bgcolor);
+ _canvas.surface->fillRect(Common::Rect(0, _canvas.textMaxHeight - h, _canvas.surface->w, _canvas.textMaxHeight), _bgcolor);
_canvas.text.pop_back();
- _textMaxHeight -= h;
+ _canvas.textMaxHeight -= h;
}
void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff) {
@@ -1541,15 +1545,15 @@ void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int
render();
- if (x + w < _surface->w || y + h < _surface->h)
+ if (x + w < _canvas.surface->w || y + h < _canvas.surface->h)
g->fillRect(Common::Rect(x + xoff, y + yoff, x + w + xoff, y + h + yoff), _bgcolor);
// blit shadow surface first
if (_textShadow)
- g->blitFrom(*_shadowSurface, Common::Rect(MIN<int>(_surface->w, x), MIN<int>(_surface->h, y), MIN<int>(_surface->w, x + w), MIN<int>(_surface->h, y + h)), Common::Point(xoff + _textShadow, yoff + _textShadow));
+ g->blitFrom(*_canvas.shadowSurface, Common::Rect(MIN<int>(_canvas.surface->w, x), MIN<int>(_canvas.surface->h, y), MIN<int>(_canvas.surface->w, x + w), MIN<int>(_canvas.surface->h, y + h)), Common::Point(xoff + _textShadow, yoff + _textShadow));
uint32 bgcolor = _bgcolor < 0xff ? _bgcolor : 0;
- g->transBlitFrom(*_surface, Common::Rect(MIN<int>(_surface->w, x), MIN<int>(_surface->h, y), MIN<int>(_surface->w, x + w), MIN<int>(_surface->h, y + h)), Common::Point(xoff, yoff), bgcolor);
+ g->transBlitFrom(*_canvas.surface, Common::Rect(MIN<int>(_canvas.surface->w, x), MIN<int>(_canvas.surface->h, y), MIN<int>(_canvas.surface->w, x + w), MIN<int>(_canvas.surface->h, y + h)), Common::Point(xoff, yoff), bgcolor);
_contentIsDirty = false;
_cursorDirty = false;
@@ -1559,7 +1563,7 @@ bool MacText::draw(bool forceRedraw) {
if (!needsRedraw() && !forceRedraw)
return false;
- if (!_surface) {
+ if (!_canvas.surface) {
warning("MacText::draw: Null surface");
return false;
}
@@ -1585,7 +1589,7 @@ bool MacText::draw(bool forceRedraw) {
if (!(_contentIsDirty || forceRedraw))
return true;
- draw(_composeSurface, 0, _scrollPos, _surface->w, _scrollPos + _surface->h, offset.x, offset.y);
+ draw(_composeSurface, 0, _scrollPos, _canvas.surface->w, _scrollPos + _canvas.surface->h, offset.x, offset.y);
for (int bb = 0; bb < _shadow; bb++) {
_composeSurface->hLine(_shadow, _composeSurface->h - _shadow + bb, _composeSurface->w, 0);
@@ -1620,12 +1624,12 @@ void MacText::drawToPoint(ManagedSurface *g, Common::Rect srcRect, Common::Point
render();
- srcRect.clip(_surface->getBounds());
+ srcRect.clip(_canvas.surface->getBounds());
if (srcRect.isEmpty())
return;
- g->blitFrom(*_surface, srcRect, dstPoint);
+ g->blitFrom(*_canvas.surface, srcRect, dstPoint);
}
void MacText::drawToPoint(ManagedSurface *g, Common::Point dstPoint) {
@@ -1634,7 +1638,7 @@ void MacText::drawToPoint(ManagedSurface *g, Common::Point dstPoint) {
render();
- g->blitFrom(*_surface, dstPoint);
+ g->blitFrom(*_canvas.surface, dstPoint);
}
// Count newline characters in String
@@ -1835,7 +1839,7 @@ void MacText::setSelection(int pos, bool start) {
row++;
if ((uint)row >= _canvas.text.size()) {
row = _canvas.text.size() - 1;
- colX = _surface->w;
+ colX = _canvas.surface->w;
col = getLineCharWidth(row);
break;
@@ -1847,10 +1851,10 @@ void MacText::setSelection(int pos, bool start) {
row = _canvas.text.size() - 1;
col = getLineCharWidth(row);
// if we don't have any text, then we won't select the whole area.
- if (_textMaxWidth == 0)
+ if (_canvas.textMaxWidth == 0)
colX = 0;
else
- colX = _textMaxWidth;
+ colX = _canvas.textMaxWidth;
}
int rowY = _canvas.text[row].y;
@@ -2296,20 +2300,20 @@ Common::U32String MacText::getMouseLink(int x, int y) {
int MacText::getAlignOffset(int row) {
int alignOffset = 0;
if (_textAlignment == kTextAlignRight)
- alignOffset = MAX<int>(0, _maxWidth - getLineWidth(row) - 1);
+ alignOffset = MAX<int>(0, _canvas.maxWidth - getLineWidth(row) - 1);
else if (_textAlignment == kTextAlignCenter)
- alignOffset = (_maxWidth / 2) - (getLineWidth(row) / 2);
+ alignOffset = (_canvas.maxWidth / 2) - (getLineWidth(row) / 2);
return alignOffset;
}
void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col, int *chunk_) {
int nsx = 0, nsy = 0, nrow = 0, ncol = 0;
- if (y > _textMaxHeight) {
- x = _surface->w;
+ if (y > _canvas.textMaxHeight) {
+ x = _canvas.surface->w;
}
- y = CLIP(y, 0, _textMaxHeight);
+ y = CLIP(y, 0, _canvas.textMaxHeight);
nrow = _canvas.text.size();
// use [lb, ub) bsearch here, final answer would be lb
@@ -2581,7 +2585,7 @@ void MacText::insertChar(byte c, int *row, int *col) {
(*col)++;
- if (getLineWidth(*row) - oldw + chunkw > _maxWidth) { // Needs reshuffle
+ if (getLineWidth(*row) - oldw + chunkw > _canvas.maxWidth) { // Needs reshuffle
reshuffleParagraph(row, col);
_fullRefresh = true;
recalcDims();
@@ -2874,7 +2878,7 @@ void MacText::processTable(int line) {
Common::Array<int> maxW(numCols), maxL(numCols), colW(numCols);
Common::Array<bool> flex(numCols), wrap(numCols);
- int width = _maxWidth * 0.9;
+ int width = _canvas.maxWidth * 0.9;
int gutter = 10;
// Compute column widths, both minimal and maximal
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 81b0c1dd00e..d1f236f7d2b 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -123,8 +123,14 @@ struct MacTextCanvas {
Common::Array<MacTextLine> text;
uint16 flags = 0;
ManagedSurface *surface = nullptr, *shadowSurface = nullptr;
- int textWidth = -1;
- int textMaxHeigh = 0;
+ int maxWidth = 0;
+ int textMaxWidth = 0;
+ int textMaxHeight = 0;
+
+ ~MacTextCanvas() {
+ delete surface;
+ delete shadowSurface;
+ }
};
struct MacTextTableRow {
@@ -204,7 +210,7 @@ public:
void drawToPoint(ManagedSurface *g, Common::Rect srcRect, Common::Point dstPoint);
void drawToPoint(ManagedSurface *g, Common::Point dstPoint);
- ManagedSurface *getSurface() { return _surface; }
+ ManagedSurface *getSurface() { return _canvas.surface; }
int getInterLinear() { return _interLinear; }
void setInterLinear(int interLinear);
void setMaxWidth(int maxWidth);
@@ -277,9 +283,9 @@ public:
int getLineCount() { return _canvas.text.size(); }
int getLineCharWidth(int line, bool enforce = false);
int getLastLineWidth();
- int getTextHeight() { return _textMaxHeight; }
+ int getTextHeight() { return _canvas.textMaxHeight; }
int getLineHeight(int line);
- int getTextMaxWidth() { return _textMaxWidth; }
+ int getTextMaxWidth() { return _canvas.textMaxWidth; }
void setText(const Common::U32String &str);
@@ -383,7 +389,6 @@ protected:
Common::U32String _str;
const MacFont *_macFont;
- int _maxWidth;
int _interLinear;
int _textShadow;
@@ -392,12 +397,6 @@ protected:
int _selEnd;
int _selStart;
- int _textMaxWidth;
- int _textMaxHeight;
-
- ManagedSurface *_surface;
- ManagedSurface *_shadowSurface;
-
TextAlign _textAlignment;
MacTextCanvas _canvas;
Commit: 74910523c3400ccea85e8279dfafbf144164af05
https://github.com/scummvm/scummvm/commit/74910523c3400ccea85e8279dfafbf144164af05
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-09T00:22:15+02:00
Commit Message:
GRAPHICS: MACGUI: Turned MacTextCanvas into a class
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index cfac74d37a6..6f4d8561132 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -133,7 +133,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
_textShadow = textShadow;
_macFontMode = true;
- _canvas.maxWidth = maxWidth;
+ _canvas._maxWidth = maxWidth;
if (macFont) {
_defaultFormatting = MacFontRun(_wm);
@@ -162,7 +162,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
_textShadow = 0;
_macFontMode = true;
- _canvas.maxWidth = maxWidth;
+ _canvas._maxWidth = maxWidth;
if (macFont) {
_defaultFormatting = MacFontRun(_wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
@@ -191,7 +191,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *f
_textShadow = 0;
_macFontMode = false;
- _canvas.maxWidth = maxWidth;
+ _canvas._maxWidth = maxWidth;
if (font) {
_defaultFormatting = MacFontRun(_wm, font, 0, font->getFontHeight(), 0, 0, 0);
@@ -206,14 +206,14 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *f
void MacText::init() {
_fullRefresh = true;
- _canvas.textMaxWidth = 0;
- _canvas.textMaxHeight = 0;
- _canvas.surface = nullptr;
- _canvas.shadowSurface = nullptr;
+ _canvas._textMaxWidth = 0;
+ _canvas._textMaxHeight = 0;
+ _canvas._surface = nullptr;
+ _canvas._shadowSurface = nullptr;
if (!_fixedDims) {
int right = _dims.right;
- _dims.right = MAX<int>(_dims.right, _dims.left + _canvas.maxWidth + (2 * _border) + (2 * _gutter) + _shadow);
+ _dims.right = MAX<int>(_dims.right, _dims.left + _canvas._maxWidth + (2 * _border) + (2 * _gutter) + _shadow);
if (right != _dims.right) {
delete _composeSurface;
_composeSurface = new ManagedSurface(_dims.width(), _dims.height(), _wm->_pixelformat);
@@ -291,12 +291,12 @@ MacText::~MacText() {
// this func returns the fg color of the first character we met in text
MacFontRun MacText::getFgColor() {
- if (_canvas.text.empty())
+ if (_canvas._text.empty())
return MacFontRun();
- for (uint i = 0; i < _canvas.text.size(); i++) {
- for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
- if (!_canvas.text[i].chunks[j].text.empty())
- return _canvas.text[i].chunks[j];
+ for (uint i = 0; i < _canvas._text.size(); i++) {
+ for (uint j = 0; j < _canvas._text[i].chunks.size(); j++) {
+ if (!_canvas._text[i].chunks[j].text.empty())
+ return _canvas._text[i].chunks[j];
}
}
return MacFontRun();
@@ -339,7 +339,7 @@ int MacText::getStringMaxWordWidth(MacFontRun &format, const Common::U32String &
void MacText::setMaxWidth(int maxWidth) {
- if (maxWidth == _canvas.maxWidth)
+ if (maxWidth == _canvas._maxWidth)
return;
if (maxWidth < 0) {
@@ -355,8 +355,8 @@ void MacText::setMaxWidth(int maxWidth) {
ppos += getLineCharWidth(i);
ppos += _cursorCol;
- _canvas.maxWidth = maxWidth;
- _canvas.text.clear();
+ _canvas._maxWidth = maxWidth;
+ _canvas._text.clear();
splitString(str);
@@ -383,7 +383,7 @@ void MacText::setColors(uint32 fg, uint32 bg) {
_fgcolor = fg;
// also set the cursor color
_cursorSurface->clear(_fgcolor);
- for (uint i = 0; i < _canvas.text.size(); i++)
+ for (uint i = 0; i < _canvas._text.size(); i++)
setTextColor(fg, i);
_fullRefresh = true;
@@ -392,9 +392,9 @@ void MacText::setColors(uint32 fg, uint32 bg) {
}
void MacText::enforceTextFont(uint16 fontId) {
- for (uint i = 0; i < _canvas.text.size(); i++) {
- for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
- _canvas.text[i].chunks[j].fontId = fontId;
+ for (uint i = 0; i < _canvas._text.size(); i++) {
+ for (uint j = 0; j < _canvas._text[i].chunks.size(); j++) {
+ _canvas._text[i].chunks[j].fontId = fontId;
}
}
@@ -404,9 +404,9 @@ void MacText::enforceTextFont(uint16 fontId) {
}
void MacText::setTextSize(int textSize) {
- for (uint i = 0; i < _canvas.text.size(); i++) {
- for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
- _canvas.text[i].chunks[j].fontSize = textSize;
+ for (uint i = 0; i < _canvas._text.size(); i++) {
+ for (uint j = 0; j < _canvas._text[i].chunks.size(); j++) {
+ _canvas._text[i].chunks[j].fontSize = textSize;
}
}
@@ -416,36 +416,36 @@ void MacText::setTextSize(int textSize) {
}
void MacText::setTextColor(uint32 color, uint32 line) {
- if (line >= _canvas.text.size()) {
+ if (line >= _canvas._text.size()) {
warning("MacText::setTextColor(): line %d is out of bounds", line);
return;
}
uint32 fgcol = _wm->findBestColor(color);
- for (uint j = 0; j < _canvas.text[line].chunks.size(); j++) {
- _canvas.text[line].chunks[j].fgcolor = fgcol;
+ for (uint j = 0; j < _canvas._text[line].chunks.size(); j++) {
+ _canvas._text[line].chunks[j].fgcolor = fgcol;
}
// if we are calling this func separately, then here need a refresh
}
void MacText::getChunkPosFromIndex(int index, uint &lineNum, uint &chunkNum, uint &offset) {
- if (_canvas.text.empty()) {
+ if (_canvas._text.empty()) {
lineNum = chunkNum = offset = 0;
return;
}
- for (uint i = 0; i < _canvas.text.size(); i++) {
+ for (uint i = 0; i < _canvas._text.size(); i++) {
if (getLineCharWidth(i) <= index) {
index -= getLineCharWidth(i);
} else {
lineNum = i;
- chunkNum = _canvas.text[i].getChunkNum(&index);
+ chunkNum = _canvas._text[i].getChunkNum(&index);
offset = index;
return;
}
}
- lineNum = _canvas.text.size() - 1;
- chunkNum = _canvas.text[lineNum].chunks.size() - 1;
+ lineNum = _canvas._text.size() - 1;
+ chunkNum = _canvas._text[lineNum].chunks.size() - 1;
offset = 0;
}
@@ -467,7 +467,7 @@ void MacText::setTextSize(int textSize, int start, int end) {
}
void MacText::setTextChunks(int start, int end, int param, void (*callback)(MacFontRun &, int)) {
- if (_canvas.text.empty())
+ if (_canvas._text.empty())
return;
if (start > end)
SWAP(start, end);
@@ -479,21 +479,21 @@ void MacText::setTextChunks(int start, int end, int param, void (*callback)(MacF
getChunkPosFromIndex(start, startRow, startCol, offset);
// if offset != 0, then we need to split the chunk
if (offset != 0) {
- uint textSize = _canvas.text[startRow].chunks[startCol].text.size();
- MacFontRun newChunk = _canvas.text[startRow].chunks[startCol];
+ uint textSize = _canvas._text[startRow].chunks[startCol].text.size();
+ MacFontRun newChunk = _canvas._text[startRow].chunks[startCol];
newChunk.text = newChunk.text.substr(offset, textSize - offset);
- _canvas.text[startRow].chunks[startCol].text = _canvas.text[startRow].chunks[startCol].text.substr(0, offset);
- _canvas.text[startRow].chunks.insert_at(startCol + 1, newChunk);
+ _canvas._text[startRow].chunks[startCol].text = _canvas._text[startRow].chunks[startCol].text.substr(0, offset);
+ _canvas._text[startRow].chunks.insert_at(startCol + 1, newChunk);
startCol++;
}
getChunkPosFromIndex(end, endRow, endCol, offset);
if (offset != 0) {
- uint textSize = _canvas.text[endRow].chunks[endCol].text.size();
- MacFontRun newChunk = _canvas.text[endRow].chunks[endCol];
+ uint textSize = _canvas._text[endRow].chunks[endCol].text.size();
+ MacFontRun newChunk = _canvas._text[endRow].chunks[endCol];
newChunk.text = newChunk.text.substr(offset, textSize - offset);
- _canvas.text[endRow].chunks[endCol].text = _canvas.text[endRow].chunks[endCol].text.substr(0, offset);
- _canvas.text[endRow].chunks.insert_at(endCol + 1, newChunk);
+ _canvas._text[endRow].chunks[endCol].text = _canvas._text[endRow].chunks[endCol].text.substr(0, offset);
+ _canvas._text[endRow].chunks.insert_at(endCol + 1, newChunk);
endCol++;
}
@@ -504,16 +504,16 @@ void MacText::setTextChunks(int start, int end, int param, void (*callback)(MacF
to = endCol;
} else if (i == startRow) {
from = startCol;
- to = _canvas.text[startRow].chunks.size();
+ to = _canvas._text[startRow].chunks.size();
} else if (i == endRow) {
from = 0;
to = endCol;
} else {
from = 0;
- to = _canvas.text[i].chunks.size();
+ to = _canvas._text[i].chunks.size();
}
for (uint j = from; j < to; j++) {
- callback(_canvas.text[i].chunks[j], param);
+ callback(_canvas._text[i].chunks[j], param);
}
}
@@ -539,12 +539,12 @@ void MacText::setTextSlant(int textSlant, int start, int end) {
}
void MacText::enforceTextSlant(int textSlant) {
- for (uint i = 0; i < _canvas.text.size(); i++) {
- for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
+ for (uint i = 0; i < _canvas._text.size(); i++) {
+ for (uint j = 0; j < _canvas._text[i].chunks.size(); j++) {
if (textSlant) {
- _canvas.text[i].chunks[j].textSlant |= textSlant;
+ _canvas._text[i].chunks[j].textSlant |= textSlant;
} else {
- _canvas.text[i].chunks[j].textSlant = textSlant;
+ _canvas._text[i].chunks[j].textSlant = textSlant;
}
}
}
@@ -574,7 +574,7 @@ int MacText::getTextSlant(int start, int end) {
// only getting the first chunk for the selected area
MacFontRun MacText::getTextChunks(int start, int end) {
- if (_canvas.text.empty())
+ if (_canvas._text.empty())
return _defaultFormatting;
if (start > end)
SWAP(start, end);
@@ -583,7 +583,7 @@ MacFontRun MacText::getTextChunks(int start, int end) {
uint offset;
getChunkPosFromIndex(start, startRow, startCol, offset);
- return _canvas.text[startRow].chunks[startCol];
+ return _canvas._text[startRow].chunks[startCol];
}
void MacText::setDefaultFormatting(uint16 fontId, byte textSlant, uint16 fontSize,
@@ -596,7 +596,7 @@ void MacText::setDefaultFormatting(uint16 fontId, byte textSlant, uint16 fontSiz
}
// Adds the given string to the end of the last line/chunk
-// while observing the _canvas.maxWidth and keeping this chunk's
+// while observing the _canvas._maxWidth and keeping this chunk's
// formatting
void MacText::chopChunk(const Common::U32String &str, int *curLinePtr, int indent, int maxWidth) {
int curLine = *curLinePtr;
@@ -604,14 +604,14 @@ void MacText::chopChunk(const Common::U32String &str, int *curLinePtr, int inden
MacFontRun *chunk;
if (!_inTable) {
- curChunk = _canvas.text[curLine].chunks.size() - 1;
- chunk = &_canvas.text[curLine].chunks[curChunk];
+ curChunk = _canvas._text[curLine].chunks.size() - 1;
+ chunk = &_canvas._text[curLine].chunks[curChunk];
} else {
if (str.empty())
return;
- curChunk = _canvas.text[curLine].table->back().cells.back().text.back().chunks.size() - 1;
- chunk = &_canvas.text[curLine].table->back().cells.back().text.back().chunks[curChunk];
+ curChunk = _canvas._text[curLine].table->back().cells.back()._text.back().chunks.size() - 1;
+ chunk = &_canvas._text[curLine].table->back().cells.back()._text.back().chunks[curChunk];
}
// Check if there is nothing to add, then remove the last chunk
@@ -620,7 +620,7 @@ void MacText::chopChunk(const Common::U32String &str, int *curLinePtr, int inden
if (chunk->text.empty() && str.empty()) {
D(9, "** chopChunk, replaced formatting, line %d", curLine);
- _canvas.text[curLine].chunks.pop_back();
+ _canvas._text[curLine].chunks.pop_back();
return;
}
@@ -661,19 +661,19 @@ void MacText::chopChunk(const Common::U32String &str, int *curLinePtr, int inden
return;
// Now add rest of the chunks
- MacFontRun newchunk = _canvas.text[curLine].chunks[curChunk];
+ MacFontRun newchunk = _canvas._text[curLine].chunks[curChunk];
for (uint i = 1; i < text.size(); i++) {
newchunk.text = text[i];
if (!_inTable) {
curLine++;
- _canvas.text.insert_at(curLine, MacTextLine());
- _canvas.text[curLine].chunks.push_back(newchunk);
- _canvas.text[curLine].indent = indent;
+ _canvas._text.insert_at(curLine, MacTextLine());
+ _canvas._text[curLine].chunks.push_back(newchunk);
+ _canvas._text[curLine].indent = indent;
} else {
- _canvas.text[curLine].table->back().cells.back().text.push_back(MacTextLine());
- _canvas.text[curLine].table->back().cells.back().text.back().chunks.push_back(newchunk);
+ _canvas._text[curLine].table->back().cells.back()._text.push_back(MacTextLine());
+ _canvas._text[curLine].table->back().cells.back()._text.back().chunks.push_back(newchunk);
}
D(9, "** chopChunk, added line: \"%s\"", toPrintable(text[i].encode()).c_str());
@@ -687,12 +687,12 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
D(9, "** splitString(\"%s\")", toPrintable(str.encode()).c_str());
- if (_canvas.text.empty()) {
- _canvas.text.resize(1);
- _canvas.text[0].chunks.push_back(_defaultFormatting);
+ if (_canvas._text.empty()) {
+ _canvas._text.resize(1);
+ _canvas._text[0].chunks.push_back(_defaultFormatting);
D(9, "** splitString, added default formatting");
} else {
- D(9, "** splitString, continuing, %d lines", _canvas.text.size());
+ D(9, "** splitString, continuing, %d lines", _canvas._text.size());
}
if (str.empty()) {
@@ -703,10 +703,10 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
Common::U32String paragraph, tmp;
if (curLine == -1)
- curLine = _canvas.text.size() - 1;
+ curLine = _canvas._text.size() - 1;
- int curChunk = _canvas.text[curLine].chunks.size() - 1;
- MacFontRun chunk = _canvas.text[curLine].chunks[curChunk];
+ int curChunk = _canvas._text[curLine].chunks.size() - 1;
+ MacFontRun chunk = _canvas._text[curLine].chunks[curChunk];
int indentSize = 0;
int firstLineIndent = 0;
@@ -739,7 +739,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
tmp.clear();
- MacTextLine *curTextLine = &_canvas.text[curLine];
+ MacTextLine *curTextLine = &_canvas._text[curLine];
while (*s) {
// Scan till next font change or end of line
@@ -763,9 +763,9 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
// Okay, now we are either at the end of the line, or in the next
// chunk definition. That means, that we have to store the previous chunk
- chopChunk(tmp, &curLine, indentSize, _inTable ? -1 : _canvas.maxWidth);
+ chopChunk(tmp, &curLine, indentSize, _inTable ? -1 : _canvas._maxWidth);
- curTextLine = &_canvas.text[curLine];
+ curTextLine = &_canvas._text[curLine];
tmp.clear();
@@ -884,23 +884,23 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
uint16 len;
- s = readHex(&_canvas.text[curLine].picpercent, s, 2);
+ s = readHex(&_canvas._text[curLine].picpercent, s, 2);
s = readHex(&len, s, 2);
- _canvas.text[curLine].picfname = Common::U32String(s, len).encode();
+ _canvas._text[curLine].picfname = Common::U32String(s, len).encode();
s += len;
s = readHex(&len, s, 2);
- _canvas.text[curLine].picalt = Common::U32String(s, len);
+ _canvas._text[curLine].picalt = Common::U32String(s, len);
s += len;
s = readHex(&len, s, 2);
- _canvas.text[curLine].pictitle = Common::U32String(s, len);
+ _canvas._text[curLine].pictitle = Common::U32String(s, len);
s += len;
D(9, "** splitString[i]: %d%% fname: '%s' alt: '%s' title: '%s'",
- _canvas.text[curLine].picpercent,
- _canvas.text[curLine].picfname.c_str(), _canvas.text[curLine].picalt.c_str(),
- _canvas.text[curLine].pictitle.c_str());
+ _canvas._text[curLine].picpercent,
+ _canvas._text[curLine].picfname.c_str(), _canvas._text[curLine].picalt.c_str(),
+ _canvas._text[curLine].pictitle.c_str());
break;
}
@@ -947,7 +947,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
processTable(curLine);
- curTextLine = &_canvas.text[curLine];
+ curTextLine = &_canvas._text[curLine];
} else if (cmd == 'r') { // Row
curTextLine->table->push_back(MacTextTableRow());
continue;
@@ -956,10 +956,10 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
s = readHex(&flags, s, 2);
curTextLine->table->back().cells.push_back(MacTextCanvas());
- curTextLine->table->back().cells.back().flags = flags;
+ curTextLine->table->back().cells.back()._flags = flags;
- curTextLine->table->back().cells.back().text.resize(1);
- curTextLine = &curTextLine->table->back().cells.back().text[0];
+ curTextLine->table->back().cells.back()._text.resize(1);
+ curTextLine = &curTextLine->table->back().cells.back()._text[0];
curTextLine->chunks.push_back(_defaultFormatting);
continue;
} else if (cmd == 'C') { // Cell end
@@ -1015,19 +1015,19 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
if (!_inTable) {
curLine++;
- _canvas.text.insert_at(curLine, MacTextLine());
- _canvas.text[curLine].chunks.push_back(chunk);
+ _canvas._text.insert_at(curLine, MacTextLine());
+ _canvas._text[curLine].chunks.push_back(chunk);
- curTextLine = &_canvas.text[curLine];
+ curTextLine = &_canvas._text[curLine];
}
}
#if DEBUG
- for (uint i = 0; i < _canvas.text.size(); i++) {
+ for (uint i = 0; i < _canvas._text.size(); i++) {
debugN(9, "** splitString: %2d ", i);
- for (uint j = 0; j < _canvas.text[i].chunks.size(); j++)
- debugN(9, "[%d] \"%s\"", _canvas.text[i].chunks[j].text.size(), Common::toPrintable(_canvas.text[i].chunks[j].text.encode()).c_str());
+ for (uint j = 0; j < _canvas._text[i].chunks.size(); j++)
+ debugN(9, "[%d] \"%s\"", _canvas._text[i].chunks[j].text.size(), Common::toPrintable(_canvas._text[i].chunks[j].text.encode()).c_str());
debugN(9, "\n");
}
@@ -1041,43 +1041,43 @@ void MacText::reallocSurface() {
//TODO: work out why this rounding doesn't correctly fill the entire width
//int requiredH = (_text.size() + (_text.size() * 10 + 9) / 10) * lineH
- if (!_canvas.surface) {
- _canvas.surface = new ManagedSurface(_canvas.maxWidth, _canvas.textMaxHeight, _wm->_pixelformat);
+ if (!_canvas._surface) {
+ _canvas._surface = new ManagedSurface(_canvas._maxWidth, _canvas._textMaxHeight, _wm->_pixelformat);
if (_textShadow)
- _canvas.shadowSurface = new ManagedSurface(_canvas.maxWidth, _canvas.textMaxHeight, _wm->_pixelformat);
+ _canvas._shadowSurface = new ManagedSurface(_canvas._maxWidth, _canvas._textMaxHeight, _wm->_pixelformat);
return;
}
- if (_canvas.surface->w < _canvas.maxWidth || _canvas.surface->h < _canvas.textMaxHeight) {
+ if (_canvas._surface->w < _canvas._maxWidth || _canvas._surface->h < _canvas._textMaxHeight) {
// realloc surface and copy old content
- ManagedSurface *n = new ManagedSurface(_canvas.maxWidth, _canvas.textMaxHeight, _wm->_pixelformat);
+ ManagedSurface *n = new ManagedSurface(_canvas._maxWidth, _canvas._textMaxHeight, _wm->_pixelformat);
n->clear(_bgcolor);
- n->blitFrom(*_canvas.surface, Common::Point(0, 0));
+ n->blitFrom(*_canvas._surface, Common::Point(0, 0));
- delete _canvas.surface;
- _canvas.surface = n;
+ delete _canvas._surface;
+ _canvas._surface = n;
// same as shadow surface
if (_textShadow) {
- ManagedSurface *newShadowSurface = new ManagedSurface(_canvas.maxWidth, _canvas.textMaxHeight, _wm->_pixelformat);
+ ManagedSurface *newShadowSurface = new ManagedSurface(_canvas._maxWidth, _canvas._textMaxHeight, _wm->_pixelformat);
newShadowSurface->clear(_bgcolor);
- newShadowSurface->blitFrom(*_canvas.shadowSurface, Common::Point(0, 0));
+ newShadowSurface->blitFrom(*_canvas._shadowSurface, Common::Point(0, 0));
- delete _canvas.shadowSurface;
- _canvas.shadowSurface = newShadowSurface;
+ delete _canvas._shadowSurface;
+ _canvas._shadowSurface = newShadowSurface;
}
}
}
void MacText::render() {
if (_fullRefresh) {
- _canvas.surface->clear(_bgcolor);
+ _canvas._surface->clear(_bgcolor);
if (_textShadow)
- _canvas.shadowSurface->clear(_bgcolor);
+ _canvas._shadowSurface->clear(_bgcolor);
- render(0, _canvas.text.size());
+ render(0, _canvas._text.size());
_fullRefresh = false;
@@ -1086,15 +1086,15 @@ void MacText::render() {
Common::String filename = Common::String::format("z-%p.png", (void *)this);
if (out.open(filename)) {
warning("Wrote: %s", filename.c_str());
- Image::writePNG(out, _canvas.surface->rawSurface());
+ Image::writePNG(out, _canvas._surface->rawSurface());
}
#endif
}
}
void MacText::render(int from, int to, int shadow) {
- int w = MIN(_canvas.maxWidth, _canvas.textMaxWidth);
- ManagedSurface *surface = shadow ? _canvas.shadowSurface : _canvas.surface;
+ int w = MIN(_canvas._maxWidth, _canvas._textMaxWidth);
+ ManagedSurface *surface = shadow ? _canvas._shadowSurface : _canvas._surface;
int myFrom = from, myTo = to + 1, delta = 1;
@@ -1105,11 +1105,11 @@ void MacText::render(int from, int to, int shadow) {
}
for (int i = myFrom; i != myTo; i += delta) {
- if (!_canvas.text[i].picfname.empty()) {
- const Surface *image = getImageSurface(_canvas.text[i].picfname);
+ if (!_canvas._text[i].picfname.empty()) {
+ const Surface *image = getImageSurface(_canvas._text[i].picfname);
- int xOffset = (_canvas.text[i].width - _canvas.text[i].charwidth) / 2;
- Common::Rect bbox(xOffset, _canvas.text[i].y, xOffset + _canvas.text[i].charwidth, _canvas.text[i].y + _canvas.text[i].height);
+ int xOffset = (_canvas._text[i].width - _canvas._text[i].charwidth) / 2;
+ Common::Rect bbox(xOffset, _canvas._text[i].y, xOffset + _canvas._text[i].charwidth, _canvas._text[i].y + _canvas._text[i].height);
if (image)
surface->blitFrom(image, Common::Rect(0, 0, image->w, image->h), bbox);
@@ -1117,62 +1117,62 @@ void MacText::render(int from, int to, int shadow) {
continue;
}
- int xOffset = getAlignOffset(i) + _canvas.text[i].indent + _canvas.text[i].firstLineIndent;
+ int xOffset = getAlignOffset(i) + _canvas._text[i].indent + _canvas._text[i].firstLineIndent;
xOffset++;
- int start = 0, end = _canvas.text[i].chunks.size();
+ int start = 0, end = _canvas._text[i].chunks.size();
if (_wm->_language == Common::HE_ISR) {
- start = _canvas.text[i].chunks.size() - 1;
+ start = _canvas._text[i].chunks.size() - 1;
end = -1;
}
int maxAscentForRow = 0;
for (int j = start; j != end; j += delta) {
- if (_canvas.text[i].chunks[j].font->getFontAscent() > maxAscentForRow)
- maxAscentForRow = _canvas.text[i].chunks[j].font->getFontAscent();
+ if (_canvas._text[i].chunks[j].font->getFontAscent() > maxAscentForRow)
+ maxAscentForRow = _canvas._text[i].chunks[j].font->getFontAscent();
}
- // TODO: _canvas.textMaxWidth, when -1, was not rendering ANY text.
+ // TODO: _canvas._textMaxWidth, when -1, was not rendering ANY text.
for (int j = start; j != end; j += delta) {
debug(9, "MacText::render: line %d[%d] h:%d at %d,%d (%s) fontid: %d fontsize: %d on %dx%d, fgcolor: %08x bgcolor: %08x, font: %p",
- i, j, _canvas.text[i].height, xOffset, _canvas.text[i].y, _canvas.text[i].chunks[j].text.encode().c_str(),
- _canvas.text[i].chunks[j].fontId, _canvas.text[i].chunks[j].fontSize, _canvas.surface->w, _canvas.surface->h, _canvas.text[i].chunks[j].fgcolor, _bgcolor,
- (const void *)_canvas.text[i].chunks[j].getFont());
+ i, j, _canvas._text[i].height, xOffset, _canvas._text[i].y, _canvas._text[i].chunks[j].text.encode().c_str(),
+ _canvas._text[i].chunks[j].fontId, _canvas._text[i].chunks[j].fontSize, _canvas._surface->w, _canvas._surface->h, _canvas._text[i].chunks[j].fgcolor, _bgcolor,
+ (const void *)_canvas._text[i].chunks[j].getFont());
- if (_canvas.text[i].chunks[j].text.empty())
+ if (_canvas._text[i].chunks[j].text.empty())
continue;
int yOffset = 0;
- if (_canvas.text[i].chunks[j].font->getFontAscent() < maxAscentForRow) {
- yOffset = maxAscentForRow - _canvas.text[i].chunks[j].font->getFontAscent();
+ if (_canvas._text[i].chunks[j].font->getFontAscent() < maxAscentForRow) {
+ yOffset = maxAscentForRow - _canvas._text[i].chunks[j].font->getFontAscent();
}
- if (_canvas.text[i].chunks[j].plainByteMode()) {
- Common::String str = _canvas.text[i].chunks[j].getEncodedText();
- _canvas.text[i].chunks[j].getFont()->drawString(surface, str, xOffset, _canvas.text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas.text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
- xOffset += _canvas.text[i].chunks[j].getFont()->getStringWidth(str);
+ if (_canvas._text[i].chunks[j].plainByteMode()) {
+ Common::String str = _canvas._text[i].chunks[j].getEncodedText();
+ _canvas._text[i].chunks[j].getFont()->drawString(surface, str, xOffset, _canvas._text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas._text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
+ xOffset += _canvas._text[i].chunks[j].getFont()->getStringWidth(str);
} else {
if (_wm->_language == Common::HE_ISR)
- _canvas.text[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_canvas.text[i].chunks[j].text, Common::BIDI_PAR_RTL), xOffset, _canvas.text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas.text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
+ _canvas._text[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_canvas._text[i].chunks[j].text, Common::BIDI_PAR_RTL), xOffset, _canvas._text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas._text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
else
- _canvas.text[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_canvas.text[i].chunks[j].text), xOffset, _canvas.text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas.text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
- xOffset += _canvas.text[i].chunks[j].getFont()->getStringWidth(_canvas.text[i].chunks[j].text);
+ _canvas._text[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_canvas._text[i].chunks[j].text), xOffset, _canvas._text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas._text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
+ xOffset += _canvas._text[i].chunks[j].getFont()->getStringWidth(_canvas._text[i].chunks[j].text);
}
}
}
}
void MacText::render(int from, int to) {
- if (_canvas.text.empty())
+ if (_canvas._text.empty())
return;
reallocSurface();
from = MAX<int>(0, from);
- to = MIN<int>(to, _canvas.text.size() - 1);
+ to = MIN<int>(to, _canvas._text.size() - 1);
// Clear the screen
- _canvas.surface->fillRect(Common::Rect(0, _canvas.text[from].y, _canvas.surface->w, _canvas.text[to].y + getLineHeight(to)), _bgcolor);
+ _canvas._surface->fillRect(Common::Rect(0, _canvas._text[from].y, _canvas._surface->w, _canvas._text[to].y + getLineHeight(to)), _bgcolor);
// render the shadow surface;
if (_textShadow)
@@ -1180,21 +1180,21 @@ void MacText::render(int from, int to) {
render(from, to, 0);
- for (uint i = 0; i < _canvas.text.size(); i++) {
+ for (uint i = 0; i < _canvas._text.size(); i++) {
debugN(9, "MacText::render: %2d ", i);
- for (uint j = 0; j < _canvas.text[i].chunks.size(); j++)
- debugN(9, "[%d (%d)] \"%s\" ", _canvas.text[i].chunks[j].fontId, _canvas.text[i].chunks[j].textSlant, _canvas.text[i].chunks[j].text.encode().c_str());
+ for (uint j = 0; j < _canvas._text[i].chunks.size(); j++)
+ debugN(9, "[%d (%d)] \"%s\" ", _canvas._text[i].chunks[j].fontId, _canvas._text[i].chunks[j].textSlant, _canvas._text[i].chunks[j].text.encode().c_str());
debug(9, "%s", "");
}
}
int MacText::getLineWidth(int line, bool enforce, int col) {
- if ((uint)line >= _canvas.text.size())
+ if ((uint)line >= _canvas._text.size())
return 0;
- return getLineWidth(&_canvas.text[line], enforce, col);
+ return getLineWidth(&_canvas._text[line], enforce, col);
}
int MacText::getLineWidth(MacTextLine *line, bool enforce, int col) {
@@ -1205,12 +1205,12 @@ int MacText::getLineWidth(MacTextLine *line, bool enforce, int col) {
const Surface *image = getImageSurface(line->picfname);
if (image) {
- float ratio = _canvas.maxWidth * line->picpercent / 100.0 / (float)image->w;
- line->width = _canvas.maxWidth;
+ float ratio = _canvas._maxWidth * line->picpercent / 100.0 / (float)image->w;
+ line->width = _canvas._maxWidth;
line->height = image->h * ratio;
line->charwidth = image->w * ratio;
} else {
- line->width = _canvas.maxWidth;
+ line->width = _canvas._maxWidth;
line->height = 1;
line->charwidth = 1;
}
@@ -1267,38 +1267,38 @@ int MacText::getLineWidth(MacTextLine *line, bool enforce, int col) {
}
int MacText::getLineCharWidth(int line, bool enforce) {
- if ((uint)line >= _canvas.text.size())
+ if ((uint)line >= _canvas._text.size())
return 0;
- if (_canvas.text[line].charwidth != -1 && !enforce)
- return _canvas.text[line].charwidth;
+ if (_canvas._text[line].charwidth != -1 && !enforce)
+ return _canvas._text[line].charwidth;
int width = 0;
- for (uint i = 0; i < _canvas.text[line].chunks.size(); i++) {
- if (!_canvas.text[line].chunks[i].text.empty())
- width += _canvas.text[line].chunks[i].text.size();
+ for (uint i = 0; i < _canvas._text[line].chunks.size(); i++) {
+ if (!_canvas._text[line].chunks[i].text.empty())
+ width += _canvas._text[line].chunks[i].text.size();
}
- _canvas.text[line].charwidth = width;
+ _canvas._text[line].charwidth = width;
return width;
}
int MacText::getLastLineWidth() {
- if (_canvas.text.size() == 0)
+ if (_canvas._text.size() == 0)
return 0;
- return getLineWidth(_canvas.text.size() - 1, true);
+ return getLineWidth(_canvas._text.size() - 1, true);
}
int MacText::getLineHeight(int line) {
- if ((uint)line >= _canvas.text.size())
+ if ((uint)line >= _canvas._text.size())
return 0;
getLineWidth(line); // This calculates height also
- return _canvas.text[line].height;
+ return _canvas._text[line].height;
}
void MacText::setInterLinear(int interLinear) {
@@ -1311,25 +1311,25 @@ void MacText::setInterLinear(int interLinear) {
}
void MacText::recalcDims() {
- if (_canvas.text.empty())
+ if (_canvas._text.empty())
return;
int y = 0;
- _canvas.textMaxWidth = 0;
+ _canvas._textMaxWidth = 0;
- for (uint i = 0; i < _canvas.text.size(); i++) {
- _canvas.text[i].y = y;
+ for (uint i = 0; i < _canvas._text.size(); i++) {
+ _canvas._text[i].y = y;
// We must calculate width first, because it enforces
// the computation. Calling Height() will return cached value!
- _canvas.textMaxWidth = MAX(_canvas.textMaxWidth, getLineWidth(i, true));
+ _canvas._textMaxWidth = MAX(_canvas._textMaxWidth, getLineWidth(i, true));
y += MAX(getLineHeight(i), _interLinear);
}
- _canvas.textMaxHeight = y;
+ _canvas._textMaxHeight = y;
if (!_fixedDims) {
- int newBottom = _dims.top + _canvas.textMaxHeight + (2 * _border) + _gutter + _shadow;
+ int newBottom = _dims.top + _canvas._textMaxHeight + (2 * _border) + _gutter + _shadow;
if (newBottom > _dims.bottom) {
_dims.bottom = newBottom;
delete _composeSurface;
@@ -1413,7 +1413,7 @@ void MacText::setEditable(bool editable) {
}
void MacText::resize(int w, int h) {
- if (_canvas.surface->w == w && _canvas.surface->h == h)
+ if (_canvas._surface->w == w && _canvas._surface->h == h)
return;
setMaxWidth(w);
@@ -1433,17 +1433,17 @@ void MacText::appendText(const Common::U32String &str, int fontId, int fontSize,
}
void MacText::appendText(const Common::U32String &str, int fontId, int fontSize, int fontSlant, uint16 r, uint16 g, uint16 b, bool skipAdd) {
- uint oldLen = _canvas.text.size();
+ uint oldLen = _canvas._text.size();
MacFontRun fontRun = MacFontRun(_wm, fontId, fontSlant, fontSize, r, g, b);
_currentFormatting = fontRun;
- // we check _str here, if _str is empty but _canvas.text is not empty, and they are not the end of paragraph
+ // we check _str here, if _str is empty but _canvas._text is not empty, and they are not the end of paragraph
// then we remove those empty lines
// too many special check may cause some strange problem in the future
if (_str.empty()) {
- while (!_canvas.text.empty() && !_canvas.text.back().paragraphEnd)
+ while (!_canvas._text.empty() && !_canvas._text.back().paragraphEnd)
removeLastLine();
}
@@ -1457,14 +1457,14 @@ void MacText::appendText(const Common::U32String &str, int fontId, int fontSize,
}
void MacText::appendText(const Common::U32String &str, const Font *font, uint16 r, uint16 g, uint16 b, bool skipAdd) {
- uint oldLen = _canvas.text.size();
+ uint oldLen = _canvas._text.size();
MacFontRun fontRun = MacFontRun(_wm, font, 0, font->getFontHeight(), r, g, b);
_currentFormatting = fontRun;
if (_str.empty()) {
- while (!_canvas.text.empty() && !_canvas.text.back().paragraphEnd)
+ while (!_canvas._text.empty() && !_canvas._text.back().paragraphEnd)
removeLastLine();
}
@@ -1480,7 +1480,7 @@ void MacText::appendText_(const Common::U32String &strWithFont, uint oldLen) {
splitString(strWithFont);
recalcDims();
- render(oldLen - 1, _canvas.text.size());
+ render(oldLen - 1, _canvas._text.size());
_contentIsDirty = true;
@@ -1495,7 +1495,7 @@ void MacText::appendText_(const Common::U32String &strWithFont, uint oldLen) {
}
void MacText::appendTextDefault(const Common::U32String &str, bool skipAdd) {
- uint oldLen = _canvas.text.size();
+ uint oldLen = _canvas._text.size();
_currentFormatting = _defaultFormatting;
Common::U32String strWithFont = Common::U32String(_defaultFormatting.toString()) + str;
@@ -1506,7 +1506,7 @@ void MacText::appendTextDefault(const Common::U32String &str, bool skipAdd) {
splitString(strWithFont);
recalcDims();
- render(oldLen - 1, _canvas.text.size());
+ render(oldLen - 1, _canvas._text.size());
}
void MacText::appendTextDefault(const Common::String &str, bool skipAdd) {
@@ -1515,11 +1515,11 @@ void MacText::appendTextDefault(const Common::String &str, bool skipAdd) {
void MacText::clearText() {
_contentIsDirty = true;
- _canvas.text.clear();
+ _canvas._text.clear();
_str.clear();
- if (_canvas.surface)
- _canvas.surface->clear(_bgcolor);
+ if (_canvas._surface)
+ _canvas._surface->clear(_bgcolor);
recalcDims();
@@ -1528,32 +1528,32 @@ void MacText::clearText() {
}
void MacText::removeLastLine() {
- if (!_canvas.text.size())
+ if (!_canvas._text.size())
return;
- int h = getLineHeight(_canvas.text.size() - 1) + _interLinear;
+ int h = getLineHeight(_canvas._text.size() - 1) + _interLinear;
- _canvas.surface->fillRect(Common::Rect(0, _canvas.textMaxHeight - h, _canvas.surface->w, _canvas.textMaxHeight), _bgcolor);
+ _canvas._surface->fillRect(Common::Rect(0, _canvas._textMaxHeight - h, _canvas._surface->w, _canvas._textMaxHeight), _bgcolor);
- _canvas.text.pop_back();
- _canvas.textMaxHeight -= h;
+ _canvas._text.pop_back();
+ _canvas._textMaxHeight -= h;
}
void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff) {
- if (_canvas.text.empty())
+ if (_canvas._text.empty())
return;
render();
- if (x + w < _canvas.surface->w || y + h < _canvas.surface->h)
+ if (x + w < _canvas._surface->w || y + h < _canvas._surface->h)
g->fillRect(Common::Rect(x + xoff, y + yoff, x + w + xoff, y + h + yoff), _bgcolor);
// blit shadow surface first
if (_textShadow)
- g->blitFrom(*_canvas.shadowSurface, Common::Rect(MIN<int>(_canvas.surface->w, x), MIN<int>(_canvas.surface->h, y), MIN<int>(_canvas.surface->w, x + w), MIN<int>(_canvas.surface->h, y + h)), Common::Point(xoff + _textShadow, yoff + _textShadow));
+ g->blitFrom(*_canvas._shadowSurface, Common::Rect(MIN<int>(_canvas._surface->w, x), MIN<int>(_canvas._surface->h, y), MIN<int>(_canvas._surface->w, x + w), MIN<int>(_canvas._surface->h, y + h)), Common::Point(xoff + _textShadow, yoff + _textShadow));
uint32 bgcolor = _bgcolor < 0xff ? _bgcolor : 0;
- g->transBlitFrom(*_canvas.surface, Common::Rect(MIN<int>(_canvas.surface->w, x), MIN<int>(_canvas.surface->h, y), MIN<int>(_canvas.surface->w, x + w), MIN<int>(_canvas.surface->h, y + h)), Common::Point(xoff, yoff), bgcolor);
+ g->transBlitFrom(*_canvas._surface, Common::Rect(MIN<int>(_canvas._surface->w, x), MIN<int>(_canvas._surface->h, y), MIN<int>(_canvas._surface->w, x + w), MIN<int>(_canvas._surface->h, y + h)), Common::Point(xoff, yoff), bgcolor);
_contentIsDirty = false;
_cursorDirty = false;
@@ -1563,7 +1563,7 @@ bool MacText::draw(bool forceRedraw) {
if (!needsRedraw() && !forceRedraw)
return false;
- if (!_canvas.surface) {
+ if (!_canvas._surface) {
warning("MacText::draw: Null surface");
return false;
}
@@ -1589,7 +1589,7 @@ bool MacText::draw(bool forceRedraw) {
if (!(_contentIsDirty || forceRedraw))
return true;
- draw(_composeSurface, 0, _scrollPos, _canvas.surface->w, _scrollPos + _canvas.surface->h, offset.x, offset.y);
+ draw(_composeSurface, 0, _scrollPos, _canvas._surface->w, _scrollPos + _canvas._surface->h, offset.x, offset.y);
for (int bb = 0; bb < _shadow; bb++) {
_composeSurface->hLine(_shadow, _composeSurface->h - _shadow + bb, _composeSurface->w, 0);
@@ -1619,26 +1619,26 @@ bool MacText::draw(ManagedSurface *g, bool forceRedraw) {
}
void MacText::drawToPoint(ManagedSurface *g, Common::Rect srcRect, Common::Point dstPoint) {
- if (_canvas.text.empty())
+ if (_canvas._text.empty())
return;
render();
- srcRect.clip(_canvas.surface->getBounds());
+ srcRect.clip(_canvas._surface->getBounds());
if (srcRect.isEmpty())
return;
- g->blitFrom(*_canvas.surface, srcRect, dstPoint);
+ g->blitFrom(*_canvas._surface, srcRect, dstPoint);
}
void MacText::drawToPoint(ManagedSurface *g, Common::Point dstPoint) {
- if (_canvas.text.empty())
+ if (_canvas._text.empty())
return;
render();
- g->blitFrom(*_canvas.surface, dstPoint);
+ g->blitFrom(*_canvas._surface, dstPoint);
}
// Count newline characters in String
@@ -1699,7 +1699,7 @@ void MacText::drawSelection(int xoff, int yoff) {
end = MIN((int)maxSelectionHeight, end);
// if we are selecting all text, then we invert the whole area
- if ((uint)s.endRow == _canvas.text.size() - 1)
+ if ((uint)s.endRow == _canvas._text.size() - 1)
end = maxSelectionHeight;
int numLines = 0;
@@ -1734,7 +1734,7 @@ void MacText::drawSelection(int xoff, int yoff) {
end = MIN(end, maxSelectionHeight - yoff);
for (int y = start; y < end; y++) {
- if (!numLines && (uint)row < _canvas.text.size()) {
+ if (!numLines && (uint)row < _canvas._text.size()) {
x1 = 0;
x2 = maxSelectionWidth;
@@ -1819,16 +1819,16 @@ void MacText::setSelection(int pos, bool start) {
if (pos > 0) {
while (pos > 0) {
if (pos < getLineCharWidth(row)) {
- for (uint i = 0; i < _canvas.text[row].chunks.size(); i++) {
- if ((uint)pos < _canvas.text[row].chunks[i].text.size()) {
- colX += getStringWidth(_canvas.text[row].chunks[i], _canvas.text[row].chunks[i].text.substr(0, pos));
+ for (uint i = 0; i < _canvas._text[row].chunks.size(); i++) {
+ if ((uint)pos < _canvas._text[row].chunks[i].text.size()) {
+ colX += getStringWidth(_canvas._text[row].chunks[i], _canvas._text[row].chunks[i].text.substr(0, pos));
col += pos;
pos = 0;
break;
} else {
- colX += getStringWidth(_canvas.text[row].chunks[i], _canvas.text[row].chunks[i].text);
- pos -= _canvas.text[row].chunks[i].text.size();
- col += _canvas.text[row].chunks[i].text.size();
+ colX += getStringWidth(_canvas._text[row].chunks[i], _canvas._text[row].chunks[i].text);
+ pos -= _canvas._text[row].chunks[i].text.size();
+ col += _canvas._text[row].chunks[i].text.size();
}
}
break;
@@ -1837,9 +1837,9 @@ void MacText::setSelection(int pos, bool start) {
}
row++;
- if ((uint)row >= _canvas.text.size()) {
- row = _canvas.text.size() - 1;
- colX = _canvas.surface->w;
+ if ((uint)row >= _canvas._text.size()) {
+ row = _canvas._text.size() - 1;
+ colX = _canvas._surface->w;
col = getLineCharWidth(row);
break;
@@ -1848,16 +1848,16 @@ void MacText::setSelection(int pos, bool start) {
} else if (pos == 0) {
colX = col = row = 0;
} else {
- row = _canvas.text.size() - 1;
+ row = _canvas._text.size() - 1;
col = getLineCharWidth(row);
// if we don't have any text, then we won't select the whole area.
- if (_canvas.textMaxWidth == 0)
+ if (_canvas._textMaxWidth == 0)
colX = 0;
else
- colX = _canvas.textMaxWidth;
+ colX = _canvas._textMaxWidth;
}
- int rowY = _canvas.text[row].y;
+ int rowY = _canvas._text[row].y;
if (start) {
_selectedText.startX = colX;
@@ -1888,9 +1888,9 @@ Common::U32String MacText::getEditedString() {
Common::U32String MacText::getPlainText() {
Common::U32String res;
- for (uint i = 0; i < _canvas.text.size(); i++) {
- for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
- res += _canvas.text[i].chunks[j].text;
+ for (uint i = 0; i < _canvas._text.size(); i++) {
+ for (uint j = 0; j < _canvas._text[i].chunks.size(); j++) {
+ res += _canvas._text[i].chunks[j].text;
}
}
@@ -1999,7 +1999,7 @@ bool MacText::processEvent(Common::Event &event) {
_cursorRow--;
- getRowCol(_cursorX, _canvas.text[_cursorRow].y, nullptr, nullptr, &_cursorRow, &_cursorCol);
+ getRowCol(_cursorX, _canvas._text[_cursorRow].y, nullptr, nullptr, &_cursorRow, &_cursorCol);
updateCursorPos();
return true;
@@ -2010,7 +2010,7 @@ bool MacText::processEvent(Common::Event &event) {
_cursorRow++;
- getRowCol(_cursorX, _canvas.text[_cursorRow].y, nullptr, nullptr, &_cursorRow, &_cursorCol);
+ getRowCol(_cursorX, _canvas._text[_cursorRow].y, nullptr, nullptr, &_cursorRow, &_cursorCol);
updateCursorPos();
return true;
@@ -2142,7 +2142,7 @@ void MacText::scroll(int delta) {
}
void MacText::startMarking(int x, int y) {
- if (_canvas.text.size() == 0)
+ if (_canvas._text.size() == 0)
return;
Common::Point offset = calculateOffset();
@@ -2202,21 +2202,21 @@ int MacText::getMouseWord(int x, int y) {
int index = 0;
for (int i = 0; i < row; i++) {
- for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
- if (_canvas.text[i].chunks[j].text.empty())
+ for (uint j = 0; j < _canvas._text[i].chunks.size(); j++) {
+ if (_canvas._text[i].chunks[j].text.empty())
continue;
index++;
}
}
int cur = 0;
- for (uint j = 0; j < _canvas.text[row].chunks.size(); j++) {
- if (_canvas.text[row].chunks[j].text.empty())
+ for (uint j = 0; j < _canvas._text[row].chunks.size(); j++) {
+ if (_canvas._text[row].chunks[j].text.empty())
continue;
- cur += _canvas.text[row].chunks[j].text.size();
+ cur += _canvas._text[row].chunks[j].text.size();
// Avoid overflowing the word index if we run out of line;
// it should count as part of the last chunk
- if ((cur <= col) && (j < _canvas.text[row].chunks.size() - 1))
+ if ((cur <= col) && (j < _canvas._text[row].chunks.size() - 1))
index++;
else
break;
@@ -2236,24 +2236,24 @@ int MacText::getMouseItem(int x, int y) {
int index = 0;
for (int i = 0; i < row; i++) {
- for (uint j = 0; j < _canvas.text[i].chunks.size(); j++) {
- if (_canvas.text[i].chunks[j].text.empty())
+ for (uint j = 0; j < _canvas._text[i].chunks.size(); j++) {
+ if (_canvas._text[i].chunks[j].text.empty())
continue;
- if (_canvas.text[i].chunks[j].getEncodedText().contains(','))
+ if (_canvas._text[i].chunks[j].getEncodedText().contains(','))
index++;
}
}
int cur = 0;
- for (uint i = 0; i < _canvas.text[row].chunks.size(); i++) {
- if (_canvas.text[row].chunks[i].text.empty())
+ for (uint i = 0; i < _canvas._text[row].chunks.size(); i++) {
+ if (_canvas._text[row].chunks[i].text.empty())
continue;
- for (uint j = 0; j < _canvas.text[row].chunks[i].text.size(); j++) {
+ for (uint j = 0; j < _canvas._text[row].chunks[i].text.size(); j++) {
cur++;
if (cur > col)
break;
- if (_canvas.text[row].chunks[i].text[j] == ',')
+ if (_canvas._text[row].chunks[i].text[j] == ',')
index++;
}
@@ -2288,11 +2288,11 @@ Common::U32String MacText::getMouseLink(int x, int y) {
if (chunk < 0)
return Common::U32String();
- if (!_canvas.text[row].picfname.empty())
- return _canvas.text[row].pictitle;
+ if (!_canvas._text[row].picfname.empty())
+ return _canvas._text[row].pictitle;
- if (!_canvas.text[row].chunks[chunk].link.empty())
- return _canvas.text[row].chunks[chunk].link;
+ if (!_canvas._text[row].chunks[chunk].link.empty())
+ return _canvas._text[row].chunks[chunk].link;
return Common::U32String();
}
@@ -2300,27 +2300,27 @@ Common::U32String MacText::getMouseLink(int x, int y) {
int MacText::getAlignOffset(int row) {
int alignOffset = 0;
if (_textAlignment == kTextAlignRight)
- alignOffset = MAX<int>(0, _canvas.maxWidth - getLineWidth(row) - 1);
+ alignOffset = MAX<int>(0, _canvas._maxWidth - getLineWidth(row) - 1);
else if (_textAlignment == kTextAlignCenter)
- alignOffset = (_canvas.maxWidth / 2) - (getLineWidth(row) / 2);
+ alignOffset = (_canvas._maxWidth / 2) - (getLineWidth(row) / 2);
return alignOffset;
}
void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col, int *chunk_) {
int nsx = 0, nsy = 0, nrow = 0, ncol = 0;
- if (y > _canvas.textMaxHeight) {
- x = _canvas.surface->w;
+ if (y > _canvas._textMaxHeight) {
+ x = _canvas._surface->w;
}
- y = CLIP(y, 0, _canvas.textMaxHeight);
+ y = CLIP(y, 0, _canvas._textMaxHeight);
- nrow = _canvas.text.size();
+ nrow = _canvas._text.size();
// use [lb, ub) bsearch here, final answer would be lb
int lb = 0, ub = nrow;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
- if (_canvas.text[mid].y <= y) {
+ if (_canvas._text[mid].y <= y) {
lb = mid;
} else {
ub = mid;
@@ -2328,40 +2328,40 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col, int
}
nrow = lb;
- nsy = _canvas.text[nrow].y;
+ nsy = _canvas._text[nrow].y;
int chunk = -1;
- if (_canvas.text[nrow].chunks.size() > 0) {
- int alignOffset = getAlignOffset(nrow) + _canvas.text[nrow].indent + _canvas.text[nrow].firstLineIndent;;
+ if (_canvas._text[nrow].chunks.size() > 0) {
+ int alignOffset = getAlignOffset(nrow) + _canvas._text[nrow].indent + _canvas._text[nrow].firstLineIndent;;
int width = 0, pwidth = 0;
int mcol = 0, pmcol = 0;
- for (chunk = 0; chunk < (int)_canvas.text[nrow].chunks.size(); chunk++) {
+ for (chunk = 0; chunk < (int)_canvas._text[nrow].chunks.size(); chunk++) {
pwidth = width;
pmcol = mcol;
- if (!_canvas.text[nrow].chunks[chunk].text.empty()) {
- width += getStringWidth(_canvas.text[nrow].chunks[chunk], _canvas.text[nrow].chunks[chunk].text);
- mcol += _canvas.text[nrow].chunks[chunk].text.size();
+ if (!_canvas._text[nrow].chunks[chunk].text.empty()) {
+ width += getStringWidth(_canvas._text[nrow].chunks[chunk], _canvas._text[nrow].chunks[chunk].text);
+ mcol += _canvas._text[nrow].chunks[chunk].text.size();
}
if (width + alignOffset > x)
break;
}
- if (chunk >= (int)_canvas.text[nrow].chunks.size())
- chunk = _canvas.text[nrow].chunks.size() - 1;
+ if (chunk >= (int)_canvas._text[nrow].chunks.size())
+ chunk = _canvas._text[nrow].chunks.size() - 1;
if (chunk_)
*chunk_ = (int)chunk;
- Common::U32String str = _canvas.text[nrow].chunks[chunk].text;
+ Common::U32String str = _canvas._text[nrow].chunks[chunk].text;
ncol = mcol;
nsx = pwidth;
for (int i = str.size(); i >= 0; i--) {
- int strw = getStringWidth(_canvas.text[nrow].chunks[chunk], str);
+ int strw = getStringWidth(_canvas._text[nrow].chunks[chunk], str);
if (strw + pwidth + alignOffset <= x) {
ncol = pmcol + i;
nsx = strw + pwidth;
@@ -2388,7 +2388,7 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col, int
// This happens when a long paragraph is split into several lines
#define ADDFORMATTING() \
if (formatted) { \
- formatting = Common::U32String(_canvas.text[i].chunks[chunk].toString()); \
+ formatting = Common::U32String(_canvas._text[i].chunks[chunk].toString()); \
if (formatting != prevformatting) { \
res += formatting; \
prevformatting = formatting; \
@@ -2399,24 +2399,24 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
Common::U32String res("");
if (endRow == -1)
- endRow = _canvas.text.size() - 1;
+ endRow = _canvas._text.size() - 1;
if (endCol == -1)
endCol = getLineCharWidth(endRow);
- if (_canvas.text.empty()) {
+ if (_canvas._text.empty()) {
return res;
}
- startRow = CLIP(startRow, 0, (int)_canvas.text.size() - 1);
- endRow = CLIP(endRow, 0, (int)_canvas.text.size() - 1);
+ startRow = CLIP(startRow, 0, (int)_canvas._text.size() - 1);
+ endRow = CLIP(endRow, 0, (int)_canvas._text.size() - 1);
Common::U32String formatting(""), prevformatting("");
for (int i = startRow; i <= endRow; i++) {
// We requested only part of one line
if (i == startRow && i == endRow) {
- for (uint chunk = 0; chunk < _canvas.text[i].chunks.size(); chunk++) {
- if (_canvas.text[i].chunks[chunk].text.empty()) {
+ for (uint chunk = 0; chunk < _canvas._text[i].chunks.size(); chunk++) {
+ if (_canvas._text[i].chunks[chunk].text.empty()) {
// skip empty chunks, but keep them formatted,
// a text input box needs to keep the formatting even when all text is removed.
ADDFORMATTING();
@@ -2426,68 +2426,68 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
if (startCol <= 0) {
ADDFORMATTING();
- if (endCol >= (int)_canvas.text[i].chunks[chunk].text.size())
- res += _canvas.text[i].chunks[chunk].text;
+ if (endCol >= (int)_canvas._text[i].chunks[chunk].text.size())
+ res += _canvas._text[i].chunks[chunk].text;
else
- res += _canvas.text[i].chunks[chunk].text.substr(0, endCol);
- } else if ((int)_canvas.text[i].chunks[chunk].text.size() > startCol) {
+ res += _canvas._text[i].chunks[chunk].text.substr(0, endCol);
+ } else if ((int)_canvas._text[i].chunks[chunk].text.size() > startCol) {
ADDFORMATTING();
- res += _canvas.text[i].chunks[chunk].text.substr(startCol, endCol - startCol);
+ res += _canvas._text[i].chunks[chunk].text.substr(startCol, endCol - startCol);
}
- startCol -= _canvas.text[i].chunks[chunk].text.size();
- endCol -= _canvas.text[i].chunks[chunk].text.size();
+ startCol -= _canvas._text[i].chunks[chunk].text.size();
+ endCol -= _canvas._text[i].chunks[chunk].text.size();
if (endCol <= 0)
break;
}
// We are at the top line and it is not completely requested
} else if (i == startRow && startCol != 0) {
- for (uint chunk = 0; chunk < _canvas.text[i].chunks.size(); chunk++) {
- if (_canvas.text[i].chunks[chunk].text.empty()) // skip empty chunks
+ for (uint chunk = 0; chunk < _canvas._text[i].chunks.size(); chunk++) {
+ if (_canvas._text[i].chunks[chunk].text.empty()) // skip empty chunks
continue;
if (startCol <= 0) {
ADDFORMATTING();
- res += _canvas.text[i].chunks[chunk].text;
- } else if ((int)_canvas.text[i].chunks[chunk].text.size() > startCol) {
+ res += _canvas._text[i].chunks[chunk].text;
+ } else if ((int)_canvas._text[i].chunks[chunk].text.size() > startCol) {
ADDFORMATTING();
- res += _canvas.text[i].chunks[chunk].text.substr(startCol);
+ res += _canvas._text[i].chunks[chunk].text.substr(startCol);
}
- startCol -= _canvas.text[i].chunks[chunk].text.size();
+ startCol -= _canvas._text[i].chunks[chunk].text.size();
}
- if (newlines && _canvas.text[i].paragraphEnd)
+ if (newlines && _canvas._text[i].paragraphEnd)
res += '\n';
// We are at the end row, and it could be not completely requested
} else if (i == endRow) {
- for (uint chunk = 0; chunk < _canvas.text[i].chunks.size(); chunk++) {
- if (_canvas.text[i].chunks[chunk].text.empty()) // skip empty chunks
+ for (uint chunk = 0; chunk < _canvas._text[i].chunks.size(); chunk++) {
+ if (_canvas._text[i].chunks[chunk].text.empty()) // skip empty chunks
continue;
ADDFORMATTING();
- if (endCol >= (int)_canvas.text[i].chunks[chunk].text.size())
- res += _canvas.text[i].chunks[chunk].text;
+ if (endCol >= (int)_canvas._text[i].chunks[chunk].text.size())
+ res += _canvas._text[i].chunks[chunk].text;
else
- res += _canvas.text[i].chunks[chunk].text.substr(0, endCol);
+ res += _canvas._text[i].chunks[chunk].text.substr(0, endCol);
- endCol -= _canvas.text[i].chunks[chunk].text.size();
+ endCol -= _canvas._text[i].chunks[chunk].text.size();
if (endCol <= 0)
break;
}
// We are in the middle of requested range, pass whole line
} else {
- for (uint chunk = 0; chunk < _canvas.text[i].chunks.size(); chunk++) {
- if (_canvas.text[i].chunks[chunk].text.empty()) // skip empty chunks
+ for (uint chunk = 0; chunk < _canvas._text[i].chunks.size(); chunk++) {
+ if (_canvas._text[i].chunks[chunk].text.empty()) // skip empty chunks
continue;
ADDFORMATTING();
- res += _canvas.text[i].chunks[chunk].text;
+ res += _canvas._text[i].chunks[chunk].text;
}
- if (newlines && _canvas.text[i].paragraphEnd)
+ if (newlines && _canvas._text[i].paragraphEnd)
res += '\n';
}
}
@@ -2500,15 +2500,15 @@ void MacText::insertTextFromClipboard() {
int ppos = 0;
Common::U32String str = _wm->getTextFromClipboard(Common::U32String(_defaultFormatting.toString()), &ppos);
- if (_canvas.text.empty()) {
+ if (_canvas._text.empty()) {
splitString(str, 0);
} else {
int start = _cursorRow, end = _cursorRow;
- while (start && !_canvas.text[start - 1].paragraphEnd)
+ while (start && !_canvas._text[start - 1].paragraphEnd)
start--;
- while (end < (int)_canvas.text.size() - 1 && !_canvas.text[end].paragraphEnd)
+ while (end < (int)_canvas._text.size() - 1 && !_canvas._text[end].paragraphEnd)
end++;
for (int i = start; i < _cursorRow; i++)
@@ -2520,7 +2520,7 @@ void MacText::insertTextFromClipboard() {
// Remove it from the text
for (int i = start; i <= end; i++) {
- _canvas.text.remove_at(start);
+ _canvas._text.remove_at(start);
}
splitString(pre_str + str + sub_str, start);
@@ -2540,7 +2540,7 @@ void MacText::insertTextFromClipboard() {
void MacText::setText(const Common::U32String &str) {
_str = str;
- _canvas.text.clear();
+ _canvas._text.clear();
splitString(_str);
_cursorRow = _cursorCol = 0;
@@ -2560,14 +2560,14 @@ void MacText::setText(const Common::U32String &str) {
//////////////////
// Text editing
void MacText::insertChar(byte c, int *row, int *col) {
- if (_canvas.text.empty()) {
+ if (_canvas._text.empty()) {
appendTextDefault(Common::String(c));
(*col)++;
return;
}
- MacTextLine *line = &_canvas.text[*row];
+ MacTextLine *line = &_canvas._text[*row];
int pos = *col;
uint ch = line->getChunkNum(&pos);
@@ -2585,7 +2585,7 @@ void MacText::insertChar(byte c, int *row, int *col) {
(*col)++;
- if (getLineWidth(*row) - oldw + chunkw > _canvas.maxWidth) { // Needs reshuffle
+ if (getLineWidth(*row) - oldw + chunkw > _canvas._maxWidth) { // Needs reshuffle
reshuffleParagraph(row, col);
_fullRefresh = true;
recalcDims();
@@ -2594,10 +2594,10 @@ void MacText::insertChar(byte c, int *row, int *col) {
recalcDims();
render(*row, *row);
}
- for (int i = 0; i < (int)_canvas.text.size(); i++) {
- D(9, "**insertChar line %d isEnd %d", i, _canvas.text[i].paragraphEnd);
- for (int j = 0; j < (int)_canvas.text[i].chunks.size(); j++) {
- D(9, "[%d] \"%s\"",_canvas.text[i].chunks[j].text.size(), Common::toPrintable(_canvas.text[i].chunks[j].text.encode()).c_str());
+ for (int i = 0; i < (int)_canvas._text.size(); i++) {
+ D(9, "**insertChar line %d isEnd %d", i, _canvas._text[i].paragraphEnd);
+ for (int j = 0; j < (int)_canvas._text[i].chunks.size(); j++) {
+ D(9, "[%d] \"%s\"",_canvas._text[i].chunks[j].text.size(), Common::toPrintable(_canvas._text[i].chunks[j].text.encode()).c_str());
}
}
D(9, "**insertChar cursor row %d col %d", _cursorRow, _cursorCol);
@@ -2644,33 +2644,33 @@ void MacText::deletePreviousCharInternal(int *row, int *col) {
(*row)--;
// formatting matches, glue texts as normal
- if (_canvas.text[*row].lastChunk().equals(_canvas.text[*row + 1].firstChunk())) {
- _canvas.text[*row].lastChunk().text += _canvas.text[*row + 1].firstChunk().text;
- _canvas.text[*row + 1].firstChunk().text.clear();
+ if (_canvas._text[*row].lastChunk().equals(_canvas._text[*row + 1].firstChunk())) {
+ _canvas._text[*row].lastChunk().text += _canvas._text[*row + 1].firstChunk().text;
+ _canvas._text[*row + 1].firstChunk().text.clear();
} else {
// formatting doesn't match, move whole chunk
- _canvas.text[*row].chunks.push_back(MacFontRun(_canvas.text[*row + 1].firstChunk()));
- _canvas.text[*row].firstChunk().text.clear();
+ _canvas._text[*row].chunks.push_back(MacFontRun(_canvas._text[*row + 1].firstChunk()));
+ _canvas._text[*row].firstChunk().text.clear();
}
- _canvas.text[*row].paragraphEnd = false;
+ _canvas._text[*row].paragraphEnd = false;
- for (uint i = 1; i < _canvas.text[*row + 1].chunks.size(); i++)
- _canvas.text[*row].chunks.push_back(MacFontRun(_canvas.text[*row + 1].chunks[i]));
+ for (uint i = 1; i < _canvas._text[*row + 1].chunks.size(); i++)
+ _canvas._text[*row].chunks.push_back(MacFontRun(_canvas._text[*row + 1].chunks[i]));
- _canvas.text.remove_at(*row + 1);
+ _canvas._text.remove_at(*row + 1);
} else {
int pos = *col - 1;
- uint ch = _canvas.text[*row].getChunkNum(&pos);
+ uint ch = _canvas._text[*row].getChunkNum(&pos);
- if (pos == (int)_canvas.text[*row].chunks[ch].text.size())
+ if (pos == (int)_canvas._text[*row].chunks[ch].text.size())
pos--;
- _canvas.text[*row].chunks[ch].text.deleteChar(pos);
+ _canvas._text[*row].chunks[ch].text.deleteChar(pos);
(*col)--;
}
- _canvas.text[*row].width = -1; // flush the cache
+ _canvas._text[*row].width = -1; // flush the cache
}
void MacText::deletePreviousChar(int *row, int *col) {
@@ -2678,10 +2678,10 @@ void MacText::deletePreviousChar(int *row, int *col) {
return;
deletePreviousCharInternal(row, col);
- for (int i = 0; i < (int)_canvas.text.size(); i++) {
+ for (int i = 0; i < (int)_canvas._text.size(); i++) {
D(9, "**deleteChar line %d", i);
- for (int j = 0; j < (int)_canvas.text[i].chunks.size(); j++) {
- D(9, "[%d] \"%s\"",_canvas.text[i].chunks[j].text.size(), Common::toPrintable(_canvas.text[i].chunks[j].text.encode()).c_str());
+ for (int j = 0; j < (int)_canvas._text[i].chunks.size(); j++) {
+ D(9, "[%d] \"%s\"",_canvas._text[i].chunks[j].text.size(), Common::toPrintable(_canvas._text[i].chunks[j].text.encode()).c_str());
}
}
D(9, "**deleteChar cursor row %d col %d", _cursorRow, _cursorCol);
@@ -2694,14 +2694,14 @@ void MacText::deletePreviousChar(int *row, int *col) {
}
void MacText::addNewLine(int *row, int *col) {
- if (_canvas.text.empty()) {
+ if (_canvas._text.empty()) {
appendTextDefault(Common::String("\n"));
(*row)++;
return;
}
- MacTextLine *line = &_canvas.text[*row];
+ MacTextLine *line = &_canvas._text[*row];
int pos = *col;
uint ch = line->getChunkNum(&pos);
MacFontRun newchunk = line->chunks[ch];
@@ -2723,19 +2723,19 @@ void MacText::addNewLine(int *row, int *col) {
}
line->width = -1; // Drop cache
- _canvas.text[*row].width = -1; // flush the cache
+ _canvas._text[*row].width = -1; // flush the cache
- _canvas.text.insert_at(*row + 1, newline);
+ _canvas._text.insert_at(*row + 1, newline);
(*row)++;
*col = 0;
reshuffleParagraph(row, col);
- for (int i = 0; i < (int)_canvas.text.size(); i++) {
+ for (int i = 0; i < (int)_canvas._text.size(); i++) {
D(9, "** addNewLine line %d", i);
- for (int j = 0; j < (int)_canvas.text[i].chunks.size(); j++) {
- D(9, "[%d] \"%s\"",_canvas.text[i].chunks[j].text.size(), Common::toPrintable(_canvas.text[i].chunks[j].text.encode()).c_str());
+ for (int j = 0; j < (int)_canvas._text[i].chunks.size(); j++) {
+ D(9, "[%d] \"%s\"",_canvas._text[i].chunks[j].text.size(), Common::toPrintable(_canvas._text[i].chunks[j].text.encode()).c_str());
}
}
D(9, "** addNewLine cursor row %d col %d", _cursorRow, _cursorCol);
@@ -2749,10 +2749,10 @@ void MacText::reshuffleParagraph(int *row, int *col) {
// First, we looking for the paragraph start and end
int start = *row, end = *row;
- while (start && !_canvas.text[start - 1].paragraphEnd)
+ while (start && !_canvas._text[start - 1].paragraphEnd)
start--;
- while (end < (int)_canvas.text.size() - 1 && !_canvas.text[end].paragraphEnd) // stop at last line
+ while (end < (int)_canvas._text.size() - 1 && !_canvas._text[end].paragraphEnd) // stop at last line
end++;
// Get character pos within paragraph
@@ -2768,7 +2768,7 @@ void MacText::reshuffleParagraph(int *row, int *col) {
// Remove it from the text
for (int i = start; i <= end; i++) {
- _canvas.text.remove_at(start);
+ _canvas._text.remove_at(start);
}
// And now read it
@@ -2797,16 +2797,16 @@ static void cursorTimerHandler(void *refCon) {
}
void MacText::updateCursorPos() {
- if (_canvas.text.empty()) {
+ if (_canvas._text.empty()) {
_cursorX = _cursorY = 0;
} else {
undrawCursor();
- _cursorRow = MIN<int>(_cursorRow, _canvas.text.size() - 1);
+ _cursorRow = MIN<int>(_cursorRow, _canvas._text.size() - 1);
int alignOffset = getAlignOffset(_cursorRow);
- _cursorY = _canvas.text[_cursorRow].y - _scrollPos;
+ _cursorY = _canvas._text[_cursorRow].y - _scrollPos;
_cursorX = getLineWidth(_cursorRow, false, _cursorCol) + alignOffset;
}
@@ -2873,12 +2873,12 @@ const Surface *MacText::getImageSurface(Common::String &fname) {
}
void MacText::processTable(int line) {
- Common::Array<MacTextTableRow> *table = _canvas.text[line].table;
+ Common::Array<MacTextTableRow> *table = _canvas._text[line].table;
uint numCols = table->front().cells.size();
Common::Array<int> maxW(numCols), maxL(numCols), colW(numCols);
Common::Array<bool> flex(numCols), wrap(numCols);
- int width = _canvas.maxWidth * 0.9;
+ int width = _canvas._maxWidth * 0.9;
int gutter = 10;
// Compute column widths, both minimal and maximal
@@ -2886,7 +2886,7 @@ void MacText::processTable(int line) {
int i = 0;
for (auto &cell : row.cells) {
int cW = 0, cL = 0;
- for (auto &l : cell.text) {
+ for (auto &l : cell._text) {
(void)getLineWidth(&l); // calculate it
cW = MAX(cW, l.width);
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index d1f236f7d2b..8fa65df2b10 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -119,17 +119,18 @@ struct MacFontRun {
struct MacTextLine;
-struct MacTextCanvas {
- Common::Array<MacTextLine> text;
- uint16 flags = 0;
- ManagedSurface *surface = nullptr, *shadowSurface = nullptr;
- int maxWidth = 0;
- int textMaxWidth = 0;
- int textMaxHeight = 0;
+class MacTextCanvas {
+public:
+ Common::Array<MacTextLine> _text;
+ uint16 _flags = 0;
+ ManagedSurface *_surface = nullptr, *_shadowSurface = nullptr;
+ int _maxWidth = 0;
+ int _textMaxWidth = 0;
+ int _textMaxHeight = 0;
~MacTextCanvas() {
- delete surface;
- delete shadowSurface;
+ delete _surface;
+ delete _shadowSurface;
}
};
@@ -210,7 +211,7 @@ public:
void drawToPoint(ManagedSurface *g, Common::Rect srcRect, Common::Point dstPoint);
void drawToPoint(ManagedSurface *g, Common::Point dstPoint);
- ManagedSurface *getSurface() { return _canvas.surface; }
+ ManagedSurface *getSurface() { return _canvas._surface; }
int getInterLinear() { return _interLinear; }
void setInterLinear(int interLinear);
void setMaxWidth(int maxWidth);
@@ -280,12 +281,12 @@ public:
void appendTextDefault(const Common::String &str, bool skipAdd = false);
void clearText();
void removeLastLine();
- int getLineCount() { return _canvas.text.size(); }
+ int getLineCount() { return _canvas._text.size(); }
int getLineCharWidth(int line, bool enforce = false);
int getLastLineWidth();
- int getTextHeight() { return _canvas.textMaxHeight; }
+ int getTextHeight() { return _canvas._textMaxHeight; }
int getLineHeight(int line);
- int getTextMaxWidth() { return _canvas.textMaxWidth; }
+ int getTextMaxWidth() { return _canvas._textMaxWidth; }
void setText(const Common::U32String &str);
Commit: 6004d955ea13fbdfd85f6b1d9d961c4816d8c850
https://github.com/scummvm/scummvm/commit/6004d955ea13fbdfd85f6b1d9d961c4816d8c850
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-09T00:22:15+02:00
Commit Message:
GRAPHICS: MACGUI: Moved several methods to MacTextCanvas
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 6f4d8561132..1d8e0e5d95c 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -119,7 +119,7 @@ uint MacTextLine::getChunkNum(int *col) {
MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::U32String &s, const MacFont *macFont, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, uint16 border, uint16 gutter, uint16 boxShadow, uint16 textShadow, bool fixedDims) :
MacWidget(parent, x, y, w, h, wm, true, border, gutter, boxShadow),
- _macFont(macFont), _textAlignment(textAlignment), _interLinear(interlinear) {
+ _macFont(macFont), _interLinear(interlinear) {
D(6, "MacText::MacText(): fgcolor: %d, bgcolor: %d s: \"%s\"", fgcolor, bgcolor, Common::toPrintable(s.encode()).c_str());
@@ -131,9 +131,13 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
_fgcolor = fgcolor;
_bgcolor = bgcolor;
_textShadow = textShadow;
- _macFontMode = true;
_canvas._maxWidth = maxWidth;
+ _canvas._textAlignment = textAlignment;
+ _canvas._wm = wm;
+ _canvas._bgcolor = bgcolor;
+ _canvas._macFontMode = true;
+ _canvas._macText = this;
if (macFont) {
_defaultFormatting = MacFontRun(_wm);
@@ -151,7 +155,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
// NOTE: This constructor and the one afterward are for MacText engines that don't use widgets. This is the classic was MacText was constructed.
MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont *macFont, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, bool fixedDims) :
MacWidget(nullptr, 0, 0, 0, 0, wm, false, 0, 0, 0),
- _macFont(macFont), _textAlignment(textAlignment), _interLinear(interlinear) {
+ _macFont(macFont), _interLinear(interlinear) {
_str = s;
@@ -160,9 +164,13 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
_fgcolor = fgcolor;
_bgcolor = bgcolor;
_textShadow = 0;
- _macFontMode = true;
_canvas._maxWidth = maxWidth;
+ _canvas._textAlignment = textAlignment;
+ _canvas._wm = wm;
+ _canvas._bgcolor = bgcolor;
+ _canvas._macFontMode = true;
+ _canvas._macText = this;
if (macFont) {
_defaultFormatting = MacFontRun(_wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
@@ -180,7 +188,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
// Working with plain Font
MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *font, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, bool fixedDims) :
MacWidget(nullptr, 0, 0, 0, 0, wm, false, 0, 0, 0),
- _macFont(nullptr), _textAlignment(textAlignment), _interLinear(interlinear) {
+ _macFont(nullptr), _interLinear(interlinear) {
_str = s;
@@ -189,9 +197,13 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *f
_fgcolor = fgcolor;
_bgcolor = bgcolor;
_textShadow = 0;
- _macFontMode = false;
_canvas._maxWidth = maxWidth;
+ _canvas._textAlignment = textAlignment;
+ _canvas._wm = wm;
+ _canvas._bgcolor = bgcolor;
+ _canvas._macFontMode = false;
+ _canvas._macText = this;
if (font) {
_defaultFormatting = MacFontRun(_wm, font, 0, font->getFontHeight(), 0, 0, 0);
@@ -268,7 +280,7 @@ void MacText::init() {
_cursorSurface2->clear(_bgcolor);
reallocSurface();
- setAlignOffset(_textAlignment);
+ setAlignOffset(_canvas._textAlignment);
updateCursorPos();
render();
}
@@ -304,14 +316,14 @@ MacFontRun MacText::getFgColor() {
// we are doing this because we may need to dealing with the plain byte. See ctor of mactext which contains String str instead of U32String str
// thus, if we are passing the str, meaning we are using plainByteMode. And when we calculate the string width. we need to convert it to it's original state first;
-int MacText::getStringWidth(MacFontRun &format, const Common::U32String &str) {
+int getStringWidth(MacFontRun &format, const Common::U32String &str) {
if (format.plainByteMode())
return format.getFont()->getStringWidth(Common::convertFromU32String(str, format.getEncoding()));
else
return format.getFont()->getStringWidth(str);
}
-int MacText::getStringMaxWordWidth(MacFontRun &format, const Common::U32String &str) {
+int getStringMaxWordWidth(MacFontRun &format, const Common::U32String &str) {
if (format.plainByteMode()) {
Common::StringTokenizer tok(Common::convertFromU32String(str, format.getEncoding()));
int maxW = 0;
@@ -633,7 +645,7 @@ void MacText::chopChunk(const Common::U32String &str, int *curLinePtr, int inden
Common::Array<Common::U32String> text;
- int w = getLineWidth(curLine, true);
+ int w = _canvas.getLineWidth(curLine, true);
D(9, "** chopChunk before wrap \"%s\"", Common::toPrintable(str.encode()).c_str());
chunk->getFont()->wordWrapText(str, maxWidth, text, w);
@@ -652,7 +664,7 @@ void MacText::chopChunk(const Common::U32String &str, int *curLinePtr, int inden
chunk->text += text[0];
// Recalc dims
- getLineWidth(curLine, true);
+ _canvas.getLineWidth(curLine, true);
D(9, "** chopChunk, subchunk: \"%s\" (%d lines, maxW: %d)", toPrintable(text[0].encode()).c_str(), text.size(), maxWidth);
@@ -957,6 +969,8 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
curTextLine->table->back().cells.push_back(MacTextCanvas());
curTextLine->table->back().cells.back()._flags = flags;
+ curTextLine->table->back().cells.back()._wm = _wm;
+ curTextLine->table->back().cells.back()._macText = this;
curTextLine->table->back().cells.back()._text.resize(1);
curTextLine = &curTextLine->table->back().cells.back()._text[0];
@@ -985,7 +999,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
fontId, textSlant, fontSize, chunk.fgcolor);
// So far, we enforce single font here, though in the future, font size could be altered
- if (!_macFontMode)
+ if (!_canvas._macFontMode)
chunk.font = _defaultFormatting.font;
}
}
@@ -1093,8 +1107,12 @@ void MacText::render() {
}
void MacText::render(int from, int to, int shadow) {
- int w = MIN(_canvas._maxWidth, _canvas._textMaxWidth);
- ManagedSurface *surface = shadow ? _canvas._shadowSurface : _canvas._surface;
+ _canvas.render(from, to, shadow);
+}
+
+void MacTextCanvas::render(int from, int to, int shadow) {
+ int w = MIN(_maxWidth, _textMaxWidth);
+ ManagedSurface *surface = shadow ? _shadowSurface : _surface;
int myFrom = from, myTo = to + 1, delta = 1;
@@ -1105,11 +1123,11 @@ void MacText::render(int from, int to, int shadow) {
}
for (int i = myFrom; i != myTo; i += delta) {
- if (!_canvas._text[i].picfname.empty()) {
- const Surface *image = getImageSurface(_canvas._text[i].picfname);
+ if (!_text[i].picfname.empty()) {
+ const Surface *image = _macText->getImageSurface(_text[i].picfname);
- int xOffset = (_canvas._text[i].width - _canvas._text[i].charwidth) / 2;
- Common::Rect bbox(xOffset, _canvas._text[i].y, xOffset + _canvas._text[i].charwidth, _canvas._text[i].y + _canvas._text[i].height);
+ int xOffset = (_text[i].width - _text[i].charwidth) / 2;
+ Common::Rect bbox(xOffset, _text[i].y, xOffset + _text[i].charwidth, _text[i].y + _text[i].height);
if (image)
surface->blitFrom(image, Common::Rect(0, 0, image->w, image->h), bbox);
@@ -1117,46 +1135,46 @@ void MacText::render(int from, int to, int shadow) {
continue;
}
- int xOffset = getAlignOffset(i) + _canvas._text[i].indent + _canvas._text[i].firstLineIndent;
+ int xOffset = getAlignOffset(i) + _text[i].indent + _text[i].firstLineIndent;
xOffset++;
- int start = 0, end = _canvas._text[i].chunks.size();
+ int start = 0, end = _text[i].chunks.size();
if (_wm->_language == Common::HE_ISR) {
- start = _canvas._text[i].chunks.size() - 1;
+ start = _text[i].chunks.size() - 1;
end = -1;
}
int maxAscentForRow = 0;
for (int j = start; j != end; j += delta) {
- if (_canvas._text[i].chunks[j].font->getFontAscent() > maxAscentForRow)
- maxAscentForRow = _canvas._text[i].chunks[j].font->getFontAscent();
+ if (_text[i].chunks[j].font->getFontAscent() > maxAscentForRow)
+ maxAscentForRow = _text[i].chunks[j].font->getFontAscent();
}
// TODO: _canvas._textMaxWidth, when -1, was not rendering ANY text.
for (int j = start; j != end; j += delta) {
debug(9, "MacText::render: line %d[%d] h:%d at %d,%d (%s) fontid: %d fontsize: %d on %dx%d, fgcolor: %08x bgcolor: %08x, font: %p",
- i, j, _canvas._text[i].height, xOffset, _canvas._text[i].y, _canvas._text[i].chunks[j].text.encode().c_str(),
- _canvas._text[i].chunks[j].fontId, _canvas._text[i].chunks[j].fontSize, _canvas._surface->w, _canvas._surface->h, _canvas._text[i].chunks[j].fgcolor, _bgcolor,
- (const void *)_canvas._text[i].chunks[j].getFont());
+ i, j, _text[i].height, xOffset, _text[i].y, _text[i].chunks[j].text.encode().c_str(),
+ _text[i].chunks[j].fontId, _text[i].chunks[j].fontSize, _surface->w, _surface->h, _text[i].chunks[j].fgcolor, _bgcolor,
+ (const void *)_text[i].chunks[j].getFont());
- if (_canvas._text[i].chunks[j].text.empty())
+ if (_text[i].chunks[j].text.empty())
continue;
int yOffset = 0;
- if (_canvas._text[i].chunks[j].font->getFontAscent() < maxAscentForRow) {
- yOffset = maxAscentForRow - _canvas._text[i].chunks[j].font->getFontAscent();
+ if (_text[i].chunks[j].font->getFontAscent() < maxAscentForRow) {
+ yOffset = maxAscentForRow - _text[i].chunks[j].font->getFontAscent();
}
- if (_canvas._text[i].chunks[j].plainByteMode()) {
- Common::String str = _canvas._text[i].chunks[j].getEncodedText();
- _canvas._text[i].chunks[j].getFont()->drawString(surface, str, xOffset, _canvas._text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas._text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
- xOffset += _canvas._text[i].chunks[j].getFont()->getStringWidth(str);
+ if (_text[i].chunks[j].plainByteMode()) {
+ Common::String str = _text[i].chunks[j].getEncodedText();
+ _text[i].chunks[j].getFont()->drawString(surface, str, xOffset, _text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
+ xOffset += _text[i].chunks[j].getFont()->getStringWidth(str);
} else {
if (_wm->_language == Common::HE_ISR)
- _canvas._text[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_canvas._text[i].chunks[j].text, Common::BIDI_PAR_RTL), xOffset, _canvas._text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas._text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
+ _text[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_text[i].chunks[j].text, Common::BIDI_PAR_RTL), xOffset, _text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
else
- _canvas._text[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_canvas._text[i].chunks[j].text), xOffset, _canvas._text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _canvas._text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
- xOffset += _canvas._text[i].chunks[j].getFont()->getStringWidth(_canvas._text[i].chunks[j].text);
+ _text[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_text[i].chunks[j].text), xOffset, _text[i].y + yOffset, w, shadow ? _wm->_colorBlack : _text[i].chunks[j].fgcolor, kTextAlignLeft, 0, true);
+ xOffset += _text[i].chunks[j].getFont()->getStringWidth(_text[i].chunks[j].text);
}
}
}
@@ -1190,27 +1208,25 @@ void MacText::render(int from, int to) {
}
}
-int MacText::getLineWidth(int line, bool enforce, int col) {
- if ((uint)line >= _canvas._text.size())
+int MacTextCanvas::getLineWidth(int lineNum, bool enforce, int col) {
+ if ((uint)lineNum >= _text.size())
return 0;
- return getLineWidth(&_canvas._text[line], enforce, col);
-}
+ MacTextLine *line = &_text[lineNum];
-int MacText::getLineWidth(MacTextLine *line, bool enforce, int col) {
if (line->width != -1 && !enforce && col == -1)
return line->width;
if (!line->picfname.empty()) {
- const Surface *image = getImageSurface(line->picfname);
+ const Surface *image = _macText->getImageSurface(line->picfname);
if (image) {
- float ratio = _canvas._maxWidth * line->picpercent / 100.0 / (float)image->w;
- line->width = _canvas._maxWidth;
+ float ratio = _maxWidth * line->picpercent / 100.0 / (float)image->w;
+ line->width = _maxWidth;
line->height = image->h * ratio;
line->charwidth = image->w * ratio;
} else {
- line->width = _canvas._maxWidth;
+ line->width = _maxWidth;
line->height = 1;
line->charwidth = 1;
}
@@ -1289,14 +1305,14 @@ int MacText::getLastLineWidth() {
if (_canvas._text.size() == 0)
return 0;
- return getLineWidth(_canvas._text.size() - 1, true);
+ return _canvas.getLineWidth(_canvas._text.size() - 1, true);
}
int MacText::getLineHeight(int line) {
if ((uint)line >= _canvas._text.size())
return 0;
- getLineWidth(line); // This calculates height also
+ _canvas.getLineWidth(line); // This calculates height also
return _canvas._text[line].height;
}
@@ -1322,7 +1338,7 @@ void MacText::recalcDims() {
// We must calculate width first, because it enforces
// the computation. Calling Height() will return cached value!
- _canvas._textMaxWidth = MAX(_canvas._textMaxWidth, getLineWidth(i, true));
+ _canvas._textMaxWidth = MAX(_canvas._textMaxWidth, _canvas.getLineWidth(i, true));
y += MAX(getLineHeight(i), _interLinear);
}
@@ -1346,12 +1362,12 @@ void MacText::recalcDims() {
}
void MacText::setAlignOffset(TextAlign align) {
- if (_textAlignment == align)
+ if (_canvas._textAlignment == align)
return;
_contentIsDirty = true;
_fullRefresh = true;
- _textAlignment = align;
+ _canvas._textAlignment = align;
}
Common::Point MacText::calculateOffset() {
@@ -1718,7 +1734,7 @@ void MacText::drawSelection(int xoff, int yoff) {
x2 = s.endX;
// deal with the first line, which is not a complete line
if (numLines) {
- alignOffset = getAlignOffset(start_row);
+ alignOffset = _canvas.getAlignOffset(start_row);
if (start_row == s.startRow && s.startCol != 0) {
x1 = MIN<int>(x1 + xoff + alignOffset, maxSelectionWidth);
@@ -1738,7 +1754,7 @@ void MacText::drawSelection(int xoff, int yoff) {
x1 = 0;
x2 = maxSelectionWidth;
- alignOffset = getAlignOffset(row);
+ alignOffset = _canvas.getAlignOffset(row);
numLines = getLineHeight(row);
if (y + _scrollPos == s.startY && s.startX > 0)
@@ -2297,12 +2313,12 @@ Common::U32String MacText::getMouseLink(int x, int y) {
return Common::U32String();
}
-int MacText::getAlignOffset(int row) {
+int MacTextCanvas::getAlignOffset(int row) {
int alignOffset = 0;
if (_textAlignment == kTextAlignRight)
- alignOffset = MAX<int>(0, _canvas._maxWidth - getLineWidth(row) - 1);
+ alignOffset = MAX<int>(0, _maxWidth - getLineWidth(row) - 1);
else if (_textAlignment == kTextAlignCenter)
- alignOffset = (_canvas._maxWidth / 2) - (getLineWidth(row) / 2);
+ alignOffset = (_maxWidth / 2) - (getLineWidth(row) / 2);
return alignOffset;
}
@@ -2332,7 +2348,7 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col, int
int chunk = -1;
if (_canvas._text[nrow].chunks.size() > 0) {
- int alignOffset = getAlignOffset(nrow) + _canvas._text[nrow].indent + _canvas._text[nrow].firstLineIndent;;
+ int alignOffset = _canvas.getAlignOffset(nrow) + _canvas._text[nrow].indent + _canvas._text[nrow].firstLineIndent;;
int width = 0, pwidth = 0;
int mcol = 0, pmcol = 0;
@@ -2585,7 +2601,7 @@ void MacText::insertChar(byte c, int *row, int *col) {
(*col)++;
- if (getLineWidth(*row) - oldw + chunkw > _canvas._maxWidth) { // Needs reshuffle
+ if (_canvas.getLineWidth(*row) - oldw + chunkw > _canvas._maxWidth) { // Needs reshuffle
reshuffleParagraph(row, col);
_fullRefresh = true;
recalcDims();
@@ -2804,10 +2820,10 @@ void MacText::updateCursorPos() {
_cursorRow = MIN<int>(_cursorRow, _canvas._text.size() - 1);
- int alignOffset = getAlignOffset(_cursorRow);
+ int alignOffset = _canvas.getAlignOffset(_cursorRow);
_cursorY = _canvas._text[_cursorRow].y - _scrollPos;
- _cursorX = getLineWidth(_cursorRow, false, _cursorCol) + alignOffset;
+ _cursorX = _canvas.getLineWidth(_cursorRow, false, _cursorCol) + alignOffset;
}
int cursorHeight = getLineHeight(_cursorRow);
@@ -2886,11 +2902,11 @@ void MacText::processTable(int line) {
int i = 0;
for (auto &cell : row.cells) {
int cW = 0, cL = 0;
- for (auto &l : cell._text) {
- (void)getLineWidth(&l); // calculate it
+ for (uint l = 0; l < cell._text.size(); l++) {
+ (void)cell.getLineWidth(l); // calculate it
- cW = MAX(cW, l.width);
- cL = MAX(cL, l.minWidth);
+ cW = MAX(cW, cell._text[l].width);
+ cL = MAX(cL, cell._text[l].minWidth);
}
maxW[i] = MAX(maxW[i], cW);
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 8fa65df2b10..3ddd1e134c3 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -127,11 +127,32 @@ public:
int _maxWidth = 0;
int _textMaxWidth = 0;
int _textMaxHeight = 0;
+ TextAlign _textAlignment = kTextAlignRight;
+ MacWindowManager *_wm = nullptr;
+ uint32 _bgcolor = 0;
+ bool _macFontMode = true;
+ MacText *_macText;
+public:
~MacTextCanvas() {
delete _surface;
delete _shadowSurface;
}
+
+ void render(int from, int to, int shadow);
+ int getAlignOffset(int row);
+
+ /**
+ * Returns line width in pixels. This takes into account chunks.
+ * The result is cached for faster subsequent calls.
+ *
+ * @param line Line number
+ * @param enforce Flag for indicating skipping the cache and computing the width,
+ * must be called when text gets changed
+ * @param col Compute line width up to specified column, including this column
+ * @return line width in pixels, or 0 for non-existent lines
+ */
+ int getLineWidth(int line, bool enforce = false, int col = -1);
};
struct MacTextTableRow {
@@ -220,7 +241,7 @@ public:
const MacFontRun &getDefaultFormatting() { return _defaultFormatting; }
void setAlignOffset(TextAlign align);
- TextAlign getAlign() { return _textAlignment; }
+ TextAlign getAlign() { return _canvas._textAlignment; }
virtual Common::Point calculateOffset();
void setActive(bool active) override;
void setEditable(bool editable);
@@ -270,10 +291,6 @@ private:
void appendText_(const Common::U32String &strWithFont, uint oldLen);
void deletePreviousCharInternal(int *row, int *col);
void insertTextFromClipboard();
- // getStringWidth for mactext version, because we may have the plain bytes mode
- int getStringWidth(MacFontRun &format, const Common::U32String &str);
- int getStringMaxWordWidth(MacFontRun &format, const Common::U32String &str);
- int getAlignOffset(int row);
MacFontRun getFgColor();
public:
@@ -328,28 +345,12 @@ public:
// Markdown
public:
void setMarkdownText(const Common::U32String &str);
-
-private:
const Surface *getImageSurface(Common::String &fname);
private:
void init();
bool isCutAllowed();
- /**
- * Returns line width in pixels. This takes into account chunks.
- * The result is cached for faster subsequent calls.
- *
- * @param line Line number
- * @param enforce Flag for indicating skipping the cache and computing the width,
- * must be called when text gets changed
- * @param col Compute line width up to specified column, including this column
- * @return line width in pixels, or 0 for non-existent lines
- */
- int getLineWidth(int line, bool enforce = false, int col = -1);
-
- int getLineWidth(MacTextLine *line, bool enforce = false, int col = -1);
-
/**
* Rewraps paragraph containing given text row.
* When text is modified, we redo whole thing again without touching
@@ -398,15 +399,11 @@ protected:
int _selEnd;
int _selStart;
- TextAlign _textAlignment;
-
MacTextCanvas _canvas;
MacFontRun _defaultFormatting;
MacFontRun _currentFormatting;
- bool _macFontMode;
-
bool _inTable = false;
private:
Commit: b2a7bad618703637591dc95be61c6dc70f1cab49
https://github.com/scummvm/scummvm/commit/b2a7bad618703637591dc95be61c6dc70f1cab49
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-09T00:22:15+02:00
Commit Message:
GRAPHICS: MACGUI: Moved more methods int MacTextCanvas
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 1d8e0e5d95c..758014b888e 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -130,10 +130,10 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
_wm = wm;
_fgcolor = fgcolor;
_bgcolor = bgcolor;
- _textShadow = textShadow;
_canvas._maxWidth = maxWidth;
_canvas._textAlignment = textAlignment;
+ _canvas._textShadow = textShadow;
_canvas._wm = wm;
_canvas._bgcolor = bgcolor;
_canvas._macFontMode = true;
@@ -163,10 +163,10 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
_wm = wm;
_fgcolor = fgcolor;
_bgcolor = bgcolor;
- _textShadow = 0;
_canvas._maxWidth = maxWidth;
_canvas._textAlignment = textAlignment;
+ _canvas._textShadow = 0;
_canvas._wm = wm;
_canvas._bgcolor = bgcolor;
_canvas._macFontMode = true;
@@ -196,10 +196,10 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *f
_wm = wm;
_fgcolor = fgcolor;
_bgcolor = bgcolor;
- _textShadow = 0;
_canvas._maxWidth = maxWidth;
_canvas._textAlignment = textAlignment;
+ _canvas._textShadow = 0;
_canvas._wm = wm;
_canvas._bgcolor = bgcolor;
_canvas._macFontMode = false;
@@ -279,7 +279,7 @@ void MacText::init() {
_cursorSurface2 = new ManagedSurface(1, kCursorMaxHeight, _wm->_pixelformat);
_cursorSurface2->clear(_bgcolor);
- reallocSurface();
+ _canvas.reallocSurface();
setAlignOffset(_canvas._textAlignment);
updateCursorPos();
render();
@@ -1050,37 +1050,37 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
}
-void MacText::reallocSurface() {
+void MacTextCanvas::reallocSurface() {
// round to closest 10
//TODO: work out why this rounding doesn't correctly fill the entire width
//int requiredH = (_text.size() + (_text.size() * 10 + 9) / 10) * lineH
- if (!_canvas._surface) {
- _canvas._surface = new ManagedSurface(_canvas._maxWidth, _canvas._textMaxHeight, _wm->_pixelformat);
+ if (!_surface) {
+ _surface = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
if (_textShadow)
- _canvas._shadowSurface = new ManagedSurface(_canvas._maxWidth, _canvas._textMaxHeight, _wm->_pixelformat);
+ _shadowSurface = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
return;
}
- if (_canvas._surface->w < _canvas._maxWidth || _canvas._surface->h < _canvas._textMaxHeight) {
+ if (_surface->w < _maxWidth || _surface->h < _textMaxHeight) {
// realloc surface and copy old content
- ManagedSurface *n = new ManagedSurface(_canvas._maxWidth, _canvas._textMaxHeight, _wm->_pixelformat);
+ ManagedSurface *n = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
n->clear(_bgcolor);
- n->blitFrom(*_canvas._surface, Common::Point(0, 0));
+ n->blitFrom(*_surface, Common::Point(0, 0));
- delete _canvas._surface;
- _canvas._surface = n;
+ delete _surface;
+ _surface = n;
// same as shadow surface
if (_textShadow) {
- ManagedSurface *newShadowSurface = new ManagedSurface(_canvas._maxWidth, _canvas._textMaxHeight, _wm->_pixelformat);
+ ManagedSurface *newShadowSurface = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
newShadowSurface->clear(_bgcolor);
- newShadowSurface->blitFrom(*_canvas._shadowSurface, Common::Point(0, 0));
+ newShadowSurface->blitFrom(*_shadowSurface, Common::Point(0, 0));
- delete _canvas._shadowSurface;
- _canvas._shadowSurface = newShadowSurface;
+ delete _shadowSurface;
+ _shadowSurface = newShadowSurface;
}
}
}
@@ -1088,10 +1088,10 @@ void MacText::reallocSurface() {
void MacText::render() {
if (_fullRefresh) {
_canvas._surface->clear(_bgcolor);
- if (_textShadow)
+ if (_canvas._textShadow)
_canvas._shadowSurface->clear(_bgcolor);
- render(0, _canvas._text.size());
+ _canvas.render(0, _canvas._text.size());
_fullRefresh = false;
@@ -1106,10 +1106,6 @@ void MacText::render() {
}
}
-void MacText::render(int from, int to, int shadow) {
- _canvas.render(from, to, shadow);
-}
-
void MacTextCanvas::render(int from, int to, int shadow) {
int w = MIN(_maxWidth, _textMaxWidth);
ManagedSurface *surface = shadow ? _shadowSurface : _surface;
@@ -1180,17 +1176,17 @@ void MacTextCanvas::render(int from, int to, int shadow) {
}
}
-void MacText::render(int from, int to) {
- if (_canvas._text.empty())
+void MacTextCanvas::render(int from, int to) {
+ if (_text.empty())
return;
reallocSurface();
from = MAX<int>(0, from);
- to = MIN<int>(to, _canvas._text.size() - 1);
+ to = MIN<int>(to, _text.size() - 1);
// Clear the screen
- _canvas._surface->fillRect(Common::Rect(0, _canvas._text[from].y, _canvas._surface->w, _canvas._text[to].y + getLineHeight(to)), _bgcolor);
+ _surface->fillRect(Common::Rect(0, _text[from].y, _surface->w, _text[to].y + getLineHeight(to)), _bgcolor);
// render the shadow surface;
if (_textShadow)
@@ -1198,11 +1194,11 @@ void MacText::render(int from, int to) {
render(from, to, 0);
- for (uint i = 0; i < _canvas._text.size(); i++) {
- debugN(9, "MacText::render: %2d ", i);
+ for (uint i = 0; i < _text.size(); i++) {
+ debugN(9, "MacTextCanvas::render: %2d ", i);
- for (uint j = 0; j < _canvas._text[i].chunks.size(); j++)
- debugN(9, "[%d (%d)] \"%s\" ", _canvas._text[i].chunks[j].fontId, _canvas._text[i].chunks[j].textSlant, _canvas._text[i].chunks[j].text.encode().c_str());
+ for (uint j = 0; j < _text[i].chunks.size(); j++)
+ debugN(9, "[%d (%d)] \"%s\" ", _text[i].chunks[j].fontId, _text[i].chunks[j].textSlant, _text[i].chunks[j].text.encode().c_str());
debug(9, "%s", "");
}
@@ -1309,12 +1305,16 @@ int MacText::getLastLineWidth() {
}
int MacText::getLineHeight(int line) {
- if ((uint)line >= _canvas._text.size())
+ return _canvas.getLineHeight(line);
+}
+
+int MacTextCanvas::getLineHeight(int line) {
+ if ((uint)line >= _text.size())
return 0;
- _canvas.getLineWidth(line); // This calculates height also
+ (void)getLineWidth(line); // This calculates height also
- return _canvas._text[line].height;
+ return _text[line].height;
}
void MacText::setInterLinear(int interLinear) {
@@ -1350,7 +1350,7 @@ void MacText::recalcDims() {
_dims.bottom = newBottom;
delete _composeSurface;
_composeSurface = new ManagedSurface(_dims.width(), _dims.height(), _wm->_pixelformat);
- reallocSurface();
+ _canvas.reallocSurface();
if (!_fullRefresh) {
_fullRefresh = true;
render();
@@ -1496,7 +1496,7 @@ void MacText::appendText_(const Common::U32String &strWithFont, uint oldLen) {
splitString(strWithFont);
recalcDims();
- render(oldLen - 1, _canvas._text.size());
+ _canvas.render(oldLen - 1, _canvas._text.size());
_contentIsDirty = true;
@@ -1522,7 +1522,7 @@ void MacText::appendTextDefault(const Common::U32String &str, bool skipAdd) {
splitString(strWithFont);
recalcDims();
- render(oldLen - 1, _canvas._text.size());
+ _canvas.render(oldLen - 1, _canvas._text.size());
}
void MacText::appendTextDefault(const Common::String &str, bool skipAdd) {
@@ -1565,8 +1565,8 @@ void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int
g->fillRect(Common::Rect(x + xoff, y + yoff, x + w + xoff, y + h + yoff), _bgcolor);
// blit shadow surface first
- if (_textShadow)
- g->blitFrom(*_canvas._shadowSurface, Common::Rect(MIN<int>(_canvas._surface->w, x), MIN<int>(_canvas._surface->h, y), MIN<int>(_canvas._surface->w, x + w), MIN<int>(_canvas._surface->h, y + h)), Common::Point(xoff + _textShadow, yoff + _textShadow));
+ if (_canvas._textShadow)
+ g->blitFrom(*_canvas._shadowSurface, Common::Rect(MIN<int>(_canvas._surface->w, x), MIN<int>(_canvas._surface->h, y), MIN<int>(_canvas._surface->w, x + w), MIN<int>(_canvas._surface->h, y + h)), Common::Point(xoff + _canvas._textShadow, yoff + _canvas._textShadow));
uint32 bgcolor = _bgcolor < 0xff ? _bgcolor : 0;
g->transBlitFrom(*_canvas._surface, Common::Rect(MIN<int>(_canvas._surface->w, x), MIN<int>(_canvas._surface->h, y), MIN<int>(_canvas._surface->w, x + w), MIN<int>(_canvas._surface->h, y + h)), Common::Point(xoff, yoff), bgcolor);
@@ -2608,7 +2608,7 @@ void MacText::insertChar(byte c, int *row, int *col) {
render();
} else {
recalcDims();
- render(*row, *row);
+ _canvas.render(*row, *row);
}
for (int i = 0; i < (int)_canvas._text.size(); i++) {
D(9, "**insertChar line %d isEnd %d", i, _canvas._text[i].paragraphEnd);
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 3ddd1e134c3..ad696e9ceff 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -128,6 +128,7 @@ public:
int _textMaxWidth = 0;
int _textMaxHeight = 0;
TextAlign _textAlignment = kTextAlignRight;
+ int _textShadow = 0;
MacWindowManager *_wm = nullptr;
uint32 _bgcolor = 0;
bool _macFontMode = true;
@@ -139,6 +140,8 @@ public:
delete _shadowSurface;
}
+ void reallocSurface();
+ void render(int from, int to);
void render(int from, int to, int shadow);
int getAlignOffset(int row);
@@ -153,6 +156,7 @@ public:
* @return line width in pixels, or 0 for non-existent lines
*/
int getLineWidth(int line, bool enforce = false, int col = -1);
+ int getLineHeight(int line);
};
struct MacTextTableRow {
@@ -360,10 +364,7 @@ private:
void chopChunk(const Common::U32String &str, int *curLine, int indent, int maxWidth);
void splitString(const Common::U32String &str, int curLine = -1);
- void render(int from, int to, int shadow);
- void render(int from, int to);
void recalcDims();
- void reallocSurface();
void drawSelection(int xoff, int yoff);
void updateCursorPos();
@@ -392,7 +393,6 @@ protected:
const MacFont *_macFont;
int _interLinear;
- int _textShadow;
bool _fixedDims;
Commit: 4fba78c13d7893a2c9f956643ce4b13a033faa02
https://github.com/scummvm/scummvm/commit/4fba78c13d7893a2c9f956643ce4b13a033faa02
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-09T00:22:15+02:00
Commit Message:
GRAPHICS: MACGUI: Render table cells in MacText
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 758014b888e..f24cb551ac6 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -119,7 +119,7 @@ uint MacTextLine::getChunkNum(int *col) {
MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::U32String &s, const MacFont *macFont, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, uint16 border, uint16 gutter, uint16 boxShadow, uint16 textShadow, bool fixedDims) :
MacWidget(parent, x, y, w, h, wm, true, border, gutter, boxShadow),
- _macFont(macFont), _interLinear(interlinear) {
+ _macFont(macFont) {
D(6, "MacText::MacText(): fgcolor: %d, bgcolor: %d s: \"%s\"", fgcolor, bgcolor, Common::toPrintable(s.encode()).c_str());
@@ -134,6 +134,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
_canvas._maxWidth = maxWidth;
_canvas._textAlignment = textAlignment;
_canvas._textShadow = textShadow;
+ _canvas._interLinear = interlinear;
_canvas._wm = wm;
_canvas._bgcolor = bgcolor;
_canvas._macFontMode = true;
@@ -155,7 +156,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
// NOTE: This constructor and the one afterward are for MacText engines that don't use widgets. This is the classic was MacText was constructed.
MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont *macFont, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, bool fixedDims) :
MacWidget(nullptr, 0, 0, 0, 0, wm, false, 0, 0, 0),
- _macFont(macFont), _interLinear(interlinear) {
+ _macFont(macFont) {
_str = s;
@@ -167,6 +168,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
_canvas._maxWidth = maxWidth;
_canvas._textAlignment = textAlignment;
_canvas._textShadow = 0;
+ _canvas._interLinear = interlinear;
_canvas._wm = wm;
_canvas._bgcolor = bgcolor;
_canvas._macFontMode = true;
@@ -188,7 +190,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
// Working with plain Font
MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *font, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, bool fixedDims) :
MacWidget(nullptr, 0, 0, 0, 0, wm, false, 0, 0, 0),
- _macFont(nullptr), _interLinear(interlinear) {
+ _macFont(nullptr) {
_str = s;
@@ -200,6 +202,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *f
_canvas._maxWidth = maxWidth;
_canvas._textAlignment = textAlignment;
_canvas._textShadow = 0;
+ _canvas._interLinear = interlinear;
_canvas._wm = wm;
_canvas._bgcolor = bgcolor;
_canvas._macFontMode = false;
@@ -1318,7 +1321,7 @@ int MacTextCanvas::getLineHeight(int line) {
}
void MacText::setInterLinear(int interLinear) {
- _interLinear = interLinear;
+ _canvas._interLinear = interLinear;
recalcDims();
_fullRefresh = true;
@@ -1327,22 +1330,7 @@ void MacText::setInterLinear(int interLinear) {
}
void MacText::recalcDims() {
- if (_canvas._text.empty())
- return;
-
- int y = 0;
- _canvas._textMaxWidth = 0;
-
- for (uint i = 0; i < _canvas._text.size(); i++) {
- _canvas._text[i].y = y;
-
- // We must calculate width first, because it enforces
- // the computation. Calling Height() will return cached value!
- _canvas._textMaxWidth = MAX(_canvas._textMaxWidth, _canvas.getLineWidth(i, true));
- y += MAX(getLineHeight(i), _interLinear);
- }
-
- _canvas._textMaxHeight = y;
+ _canvas.recalcDims();
if (!_fixedDims) {
int newBottom = _dims.top + _canvas._textMaxHeight + (2 * _border) + _gutter + _shadow;
@@ -1361,6 +1349,25 @@ void MacText::recalcDims() {
}
}
+void MacTextCanvas::recalcDims() {
+ if (_text.empty())
+ return;
+
+ int y = 0;
+ _textMaxWidth = 0;
+
+ for (uint i = 0; i < _text.size(); i++) {
+ _text[i].y = y;
+
+ // We must calculate width first, because it enforces
+ // the computation. Calling Height() will return cached value!
+ _textMaxWidth = MAX(_textMaxWidth, getLineWidth(i, true));
+ y += MAX(getLineHeight(i), _interLinear);
+ }
+
+ _textMaxHeight = y;
+}
+
void MacText::setAlignOffset(TextAlign align) {
if (_canvas._textAlignment == align)
return;
@@ -1547,7 +1554,7 @@ void MacText::removeLastLine() {
if (!_canvas._text.size())
return;
- int h = getLineHeight(_canvas._text.size() - 1) + _interLinear;
+ int h = getLineHeight(_canvas._text.size() - 1) + _canvas._interLinear;
_canvas._surface->fillRect(Common::Rect(0, _canvas._textMaxHeight - h, _canvas._surface->w, _canvas._textMaxHeight), _bgcolor);
@@ -2975,6 +2982,20 @@ void MacText::processTable(int line) {
for (uint i = 0; i < numCols; i++) {
warning("%d: %d", i, colW[i]);
}
+
+ for (auto &row : *table) {
+ int i = 0;
+ for (auto &cell : row.cells) {
+ cell._maxWidth = colW[i];
+
+ cell.recalcDims();
+ cell.reallocSurface();
+ cell._surface->clear(_bgcolor);
+ cell.render(0, cell._text.size());
+
+ i++;
+ }
+ }
}
} // End of namespace Graphics
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index ad696e9ceff..1f797ab4441 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -128,6 +128,7 @@ public:
int _textMaxWidth = 0;
int _textMaxHeight = 0;
TextAlign _textAlignment = kTextAlignRight;
+ int _interLinear = 0;
int _textShadow = 0;
MacWindowManager *_wm = nullptr;
uint32 _bgcolor = 0;
@@ -140,6 +141,7 @@ public:
delete _shadowSurface;
}
+ void recalcDims();
void reallocSurface();
void render(int from, int to);
void render(int from, int to, int shadow);
@@ -237,7 +239,7 @@ public:
void drawToPoint(ManagedSurface *g, Common::Point dstPoint);
ManagedSurface *getSurface() { return _canvas._surface; }
- int getInterLinear() { return _interLinear; }
+ int getInterLinear() { return _canvas._interLinear; }
void setInterLinear(int interLinear);
void setMaxWidth(int maxWidth);
void setDefaultFormatting(uint16 fontId, byte textSlant, uint16 fontSize,
@@ -329,7 +331,7 @@ public:
Common::U32String cutSelection();
const SelectedText *getSelectedText() { return &_selectedText; }
- int getLineSpacing() { return _interLinear; }
+ int getLineSpacing() { return _canvas._interLinear; }
/**
* set the selection of mactext
@@ -392,8 +394,6 @@ protected:
Common::U32String _str;
const MacFont *_macFont;
- int _interLinear;
-
bool _fixedDims;
int _selEnd;
Commit: 0485f4a593b307bfc90b69bd625058c01ea9df8a
https://github.com/scummvm/scummvm/commit/0485f4a593b307bfc90b69bd625058c01ea9df8a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-09T00:22:15+02:00
Commit Message:
SDL: Added (disabled) Markdown table to the Keyboard help
Changed paths:
backends/platform/sdl/sdl.cpp
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index d484926c274..3f5098e50ff 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -1009,6 +1009,7 @@ void OSystem_SDL::clearGraphicsModes() {
static const char * const helpTabs[] = {
_s("Keyboard"),
"",
+#if 1
_s(
"## Keyboard shortcuts\n"
"\n"
@@ -1042,6 +1043,41 @@ _s(
"| `Ctrl+F7` -- Opens virtual keyboard (if enabled). This can also be opened with a long press of the middle mouse button or wheel.\n"
"| `Ctrl+Alt+d` -- Opens the ScummVM debugger\n"
),
+#else
+_s(
+"## Keyboard shortcuts\n"
+"\n"
+"ScummVM supports various in-game keyboard and mouse shortcuts, and since version 2.2.0 these can be manually configured in the **Keymaps tab**, or in the **configuration file**.\n"
+"\n"
+"For game-specific controls, see the [wiki entry](https://wiki.scummvm.org/index.php?title=Category:Supported_Games) for the game you are playing.\n"
+"\n"
+"Default shortcuts are shown in the table.\n"
+"\n"
+"| Shortcut | Description \n"
+"| --------------|------------------\n"
+"| `Ctrl+F5` | Displays the Global Main Menu\n")
+#if defined(MACOSX)
+_s("| `Cmd+q` | Quit (macOS)\n")
+#elif defined(WIN32)
+_s("| `Alt+F4` | Quit (Windows)\n")
+#else
+_s("| `Ctrl+q` | Quit (Linux/Unix)\n")
+_s("| `Ctrl+z` | Quit (other platforms)\n")
+#endif
+_s(
+"| `Ctrl+u` | Mutes all sounds\n"
+"| `Ctrl+m` | Toggles mouse capture\n"
+"| `Ctrl+Alt` and `9` or `0` | Cycles forwards/backwards between graphics filters\n"
+"| `Ctrl+Alt` and `+` or `-` | Increases/decreases the scale factor\n"
+"| `Ctrl+Alt+a` | Toggles aspect ratio correction on/off\n"
+"| `Ctrl+Alt+f` | Toggles between nearest neighbor and bilinear interpolation (graphics filtering on/off)\n"
+"| `Ctrl+Alt+s` | Cycles through stretch modes\n"
+"| `Alt+Enter` | Toggles full screen/windowed mode\n"
+"| `Alt+s` | Takes a screenshot\n"
+"| `Ctrl+F7` | Opens virtual keyboard (if enabled). This can also be opened with a long press of the middle mouse button or wheel.\n"
+"| `Ctrl+Alt+d` | Opens the ScummVM debugger\n"
+),
+#endif
0,
};
More information about the Scummvm-git-logs
mailing list