From c80bc8cbe0b02c8cd4ced475e395aadc5a06158f Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 12 Feb 2016 11:28:42 +0100 Subject: WAGE: Move all console-related stuff to gui-console.cpp --- engines/wage/gui-console.cpp | 350 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 350 insertions(+) create mode 100644 engines/wage/gui-console.cpp (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp new file mode 100644 index 0000000000..0d9fb394c4 --- /dev/null +++ b/engines/wage/gui-console.cpp @@ -0,0 +1,350 @@ +/* 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/timer.h" +#include "common/unzip.h" +#include "graphics/cursorman.h" +#include "graphics/fonts/bdf.h" +#include "graphics/palette.h" + +#include "wage/wage.h" +#include "wage/design.h" +#include "wage/entities.h" +#include "wage/menu.h" +#include "wage/gui.h" +#include "wage/world.h" + +namespace Wage { + +const Graphics::Font *Gui::getConsoleFont() { + char fontName[128]; + Scene *scene = _engine->_world->_player->_currentScene; + + snprintf(fontName, 128, "%s-%d", scene->getFontName(), scene->_fontSize); + + return getFont(fontName, Graphics::FontManager::kConsoleFont); +} + +void Gui::clearOutput() { + _out.clear(); + _lines.clear(); + _consoleFullRedraw = true; +} + +void Gui::appendText(const char *s) { + 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 = ""; + continue; + } + + tmp += str[i]; + } + + _out.push_back(tmp); + flowText(tmp); +} + +enum { + kConWOverlap = 20, + kConHOverlap = 20, + kConWPadding = 3, + kConHPadding = 4, + kConOverscan = 3 +}; + +void Gui::flowText(Common::String &str) { + Common::StringArray wrappedLines; + int textW = _consoleTextArea.width() - kConWPadding * 2; + const Graphics::Font *font = getConsoleFont(); + + font->wordWrapText(str, textW, wrappedLines); + + if (wrappedLines.size() == 0) // 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::renderConsole(Graphics::Surface *g, 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); + Common::Rect fullR(0, 0, surfW, surfH); + + 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.fillRect(fullR, 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]); + } + + 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; + + 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, _patterns, kPatternSolid); + } + + if (line == _selectionStartY || line == _selectionEndY) { + 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; + + Design::drawFilledRect(&_console, trect, kColorBlack, _patterns, kPatternSolid); + + font->drawString(&_console, beg, x1, y1, textW, color1); + font->drawString(&_console, end, x1 + rectW - kConWPadding - kConWOverlap, y1, textW, color2); + } else { + 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); + + Design::drawFilledRect(&_console, trect, kColorBlack, _patterns, kPatternSolid); + + font->drawString(&_console, beg, x1, y1, textW, kColorBlack); + font->drawString(&_console, mid, x1 + rectW1 - kConWPadding - kConWOverlap, y1, textW, kColorWhite); + font->drawString(&_console, end, x1 + rectW2 - kConWPadding - kConWOverlap, y1, textW, kColorBlack); + } + } else { + if (*str) + font->drawString(&_console, _lines[line], x1, y1, textW, color); + } + + y1 += _consoleLineHeight; + } + + g->copyRectToSurface(_console, r.left - kConOverscan, r.top - kConOverscan, boundsR); + g_system->copyRectToScreen(g->getBasePtr(r.left, r.top), g->pitch, r.left, r.top, r.width(), r.height()); +} + +void Gui::drawInput() { + if (!_screen.getPixels()) + return; + + if (_sceneIsActive) { + _sceneIsActive = false; + _bordersDirty = true; + } + + _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 + _consoleTextArea.left; + int y = _cursorY + _consoleTextArea.top; + + Common::Rect r(x, y, x + _consoleTextArea.width() - kConWPadding, y + font->getFontHeight()); + _screen.fillRect(r, kColorWhite); + + undrawCursor(); + + font->drawString(&_screen, _out[_inputTextLineNum], x, y, _screen.w, kColorBlack); + + g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, _consoleTextArea.width(), font->getFontHeight()); + } + + _cursorX = font->getStringWidth(_out[_inputTextLineNum]) + kConHPadding; +} + +void Gui::actionCopy() { + if (_selectionStartX == -1) + return; + + int startX = _selectionStartX; + int startY = _selectionStartY; + int endX = _selectionEndX; + int endY = _selectionEndY; + + if (startY > endY) { + SWAP(startX, endX); + SWAP(endX, endY); + } + + _clipboard.clear(); + + for (int i = startY; i <= endY; i++) { + if (startY == endY) { + _clipboard = Common::String(&_lines[i].c_str()[startX], &_lines[i].c_str()[endX]); + break; + } + + if (i == startY) { + _clipboard += &_lines[i].c_str()[startX]; + _clipboard += '\n'; + } else if (i == endY) { + _clipboard += Common::String(_lines[i].c_str(), &_lines[i].c_str()[endX]); + } else { + _clipboard += _lines[i]; + _clipboard += '\n'; + } + } + + _menu->enableCommand(kMenuEdit, kMenuActionPaste, true); +} + +void Gui::actionPaste() { + _undobuffer = _engine->_inputText; + _engine->_inputText += _clipboard; + drawInput(); + + _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); +} + +void Gui::actionUndo() { + _engine->_inputText = _undobuffer; + drawInput(); + + _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); +} + +} // End of namespace Wage -- cgit v1.2.3 From fcebf28fd2501e8cd835fc57588ae3e51b2cb5ca Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 12 Feb 2016 19:12:37 +0100 Subject: WAGE: Fix behavior of the multiline paste --- engines/wage/gui-console.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 0d9fb394c4..414d13f27d 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -336,6 +336,7 @@ void Gui::actionPaste() { _undobuffer = _engine->_inputText; _engine->_inputText += _clipboard; drawInput(); + _engine->_inputText = _out.back(); // Set last part of the multiline text _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); } -- cgit v1.2.3 From 1158987a1e4f078ed1ae699409fd26558486722e Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 12 Feb 2016 19:16:55 +0100 Subject: WAGE: Disable Undo action after command exectution --- engines/wage/gui-console.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 414d13f27d..9b02608989 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -348,4 +348,8 @@ void Gui::actionUndo() { _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); } +void Gui::disableUndo() { + _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); +} + } // End of namespace Wage -- cgit v1.2.3 From 5cea5a4d3aa712c21fbdfd9283c8ce9981086a67 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 12 Feb 2016 19:36:08 +0100 Subject: WAGE: Implement Cut and Clear actions --- engines/wage/gui-console.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 9b02608989..92e61f9617 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -348,6 +348,49 @@ void Gui::actionUndo() { _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); } +void Gui::actionClear() { + int startPos = _selectionStartX; + int endPos = _selectionEndX; + + if (startPos > endPos) + SWAP(startPos, endPos); + + Common::String beg(_lines[_selectionStartY].c_str(), &_lines[_selectionStartY].c_str()[startPos]); + Common::String end(&_lines[_selectionStartY].c_str()[endPos]); + + _undobuffer = _engine->_inputText; + _engine->_inputText = beg + end; + drawInput(); + + _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); + + _selectionStartY = -1; + _selectionEndY = -1; +} + +void Gui::actionCut() { + int startPos = _selectionStartX; + int endPos = _selectionEndX; + + if (startPos > endPos) + SWAP(startPos, endPos); + + Common::String beg(_lines[_selectionStartY].c_str(), &_lines[_selectionStartY].c_str()[startPos]); + Common::String mid(&_lines[_selectionStartY].c_str()[startPos], &_lines[_selectionStartY].c_str()[endPos]); + Common::String end(&_lines[_selectionStartY].c_str()[endPos]); + + _undobuffer = _engine->_inputText; + _engine->_inputText = beg + end; + _clipboard = mid; + drawInput(); + + _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); + _menu->enableCommand(kMenuEdit, kMenuActionPaste, true); + + _selectionStartY = -1; + _selectionEndY = -1; +} + void Gui::disableUndo() { _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); } -- cgit v1.2.3 From 362557935b0dd6b7941ae667cefae79481218e07 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 14 Feb 2016 14:04:36 +0100 Subject: WAGE: Use String::clear() for emptying stings --- engines/wage/gui-console.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 92e61f9617..2f4bac2937 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -87,13 +87,13 @@ void Gui::appendText(const char *s) { // Okay, we got new lines, need to split it // and push substrings individually - Common::String tmp = ""; + Common::String tmp; for (uint i = 0; i < str.size(); i++) { if (str[i] == '\n') { _out.push_back(tmp); flowText(tmp); - tmp = ""; + tmp.clear(); continue; } -- cgit v1.2.3 From b09e70d1ca528f8eecf31ed1957866d888ede190 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 14 Feb 2016 14:31:57 +0100 Subject: WAGE: Consistently use .empty() instead of .size() == 0 --- engines/wage/gui-console.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 2f4bac2937..f1095de3ca 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -119,7 +119,7 @@ void Gui::flowText(Common::String &str) { font->wordWrapText(str, textW, wrappedLines); - if (wrappedLines.size() == 0) // Sometimes we have empty lines + if (wrappedLines.empty()) // Sometimes we have empty lines _lines.push_back(""); for (Common::StringArray::const_iterator j = wrappedLines.begin(); j != wrappedLines.end(); ++j) -- cgit v1.2.3 From a6120d8b27b67c86faab724f501327368a8d19f8 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 16 Feb 2016 11:13:08 +0100 Subject: WAGE: Started post-gameover code implementation --- engines/wage/gui-console.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index f1095de3ca..18f6b25291 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -395,4 +395,8 @@ void Gui::disableUndo() { _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); } +void Gui::disableAllMenus() { + _menu->disableAllMenus(); +} + } // End of namespace Wage -- cgit v1.2.3 From bd7ef4143df7fb85b70ee98b4dc338618d1602a4 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 16 Feb 2016 11:17:00 +0100 Subject: WAGE: Enable required menu items to allow game restart --- engines/wage/gui-console.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 18f6b25291..ad1bf5839b 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -399,4 +399,10 @@ 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 -- cgit v1.2.3 From 1415e620e49ce5585c6e9d277c859e31a539a2a6 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 25 Feb 2016 11:29:06 +0100 Subject: WAGE: Implemented cropping in cosole. That fixes crashes in Bug Hunt --- engines/wage/gui-console.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index ad1bf5839b..ab5df637ec 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -257,8 +257,30 @@ void Gui::renderConsole(Graphics::Surface *g, Common::Rect &r) { y1 += _consoleLineHeight; } - g->copyRectToSurface(_console, r.left - kConOverscan, r.top - kConOverscan, boundsR); - g_system->copyRectToScreen(g->getBasePtr(r.left, r.top), g->pitch, r.left, r.top, r.width(), r.height()); + // 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); + g_system->copyRectToScreen(g->getBasePtr(rr.left, rr.top), g->pitch, rr.left, rr.top, rr.width(), rr.height()); } void Gui::drawInput() { -- cgit v1.2.3 From 00399d27dbe3466b4734345bfb4879c056465f80 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 15 Apr 2016 08:29:10 +0200 Subject: WAGE: Switch to ManagedSurface --- engines/wage/gui-console.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index ab5df637ec..3a3f189dce 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -142,7 +142,7 @@ void Gui::flowText(Common::String &str) { draw(); } -void Gui::renderConsole(Graphics::Surface *g, Common::Rect &r) { +void Gui::renderConsole(Graphics::ManagedSurface *g, Common::Rect &r) { bool fullRedraw = _consoleFullRedraw; bool textReflow = false; int surfW = r.width() + kConWOverlap * 2; -- cgit v1.2.3 From 0e4c846a39cdf5c8370106ba87b24ac7936818fd Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 15 Apr 2016 08:55:14 +0200 Subject: WAGE: Benefit from ManagedSurface methods --- engines/wage/gui-console.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 3a3f189dce..5f9cfe5519 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -150,7 +150,6 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, Common::Rect &r) { Common::Rect boundsR(kConWOverlap - kConOverscan, kConHOverlap - kConOverscan, r.width() + kConWOverlap + kConOverscan, r.height() + kConHOverlap + kConOverscan); - Common::Rect fullR(0, 0, surfW, surfH); if (_console.w != surfW || _console.h != surfH) { if (_console.w != surfW) @@ -163,7 +162,7 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, Common::Rect &r) { } if (fullRedraw) - _console.fillRect(fullR, kColorWhite); + _console.clear(kColorWhite); const Graphics::Font *font = getConsoleFont(); -- cgit v1.2.3 From 43d49e68b2bdf9e45fdf7542272c013ee2e3fde7 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 15 Apr 2016 14:20:22 +0200 Subject: WAGE: Draw console via MacWindow --- engines/wage/gui-console.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 5f9cfe5519..840b8e3ced 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -142,7 +142,7 @@ void Gui::flowText(Common::String &str) { draw(); } -void Gui::renderConsole(Graphics::ManagedSurface *g, Common::Rect &r) { +void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) { bool fullRedraw = _consoleFullRedraw; bool textReflow = false; int surfW = r.width() + kConWOverlap * 2; @@ -279,7 +279,6 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, Common::Rect &r) { rr.bottom = _screen.h - 1; g->copyRectToSurface(_console, xcon, ycon, boundsR); - g_system->copyRectToScreen(g->getBasePtr(rr.left, rr.top), g->pitch, rr.left, rr.top, rr.width(), rr.height()); } void Gui::drawInput() { -- cgit v1.2.3 From c1bf8f9e559f939136588f4ce472565ff456ecaf Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 21 Apr 2016 21:37:31 +0200 Subject: WAGE: Cleanup --- engines/wage/gui-console.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 840b8e3ced..ea66826c3b 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -285,10 +285,7 @@ void Gui::drawInput() { if (!_screen.getPixels()) return; - if (_sceneIsActive) { - _sceneIsActive = false; - _bordersDirty = true; - } + _wm.setActive(_consoleWindow->getId()); _out.pop_back(); _lines.pop_back(); -- cgit v1.2.3 From 9877abe93697c016d18f7fee1c252577e6fd47df Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 24 Apr 2016 10:47:09 +0200 Subject: WAGE: Implemented window resizing --- engines/wage/gui-console.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index ea66826c3b..ca1917b96d 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -114,7 +114,7 @@ enum { void Gui::flowText(Common::String &str) { Common::StringArray wrappedLines; - int textW = _consoleTextArea.width() - kConWPadding * 2; + int textW = _consoleWindow->getInnerDimensions().width() - kConWPadding * 2; const Graphics::Font *font = getConsoleFont(); font->wordWrapText(str, textW, wrappedLines); @@ -297,17 +297,17 @@ void Gui::drawInput() { if (_engine->_inputText.contains('\n')) { _consoleDirty = true; } else { - int x = kConWPadding + _consoleTextArea.left; - int y = _cursorY + _consoleTextArea.top; + int x = kConWPadding + _consoleWindow->getInnerDimensions().left; + int y = _cursorY + _consoleWindow->getInnerDimensions().top; - Common::Rect r(x, y, x + _consoleTextArea.width() - kConWPadding, y + font->getFontHeight()); + 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); - g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, _consoleTextArea.width(), font->getFontHeight()); + g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, _consoleWindow->getInnerDimensions().width(), font->getFontHeight()); } _cursorX = font->getStringWidth(_out[_inputTextLineNum]) + kConHPadding; -- cgit v1.2.3 From 3a9159c5a34c891b10ff6b44d6982eda717e48f7 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Mon, 25 Apr 2016 19:02:25 +0200 Subject: WAGE: Made Menu subclass of BaseMacWindow --- engines/wage/gui-console.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index ca1917b96d..e0373687bf 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -45,6 +45,7 @@ * */ +#include "common/events.h" #include "common/timer.h" #include "common/unzip.h" #include "graphics/cursorman.h" @@ -54,6 +55,7 @@ #include "wage/wage.h" #include "wage/design.h" #include "wage/entities.h" +#include "wage/macwindow.h" #include "wage/menu.h" #include "wage/gui.h" #include "wage/world.h" -- cgit v1.2.3 From c31e59b10cf51bc06ab8c2a75d4f084a4e671fc2 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 28 Apr 2016 11:14:13 +0200 Subject: WAGE: Moved font loading to WM. wage.dat is now classicmacfonts.dat --- engines/wage/gui-console.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index e0373687bf..0609b4f35c 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -68,7 +68,7 @@ const Graphics::Font *Gui::getConsoleFont() { snprintf(fontName, 128, "%s-%d", scene->getFontName(), scene->_fontSize); - return getFont(fontName, Graphics::FontManager::kConsoleFont); + return _wm.getFont(fontName, Graphics::FontManager::kConsoleFont); } void Gui::clearOutput() { -- cgit v1.2.3 From 367946f83b5688490bb40c54bb884df4dac3c11e Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 28 Apr 2016 11:17:27 +0200 Subject: WAGE: Renamed menu.* to macmenu.* --- engines/wage/gui-console.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 0609b4f35c..9c89c2721f 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -56,7 +56,7 @@ #include "wage/design.h" #include "wage/entities.h" #include "wage/macwindow.h" -#include "wage/menu.h" +#include "wage/macmenu.h" #include "wage/gui.h" #include "wage/world.h" -- cgit v1.2.3 From 6998182b1fef719499ab8b19d415d1a24dd7d908 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 28 Apr 2016 11:28:55 +0200 Subject: WAGE: Moved pattern and palette to WM --- engines/wage/gui-console.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 9c89c2721f..ef494bf25d 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -198,7 +198,7 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) { color = kColorWhite; Common::Rect trect(0, y1, _console.w, y1 + _consoleLineHeight); - Design::drawFilledRect(&_console, trect, kColorBlack, _patterns, kPatternSolid); + Design::drawFilledRect(&_console, trect, kColorBlack, _wm.getPatterns(), kPatternSolid); } if (line == _selectionStartY || line == _selectionEndY) { @@ -225,7 +225,7 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) { else trect.left = rectW; - Design::drawFilledRect(&_console, trect, kColorBlack, _patterns, kPatternSolid); + Design::drawFilledRect(&_console, trect, kColorBlack, _wm.getPatterns(), kPatternSolid); font->drawString(&_console, beg, x1, y1, textW, color1); font->drawString(&_console, end, x1 + rectW - kConWPadding - kConWOverlap, y1, textW, color2); @@ -244,7 +244,7 @@ void Gui::renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r) { int rectW2 = rectW1 + font->getStringWidth(mid); Common::Rect trect(rectW1, y1, rectW2, y1 + _consoleLineHeight); - Design::drawFilledRect(&_console, trect, kColorBlack, _patterns, kPatternSolid); + Design::drawFilledRect(&_console, trect, kColorBlack, _wm.getPatterns(), kPatternSolid); font->drawString(&_console, beg, x1, y1, textW, kColorBlack); font->drawString(&_console, mid, x1 + rectW1 - kConWPadding - kConWOverlap, y1, textW, kColorWhite); -- cgit v1.2.3 From 6c610e7a1882144283b1de0347ea91f4bb4f41ea Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 28 Apr 2016 12:51:30 +0200 Subject: WAGE: Move rest of console-related functionality to gui-console.cpp --- engines/wage/gui-console.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) (limited to 'engines/wage/gui-console.cpp') diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index ef494bf25d..8b6fe43a17 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -424,4 +424,140 @@ void Gui::enableNewGameMenus() { _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 -- cgit v1.2.3