Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup GrabInput()

Convert to bitflags to ease moving it.
  • Loading branch information...
commit 6dcf07974d397d5023e3e45ac2891b50cce70ae7 1 parent a75387c
@dhewg dhewg authored
Showing with 30 additions and 5 deletions.
  1. +30 −5 neo/sys/events.cpp
View
35 neo/sys/events.cpp
@@ -256,14 +256,24 @@ static void PushConsoleEvent(const char *s) {
SDL_PushEvent(&event);
}
-static void GrabInput(bool grab, bool hide_cursor, bool set_state) {
+const int GRAB_ENABLE = (1 << 0);
+const int GRAB_REENABLE = (1 << 1);
+const int GRAB_HIDECURSOR = (1 << 2);
+const int GRAB_SETSTATE = (1 << 3);
+
+static void GrabInput(int flags) {
#if defined(ID_DEDICATED)
return;
#else
- if (set_state)
+ bool grab = flags & GRAB_ENABLE;
+
+ if (grab && (flags & GRAB_REENABLE))
+ grab = false;
+
+ if (flags & GRAB_SETSTATE)
grabbed = grab;
- if (hide_cursor)
+ if (flags & GRAB_HIDECURSOR)
SDL_ShowCursor(SDL_DISABLE);
else
SDL_ShowCursor(SDL_ENABLE);
@@ -365,7 +375,14 @@ Sys_GrabMouseCursor
===============
*/
void Sys_GrabMouseCursor(bool grabIt) {
- GrabInput(grabIt, grabIt, true);
+ int flags;
+
+ if (grabIt)
+ flags = GRAB_ENABLE | GRAB_HIDECURSOR | GRAB_SETSTATE;
+ else
+ flags = GRAB_SETSTATE;
+
+ GrabInput(flags);
}
/*
@@ -393,7 +410,15 @@ sysEvent_t Sys_GetEvent() {
if (SDL_PollEvent(&ev)) {
switch (ev.type) {
case SDL_ACTIVEEVENT:
- GrabInput(grabbed && ev.active.gain == 1, ev.active.gain == 1, false);
+ {
+ int flags = 0;
+
+ if (ev.active.gain)
+ flags = GRAB_ENABLE | GRAB_REENABLE | GRAB_HIDECURSOR;
+
+ GrabInput(flags);
+ }
+
return res_none;
case SDL_VIDEOEXPOSE:
Please sign in to comment.
Something went wrong with that request. Please try again.