1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-03 06:24:32 +00:00

Fix input grabbing logic, add related user setting, minor cleanup

This commit is contained in:
fgenesis 2016-11-14 03:41:48 +01:00
parent e92b76cf40
commit 6d4f1175ba
6 changed files with 48 additions and 82 deletions

View file

@ -127,8 +127,6 @@ void Core::setup_opengl()
{
assert(gGLctx);
SDL_SetWindowGrab(gScreen, SDL_TRUE);
glViewport(0, 0, width, height);
SDL_ShowCursor(SDL_DISABLE);
@ -413,7 +411,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
debugLogTextures = true;
grabInputOnReentry = -1;
grabInput = false;
srand(time(NULL));
old_dt = 0;
@ -564,28 +562,22 @@ Core::~Core()
core = 0;
}
void Core::setInputGrab(bool on)
void Core::updateInputGrab()
{
if (isWindowFocus())
{
#ifdef BBGE_BUILD_SDL2
SDL_SetWindowGrab(gScreen, on ? SDL_TRUE : SDL_FALSE);
#else
SDL_WM_GrabInput(on?SDL_GRAB_ON:SDL_GRAB_OFF);
#endif
}
// Can and MUST always ungrab if window is not in focus
const bool on = grabInput && isWindowFocus();
#ifdef BBGE_BUILD_SDL2
SDL_SetWindowGrab(gScreen, on ? SDL_TRUE : SDL_FALSE);
#else
SDL_WM_GrabInput(on?SDL_GRAB_ON:SDL_GRAB_OFF);
#endif
}
void Core::setReentryInputGrab(int on)
void Core::setInputGrab(bool on)
{
if (grabInputOnReentry == -1)
{
setInputGrab(on);
}
else
{
setInputGrab(grabInputOnReentry);
}
grabInput = on;
updateInputGrab();
}
bool Core::isFullscreen()
@ -940,27 +932,23 @@ void Core::shutdownSoundLibrary()
{
}
void Core::shutdownGraphicsLibrary(bool killVideo)
void Core::shutdownGraphicsLibrary()
{
glFinish();
if (killVideo) {
#ifdef BBGE_BUILD_SDL2
SDL_SetWindowGrab(gScreen, SDL_FALSE);
SDL_GL_MakeCurrent(gScreen, NULL);
SDL_GL_DeleteContext(gGLctx);
SDL_DestroyWindow(gScreen);
gGLctx = 0;
SDL_QuitSubSystem(SDL_INIT_VIDEO);
#else
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif
setInputGrab(false);
gScreen = 0;
#if BBGE_BUILD_OPENGL_DYNAMIC
unload_all_glsyms();
glFinish();
#ifdef BBGE_BUILD_SDL2
SDL_GL_MakeCurrent(gScreen, NULL);
SDL_GL_DeleteContext(gGLctx);
SDL_DestroyWindow(gScreen);
gGLctx = 0;
#endif
SDL_QuitSubSystem(SDL_INIT_VIDEO);
gScreen = 0;
#if BBGE_BUILD_OPENGL_DYNAMIC
unload_all_glsyms();
#endif
}
_hasFocus = false;
@ -1011,16 +999,6 @@ void centerWindow(HWND hwnd)
#endif
bool Core::createWindow(int width, int height, int bits, bool fullscreen, std::string windowTitle)
{
this->width = width;
this->height = height;
return true;
}
// No longer part of C/C++ standard
#ifndef M_PI
#define M_PI 3.14159265358979323846
@ -1271,9 +1249,7 @@ void Core::run(float runTime)
if (wasInactive)
{
debugLog("WINDOW ACTIVE");
setReentryInputGrab(1);
updateInputGrab();
wasInactive = false;
}
}
@ -1286,9 +1262,7 @@ void Core::run(float runTime)
wasInactive = true;
_hasFocus = false;
setReentryInputGrab(0);
updateInputGrab();
sound->pause();
while (!isWindowFocus())
@ -1533,8 +1507,7 @@ void Core::pollEvents(float dt)
if ((event.key.keysym.sym == SDLK_g) && (event.key.keysym.mod & KMOD_CTRL))
{
grabInputOnReentry = (grabInputOnReentry)?0:-1;
setReentryInputGrab(1);
setInputGrab(!grabInput);
}
else if (_hasFocus)
{

View file

@ -210,8 +210,6 @@ public:
void applyState(const std::string &state);
bool createWindow(int width, int height, int bits, bool fullscreen, std::string windowTitle="");
void clearBuffers();
void render(int startLayer=-1, int endLayer=-1, bool useFrameBufferIfAvail=true);
void showBuffer();
@ -263,8 +261,6 @@ public:
void setMouseConstraint(bool on);
void setMouseConstraintCircle(const Vector& pos, float mouseCircle);
void setReentryInputGrab(int on);
virtual void action(int id, int state, int source){}
bool exists(const std::string &file);
@ -415,6 +411,7 @@ public:
bool debugLogActive;
void setInputGrab(bool on);
void updateInputGrab();
bool isFullscreen();
@ -450,7 +447,7 @@ protected:
std::string userDataFolder;
int grabInputOnReentry;
bool grabInput;
int virtualOffX, virtualOffY;
@ -487,7 +484,7 @@ protected:
bool initGraphicsLibrary(int w, int h, bool fullscreen, bool vsync, int bpp);
void shutdownInputLibrary();
void shutdownJoystickLibrary();
void shutdownGraphicsLibrary(bool kill=true);
void shutdownGraphicsLibrary();
void shutdownSoundLibrary();
void detectJoysticks();