mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-01-19 07:51:54 +00:00
Use SDL GLimp and input implementations on Windows
The DirectX SDK is not required anymore.
This commit is contained in:
parent
95233c470b
commit
b83868090c
13 changed files with 35 additions and 2697 deletions
|
@ -214,19 +214,10 @@ if (WIN32)
|
|||
add_definitions(-D_WIN32_WINNT=0x0501)
|
||||
|
||||
set(sys_libs ${sys_libs}
|
||||
dinput8
|
||||
ksuser
|
||||
dxguid
|
||||
winmm
|
||||
iphlpapi
|
||||
wsock32
|
||||
)
|
||||
|
||||
if (MINGW)
|
||||
list(APPEND sys_libs dxerr8)
|
||||
else()
|
||||
list(APPEND sys_libs dxerr)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "Building ${CMAKE_BUILD_TYPE} for ${os}.${cpu}")
|
||||
|
@ -655,17 +646,15 @@ elseif (WIN32)
|
|||
set(src_sys_base
|
||||
sys/cpu.cpp
|
||||
sys/threads.cpp
|
||||
sys/glimp.cpp
|
||||
sys/events.cpp
|
||||
sys/sys_local.cpp
|
||||
sys/win32/win_cpu.cpp
|
||||
# sys/win32/win_gamma.cpp
|
||||
sys/win32/win_glimp.cpp
|
||||
sys/win32/win_input.cpp
|
||||
sys/win32/win_main.cpp
|
||||
sys/win32/win_net.cpp
|
||||
sys/win32/win_shared.cpp
|
||||
sys/win32/win_syscon.cpp
|
||||
sys/win32/win_taskkeyhook.cpp
|
||||
sys/win32/win_wndproc.cpp
|
||||
)
|
||||
|
||||
set(src_sys_core
|
||||
|
|
|
@ -44,9 +44,6 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include <mmsystem.h>
|
||||
#include <mmreg.h>
|
||||
|
||||
#define DIRECTINPUT_VERSION 0x0800 // was 0x0700 with the old mssdk
|
||||
#include <dinput.h>
|
||||
|
||||
#pragma warning(disable : 4100) // unreferenced formal parameter
|
||||
#pragma warning(disable : 4244) // conversion to smaller type, possible loss of data
|
||||
#pragma warning(disable : 4714) // function marked as __forceinline not inlined
|
||||
|
|
|
@ -55,6 +55,9 @@ polygon offset factor causes occasional texture holes from highly angled texture
|
|||
|
||||
*/
|
||||
|
||||
// WGL_ARB_pixel_format
|
||||
static PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
|
||||
|
||||
// WGL_ARB_pixel_format
|
||||
static PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB;
|
||||
static PFNWGLGETPIXELFORMATATTRIBFVARBPROC wglGetPixelFormatAttribfvARB;
|
||||
|
@ -523,6 +526,9 @@ void R_Exp_Allocate( void ) {
|
|||
|
||||
initialized = true;
|
||||
|
||||
// WGL_ARB_pixel_format
|
||||
wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)GLimp_ExtensionPointer("wglChoosePixelFormatARB");
|
||||
|
||||
// WGL_ARB_pixel_format
|
||||
wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)GLimp_ExtensionPointer("wglGetPixelFormatAttribivARB");
|
||||
wglGetPixelFormatAttribfvARB = (PFNWGLGETPIXELFORMATATTRIBFVARBPROC)GLimp_ExtensionPointer("wglGetPixelFormatAttribfvARB");
|
||||
|
|
|
@ -307,8 +307,11 @@ void Sys_ShutdownInput() {
|
|||
Sys_InitScanTable
|
||||
===========
|
||||
*/
|
||||
// Windows has its own version due to the tools
|
||||
#ifndef _WIN32
|
||||
void Sys_InitScanTable() {
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
===============
|
||||
|
|
|
@ -34,6 +34,10 @@ If you have questions concerning this license or the applicable additional terms
|
|||
|
||||
#include "renderer/tr_local.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "sys/win32/win_local.h"
|
||||
#endif
|
||||
|
||||
idCVar sys_videoRam("sys_videoRam", "0", CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_INTEGER, "Texture memory on the video card (in megabytes) - 0: autodetect", 0, 512);
|
||||
|
||||
/*
|
||||
|
@ -162,6 +166,25 @@ bool GLimp_Init(glimpParms_t parms) {
|
|||
|
||||
glConfig.wgl_extensions_string = "";
|
||||
|
||||
#ifdef _WIN32
|
||||
PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)GLimp_ExtensionPointer("wglGetExtensionsStringARB");
|
||||
|
||||
if (wglGetExtensionsStringARB)
|
||||
glConfig.wgl_extensions_string = (const char *)wglGetExtensionsStringARB(wglGetCurrentDC());
|
||||
|
||||
// the editors still rely on these vars
|
||||
SDL_SysWMinfo info;
|
||||
SDL_VERSION(&info.version);
|
||||
|
||||
if (SDL_GetWMInfo(&info)) {
|
||||
win32.hDC = wglGetCurrentDC();
|
||||
win32.hGLRC = info.hglrc;
|
||||
}
|
||||
|
||||
win32.pixelformat = GetPixelFormat(win32.hDC);
|
||||
DescribePixelFormat(win32.hDC, win32.pixelformat, sizeof(win32.pfd), &win32.pfd);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 GPL Source Code
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
|
||||
|
||||
Doom 3 Source Code 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 Source Code 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 Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||
|
||||
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
/*
|
||||
** WIN_GAMMA.C
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "renderer/tr_local.h"
|
||||
|
||||
#include "sys/win32/win_local.h"
|
||||
|
||||
static unsigned short s_oldHardwareGamma[3][256];
|
||||
|
||||
/*
|
||||
** WG_GetOldGammaRamp
|
||||
**
|
||||
*/
|
||||
void WG_GetOldGammaRamp( void )
|
||||
{
|
||||
HDC hDC;
|
||||
|
||||
hDC = GetDC( GetDesktopWindow() );
|
||||
GetDeviceGammaRamp( hDC, s_oldHardwareGamma );
|
||||
ReleaseDC( GetDesktopWindow(), hDC );
|
||||
|
||||
|
||||
/*
|
||||
** GLimp_SetGamma
|
||||
**
|
||||
*/
|
||||
void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned char blue[256] )
|
||||
{
|
||||
unsigned short table[3][256];
|
||||
int i;
|
||||
|
||||
if ( !glw_state.hDC )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for ( i = 0; i < 256; i++ )
|
||||
{
|
||||
table[0][i] = ( ( ( unsigned short ) red[i] ) << 8 ) | red[i];
|
||||
table[1][i] = ( ( ( unsigned short ) green[i] ) << 8 ) | green[i];
|
||||
table[2][i] = ( ( ( unsigned short ) blue[i] ) << 8 ) | blue[i];
|
||||
}
|
||||
|
||||
if ( !SetDeviceGammaRamp( glw_state.hDC, table ) ) {
|
||||
common->Printf( "WARNING: SetDeviceGammaRamp failed.\n" );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** WG_RestoreGamma
|
||||
*/
|
||||
void WG_RestoreGamma( void )
|
||||
{
|
||||
HDC hDC;
|
||||
|
||||
// if we never read in a reasonable looking
|
||||
// table, don't write it out
|
||||
if ( s_oldHardwareGamma[0][255] == 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
hDC = GetDC( GetDesktopWindow() );
|
||||
SetDeviceGammaRamp( hDC, s_oldHardwareGamma );
|
||||
ReleaseDC( GetDesktopWindow(), hDC );
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -32,33 +32,6 @@ If you have questions concerning this license or the applicable additional terms
|
|||
|
||||
#include "sys/win32/win_local.h"
|
||||
|
||||
#define DINPUT_BUFFERSIZE 256
|
||||
|
||||
#define CHAR_FIRSTREPEAT 200
|
||||
#define CHAR_REPEAT 100
|
||||
|
||||
typedef struct MYDATA {
|
||||
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
|
||||
} MYDATA;
|
||||
|
||||
static DIOBJECTDATAFORMAT rgodf[] = {
|
||||
{ &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,},
|
||||
};
|
||||
|
||||
//==========================================================================
|
||||
|
||||
static const unsigned char s_scantokey[256] = {
|
||||
// 0 1 2 3 4 5 6 7
|
||||
// 8 9 A B C D E F
|
||||
|
@ -261,450 +234,6 @@ static const unsigned char *keyScanTable = s_scantokey;
|
|||
// scan codes instead of just the first 128.
|
||||
static unsigned char rightAltKey = K_ALT;
|
||||
|
||||
#define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
/*
|
||||
============================================================
|
||||
|
||||
DIRECT INPUT KEYBOARD CONTROL
|
||||
|
||||
============================================================
|
||||
*/
|
||||
|
||||
bool IN_StartupKeyboard( void ) {
|
||||
HRESULT hr;
|
||||
bool bExclusive;
|
||||
bool bForeground;
|
||||
bool bImmediate;
|
||||
bool bDisableWindowsKey;
|
||||
DWORD dwCoopFlags;
|
||||
|
||||
if (!win32.g_pdi) {
|
||||
common->Printf("keyboard: DirectInput has not been started\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (win32.g_pKeyboard) {
|
||||
win32.g_pKeyboard->Release();
|
||||
win32.g_pKeyboard = NULL;
|
||||
}
|
||||
|
||||
// Detrimine where the buffer would like to be allocated
|
||||
bExclusive = false;
|
||||
bForeground = true;
|
||||
bImmediate = false;
|
||||
bDisableWindowsKey = true;
|
||||
|
||||
if( bExclusive )
|
||||
dwCoopFlags = DISCL_EXCLUSIVE;
|
||||
else
|
||||
dwCoopFlags = DISCL_NONEXCLUSIVE;
|
||||
|
||||
if( bForeground )
|
||||
dwCoopFlags |= DISCL_FOREGROUND;
|
||||
else
|
||||
dwCoopFlags |= DISCL_BACKGROUND;
|
||||
|
||||
// Disabling the windows key is only allowed only if we are in foreground nonexclusive
|
||||
if( bDisableWindowsKey && !bExclusive && bForeground )
|
||||
dwCoopFlags |= DISCL_NOWINKEY;
|
||||
|
||||
// Obtain an interface to the system keyboard device.
|
||||
if( FAILED( hr = win32.g_pdi->CreateDevice( GUID_SysKeyboard, &win32.g_pKeyboard, NULL ) ) ) {
|
||||
common->Printf("keyboard: couldn't find a keyboard device\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the data format to "keyboard format" - a predefined data format
|
||||
//
|
||||
// A data format specifies which controls on a device we
|
||||
// are interested in, and how they should be reported.
|
||||
//
|
||||
// This tells DirectInput that we will be passing an array
|
||||
// of 256 bytes to IDirectInputDevice::GetDeviceState.
|
||||
if( FAILED( hr = win32.g_pKeyboard->SetDataFormat( &c_dfDIKeyboard ) ) )
|
||||
return false;
|
||||
|
||||
// Set the cooperativity level to let DirectInput know how
|
||||
// this device should interact with the system and with other
|
||||
// DirectInput applications.
|
||||
hr = win32.g_pKeyboard->SetCooperativeLevel( win32.hWnd, dwCoopFlags );
|
||||
if( hr == DIERR_UNSUPPORTED && !bForeground && bExclusive ) {
|
||||
common->Printf("keyboard: SetCooperativeLevel() returned DIERR_UNSUPPORTED.\nFor security reasons, background exclusive keyboard access is not allowed.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if( FAILED(hr) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !bImmediate ) {
|
||||
// IMPORTANT STEP TO USE BUFFERED DEVICE DATA!
|
||||
//
|
||||
// DirectInput uses unbuffered I/O (buffer size = 0) by default.
|
||||
// If you want to read buffered data, you need to set a nonzero
|
||||
// buffer size.
|
||||
//
|
||||
// Set the buffer size to DINPUT_BUFFERSIZE (defined above) elements.
|
||||
//
|
||||
// The buffer size is a DWORD property associated with the device.
|
||||
DIPROPDWORD dipdw;
|
||||
|
||||
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
|
||||
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
dipdw.diph.dwObj = 0;
|
||||
dipdw.diph.dwHow = DIPH_DEVICE;
|
||||
dipdw.dwData = DINPUT_BUFFERSIZE; // Arbitary buffer size
|
||||
|
||||
if( FAILED( hr = win32.g_pKeyboard->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph ) ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
// Acquire the newly created device
|
||||
win32.g_pKeyboard->Acquire();
|
||||
|
||||
common->Printf( "keyboard: DirectInput initialized.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
=======
|
||||
MapKey
|
||||
|
||||
Map from windows to quake keynums
|
||||
|
||||
FIXME: scan code tables should include the upper 128 scan codes instead
|
||||
of having to special-case them here. The current code makes it difficult
|
||||
to special-case conversions for non-US keyboards. Currently the only
|
||||
special-case is for right alt.
|
||||
=======
|
||||
*/
|
||||
int IN_DIMapKey (int key) {
|
||||
if ( key>=128 ) {
|
||||
switch ( key ) {
|
||||
case DIK_HOME:
|
||||
return K_HOME;
|
||||
case DIK_UPARROW:
|
||||
return K_UPARROW;
|
||||
case DIK_PGUP:
|
||||
return K_PGUP;
|
||||
case DIK_LEFTARROW:
|
||||
return K_LEFTARROW;
|
||||
case DIK_RIGHTARROW:
|
||||
return K_RIGHTARROW;
|
||||
case DIK_END:
|
||||
return K_END;
|
||||
case DIK_DOWNARROW:
|
||||
return K_DOWNARROW;
|
||||
case DIK_PGDN:
|
||||
return K_PGDN;
|
||||
case DIK_INSERT:
|
||||
return K_INS;
|
||||
case DIK_DELETE:
|
||||
return K_DEL;
|
||||
case DIK_RMENU:
|
||||
return rightAltKey;
|
||||
case DIK_RCONTROL:
|
||||
return K_CTRL;
|
||||
case DIK_NUMPADENTER:
|
||||
return K_KP_ENTER;
|
||||
case DIK_NUMPADEQUALS:
|
||||
return K_KP_EQUALS;
|
||||
case DIK_PAUSE:
|
||||
return K_PAUSE;
|
||||
case DIK_DIVIDE:
|
||||
return K_KP_SLASH;
|
||||
case DIK_LWIN:
|
||||
return K_LWIN;
|
||||
case DIK_RWIN:
|
||||
return K_RWIN;
|
||||
case DIK_APPS:
|
||||
return K_MENU;
|
||||
case DIK_SYSRQ:
|
||||
return K_PRINT_SCR;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
switch (key) {
|
||||
case DIK_NUMPAD7:
|
||||
return K_KP_HOME;
|
||||
case DIK_NUMPAD8:
|
||||
return K_KP_UPARROW;
|
||||
case DIK_NUMPAD9:
|
||||
return K_KP_PGUP;
|
||||
case DIK_NUMPAD4:
|
||||
return K_KP_LEFTARROW;
|
||||
case DIK_NUMPAD5:
|
||||
return K_KP_5;
|
||||
case DIK_NUMPAD6:
|
||||
return K_KP_RIGHTARROW;
|
||||
case DIK_NUMPAD1:
|
||||
return K_KP_END;
|
||||
case DIK_NUMPAD2:
|
||||
return K_KP_DOWNARROW;
|
||||
case DIK_NUMPAD3:
|
||||
return K_KP_PGDN;
|
||||
case DIK_NUMPAD0:
|
||||
return K_KP_INS;
|
||||
case DIK_DECIMAL:
|
||||
return K_KP_DEL;
|
||||
case DIK_SUBTRACT:
|
||||
return K_KP_MINUS;
|
||||
case DIK_ADD:
|
||||
return K_KP_PLUS;
|
||||
case DIK_NUMLOCK:
|
||||
return K_KP_NUMLOCK;
|
||||
case DIK_MULTIPLY:
|
||||
return K_KP_STAR;
|
||||
default:
|
||||
return keyScanTable[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==========================
|
||||
IN_DeactivateKeyboard
|
||||
==========================
|
||||
*/
|
||||
void IN_DeactivateKeyboard( void ) {
|
||||
if (!win32.g_pKeyboard) {
|
||||
return;
|
||||
}
|
||||
win32.g_pKeyboard->Unacquire( );
|
||||
}
|
||||
|
||||
/*
|
||||
============================================================
|
||||
|
||||
DIRECT INPUT MOUSE CONTROL
|
||||
|
||||
============================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
========================
|
||||
IN_InitDirectInput
|
||||
========================
|
||||
*/
|
||||
|
||||
void IN_InitDirectInput( void ) {
|
||||
HRESULT hr;
|
||||
|
||||
common->Printf( "Initializing DirectInput...\n" );
|
||||
|
||||
if ( win32.g_pdi != NULL ) {
|
||||
win32.g_pdi->Release(); // if the previous window was destroyed we need to do this
|
||||
win32.g_pdi = NULL;
|
||||
}
|
||||
|
||||
// Register with the DirectInput subsystem and get a pointer
|
||||
// to a IDirectInput interface we can use.
|
||||
// Create the base DirectInput object
|
||||
if ( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&win32.g_pdi, NULL ) ) ) {
|
||||
common->Printf ("DirectInputCreate failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
IN_InitDIMouse
|
||||
========================
|
||||
*/
|
||||
bool IN_InitDIMouse( void ) {
|
||||
HRESULT hr;
|
||||
|
||||
if ( win32.g_pdi == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// obtain an interface to the system mouse device.
|
||||
hr = win32.g_pdi->CreateDevice( GUID_SysMouse, &win32.g_pMouse, NULL);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
common->Printf ("mouse: Couldn't open DI mouse device\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the data format to "mouse format" - a predefined data format
|
||||
//
|
||||
// A data format specifies which controls on a device we
|
||||
// are interested in, and how they should be reported.
|
||||
//
|
||||
// This tells DirectInput that we will be passing a
|
||||
// DIMOUSESTATE2 structure to IDirectInputDevice::GetDeviceState.
|
||||
if( FAILED( hr = win32.g_pMouse->SetDataFormat( &c_dfDIMouse2 ) ) ) {
|
||||
common->Printf ("mouse: Couldn't set DI mouse format\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// set the cooperativity level.
|
||||
hr = win32.g_pMouse->SetCooperativeLevel( win32.hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
common->Printf ("mouse: Couldn't set DI coop level\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// IMPORTANT STEP TO USE BUFFERED DEVICE DATA!
|
||||
//
|
||||
// DirectInput uses unbuffered I/O (buffer size = 0) by default.
|
||||
// If you want to read buffered data, you need to set a nonzero
|
||||
// buffer size.
|
||||
//
|
||||
// Set the buffer size to SAMPLE_BUFFER_SIZE (defined above) elements.
|
||||
//
|
||||
// The buffer size is a DWORD property associated with the device.
|
||||
DIPROPDWORD dipdw;
|
||||
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
|
||||
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
dipdw.diph.dwObj = 0;
|
||||
dipdw.diph.dwHow = DIPH_DEVICE;
|
||||
dipdw.dwData = DINPUT_BUFFERSIZE; // Arbitary buffer size
|
||||
|
||||
if( FAILED( hr = win32.g_pMouse->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph ) ) ) {
|
||||
common->Printf ("mouse: Couldn't set DI buffersize\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
IN_ActivateMouse();
|
||||
|
||||
// clear any pending samples
|
||||
Sys_PollMouseInputEvents();
|
||||
|
||||
common->Printf( "mouse: DirectInput initialized.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==========================
|
||||
IN_ActivateMouse
|
||||
==========================
|
||||
*/
|
||||
void IN_ActivateMouse( void ) {
|
||||
int i;
|
||||
HRESULT hr;
|
||||
|
||||
if ( !win32.in_mouse.GetBool() || win32.mouseGrabbed || !win32.g_pMouse ) {
|
||||
return;
|
||||
}
|
||||
|
||||
win32.mouseGrabbed = true;
|
||||
for ( i = 0; i < 10; i++ ) {
|
||||
if ( ::ShowCursor( false ) < 0 ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// we may fail to reacquire if the window has been recreated
|
||||
hr = win32.g_pMouse->Acquire();
|
||||
if (FAILED(hr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// set the cooperativity level.
|
||||
hr = win32.g_pMouse->SetCooperativeLevel( win32.hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
|
||||
}
|
||||
|
||||
/*
|
||||
==========================
|
||||
IN_DeactivateMouse
|
||||
==========================
|
||||
*/
|
||||
void IN_DeactivateMouse( void ) {
|
||||
int i;
|
||||
|
||||
if (!win32.g_pMouse || !win32.mouseGrabbed ) {
|
||||
return;
|
||||
}
|
||||
|
||||
win32.g_pMouse->Unacquire();
|
||||
|
||||
for ( i = 0; i < 10; i++ ) {
|
||||
if ( ::ShowCursor( true ) >= 0 ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
win32.mouseGrabbed = false;
|
||||
}
|
||||
|
||||
/*
|
||||
==========================
|
||||
IN_DeactivateMouseIfWindowed
|
||||
==========================
|
||||
*/
|
||||
void IN_DeactivateMouseIfWindowed( void ) {
|
||||
if ( !win32.cdsFullscreen ) {
|
||||
IN_DeactivateMouse();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
============================================================
|
||||
|
||||
MOUSE CONTROL
|
||||
|
||||
============================================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
===========
|
||||
Sys_ShutdownInput
|
||||
===========
|
||||
*/
|
||||
void Sys_ShutdownInput( void ) {
|
||||
IN_DeactivateMouse();
|
||||
IN_DeactivateKeyboard();
|
||||
if ( win32.g_pKeyboard ) {
|
||||
win32.g_pKeyboard->Release();
|
||||
win32.g_pKeyboard = NULL;
|
||||
}
|
||||
|
||||
if ( win32.g_pMouse ) {
|
||||
win32.g_pMouse->Release();
|
||||
win32.g_pMouse = NULL;
|
||||
}
|
||||
|
||||
if ( win32.g_pdi ) {
|
||||
win32.g_pdi->Release();
|
||||
win32.g_pdi = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
===========
|
||||
Sys_InitInput
|
||||
===========
|
||||
*/
|
||||
void Sys_InitInput( void ) {
|
||||
common->Printf ("\n------- Input Initialization -------\n");
|
||||
IN_InitDirectInput();
|
||||
if ( win32.in_mouse.GetBool() ) {
|
||||
IN_InitDIMouse();
|
||||
// don't grab the mouse on initialization
|
||||
Sys_GrabMouseCursor( false );
|
||||
} else {
|
||||
common->Printf ("Mouse control not active.\n");
|
||||
}
|
||||
IN_StartupKeyboard();
|
||||
common->Printf ("------------------------------------\n");
|
||||
win32.in_mouse.ClearModified();
|
||||
}
|
||||
|
||||
/*
|
||||
===========
|
||||
Sys_InitScanTable
|
||||
|
@ -830,301 +359,3 @@ int Win_MapKey (int key)
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
Sys_GetConsoleKey
|
||||
===============
|
||||
*/
|
||||
unsigned char Sys_GetConsoleKey( bool shifted ) {
|
||||
return keyScanTable[41 + ( shifted ? 128 : 0 )];
|
||||
}
|
||||
|
||||
/*
|
||||
==================
|
||||
IN_Frame
|
||||
|
||||
Called every frame, even if not generating commands
|
||||
==================
|
||||
*/
|
||||
void IN_Frame( void ) {
|
||||
bool shouldGrab = true;
|
||||
|
||||
if ( !win32.in_mouse.GetBool() ) {
|
||||
shouldGrab = false;
|
||||
}
|
||||
// if fullscreen, we always want the mouse
|
||||
if ( !win32.cdsFullscreen ) {
|
||||
if ( win32.mouseReleased ) {
|
||||
shouldGrab = false;
|
||||
}
|
||||
if ( win32.movingWindow ) {
|
||||
shouldGrab = false;
|
||||
}
|
||||
if ( !win32.activeApp ) {
|
||||
shouldGrab = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( shouldGrab != win32.mouseGrabbed ) {
|
||||
if ( win32.mouseGrabbed ) {
|
||||
IN_DeactivateMouse();
|
||||
} else {
|
||||
IN_ActivateMouse();
|
||||
|
||||
#if 0 // if we can't reacquire, try reinitializing
|
||||
if ( !IN_InitDIMouse() ) {
|
||||
win32.in_mouse.SetBool( false );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Sys_GrabMouseCursor( bool grabIt ) {
|
||||
#ifndef ID_DEDICATED
|
||||
win32.mouseReleased = !grabIt;
|
||||
if ( !grabIt ) {
|
||||
// release it right now
|
||||
IN_Frame();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
|
||||
static DIDEVICEOBJECTDATA polled_didod[ DINPUT_BUFFERSIZE ]; // Receives buffered data
|
||||
|
||||
static int diFetch;
|
||||
static byte toggleFetch[2][ 256 ];
|
||||
|
||||
|
||||
#if 1
|
||||
// I tried doing the full-state get to address a keyboard problem on one system,
|
||||
// but it didn't make any difference
|
||||
|
||||
/*
|
||||
====================
|
||||
Sys_PollKeyboardInputEvents
|
||||
====================
|
||||
*/
|
||||
int Sys_PollKeyboardInputEvents( void ) {
|
||||
DWORD dwElements;
|
||||
HRESULT hr;
|
||||
|
||||
if( win32.g_pKeyboard == NULL ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
dwElements = DINPUT_BUFFERSIZE;
|
||||
hr = win32.g_pKeyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA),
|
||||
polled_didod, &dwElements, 0 );
|
||||
if( hr != DI_OK )
|
||||
{
|
||||
// We got an error or we got DI_BUFFEROVERFLOW.
|
||||
//
|
||||
// Either way, it means that continuous contact with the
|
||||
// device has been lost, either due to an external
|
||||
// interruption, or because the buffer overflowed
|
||||
// and some events were lost.
|
||||
hr = win32.g_pKeyboard->Acquire();
|
||||
|
||||
|
||||
|
||||
// nuke the garbage
|
||||
if (!FAILED(hr)) {
|
||||
//Bug 951: The following command really clears the garbage input.
|
||||
//The original will still process keys in the buffer and was causing
|
||||
//some problems.
|
||||
win32.g_pKeyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), NULL, &dwElements, 0 );
|
||||
dwElements = 0;
|
||||
}
|
||||
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
|
||||
// may occur when the app is minimized or in the process of
|
||||
// switching, so just try again later
|
||||
}
|
||||
|
||||
if( FAILED(hr) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return dwElements;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
====================
|
||||
Sys_PollKeyboardInputEvents
|
||||
|
||||
Fake events by getting the entire device state
|
||||
and checking transitions
|
||||
====================
|
||||
*/
|
||||
int Sys_PollKeyboardInputEvents( void ) {
|
||||
HRESULT hr;
|
||||
|
||||
if( win32.g_pKeyboard == NULL ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
hr = win32.g_pKeyboard->GetDeviceState( sizeof( toggleFetch[ diFetch ] ), toggleFetch[ diFetch ] );
|
||||
if( hr != DI_OK )
|
||||
{
|
||||
// We got an error or we got DI_BUFFEROVERFLOW.
|
||||
//
|
||||
// Either way, it means that continuous contact with the
|
||||
// device has been lost, either due to an external
|
||||
// interruption, or because the buffer overflowed
|
||||
// and some events were lost.
|
||||
hr = win32.g_pKeyboard->Acquire();
|
||||
|
||||
// nuke the garbage
|
||||
if (!FAILED(hr)) {
|
||||
hr = win32.g_pKeyboard->GetDeviceState( sizeof( toggleFetch[ diFetch ] ), toggleFetch[ diFetch ] );
|
||||
}
|
||||
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
|
||||
// may occur when the app is minimized or in the process of
|
||||
// switching, so just try again later
|
||||
}
|
||||
|
||||
if( FAILED(hr) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// build faked events
|
||||
int numChanges = 0;
|
||||
|
||||
for ( int i = 0 ; i < 256 ; i++ ) {
|
||||
if ( toggleFetch[0][i] != toggleFetch[1][i] ) {
|
||||
polled_didod[ numChanges ].dwOfs = i;
|
||||
polled_didod[ numChanges ].dwData = toggleFetch[ diFetch ][i] ? 0x80 : 0;
|
||||
numChanges++;
|
||||
}
|
||||
}
|
||||
|
||||
diFetch ^= 1;
|
||||
|
||||
return numChanges;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
====================
|
||||
Sys_PollKeyboardInputEvents
|
||||
====================
|
||||
*/
|
||||
int Sys_ReturnKeyboardInputEvent( const int n, int &ch, bool &state ) {
|
||||
ch = IN_DIMapKey( polled_didod[ n ].dwOfs );
|
||||
state = (polled_didod[ n ].dwData & 0x80) == 0x80;
|
||||
if ( ch == K_PRINT_SCR || ch == K_CTRL || ch == K_ALT || ch == K_RIGHT_ALT ) {
|
||||
// for windows, add a keydown event for print screen here, since
|
||||
// windows doesn't send keydown events to the WndProc for this key.
|
||||
// ctrl and alt are handled here to get around windows sending ctrl and
|
||||
// alt messages when the right-alt is pressed on non-US 102 keyboards.
|
||||
Sys_QueEvent( GetTickCount(), SE_KEY, ch, state, 0, NULL );
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
void Sys_EndKeyboardInputEvents( void ) {
|
||||
}
|
||||
|
||||
void Sys_QueMouseEvents( int dwElements ) {
|
||||
int i, value;
|
||||
|
||||
for( i = 0; i < dwElements; i++ ) {
|
||||
int diaction = polled_didod[i].dwOfs;
|
||||
|
||||
if ( diaction >= DIMOFS_BUTTON0 && diaction <= DIMOFS_BUTTON7 ) {
|
||||
value = (polled_didod[i].dwData & 0x80) == 0x80;
|
||||
Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, K_MOUSE1 + ( diaction - DIMOFS_BUTTON0 ), value, 0, NULL );
|
||||
} else if (diaction == DIMOFS_X) {
|
||||
value = polled_didod[i].dwData;
|
||||
Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_MOUSE, value, 0, 0, NULL );
|
||||
} else if (diaction == DIMOFS_Y) {
|
||||
value = polled_didod[i].dwData;
|
||||
Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_MOUSE, 0, value, 0, NULL );
|
||||
} else if (diaction == DIMOFS_Z) {
|
||||
value = ( (int) polled_didod[i].dwData ) / WHEEL_DELTA;
|
||||
int key = value < 0 ? K_MWHEELDOWN : K_MWHEELUP;
|
||||
value = abs( value );
|
||||
while( value-- > 0 ) {
|
||||
Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, key, true, 0, NULL );
|
||||
Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, key, false, 0, NULL );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
|
||||
int Sys_PollMouseInputEvents( void ) {
|
||||
DWORD dwElements;
|
||||
HRESULT hr;
|
||||
|
||||
if ( !win32.g_pMouse || !win32.mouseGrabbed ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
dwElements = DINPUT_BUFFERSIZE;
|
||||
hr = win32.g_pMouse->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), polled_didod, &dwElements, 0 );
|
||||
|
||||
if( hr != DI_OK ) {
|
||||
hr = win32.g_pMouse->Acquire();
|
||||
// clear the garbage
|
||||
if (!FAILED(hr)) {
|
||||
win32.g_pMouse->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), polled_didod, &dwElements, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
if( FAILED(hr) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Sys_QueMouseEvents( dwElements );
|
||||
|
||||
return dwElements;
|
||||
}
|
||||
|
||||
int Sys_ReturnMouseInputEvent( const int n, int &action, int &value ) {
|
||||
int diaction = polled_didod[n].dwOfs;
|
||||
|
||||
if ( diaction >= DIMOFS_BUTTON0 && diaction <= DIMOFS_BUTTON7 ) {
|
||||
value = (polled_didod[n].dwData & 0x80) == 0x80;
|
||||
action = M_ACTION1 + ( diaction - DIMOFS_BUTTON0 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( diaction == DIMOFS_X) {
|
||||
value = polled_didod[n].dwData;
|
||||
action = M_DELTAX;
|
||||
return 1;
|
||||
}
|
||||
if ( diaction == DIMOFS_Y) {
|
||||
value = polled_didod[n].dwData;
|
||||
action = M_DELTAY;
|
||||
return 1;
|
||||
}
|
||||
if ( diaction == DIMOFS_Z) {
|
||||
// mouse wheel actions are impulses, without a specific up / down
|
||||
value = ( (int) polled_didod[n].dwData ) / WHEEL_DELTA;
|
||||
action = M_DELTAZ;
|
||||
// a value of zero here should never happen
|
||||
if ( value == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Sys_EndMouseInputEvents( void ) { }
|
||||
|
||||
unsigned char Sys_MapCharForKey( int key ) {
|
||||
return (unsigned char)key;
|
||||
}
|
||||
|
|
|
@ -38,9 +38,7 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include <winsock2.h>
|
||||
#include <mmsystem.h>
|
||||
#include <mmreg.h>
|
||||
|
||||
#define DIRECTINPUT_VERSION 0x0800 // was 0x0700 with the old mssdk
|
||||
#include <dinput.h>
|
||||
#include <objbase.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
|
@ -48,18 +46,10 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include "renderer/wglext.h" // windows OpenGL extensions
|
||||
#include "sys/sys_public.h"
|
||||
|
||||
// WGL_EXT_swap_interval
|
||||
extern PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
|
||||
|
||||
// WGL_ARB_pixel_format
|
||||
extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
|
||||
|
||||
#define MAX_OSPATH 256
|
||||
|
||||
#define WINDOW_STYLE (WS_OVERLAPPED|WS_BORDER|WS_CAPTION|WS_VISIBLE | WS_THICKFRAME)
|
||||
|
||||
void Sys_QueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr );
|
||||
|
||||
void Sys_CreateConsole( void );
|
||||
void Sys_DestroyConsole( void );
|
||||
|
||||
|
@ -70,24 +60,6 @@ void Win_SetErrorText( const char *text );
|
|||
const unsigned char *Win_GetScanTable( void );
|
||||
int Win_MapKey (int key);
|
||||
|
||||
|
||||
// Input subsystem
|
||||
|
||||
void IN_Init (void);
|
||||
void IN_Shutdown (void);
|
||||
// add additional non keyboard / non mouse movement on top of the keyboard move cmd
|
||||
|
||||
void IN_DeactivateMouseIfWindowed( void );
|
||||
void IN_DeactivateMouse( void );
|
||||
void IN_ActivateMouse( void );
|
||||
|
||||
void IN_Frame( void );
|
||||
|
||||
int IN_DIMapKey( int key );
|
||||
|
||||
void DisableTaskKeys( BOOL bDisable, BOOL bBeep, BOOL bTaskMgr );
|
||||
|
||||
|
||||
// window procedure
|
||||
LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
|
@ -97,56 +69,23 @@ struct Win32Vars_t {
|
|||
HWND hWnd;
|
||||
HINSTANCE hInstance;
|
||||
|
||||
bool activeApp; // changed with WM_ACTIVATE messages
|
||||
bool mouseReleased; // when the game has the console down or is doing a long operation
|
||||
bool movingWindow; // inhibit mouse grab when dragging the window
|
||||
bool mouseGrabbed; // current state of grab and hide
|
||||
|
||||
OSVERSIONINFOEX osversion;
|
||||
|
||||
// when we get a windows message, we store the time off so keyboard processing
|
||||
// can know the exact time of an event (not really needed now that we use async direct input)
|
||||
int sysMsgTime;
|
||||
|
||||
bool windowClassRegistered;
|
||||
|
||||
WNDPROC wndproc;
|
||||
|
||||
HDC hDC; // handle to device context
|
||||
HGLRC hGLRC; // handle to GL rendering context
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
int pixelformat;
|
||||
|
||||
int desktopBitsPixel;
|
||||
int desktopWidth, desktopHeight;
|
||||
|
||||
bool cdsFullscreen;
|
||||
|
||||
unsigned short oldHardwareGamma[3][256];
|
||||
// desktop gamma is saved here for restoration at exit
|
||||
|
||||
static idCVar sys_arch;
|
||||
static idCVar in_mouse;
|
||||
static idCVar win_allowAltTab;
|
||||
static idCVar win_notaskkeys;
|
||||
static idCVar win_username;
|
||||
static idCVar win_xpos; // archived X coordinate of window position
|
||||
static idCVar win_ypos; // archived Y coordinate of window position
|
||||
static idCVar win_outputDebugString;
|
||||
static idCVar win_outputEditString;
|
||||
static idCVar win_viewlog;
|
||||
static idCVar win_timerUpdate;
|
||||
static idCVar win_allowMultipleInstances;
|
||||
|
||||
HINSTANCE hInstDI; // direct input
|
||||
|
||||
LPDIRECTINPUT8 g_pdi;
|
||||
LPDIRECTINPUTDEVICE8 g_pMouse;
|
||||
LPDIRECTINPUTDEVICE8 g_pKeyboard;
|
||||
|
||||
int wglErrors;
|
||||
// SMP acceleration vars
|
||||
|
||||
};
|
||||
|
||||
extern Win32Vars_t win32;
|
||||
|
|
|
@ -53,16 +53,10 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include <SDL_main.h>
|
||||
|
||||
idCVar Win32Vars_t::sys_arch( "sys_arch", "", CVAR_SYSTEM | CVAR_INIT, "" );
|
||||
idCVar Win32Vars_t::in_mouse( "in_mouse", "1", CVAR_SYSTEM | CVAR_BOOL, "enable mouse input" );
|
||||
idCVar Win32Vars_t::win_allowAltTab( "win_allowAltTab", "0", CVAR_SYSTEM | CVAR_BOOL, "allow Alt-Tab when fullscreen" );
|
||||
idCVar Win32Vars_t::win_notaskkeys( "win_notaskkeys", "0", CVAR_SYSTEM | CVAR_INTEGER, "disable windows task keys" );
|
||||
idCVar Win32Vars_t::win_username( "win_username", "", CVAR_SYSTEM | CVAR_INIT, "windows user name" );
|
||||
idCVar Win32Vars_t::win_xpos( "win_xpos", "3", CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_INTEGER, "horizontal position of window" );
|
||||
idCVar Win32Vars_t::win_ypos( "win_ypos", "22", CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_INTEGER, "vertical position of window" );
|
||||
idCVar Win32Vars_t::win_outputDebugString( "win_outputDebugString", "0", CVAR_SYSTEM | CVAR_BOOL, "" );
|
||||
idCVar Win32Vars_t::win_outputEditString( "win_outputEditString", "1", CVAR_SYSTEM | CVAR_BOOL, "" );
|
||||
idCVar Win32Vars_t::win_viewlog( "win_viewlog", "0", CVAR_SYSTEM | CVAR_INTEGER, "" );
|
||||
idCVar Win32Vars_t::win_timerUpdate( "win_timerUpdate", "0", CVAR_SYSTEM | CVAR_BOOL, "allows the game to be updated while dragging the window" );
|
||||
idCVar Win32Vars_t::win_allowMultipleInstances( "win_allowMultipleInstances", "0", CVAR_SYSTEM | CVAR_BOOL, "allow multiple instances running concurrently" );
|
||||
|
||||
Win32Vars_t win32;
|
||||
|
@ -581,165 +575,6 @@ void Sys_DLL_Unload( uintptr_t dllHandle ) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
EVENT LOOP
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#define MAX_QUED_EVENTS 256
|
||||
#define MASK_QUED_EVENTS ( MAX_QUED_EVENTS - 1 )
|
||||
|
||||
sysEvent_t eventQue[MAX_QUED_EVENTS];
|
||||
int eventHead = 0;
|
||||
int eventTail = 0;
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_QueEvent
|
||||
|
||||
Ptr should either be null, or point to a block of data that can
|
||||
be freed by the game later.
|
||||
================
|
||||
*/
|
||||
void Sys_QueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr ) {
|
||||
sysEvent_t *ev;
|
||||
|
||||
ev = &eventQue[ eventHead & MASK_QUED_EVENTS ];
|
||||
|
||||
if ( eventHead - eventTail >= MAX_QUED_EVENTS ) {
|
||||
common->Printf("Sys_QueEvent: overflow\n");
|
||||
// we are discarding an event, but don't leak memory
|
||||
if ( ev->evPtr ) {
|
||||
Mem_Free( ev->evPtr );
|
||||
}
|
||||
eventTail++;
|
||||
}
|
||||
|
||||
eventHead++;
|
||||
|
||||
ev->evType = type;
|
||||
ev->evValue = value;
|
||||
ev->evValue2 = value2;
|
||||
ev->evPtrLength = ptrLength;
|
||||
ev->evPtr = ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
Sys_PumpEvents
|
||||
|
||||
This allows windows to be moved during renderbump
|
||||
=============
|
||||
*/
|
||||
void Sys_PumpEvents( void ) {
|
||||
MSG msg;
|
||||
|
||||
// pump the message loop
|
||||
while( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) {
|
||||
if ( !GetMessage( &msg, NULL, 0, 0 ) ) {
|
||||
common->Quit();
|
||||
}
|
||||
|
||||
// save the msg time, because wndprocs don't have access to the timestamp
|
||||
if ( win32.sysMsgTime && win32.sysMsgTime > (int)msg.time ) {
|
||||
// don't ever let the event times run backwards
|
||||
// common->Printf( "Sys_PumpEvents: win32.sysMsgTime (%i) > msg.time (%i)\n", win32.sysMsgTime, msg.time );
|
||||
} else {
|
||||
win32.sysMsgTime = msg.time;
|
||||
}
|
||||
|
||||
#ifdef ID_ALLOW_TOOLS
|
||||
if ( GUIEditorHandleMessage ( &msg ) ) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
TranslateMessage (&msg);
|
||||
DispatchMessage (&msg);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_GenerateEvents
|
||||
================
|
||||
*/
|
||||
void Sys_GenerateEvents( void ) {
|
||||
static int entered = false;
|
||||
char *s;
|
||||
|
||||
if ( entered ) {
|
||||
return;
|
||||
}
|
||||
entered = true;
|
||||
|
||||
// pump the message loop
|
||||
Sys_PumpEvents();
|
||||
|
||||
// make sure mouse and joystick are only called once a frame
|
||||
IN_Frame();
|
||||
|
||||
// check for console commands
|
||||
s = Sys_ConsoleInput();
|
||||
if ( s ) {
|
||||
char *b;
|
||||
int len;
|
||||
|
||||
len = strlen( s ) + 1;
|
||||
b = (char *)Mem_Alloc( len );
|
||||
strcpy( b, s );
|
||||
Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b );
|
||||
}
|
||||
|
||||
entered = false;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_ClearEvents
|
||||
================
|
||||
*/
|
||||
void Sys_ClearEvents( void ) {
|
||||
eventHead = eventTail = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_GetEvent
|
||||
================
|
||||
*/
|
||||
sysEvent_t Sys_GetEvent( void ) {
|
||||
sysEvent_t ev;
|
||||
|
||||
// return if we have data
|
||||
if ( eventHead > eventTail ) {
|
||||
eventTail++;
|
||||
return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ];
|
||||
}
|
||||
|
||||
// return the empty event
|
||||
memset( &ev, 0, sizeof( ev ) );
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
//================================================================
|
||||
|
||||
/*
|
||||
=================
|
||||
Sys_In_Restart_f
|
||||
|
||||
Restart the input subsystem
|
||||
=================
|
||||
*/
|
||||
void Sys_In_Restart_f( const idCmdArgs &args ) {
|
||||
Sys_ShutdownInput();
|
||||
Sys_InitInput();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_AlreadyRunning
|
||||
|
@ -780,7 +615,6 @@ void Sys_Init( void ) {
|
|||
// get WM_TIMER messages pumped every millisecond
|
||||
// SetTimer( NULL, 0, 100, NULL );
|
||||
|
||||
cmdSystem->AddCommand( "in_restart", Sys_In_Restart_f, CMD_FL_SYSTEM, "restarts the input system" );
|
||||
#ifdef DEBUG
|
||||
cmdSystem->AddCommand( "createResourceIDs", CreateResourceIDs_f, CMD_FL_TOOL, "assigns resource IDs in _resouce.h files" );
|
||||
#endif
|
||||
|
@ -957,12 +791,6 @@ int main(int argc, char *argv[]) {
|
|||
common->Printf( Sys_FPU_GetState() );
|
||||
#endif
|
||||
|
||||
#ifndef ID_DEDICATED
|
||||
if ( win32.win_notaskkeys.GetInteger() ) {
|
||||
DisableTaskKeys( TRUE, FALSE, /*( win32.win_notaskkeys.GetInteger() == 2 )*/ FALSE );
|
||||
}
|
||||
#endif
|
||||
|
||||
// hide or show the early console as necessary
|
||||
if ( win32.win_viewlog.GetInteger() || com_skipRenderer.GetBool() || idAsyncNetwork::serverDedicated.GetInteger() ) {
|
||||
Sys_ShowConsole( 1, true );
|
||||
|
|
|
@ -39,14 +39,6 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include <io.h>
|
||||
#include <conio.h>
|
||||
|
||||
#if !defined(ID_DEDICATED) && !defined(__MINGW32__)
|
||||
#include <comdef.h>
|
||||
#include <comutil.h>
|
||||
#include <wbemidl.h>
|
||||
|
||||
#pragma comment (lib, "wbemuuid.lib")
|
||||
#endif
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_GetSystemRam
|
||||
|
@ -84,68 +76,6 @@ int Sys_GetDriveFreeSpace( const char *path ) {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_GetVideoRam
|
||||
returns in megabytes
|
||||
================
|
||||
*/
|
||||
int Sys_GetVideoRam( void ) {
|
||||
#if defined(ID_DEDICATED)
|
||||
return 0;
|
||||
#elif !defined(_MFC_VER)
|
||||
// no <atlbase.h> (MinGW, VS Express etc.), so assume the min. req. 64Mb
|
||||
return 64;
|
||||
#else
|
||||
unsigned int retSize = 64;
|
||||
|
||||
CComPtr<IWbemLocator> spLoc = NULL;
|
||||
HRESULT hr = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_SERVER, IID_IWbemLocator, ( LPVOID * ) &spLoc );
|
||||
if ( hr != S_OK || spLoc == NULL ) {
|
||||
return retSize;
|
||||
}
|
||||
|
||||
CComBSTR bstrNamespace( _T( "\\\\.\\root\\CIMV2" ) );
|
||||
CComPtr<IWbemServices> spServices;
|
||||
|
||||
// Connect to CIM
|
||||
hr = spLoc->ConnectServer( bstrNamespace, NULL, NULL, 0, NULL, 0, 0, &spServices );
|
||||
if ( hr != WBEM_S_NO_ERROR ) {
|
||||
return retSize;
|
||||
}
|
||||
|
||||
// Switch the security level to IMPERSONATE so that provider will grant access to system-level objects.
|
||||
hr = CoSetProxyBlanket( spServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
|
||||
if ( hr != S_OK ) {
|
||||
return retSize;
|
||||
}
|
||||
|
||||
// Get the vid controller
|
||||
CComPtr<IEnumWbemClassObject> spEnumInst = NULL;
|
||||
hr = spServices->CreateInstanceEnum( CComBSTR( "Win32_VideoController" ), WBEM_FLAG_SHALLOW, NULL, &spEnumInst );
|
||||
if ( hr != WBEM_S_NO_ERROR || spEnumInst == NULL ) {
|
||||
return retSize;
|
||||
}
|
||||
|
||||
ULONG uNumOfInstances = 0;
|
||||
CComPtr<IWbemClassObject> spInstance = NULL;
|
||||
hr = spEnumInst->Next( 10000, 1, &spInstance, &uNumOfInstances );
|
||||
|
||||
if ( hr == S_OK && spInstance ) {
|
||||
// Get properties from the object
|
||||
CComVariant varSize;
|
||||
hr = spInstance->Get( CComBSTR( _T( "AdapterRAM" ) ), 0, &varSize, 0, 0 );
|
||||
if ( hr == S_OK ) {
|
||||
retSize = varSize.intVal / ( 1024 * 1024 );
|
||||
if ( retSize == 0 ) {
|
||||
retSize = 64;
|
||||
}
|
||||
}
|
||||
}
|
||||
return retSize;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_GetCurrentMemoryStatus
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 GPL Source Code
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
|
||||
|
||||
Doom 3 Source Code 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 Source Code 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 Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||
|
||||
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#include "sys/platform.h"
|
||||
|
||||
#include "sys/win32/win_local.h"
|
||||
|
||||
//
|
||||
// This file implements the low-level keyboard hook that traps the task keys.
|
||||
//
|
||||
|
||||
// Magic registry key/value for "Remove Task Manager" policy.
|
||||
LPCTSTR KEY_DisableTaskMgr = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
|
||||
LPCTSTR VAL_DisableTaskMgr = "DisableTaskMgr";
|
||||
|
||||
// The section is SHARED among all instances of this DLL.
|
||||
// A low-level keyboard hook is always a system-wide hook.
|
||||
#pragma data_seg (".mydata")
|
||||
HHOOK g_hHookKbdLL = NULL; // hook handle
|
||||
BOOL g_bBeep = FALSE; // beep on illegal key
|
||||
#pragma data_seg ()
|
||||
#pragma comment(linker, "/SECTION:.mydata,RWS") // tell linker: make it shared
|
||||
|
||||
/*
|
||||
================
|
||||
MyTaskKeyHookLL
|
||||
|
||||
Low-level keyboard hook:
|
||||
Trap task-switching keys by returning without passing along.
|
||||
================
|
||||
*/
|
||||
LRESULT CALLBACK MyTaskKeyHookLL( int nCode, WPARAM wp, LPARAM lp ) {
|
||||
KBDLLHOOKSTRUCT *pkh = (KBDLLHOOKSTRUCT *) lp;
|
||||
|
||||
if ( nCode == HC_ACTION ) {
|
||||
BOOL bCtrlKeyDown = GetAsyncKeyState( VK_CONTROL)>>((sizeof(SHORT) * 8) - 1 );
|
||||
|
||||
if ( ( pkh->vkCode == VK_ESCAPE && bCtrlKeyDown ) // Ctrl+Esc
|
||||
|| ( pkh->vkCode == VK_TAB && pkh->flags & LLKHF_ALTDOWN ) // Alt+TAB
|
||||
|| ( pkh->vkCode == VK_ESCAPE && pkh->flags & LLKHF_ALTDOWN ) // Alt+Esc
|
||||
|| ( pkh->vkCode == VK_LWIN || pkh->vkCode == VK_RWIN ) // Start Menu
|
||||
) {
|
||||
|
||||
if ( g_bBeep && ( wp == WM_SYSKEYDOWN || wp == WM_KEYDOWN ) ) {
|
||||
MessageBeep( 0 ); // beep on downstroke if requested
|
||||
}
|
||||
return 1; // return without processing the key strokes
|
||||
}
|
||||
}
|
||||
return CallNextHookEx( g_hHookKbdLL, nCode, wp, lp );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
AreTaskKeysDisabled
|
||||
|
||||
Are task keys disabled--ie, is hook installed?
|
||||
Note: This assumes there's no other hook that does the same thing!
|
||||
================
|
||||
*/
|
||||
BOOL AreTaskKeysDisabled() {
|
||||
return g_hHookKbdLL != NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
IsTaskMgrDisabled
|
||||
================
|
||||
*/
|
||||
BOOL IsTaskMgrDisabled() {
|
||||
HKEY hk;
|
||||
|
||||
if ( RegOpenKey( HKEY_CURRENT_USER, KEY_DisableTaskMgr, &hk ) != ERROR_SUCCESS ) {
|
||||
return FALSE; // no key ==> not disabled
|
||||
}
|
||||
|
||||
DWORD val = 0;
|
||||
DWORD len = 4;
|
||||
return RegQueryValueEx( hk, VAL_DisableTaskMgr, NULL, NULL, (BYTE*)&val, &len ) == ERROR_SUCCESS && val == 1;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DisableTaskKeys
|
||||
================
|
||||
*/
|
||||
void DisableTaskKeys( BOOL bDisable, BOOL bBeep, BOOL bTaskMgr ) {
|
||||
|
||||
// task keys (Ctrl+Esc, Alt-Tab, etc.)
|
||||
if ( bDisable ) {
|
||||
if ( !g_hHookKbdLL ) {
|
||||
g_hHookKbdLL = SetWindowsHookEx( WH_KEYBOARD_LL, MyTaskKeyHookLL, win32.hInstance, 0 );
|
||||
}
|
||||
} else if ( g_hHookKbdLL != NULL ) {
|
||||
UnhookWindowsHookEx( g_hHookKbdLL );
|
||||
g_hHookKbdLL = NULL;
|
||||
}
|
||||
g_bBeep = bBeep;
|
||||
|
||||
// task manager (Ctrl+Alt+Del)
|
||||
if ( bTaskMgr ) {
|
||||
HKEY hk;
|
||||
if ( RegOpenKey( HKEY_CURRENT_USER, KEY_DisableTaskMgr, &hk ) != ERROR_SUCCESS ) {
|
||||
RegCreateKey( HKEY_CURRENT_USER, KEY_DisableTaskMgr, &hk );
|
||||
}
|
||||
if ( bDisable ) {
|
||||
// disable TM: set policy = 1
|
||||
DWORD val = 1;
|
||||
RegSetValueEx( hk, VAL_DisableTaskMgr, NULL, REG_DWORD, (BYTE*)&val, sizeof(val) );
|
||||
} else {
|
||||
// enable TM: remove policy
|
||||
RegDeleteValue( hk,VAL_DisableTaskMgr );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,367 +0,0 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 GPL Source Code
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
|
||||
|
||||
Doom 3 Source Code 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 Source Code 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 Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||
|
||||
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#include "sys/platform.h"
|
||||
#include "framework/Session.h"
|
||||
#include "framework/KeyInput.h"
|
||||
#include "renderer/tr_local.h"
|
||||
|
||||
#include "sys/win32/win_local.h"
|
||||
|
||||
LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
|
||||
|
||||
static bool s_alttab_disabled;
|
||||
|
||||
static void WIN_DisableAltTab( void ) {
|
||||
if ( s_alttab_disabled || win32.win_allowAltTab.GetBool() ) {
|
||||
return;
|
||||
}
|
||||
if ( !idStr::Icmp( cvarSystem->GetCVarString( "sys_arch" ), "winnt" ) ) {
|
||||
RegisterHotKey( 0, 0, MOD_ALT, VK_TAB );
|
||||
} else {
|
||||
BOOL old;
|
||||
|
||||
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, &old, 0 );
|
||||
}
|
||||
s_alttab_disabled = true;
|
||||
}
|
||||
|
||||
static void WIN_EnableAltTab( void ) {
|
||||
if ( !s_alttab_disabled || win32.win_allowAltTab.GetBool() ) {
|
||||
return;
|
||||
}
|
||||
if ( !idStr::Icmp( cvarSystem->GetCVarString( "sys_arch" ), "winnt" ) ) {
|
||||
UnregisterHotKey( 0, 0 );
|
||||
} else {
|
||||
BOOL old;
|
||||
|
||||
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 0, &old, 0 );
|
||||
}
|
||||
|
||||
s_alttab_disabled = false;
|
||||
}
|
||||
|
||||
void WIN_Sizing(WORD side, RECT *rect)
|
||||
{
|
||||
if ( !glConfig.isInitialized || glConfig.vidHeight <= 0 || glConfig.vidWidth <= 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( idKeyInput::IsDown( K_CTRL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
int width = rect->right - rect->left;
|
||||
int height = rect->bottom - rect->top;
|
||||
|
||||
// Adjust width/height for window decoration
|
||||
RECT decoRect = { 0, 0, 0, 0 };
|
||||
AdjustWindowRect( &decoRect, WINDOW_STYLE|WS_SYSMENU, FALSE );
|
||||
int decoWidth = decoRect.right - decoRect.left;
|
||||
int decoHeight = decoRect.bottom - decoRect.top;
|
||||
|
||||
width -= decoWidth;
|
||||
height -= decoHeight;
|
||||
|
||||
// Clamp to a minimum size
|
||||
int minWidth = 160;
|
||||
int minHeight = minWidth * SCREEN_HEIGHT / SCREEN_WIDTH;
|
||||
|
||||
if ( width < minWidth ) {
|
||||
width = minWidth;
|
||||
}
|
||||
if ( height < minHeight ) {
|
||||
height = minHeight;
|
||||
}
|
||||
|
||||
// Set the new size
|
||||
switch ( side ) {
|
||||
case WMSZ_LEFT:
|
||||
rect->left = rect->right - width - decoWidth;
|
||||
rect->bottom = rect->top + ( width * SCREEN_HEIGHT / SCREEN_WIDTH ) + decoHeight;
|
||||
break;
|
||||
case WMSZ_RIGHT:
|
||||
rect->right = rect->left + width + decoWidth;
|
||||
rect->bottom = rect->top + ( width * SCREEN_HEIGHT / SCREEN_WIDTH ) + decoHeight;
|
||||
break;
|
||||
case WMSZ_BOTTOM:
|
||||
case WMSZ_BOTTOMRIGHT:
|
||||
rect->bottom = rect->top + height + decoHeight;
|
||||
rect->right = rect->left + ( height * SCREEN_WIDTH / SCREEN_HEIGHT ) + decoWidth;
|
||||
break;
|
||||
case WMSZ_TOP:
|
||||
case WMSZ_TOPRIGHT:
|
||||
rect->top = rect->bottom - height - decoHeight;
|
||||
rect->right = rect->left + ( height * SCREEN_WIDTH / SCREEN_HEIGHT ) + decoWidth;
|
||||
break;
|
||||
case WMSZ_BOTTOMLEFT:
|
||||
rect->bottom = rect->top + height + decoHeight;
|
||||
rect->left = rect->right - ( height * SCREEN_WIDTH / SCREEN_HEIGHT ) - decoWidth;
|
||||
break;
|
||||
case WMSZ_TOPLEFT:
|
||||
rect->top = rect->bottom - height - decoHeight;
|
||||
rect->left = rect->right - ( height * SCREEN_WIDTH / SCREEN_HEIGHT ) - decoWidth;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
||||
// Keep this in sync with the one in win_input.cpp
|
||||
// This one is used in the menu, the other one is used in game
|
||||
|
||||
static byte s_scantokey[128] =
|
||||
{
|
||||
// 0 1 2 3 4 5 6 7
|
||||
// 8 9 A B C D E F
|
||||
0, 27, '1', '2', '3', '4', '5', '6',
|
||||
'7', '8', '9', '0', '-', '=', K_BACKSPACE, 9, // 0
|
||||
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
|
||||
'o', 'p', '[', ']', K_ENTER,K_CTRL, 'a', 's', // 1
|
||||
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
|
||||
'\'', '`', K_SHIFT, '\\', 'z', 'x', 'c', 'v', // 2
|
||||
'b', 'n', 'm', ',', '.', '/', K_SHIFT, K_KP_STAR,
|
||||
K_ALT, ' ', K_CAPSLOCK,K_F1, K_F2, K_F3, K_F4, K_F5, // 3
|
||||
K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE, K_SCROLL, K_HOME,
|
||||
K_UPARROW, K_PGUP, K_KP_MINUS,K_LEFTARROW,K_KP_5, K_RIGHTARROW,K_KP_PLUS,K_END, // 4
|
||||
K_DOWNARROW,K_PGDN, K_INS, K_DEL, 0, 0, 0, K_F11,
|
||||
K_F12, 0, 0, K_LWIN, K_RWIN, K_MENU, 0, 0, // 5
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, // 6
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0 // 7
|
||||
};
|
||||
|
||||
static byte s_scantoshift[128] =
|
||||
{
|
||||
// 0 1 2 3 4 5 6 7
|
||||
// 8 9 A B C D E F
|
||||
0, 27, '!', '@', '#', '$', '%', '^',
|
||||
'&', '*', '(', ')', '_', '+', K_BACKSPACE, 9, // 0
|
||||
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
|
||||
'O', 'P', '{', '}', K_ENTER,K_CTRL, 'A', 'S', // 1
|
||||
'D', 'F', 'G', 'H', 'J', 'K', 'L', ':',
|
||||
'|' , '~', K_SHIFT, '\\', 'Z', 'X', 'C', 'V', // 2
|
||||
'B', 'N', 'M', '<', '>', '?', K_SHIFT, K_KP_STAR,
|
||||
K_ALT, ' ', K_CAPSLOCK,K_F1, K_F2, K_F3, K_F4, K_F5, // 3
|
||||
K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE, K_SCROLL, K_HOME,
|
||||
K_UPARROW, K_PGUP, K_KP_MINUS,K_LEFTARROW,K_KP_5, K_RIGHTARROW,K_KP_PLUS,K_END, // 4
|
||||
K_DOWNARROW,K_PGDN, K_INS, K_DEL, 0, 0, 0, K_F11,
|
||||
K_F12, 0, 0, K_LWIN, K_RWIN, K_MENU, 0, 0, // 5
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, // 6
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0 // 7
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
====================
|
||||
MainWndProc
|
||||
|
||||
main window procedure
|
||||
====================
|
||||
*/
|
||||
LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
|
||||
int key;
|
||||
switch( uMsg ) {
|
||||
case WM_WINDOWPOSCHANGED:
|
||||
if (glConfig.isInitialized) {
|
||||
RECT rect;
|
||||
if (::GetClientRect(win32.hWnd, &rect)) {
|
||||
glConfig.vidWidth = rect.right - rect.left;
|
||||
glConfig.vidHeight = rect.bottom - rect.top;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CREATE:
|
||||
|
||||
win32.hWnd = hWnd;
|
||||
|
||||
if ( win32.cdsFullscreen ) {
|
||||
WIN_DisableAltTab();
|
||||
} else {
|
||||
WIN_EnableAltTab();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
// let sound and input know about this?
|
||||
win32.hWnd = NULL;
|
||||
if ( win32.cdsFullscreen ) {
|
||||
WIN_EnableAltTab();
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CLOSE:
|
||||
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "quit" );
|
||||
break;
|
||||
|
||||
case WM_ACTIVATE:
|
||||
// if we got here because of an alt-tab or maximize,
|
||||
// we should activate immediately. If we are here because
|
||||
// the mouse was clicked on a title bar or drag control,
|
||||
// don't activate until the mouse button is released
|
||||
{
|
||||
int fActive, fMinimized;
|
||||
|
||||
fActive = LOWORD(wParam);
|
||||
fMinimized = (BOOL) HIWORD(wParam);
|
||||
|
||||
win32.activeApp = (fActive != WA_INACTIVE);
|
||||
if ( win32.activeApp ) {
|
||||
idKeyInput::ClearStates();
|
||||
com_editorActive = false;
|
||||
Sys_GrabMouseCursor( true );
|
||||
}
|
||||
|
||||
if ( fActive == WA_INACTIVE ) {
|
||||
win32.movingWindow = false;
|
||||
}
|
||||
|
||||
// start playing the game sound world
|
||||
session->SetPlayingSoundWorld();
|
||||
|
||||
// we do not actually grab or release the mouse here,
|
||||
// that will be done next time through the main loop
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_MOVE: {
|
||||
int xPos, yPos;
|
||||
RECT r;
|
||||
int style;
|
||||
|
||||
if (!win32.cdsFullscreen )
|
||||
{
|
||||
xPos = (short) LOWORD(lParam); // horizontal position
|
||||
yPos = (short) HIWORD(lParam); // vertical position
|
||||
|
||||
r.left = 0;
|
||||
r.top = 0;
|
||||
r.right = 1;
|
||||
r.bottom = 1;
|
||||
|
||||
style = GetWindowLong( hWnd, GWL_STYLE );
|
||||
AdjustWindowRect( &r, style, FALSE );
|
||||
|
||||
win32.win_xpos.SetInteger( xPos + r.left );
|
||||
win32.win_ypos.SetInteger( yPos + r.top );
|
||||
win32.win_xpos.ClearModified();
|
||||
win32.win_ypos.ClearModified();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_TIMER: {
|
||||
if ( win32.win_timerUpdate.GetBool() ) {
|
||||
common->Frame();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_SYSCOMMAND:
|
||||
if ( wParam == SC_SCREENSAVE || wParam == SC_KEYMENU ) {
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_SYSKEYDOWN:
|
||||
if ( wParam == 13 ) { // alt-enter toggles full-screen
|
||||
cvarSystem->SetCVarBool( "r_fullscreen", !renderSystem->IsFullScreen() );
|
||||
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "vid_restart\n" );
|
||||
return 0;
|
||||
}
|
||||
// fall through for other keys
|
||||
case WM_KEYDOWN:
|
||||
key = Win_MapKey( lParam );
|
||||
if ( key == K_CTRL || key == K_ALT || key == K_RIGHT_ALT ) {
|
||||
// let direct-input handle this because windows sends Alt-Gr
|
||||
// as two events (ctrl then alt)
|
||||
break;
|
||||
}
|
||||
Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, true, 0, NULL );
|
||||
break;
|
||||
|
||||
case WM_SYSKEYUP:
|
||||
case WM_KEYUP:
|
||||
key = Win_MapKey( lParam );
|
||||
if ( key == K_PRINT_SCR ) {
|
||||
// don't queue printscreen keys. Since windows doesn't send us key
|
||||
// down events for this, we handle queueing them with DirectInput
|
||||
break;
|
||||
} else if ( key == K_CTRL || key == K_ALT || key == K_RIGHT_ALT ) {
|
||||
// let direct-input handle this because windows sends Alt-Gr
|
||||
// as two events (ctrl then alt)
|
||||
break;
|
||||
}
|
||||
Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, false, 0, NULL );
|
||||
break;
|
||||
|
||||
case WM_CHAR:
|
||||
Sys_QueEvent( win32.sysMsgTime, SE_CHAR, wParam, 0, 0, NULL );
|
||||
break;
|
||||
|
||||
case WM_NCLBUTTONDOWN:
|
||||
// win32.movingWindow = true;
|
||||
break;
|
||||
|
||||
case WM_ENTERSIZEMOVE:
|
||||
win32.movingWindow = true;
|
||||
break;
|
||||
|
||||
case WM_EXITSIZEMOVE:
|
||||
win32.movingWindow = false;
|
||||
break;
|
||||
|
||||
case WM_SIZING:
|
||||
WIN_Sizing(wParam, (RECT *)lParam);
|
||||
break;
|
||||
|
||||
case WM_RBUTTONDOWN:
|
||||
case WM_RBUTTONUP:
|
||||
case WM_MBUTTONDOWN:
|
||||
case WM_MBUTTONUP:
|
||||
case WM_MOUSEMOVE: {
|
||||
break;
|
||||
}
|
||||
case WM_MOUSEWHEEL: {
|
||||
int delta = GET_WHEEL_DELTA_WPARAM( wParam ) / WHEEL_DELTA;
|
||||
int key = delta < 0 ? K_MWHEELDOWN : K_MWHEELUP;
|
||||
delta = abs( delta );
|
||||
while( delta-- > 0 ) {
|
||||
Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, true, 0, NULL );
|
||||
Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, false, 0, NULL );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return DefWindowProc( hWnd, uMsg, wParam, lParam );
|
||||
}
|
Loading…
Reference in a new issue