diff options
-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 | ||||
-rw-r--r-- | graphics/macgui/macfontmanager.h | 6 | ||||
-rw-r--r-- | graphics/macgui/mactext.cpp | 11 | ||||
-rw-r--r-- | graphics/macgui/mactext.h | 4 | ||||
-rw-r--r-- | graphics/macgui/mactextwindow.cpp | 19 | ||||
-rw-r--r-- | graphics/macgui/mactextwindow.h | 21 |
9 files changed, 138 insertions, 81 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) { diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h index c154b8ba66..20c645a7bd 100644 --- a/graphics/macgui/macfontmanager.h +++ b/graphics/macgui/macfontmanager.h @@ -77,9 +77,9 @@ public: _font = NULL; } - int getId() { return _id; }; - int getSize() { return _size; } - int getSlant() { return _slant; } + const int getId() const { return _id; }; + const int getSize() const { return _size; } + const int getSlant() const { return _slant; } Common::String getName() { return _name; } void setName(Common::String &name) { _name = name; } void setName(const char *name) { _name = name; } diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp index 44dddad3ba..fa0510b544 100644 --- a/graphics/macgui/mactext.cpp +++ b/graphics/macgui/mactext.cpp @@ -327,6 +327,8 @@ void MacText::recalcDims() { } void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff) { + if (_textLines.empty()) return; + render(); if (x + w < _surface->w || y + h < _surface->h) { @@ -361,7 +363,7 @@ void MacText::resizeAndFormatLines(uint numNewLines, MacFontRun *fontRun) { } } -void MacText::appendText(Common::String str, int fontId, int fontSize, int fontSlant) { +void MacText::appendText(Common::String str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular) { uint oldLen = _textLines.size(); uint newLines = 1 + getNewlinesInString(str); @@ -387,6 +389,13 @@ void MacText::appendTextDefault(Common::String str) { render(oldLen, _textLines.size()); } +void MacText::clearText() { + _textLines.clear(); + _str.clear(); + + recalcDims(); +} + void MacText::replaceLastLine(Common::String str) { int oldLen = MAX<int>(0, _textLines.size() - 1); diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h index cd2adb3f0e..3870451014 100644 --- a/graphics/macgui/mactext.h +++ b/graphics/macgui/mactext.h @@ -92,12 +92,14 @@ public: int maxWidth = -1, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0); // 0 pixels between the lines by default ~MacText(); + void setInterLinear(int interLinear); void draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff); void resizeAndFormatLines(uint numNewLines, MacFontRun * fontRun); - void appendText(Common::String str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular); + void appendText(Common::String str, int fontId, int fontSize, int fontSlant); void appendTextDefault(Common::String str); + void clearText(); void replaceLastLine(Common::String str); int getLineCount() { return _textLines.size(); } diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp index 22bd2407de..19ed9a8398 100644 --- a/graphics/macgui/mactextwindow.cpp +++ b/graphics/macgui/mactextwindow.cpp @@ -27,7 +27,7 @@ namespace Graphics { -MacTextWindow::MacTextWindow(MacWindowManager *wm, const Font *font, int fgcolor, +MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment) : MacWindow(wm->getNextId(), true, true, true, wm) { @@ -45,10 +45,25 @@ void MacTextWindow::appendText(Common::String str, int id, int size, int slant) _mactext->appendText(str, id, size, slant); } +void MacTextWindow::appendText(Common::String str, const MacFont *macFont) { + _mactext->appendText(str, macFont->getId(), macFont->getSize(), macFont->getSlant()); +} + +void MacTextWindow::clearText() { + _mactext->clearText(); +} + +void MacTextWindow::setSelection(int selStartX, int selStartY, int selEndX, int selEndY) { + _selectedText.startX = selStartX; + _selectedText.startY = selStartY; + _selectedText.endX = selEndX; + _selectedText.endY = selEndY; +} + MacTextWindow::~MacTextWindow() { } -const Font *MacTextWindow::getTextWindowFont() { +const MacFont *MacTextWindow::getTextWindowFont() { return _font; } diff --git a/graphics/macgui/mactextwindow.h b/graphics/macgui/mactextwindow.h index 3ef928eab9..f302f3724d 100644 --- a/graphics/macgui/mactextwindow.h +++ b/graphics/macgui/mactextwindow.h @@ -28,20 +28,35 @@ namespace Graphics { +struct SelectedText { + int startX = 0, startY = 0; + int endX = 0, endY = 0; + + bool needsRender() { + return startX != endX || startY != endY; + } +}; + class MacTextWindow : public MacWindow { public: - MacTextWindow(MacWindowManager *wm, const Font *font, int fgcolor, + MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment); ~MacTextWindow(); - const Font *getTextWindowFont(); + const MacFont *getTextWindowFont(); void drawText(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff); void appendText(Common::String str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular); + void appendText(Common::String str, const MacFont *macFont); + void clearText(); + + void setSelection(int selStartX, int selStartY, int selEndX, int selEndY); private: MacText *_mactext; - const Font *_font; + const MacFont *_font; + + SelectedText _selectedText; }; } // End of namespace Graphics |