mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-25 17:53:47 +00:00
Fix input grabbing logic, add related user setting, minor cleanup
This commit is contained in:
parent
e92b76cf40
commit
6d4f1175ba
6 changed files with 48 additions and 82 deletions
|
@ -790,8 +790,6 @@ void DSQ::init()
|
||||||
{
|
{
|
||||||
core->settings.runInBackground = true;
|
core->settings.runInBackground = true;
|
||||||
|
|
||||||
weird = 0;
|
|
||||||
|
|
||||||
#ifdef BBGE_BUILD_WINDOWS
|
#ifdef BBGE_BUILD_WINDOWS
|
||||||
/*
|
/*
|
||||||
const std::string welcomeMessage = \
|
const std::string welcomeMessage = \
|
||||||
|
@ -902,19 +900,6 @@ This build is not yet final, and as such there are a couple things lacking. They
|
||||||
else
|
else
|
||||||
debugLog("VoiceOvers Disabled");
|
debugLog("VoiceOvers Disabled");
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
if (!createWindow(800, 600, user.video.bits, false, "Aquaria"))
|
|
||||||
#else
|
|
||||||
if (!createWindow(user.video.resx, user.video.resy, user.video.bits, user.video.full, "Aquaria"))
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
exit_error("Failed to create window");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
if (fullscreen && !sdlVideoModeOK(user.video.resx, user.video.resy, user.video.bits))
|
if (fullscreen && !sdlVideoModeOK(user.video.resx, user.video.resy, user.video.bits))
|
||||||
{
|
{
|
||||||
|
@ -1386,7 +1371,7 @@ This build is not yet final, and as such there are a couple things lacking. They
|
||||||
core->afterEffectManager = 0;
|
core->afterEffectManager = 0;
|
||||||
|
|
||||||
bindInput();
|
bindInput();
|
||||||
setInputGrab(1);
|
setInputGrab(user.system.grabInput);
|
||||||
|
|
||||||
// Go directly to the title in dev mode
|
// Go directly to the title in dev mode
|
||||||
if(isDeveloperKeys())
|
if(isDeveloperKeys())
|
||||||
|
|
|
@ -466,8 +466,6 @@ public:
|
||||||
|
|
||||||
void bindInput();
|
void bindInput();
|
||||||
|
|
||||||
int weird;
|
|
||||||
|
|
||||||
void setCutscene(bool on, bool canSkip=false);
|
void setCutscene(bool on, bool canSkip=false);
|
||||||
bool isInCutscene();
|
bool isInCutscene();
|
||||||
bool isCutscenePaused();
|
bool isCutscenePaused();
|
||||||
|
|
|
@ -63,6 +63,12 @@ void UserSettings::save()
|
||||||
xml_unsafe->SetAttribute("on", system.allowDangerousScriptFunctions);
|
xml_unsafe->SetAttribute("on", system.allowDangerousScriptFunctions);
|
||||||
}
|
}
|
||||||
xml_system->InsertEndChild(xml_unsafe);
|
xml_system->InsertEndChild(xml_unsafe);
|
||||||
|
|
||||||
|
XMLElement *xml_grabInp = doc.NewElement("GrabInput");
|
||||||
|
{
|
||||||
|
xml_grabInp->SetAttribute("on", system.grabInput);
|
||||||
|
}
|
||||||
|
xml_system->InsertEndChild(xml_grabInp);
|
||||||
}
|
}
|
||||||
doc.InsertEndChild(xml_system);
|
doc.InsertEndChild(xml_system);
|
||||||
|
|
||||||
|
@ -387,6 +393,12 @@ void UserSettings::load(bool doApply, const std::string &overrideFile)
|
||||||
{
|
{
|
||||||
system.allowDangerousScriptFunctions = xml_unsafe->IntAttribute("on");
|
system.allowDangerousScriptFunctions = xml_unsafe->IntAttribute("on");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XMLElement *xml_grabInp = xml_system->FirstChildElement("GrabInput");
|
||||||
|
if (xml_grabInp)
|
||||||
|
{
|
||||||
|
system.allowDangerousScriptFunctions = xml_grabInp->IntAttribute("on");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLElement *xml_audio = doc.FirstChildElement("Audio");
|
XMLElement *xml_audio = doc.FirstChildElement("Audio");
|
||||||
|
|
|
@ -37,11 +37,12 @@ class UserSettings
|
||||||
public:
|
public:
|
||||||
struct System
|
struct System
|
||||||
{
|
{
|
||||||
System() { debugLogOn = 0; devModeOn = 0; allowDangerousScriptFunctions = 0; }
|
System() { debugLogOn = 0; devModeOn = 0; allowDangerousScriptFunctions = 0; grabInput=1; }
|
||||||
int debugLogOn;
|
int debugLogOn;
|
||||||
std::string locale;
|
std::string locale;
|
||||||
int devModeOn;
|
int devModeOn;
|
||||||
int allowDangerousScriptFunctions;
|
int allowDangerousScriptFunctions;
|
||||||
|
int grabInput;
|
||||||
} system;
|
} system;
|
||||||
|
|
||||||
struct Audio
|
struct Audio
|
||||||
|
|
|
@ -127,8 +127,6 @@ void Core::setup_opengl()
|
||||||
{
|
{
|
||||||
assert(gGLctx);
|
assert(gGLctx);
|
||||||
|
|
||||||
SDL_SetWindowGrab(gScreen, SDL_TRUE);
|
|
||||||
|
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
|
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
@ -413,7 +411,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
|
||||||
|
|
||||||
debugLogTextures = true;
|
debugLogTextures = true;
|
||||||
|
|
||||||
grabInputOnReentry = -1;
|
grabInput = false;
|
||||||
|
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
old_dt = 0;
|
old_dt = 0;
|
||||||
|
@ -564,28 +562,22 @@ Core::~Core()
|
||||||
core = 0;
|
core = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::setInputGrab(bool on)
|
void Core::updateInputGrab()
|
||||||
{
|
|
||||||
if (isWindowFocus())
|
|
||||||
{
|
{
|
||||||
|
// Can and MUST always ungrab if window is not in focus
|
||||||
|
const bool on = grabInput && isWindowFocus();
|
||||||
|
|
||||||
#ifdef BBGE_BUILD_SDL2
|
#ifdef BBGE_BUILD_SDL2
|
||||||
SDL_SetWindowGrab(gScreen, on ? SDL_TRUE : SDL_FALSE);
|
SDL_SetWindowGrab(gScreen, on ? SDL_TRUE : SDL_FALSE);
|
||||||
#else
|
#else
|
||||||
SDL_WM_GrabInput(on?SDL_GRAB_ON:SDL_GRAB_OFF);
|
SDL_WM_GrabInput(on?SDL_GRAB_ON:SDL_GRAB_OFF);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Core::setReentryInputGrab(int on)
|
void Core::setInputGrab(bool on)
|
||||||
{
|
{
|
||||||
if (grabInputOnReentry == -1)
|
grabInput = on;
|
||||||
{
|
updateInputGrab();
|
||||||
setInputGrab(on);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setInputGrab(grabInputOnReentry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Core::isFullscreen()
|
bool Core::isFullscreen()
|
||||||
|
@ -940,27 +932,23 @@ void Core::shutdownSoundLibrary()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::shutdownGraphicsLibrary(bool killVideo)
|
void Core::shutdownGraphicsLibrary()
|
||||||
{
|
{
|
||||||
|
setInputGrab(false);
|
||||||
|
|
||||||
glFinish();
|
glFinish();
|
||||||
if (killVideo) {
|
|
||||||
#ifdef BBGE_BUILD_SDL2
|
#ifdef BBGE_BUILD_SDL2
|
||||||
SDL_SetWindowGrab(gScreen, SDL_FALSE);
|
|
||||||
SDL_GL_MakeCurrent(gScreen, NULL);
|
SDL_GL_MakeCurrent(gScreen, NULL);
|
||||||
SDL_GL_DeleteContext(gGLctx);
|
SDL_GL_DeleteContext(gGLctx);
|
||||||
SDL_DestroyWindow(gScreen);
|
SDL_DestroyWindow(gScreen);
|
||||||
gGLctx = 0;
|
gGLctx = 0;
|
||||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
|
||||||
#else
|
|
||||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
|
||||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
|
||||||
#endif
|
#endif
|
||||||
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||||
gScreen = 0;
|
gScreen = 0;
|
||||||
#if BBGE_BUILD_OPENGL_DYNAMIC
|
#if BBGE_BUILD_OPENGL_DYNAMIC
|
||||||
unload_all_glsyms();
|
unload_all_glsyms();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
_hasFocus = false;
|
_hasFocus = false;
|
||||||
|
|
||||||
|
@ -1011,16 +999,6 @@ void centerWindow(HWND hwnd)
|
||||||
#endif
|
#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
|
// No longer part of C/C++ standard
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
#define M_PI 3.14159265358979323846
|
#define M_PI 3.14159265358979323846
|
||||||
|
@ -1271,9 +1249,7 @@ void Core::run(float runTime)
|
||||||
if (wasInactive)
|
if (wasInactive)
|
||||||
{
|
{
|
||||||
debugLog("WINDOW ACTIVE");
|
debugLog("WINDOW ACTIVE");
|
||||||
|
updateInputGrab();
|
||||||
setReentryInputGrab(1);
|
|
||||||
|
|
||||||
wasInactive = false;
|
wasInactive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1286,9 +1262,7 @@ void Core::run(float runTime)
|
||||||
|
|
||||||
wasInactive = true;
|
wasInactive = true;
|
||||||
_hasFocus = false;
|
_hasFocus = false;
|
||||||
|
updateInputGrab();
|
||||||
setReentryInputGrab(0);
|
|
||||||
|
|
||||||
sound->pause();
|
sound->pause();
|
||||||
|
|
||||||
while (!isWindowFocus())
|
while (!isWindowFocus())
|
||||||
|
@ -1533,8 +1507,7 @@ void Core::pollEvents(float dt)
|
||||||
|
|
||||||
if ((event.key.keysym.sym == SDLK_g) && (event.key.keysym.mod & KMOD_CTRL))
|
if ((event.key.keysym.sym == SDLK_g) && (event.key.keysym.mod & KMOD_CTRL))
|
||||||
{
|
{
|
||||||
grabInputOnReentry = (grabInputOnReentry)?0:-1;
|
setInputGrab(!grabInput);
|
||||||
setReentryInputGrab(1);
|
|
||||||
}
|
}
|
||||||
else if (_hasFocus)
|
else if (_hasFocus)
|
||||||
{
|
{
|
||||||
|
|
|
@ -210,8 +210,6 @@ public:
|
||||||
|
|
||||||
void applyState(const std::string &state);
|
void applyState(const std::string &state);
|
||||||
|
|
||||||
bool createWindow(int width, int height, int bits, bool fullscreen, std::string windowTitle="");
|
|
||||||
|
|
||||||
void clearBuffers();
|
void clearBuffers();
|
||||||
void render(int startLayer=-1, int endLayer=-1, bool useFrameBufferIfAvail=true);
|
void render(int startLayer=-1, int endLayer=-1, bool useFrameBufferIfAvail=true);
|
||||||
void showBuffer();
|
void showBuffer();
|
||||||
|
@ -263,8 +261,6 @@ public:
|
||||||
void setMouseConstraint(bool on);
|
void setMouseConstraint(bool on);
|
||||||
void setMouseConstraintCircle(const Vector& pos, float mouseCircle);
|
void setMouseConstraintCircle(const Vector& pos, float mouseCircle);
|
||||||
|
|
||||||
void setReentryInputGrab(int on);
|
|
||||||
|
|
||||||
virtual void action(int id, int state, int source){}
|
virtual void action(int id, int state, int source){}
|
||||||
|
|
||||||
bool exists(const std::string &file);
|
bool exists(const std::string &file);
|
||||||
|
@ -415,6 +411,7 @@ public:
|
||||||
bool debugLogActive;
|
bool debugLogActive;
|
||||||
|
|
||||||
void setInputGrab(bool on);
|
void setInputGrab(bool on);
|
||||||
|
void updateInputGrab();
|
||||||
|
|
||||||
bool isFullscreen();
|
bool isFullscreen();
|
||||||
|
|
||||||
|
@ -450,7 +447,7 @@ protected:
|
||||||
|
|
||||||
std::string userDataFolder;
|
std::string userDataFolder;
|
||||||
|
|
||||||
int grabInputOnReentry;
|
bool grabInput;
|
||||||
|
|
||||||
int virtualOffX, virtualOffY;
|
int virtualOffX, virtualOffY;
|
||||||
|
|
||||||
|
@ -487,7 +484,7 @@ protected:
|
||||||
bool initGraphicsLibrary(int w, int h, bool fullscreen, bool vsync, int bpp);
|
bool initGraphicsLibrary(int w, int h, bool fullscreen, bool vsync, int bpp);
|
||||||
void shutdownInputLibrary();
|
void shutdownInputLibrary();
|
||||||
void shutdownJoystickLibrary();
|
void shutdownJoystickLibrary();
|
||||||
void shutdownGraphicsLibrary(bool kill=true);
|
void shutdownGraphicsLibrary();
|
||||||
void shutdownSoundLibrary();
|
void shutdownSoundLibrary();
|
||||||
|
|
||||||
void detectJoysticks();
|
void detectJoysticks();
|
||||||
|
|
Loading…
Reference in a new issue