diff options
author | Paul Gilbert | 2016-11-08 20:11:11 -0500 |
---|---|---|
committer | Paul Gilbert | 2016-11-08 20:11:11 -0500 |
commit | 806e5827f1599d650836546b7abadc7d61d0bc28 (patch) | |
tree | b2b59fe8059d96a691bd7b8dc24b893c6e27e88f | |
parent | 3291a9761cf43e67fe0d085ac63fd89b46367765 (diff) | |
download | scummvm-rg350-806e5827f1599d650836546b7abadc7d61d0bc28.tar.gz scummvm-rg350-806e5827f1599d650836546b7abadc7d61d0bc28.tar.bz2 scummvm-rg350-806e5827f1599d650836546b7abadc7d61d0bc28.zip |
TITANIC: Fix spurious drag starts happening after view changes
-rw-r--r-- | engines/titanic/events.cpp | 48 | ||||
-rw-r--r-- | engines/titanic/events.h | 33 | ||||
-rw-r--r-- | engines/titanic/game_state.cpp | 2 | ||||
-rw-r--r-- | engines/titanic/input_translator.cpp | 2 | ||||
-rw-r--r-- | engines/titanic/main_game_window.cpp | 32 | ||||
-rw-r--r-- | engines/titanic/main_game_window.h | 15 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_rooms_glyphs.cpp | 4 |
7 files changed, 66 insertions, 70 deletions
diff --git a/engines/titanic/events.cpp b/engines/titanic/events.cpp index 6ca1b61ec0..89ad33881e 100644 --- a/engines/titanic/events.cpp +++ b/engines/titanic/events.cpp @@ -31,7 +31,7 @@ namespace Titanic { Events::Events(TitanicEngine *vm): _vm(vm), _frameCounter(1), - _priorFrameTime(0) { + _priorFrameTime(0), _specialButtons(0) { } void Events::pollEvents() { @@ -47,26 +47,32 @@ void Events::pollEvents() { eventTarget()->mouseMove(_mousePos); break; case Common::EVENT_LBUTTONDOWN: + _specialButtons |= MK_LBUTTON; _mousePos = event.mouse; eventTarget()->leftButtonDown(_mousePos); break; case Common::EVENT_LBUTTONUP: + _specialButtons &= ~MK_LBUTTON; _mousePos = event.mouse; eventTarget()->leftButtonUp(_mousePos); break; case Common::EVENT_MBUTTONDOWN: + _specialButtons |= MK_MBUTTON; _mousePos = event.mouse; eventTarget()->middleButtonDown(_mousePos); break; case Common::EVENT_MBUTTONUP: + _specialButtons &= ~MK_MBUTTON; _mousePos = event.mouse; eventTarget()->middleButtonUp(_mousePos); break; case Common::EVENT_RBUTTONDOWN: + _specialButtons |= MK_RBUTTON; _mousePos = event.mouse; eventTarget()->rightButtonDown(_mousePos); break; case Common::EVENT_RBUTTONUP: + _specialButtons &= ~MK_RBUTTON; _mousePos = event.mouse; eventTarget()->rightButtonUp(_mousePos); break; @@ -76,9 +82,11 @@ void Events::pollEvents() { eventTarget()->mouseWheel(_mousePos, event.type == Common::EVENT_WHEELUP); break; case Common::EVENT_KEYDOWN: + handleKbdSpecial(event.kbd); eventTarget()->keyDown(event.kbd); break; case Common::EVENT_KEYUP: + handleKbdSpecial(event.kbd); eventTarget()->keyUp(event.kbd); break; default: @@ -132,29 +140,15 @@ void Events::sleep(uint time) { bool Events::waitForPress(uint expiry) { CGameManager *gameManager = g_vm->_window->_gameManager; uint32 delayEnd = g_system->getMillis() + expiry; + CPressTarget pressTarget; + addTarget(&pressTarget); - while (!_vm->shouldQuit() && g_system->getMillis() < delayEnd) { - g_system->delayMillis(10); - checkForNextFrameCounter(); - - // Regularly update the sound mixer - if (gameManager) - gameManager->_sound.updateMixer(); - - Common::Event event; - if (g_system->getEventManager()->pollEvent(event)) { - switch (event.type) { - case Common::EVENT_LBUTTONDOWN: - case Common::EVENT_MBUTTONDOWN: - case Common::EVENT_KEYDOWN: - return true; - default: - break; - } - } + while (!_vm->shouldQuit() && g_system->getMillis() < delayEnd && !pressTarget._pressed) { + pollEventsAndWait(); } - return false; + removeTarget(); + return pressTarget._pressed; } void Events::setMousePos(const Common::Point &pt) { @@ -163,4 +157,16 @@ void Events::setMousePos(const Common::Point &pt) { eventTarget()->mouseMove(_mousePos); } +void Events::handleKbdSpecial(Common::KeyState keyState) { + if (keyState.flags & Common::KBD_CTRL) + _specialButtons |= MK_CONTROL; + else + _specialButtons &= ~MK_CONTROL; + + if (keyState.flags & Common::KBD_SHIFT) + _specialButtons |= MK_SHIFT; + else + _specialButtons &= ~MK_SHIFT; +} + } // End of namespace Titanic diff --git a/engines/titanic/events.h b/engines/titanic/events.h index 03b271544a..52e900c2ef 100644 --- a/engines/titanic/events.h +++ b/engines/titanic/events.h @@ -70,6 +70,21 @@ public: virtual void keyUp(Common::KeyState keyState) {} }; +/** + * An eent target used for waiting for a mouse or keypress + */ +class CPressTarget : public CEventTarget { +public: + bool _pressed; +public: + CPressTarget() : _pressed(false) {} + virtual ~CPressTarget() {} + virtual void leftButtonDown(const Point &mousePos) { _pressed = true; } + virtual void middleButtonDown(const Point &mousePos) { _pressed = true; } + virtual void rightButtonDown(const Point &mousePos) { _pressed = true; } + virtual void keyDown(Common::KeyState keyState) { _pressed = true; } +}; + class Events { private: TitanicEngine *_vm; @@ -77,6 +92,7 @@ private: uint32 _frameCounter; uint32 _priorFrameTime; Common::Point _mousePos; + uint _specialButtons; /** * Check whether it's time to display the next screen frame @@ -89,6 +105,11 @@ private: CEventTarget *eventTarget() const { return _eventTargets.top(); } + + /** + * Handles setting/resettings special buttons on key up/down + */ + void handleKbdSpecial(Common::KeyState keyState); public: Events(TitanicEngine *vm); ~Events() {} @@ -149,6 +170,18 @@ public: * Sets the mouse position */ void setMousePos(const Common::Point &pt); + + /* + * Return whether a given special key is currently pressed + */ + bool isSpecialPressed(SpecialButtons btn) const { + return (_specialButtons & btn) != 0; + } + + /** + * Returns the bitset of the currently pressed special buttons + */ + uint getSpecialButtons() const { return _specialButtons; } }; } // End of namespace Titanic diff --git a/engines/titanic/game_state.cpp b/engines/titanic/game_state.cpp index ecff021266..5b6d34ad76 100644 --- a/engines/titanic/game_state.cpp +++ b/engines/titanic/game_state.cpp @@ -129,7 +129,7 @@ void CGameState::changeView(CViewItem *newView, CMovieClip *clip) { oldView->leaveView(newView); // If Shift key is pressed, skip showing the transition clip - if (g_vm->_window->isSpecialPressed(MK_SHIFT)) + if (g_vm->_events->isSpecialPressed(MK_SHIFT)) clip = nullptr; if (_mode == GSMODE_CUTSCENE) { diff --git a/engines/titanic/input_translator.cpp b/engines/titanic/input_translator.cpp index a909b8070e..0f717de37f 100644 --- a/engines/titanic/input_translator.cpp +++ b/engines/titanic/input_translator.cpp @@ -113,7 +113,7 @@ void CInputTranslator::keyDown(const Common::KeyState &keyState) { } bool CInputTranslator::isMousePressed() const { - return g_vm->_window->getSpecialButtons() & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON); + return g_vm->_events->getSpecialButtons() & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON); } } // End of namespace Titanic diff --git a/engines/titanic/main_game_window.cpp b/engines/titanic/main_game_window.cpp index 6438929ae5..de0ac715ba 100644 --- a/engines/titanic/main_game_window.cpp +++ b/engines/titanic/main_game_window.cpp @@ -32,8 +32,7 @@ namespace Titanic { CMainGameWindow::CMainGameWindow(TitanicEngine *vm): _vm(vm), - _specialButtons(0), _priorLeftDownTime(0), - _priorMiddleDownTime(0), _priorRightDownTime(0) { + _priorLeftDownTime(0), _priorMiddleDownTime(0), _priorRightDownTime(0) { _gameView = nullptr; _gameManager = nullptr; _project = nullptr; @@ -248,7 +247,7 @@ void CMainGameWindow::onIdle() { } #define HANDLE_MESSAGE(METHOD) if (_inputAllowed) { \ - _gameManager->_inputTranslator.METHOD(_specialButtons, mousePos); \ + _gameManager->_inputTranslator.METHOD(g_vm->_events->getSpecialButtons(), mousePos); \ mouseChanged(); \ } @@ -264,8 +263,6 @@ void CMainGameWindow::leftButtonDown(const Point &mousePos) { if (!isMouseControlEnabled()) return; - _specialButtons |= MK_LBUTTON; - if ((_vm->_events->getTicksCount() - _priorLeftDownTime) < DOUBLE_CLICK_TIME) { _priorLeftDownTime = 0; leftButtonDoubleClick(mousePos); @@ -279,7 +276,6 @@ void CMainGameWindow::leftButtonUp(const Point &mousePos) { if (!isMouseControlEnabled()) return; - _specialButtons &= ~MK_LBUTTON; HANDLE_MESSAGE(leftButtonUp) } @@ -294,8 +290,6 @@ void CMainGameWindow::middleButtonDown(const Point &mousePos) { if (!isMouseControlEnabled()) return; - _specialButtons |= MK_MBUTTON; - if ((_vm->_events->getTicksCount() - _priorMiddleDownTime) < DOUBLE_CLICK_TIME) { _priorMiddleDownTime = 0; middleButtonDoubleClick(mousePos); @@ -309,7 +303,6 @@ void CMainGameWindow::middleButtonUp(const Point &mousePos) { if (!isMouseControlEnabled()) return; - _specialButtons &= ~MK_MBUTTON; HANDLE_MESSAGE(middleButtonUp) } @@ -324,8 +317,6 @@ void CMainGameWindow::rightButtonDown(const Point &mousePos) { if (!isMouseControlEnabled()) return; - _specialButtons |= MK_RBUTTON; - if ((_vm->_events->getTicksCount() - _priorRightDownTime) < DOUBLE_CLICK_TIME) { _priorRightDownTime = 0; rightButtonDoubleClick(mousePos); @@ -339,7 +330,6 @@ void CMainGameWindow::rightButtonUp(const Point &mousePos) { if (!isMouseControlEnabled()) return; - _specialButtons &= ~MK_RBUTTON; HANDLE_MESSAGE(rightButtonUp) } @@ -359,8 +349,6 @@ void CMainGameWindow::rightButtonDoubleClick(const Point &mousePos) { } void CMainGameWindow::keyDown(Common::KeyState keyState) { - handleKbdSpecial(keyState); - if (keyState.keycode == Common::KEYCODE_d && (keyState.flags & Common::KBD_CTRL)) { // Attach to the debugger _vm->_debugger->attach(); @@ -371,22 +359,6 @@ void CMainGameWindow::keyDown(Common::KeyState keyState) { _gameManager->_inputTranslator.keyDown(keyState); } -void CMainGameWindow::keyUp(Common::KeyState keyState) { - handleKbdSpecial(keyState); -} - -void CMainGameWindow::handleKbdSpecial(Common::KeyState keyState) { - if (keyState.flags & Common::KBD_CTRL) - _specialButtons |= MK_CONTROL; - else - _specialButtons &= ~MK_CONTROL; - - if (keyState.flags & Common::KBD_SHIFT) - _specialButtons |= MK_SHIFT; - else - _specialButtons &= ~MK_SHIFT; -} - bool CMainGameWindow::isMouseControlEnabled() const { CScreenManager *screenMan = CScreenManager::_screenManagerPtr; if (!screenMan || !screenMan->_mouseCursor) diff --git a/engines/titanic/main_game_window.h b/engines/titanic/main_game_window.h index c70aa478b5..52d4267c83 100644 --- a/engines/titanic/main_game_window.h +++ b/engines/titanic/main_game_window.h @@ -39,7 +39,6 @@ class CMainGameWindow : public CEventTarget { private: TitanicEngine *_vm; int _pendingLoadSlot; - uint _specialButtons; uint32 _priorLeftDownTime; uint32 _priorMiddleDownTime; uint32 _priorRightDownTime; @@ -74,7 +73,6 @@ private: void leftButtonDoubleClick(const Point &mousePos); void middleButtonDoubleClick(const Point &mousePos); void rightButtonDoubleClick(const Point &mousePos); - void handleKbdSpecial(Common::KeyState keyState); /** * Returns true if the player can control the mouse @@ -105,7 +103,6 @@ public: virtual void rightButtonUp(const Point &mousePos); virtual void mouseWheel(const Point &mousePos, bool wheelUp); virtual void keyDown(Common::KeyState keyState); - virtual void keyUp(Common::KeyState keyState); /** * Called when the application starts @@ -131,18 +128,6 @@ public: * Schedules a savegame to be loaded */ void loadGame(int slotId); - - /* - * Return whether a given special key is currently pressed - */ - bool isSpecialPressed(SpecialButtons btn) const { - return (_specialButtons & btn) != 0; - } - - /** - * Returns the bitset of the currently pressed special buttons - */ - uint getSpecialButtons() const { return _specialButtons; } }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_rooms_glyphs.cpp b/engines/titanic/pet_control/pet_rooms_glyphs.cpp index 6855e5b98e..0f7a5828b3 100644 --- a/engines/titanic/pet_control/pet_rooms_glyphs.cpp +++ b/engines/titanic/pet_control/pet_rooms_glyphs.cpp @@ -103,7 +103,7 @@ void CPetRoomsGlyph::drawAt(CScreenManager *screenManager, const Point &pt, bool void CPetRoomsGlyph::selectGlyph(const Point &topLeft, const Point &pt) { if (!isAssigned()) { - bool isShiftPressed = g_vm->_window->getSpecialButtons() & MK_SHIFT; + bool isShiftPressed = g_vm->_events->getSpecialButtons() & MK_SHIFT; if (isShiftPressed) { int selection = getSelection(topLeft, pt); @@ -116,7 +116,7 @@ void CPetRoomsGlyph::selectGlyph(const Point &topLeft, const Point &pt) { } bool CPetRoomsGlyph::dragGlyph(const Point &topLeft, CMouseDragStartMsg *msg) { - bool isShiftPressed = g_vm->_window->getSpecialButtons() & MK_SHIFT; + bool isShiftPressed = g_vm->_events->getSpecialButtons() & MK_SHIFT; CPetControl *petControl = getPetControl(); if (!isShiftPressed && petControl) { |