From bfb5bee2082a85ebcdfce663fdb076f48a149908 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Mon, 30 Dec 2019 09:46:46 +0100 Subject: [PATCH] make user aware of grab mouse limitations --- src/emucore/EventHandler.cxx | 7 +++++-- src/emucore/FrameBuffer.cxx | 25 ++++++++++++++++++------- src/gui/InputDialog.cxx | 34 +++++++++++++++++++++++++++------- src/gui/InputDialog.hxx | 20 +++++++++++--------- 4 files changed, 61 insertions(+), 25 deletions(-) diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 88e9cc345..3b8ffe6eb 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -566,9 +566,12 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated) case Event::ToggleGrabMouse: if (pressed && !repeated && !myOSystem.frameBuffer().fullScreen()) { + bool oldState = myOSystem.frameBuffer().grabMouseEnabled(); myOSystem.frameBuffer().toggleGrabMouse(); - myOSystem.frameBuffer().showMessage(myOSystem.frameBuffer().grabMouseEnabled() - ? "Grab mouse enabled" : "Grab mouse disabled"); + bool newState = myOSystem.frameBuffer().grabMouseEnabled(); + myOSystem.frameBuffer().showMessage(oldState != newState ? myOSystem.frameBuffer().grabMouseEnabled() + ? "Grab mouse enabled" : "Grab mouse disabled" + : "Grab mouse not allowed while cursor shown"); } return; diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index 922c694dd..e4e6bf480 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -843,16 +843,27 @@ void FrameBuffer::setCursorState() myOSystem.console().rightController().isAnalog()) : false; bool alwaysUseMouse = BSPF::equalsIgnoreCase("always", myOSystem.settings().getString("usemouse")); - grabMouse(emulation && (analog || alwaysUseMouse) && myGrabMouse); - // Show/hide cursor in UI/emulation mode based on 'cursor' setting - switch(myOSystem.settings().getInt("cursor")) + int cursor = myOSystem.settings().getInt("cursor"); + switch(cursor) { - case 0: showCursor(false); break; - case 1: showCursor(emulation); break; - case 2: showCursor(!emulation); break; - case 3: showCursor(true); break; + case 0: + showCursor(false); + break; + case 1: + showCursor(emulation); + myGrabMouse = false; // disable grab while cursor is shown in emulation + break; + case 2: + showCursor(!emulation); + break; + case 3: + showCursor(true); + myGrabMouse = false; // disable grab while cursor is shown in emulation + break; } + + grabMouse(emulation && (analog || alwaysUseMouse) && myGrabMouse); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index 63667e660..7a30b20a3 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -129,7 +129,7 @@ void InputDialog::addDevicePortTab(const GUI::Font& font) VarList::push_back(items, "+UI, -Emulation", "2"); VarList::push_back(items, "+UI, +Emulation", "3"); myCursorState = new PopUpWidget(myTab, font, HBORDER, ypos, pwidth, lineHeight, items, - "Mouse cursor visibility ", lwidth); + "Mouse cursor visibility ", lwidth, kCursorStateChanged); wid.push_back(myCursorState); #ifndef WINDOWED_SUPPORT myCursorState->clearFlags(Widget::FLAG_ENABLED); @@ -272,6 +272,7 @@ void InputDialog::loadConfig() // Mouse cursor state myCursorState->setSelected(instance().settings().getString("cursor"), "2"); + handleCursorState(); // Joystick deadzone myDeadzone->setValue(instance().settings().getInt("joydeadzone")); @@ -280,7 +281,7 @@ void InputDialog::loadConfig() // Paddle speed (digital and mouse) myDejitterBase->setValue(instance().settings().getInt("dejitter.base")); myDejitterDiff->setValue(instance().settings().getInt("dejitter.diff")); - UpdateDejitter(); + updateDejitter(); myDPaddleSpeed->setValue(instance().settings().getInt("dsense")); myDPaddleLabel->setLabel(instance().settings().getString("dsense")); myMPaddleSpeed->setValue(instance().settings().getInt("msense")); @@ -365,8 +366,12 @@ void InputDialog::saveConfig() // Grab mouse and hide cursor const string& cursor = myCursorState->getSelectedTag().toString(); instance().settings().setValue("cursor", cursor); - instance().settings().setValue("grabmouse", myGrabMouse->getState()); - instance().frameBuffer().enableGrabMouse(myGrabMouse->getState()); + // only allow grab mouse if cursor is hidden in emulation + int state = myCursorState->getSelected(); + bool enableGrab = state != 1 && state != 3; + bool grab = enableGrab ? myGrabMouse->getState() : false; + instance().settings().setValue("grabmouse", grab); + instance().frameBuffer().enableGrabMouse(grab); // Enable/disable modifier key-combos instance().settings().setValue("modcombo", myModCombo->getState()); @@ -416,7 +421,7 @@ void InputDialog::setDefaults() myDejitterBase->setValue(0); myDejitterDiff->setValue(0); #endif - UpdateDejitter(); + updateDejitter(); myTrackBallSpeed->setValue(10); myTrackBallLabel->setLabel("10"); @@ -432,6 +437,8 @@ void InputDialog::setDefaults() // Enable/disable modifier key-combos myModCombo->setState(true); + handleCursorState(); + break; } @@ -559,6 +566,10 @@ void InputDialog::handleCommand(CommandSender* sender, int cmd, setDefaults(); break; + case kCursorStateChanged: + handleCursorState(); + break; + case kDeadzoneChanged: myDeadzoneLabel->setValue(3200 + 1000*myDeadzone->getValue()); break; @@ -572,7 +583,7 @@ void InputDialog::handleCommand(CommandSender* sender, int cmd, break; case kDejitterChanged: - UpdateDejitter(); + updateDejitter(); break; case kTBSpeedChanged: @@ -618,7 +629,16 @@ void InputDialog::handleCommand(CommandSender* sender, int cmd, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void InputDialog::UpdateDejitter() +void InputDialog::handleCursorState() +{ + int state = myCursorState->getSelected(); + bool enableGrab = state != 1 && state != 3; + + myGrabMouse->setEnabled(enableGrab); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void InputDialog::updateDejitter() { int strength = myDejitterBase->getValue(); stringstream label; diff --git a/src/gui/InputDialog.hxx b/src/gui/InputDialog.hxx index 8f2b891a6..9df3c7879 100644 --- a/src/gui/InputDialog.hxx +++ b/src/gui/InputDialog.hxx @@ -61,19 +61,21 @@ class InputDialog : public Dialog void addDevicePortTab(const GUI::Font& font); + void handleCursorState(); + void updateDejitter(); void eraseEEPROM(); - void UpdateDejitter(); private: enum { - kDeadzoneChanged = 'DZch', - kDejitterChanged = 'Pjch', - kDPSpeedChanged = 'PDch', - kMPSpeedChanged = 'PMch', - kTBSpeedChanged = 'TBch', - kDBButtonPressed = 'DBbp', - kEEButtonPressed = 'EEbp', - kConfirmEEEraseCmd = 'EEcf' + kCursorStateChanged = 'CSch', + kDeadzoneChanged = 'DZch', + kDejitterChanged = 'Pjch', + kDPSpeedChanged = 'PDch', + kMPSpeedChanged = 'PMch', + kTBSpeedChanged = 'TBch', + kDBButtonPressed = 'DBbp', + kEEButtonPressed = 'EEbp', + kConfirmEEEraseCmd = 'EEcf' }; TabWidget* myTab{nullptr};