aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVelocityRa2017-04-04 02:07:35 +0300
committerEugene Sandulenko2017-07-17 23:45:22 +0200
commit2b06c02d7deb866138ff6fa8f469d48313d9afbd (patch)
tree32800dbda96962593bc3484d3d3ef25d9afbe22b
parent0f65852d2f8f4ea2814cb7f626617e6b7c27f49f (diff)
downloadscummvm-rg350-2b06c02d7deb866138ff6fa8f469d48313d9afbd.tar.gz
scummvm-rg350-2b06c02d7deb866138ff6fa8f469d48313d9afbd.tar.bz2
scummvm-rg350-2b06c02d7deb866138ff6fa8f469d48313d9afbd.zip
GRAPHICS: Add MacText::appendText() variants that accept text format args
Made 1 helper method and 1 function to reduce duplication size as much as possible and still keep them useful for other purposes.
-rw-r--r--graphics/macgui/mactext.cpp43
-rw-r--r--graphics/macgui/mactext.h4
2 files changed, 37 insertions, 10 deletions
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index a3154ca460..44dddad3ba 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -338,23 +338,48 @@ void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int
Common::Point(xoff, yoff));
}
-void MacText::appendText(Common::String str) {
- uint oldLen = _textLines.size();
- uint newLines = 1;
-
- // Calc newline characters in str
- Common::String::iterator p = str.begin();
+// Count newline characters in String
+uint getNewlinesInString(const Common::String &str) {
+ Common::String::const_iterator p = str.begin();
+ uint newLines = 0;
while (*p) {
if (*p == '\n')
newLines++;
p++;
}
+ return newLines;
+}
+
+// Appends numNewLines new lines in _textLines, formatted with the MacFontRun specified
+void MacText::resizeAndFormatLines(uint numNewLines, MacFontRun *fontRun) {
+ uint oldLen = _textLines.size();
// Resize _textLines appropriately
- for (int curLine = 0; curLine < newLines; ++curLine) {
- _textLines.resize(oldLen + newLines);
- _textLines[oldLen + curLine].chunks.push_back(_currentFormatting);
+ for (uint curLine = 0; curLine < numNewLines; ++curLine) {
+ _textLines.resize(oldLen + numNewLines);
+ _textLines[oldLen + curLine].chunks.push_back(*fontRun);
}
+}
+
+void MacText::appendText(Common::String str, int fontId, int fontSize, int fontSlant) {
+ uint oldLen = _textLines.size();
+ uint newLines = 1 + getNewlinesInString(str);
+
+ MacFontRun fontRun = MacFontRun(_wm, fontId, fontSlant, 0, fontSize, 0, 0, 0);
+
+ resizeAndFormatLines(newLines, &fontRun);
+
+ splitString(str);
+ recalcDims();
+
+ render(oldLen, _textLines.size());
+}
+
+void MacText::appendTextDefault(Common::String str) {
+ uint oldLen = _textLines.size();
+ uint newLines = 1 + getNewlinesInString(str);
+
+ resizeAndFormatLines(newLines, &_defaultFormatting);
splitString(str);
recalcDims();
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index f0a3ed6a0c..cd2adb3f0e 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -95,7 +95,9 @@ public:
void setInterLinear(int interLinear);
void draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff);
- void appendText(Common::String str);
+ void resizeAndFormatLines(uint numNewLines, MacFontRun * fontRun);
+ void appendText(Common::String str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular);
+ void appendTextDefault(Common::String str);
void replaceLastLine(Common::String str);
int getLineCount() { return _textLines.size(); }