2006-04-24 01:14:18 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "lib/input.h"
|
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
|
|
|
|
bool g_app_minimized = false;
|
|
|
|
bool g_app_has_focus = true;
|
|
|
|
|
|
|
|
bool g_keys[SDLK_LAST] = {0};
|
|
|
|
int g_mouse_x = 50, g_mouse_y = 50;
|
|
|
|
|
|
|
|
// unused, left, right, middle, wheel up, wheel down
|
|
|
|
// (order is given by SDL_BUTTON_* constants).
|
|
|
|
bool g_mouse_buttons[6] = {0};
|
|
|
|
|
|
|
|
|
|
|
|
// updates the state of the above; never swallows messages.
|
2006-08-26 23:52:18 +02:00
|
|
|
InReaction GlobalsInputHandler(const SDL_Event_* ev)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
uint c;
|
|
|
|
|
2006-08-26 23:52:18 +02:00
|
|
|
switch(ev->ev.type)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
case SDL_ACTIVEEVENT:
|
2006-08-26 23:52:18 +02:00
|
|
|
if(ev->ev.active.state & SDL_APPACTIVE)
|
|
|
|
g_app_minimized = (ev->ev.active.gain == 0); // negated
|
|
|
|
if(ev->ev.active.state & SDL_APPINPUTFOCUS)
|
|
|
|
g_app_has_focus = (ev->ev.active.gain != 0);
|
2006-04-24 01:14:18 +02:00
|
|
|
return IN_PASS;
|
|
|
|
|
|
|
|
case SDL_MOUSEMOTION:
|
2006-08-26 23:52:18 +02:00
|
|
|
g_mouse_x = ev->ev.motion.x;
|
|
|
|
g_mouse_y = ev->ev.motion.y;
|
2006-04-24 01:14:18 +02:00
|
|
|
return IN_PASS;
|
|
|
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
2006-08-26 23:52:18 +02:00
|
|
|
c = ev->ev.button.button;
|
2006-04-24 01:14:18 +02:00
|
|
|
if(c < ARRAY_SIZE(g_mouse_buttons))
|
2006-08-26 23:52:18 +02:00
|
|
|
g_mouse_buttons[c] = (ev->ev.type == SDL_MOUSEBUTTONDOWN);
|
2006-04-24 01:14:18 +02:00
|
|
|
else
|
2007-05-26 20:38:38 +02:00
|
|
|
{
|
|
|
|
// don't complain: just ignore people with too many mouse buttons
|
|
|
|
//debug_warn("invalid mouse button");
|
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
return IN_PASS;
|
|
|
|
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
case SDL_KEYUP:
|
2006-08-26 23:52:18 +02:00
|
|
|
c = ev->ev.key.keysym.sym;
|
2006-04-24 01:14:18 +02:00
|
|
|
if(c < ARRAY_SIZE(g_keys))
|
2006-08-26 23:52:18 +02:00
|
|
|
g_keys[c] = (ev->ev.type == SDL_KEYDOWN);
|
2006-04-24 01:14:18 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// don't complain: this happens when the hotkey system
|
|
|
|
// spoofs keys (it assigns values starting from SDLK_LAST)
|
|
|
|
//debug_warn("invalid key");
|
|
|
|
}
|
|
|
|
return IN_PASS;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return IN_PASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
UNREACHABLE;
|
|
|
|
}
|