aboutsummaryrefslogtreecommitdiff
path: root/graphics/macgui
diff options
context:
space:
mode:
authorEugene Sandulenko2019-10-18 17:20:02 +0200
committerEugene Sandulenko2019-10-18 17:20:27 +0200
commit419cb1e7c77f7b8089b19becabff105ea4d5e7d5 (patch)
tree12438010dfa7c00cfe07e5aaed937fab9595fb8f /graphics/macgui
parent9ff8e69aa98b41a92ac561bfbb15efb9cf58cdac (diff)
downloadscummvm-rg350-419cb1e7c77f7b8089b19becabff105ea4d5e7d5.tar.gz
scummvm-rg350-419cb1e7c77f7b8089b19becabff105ea4d5e7d5.tar.bz2
scummvm-rg350-419cb1e7c77f7b8089b19becabff105ea4d5e7d5.zip
GRAPHICS: MACGUI: Switched MacText to U32String internally
Diffstat (limited to 'graphics/macgui')
-rw-r--r--graphics/macgui/mactext.cpp75
-rw-r--r--graphics/macgui/mactext.h21
-rw-r--r--graphics/macgui/mactextwindow.cpp35
-rw-r--r--graphics/macgui/mactextwindow.h14
4 files changed, 99 insertions, 46 deletions
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 366a79ba33..fa2b92f2fc 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -52,7 +52,7 @@ MacText::~MacText() {
delete _macFont;
}
-MacText::MacText(Common::String s, MacWindowManager *wm, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) {
+MacText::MacText(Common::U32String s, MacWindowManager *wm, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) {
_str = s;
_wm = wm;
_macFont = macFont;
@@ -83,6 +83,37 @@ MacText::MacText(Common::String s, MacWindowManager *wm, const MacFont *macFont,
_fullRefresh = true;
}
+MacText::MacText(const Common::String &s, MacWindowManager *wm, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) {
+ _str = Common::U32String(s);
+ _wm = wm;
+ _macFont = macFont;
+ _fgcolor = fgcolor;
+ _bgcolor = bgcolor;
+ _maxWidth = maxWidth;
+ _textMaxWidth = 0;
+ _textMaxHeight = 0;
+ _surface = nullptr;
+ _textAlignment = textAlignment;
+ _interLinear = interlinear;
+
+ if (macFont) {
+ _defaultFormatting.font = wm->_fontMan->getFont(*macFont);
+ } else {
+ _defaultFormatting.font = NULL;
+ }
+
+ _defaultFormatting.wm = wm;
+
+ _currentFormatting = _defaultFormatting;
+
+ if (!_str.empty())
+ splitString(_str);
+
+ recalcDims();
+
+ _fullRefresh = true;
+}
+
void MacText::setMaxWidth(int maxWidth) {
_maxWidth = maxWidth;
@@ -97,10 +128,10 @@ void MacText::setMaxWidth(int maxWidth) {
}
}
-void MacText::splitString(Common::String &str) {
- const char *s = str.c_str();
+void MacText::splitString(Common::U32String &str) {
+ const Common::U32String::value_type *s = str.c_str();
- Common::String tmp;
+ Common::U32String tmp;
bool prevCR = false;
if (_textLines.empty()) {
@@ -161,7 +192,7 @@ void MacText::splitString(Common::String &str) {
}
if (*s == '\r' || *s == '\n' || nextChunk) {
- Common::Array<Common::String> text;
+ Common::Array<Common::U32String> text;
if (!nextChunk)
previousFormatting = _currentFormatting;
@@ -213,7 +244,7 @@ void MacText::splitString(Common::String &str) {
}
if (tmp.size()) {
- Common::Array<Common::String> text;
+ Common::Array<Common::U32String> text;
int w = getLineWidth(curLine, true);
_currentFormatting.getFont()->wordWrapText(tmp, _maxWidth, text, w);
@@ -369,8 +400,8 @@ void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int
}
// Count newline characters in String
-uint getNewlinesInString(const Common::String &str) {
- Common::String::const_iterator p = str.begin();
+uint getNewlinesInString(const Common::U32String &str) {
+ Common::U32String::const_iterator p = str.begin();
uint newLines = 0;
while (*p) {
if (*p == '\n')
@@ -380,7 +411,7 @@ uint getNewlinesInString(const Common::String &str) {
return newLines;
}
-void MacText::appendText(Common::String str, int fontId, int fontSize, int fontSlant, bool skipAdd) {
+void MacText::appendText(Common::U32String str, int fontId, int fontSize, int fontSlant, bool skipAdd) {
uint oldLen = _textLines.size();
MacFontRun fontRun = MacFontRun(_wm, fontId, fontSlant, fontSize, 0, 0, 0);
@@ -398,7 +429,11 @@ void MacText::appendText(Common::String str, int fontId, int fontSize, int fontS
render(oldLen - 1, _textLines.size());
}
-void MacText::appendTextDefault(Common::String str, bool skipAdd) {
+void MacText::appendText(const Common::String &str, int fontId, int fontSize, int fontSlant, bool skipAdd) {
+ appendText(Common::U32String(str), fontId, fontSize, fontSlant, skipAdd);
+}
+
+void MacText::appendTextDefault(Common::U32String str, bool skipAdd) {
uint oldLen = _textLines.size();
_currentFormatting = _defaultFormatting;
@@ -414,6 +449,10 @@ void MacText::appendTextDefault(Common::String str, bool skipAdd) {
render(oldLen - 1, _textLines.size());
}
+void MacText::appendTextDefault(const Common::String &str, bool skipAdd) {
+ appendTextDefault(Common::U32String(str), skipAdd);
+}
+
void MacText::clearText() {
_textLines.clear();
_str.clear();
@@ -424,7 +463,7 @@ void MacText::clearText() {
recalcDims();
}
-void MacText::replaceLastLine(Common::String str) {
+void MacText::replaceLastLine(Common::U32String str) {
int oldLen = MAX<int>(0, _textLines.size() - 1);
// TODO: Recalc length, adapt to _textLines
@@ -485,7 +524,7 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col) {
if (chunk == _textLines[*row].chunks.size())
chunk--;
- Common::String str = _textLines[*row].chunks[chunk].text;
+ Common::U32String str = _textLines[*row].chunks[chunk].text;
*col = mcol;
@@ -501,8 +540,8 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col) {
}
}
-Common::String MacText::getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted, bool newlines) {
- Common::String res;
+Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted, bool newlines) {
+ Common::U32String res;
startRow = CLIP(startRow, 0, (int)_textLines.size() - 1);
endRow = CLIP(endRow, 0, (int)_textLines.size() - 1);
@@ -517,12 +556,12 @@ Common::String MacText::getTextChunk(int startRow, int startCol, int endRow, int
if (endCol >= (int)_textLines[i].chunks[chunk].text.size())
res += _textLines[i].chunks[chunk].text;
else
- res += Common::String(_textLines[i].chunks[chunk].text.c_str(), endCol);
+ res += Common::U32String(_textLines[i].chunks[chunk].text.c_str(), endCol);
} else if ((int)_textLines[i].chunks[chunk].text.size() > startCol) {
if (formatted)
res += _textLines[i].chunks[chunk].toString();
- res += Common::String(_textLines[i].chunks[chunk].text.c_str() + startCol, endCol - startCol);
+ res += Common::U32String(_textLines[i].chunks[chunk].text.c_str() + startCol, endCol - startCol);
}
startCol -= _textLines[i].chunks[chunk].text.size();
@@ -542,7 +581,7 @@ Common::String MacText::getTextChunk(int startRow, int startCol, int endRow, int
if (formatted)
res += _textLines[i].chunks[chunk].toString();
- res += Common::String(_textLines[i].chunks[chunk].text.c_str() + startCol);
+ res += Common::U32String(_textLines[i].chunks[chunk].text.c_str() + startCol);
}
startCol -= _textLines[i].chunks[chunk].text.size();
@@ -559,7 +598,7 @@ Common::String MacText::getTextChunk(int startRow, int startCol, int endRow, int
if (endCol >= (int)_textLines[i].chunks[chunk].text.size())
res += _textLines[i].chunks[chunk].text;
else
- res += Common::String(_textLines[i].chunks[chunk].text.c_str(), endCol);
+ res += Common::U32String(_textLines[i].chunks[chunk].text.c_str(), endCol);
endCol -= _textLines[i].chunks[chunk].text.size();
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 7cb115902e..e66a394c0d 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -32,7 +32,7 @@ namespace Graphics {
class MacWindowManager;
struct MacFontRun {
- Common::String text;
+ Common::U32String text;
uint16 fontId;
byte textSlant;
@@ -88,7 +88,9 @@ struct MacTextLine {
class MacText {
public:
- MacText(Common::String s, MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor,
+ MacText(Common::U32String s, MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor,
+ int maxWidth = -1, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0);
+ MacText(const Common::String &s, MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor,
int maxWidth = -1, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0);
// 0 pixels between the lines by default
~MacText();
@@ -102,10 +104,13 @@ public:
}
void draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff);
- void appendText(Common::String str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular, bool skipAdd = false);
- void appendTextDefault(Common::String str, bool skipAdd = false);
+ void appendText(Common::U32String str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular, bool skipAdd = false);
+ void appendText(const Common::String &str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular, bool skipAdd = false);
+ void appendTextDefault(Common::U32String str, bool skipAdd = false);
+ void appendTextDefault(const Common::String &str, bool skipAdd = false);
void clearText();
- void replaceLastLine(Common::String str);
+ void replaceLastLine(Common::U32String str);
+ void replaceLastLine(const Common::String &str);
void removeLastLine();
int getLineCount() { return _textLines.size(); }
int getTextHeight() { return _textMaxHeight; }
@@ -116,10 +121,10 @@ public:
void getRowCol(int x, int y, int *sx, int *sy, int *row, int *col);
- Common::String getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted = false, bool newlines = true);
+ Common::U32String getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted = false, bool newlines = true);
private:
- void splitString(Common::String &s);
+ void splitString(Common::U32String &s);
void render(int from, int to);
void recalcDims();
void reallocSurface();
@@ -128,7 +133,7 @@ private:
private:
MacWindowManager *_wm;
- Common::String _str;
+ Common::U32String _str;
const MacFont *_macFont;
int _fgcolor, _bgcolor;
diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp
index ebd3dd2377..12af27a908 100644
--- a/graphics/macgui/mactextwindow.cpp
+++ b/graphics/macgui/mactextwindow.cpp
@@ -90,7 +90,7 @@ void MacTextWindow::resize(int w, int h) {
_mactext->setMaxWidth(_maxWidth);
}
-void MacTextWindow::appendText(Common::String str, const MacFont *macFont, bool skipAdd) {
+void MacTextWindow::appendText(Common::U32String str, const MacFont *macFont, bool skipAdd) {
_mactext->appendText(str, macFont->getId(), macFont->getSize(), macFont->getSlant(), skipAdd);
_contentIsDirty = true;
@@ -102,6 +102,10 @@ void MacTextWindow::appendText(Common::String str, const MacFont *macFont, bool
}
}
+void MacTextWindow::appendText(const Common::String &str, const MacFont *macFont, bool skipAdd) {
+ appendText(Common::U32String(str), macFont, skipAdd);
+}
+
void MacTextWindow::clearText() {
_mactext->clearText();
@@ -223,9 +227,9 @@ void MacTextWindow::drawSelection() {
}
}
-Common::String MacTextWindow::getSelection(bool formatted, bool newlines) {
+Common::U32String MacTextWindow::getSelection(bool formatted, bool newlines) {
if (_selectedText.endY == -1)
- return Common::String("");
+ return Common::U32String("");
SelectedText s = _selectedText;
@@ -249,9 +253,9 @@ bool MacTextWindow::isCutAllowed() {
return false;
}
-Common::String MacTextWindow::cutSelection() {
+Common::U32String MacTextWindow::cutSelection() {
if (!isCutAllowed())
- return Common::String("");
+ return Common::U32String("");
SelectedText s = _selectedText;
@@ -260,18 +264,17 @@ Common::String MacTextWindow::cutSelection() {
SWAP(s.startCol, s.endCol);
}
- Common::String selection = _mactext->getTextChunk(s.startRow, s.startCol, s.endRow, s.endCol, false, false);
+ Common::U32String selection = _mactext->getTextChunk(s.startRow, s.startCol, s.endRow, s.endCol, false, false);
- const char *selStart = strstr(_inputText.c_str(), selection.c_str());
+ uint32 selPos = _inputText.find(selection);
- if (!selStart) {
- warning("Cannot find substring '%s' in '%s'", selection.c_str(), _inputText.c_str());
+ if (selPos == Common::U32String::npos) {
+ //warning("Cannot find substring '%s' in '%s'", selection.c_str(), _inputText.c_str()); // Needed encode method
- return Common::String("");
+ return Common::U32String("");
}
- int selPos = selStart - _inputText.c_str();
- Common::String newInput = Common::String(_inputText.c_str(), selPos) + Common::String(_inputText.c_str() + selPos + selection.size());
+ Common::U32String newInput = Common::U32String(_inputText.c_str(), selPos) + Common::U32String(_inputText.c_str() + selPos + selection.size());
clearSelection();
clearInput();
@@ -459,7 +462,7 @@ void MacTextWindow::undrawInput() {
void MacTextWindow::drawInput() {
undrawInput();
- Common::Array<Common::String> text;
+ Common::Array<Common::U32String> text;
// Now recalc new text height
_fontRef->wordWrapText(_inputText, _maxWidth, text);
@@ -482,12 +485,16 @@ void MacTextWindow::clearInput() {
_inputText.clear();
}
-void MacTextWindow::appendInput(Common::String str) {
+void MacTextWindow::appendInput(Common::U32String str) {
_inputText += str;
drawInput();
}
+void MacTextWindow::appendInput(const Common::String &str) {
+ appendInput(Common::U32String(str));
+}
+
//////////////////
// Cursor stuff
static void cursorTimerHandler(void *refCon) {
diff --git a/graphics/macgui/mactextwindow.h b/graphics/macgui/mactextwindow.h
index c236f47e47..9ff7e7fbd1 100644
--- a/graphics/macgui/mactextwindow.h
+++ b/graphics/macgui/mactextwindow.h
@@ -60,7 +60,8 @@ public:
void setTextWindowFont(const MacFont *macFont);
const MacFont *getTextWindowFont();
- void appendText(Common::String str, const MacFont *macFont, bool skipAdd = false);
+ void appendText(Common::U32String str, const MacFont *macFont, bool skipAdd = false);
+ void appendText(const Common::String &str, const MacFont *macFont, bool skipAdd = false);
void clearText();
void setEditable(bool editable) { _editable = editable; }
@@ -68,13 +69,14 @@ public:
void undrawCursor();
- const Common::String getInput() { return _inputText; }
+ const Common::U32String getInput() { return _inputText; }
void clearInput();
- void appendInput(Common::String str);
+ void appendInput(Common::U32String str);
+ void appendInput(const Common::String &str);
- Common::String getSelection(bool formatted = false, bool newlines = true);
+ Common::U32String getSelection(bool formatted = false, bool newlines = true);
void clearSelection();
- Common::String cutSelection();
+ Common::U32String cutSelection();
const SelectedText *getSelectedText() { return &_selectedText; }
private:
@@ -113,7 +115,7 @@ private:
SelectedText _selectedText;
int _maxWidth;
- Common::String _inputText;
+ Common::U32String _inputText;
uint _inputTextHeight;
bool _inputIsDirty;