diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/wage/gui-console.cpp | 103 | ||||
-rw-r--r-- | engines/wage/gui.cpp | 23 | ||||
-rw-r--r-- | engines/wage/gui.h | 27 | ||||
-rw-r--r-- | engines/wage/wage.cpp | 5 |
4 files changed, 87 insertions, 71 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() { diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp index 4c75550f41..54601ccc9f 100644 --- a/engines/wage/gui.cpp +++ b/engines/wage/gui.cpp @@ -173,37 +173,23 @@ Gui::Gui(WageEngine *engine) { _sceneWindow = _wm.addWindow(false, false, false); _sceneWindow->setCallback(sceneWindowCallback, this); +#ifdef USE_MACTEXTWINDOW //TODO: Make the font we use here work // (currently MacFontRun::getFont gets called with the fonts being uninitialized, // so it initializes them by itself with default params, and not those here) -#ifdef USE_NEW_TEXT_RENDERER -#ifdef USE_MACTEXTWINDOW const Graphics::Font *font = _wm._fontMan->getFont(Graphics::MacFont(Graphics::kMacFontChicago, 8)); uint maxWidth = _screen.w; - _consoleWindow = new Graphics::MacTextWindow(&_wm, font, kColorBlack, kColorWhite, - maxWidth, Graphics::kTextAlignCenter); + _consoleWindow = new Graphics::MacTextWindow(&_wm, const_cast<Graphics::Font *>(font), kColorBlack, kColorWhite, + maxWidth, Graphics::kTextAlignLeft); #else - _consoleWindow = _wm.addWindow(true, true, true); - const Graphics::Font *font = _wm._fontMan->getFont(Graphics::MacFont(Graphics::kMacFontChicago, 8)); + _consoleWindow = _wm.addWindow(true, true, true); #endif // USE_MACTEXTWINDOW -#else - _consoleWindow = _wm.addWindow(true, true, true); -#endif // USE_NEW_TEXT_RENDERER _consoleWindow->setCallback(consoleWindowCallback, this); loadBorders(); - -#ifdef USE_NEW_TEXT_RENDERER -#ifndef USE_MACTEXTWINDOW - unsigned maxWidth = _screen.w; - - _mactext = new Graphics::MacText("", &_wm, font, - kColorBlack, kColorWhite, maxWidth, Graphics::kTextAlignCenter); -#endif // USE_MACTEXTWINDOW -#endif // USE_NEW_TEXT_RENDERER } Gui::~Gui() { @@ -236,7 +222,6 @@ void Gui::draw() { _sceneWindow->setDimensions(*_scene->_designBounds); _sceneWindow->setTitle(_scene->_name); - _consoleWindow->setDimensions(*_scene->_textBounds); _wm.setFullRefresh(true); } diff --git a/engines/wage/gui.h b/engines/wage/gui.h index 9bb4659233..5f8be34877 100644 --- a/engines/wage/gui.h +++ b/engines/wage/gui.h @@ -48,20 +48,8 @@ #ifndef WAGE_GUI_H #define WAGE_GUI_H -// Whether to use the new text renderer -// Currently renders along with (on top of) the current one -#define USE_NEW_TEXT_RENDERER - // Whether to use the new MacTextWindow class for rendering the console -// Currently it's just a simple wrapper that mostly only holds a MacText -#define USE_MACTEXTWINDOW - -// Make sure USE_MACTEXTWINDOW can't be defined without USE_NEW_TEXT_RENDERER being defined as well -#ifndef USE_NEW_TEXT_RENDERER -#ifdef USE_MACTEXTWINDOW -#define USE_NEW_TEXT_RENDERER -#endif // USE_MACTEXTWINDOW -#endif // USE_NEW_TEXT_RENDERER +// #define USE_MACTEXTWINDOW #include "common/str-array.h" #include "graphics/font.h" @@ -72,6 +60,7 @@ #else #include "graphics/macgui/macwindow.h" #endif +#include "graphics/macgui/macwindow.h" #include "graphics/macgui/mactext.h" #include "graphics/macgui/macmenu.h" #include "graphics/macgui/macwindowborder.h" @@ -141,6 +130,7 @@ public: void draw(); void appendText(const char *str); + void reflowText(); void clearOutput(); bool processEvent(Common::Event &event); @@ -168,6 +158,7 @@ private: void undrawCursor(); void renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r); void flowText(Common::String &str); + const Graphics::MacFont *getConsoleMacFont(); const Graphics::Font *getConsoleFont(); const Graphics::Font *getTitleFont(); void startMarking(int x, int y); @@ -195,19 +186,13 @@ public: Graphics::MacWindow *_sceneWindow; #ifdef USE_MACTEXTWINDOW - Graphics::MacTextWindow *_consoleWindow; + Graphics::MacTextWindow *_consoleWindow; #else - Graphics::MacWindow *_consoleWindow; + Graphics::MacWindow *_consoleWindow; #endif private: -#ifdef USE_NEW_TEXT_RENDERER -#ifndef USE_MACTEXTWINDOW - Graphics::MacText *_mactext; -#endif // USE_MACTEXTWINDOW -#endif // USE_NEW_TEXT_RENDERER - Graphics::ManagedSurface _console; Graphics::MacMenu *_menu; bool _sceneDirty; diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp index 3419a86fbd..54d821f17d 100644 --- a/engines/wage/wage.cpp +++ b/engines/wage/wage.cpp @@ -133,6 +133,7 @@ Common::Error WageEngine::run() { _gui->regenCommandsMenu(); _gui->regenWeaponsMenu(); } + Common::String input("look"); processTurn(&input, NULL); _temporarilyHidden = false; @@ -312,6 +313,10 @@ void WageEngine::performInitialSetup() { if (!playerPlaced) { _world->move(_world->_player, _world->getRandomScene()); } + + // Set the console window's dimensions early here because + // flowText() that needs them gets called before they're set + _gui->_consoleWindow->setDimensions(*_world->_player->_currentScene->_textBounds); } void WageEngine::wearObjs(Chr* chr) { |