2001-02-19 21:15:25 +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
|
2001-02-21 21:44:57 +00:00
|
|
|
# include "config.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
|
|
|
#include "client.h"
|
2001-03-28 17:17:56 +00:00
|
|
|
#include "QF/compat.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "draw.h"
|
|
|
|
#include "host.h"
|
2001-04-10 21:45:42 +00:00
|
|
|
#include "QF/input.h"
|
|
|
|
#include "QF/joystick.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/keys.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/qendian.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "vid.h"
|
|
|
|
#include "view.h"
|
|
|
|
|
|
|
|
#ifdef WIN32
|
2001-02-22 00:15:03 +00:00
|
|
|
// FIXME: this is evil...
|
2001-02-21 21:44:57 +00:00
|
|
|
# include <windows.h>
|
|
|
|
HWND mainwindow;
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
2001-04-11 07:57:08 +00:00
|
|
|
cvar_t *m_filter;
|
2001-02-21 21:44:57 +00:00
|
|
|
cvar_t *_windowed_mouse;
|
|
|
|
int old_windowed_mouse;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-22 00:15:03 +00:00
|
|
|
int modestate; // FIXME: just to avoid cross-comp.
|
2001-02-21 21:44:57 +00:00
|
|
|
|
|
|
|
// errors - remove later
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
static qboolean mouse_avail;
|
2001-02-21 21:44:57 +00:00
|
|
|
static float mouse_x, mouse_y;
|
2001-04-11 07:57:08 +00:00
|
|
|
static float old_mouse_x, old_mouse_y;
|
2001-02-21 21:44:57 +00:00
|
|
|
static int mouse_oldbuttonstate = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-21 21:44:57 +00:00
|
|
|
extern viddef_t vid; // global video state
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
2001-02-21 21:44:57 +00:00
|
|
|
IN_SendKeyEvents
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
IN_SendKeyEvents (void)
|
|
|
|
{
|
2001-02-21 21:44:57 +00:00
|
|
|
SDL_Event event;
|
|
|
|
int sym, state, but;
|
|
|
|
int modstate;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-21 21:44:57 +00:00
|
|
|
while (SDL_PollEvent (&event)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
switch (event.type) {
|
2001-02-21 21:44:57 +00:00
|
|
|
case SDL_KEYDOWN:
|
|
|
|
case SDL_KEYUP:
|
2001-02-26 06:48:02 +00:00
|
|
|
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;
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-02-26 06:48:02 +00:00
|
|
|
case SDLK_RALT:
|
|
|
|
case SDLK_LALT:
|
|
|
|
sym = K_ALT;
|
|
|
|
break;
|
|
|
|
case SDLK_CAPSLOCK:
|
|
|
|
sym = K_CAPSLOCK;
|
|
|
|
break;
|
|
|
|
case SDLK_KP0:
|
|
|
|
if (modstate & KMOD_NUM)
|
|
|
|
sym = K_INS;
|
|
|
|
else
|
|
|
|
sym = SDLK_0;
|
|
|
|
break;
|
|
|
|
case SDLK_KP1:
|
|
|
|
if (modstate & KMOD_NUM)
|
|
|
|
sym = K_END;
|
|
|
|
else
|
|
|
|
sym = SDLK_1;
|
|
|
|
break;
|
|
|
|
case SDLK_KP2:
|
|
|
|
if (modstate & KMOD_NUM)
|
|
|
|
sym = K_DOWNARROW;
|
|
|
|
else
|
|
|
|
sym = SDLK_2;
|
|
|
|
break;
|
|
|
|
case SDLK_KP3:
|
|
|
|
if (modstate & KMOD_NUM)
|
|
|
|
sym = K_PGDN;
|
|
|
|
else
|
|
|
|
sym = SDLK_3;
|
|
|
|
break;
|
|
|
|
case SDLK_KP4:
|
|
|
|
if (modstate & KMOD_NUM)
|
|
|
|
sym = K_LEFTARROW;
|
|
|
|
else
|
|
|
|
sym = SDLK_4;
|
|
|
|
break;
|
|
|
|
case SDLK_KP5:
|
|
|
|
sym = SDLK_5;
|
|
|
|
break;
|
|
|
|
case SDLK_KP6:
|
|
|
|
if (modstate & KMOD_NUM)
|
|
|
|
sym = K_RIGHTARROW;
|
|
|
|
else
|
|
|
|
sym = SDLK_6;
|
|
|
|
break;
|
|
|
|
case SDLK_KP7:
|
|
|
|
if (modstate & KMOD_NUM)
|
|
|
|
sym = K_HOME;
|
|
|
|
else
|
|
|
|
sym = SDLK_7;
|
|
|
|
break;
|
|
|
|
case SDLK_KP8:
|
|
|
|
if (modstate & KMOD_NUM)
|
|
|
|
sym = K_UPARROW;
|
|
|
|
else
|
|
|
|
sym = SDLK_8;
|
|
|
|
break;
|
|
|
|
case SDLK_KP9:
|
|
|
|
if (modstate & KMOD_NUM)
|
|
|
|
sym = K_PGUP;
|
|
|
|
else
|
|
|
|
sym = SDLK_9;
|
|
|
|
break;
|
|
|
|
case SDLK_KP_PERIOD:
|
|
|
|
if (modstate & KMOD_NUM)
|
|
|
|
sym = K_DEL;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
// If we're not directly handled and still above 255
|
|
|
|
// just force it to 0
|
|
|
|
if (sym > 255)
|
|
|
|
sym = 0;
|
|
|
|
Key_Event (sym, -1, state);
|
|
|
|
break;
|
2001-02-21 21:44:57 +00:00
|
|
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
2001-02-26 06:48:02 +00:00
|
|
|
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:
|
|
|
|
Key_Event (K_MWHEELUP, 0, event.type == SDL_MOUSEBUTTONDOWN);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-02-26 06:48:02 +00:00
|
|
|
case 5:
|
|
|
|
Key_Event (K_MWHEELDOWN, 0, event.type == SDL_MOUSEBUTTONDOWN);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2001-02-21 21:44:57 +00:00
|
|
|
|
|
|
|
case SDL_MOUSEMOTION:
|
2001-02-26 06:48:02 +00:00
|
|
|
if (_windowed_mouse->value) {
|
|
|
|
if ((event.motion.x != (vid.width / 2))
|
|
|
|
|| (event.motion.y != (vid.height / 2))) {
|
|
|
|
// *2 for vid_sdl.c, *10 for vid_sgl.c.
|
2001-02-21 21:44:57 +00:00
|
|
|
mouse_x = event.motion.xrel * 5;
|
|
|
|
mouse_y = event.motion.yrel * 5;
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((event.motion.x < ((vid.width / 2) - (vid.width / 4)))
|
|
|
|
|| (event.motion.x >
|
|
|
|
((vid.width / 2) + (vid.width / 4)))
|
|
|
|
|| (event.motion.y <
|
|
|
|
((vid.height / 2) - (vid.height / 4)))
|
|
|
|
|| (event.motion.y >
|
|
|
|
((vid.height / 2) + (vid.height / 4))))
|
|
|
|
SDL_WarpMouse (vid.width / 2, vid.height / 2);
|
2001-02-21 21:44:57 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
// following are *2 in vid_sdl.c, vid_sgl.c is *10
|
|
|
|
mouse_x = event.motion.xrel * 5;
|
|
|
|
mouse_y = event.motion.yrel * 5;
|
|
|
|
}
|
|
|
|
break;
|
2001-02-21 21:44:57 +00:00
|
|
|
|
|
|
|
case SDL_QUIT:
|
2001-02-26 06:48:02 +00:00
|
|
|
CL_Disconnect ();
|
|
|
|
Sys_Quit ();
|
|
|
|
break;
|
2001-02-21 21:44:57 +00:00
|
|
|
default:
|
2001-02-26 06:48:02 +00:00
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
IN_Commands (void)
|
|
|
|
{
|
|
|
|
JOY_Command ();
|
|
|
|
|
|
|
|
if (old_windowed_mouse != _windowed_mouse->value) {
|
|
|
|
old_windowed_mouse = _windowed_mouse->value;
|
|
|
|
if (!_windowed_mouse->value) {
|
2001-02-21 21:44:57 +00:00
|
|
|
// SDL_ShowCursor (0);
|
2001-02-19 21:15:25 +00:00
|
|
|
SDL_WM_GrabInput (SDL_GRAB_OFF);
|
|
|
|
} else {
|
|
|
|
SDL_WM_GrabInput (SDL_GRAB_ON);
|
2001-02-21 21:44:57 +00:00
|
|
|
// SDL_ShowCursor (1);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IN_Init (void)
|
|
|
|
{
|
|
|
|
JOY_Init ();
|
|
|
|
|
2001-02-21 21:44:57 +00:00
|
|
|
if (COM_CheckParm ("-nomouse") && !_windowed_mouse->value)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
mouse_x = mouse_y = 0.0;
|
|
|
|
mouse_avail = 1;
|
2001-02-21 21:44:57 +00:00
|
|
|
// SDL_ShowCursor (0);
|
|
|
|
// SDL_WM_GrabInput (SDL_GRAB_ON);
|
|
|
|
// FIXME: disable DGA if in_dgamouse says to.
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IN_Init_Cvars (void)
|
|
|
|
{
|
|
|
|
JOY_Init_Cvars ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
_windowed_mouse =
|
2001-04-10 23:39:30 +00:00
|
|
|
Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL,
|
2001-02-26 06:48:02 +00:00
|
|
|
"If set to 1, quake will grab the mouse in X");
|
2001-04-11 07:57:08 +00:00
|
|
|
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL, "Toggle mouse input filtering");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IN_Shutdown (void)
|
|
|
|
{
|
|
|
|
mouse_avail = 0;
|
|
|
|
}
|
|
|
|
|
2001-02-21 21:44:57 +00:00
|
|
|
void
|
|
|
|
IN_Frame (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-21 21:44:57 +00:00
|
|
|
int i;
|
|
|
|
int mouse_buttonstate;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-21 21:44:57 +00:00
|
|
|
if (!mouse_avail)
|
|
|
|
return;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-21 21:44:57 +00:00
|
|
|
i = SDL_GetMouseState (NULL, NULL);
|
2001-02-19 21:15:25 +00:00
|
|
|
/* Quake swaps the second and third buttons */
|
2001-02-21 21:44:57 +00:00
|
|
|
mouse_buttonstate = (i & ~0x06) | ((i & 0x02) << 1) | ((i & 0x04) >> 1);
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
if ((mouse_buttonstate & (1 << i))
|
2001-02-26 06:48:02 +00:00
|
|
|
&& !(mouse_oldbuttonstate & (1 << i)))
|
|
|
|
Key_Event (K_MOUSE1 + i, 0, true);
|
2001-02-21 21:44:57 +00:00
|
|
|
|
|
|
|
if (!(mouse_buttonstate & (1 << i))
|
2001-02-26 06:48:02 +00:00
|
|
|
&& (mouse_oldbuttonstate & (1 << i)))
|
|
|
|
Key_Event (K_MOUSE1 + i, 0, false);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
mouse_oldbuttonstate = mouse_buttonstate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-04-11 07:57:08 +00:00
|
|
|
IN_Move (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-04-11 07:57:08 +00:00
|
|
|
JOY_Move ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!mouse_avail)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_filter->value) {
|
|
|
|
mouse_x = (mouse_x + old_mouse_x) * 0.5;
|
|
|
|
mouse_y = (mouse_y + old_mouse_y) * 0.5;
|
|
|
|
}
|
|
|
|
old_mouse_x = mouse_x;
|
|
|
|
old_mouse_y = mouse_y;
|
|
|
|
|
|
|
|
mouse_x *= sensitivity->value;
|
|
|
|
mouse_y *= sensitivity->value;
|
|
|
|
|
2001-02-21 21:44:57 +00:00
|
|
|
if ((in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1)))
|
2001-04-11 07:57:08 +00:00
|
|
|
viewdelta.position[0] += mouse_x;
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-04-11 07:57:08 +00:00
|
|
|
viewdelta.angles[YAW] -= mouse_x;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-21 21:44:57 +00:00
|
|
|
if (freelook && !(in_strafe.state & 1)) {
|
2001-04-11 07:57:08 +00:00
|
|
|
viewdelta.angles[PITCH] += mouse_y;
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
|
|
|
if ((in_strafe.state & 1) && noclip_anglehack)
|
2001-04-11 07:57:08 +00:00
|
|
|
viewdelta.position[1] -= mouse_y;
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-04-11 07:57:08 +00:00
|
|
|
viewdelta.position[2] -= mouse_y;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
mouse_x = mouse_y = 0.0;
|
|
|
|
}
|
2001-02-21 21:44:57 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
|
|
|
IN_HandlePause (qboolean paused)
|
|
|
|
{
|
|
|
|
}
|