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 +++++++++++++++++++++++++++++++++++++++++++ engines/wage/gui.cpp | 136 ------------------------------------------- 2 files changed, 136 insertions(+), 136 deletions(-) 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 diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp index afc61c4a27..2809656bec 100644 --- a/engines/wage/gui.cpp +++ b/engines/wage/gui.cpp @@ -230,93 +230,6 @@ static bool consoleWindowCallback(WindowClick click, Common::Event &event, void return gui->processConsoleEvents(click, event); } -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; -} - void Gui::regenCommandsMenu() { _menu->regenCommandsMenu(); } @@ -329,53 +242,4 @@ bool Gui::processEvent(Common::Event &event) { return _wm.processEvent(event); } -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