mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-25 09:44:02 +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;
|
||||
|
||||
weird = 0;
|
||||
|
||||
#ifdef BBGE_BUILD_WINDOWS
|
||||
/*
|
||||
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
|
||||
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);
|
||||
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;
|
||||
|
||||
bindInput();
|
||||
setInputGrab(1);
|
||||
setInputGrab(user.system.grabInput);
|
||||
|
||||
// Go directly to the title in dev mode
|
||||
if(isDeveloperKeys())
|
||||
|
|
|
@ -466,8 +466,6 @@ public:
|
|||
|
||||
void bindInput();
|
||||
|
||||
int weird;
|
||||
|
||||
void setCutscene(bool on, bool canSkip=false);
|
||||
bool isInCutscene();
|
||||
bool isCutscenePaused();
|
||||
|
|
|
@ -63,6 +63,12 @@ void UserSettings::save()
|
|||
xml_unsafe->SetAttribute("on", system.allowDangerousScriptFunctions);
|
||||
}
|
||||
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);
|
||||
|
||||
|
@ -387,6 +393,12 @@ void UserSettings::load(bool doApply, const std::string &overrideFile)
|
|||
{
|
||||
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");
|
||||
|
|
|
@ -37,11 +37,12 @@ class UserSettings
|
|||
public:
|
||||
struct System
|
||||
{
|
||||
System() { debugLogOn = 0; devModeOn = 0; allowDangerousScriptFunctions = 0; }
|
||||
System() { debugLogOn = 0; devModeOn = 0; allowDangerousScriptFunctions = 0; grabInput=1; }
|
||||
int debugLogOn;
|
||||
std::string locale;
|
||||
int devModeOn;
|
||||
int allowDangerousScriptFunctions;
|
||||
int grabInput;
|
||||
} system;
|
||||
|
||||
struct Audio
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
if (isWindowFocus())
|
||||
void Core::updateInputGrab()
|
||||
{
|
||||
// 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()
|
||||
{
|
||||
setInputGrab(false);
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue