Grabmouse is not used when using a virtual controller that doesn't output

analog data (ie, not a mouse).  This fixes the issue of mouse grabbing
when a ROM isn't even using the mouse.
This commit is contained in:
Stephen Anthony 2017-01-28 19:45:30 -03:30
parent d99f83580f
commit 8b4096e1ef
3 changed files with 38 additions and 28 deletions

View File

@ -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 ?

View File

@ -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).

View File

@ -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"))