aboutsummaryrefslogtreecommitdiff
path: root/engines/wage/gui-console.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/wage/gui-console.cpp')
-rw-r--r--engines/wage/gui-console.cpp103
1 files changed, 72 insertions, 31 deletions
diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp
index 19b2c5224f..b97b76e635 100644
--- a/engines/wage/gui-console.cpp
+++ b/engines/wage/gui-console.cpp
@@ -63,12 +63,17 @@
namespace Wage {
-const Graphics::Font *Gui::getConsoleFont() {
+const Graphics::MacFont *Gui::getConsoleMacFont() {
Scene *scene = _engine->_world->_player->_currentScene;
- return _wm._fontMan->getFont(*scene->getFont());
+ return scene->getFont();
}
+const Graphics::Font *Gui::getConsoleFont() {
+ return _wm._fontMan->getFont(*getConsoleMacFont());
+}
+
+
void Gui::clearOutput() {
_out.clear();
_lines.clear();
@@ -88,7 +93,6 @@ void Gui::appendText(const char *s) {
// Okay, we got new lines, need to split it
// and push substrings individually
Common::String tmp;
-
for (uint i = 0; i < str.size(); i++) {
if (str[i] == '\n') {
_out.push_back(tmp);
@@ -100,8 +104,16 @@ void Gui::appendText(const char *s) {
tmp += str[i];
}
+ // Process last/leftover line
_out.push_back(tmp);
flowText(tmp);
+
+#ifdef USE_MACTEXTWINDOW
+ // Append _lines content to MacTextWindow after it has
+ // been processed by flowText above
+ for (uint line = 0; line < _lines.size(); ++line)
+ _consoleWindow->appendText(_lines[line], getConsoleMacFont());
+#endif // USE_MACTEXTWINDOW
}
enum {
@@ -114,9 +126,16 @@ enum {
void Gui::flowText(Common::String &str) {
Common::StringArray wrappedLines;
- int textW = _consoleWindow->getInnerDimensions().width() - kConWPadding * 2;
- const Graphics::Font *font = getConsoleFont();
+ int16 conTextWidth = _consoleWindow->getInnerDimensions().width() - kConWPadding * 2;
+ if (conTextWidth <= 0) {
+ warning("Gui::flowText: Console text width is non-positive. Text will not be visible.");
+ return;
+ }
+
+ int textW = conTextWidth;
+
+ const Graphics::Font *font = getConsoleFont();
font->wordWrapText(str, textW, wrappedLines);
if (wrappedLines.empty()) // Sometimes we have empty lines
@@ -142,6 +161,21 @@ void Gui::flowText(Common::String &str) {
draw();
}
+void Gui::reflowText() {
+ _lines.clear();
+
+ for (uint i = 0; i < _out.size(); i++)
+ flowText(_out[i]);
+
+#ifdef USE_MACTEXTWINDOW
+ // Append _lines content to MacTextWindow after it has
+ // been processed by flowText above
+ _consoleWindow->clearText();
+ for (uint line = 0; line < _lines.size(); ++line)
+ _consoleWindow->appendText(_lines[line], getConsoleMacFont());
+#endif // USE_MACTEXTWINDOW
+}
+
void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) {
bool fullRedraw = _consoleFullRedraw;
bool textReflow = false;
@@ -161,21 +195,22 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) {
fullRedraw = true;
}
- if (fullRedraw)
- _console.clear(kColorWhite);
+#ifdef USE_MACTEXTWINDOW
+ // TODO: Call this at an appropriate place (only when the selection can change)
+ _consoleWindow->setSelection(_selectionStartX, _selectionStartY, _selectionEndX, _selectionEndY);
+#endif // USE_MACTEXTWINDOW
+ if (fullRedraw) {
+ _console.clear(kColorWhite);
+ }
const Graphics::Font *font = getConsoleFont();
_consoleLineHeight = font->getFontHeight();
int textW = r.width() - kConWPadding * 2;
int textH = r.height() - kConHPadding * 2;
- if (textReflow) {
- _lines.clear();
-
- for (uint i = 0; i < _out.size(); i++)
- flowText(_out[i]);
- }
+ if (textReflow)
+ reflowText();
const int firstLine = _scrollPos / _consoleLineHeight;
const int lastLine = MIN((_scrollPos + textH) / _consoleLineHeight + 1, _lines.size());
@@ -187,10 +222,13 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) {
if (fullRedraw)
_consoleNumLines = (r.height() - 2 * kConWPadding) / _consoleLineHeight - 2;
- for (int line = firstLine; line < lastLine; line++) {
+#ifndef USE_MACTEXTWINDOW
+
+ for (int line = firstLine; line < lastLine; line++) {
const char *str = _lines[line].c_str();
int color = kColorBlack;
+ // Draw selexted text box except first and last line
if ((line > _selectionStartY && line < _selectionEndY) ||
(line > _selectionEndY && line < _selectionStartY)) {
color = kColorWhite;
@@ -199,7 +237,9 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) {
Design::drawFilledRect(&_console, trect, kColorBlack, _wm.getPatterns(), kPatternSolid);
}
+ // Draw selexted text box on first and last line
if (line == _selectionStartY || line == _selectionEndY) {
+ // Draw selected text if multiple lines are selected
if (_selectionStartY != _selectionEndY) {
int color1 = kColorBlack;
int color2 = kColorWhite;
@@ -223,11 +263,15 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) {
else
trect.left = rectW;
+ // Draw background rectangle on selected text
Design::drawFilledRect(&_console, trect, kColorBlack, _wm.getPatterns(), kPatternSolid);
+ // Draw left of the selected character (either start or end char)
font->drawString(&_console, beg, x1, y1, textW, color1);
+ // Draw right of the selected character (either star or end char)
font->drawString(&_console, end, x1 + rectW - kConWPadding - kConWOverlap, y1, textW, color2);
- } else {
+
+ } else { // Draw selected text if only 1 line is selected
int startPos = _selectionStartX;
int endPos = _selectionEndX;
@@ -242,30 +286,27 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) {
int rectW2 = rectW1 + font->getStringWidth(mid);
Common::Rect trect(rectW1, y1, rectW2, y1 + _consoleLineHeight);
+ // Draw background rectangle on selected text
Design::drawFilledRect(&_console, trect, kColorBlack, _wm.getPatterns(), kPatternSolid);
+ // Draw text left of the first selected character
font->drawString(&_console, beg, x1, y1, textW, kColorBlack);
+ // Draw selected text
font->drawString(&_console, mid, x1 + rectW1 - kConWPadding - kConWOverlap, y1, textW, kColorWhite);
+ // Draw text right of the last selected character
font->drawString(&_console, end, x1 + rectW2 - kConWPadding - kConWOverlap, y1, textW, kColorBlack);
}
- } else {
+ } else { // Neither first nor last line
if (*str) {
font->drawString(&_console, _lines[line], x1, y1, textW, color);
-
- // TODO: Take into account color (and maybe position)
-#ifdef USE_NEW_TEXT_RENDERER
-#ifdef USE_MACTEXTWINDOW
- _consoleWindow->appendText(_lines[line]);
-#else
- _mactext->appendText(_lines[line]);
-#endif // USE_MACTEXTWINDOW
-#endif // USE_OLD_TEXT_RENDERER
}
}
y1 += _consoleLineHeight;
}
+#endif
+
// Now we need to clip it to the screen
int xcon = r.left - kConOverscan;
int ycon = r.top - kConOverscan;
@@ -288,13 +329,11 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) {
if (rr.bottom > _screen.h - 1)
rr.bottom = _screen.h - 1;
-#ifdef USE_NEW_TEXT_RENDERER
#ifdef USE_MACTEXTWINDOW
- _consoleWindow->drawText(&_console, xcon, ycon, rr.width() - xcon, rr.height() - ycon, rr.left, rr.top);
-#else
- _mactext->draw(&_console, xcon, ycon, rr.width() - xcon, rr.height() - ycon, rr.left, rr.top);
+ _consoleWindow->drawText(&_console, 0, 0,
+ boundsR.width(), boundsR.height(),
+ boundsR.left + 7, boundsR.top + 7);
#endif // USE_MACTEXTWINDOW
-#endif // USE_NEW_TEXT_RENDERER
g->copyRectToSurface(_console, xcon, ycon, boundsR);
}
@@ -302,7 +341,6 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) {
void Gui::drawInput() {
if (!_screen.getPixels())
return;
-
_wm.setActive(_consoleWindow->getId());
_out.pop_back();
@@ -310,6 +348,7 @@ void Gui::drawInput() {
appendText(_engine->_inputText.c_str());
_inputTextLineNum = _out.size() - 1;
+ #ifndef USE_MACTEXTWINDOW
const Graphics::Font *font = getConsoleFont();
if (_engine->_inputText.contains('\n')) {
@@ -342,6 +381,8 @@ void Gui::drawInput() {
}
_cursorX = font->getStringWidth(_out[_inputTextLineNum]) + kConHPadding;
+
+#endif // USE_MACTEXTWINDOW
}
void Gui::actionCopy() {