From 33ece271fde12033c620660216a678e1c506fd75 Mon Sep 17 00:00:00 2001 From: johndoe123 Date: Fri, 25 May 2018 05:27:57 +1000 Subject: ILLUSIONS: Implement cursor movement via arrow keys (cherry picked from commit 12e33c6) --- engines/illusions/input.cpp | 25 +++++++++++++++++++++++++ engines/illusions/input.h | 3 +++ 2 files changed, 28 insertions(+) (limited to 'engines/illusions') diff --git a/engines/illusions/input.cpp b/engines/illusions/input.cpp index 1374e44ce3..6af6cd5c00 100644 --- a/engines/illusions/input.cpp +++ b/engines/illusions/input.cpp @@ -21,6 +21,7 @@ */ #include "illusions/input.h" +#include "common/system.h" namespace Illusions { @@ -93,6 +94,7 @@ Input::Input() { _cursorPos.y = 0; _prevCursorPos.x = 0; _prevCursorPos.y = 0; + _cursorMovedByKeyboard = false; _cheatCodeIndex = 0; } @@ -105,6 +107,7 @@ void Input::processEvent(Common::Event event) { handleKey(event.kbd.keycode, MOUSE_NONE, false); break; case Common::EVENT_MOUSEMOVE: + _cursorMovedByKeyboard = false; _cursorPos.x = event.mouse.x; _cursorPos.y = event.mouse.y; break; @@ -172,6 +175,22 @@ InputEvent& Input::setInputEvent(uint evt, uint bitMask) { } void Input::handleKey(Common::KeyCode key, int mouseButton, bool down) { + switch (key) { + case Common::KEYCODE_UP: + moveCursorByKeyboard(0, -4); + break; + case Common::KEYCODE_DOWN: + moveCursorByKeyboard(0, 4); + break; + case Common::KEYCODE_RIGHT: + moveCursorByKeyboard(4, 0); + break; + case Common::KEYCODE_LEFT: + moveCursorByKeyboard(-4, 0); + break; + default: + break; + } for (uint i = 0; i < kEventMax; ++i) { _newKeys |= _inputEvents[i].handle(key, mouseButton, down); } @@ -221,6 +240,12 @@ void Input::discardButtons(uint bitMask) { _buttonStates &= ~bitMask; } +void Input::moveCursorByKeyboard(int deltaX, int deltaY) { + _cursorMovedByKeyboard = true; + _cursorPos.x = CLIP(_cursorPos.x + deltaX, 0, g_system->getWidth() - 1); + _cursorPos.y = CLIP(_cursorPos.y + deltaY, 0, g_system->getHeight() - 1); +} + bool Input::isCheatModeActive() { return _cheatCodeIndex == 7; } diff --git a/engines/illusions/input.h b/engines/illusions/input.h index 3b554bd622..b92cd1d2cf 100644 --- a/engines/illusions/input.h +++ b/engines/illusions/input.h @@ -90,6 +90,7 @@ public: void setCursorPosition(Common::Point mousePos); Common::Point getCursorDelta(); InputEvent& setInputEvent(uint evt, uint bitMask); + bool isCursorMovedByKeyboard() const { return _cursorMovedByKeyboard; } bool isCheatModeActive(); protected: uint _cheatCodeIndex; @@ -98,12 +99,14 @@ protected: uint _newKeys; Common::Point _cursorPos, _prevCursorPos; InputEvent _inputEvents[kEventMax]; + bool _cursorMovedByKeyboard; void handleKey(Common::KeyCode key, int mouseButton, bool down); void handleMouseButton(int mouseButton, bool down); void discardButtons(uint bitMask); bool lookButtonStates(uint bitMask); bool lookNewButtons(uint bitMask); void setButtonState(uint bitMask); + void moveCursorByKeyboard(int deltaX, int deltaY); }; } // End of namespace Illusions -- cgit v1.2.3