From b60e2eb89babe3fa5f1bdb757ea6d95b22878e23 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 5 Aug 2017 00:27:12 +0200 Subject: WAGE: Remove all old console code Now we have fully switched to MacTextWindow. Yay! --- engines/wage/gui-console.cpp | 603 ------------------------------------------- engines/wage/gui.cpp | 228 ++++++++-------- engines/wage/gui.h | 49 +--- engines/wage/module.mk | 1 - 4 files changed, 115 insertions(+), 766 deletions(-) delete mode 100644 engines/wage/gui-console.cpp diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp deleted file mode 100644 index c8b5782108..0000000000 --- a/engines/wage/gui-console.cpp +++ /dev/null @@ -1,603 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * MIT License: - * - * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#include "common/events.h" -#include "common/timer.h" -#include "common/unzip.h" -#include "graphics/cursorman.h" -#include "graphics/fonts/bdf.h" -#include "graphics/palette.h" -#include "graphics/macgui/macfontmanager.h" -#include "graphics/macgui/macwindow.h" -#include "graphics/macgui/macmenu.h" - -#include "wage/wage.h" -#include "wage/design.h" -#include "wage/entities.h" -#include "wage/gui.h" -#include "wage/world.h" - -namespace Wage { - -const Graphics::MacFont *Gui::getConsoleMacFont() { - Scene *scene = _engine->_world->_player->_currentScene; - - return scene->getFont(); -} - -const Graphics::Font *Gui::getConsoleFont() { - return _wm._fontMan->getFont(*getConsoleMacFont()); -} - - -void Gui::clearOutput() { - _out.clear(); - _lines.clear(); - _consoleFullRedraw = true; -} - -void Gui::appendText(const char *s) { -#ifdef USE_MACTEXTWINDOW - _consoleWindow->appendText(s, getConsoleMacFont()); -#else - Common::String str(s); - _consoleDirty = true; - - if (!str.contains('\n')) { - _out.push_back(str); - flowText(str); - return; - } - - // 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); - flowText(tmp); - tmp.clear(); - continue; - } - - tmp += str[i]; - } - - // Process last/leftover line - _out.push_back(tmp); - flowText(tmp); -#endif // USE_MACTEXTWINDOW -} - -enum { - kConWOverlap = 20, - kConHOverlap = 20, - kConWPadding = 3, - kConHPadding = 4, - kConOverscan = 3 -}; - -void Gui::flowText(Common::String &str) { - Common::StringArray wrappedLines; - 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 - _lines.push_back(""); - - for (Common::StringArray::const_iterator j = wrappedLines.begin(); j != wrappedLines.end(); ++j) - _lines.push_back(*j); - - uint pos = _scrollPos; - _scrollPos = MAX(0, (_lines.size() - 1 - _consoleNumLines) * _consoleLineHeight); - - _cursorX = kConWPadding; - - if (_scrollPos) - _cursorY = (_consoleNumLines) * _consoleLineHeight + kConHPadding; - else - _cursorY = (_lines.size() - 1) * _consoleLineHeight + kConHPadding; - - if (pos != _scrollPos) - _consoleFullRedraw = true; - - if (!_engine->_temporarilyHidden) - draw(); -} - -void Gui::reflowText() { - _lines.clear(); - - for (uint i = 0; i < _out.size(); i++) - flowText(_out[i]); - -#ifdef USE_MACTEXTWINDOW1 - // 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; - int surfW = r.width() + kConWOverlap * 2; - int surfH = r.height() + kConHOverlap * 2; - - Common::Rect boundsR(kConWOverlap - kConOverscan, kConHOverlap - kConOverscan, - r.width() + kConWOverlap + kConOverscan, r.height() + kConHOverlap + kConOverscan); - - if (_console.w != surfW || _console.h != surfH) { - if (_console.w != surfW) - textReflow = true; - - _console.free(); - - _console.create(surfW, surfH, Graphics::PixelFormat::createFormatCLUT8()); - fullRedraw = true; - } - - if (fullRedraw) { - _console.clear(kColorWhite); - } - const Graphics::Font *font = getConsoleFont(); - - _consoleLineHeight = font->getFontHeight(); - - if (textReflow) - reflowText(); - -#ifndef USE_MACTEXTWINDOW - int textW = r.width() - kConWPadding * 2; - int textH = r.height() - kConHPadding * 2; - - const int firstLine = _scrollPos / _consoleLineHeight; - const int lastLine = MIN((_scrollPos + textH) / _consoleLineHeight + 1, _lines.size()); - const int xOff = kConWOverlap; - const int yOff = kConHOverlap; - int x1 = xOff + kConWPadding; - int y1 = yOff - (_scrollPos % _consoleLineHeight) + kConHPadding; - - if (fullRedraw) - _consoleNumLines = (r.height() - 2 * kConWPadding) / _consoleLineHeight - 2; - - 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; - Common::Rect trect(0, y1, _console.w, y1 + _consoleLineHeight); - - 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; - int midpoint = _selectionStartX; - - if (_selectionStartY > _selectionEndY) - SWAP(color1, color2); - - if (line == _selectionEndY) { - SWAP(color1, color2); - midpoint = _selectionEndX; - } - - Common::String beg(_lines[line].c_str(), &_lines[line].c_str()[midpoint]); - Common::String end(&_lines[line].c_str()[midpoint]); - - int rectW = font->getStringWidth(beg) + kConWPadding + kConWOverlap; - Common::Rect trect(0, y1, _console.w, y1 + _consoleLineHeight); - if (color1 == kColorWhite) - trect.right = rectW; - 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 { // Draw selected text if only 1 line is selected - int startPos = _selectionStartX; - int endPos = _selectionEndX; - - if (startPos > endPos) - SWAP(startPos, endPos); - - Common::String beg(_lines[line].c_str(), &_lines[line].c_str()[startPos]); - Common::String mid(&_lines[line].c_str()[startPos], &_lines[line].c_str()[endPos]); - Common::String end(&_lines[line].c_str()[endPos]); - - int rectW1 = font->getStringWidth(beg) + kConWPadding + kConWOverlap; - 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 { // Neither first nor last line - if (*str) { - font->drawString(&_console, _lines[line], x1, y1, textW, color); - } - } - - y1 += _consoleLineHeight; - } - - // Now we need to clip it to the screen - int xcon = r.left - kConOverscan; - int ycon = r.top - kConOverscan; - if (xcon < 0) { - boundsR.left -= xcon; - xcon = 0; - } - if (ycon < 0) { - boundsR.top -= ycon; - ycon = 0; - } - if (xcon + boundsR.width() >= g->w) - boundsR.right -= xcon + boundsR.width() - g->w; - if (ycon + boundsR.height() >= g->h) - boundsR.bottom -= ycon + boundsR.height() - g->h; - - Common::Rect rr(r); - if (rr.right > _screen.w - 1) - rr.right = _screen.w - 1; - if (rr.bottom > _screen.h - 1) - rr.bottom = _screen.h - 1; - - g->copyRectToSurface(_console, xcon, ycon, boundsR); -#endif -} - -void Gui::drawInput() { -#ifndef USE_MACTEXTWINDOW - - if (!_screen.getPixels()) - return; - _wm.setActive(_consoleWindow->getId()); - - _out.pop_back(); - _lines.pop_back(); - appendText(_engine->_inputText.c_str()); - _inputTextLineNum = _out.size() - 1; - - const Graphics::Font *font = getConsoleFont(); - - if (_engine->_inputText.contains('\n')) { - _consoleDirty = true; - } else { - int x = kConWPadding + _consoleWindow->getInnerDimensions().left; - int y = _cursorY + _consoleWindow->getInnerDimensions().top; - - Common::Rect r(x, y, x + _consoleWindow->getInnerDimensions().width() - kConWPadding, y + font->getFontHeight()); - _screen.fillRect(r, kColorWhite); - - undrawCursor(); - - font->drawString(&_screen, _out[_inputTextLineNum], x, y, _screen.w, kColorBlack); - - int w = _consoleWindow->getInnerDimensions().width(); - int h = font->getFontHeight(); - if (x < 0) { - w += x; - x = 0; - } - if (y < 0) { - h += y; - y = 0; - } - if (x + w > _screen.w) w = _screen.w - x; - if (y + h > _screen.h) h = _screen.h - y; - if (w != 0 && h != 0) - g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, w, h); - } - - _cursorX = font->getStringWidth(_out[_inputTextLineNum]) + kConHPadding; -#else - warning("Gui::drawInput()"); -#endif // USE_MACTEXTWINDOW -} - -void Gui::actionCopy() { - _clipboard = _consoleWindow->getSelection(); - - _menu->enableCommand(kMenuEdit, kMenuActionPaste, true); -} - -void Gui::actionPaste() { - _undobuffer = _engine->_inputText; - - _consoleWindow->appendInput(_clipboard); - - _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); -} - -void Gui::actionUndo() { - _consoleWindow->clearInput(); - _consoleWindow->appendInput(_clipboard); - - _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); -} - -void Gui::actionClear() { - const Graphics::SelectedText *s = _consoleWindow->getSelectedText(); - - if (s->endY == -1) - return; - - int startPos = s->startCol; - int endPos = s->endCol; - - if (startPos > endPos) - SWAP(startPos, endPos); - - Common::String input = _consoleWindow->getInput(); - - Common::String beg(input.c_str(), &input.c_str()[startPos]); - Common::String end(&input.c_str()[endPos]); - - _undobuffer = input; - - _consoleWindow->clearInput(); - _consoleWindow->appendInput(beg + end); - - _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); - - _consoleWindow->clearSelection(); -} - -void Gui::actionCut() { - const Graphics::SelectedText *s = _consoleWindow->getSelectedText(); - - if (s->endY == -1) - return; - - int startPos = s->startCol; - int endPos = s->endCol; - - if (startPos > endPos) - SWAP(startPos, endPos); - - Common::String input = _consoleWindow->getInput(); - - Common::String beg(input.c_str(), &input.c_str()[startPos]); - Common::String mid(&input.c_str()[startPos], &input.c_str()[endPos]); - Common::String end(&input.c_str()[endPos]); - - _undobuffer = input; - - _consoleWindow->clearInput(); - _consoleWindow->appendInput(beg + end); - _clipboard = mid; - - _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); - _menu->enableCommand(kMenuEdit, kMenuActionPaste, true); - - _consoleWindow->clearSelection(); -} - -void Gui::disableUndo() { - _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); -} - -void Gui::disableAllMenus() { - _menu->disableAllMenus(); -} - -void Gui::enableNewGameMenus() { - _menu->enableCommand(kMenuFile, kMenuActionNew, true); - _menu->enableCommand(kMenuFile, kMenuActionOpen, true); - _menu->enableCommand(kMenuFile, kMenuActionQuit, true); -} - -bool Gui::processConsoleEvents(WindowClick click, Common::Event &event) { - if (click == kBorderScrollUp || click == kBorderScrollDown) { - if (event.type == Common::EVENT_LBUTTONDOWN) { - int consoleHeight = _consoleWindow->getInnerDimensions().height(); - int textFullSize = _lines.size() * _consoleLineHeight + consoleHeight; - float scrollPos = (float)_scrollPos / textFullSize; - float scrollSize = (float)consoleHeight / textFullSize; - - _consoleWindow->setScroll(scrollPos, scrollSize); - - return true; - } else if (event.type == Common::EVENT_LBUTTONUP) { - int oldScrollPos = _scrollPos; - - switch (click) { - case kBorderScrollUp: - _scrollPos = MAX(0, _scrollPos - _consoleLineHeight); - undrawCursor(); - _cursorY -= (_scrollPos - oldScrollPos); - _consoleDirty = true; - _consoleFullRedraw = true; - break; - case kBorderScrollDown: - _scrollPos = MIN((_lines.size() - 2) * _consoleLineHeight, _scrollPos + _consoleLineHeight); - undrawCursor(); - _cursorY -= (_scrollPos - oldScrollPos); - _consoleDirty = true; - _consoleFullRedraw = true; - break; - default: - return false; - } - - return true; - } - - return false; - } - - if (click == kBorderResizeButton) { - _consoleDirty = true; - _consoleFullRedraw = true; - - return true; - } - - if (click == kBorderInner) { - if (event.type == Common::EVENT_LBUTTONDOWN) { - startMarking(event.mouse.x, event.mouse.y); - - return true; - } else if (event.type == Common::EVENT_LBUTTONUP) { - if (_inTextSelection) { - _inTextSelection = false; - - if (_selectionEndY == -1 || - (_selectionEndX == _selectionStartX && _selectionEndY == _selectionStartY)) { - _selectionStartY = _selectionEndY = -1; - _consoleFullRedraw = true; - _menu->enableCommand(kMenuEdit, kMenuActionCopy, false); - } else { - _menu->enableCommand(kMenuEdit, kMenuActionCopy, true); - - bool cutAllowed = false; - - if (_selectionStartY == _selectionEndY && _selectionStartY == (int)_lines.size() - 1) - cutAllowed = true; - - _menu->enableCommand(kMenuEdit, kMenuActionCut, cutAllowed); - _menu->enableCommand(kMenuEdit, kMenuActionClear, cutAllowed); - } - } - - return true; - } else if (event.type == Common::EVENT_MOUSEMOVE) { - if (_inTextSelection) { - updateTextSelection(event.mouse.x, event.mouse.y); - return true; - } - } - - return false; - } - - return false; -} - -int Gui::calcTextX(int x, int textLine) { - const Graphics::Font *font = getConsoleFont(); - - if ((uint)textLine >= _lines.size()) - return 0; - - Common::String str = _lines[textLine]; - - x -= _consoleWindow->getInnerDimensions().left; - - for (int i = str.size(); i >= 0; i--) { - if (font->getStringWidth(str) < x) { - return i; - } - - str.deleteLastChar(); - } - - return 0; -} - -int Gui::calcTextY(int y) { - y -= _consoleWindow->getInnerDimensions().top; - - if (y < 0) - y = 0; - - const int firstLine = _scrollPos / _consoleLineHeight; - int textLine = (y - _scrollPos % _consoleLineHeight) / _consoleLineHeight + firstLine; - - return textLine; -} - -void Gui::startMarking(int x, int y) { - _selectionStartY = calcTextY(y); - _selectionStartX = calcTextX(x, _selectionStartY); - - _selectionEndY = -1; - - _inTextSelection = true; -} - -void Gui::updateTextSelection(int x, int y) { - _selectionEndY = calcTextY(y); - _selectionEndX = calcTextX(x, _selectionEndY); - - _consoleFullRedraw = true; -} - -} // End of namespace Wage diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp index f4028dfe17..63db460920 100644 --- a/engines/wage/gui.cpp +++ b/engines/wage/gui.cpp @@ -83,42 +83,7 @@ static const Graphics::MacMenuData menuSubItems[] = { { 0, NULL, 0, 0, false } }; -static void cursorTimerHandler(void *refCon) { - Gui *gui = (Gui *)refCon; - - int x = gui->_cursorX; - int y = gui->_cursorY; - - if (x == 0 && y == 0) - return; - - if (!gui->_screen.getPixels()) - return; - - x += gui->_consoleWindow->getInnerDimensions().left; - y += gui->_consoleWindow->getInnerDimensions().top; - int h = kCursorHeight; - - if (y + h > gui->_consoleWindow->getInnerDimensions().bottom) { - h = gui->_consoleWindow->getInnerDimensions().bottom - y; - } - - if (h > 0) - gui->_screen.vLine(x, y, y + h, gui->_cursorState ? kColorBlack : kColorWhite); - - if (!gui->_cursorOff) - gui->_cursorState = !gui->_cursorState; - - gui->_cursorRect.left = x; - gui->_cursorRect.right = MIN(x + 1, gui->_screen.w); - gui->_cursorRect.top = MIN(y - 1, gui->_consoleWindow->getInnerDimensions().top); - gui->_cursorRect.bottom = MIN(MIN(y + h, gui->_screen.h), gui->_consoleWindow->getInnerDimensions().bottom); - - gui->_cursorDirty = true; -} - static bool sceneWindowCallback(WindowClick click, Common::Event &event, void *gui); -static bool consoleWindowCallback(WindowClick click, Common::Event &event, void *gui); static void menuCommandsCallback(int action, Common::String &text, void *data); @@ -126,32 +91,10 @@ Gui::Gui(WageEngine *engine) { _engine = engine; _scene = NULL; _sceneDirty = true; - _consoleDirty = true; - _cursorDirty = false; - _consoleFullRedraw = true; _screen.create(g_system->getWidth(), g_system->getHeight(), Graphics::PixelFormat::createFormatCLUT8()); _wm.setScreen(&_screen); - _scrollPos = 0; - _consoleLineHeight = 8; // Dummy value which makes sense - _consoleNumLines = 24; // Dummy value - - _cursorX = 0; - _cursorY = 0; - _cursorState = false; - _cursorOff = false; - - _inTextSelection = false; - _selectionStartX = _selectionStartY = -1; - _selectionEndX = _selectionEndY = -1; - - _inputTextLineNum = 0; - -#ifndef USE_MACTEXTWINDOW - g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 200000, this, "wageCursor"); -#endif - _menu = _wm.addMenu(); _menu->setCommandsCallback(menuCommandsCallback, this); @@ -175,7 +118,6 @@ 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) @@ -184,11 +126,6 @@ Gui::Gui(WageEngine *engine) { uint maxWidth = _screen.w; _consoleWindow = _wm.addTextWindow(font, kColorBlack, kColorWhite, maxWidth, Graphics::kTextAlignLeft, _menu); -#else - _consoleWindow = _wm.addWindow(true, true, true); -#endif // USE_MACTEXTWINDOW - - _consoleWindow->setCallback(consoleWindowCallback, this); loadBorders(); } @@ -196,17 +133,6 @@ Gui::Gui(WageEngine *engine) { Gui::~Gui() { _screen.free(); _console.free(); - -#ifndef USE_MACTEXTWINDOW - g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler); -#endif -} - -void Gui::undrawCursor() { - _cursorOff = true; - _cursorState = false; - cursorTimerHandler(this); - _cursorOff = false; } void Gui::draw() { @@ -231,33 +157,10 @@ void Gui::draw() { } drawScene(); -#ifndef USE_MACTEXTWINDOW - drawConsole(); -#endif _wm.draw(); - if (_cursorDirty && _cursorRect.left < _screen.w && _cursorRect.bottom < _screen.h) { - int x = _cursorRect.left, y = _cursorRect.top, w = _cursorRect.width(), h = _cursorRect.height(); - if (x < 0) { - w += x; - x = 0; - } - if (y < 0) { - h += y; - y = 0; - } - if (x + w > _screen.w) w = _screen.w - x; - if (y + h > _screen.h) h = _screen.h - y; - if (w != 0 && h != 0) - g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, w, h); - - _cursorDirty = false; - } - _sceneDirty = false; - _consoleDirty = false; - _consoleFullRedraw = false; } void Gui::drawScene() { @@ -268,9 +171,7 @@ void Gui::drawScene() { _sceneWindow->setDirty(true); _sceneDirty = true; - _consoleDirty = true; _menu->setDirty(true); - _consoleFullRedraw = true; } static bool sceneWindowCallback(WindowClick click, Common::Event &event, void *g) { @@ -293,22 +194,6 @@ bool Gui::processSceneEvents(WindowClick click, Common::Event &event) { return false; } -// Render console -void Gui::drawConsole() { - if (!_consoleDirty && !_consoleFullRedraw && !_sceneDirty) - return; - - renderConsole(_consoleWindow->getSurface(), Common::Rect(kBorderWidth - 2, kBorderWidth - 2, - _consoleWindow->getDimensions().width(), _consoleWindow->getDimensions().height())); - _consoleWindow->setDirty(true); -} - -static bool consoleWindowCallback(WindowClick click, Common::Event &event, void *g) { - Gui *gui = (Gui *)g; - - return gui->processConsoleEvents(click, event); -} - //////////////// // Menu stuff //////////////// @@ -427,4 +312,117 @@ void Gui::loadBorder(Graphics::MacWindow *target, Common::String filename, bool } } +////////////////// +// Console stuff +////////////////// +const Graphics::MacFont *Gui::getConsoleMacFont() { + Scene *scene = _engine->_world->_player->_currentScene; + + return scene->getFont(); +} + +const Graphics::Font *Gui::getConsoleFont() { + return _wm._fontMan->getFont(*getConsoleMacFont()); +} + +void Gui::appendText(const char *s) { + _consoleWindow->appendText(s, getConsoleMacFont()); +} + +void Gui::clearOutput() { + //_consoleWindow->clearAllContent(); +} + +void Gui::actionCopy() { + _clipboard = _consoleWindow->getSelection(); + + _menu->enableCommand(kMenuEdit, kMenuActionPaste, true); +} + +void Gui::actionPaste() { + _undobuffer = _engine->_inputText; + + _consoleWindow->appendInput(_clipboard); + + _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); +} + +void Gui::actionUndo() { + _consoleWindow->clearInput(); + _consoleWindow->appendInput(_clipboard); + + _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); +} + +void Gui::actionClear() { + const Graphics::SelectedText *s = _consoleWindow->getSelectedText(); + + if (s->endY == -1) + return; + + int startPos = s->startCol; + int endPos = s->endCol; + + if (startPos > endPos) + SWAP(startPos, endPos); + + Common::String input = _consoleWindow->getInput(); + + Common::String beg(input.c_str(), &input.c_str()[startPos]); + Common::String end(&input.c_str()[endPos]); + + _undobuffer = input; + + _consoleWindow->clearInput(); + _consoleWindow->appendInput(beg + end); + + _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); + + _consoleWindow->clearSelection(); +} + +void Gui::actionCut() { + const Graphics::SelectedText *s = _consoleWindow->getSelectedText(); + + if (s->endY == -1) + return; + + int startPos = s->startCol; + int endPos = s->endCol; + + if (startPos > endPos) + SWAP(startPos, endPos); + + Common::String input = _consoleWindow->getInput(); + + Common::String beg(input.c_str(), &input.c_str()[startPos]); + Common::String mid(&input.c_str()[startPos], &input.c_str()[endPos]); + Common::String end(&input.c_str()[endPos]); + + _undobuffer = input; + + _consoleWindow->clearInput(); + _consoleWindow->appendInput(beg + end); + _clipboard = mid; + + _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); + _menu->enableCommand(kMenuEdit, kMenuActionPaste, true); + + _consoleWindow->clearSelection(); +} + +void Gui::disableUndo() { + _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); +} + +void Gui::disableAllMenus() { + _menu->disableAllMenus(); +} + +void Gui::enableNewGameMenus() { + _menu->enableCommand(kMenuFile, kMenuActionNew, true); + _menu->enableCommand(kMenuFile, kMenuActionOpen, true); + _menu->enableCommand(kMenuFile, kMenuActionQuit, true); +} + } // End of namespace Wage diff --git a/engines/wage/gui.h b/engines/wage/gui.h index 64d40bd228..446cb9d0a0 100644 --- a/engines/wage/gui.h +++ b/engines/wage/gui.h @@ -48,18 +48,11 @@ #ifndef WAGE_GUI_H #define WAGE_GUI_H -// Whether to use the new MacTextWindow class for rendering the console -#define USE_MACTEXTWINDOW - #include "common/str-array.h" #include "graphics/font.h" #include "graphics/managed_surface.h" #include "graphics/macgui/macwindowmanager.h" -#ifdef USE_MACTEXTWINDOW #include "graphics/macgui/mactextwindow.h" -#else -#include "graphics/macgui/macwindow.h" -#endif #include "graphics/macgui/macwindow.h" #include "graphics/macgui/mactext.h" #include "graphics/macgui/macmenu.h" @@ -130,11 +123,8 @@ public: void draw(); void appendText(const char *str); - void reflowText(); - void clearOutput(); bool processEvent(Common::Event &event); - void drawInput(); void setSceneDirty() { _sceneDirty = true; } void regenCommandsMenu(); void regenWeaponsMenu(); @@ -149,73 +139,38 @@ public: void enableNewGameMenus(); bool processSceneEvents(WindowClick click, Common::Event &event); - bool processConsoleEvents(WindowClick click, Common::Event &event); void executeMenuCommand(int action, Common::String &text); + void clearOutput(); + private: void drawScene(); - void drawConsole(); - 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); - int calcTextX(int x, int textLine); - int calcTextY(int y); - void updateTextSelection(int x, int y); void loadBorders(); void loadBorder(Graphics::MacWindow *target, Common::String filename, bool active); public: Graphics::ManagedSurface _screen; - int _cursorX, _cursorY; - bool _cursorState; WageEngine *_engine; - bool _cursorDirty; - Common::Rect _cursorRect; - bool _cursorOff; - Scene *_scene; Graphics::MacWindowManager _wm; Graphics::MacWindow *_sceneWindow; - -#ifdef USE_MACTEXTWINDOW Graphics::MacTextWindow *_consoleWindow; -#else - Graphics::MacWindow *_consoleWindow; -#endif private: - Graphics::ManagedSurface _console; Graphics::MacMenu *_menu; bool _sceneDirty; - bool _consoleDirty; - - Common::StringArray _out; - Common::StringArray _lines; - uint _scrollPos; - int _consoleLineHeight; - uint _consoleNumLines; - bool _consoleFullRedraw; - - bool _inTextSelection; - int _selectionStartX; - int _selectionStartY; - int _selectionEndX; - int _selectionEndY; Common::String _clipboard; Common::String _undobuffer; - int _inputTextLineNum; - int _commandsMenuId; int _weaponsMenuId; }; diff --git a/engines/wage/module.mk b/engines/wage/module.mk index be148dd439..9f11e16db0 100644 --- a/engines/wage/module.mk +++ b/engines/wage/module.mk @@ -8,7 +8,6 @@ MODULE_OBJS := \ dialog.o \ entities.o \ gui.o \ - gui-console.o \ randomhat.o \ saveload.o \ script.o \ -- cgit v1.2.3