[Scummvm-git-logs] scummvm master -> d4e4a20cc53b28db31a66af3fd5d4b7569fad3c8
sev-
sev at scummvm.org
Tue Jan 31 23:12:57 CET 2017
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
93265c6d41 GRAPHICS: Fix font transtion formatting for MacText
c15e063bbd GRAPHICS: Store more metainformation on lines in MacText
d4e4a20cc5 GRAPHICS: Implement rendering of rich MacText
Commit: 93265c6d41466dd7513472e160a3579c740410dd
https://github.com/scummvm/scummvm/commit/93265c6d41466dd7513472e160a3579c740410dd
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2017-01-31T23:14:37+01:00
Commit Message:
GRAPHICS: Fix font transtion formatting for MacText
Changed paths:
graphics/macgui/mactext.cpp
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 6a3deb2..4b7dc07 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -136,10 +136,11 @@ void MacText::splitString(Common::String &str) {
for (uint i = 0; i < text.size(); i++) {
_text.push_back(text[i]);
+ (_textLines[curLine])[curChunk].text = text[i];
+
curLine++;
_textLines.resize(curLine + 1);
_textLines[curLine].push_back(_currentFormatting);
- (_textLines[curLine])[0].text = text[i];
curChunk = 0;
}
} else {
Commit: c15e063bbd549261e6be020cdd046e7368d22769
https://github.com/scummvm/scummvm/commit/c15e063bbd549261e6be020cdd046e7368d22769
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2017-01-31T23:14:37+01:00
Commit Message:
GRAPHICS: Store more metainformation on lines 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 4b7dc07..426fc29 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -68,11 +68,11 @@ void MacText::splitString(Common::String &str) {
if (_textLines.empty()) {
_textLines.resize(1);
- _textLines[0].push_back(_defaultFormatting);
+ _textLines[0].chunks.push_back(_defaultFormatting);
}
int curLine = _textLines.size() - 1;
- int curChunk = _textLines[curLine].size() - 1;
+ int curChunk = _textLines[curLine].chunks.size() - 1;
bool nextChunk = false;
while (*s) {
@@ -97,11 +97,11 @@ void MacText::splitString(Common::String &str) {
_currentFormatting.setValues(_wm, fontId, textSlant, unk3f, fontSize, palinfo1, palinfo2, palinfo3);
- if ((_textLines[curLine])[curChunk].text.empty()) {
- (_textLines[curLine])[curChunk] = _currentFormatting;
+ if (_textLines[curLine].chunks[curChunk].text.empty()) {
+ _textLines[curLine].chunks[curChunk] = _currentFormatting;
continue;
} else {
- _textLines[curLine].push_back(_currentFormatting);
+ _textLines[curLine].chunks.push_back(_currentFormatting);
}
nextChunk = true;
@@ -123,7 +123,7 @@ void MacText::splitString(Common::String &str) {
if (text.size()) {
if (nextChunk) {
- (_textLines[curLine])[curChunk].text += text[0];
+ _textLines[curLine].chunks[curChunk].text += text[0];
curChunk++;
_text[curLine] += text[0];
@@ -136,16 +136,16 @@ void MacText::splitString(Common::String &str) {
for (uint i = 0; i < text.size(); i++) {
_text.push_back(text[i]);
- (_textLines[curLine])[curChunk].text = text[i];
+ _textLines[curLine].chunks[curChunk].text = text[i];
curLine++;
_textLines.resize(curLine + 1);
- _textLines[curLine].push_back(_currentFormatting);
+ _textLines[curLine].chunks.push_back(_currentFormatting);
curChunk = 0;
}
} else {
if (nextChunk) { // No text, replacing formatting
- (_textLines[curLine])[curChunk] = _currentFormatting;
+ _textLines[curLine].chunks[curChunk] = _currentFormatting;
}
}
@@ -165,7 +165,7 @@ void MacText::splitString(Common::String &str) {
_textMaxWidth = MAX(_font->wordWrapText(tmp, _maxWidth, text), _textMaxWidth);
- (_textLines[curLine])[curChunk].text = text[0];
+ _textLines[curLine].chunks[curChunk].text = text[0];
_text.push_back(text[0]);
@@ -175,8 +175,8 @@ void MacText::splitString(Common::String &str) {
curLine++;
_textLines.resize(curLine + 1);
- _textLines[curLine].push_back(_currentFormatting);
- (_textLines[curLine])[0].text = text[i];
+ _textLines[curLine].chunks.push_back(_currentFormatting);
+ _textLines[curLine].chunks[0].text = text[i];
}
}
}
@@ -242,8 +242,8 @@ void MacText::render(int from, int to) {
for (uint i = 0; i < _textLines.size(); i++) {
debugN(4, "%2d ", i);
- for (uint j = 0; j < _textLines[i].size(); j++)
- debugN(4, "[%d] \"%s\"", (_textLines[i])[j].fontId, (_textLines[i])[j].text.c_str());
+ for (uint j = 0; j < _textLines[i].chunks.size(); j++)
+ debugN(4, "[%d] \"%s\"", _textLines[i].chunks[j].fontId, _textLines[i].chunks[j].text.c_str());
debug(4, "");
}
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 7234cdc..f94b2bc 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -73,6 +73,17 @@ struct MacFontRun {
const Font *getFont();
};
+struct MacTextLine {
+ int width;
+ int height;
+
+ Common::Array<MacFontRun> chunks;
+
+ MacTextLine() {
+ width = height = -1;
+ }
+};
+
class MacText {
public:
MacText(Common::String s, MacWindowManager *wm, const Graphics::Font *font, int fgcolor, int bgcolor,
@@ -112,7 +123,7 @@ private:
TextAlign _textAlignment;
- Common::Array< Common::Array<MacFontRun> > _textLines;
+ Common::Array<MacTextLine> _textLines;
MacFontRun _defaultFormatting;
MacFontRun _currentFormatting;
};
Commit: d4e4a20cc53b28db31a66af3fd5d4b7569fad3c8
https://github.com/scummvm/scummvm/commit/d4e4a20cc53b28db31a66af3fd5d4b7569fad3c8
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2017-01-31T23:14:37+01:00
Commit Message:
GRAPHICS: Implement rendering of rich MacText
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 426fc29..e411903 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -45,19 +45,22 @@ MacText::MacText(Common::String s, MacWindowManager *wm, const Font *font, int f
_bgcolor = bgcolor;
_maxWidth = maxWidth;
_textMaxWidth = 0;
+ _textMaxHeight = 0;
_surface = nullptr;
_textAlignment = textAlignment;
_interLinear = 0; // 0 pixels between the lines by default
- splitString(_str);
-
- _fullRefresh = true;
-
_defaultFormatting.font = font;
_defaultFormatting.wm = wm;
_currentFormatting = _defaultFormatting;
+
+ splitString(_str);
+
+ recalcDims();
+
+ _fullRefresh = true;
}
void MacText::splitString(Common::String &str) {
@@ -118,7 +121,7 @@ void MacText::splitString(Common::String &str) {
if (*s == '\r' || *s == '\n' || nextChunk) {
Common::Array<Common::String> text;
- _textMaxWidth = MAX(_font->wordWrapText(tmp, _maxWidth, text), _textMaxWidth);
+ _font->wordWrapText(tmp, _maxWidth, text);
tmp.clear();
if (text.size()) {
@@ -163,7 +166,7 @@ void MacText::splitString(Common::String &str) {
if (tmp.size()) {
Common::Array<Common::String> text;
- _textMaxWidth = MAX(_font->wordWrapText(tmp, _maxWidth, text), _textMaxWidth);
+ _font->wordWrapText(tmp, _maxWidth, text);
_textLines[curLine].chunks[curChunk].text = text[0];
@@ -183,22 +186,19 @@ void MacText::splitString(Common::String &str) {
}
void MacText::reallocSurface() {
- int lineH = _font->getFontHeight() + _interLinear;
// 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
- int requiredH = _text.size() * lineH;
- int surfW = _textMaxWidth;
if (!_surface) {
- _surface = new ManagedSurface(surfW, requiredH);
+ _surface = new ManagedSurface(_textMaxWidth, _textMaxHeight);
return;
}
- if (_surface->h < requiredH) {
+ if (_surface->h < _textMaxWidth) {
// realloc surface and copy old content
- ManagedSurface *n = new ManagedSurface(surfW, requiredH);
+ ManagedSurface *n = new ManagedSurface(_textMaxWidth, _textMaxHeight);
n->blitFrom(*_surface, Common::Point(0, 0));
delete _surface;
@@ -208,7 +208,7 @@ void MacText::reallocSurface() {
void MacText::render() {
if (_fullRefresh) {
- render(0, _text.size());
+ render(0, _textLines.size());
_fullRefresh = false;
}
@@ -218,25 +218,23 @@ void MacText::render(int from, int to) {
reallocSurface();
from = MAX<int>(0, from);
- to = MIN<int>(to, _text.size());
-
- int lineH = _font->getFontHeight() + _interLinear;
- int y = from * lineH;
+ to = MIN<int>(to, _textLines.size() - 1);
// Clear the screen
- _surface->fillRect(Common::Rect(0, y, _surface->w, to * lineH), _bgcolor);
+ _surface->fillRect(Common::Rect(0, _textLines[from].y, _surface->w, _textLines[to].y + getLineHeight(to)), _bgcolor);
- for (int i = from; i < to; i++) {
+ for (int i = from; i <= to; i++) {
int xOffset = 0;
if (_textAlignment == kTextAlignRight)
- xOffset = _textMaxWidth - _font->getStringWidth(_text[i]);
+ xOffset = _textMaxWidth - getLineWidth(i);
else if (_textAlignment == kTextAlignCenter)
- xOffset = (_textMaxWidth / 2) - (_font->getStringWidth(_text[i]) / 2);
-
- //TODO: _textMaxWidth, when -1, was not rendering ANY text.
- _font->drawString(_surface, _text[i], xOffset, y, _maxWidth, _fgcolor);
+ xOffset = (_textMaxWidth / 2) - (getLineWidth(i) / 2);
- y += _font->getFontHeight() + _interLinear;
+ // TODO: _textMaxWidth, when -1, was not rendering ANY text.
+ for (uint j = 0; j < _textLines[i].chunks.size(); j++) {
+ _textLines[i].chunks[j].getFont()->drawString(_surface, _textLines[i].chunks[j].text, xOffset, _textLines[i].y, _maxWidth, _fgcolor);
+ xOffset += _textLines[i].chunks[j].getFont()->getStringWidth(_textLines[i].chunks[j].text);
+ }
}
for (uint i = 0; i < _textLines.size(); i++) {
@@ -249,6 +247,50 @@ void MacText::render(int from, int to) {
}
}
+int MacText::getLineWidth(int line) {
+ if (line >= _textLines.size())
+ return 0;
+
+ if (_textLines[line].width != -1)
+ return _textLines[line].width;
+
+ int width = 0;
+ int height = 0;
+
+ for (uint i = 0; i < _textLines[line].chunks.size(); i++) {
+ width += _textLines[line].chunks[i].getFont()->getStringWidth(_textLines[line].chunks[i].text);
+ height = MAX(height, _textLines[line].chunks[i].getFont()->getFontHeight());
+ }
+
+ _textLines[line].width = width;
+ _textLines[line].height = height;
+
+ return width;
+}
+
+int MacText::getLineHeight(int line) {
+ if (line >= _textLines.size())
+ return 0;
+
+ getLineWidth(line); // This calculates height also
+
+ return _textLines[line].height;
+}
+
+void MacText::recalcDims() {
+ int y = 0;
+ _textMaxWidth = 0;
+
+ for (uint i = 0; i < _textLines.size(); i++) {
+ _textLines[i].y = y;
+
+ y += getLineHeight(i) + _interLinear;
+ _textMaxWidth = MAX(_textMaxWidth, getLineWidth(i));
+ }
+
+ _textMaxHeight = y;
+}
+
void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff) {
render();
@@ -264,7 +306,10 @@ void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int
void MacText::appendText(Common::String str) {
int oldLen = _text.size();
+ // TODO: Recalc length
+
splitString(str);
+ recalcDims();
render(oldLen + 1, _text.size());
}
@@ -272,10 +317,13 @@ void MacText::appendText(Common::String str) {
void MacText::replaceLastLine(Common::String str) {
int oldLen = MAX<int>(0, _text.size() - 1);
+ // TODO: Recalc length, adapt to _textLines
+
if (_text.size())
_text.pop_back();
splitString(str);
+ recalcDims();
render(oldLen, _text.size());
}
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index f94b2bc..90f85e6 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -76,11 +76,13 @@ struct MacFontRun {
struct MacTextLine {
int width;
int height;
+ int y;
Common::Array<MacFontRun> chunks;
MacTextLine() {
width = height = -1;
+ y = 0;
}
};
@@ -101,8 +103,10 @@ public:
private:
void splitString(Common::String &s);
void render(int from, int to);
- void calcMaxWidth();
+ void recalcDims();
void reallocSurface();
+ int getLineWidth(int line);
+ int getLineHeight(int line);
private:
MacWindowManager *_wm;
@@ -117,6 +121,7 @@ private:
Common::Array<Common::String> _text;
int _textMaxWidth;
+ int _textMaxHeight;
Graphics::ManagedSurface *_surface;
bool _fullRefresh;
More information about the Scummvm-git-logs
mailing list