Fixed some state problems with (un)grabbing the mouse and showing/hiding

the cursor.  It should now work correctly.

Thanks to Mark Grebe for the suggestions.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@239 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2004-04-26 12:49:46 +00:00
parent cc9a03f512
commit 87277a770f
5 changed files with 26 additions and 45 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferGL.cxx,v 1.17 2004-04-20 21:07:50 stephena Exp $
// $Id: FrameBufferGL.cxx,v 1.18 2004-04-26 12:49:46 stephena Exp $
//============================================================================
#include <SDL.h>
@ -233,21 +233,18 @@ bool FrameBufferGL::init()
}
// Make sure that theUseFullScreenFlag sets up fullscreen mode correctly
theGrabMouseIndicator = myConsole->settings().getBool("grabmouse");
theHideCursorIndicator = myConsole->settings().getBool("hidecursor");
if(myConsole->settings().getBool("fullscreen"))
{
grabMouse(true);
showCursor(false);
isFullscreen = true;
}
else
{
// Keep mouse in game window if grabmouse is selected
grabMouse(theGrabMouseIndicator);
grabMouse(myConsole->settings().getBool("grabmouse"));
// Show or hide the cursor depending on the 'hidecursor' argument
showCursor(!theHideCursorIndicator);
showCursor(!myConsole->settings().getBool("hidecursor"));
}
return true;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferSDL.cxx,v 1.13 2004-04-21 16:27:34 stephena Exp $
// $Id: FrameBufferSDL.cxx,v 1.14 2004-04-26 12:49:46 stephena Exp $
//============================================================================
#include <SDL.h>
@ -33,10 +33,7 @@ FrameBufferSDL::FrameBufferSDL()
: x11Available(false),
theZoomLevel(1),
theMaxZoomLevel(1),
theGrabMouseIndicator(false),
theHideCursorIndicator(false),
theAspectRatio(1.0),
isFullscreen(false),
myPauseStatus(false)
{
}
@ -80,7 +77,7 @@ void FrameBufferSDL::setupPalette()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferSDL::toggleFullscreen()
{
isFullscreen = !isFullscreen;
bool isFullscreen = !myConsole->settings().getBool("fullscreen");
// Update the settings
myConsole->settings().setBool("fullscreen", isFullscreen);
@ -100,8 +97,8 @@ void FrameBufferSDL::toggleFullscreen()
}
else // now in windowed mode
{
grabMouse(theGrabMouseIndicator);
showCursor(!theHideCursorIndicator);
grabMouse(myConsole->settings().getBool("grabmouse"));
showCursor(!myConsole->settings().getBool("hidecursor"));
}
}
@ -117,7 +114,7 @@ void FrameBufferSDL::resize(int mode)
}
else if(mode == 1) // increase size
{
if(isFullscreen)
if(myConsole->settings().getBool("fullscreen"))
return;
if(theZoomLevel == theMaxZoomLevel)
@ -127,7 +124,7 @@ void FrameBufferSDL::resize(int mode)
}
else if(mode == -1) // decrease size
{
if(isFullscreen)
if(myConsole->settings().getBool("fullscreen"))
return;
if(theZoomLevel == 1)
@ -146,31 +143,25 @@ void FrameBufferSDL::resize(int mode)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferSDL::showCursor(bool show)
{
if(isFullscreen)
return;
if(show)
SDL_ShowCursor(SDL_ENABLE);
else
SDL_ShowCursor(SDL_DISABLE);
// Update the settings
myConsole->settings().setBool("hidecursor", !show);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferSDL::grabMouse(bool grab)
{
if(isFullscreen)
return;
if(grab)
SDL_WM_GrabInput(SDL_GRAB_ON);
else
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
// Update the settings
myConsole->settings().setBool("grabmouse", grab);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FrameBufferSDL::fullScreen()
{
return myConsole->settings().getBool("fullscreen");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferSDL.hxx,v 1.10 2004-04-15 22:52:43 stephena Exp $
// $Id: FrameBufferSDL.hxx,v 1.11 2004-04-26 12:49:46 stephena Exp $
//============================================================================
#ifndef FRAMEBUFFER_SDL_HXX
@ -23,6 +23,7 @@
#include <SDL_syswm.h>
#include "FrameBuffer.hxx"
#include "Settings.hxx"
#include "bspf.hxx"
/**
@ -34,7 +35,7 @@
the core FrameBuffer.
@author Stephen Anthony
@version $Id: FrameBufferSDL.hxx,v 1.10 2004-04-15 22:52:43 stephena Exp $
@version $Id: FrameBufferSDL.hxx,v 1.11 2004-04-26 12:49:46 stephena Exp $
*/
class FrameBufferSDL : public FrameBuffer
{
@ -79,7 +80,7 @@ class FrameBufferSDL : public FrameBuffer
/**
Answers if the display is currently in fullscreen mode.
*/
bool fullScreen() { return isFullscreen; }
bool fullScreen();
/**
Answers the current zoom level of the SDL
@ -152,18 +153,9 @@ class FrameBufferSDL : public FrameBuffer
// Indicates the maximum zoom of the SDL screen
uInt32 theMaxZoomLevel;
// Indicates if the mouse should be grabbed
bool theGrabMouseIndicator;
// Indicates if the mouse cursor should be hidden
bool theHideCursorIndicator;
// The aspect ratio of the window
float theAspectRatio;
// Indicates whether the game is currently in fullscreen
bool isFullscreen;
// Indicates whether the emulation has paused
bool myPauseStatus;
};

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferSoft.cxx,v 1.6 2004-04-20 21:08:03 stephena Exp $
// $Id: FrameBufferSoft.cxx,v 1.7 2004-04-26 12:49:46 stephena Exp $
//============================================================================
#include <SDL.h>
@ -106,21 +106,18 @@ bool FrameBufferSoft::init()
setupPalette();
// Make sure that theUseFullScreenFlag sets up fullscreen mode correctly
theGrabMouseIndicator = myConsole->settings().getBool("grabmouse");
theHideCursorIndicator = myConsole->settings().getBool("hidecursor");
if(myConsole->settings().getBool("fullscreen"))
{
grabMouse(true);
showCursor(false);
isFullscreen = true;
}
else
{
// Keep mouse in game window if grabmouse is selected
grabMouse(theGrabMouseIndicator);
grabMouse(myConsole->settings().getBool("grabmouse"));
// Show or hide the cursor depending on the 'hidecursor' argument
showCursor(!theHideCursorIndicator);
showCursor(!myConsole->settings().getBool("hidecursor"));
}
return true;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: mainSDL.cxx,v 1.71 2004-04-16 13:10:37 stephena Exp $
// $Id: mainSDL.cxx,v 1.72 2004-04-26 12:49:46 stephena Exp $
//============================================================================
#include <fstream>
@ -370,6 +370,7 @@ void handleEvents()
if(!theDisplay->fullScreen())
{
theGrabMouseIndicator = !theGrabMouseIndicator;
theSettings->setBool("grabmouse", theGrabMouseIndicator);
theDisplay->grabMouse(theGrabMouseIndicator);
}
}
@ -379,6 +380,7 @@ void handleEvents()
if(!theDisplay->fullScreen())
{
theHideCursorIndicator = !theHideCursorIndicator;
theSettings->setBool("hidecursor", theHideCursorIndicator);
theDisplay->showCursor(!theHideCursorIndicator);
}
}
@ -682,6 +684,8 @@ int main(int argc, char* argv[])
// Cache some settings so they don't have to be repeatedly searched for
thePaddleMode = theSettings->getInt("paddle");
theShowInfoFlag = theSettings->getBool("showinfo");
theGrabMouseIndicator = theSettings->getBool("grabmouse");
theHideCursorIndicator = theSettings->getBool("hidecursor");
// Request that the SDL window be centered, if possible
putenv("SDL_VIDEO_CENTERED=1");