2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-12-04 01:30:46 +00:00
|
|
|
Copyright (C) 2012 Robert Beckebans
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition 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 BFG Edition 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.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma hdrstop
|
2012-12-22 15:18:19 +00:00
|
|
|
#include "precompiled.h"
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
#include "win_local.h"
|
|
|
|
#include "../../renderer/tr_local.h"
|
|
|
|
|
2012-12-02 21:37:32 +00:00
|
|
|
#include <windowsx.h>
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
|
|
|
|
|
|
|
|
static bool s_alttab_disabled;
|
|
|
|
|
|
|
|
extern idCVar r_windowX;
|
|
|
|
extern idCVar r_windowY;
|
|
|
|
extern idCVar r_windowWidth;
|
|
|
|
extern idCVar r_windowHeight;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
static void WIN_DisableAltTab()
|
|
|
|
{
|
|
|
|
if( s_alttab_disabled || win32.win_allowAltTab.GetBool() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !idStr::Icmp( cvarSystem->GetCVarString( "sys_arch" ), "winnt" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
RegisterHotKey( 0, 0, MOD_ALT, VK_TAB );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
BOOL old;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-12-04 11:11:14 +00:00
|
|
|
// RB begin
|
2012-12-04 01:30:46 +00:00
|
|
|
#if defined(__MINGW32__)
|
|
|
|
SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 1, &old, 0 );
|
|
|
|
#else
|
2012-11-26 18:58:24 +00:00
|
|
|
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, &old, 0 );
|
2012-12-04 01:30:46 +00:00
|
|
|
#endif
|
2012-12-04 11:11:14 +00:00
|
|
|
// RB end
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
s_alttab_disabled = true;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
static void WIN_EnableAltTab()
|
|
|
|
{
|
|
|
|
if( !s_alttab_disabled || win32.win_allowAltTab.GetBool() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !idStr::Icmp( cvarSystem->GetCVarString( "sys_arch" ), "winnt" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
UnregisterHotKey( 0, 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
BOOL old;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-12-04 01:30:46 +00:00
|
|
|
// RB begin
|
|
|
|
#if defined(__MINGW32__)
|
|
|
|
SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 1, &old, 0 );
|
|
|
|
#else
|
|
|
|
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, &old, 0 );
|
|
|
|
#endif
|
|
|
|
// RB end
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
s_alttab_disabled = false;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void WIN_Sizing( WORD side, RECT* rect )
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !R_IsInitialized() || renderSystem->GetWidth() <= 0 || renderSystem->GetHeight() <= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// restrict to a standard aspect ratio
|
|
|
|
int width = rect->right - rect->left;
|
|
|
|
int height = rect->bottom - rect->top;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Adjust width/height for window decoration
|
|
|
|
RECT decoRect = { 0, 0, 0, 0 };
|
2012-11-28 15:47:07 +00:00
|
|
|
AdjustWindowRect( &decoRect, WINDOW_STYLE | WS_SYSMENU, FALSE );
|
2012-11-26 18:58:24 +00:00
|
|
|
int decoWidth = decoRect.right - decoRect.left;
|
|
|
|
int decoHeight = decoRect.bottom - decoRect.top;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
width -= decoWidth;
|
|
|
|
height -= decoHeight;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Clamp to a minimum size
|
2012-11-28 15:47:07 +00:00
|
|
|
if( width < SCREEN_WIDTH / 4 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
width = SCREEN_WIDTH / 4;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( height < SCREEN_HEIGHT / 4 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
height = SCREEN_HEIGHT / 4;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
const int minWidth = height * 4 / 3;
|
|
|
|
const int maxHeight = width * 3 / 4;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
const int maxWidth = height * 16 / 9;
|
|
|
|
const int minHeight = width * 9 / 16;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Set the new size
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( side )
|
|
|
|
{
|
|
|
|
case WMSZ_LEFT:
|
|
|
|
rect->left = rect->right - width - decoWidth;
|
|
|
|
rect->bottom = rect->top + idMath::ClampInt( minHeight, maxHeight, height ) + decoHeight;
|
|
|
|
break;
|
|
|
|
case WMSZ_RIGHT:
|
|
|
|
rect->right = rect->left + width + decoWidth;
|
|
|
|
rect->bottom = rect->top + idMath::ClampInt( minHeight, maxHeight, height ) + decoHeight;
|
|
|
|
break;
|
|
|
|
case WMSZ_BOTTOM:
|
|
|
|
case WMSZ_BOTTOMRIGHT:
|
|
|
|
rect->bottom = rect->top + height + decoHeight;
|
|
|
|
rect->right = rect->left + idMath::ClampInt( minWidth, maxWidth, width ) + decoWidth;
|
|
|
|
break;
|
|
|
|
case WMSZ_TOP:
|
|
|
|
case WMSZ_TOPRIGHT:
|
|
|
|
rect->top = rect->bottom - height - decoHeight;
|
|
|
|
rect->right = rect->left + idMath::ClampInt( minWidth, maxWidth, width ) + decoWidth;
|
|
|
|
break;
|
|
|
|
case WMSZ_BOTTOMLEFT:
|
|
|
|
rect->bottom = rect->top + height + decoHeight;
|
|
|
|
rect->left = rect->right - idMath::ClampInt( minWidth, maxWidth, width ) - decoWidth;
|
|
|
|
break;
|
|
|
|
case WMSZ_TOPLEFT:
|
|
|
|
rect->top = rect->bottom - height - decoHeight;
|
|
|
|
rect->left = rect->right - idMath::ClampInt( minWidth, maxWidth, width ) - decoWidth;
|
|
|
|
break;
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
MainWndProc
|
|
|
|
|
|
|
|
main window procedure
|
|
|
|
====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int key;
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( uMsg )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
case WM_WINDOWPOSCHANGED:
|
2012-11-28 15:47:07 +00:00
|
|
|
if( R_IsInitialized() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
RECT rect;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ::GetClientRect( win32.hWnd, &rect ) )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( rect.right > rect.left && rect.bottom > rect.top )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
glConfig.nativeScreenWidth = rect.right - rect.left;
|
|
|
|
glConfig.nativeScreenHeight = rect.bottom - rect.top;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// save the window size in cvars if we aren't fullscreen
|
|
|
|
int style = GetWindowLong( hWnd, GWL_STYLE );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ( style & WS_POPUP ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
r_windowWidth.SetInteger( glConfig.nativeScreenWidth );
|
|
|
|
r_windowHeight.SetInteger( glConfig.nativeScreenHeight );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_MOVE:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int xPos, yPos;
|
|
|
|
RECT r;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// save the window origin in cvars if we aren't fullscreen
|
|
|
|
int style = GetWindowLong( hWnd, GWL_STYLE );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ( style & WS_POPUP ) == 0 )
|
|
|
|
{
|
|
|
|
xPos = ( short ) LOWORD( lParam ); // horizontal position
|
|
|
|
yPos = ( short ) HIWORD( lParam ); // vertical position
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
r.left = 0;
|
|
|
|
r.top = 0;
|
|
|
|
r.right = 1;
|
|
|
|
r.bottom = 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
AdjustWindowRect( &r, style, FALSE );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
r_windowX.SetInteger( xPos + r.left );
|
|
|
|
r_windowY.SetInteger( yPos + r.top );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WM_CREATE:
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
win32.hWnd = hWnd;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( win32.cdsFullscreen )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
WIN_DisableAltTab();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
WIN_EnableAltTab();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// do the OpenGL setup
|
|
|
|
void GLW_WM_CREATE( HWND hWnd );
|
|
|
|
GLW_WM_CREATE( hWnd );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case WM_DESTROY:
|
|
|
|
// let sound and input know about this?
|
|
|
|
win32.hWnd = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( win32.cdsFullscreen )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
WIN_EnableAltTab();
|
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case WM_CLOSE:
|
|
|
|
soundSystem->SetMute( true );
|
|
|
|
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "quit\n" );
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
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
|
2012-11-28 15:47:07 +00:00
|
|
|
{
|
|
|
|
int fActive, fMinimized;
|
|
|
|
|
|
|
|
fActive = LOWORD( wParam );
|
|
|
|
fMinimized = ( BOOL ) HIWORD( wParam );
|
|
|
|
|
|
|
|
win32.activeApp = ( fActive != WA_INACTIVE );
|
|
|
|
if( win32.activeApp )
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
2012-11-28 15:47:07 +00:00
|
|
|
idKeyInput::ClearStates();
|
|
|
|
Sys_GrabMouseCursor( true );
|
|
|
|
if( common->IsInitialized() )
|
|
|
|
{
|
|
|
|
SetCursor( NULL );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( fActive == WA_INACTIVE )
|
|
|
|
{
|
|
|
|
win32.movingWindow = false;
|
|
|
|
if( common->IsInitialized() )
|
|
|
|
{
|
|
|
|
SetCursor( LoadCursor( 0, IDC_ARROW ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
// start playing the game sound world
|
|
|
|
soundSystem->SetMute( !win32.activeApp );
|
2013-01-03 11:39:16 +00:00
|
|
|
// DG: set com_pause so game pauses when focus is lost
|
|
|
|
// and continues when focus is regained
|
|
|
|
cvarSystem->SetCVarBool( "com_pause", !win32.activeApp );
|
|
|
|
// DG end
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
// we do not actually grab or release the mouse here,
|
|
|
|
// that will be done next time through the main loop
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_TIMER:
|
|
|
|
{
|
|
|
|
if( win32.win_timerUpdate.GetBool() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Frame();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WM_SYSCOMMAND:
|
2012-11-28 15:47:07 +00:00
|
|
|
if( wParam == SC_SCREENSAVE || wParam == SC_KEYMENU )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case WM_SYSKEYDOWN:
|
2012-11-28 15:47:07 +00:00
|
|
|
if( wParam == 13 ) // alt-enter toggles full-screen
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
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 = ( ( lParam >> 16 ) & 0xFF ) | ( ( ( lParam >> 24 ) & 1 ) << 7 );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( key == K_LCTRL || key == K_LALT || key == K_RCTRL || key == K_RALT )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// let direct-input handle this because windows sends Alt-Gr
|
|
|
|
// as two events (ctrl then alt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// D
|
2012-11-28 15:47:07 +00:00
|
|
|
if( key == K_NUMLOCK )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
key = K_PAUSE;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( key == K_PAUSE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
key = K_NUMLOCK;
|
|
|
|
}
|
|
|
|
Sys_QueEvent( SE_KEY, key, true, 0, NULL, 0 );
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case WM_SYSKEYUP:
|
|
|
|
case WM_KEYUP:
|
|
|
|
key = ( ( lParam >> 16 ) & 0xFF ) | ( ( ( lParam >> 24 ) & 1 ) << 7 );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( key == K_PRINTSCREEN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// don't queue printscreen keys. Since windows doesn't send us key
|
|
|
|
// down events for this, we handle queueing them with DirectInput
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( key == K_LCTRL || key == K_LALT || key == K_RCTRL || key == K_RALT )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// let direct-input handle this because windows sends Alt-Gr
|
|
|
|
// as two events (ctrl then alt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Sys_QueEvent( SE_KEY, key, false, 0, NULL, 0 );
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case WM_CHAR:
|
|
|
|
Sys_QueEvent( SE_CHAR, wParam, 0, 0, NULL, 0 );
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case WM_NCLBUTTONDOWN:
|
|
|
|
// win32.movingWindow = true;
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case WM_ENTERSIZEMOVE:
|
|
|
|
win32.movingWindow = true;
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case WM_EXITSIZEMOVE:
|
|
|
|
win32.movingWindow = false;
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case WM_SIZING:
|
2012-11-28 15:47:07 +00:00
|
|
|
WIN_Sizing( wParam, ( RECT* )lParam );
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
{
|
|
|
|
if( !common->IsInitialized() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
const bool isShellActive = ( game && ( game->Shell_IsActive() || game->IsPDAOpen() ) );
|
|
|
|
const bool isConsoleActive = console->Active();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( win32.activeApp )
|
|
|
|
{
|
|
|
|
if( isShellActive )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// If the shell is active, it will display its own cursor.
|
|
|
|
SetCursor( NULL );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( isConsoleActive )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// The console is active but the shell is not.
|
|
|
|
// Show the Windows cursor.
|
|
|
|
SetCursor( LoadCursor( 0, IDC_ARROW ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// The shell not active and neither is the console.
|
|
|
|
// This is normal gameplay, hide the cursor.
|
|
|
|
SetCursor( NULL );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !isShellActive )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Always show the cursor when the window is in the background
|
|
|
|
SetCursor( LoadCursor( 0, IDC_ARROW ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SetCursor( NULL );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
const int x = GET_X_LPARAM( lParam );
|
|
|
|
const int y = GET_Y_LPARAM( lParam );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Generate an event
|
|
|
|
Sys_QueEvent( SE_MOUSE_ABSOLUTE, x, y, 0, NULL, 0 );
|
|
|
|
|
|
|
|
// Get a mouse leave message
|
2012-11-28 15:47:07 +00:00
|
|
|
TRACKMOUSEEVENT tme =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
sizeof( TRACKMOUSEEVENT ),
|
|
|
|
TME_LEAVE,
|
|
|
|
hWnd,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
TrackMouseEvent( &tme );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_MOUSE_LEAVE, 0, 0, 0, NULL, 0 );
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE1, 1, 0, NULL, 0 );
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_LBUTTONUP:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE1, 0, 0, NULL, 0 );
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE2, 1, 0, NULL, 0 );
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_RBUTTONUP:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE2, 0, 0, NULL, 0 );
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE3, 1, 0, NULL, 0 );
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_MBUTTONUP:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE3, 0, 0, NULL, 0 );
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_XBUTTONDOWN:
|
|
|
|
{
|
2012-12-04 01:30:46 +00:00
|
|
|
// RB begin
|
|
|
|
#if defined(__MINGW32__)
|
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE4, 1, 0, NULL, 0 );
|
|
|
|
#else
|
2012-11-26 18:58:24 +00:00
|
|
|
int button = GET_XBUTTON_WPARAM( wParam );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( button == 1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE4, 1, 0, NULL, 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( button == 2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE5, 1, 0, NULL, 0 );
|
|
|
|
}
|
2012-12-04 01:30:46 +00:00
|
|
|
#endif
|
|
|
|
// RB end
|
2012-11-26 18:58:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_XBUTTONUP:
|
|
|
|
{
|
2012-12-04 01:30:46 +00:00
|
|
|
// RB begin
|
|
|
|
#if defined(__MINGW32__)
|
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE4, 0, 0, NULL, 0 );
|
|
|
|
#else
|
2012-11-26 18:58:24 +00:00
|
|
|
int button = GET_XBUTTON_WPARAM( wParam );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( button == 1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE4, 0, 0, NULL, 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( button == 2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_KEY, K_MOUSE5, 0, 0, NULL, 0 );
|
|
|
|
}
|
2012-12-04 01:30:46 +00:00
|
|
|
#endif
|
|
|
|
// RB end
|
2012-11-26 18:58:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int delta = GET_WHEEL_DELTA_WPARAM( wParam ) / WHEEL_DELTA;
|
|
|
|
int key = delta < 0 ? K_MWHEELDOWN : K_MWHEELUP;
|
|
|
|
delta = abs( delta );
|
2012-11-28 15:47:07 +00:00
|
|
|
while( delta-- > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Sys_QueEvent( SE_KEY, key, true, 0, NULL, 0 );
|
|
|
|
Sys_QueEvent( SE_KEY, key, false, 0, NULL, 0 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
return DefWindowProc( hWnd, uMsg, wParam, lParam );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|