2000-05-10 20:33:16 +00:00
|
|
|
/*
|
2000-05-11 16:03:29 +00:00
|
|
|
in_win.c
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-30 10:56:03 +00:00
|
|
|
windows 95 mouse stuff
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
$Id$
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-05-22 06:58:14 +00:00
|
|
|
|
2000-05-10 20:33:16 +00:00
|
|
|
// 02/21/97 JCB Added extended DirectInput code to support external controllers.
|
|
|
|
|
2000-05-17 10:03:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-05-17 10:03:19 +00:00
|
|
|
#endif
|
2000-12-30 18:46:10 +00:00
|
|
|
|
2000-05-10 20:33:16 +00:00
|
|
|
#include "winquake.h"
|
2000-05-20 03:25:47 +00:00
|
|
|
#include <dinput.h>
|
2000-05-21 11:28:37 +00:00
|
|
|
#include "client.h"
|
|
|
|
#include "keys.h"
|
2000-05-21 18:40:10 +00:00
|
|
|
#include "console.h"
|
|
|
|
#include "qargs.h"
|
|
|
|
#include "cmd.h"
|
2000-05-22 03:15:30 +00:00
|
|
|
#include "input.h"
|
2000-11-01 03:40:05 +00:00
|
|
|
#include "cl_input.h"
|
|
|
|
#include "view.h"
|
2000-12-05 20:29:15 +00:00
|
|
|
#include "host.h"
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
#define DINPUT_BUFFERSIZE 16
|
|
|
|
#define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
HRESULT (WINAPI * pDirectInputCreate) (HINSTANCE hinst, DWORD dwVersion,
|
|
|
|
LPDIRECTINPUT * lplpDirectInput,
|
|
|
|
LPUNKNOWN punkOuter);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-14 09:57:28 +00:00
|
|
|
// mouse public variables
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
float mouse_x, mouse_y;
|
|
|
|
qboolean mouseactive;
|
|
|
|
unsigned int uiWheelMessage;
|
2000-05-14 09:57:28 +00:00
|
|
|
|
|
|
|
// mouse local variables
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static int mouse_buttons;
|
|
|
|
static int mouse_oldbuttonstate;
|
|
|
|
static POINT current_pos;
|
|
|
|
static float old_mouse_x, old_mouse_y, mx_accum, my_accum;
|
|
|
|
static qboolean mouseinitialized;
|
|
|
|
static cvar_t *m_filter;
|
|
|
|
static qboolean restore_spi;
|
|
|
|
static int originalmouseparms[3], newmouseparms[3] = { 0, 0, 1 };
|
|
|
|
static qboolean mouseparmsvalid, mouseactivatetoggle;
|
|
|
|
static qboolean mouseshowtoggle = 1;
|
|
|
|
static qboolean dinput_acquired;
|
|
|
|
static unsigned int mstate_di;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-14 09:57:28 +00:00
|
|
|
// misc locals
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static LPDIRECTINPUT g_pdi;
|
|
|
|
static LPDIRECTINPUTDEVICE g_pMouse;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
static HINSTANCE hInstDI;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static qboolean dinput;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
typedef struct MYDATA {
|
2000-12-08 06:51:37 +00:00
|
|
|
LONG lX; // X axis goes here
|
|
|
|
LONG lY; // Y axis goes here
|
|
|
|
LONG lZ; // Z axis goes here
|
|
|
|
BYTE bButtonA; // One button goes here
|
|
|
|
BYTE bButtonB; // Another button goes here
|
|
|
|
BYTE bButtonC; // Another button goes here
|
|
|
|
BYTE bButtonD; // Another button goes here
|
2000-05-10 20:33:16 +00:00
|
|
|
} MYDATA;
|
|
|
|
|
|
|
|
static DIOBJECTDATAFORMAT rgodf[] = {
|
2000-12-08 06:51:37 +00:00
|
|
|
{&GUID_XAxis, FIELD_OFFSET (MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
|
|
|
|
{&GUID_YAxis, FIELD_OFFSET (MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
|
|
|
|
|
|
|
|
{&GUID_ZAxis, FIELD_OFFSET (MYDATA, lZ),
|
|
|
|
0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
|
|
|
|
{0, FIELD_OFFSET (MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
|
|
|
|
{0, FIELD_OFFSET (MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
|
|
|
|
|
|
|
|
{0, FIELD_OFFSET (MYDATA, bButtonC),
|
|
|
|
0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
|
|
|
|
{0, FIELD_OFFSET (MYDATA, bButtonD),
|
|
|
|
0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
|
2000-05-10 20:33:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static DIDATAFORMAT df = {
|
|
|
|
sizeof (DIDATAFORMAT), // this structure
|
|
|
|
sizeof (DIOBJECTDATAFORMAT), // size of object data format
|
|
|
|
DIDF_RELAXIS, // absolute axis coordinates
|
|
|
|
sizeof (MYDATA), // device data size
|
|
|
|
NUM_OBJECTS, // number of objects
|
|
|
|
rgodf, // and here they are
|
2000-05-10 20:33:16 +00:00
|
|
|
};
|
|
|
|
|
2000-12-30 10:56:03 +00:00
|
|
|
// forward-referenced functions, joy
|
|
|
|
|
2000-12-30 11:17:23 +00:00
|
|
|
extern void JOY_Command(void);
|
2000-12-30 10:56:03 +00:00
|
|
|
extern void JOY_Init_Cvars(void);
|
|
|
|
extern void JOY_Init (void);
|
|
|
|
extern void JOY_AdvancedUpdate_f (void);
|
|
|
|
extern void JOY_Move (usercmd_t *cmd);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
Force_CenterView_f
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
static void
|
|
|
|
Force_CenterView_f (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
cl.viewangles[PITCH] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_UpdateClipCursor
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_UpdateClipCursor (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (mouseinitialized && mouseactive && !dinput) {
|
2000-05-10 20:33:16 +00:00
|
|
|
ClipCursor (&window_rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_ShowMouse
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_ShowMouse (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!mouseshowtoggle) {
|
2000-05-10 20:33:16 +00:00
|
|
|
ShowCursor (TRUE);
|
|
|
|
mouseshowtoggle = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_HideMouse
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_HideMouse (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (mouseshowtoggle) {
|
2000-05-10 20:33:16 +00:00
|
|
|
ShowCursor (FALSE);
|
|
|
|
mouseshowtoggle = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_ActivateMouse
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_ActivateMouse (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
mouseactivatetoggle = true;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (mouseinitialized) {
|
|
|
|
if (dinput) {
|
|
|
|
if (g_pMouse) {
|
|
|
|
if (!dinput_acquired) {
|
|
|
|
IDirectInputDevice_Acquire (g_pMouse);
|
2000-05-10 20:33:16 +00:00
|
|
|
dinput_acquired = true;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
} else {
|
2000-05-10 20:33:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
} else {
|
2000-05-10 20:33:16 +00:00
|
|
|
if (mouseparmsvalid)
|
2000-12-08 06:51:37 +00:00
|
|
|
restore_spi =
|
|
|
|
SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
SetCursorPos (window_center_x, window_center_y);
|
|
|
|
SetCapture (mainwindow);
|
|
|
|
ClipCursor (&window_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
mouseactive = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_SetQuakeMouseState
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_SetQuakeMouseState (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
if (mouseactivatetoggle)
|
|
|
|
IN_ActivateMouse ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_DeactivateMouse
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_DeactivateMouse (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
mouseactivatetoggle = false;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (mouseinitialized) {
|
|
|
|
if (dinput) {
|
|
|
|
if (g_pMouse) {
|
|
|
|
if (dinput_acquired) {
|
|
|
|
IDirectInputDevice_Unacquire (g_pMouse);
|
2000-05-10 20:33:16 +00:00
|
|
|
dinput_acquired = false;
|
|
|
|
}
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
} else {
|
|
|
|
if (restore_spi)
|
|
|
|
SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
ClipCursor (NULL);
|
|
|
|
ReleaseCapture ();
|
|
|
|
}
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
mouseactive = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_RestoreOriginalMouseState
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_RestoreOriginalMouseState (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
if (mouseactivatetoggle) {
|
2000-05-10 20:33:16 +00:00
|
|
|
IN_DeactivateMouse ();
|
|
|
|
mouseactivatetoggle = true;
|
|
|
|
}
|
|
|
|
// try to redraw the cursor so it gets reinitialized, because sometimes it
|
|
|
|
// has garbage after the mode switch
|
|
|
|
ShowCursor (TRUE);
|
|
|
|
ShowCursor (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_InitDInput
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
static qboolean
|
|
|
|
IN_InitDInput (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
HRESULT hr;
|
|
|
|
DIPROPDWORD dipdw = {
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
sizeof (DIPROPDWORD), // diph.dwSize
|
|
|
|
sizeof (DIPROPHEADER), // diph.dwHeaderSize
|
|
|
|
0, // diph.dwObj
|
|
|
|
DIPH_DEVICE, // diph.dwHow
|
|
|
|
}
|
|
|
|
,
|
|
|
|
DINPUT_BUFFERSIZE, // dwData
|
2000-05-10 20:33:16 +00:00
|
|
|
};
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!hInstDI) {
|
|
|
|
hInstDI = LoadLibrary ("dinput.dll");
|
|
|
|
|
|
|
|
if (hInstDI == NULL) {
|
2000-09-29 19:29:22 +00:00
|
|
|
Con_Printf ("Couldn't load dinput.dll\n");
|
2000-05-10 20:33:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!pDirectInputCreate) {
|
|
|
|
pDirectInputCreate =
|
|
|
|
(void *) GetProcAddress (hInstDI, "DirectInputCreateA");
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!pDirectInputCreate) {
|
2000-09-29 19:29:22 +00:00
|
|
|
Con_Printf ("Couldn't get DI proc addr\n");
|
2000-05-10 20:33:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// register with DirectInput and get an IDirectInput to play with.
|
2000-12-08 06:51:37 +00:00
|
|
|
hr =
|
|
|
|
iDirectInputCreate (global_hInstance, DIRECTINPUT_VERSION, &g_pdi,
|
|
|
|
NULL);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (FAILED (hr)) {
|
2000-05-10 20:33:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// obtain an interface to the system mouse device.
|
2000-12-08 06:51:37 +00:00
|
|
|
hr = IDirectInput_CreateDevice (g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (FAILED (hr)) {
|
2000-09-29 19:29:22 +00:00
|
|
|
Con_Printf ("Couldn't open DI mouse device\n");
|
2000-05-10 20:33:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// set the data format to "mouse format".
|
2000-12-08 06:51:37 +00:00
|
|
|
hr = IDirectInputDevice_SetDataFormat (g_pMouse, &df);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (FAILED (hr)) {
|
2000-09-29 19:29:22 +00:00
|
|
|
Con_Printf ("Couldn't set DI mouse format\n");
|
2000-05-10 20:33:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// set the cooperativity level.
|
2000-12-08 06:51:37 +00:00
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel (g_pMouse, mainwindow,
|
|
|
|
DISCL_EXCLUSIVE |
|
|
|
|
DISCL_FOREGROUND);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (FAILED (hr)) {
|
2000-09-29 19:29:22 +00:00
|
|
|
Con_Printf ("Couldn't set DI coop level\n");
|
2000-05-10 20:33:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the buffer size to DINPUT_BUFFERSIZE elements.
|
|
|
|
// the buffer size is a DWORD property associated with the device
|
2000-12-08 06:51:37 +00:00
|
|
|
hr =
|
|
|
|
IDirectInputDevice_SetProperty (g_pMouse, DIPROP_BUFFERSIZE,
|
|
|
|
&dipdw.diph);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (FAILED (hr)) {
|
2000-09-29 19:29:22 +00:00
|
|
|
Con_Printf ("Couldn't set DI buffersize\n");
|
2000-05-10 20:33:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_StartupMouse
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
static void
|
|
|
|
IN_StartupMouse (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
// HDC hdc;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (COM_CheckParm ("-nomouse"))
|
|
|
|
return;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
mouseinitialized = true;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (COM_CheckParm ("-dinput")) {
|
2000-05-10 20:33:16 +00:00
|
|
|
dinput = IN_InitDInput ();
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (dinput) {
|
2000-09-29 19:29:22 +00:00
|
|
|
Con_Printf ("DirectInput initialized\n");
|
2000-12-08 06:51:37 +00:00
|
|
|
} else {
|
2000-09-29 19:29:22 +00:00
|
|
|
Con_Printf ("DirectInput not initialized\n");
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!dinput) {
|
|
|
|
mouseparmsvalid =
|
|
|
|
SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (mouseparmsvalid) {
|
|
|
|
if (COM_CheckParm ("-noforcemspd"))
|
2000-05-10 20:33:16 +00:00
|
|
|
newmouseparms[2] = originalmouseparms[2];
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (COM_CheckParm ("-noforcemaccel")) {
|
2000-05-10 20:33:16 +00:00
|
|
|
newmouseparms[0] = originalmouseparms[0];
|
|
|
|
newmouseparms[1] = originalmouseparms[1];
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (COM_CheckParm ("-noforcemparms")) {
|
2000-05-10 20:33:16 +00:00
|
|
|
newmouseparms[0] = originalmouseparms[0];
|
|
|
|
newmouseparms[1] = originalmouseparms[1];
|
|
|
|
newmouseparms[2] = originalmouseparms[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mouse_buttons = 3;
|
|
|
|
|
|
|
|
// if a fullscreen video mode was set before the mouse was initialized,
|
|
|
|
// set the mouse state appropriately
|
|
|
|
if (mouseactivatetoggle)
|
|
|
|
IN_ActivateMouse ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_Init
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_Init (void)
|
2000-10-29 15:35:24 +00:00
|
|
|
{
|
2001-02-06 02:56:14 +00:00
|
|
|
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "Force view of player to center");
|
2000-10-29 15:35:24 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
uiWheelMessage = RegisterWindowMessage ("MSWHEEL_ROLLMSG");
|
2000-10-29 15:35:24 +00:00
|
|
|
|
2000-12-30 10:56:03 +00:00
|
|
|
|
2000-10-29 15:35:24 +00:00
|
|
|
IN_StartupMouse ();
|
2000-12-30 10:56:03 +00:00
|
|
|
|
|
|
|
JOY_Init ();
|
2000-10-29 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_Init_Cvars (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
// mouse variables
|
2000-12-31 04:46:04 +00:00
|
|
|
m_filter = Cvar_Get ("m_filter", "0", CVAR_NONE, "Toggle mouse input filtering.");
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-30 10:56:03 +00:00
|
|
|
JOY_Init_Cvars();
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_Shutdown
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_Shutdown (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
IN_DeactivateMouse ();
|
|
|
|
IN_ShowMouse ();
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (g_pMouse) {
|
|
|
|
IDirectInputDevice_Release (g_pMouse);
|
2000-05-10 20:33:16 +00:00
|
|
|
g_pMouse = NULL;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (g_pdi) {
|
|
|
|
IDirectInput_Release (g_pdi);
|
2000-05-10 20:33:16 +00:00
|
|
|
g_pdi = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_MouseEvent
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_MouseEvent (int mstate)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (mouseactive && !dinput) {
|
|
|
|
// perform button actions
|
|
|
|
for (i = 0; i < mouse_buttons; i++) {
|
|
|
|
if ((mstate & (1 << i)) && !(mouse_oldbuttonstate & (1 << i))) {
|
|
|
|
Key_Event (K_MOUSE1 + i, -1, true);
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!(mstate & (1 << i)) && (mouse_oldbuttonstate & (1 << i))) {
|
|
|
|
Key_Event (K_MOUSE1 + i, -1, false);
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
}
|
|
|
|
|
2000-05-10 20:33:16 +00:00
|
|
|
mouse_oldbuttonstate = mstate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_MouseMove
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_MouseMove (usercmd_t *cmd)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int mx, my;
|
|
|
|
|
|
|
|
// HDC hdc;
|
|
|
|
int i;
|
|
|
|
DIDEVICEOBJECTDATA od;
|
|
|
|
DWORD dwElements;
|
|
|
|
HRESULT hr;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
if (!mouseactive)
|
|
|
|
return;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (dinput) {
|
2000-05-10 20:33:16 +00:00
|
|
|
mx = 0;
|
|
|
|
my = 0;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (;;) {
|
2000-05-10 20:33:16 +00:00
|
|
|
dwElements = 1;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
hr = IDirectInputDevice_GetDeviceData (g_pMouse,
|
|
|
|
sizeof (DIDEVICEOBJECTDATA),
|
|
|
|
&od, &dwElements, 0);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED)) {
|
2000-05-10 20:33:16 +00:00
|
|
|
dinput_acquired = true;
|
2000-12-08 06:51:37 +00:00
|
|
|
IDirectInputDevice_Acquire (g_pMouse);
|
2000-05-10 20:33:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unable to read data or no data available */
|
2000-12-08 06:51:37 +00:00
|
|
|
if (FAILED (hr) || dwElements == 0) {
|
2000-05-10 20:33:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look at the element to see what happened */
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
switch (od.dwOfs) {
|
2000-05-10 20:33:16 +00:00
|
|
|
case DIMOFS_X:
|
|
|
|
mx += od.dwData;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIMOFS_Y:
|
|
|
|
my += od.dwData;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIMOFS_BUTTON0:
|
|
|
|
if (od.dwData & 0x80)
|
|
|
|
mstate_di |= 1;
|
|
|
|
else
|
|
|
|
mstate_di &= ~1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIMOFS_BUTTON1:
|
|
|
|
if (od.dwData & 0x80)
|
2000-12-08 06:51:37 +00:00
|
|
|
mstate_di |= (1 << 1);
|
2000-05-10 20:33:16 +00:00
|
|
|
else
|
2000-12-08 06:51:37 +00:00
|
|
|
mstate_di &= ~(1 << 1);
|
2000-05-10 20:33:16 +00:00
|
|
|
break;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-10 20:33:16 +00:00
|
|
|
case DIMOFS_BUTTON2:
|
|
|
|
if (od.dwData & 0x80)
|
2000-12-08 06:51:37 +00:00
|
|
|
mstate_di |= (1 << 2);
|
2000-05-10 20:33:16 +00:00
|
|
|
else
|
2000-12-08 06:51:37 +00:00
|
|
|
mstate_di &= ~(1 << 2);
|
2000-05-10 20:33:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// perform button actions
|
|
|
|
for (i = 0; i < mouse_buttons; i++) {
|
|
|
|
if ((mstate_di & (1 << i)) && !(mouse_oldbuttonstate & (1 << i))) {
|
|
|
|
Key_Event (K_MOUSE1 + i, -1, true);
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!(mstate_di & (1 << i)) && (mouse_oldbuttonstate & (1 << i))) {
|
|
|
|
Key_Event (K_MOUSE1 + i, -1, false);
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
}
|
|
|
|
|
2000-05-10 20:33:16 +00:00
|
|
|
mouse_oldbuttonstate = mstate_di;
|
2000-12-08 06:51:37 +00:00
|
|
|
} else {
|
2000-05-10 20:33:16 +00:00
|
|
|
GetCursorPos (¤t_pos);
|
2000-12-08 06:51:37 +00:00
|
|
|
mx = current_pos.x - window_center_x + mx_accum;
|
|
|
|
my = current_pos.y - window_center_y + my_accum;
|
|
|
|
mx_accum = 0;
|
|
|
|
my_accum = 0;
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (m_filter->value) {
|
2000-05-10 20:33:16 +00:00
|
|
|
mouse_x = (mx + old_mouse_x) * 0.5;
|
|
|
|
mouse_y = (my + old_mouse_y) * 0.5;
|
2000-12-08 06:51:37 +00:00
|
|
|
} else {
|
2000-05-10 20:33:16 +00:00
|
|
|
mouse_x = mx;
|
|
|
|
mouse_y = my;
|
|
|
|
}
|
|
|
|
|
|
|
|
old_mouse_x = mx;
|
|
|
|
old_mouse_y = my;
|
|
|
|
|
2000-05-16 04:47:41 +00:00
|
|
|
mouse_x *= sensitivity->value;
|
|
|
|
mouse_y *= sensitivity->value;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
// add mouse X/Y movement to cmd
|
2000-12-08 06:51:37 +00:00
|
|
|
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
|
2000-05-16 04:47:41 +00:00
|
|
|
cmd->sidemove += m_side->value * mouse_x;
|
2000-05-10 20:33:16 +00:00
|
|
|
else
|
2000-05-16 04:47:41 +00:00
|
|
|
cl.viewangles[YAW] -= m_yaw->value * mouse_x;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-22 03:15:30 +00:00
|
|
|
if (freelook)
|
2000-05-10 20:33:16 +00:00
|
|
|
V_StopPitchDrift ();
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
if (freelook && !(in_strafe.state & 1)) {
|
2000-05-16 04:47:41 +00:00
|
|
|
cl.viewangles[PITCH] += m_pitch->value * mouse_y;
|
2000-10-13 05:36:46 +00:00
|
|
|
cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
|
|
|
|
} else {
|
2000-05-10 20:33:16 +00:00
|
|
|
if ((in_strafe.state & 1) && noclip_anglehack)
|
2000-05-16 04:47:41 +00:00
|
|
|
cmd->upmove -= m_forward->value * mouse_y;
|
2000-05-10 20:33:16 +00:00
|
|
|
else
|
2000-05-16 04:47:41 +00:00
|
|
|
cmd->forwardmove -= m_forward->value * mouse_y;
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if the mouse has moved, force it to the center, so there's room to move
|
2000-12-08 06:51:37 +00:00
|
|
|
if (mx || my) {
|
2000-05-10 20:33:16 +00:00
|
|
|
SetCursorPos (window_center_x, window_center_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_Move
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_Move (usercmd_t *cmd)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (ActiveApp && !Minimized) {
|
2000-05-10 20:33:16 +00:00
|
|
|
IN_MouseMove (cmd);
|
2000-12-30 10:56:03 +00:00
|
|
|
JOY_Move (cmd);
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_Accumulate
|
|
|
|
===========
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_Accumulate (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
// int mx, my;
|
|
|
|
// HDC hdc;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-30 10:56:03 +00:00
|
|
|
// if (dinput) return; // If using dinput we don't probably need this
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (mouseactive) {
|
2000-05-10 20:33:16 +00:00
|
|
|
GetCursorPos (¤t_pos);
|
|
|
|
|
|
|
|
mx_accum += current_pos.x - window_center_x;
|
|
|
|
my_accum += current_pos.y - window_center_y;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// force the mouse to the center, so there's room to move
|
2000-05-10 20:33:16 +00:00
|
|
|
SetCursorPos (window_center_x, window_center_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
IN_ClearStates
|
|
|
|
===================
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
IN_ClearStates (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (mouseactive) {
|
2000-05-10 20:33:16 +00:00
|
|
|
mx_accum = 0;
|
|
|
|
my_accum = 0;
|
|
|
|
mouse_oldbuttonstate = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-30 11:17:23 +00:00
|
|
|
/*
|
|
|
|
===========
|
|
|
|
IN_Commands
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
IN_Commands (void)
|
|
|
|
{
|
|
|
|
// Joystick
|
|
|
|
JOY_Command();
|
|
|
|
}
|