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.
This commit is contained in:
parent
0f65852d2f
commit
2b06c02d7d
2 changed files with 37 additions and 10 deletions
|
@ -338,23 +338,48 @@ void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int
|
||||||
Common::Point(xoff, yoff));
|
Common::Point(xoff, yoff));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacText::appendText(Common::String str) {
|
// Count newline characters in String
|
||||||
uint oldLen = _textLines.size();
|
uint getNewlinesInString(const Common::String &str) {
|
||||||
uint newLines = 1;
|
Common::String::const_iterator p = str.begin();
|
||||||
|
uint newLines = 0;
|
||||||
// Calc newline characters in str
|
|
||||||
Common::String::iterator p = str.begin();
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
newLines++;
|
newLines++;
|
||||||
p++;
|
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
|
// Resize _textLines appropriately
|
||||||
for (int curLine = 0; curLine < newLines; ++curLine) {
|
for (uint curLine = 0; curLine < numNewLines; ++curLine) {
|
||||||
_textLines.resize(oldLen + newLines);
|
_textLines.resize(oldLen + numNewLines);
|
||||||
_textLines[oldLen + curLine].chunks.push_back(_currentFormatting);
|
_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);
|
splitString(str);
|
||||||
recalcDims();
|
recalcDims();
|
||||||
|
|
|
@ -95,7 +95,9 @@ public:
|
||||||
void setInterLinear(int interLinear);
|
void setInterLinear(int interLinear);
|
||||||
|
|
||||||
void draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff);
|
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);
|
void replaceLastLine(Common::String str);
|
||||||
int getLineCount() { return _textLines.size(); }
|
int getLineCount() { return _textLines.size(); }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue