2001-04-15 04:18:22 +00:00
|
|
|
/*
|
|
|
|
in_sdl.c
|
|
|
|
|
|
|
|
general sdl input driver
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
2001-05-31 05:33:13 +00:00
|
|
|
#include "compat.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/input.h"
|
|
|
|
#include "QF/joystick.h"
|
|
|
|
#include "QF/keys.h"
|
2001-04-16 03:55:44 +00:00
|
|
|
#include "QF/mathlib.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/qendian.h"
|
2001-04-16 03:55:44 +00:00
|
|
|
#include "QF/vid.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
// FIXME: this is evil...
|
|
|
|
# include <windows.h>
|
|
|
|
HWND mainwindow;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cvar_t *m_filter;
|
|
|
|
cvar_t *_windowed_mouse;
|
|
|
|
int old_windowed_mouse;
|
|
|
|
|
|
|
|
int modestate; // FIXME: just to avoid cross-comp.
|
|
|
|
|
|
|
|
// errors - remove later
|
|
|
|
|
|
|
|
/*
|
|
|
|
IN_SendKeyEvents
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2001-04-16 03:55:44 +00:00
|
|
|
IN_LL_SendKeyEvents (void)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
SDL_Event event;
|
|
|
|
int sym, state, but;
|
|
|
|
int modstate;
|
|
|
|
|
|
|
|
while (SDL_PollEvent (&event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
case SDL_KEYUP:
|
|
|
|
sym = event.key.keysym.sym;
|
|
|
|
state = event.key.state;
|
|
|
|
modstate = SDL_GetModState ();
|
|
|
|
switch (sym) {
|
|
|
|
case SDLK_DELETE:
|
|
|
|
sym = K_DEL;
|
|
|
|
break;
|
|
|
|
case SDLK_BACKSPACE:
|
|
|
|
sym = K_BACKSPACE;
|
|
|
|
break;
|
|
|
|
case SDLK_F1:
|
|
|
|
sym = K_F1;
|
|
|
|
break;
|
|
|
|
case SDLK_F2:
|
|
|
|
sym = K_F2;
|
|
|
|
break;
|
|
|
|
case SDLK_F3:
|
|
|
|
sym = K_F3;
|
|
|
|
break;
|
|
|
|
case SDLK_F4:
|
|
|
|
sym = K_F4;
|
|
|
|
break;
|
|
|
|
case SDLK_F5:
|
|
|
|
sym = K_F5;
|
|
|
|
break;
|
|
|
|
case SDLK_F6:
|
|
|
|
sym = K_F6;
|
|
|
|
break;
|
|
|
|
case SDLK_F7:
|
|
|
|
sym = K_F7;
|
|
|
|
break;
|
|
|
|
case SDLK_F8:
|
|
|
|
sym = K_F8;
|
|
|
|
break;
|
|
|
|
case SDLK_F9:
|
|
|
|
sym = K_F9;
|
|
|
|
break;
|
|
|
|
case SDLK_F10:
|
|
|
|
sym = K_F10;
|
|
|
|
break;
|
|
|
|
case SDLK_F11:
|
|
|
|
sym = K_F11;
|
|
|
|
break;
|
|
|
|
case SDLK_F12:
|
|
|
|
sym = K_F12;
|
|
|
|
break;
|
|
|
|
case SDLK_BREAK:
|
|
|
|
case SDLK_PAUSE:
|
|
|
|
sym = K_PAUSE;
|
|
|
|
break;
|
|
|
|
case SDLK_UP:
|
|
|
|
sym = K_UPARROW;
|
|
|
|
break;
|
|
|
|
case SDLK_DOWN:
|
|
|
|
sym = K_DOWNARROW;
|
|
|
|
break;
|
|
|
|
case SDLK_RIGHT:
|
|
|
|
sym = K_RIGHTARROW;
|
|
|
|
break;
|
|
|
|
case SDLK_LEFT:
|
|
|
|
sym = K_LEFTARROW;
|
|
|
|
break;
|
|
|
|
case SDLK_INSERT:
|
|
|
|
sym = K_INS;
|
|
|
|
break;
|
|
|
|
case SDLK_HOME:
|
|
|
|
sym = K_HOME;
|
|
|
|
break;
|
|
|
|
case SDLK_END:
|
|
|
|
sym = K_END;
|
|
|
|
break;
|
|
|
|
case SDLK_PAGEUP:
|
|
|
|
sym = K_PGUP;
|
|
|
|
break;
|
|
|
|
case SDLK_PAGEDOWN:
|
|
|
|
sym = K_PGDN;
|
|
|
|
break;
|
|
|
|
case SDLK_RSHIFT:
|
|
|
|
case SDLK_LSHIFT:
|
|
|
|
sym = K_SHIFT;
|
|
|
|
break;
|
|
|
|
case SDLK_RCTRL:
|
|
|
|
case SDLK_LCTRL:
|
|
|
|
sym = K_CTRL;
|
|
|
|
break;
|
|
|
|
case SDLK_RALT:
|
|
|
|
case SDLK_LALT:
|
|
|
|
sym = K_ALT;
|
|
|
|
break;
|
|
|
|
case SDLK_CAPSLOCK:
|
|
|
|
sym = K_CAPSLOCK;
|
|
|
|
break;
|
|
|
|
case SDLK_KP0:
|
|
|
|
if (modstate & KMOD_NUM)
|
2001-08-06 00:16:48 +00:00
|
|
|
sym = KP_INS;
|
2001-04-15 04:18:22 +00:00
|
|
|
else
|
|
|
|
sym = SDLK_0;
|
|
|
|
break;
|
|
|
|
case SDLK_KP1:
|
|
|
|
if (modstate & KMOD_NUM)
|
2001-08-06 00:16:48 +00:00
|
|
|
sym = KP_END;
|
2001-04-15 04:18:22 +00:00
|
|
|
else
|
|
|
|
sym = SDLK_1;
|
|
|
|
break;
|
|
|
|
case SDLK_KP2:
|
|
|
|
if (modstate & KMOD_NUM)
|
2001-08-06 00:16:48 +00:00
|
|
|
sym = KP_DOWNARROW;
|
2001-04-15 04:18:22 +00:00
|
|
|
else
|
|
|
|
sym = SDLK_2;
|
|
|
|
break;
|
|
|
|
case SDLK_KP3:
|
|
|
|
if (modstate & KMOD_NUM)
|
2001-08-06 00:16:48 +00:00
|
|
|
sym = KP_PGDN;
|
2001-04-15 04:18:22 +00:00
|
|
|
else
|
|
|
|
sym = SDLK_3;
|
|
|
|
break;
|
|
|
|
case SDLK_KP4:
|
|
|
|
if (modstate & KMOD_NUM)
|
2001-08-06 00:16:48 +00:00
|
|
|
sym = KP_LEFTARROW;
|
2001-04-15 04:18:22 +00:00
|
|
|
else
|
|
|
|
sym = SDLK_4;
|
|
|
|
break;
|
|
|
|
case SDLK_KP5:
|
2001-08-06 00:16:48 +00:00
|
|
|
if (modstate & KMOD_NUM)
|
|
|
|
sym = KP_5;
|
|
|
|
else
|
|
|
|
sym = SDLK_5;
|
2001-04-15 04:18:22 +00:00
|
|
|
break;
|
|
|
|
case SDLK_KP6:
|
|
|
|
if (modstate & KMOD_NUM)
|
2001-08-06 00:16:48 +00:00
|
|
|
sym = KP_RIGHTARROW;
|
2001-04-15 04:18:22 +00:00
|
|
|
else
|
|
|
|
sym = SDLK_6;
|
|
|
|
break;
|
|
|
|
case SDLK_KP7:
|
|
|
|
if (modstate & KMOD_NUM)
|
2001-08-06 00:16:48 +00:00
|
|
|
sym = KP_HOME;
|
2001-04-15 04:18:22 +00:00
|
|
|
else
|
|
|
|
sym = SDLK_7;
|
|
|
|
break;
|
|
|
|
case SDLK_KP8:
|
|
|
|
if (modstate & KMOD_NUM)
|
2001-08-06 00:16:48 +00:00
|
|
|
sym = KP_UPARROW;
|
2001-04-15 04:18:22 +00:00
|
|
|
else
|
|
|
|
sym = SDLK_8;
|
|
|
|
break;
|
|
|
|
case SDLK_KP9:
|
|
|
|
if (modstate & KMOD_NUM)
|
2001-08-06 00:16:48 +00:00
|
|
|
sym = KP_PGUP;
|
2001-04-15 04:18:22 +00:00
|
|
|
else
|
|
|
|
sym = SDLK_9;
|
|
|
|
break;
|
|
|
|
case SDLK_KP_PERIOD:
|
|
|
|
if (modstate & KMOD_NUM)
|
2001-08-06 00:16:48 +00:00
|
|
|
sym = KP_DEL;
|
2001-04-15 04:18:22 +00:00
|
|
|
else
|
|
|
|
sym = SDLK_PERIOD;
|
|
|
|
break;
|
|
|
|
case SDLK_KP_DIVIDE:
|
|
|
|
sym = SDLK_SLASH;
|
|
|
|
break;
|
|
|
|
case SDLK_KP_MULTIPLY:
|
|
|
|
sym = SDLK_ASTERISK;
|
|
|
|
break;
|
|
|
|
case SDLK_KP_MINUS:
|
|
|
|
sym = SDLK_MINUS;
|
|
|
|
break;
|
|
|
|
case SDLK_KP_PLUS:
|
|
|
|
sym = SDLK_PLUS;
|
|
|
|
break;
|
|
|
|
case SDLK_KP_ENTER:
|
|
|
|
sym = SDLK_RETURN;
|
|
|
|
break;
|
|
|
|
case SDLK_KP_EQUALS:
|
|
|
|
sym = SDLK_EQUALS;
|
|
|
|
break;
|
|
|
|
}
|
2001-07-20 05:18:46 +00:00
|
|
|
// If we're not directly handled and still >= K_NUM_KEYS
|
2001-04-15 04:18:22 +00:00
|
|
|
// just force it to 0
|
2001-07-20 05:18:46 +00:00
|
|
|
if (sym >= K_NUM_KEYS)
|
2001-04-15 04:18:22 +00:00
|
|
|
sym = 0;
|
|
|
|
Key_Event (sym, -1, state);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
but = event.button.button;
|
|
|
|
if (but == 2)
|
|
|
|
but = 3;
|
|
|
|
else if (but == 3)
|
|
|
|
but = 2;
|
|
|
|
|
|
|
|
switch (but) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
Key_Event (K_MOUSE1 + but - 1, 0, event.type
|
|
|
|
== SDL_MOUSEBUTTONDOWN);
|
|
|
|
break;
|
|
|
|
case 4:
|
2001-08-06 00:16:48 +00:00
|
|
|
Key_Event (K_MWHEELUP, 0, true);
|
|
|
|
Key_Event (K_MWHEELUP, 0, false);
|
2001-04-15 04:18:22 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2001-08-06 00:16:48 +00:00
|
|
|
Key_Event (K_MWHEELDOWN, 0, true);
|
|
|
|
Key_Event (K_MWHEELDOWN, 0, false);
|
2001-04-15 04:18:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_MOUSEMOTION:
|
2001-08-06 00:16:48 +00:00
|
|
|
in_mouse_x += event.motion.xrel;
|
|
|
|
in_mouse_y += event.motion.yrel;
|
2001-04-15 04:18:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_QUIT:
|
2001-04-16 03:55:44 +00:00
|
|
|
//CL_Disconnect ();
|
2001-04-15 04:18:22 +00:00
|
|
|
Sys_Quit ();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2001-04-16 03:55:44 +00:00
|
|
|
IN_LL_Commands (void)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
JOY_Command ();
|
|
|
|
|
|
|
|
if (old_windowed_mouse != _windowed_mouse->value) {
|
|
|
|
old_windowed_mouse = _windowed_mouse->value;
|
|
|
|
if (!_windowed_mouse->value) {
|
2001-08-06 00:16:48 +00:00
|
|
|
SDL_ShowCursor (1);
|
2001-04-15 04:18:22 +00:00
|
|
|
SDL_WM_GrabInput (SDL_GRAB_OFF);
|
|
|
|
} else {
|
|
|
|
SDL_WM_GrabInput (SDL_GRAB_ON);
|
2001-08-06 00:16:48 +00:00
|
|
|
SDL_ShowCursor (0);
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-04-16 03:55:44 +00:00
|
|
|
IN_LL_Init (void)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
JOY_Init ();
|
|
|
|
|
|
|
|
if (COM_CheckParm ("-nomouse") && !_windowed_mouse->value)
|
|
|
|
return;
|
|
|
|
|
2001-04-16 03:55:44 +00:00
|
|
|
in_mouse_x = in_mouse_y = 0.0;
|
|
|
|
in_mouse_avail = 1;
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-04-16 03:55:44 +00:00
|
|
|
IN_LL_Init_Cvars (void)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-04-16 03:55:44 +00:00
|
|
|
IN_LL_Shutdown (void)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
2001-04-16 03:55:44 +00:00
|
|
|
in_mouse_avail = 0;
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
2001-04-17 15:55:33 +00:00
|
|
|
void
|
|
|
|
IN_LL_ClearStates (void)
|
|
|
|
{
|
|
|
|
}
|