mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-04 17:29:11 +00:00
WAGE: Move rest of console-related functionality to gui-console.cpp
This commit is contained in:
parent
5fb5d7a814
commit
6c610e7a18
@ -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<int>(0, _scrollPos - _consoleLineHeight);
|
||||
undrawCursor();
|
||||
_cursorY -= (_scrollPos - oldScrollPos);
|
||||
_consoleDirty = true;
|
||||
_consoleFullRedraw = true;
|
||||
break;
|
||||
case kBorderScrollDown:
|
||||
_scrollPos = MIN<int>((_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
|
||||
|
@ -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<int>(0, _scrollPos - _consoleLineHeight);
|
||||
undrawCursor();
|
||||
_cursorY -= (_scrollPos - oldScrollPos);
|
||||
_consoleDirty = true;
|
||||
_consoleFullRedraw = true;
|
||||
break;
|
||||
case kBorderScrollDown:
|
||||
_scrollPos = MIN<int>((_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
|
||||
|
Loading…
x
Reference in New Issue
Block a user