diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 9b0c46e7e..39084773b 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -1868,6 +1868,26 @@ void EventHandler::takeSnapshot(uInt32 number) } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool EventHandler::controllerIsAnalog(Controller::Jack jack) const +{ + const Controller& controller = jack == Controller::Left ? + myOSystem.console().leftController() : myOSystem.console().rightController(); + + switch(controller.type()) + { + case Controller::Paddles: + case Controller::Driving: + case Controller::TrackBall22: + case Controller::TrackBall80: + case Controller::AmigaMouse: + case Controller::MindLink: + return true; + default: + return false; + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventHandler::setMouseControllerMode(const string& enable) { @@ -1880,32 +1900,9 @@ void EventHandler::setMouseControllerMode(const string& enable) usemouse = false; else // 'analog' { - switch(myOSystem.console().leftController().type()) - { - case Controller::Paddles: - case Controller::Driving: - case Controller::TrackBall22: - case Controller::TrackBall80: - case Controller::AmigaMouse: - case Controller::MindLink: - usemouse = true; - break; - default: - break; - } - switch(myOSystem.console().rightController().type()) - { - case Controller::Paddles: - case Controller::Driving: - case Controller::TrackBall22: - case Controller::TrackBall80: - case Controller::AmigaMouse: - case Controller::MindLink: - usemouse = true; - break; - default: - break; - } + if(controllerIsAnalog(Controller::Left) || + controllerIsAnalog(Controller::Right)) + usemouse = true; } const string& control = usemouse ? diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index 58fe3453c..ee33947c4 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -314,6 +314,14 @@ class EventHandler */ void allowAllDirections(bool allow) { myAllowAllDirectionsFlag = allow; } + /** + Determines whether the given controller must use the mouse (aka, + whether the controller generates analog output). + + @param jack The controller to query + */ + bool controllerIsAnalog(Controller::Jack jack) const; + /** Return a list of all joysticks currently in the internal database (first part of variant) and its internal ID (second part of variant). diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index de6676a82..3753caf2e 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -581,10 +581,15 @@ bool FrameBuffer::changeWindowedVidMode(int direction) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FrameBuffer::setCursorState() { - // Always grab mouse in emulation (if enabled) + // Always grab mouse in emulation (if enabled) and emulating a controller + // that always uses the mouse bool emulation = myOSystem.eventHandler().state() == EventHandler::S_EMULATE; - grabMouse(emulation && myOSystem.settings().getBool("grabmouse")); + bool analog = myOSystem.hasConsole() ? + (myOSystem.eventHandler().controllerIsAnalog(Controller::Left) || + myOSystem.eventHandler().controllerIsAnalog(Controller::Right)) : false; + + grabMouse(emulation && analog && myOSystem.settings().getBool("grabmouse")); // Show/hide cursor in UI/emulation mode based on 'cursor' setting switch(myOSystem.settings().getInt("cursor"))