📄 winwindow.cc
字号:
processCharMessage( wParam, lParam );
break;
#endif
// We want to show the system cursor whenever we leave
// our window, and it'd be simple, except for one problem:
// showcursor isn't a toggle. so, keep hammering it until
// the cursor is *actually* going to be shown.
case WM_NCMOUSEMOVE:
{
while(ShowCursor(TRUE) < 0);
break;
}
case WM_MOUSEMOVE:
// keep trying until we actually show it
while(ShowCursor(FALSE) >= 0);
if ( !windowLocked )
{
MouseMoveEvent event;
S16 xPos = LOWORD(lParam);
S16 yPos = HIWORD(lParam);
event.xPos = xPos; // horizontal position of cursor
event.yPos = yPos; // vertical position of cursor
event.modifier = modifierKeys;
#ifdef LOG_INPUT
#ifdef LOG_MOUSEMOVE
Input::log( "EVENT (Win): mouse move to (%d, %d).\n", event.xPos, event.yPos );
#endif
#endif
Game->postEvent(event);
}
break;
case WM_LBUTTONDOWN:
mouseButtonEvent(SI_MAKE, KEY_BUTTON0);
break;
case WM_MBUTTONDOWN:
mouseButtonEvent(SI_MAKE, KEY_BUTTON2);
break;
case WM_RBUTTONDOWN:
mouseButtonEvent(SI_MAKE, KEY_BUTTON1);
break;
case WM_LBUTTONUP:
mouseButtonEvent(SI_BREAK, KEY_BUTTON0);
break;
case WM_MBUTTONUP:
mouseButtonEvent(SI_BREAK, KEY_BUTTON2);
break;
case WM_RBUTTONUP:
mouseButtonEvent(SI_BREAK, KEY_BUTTON1);
break;
case WM_MOUSEWHEEL:
mouseWheelEvent( (S16) HIWORD( wParam ) );
break;
}
}
if ( !mgr || !mgr->isKeyboardActive() )
{
switch ( message )
{
case WM_CHAR:
ProcessGBMessage(message, wParam, lParam); //IME Chinese
break;
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
if(g_pIME ==NULL || !g_pIME->IsEnable())//IME
processKeyMessage(message, wParam, lParam);
break;
}
}
}
}
//--------------------------------------
static bool ProcessMessages()
{
MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
return false;
TranslateMessage(&msg);
DispatchMessage(&msg);
OurDispatchMessages();
}
return true;
}
//--------------------------------------
void Platform::process()
{
DInputManager* mgr = dynamic_cast<DInputManager*>( Input::getManager() );
if ( !mgr || !mgr->isMouseActive() )
CheckCursorPos();
WindowsConsole->process();
if(!ProcessMessages())
{
// generate a quit event
Event quitEvent;
quitEvent.type = QuitEventType;
Game->postEvent(quitEvent);
}
// if there's no window, we sleep 1, otherwise we sleep 0
if(!Game->isJournalReading())
Sleep(gWindowCreated ? 0 : 1); // give others some process time if necessary...
HWND window = GetForegroundWindow();
if (window && gWindowCreated)
{
// check to see if we are in the foreground or not
// if not Sleep for a bit or until a Win32 message/input is recieved
DWORD foregroundProcessId;
GetWindowThreadProcessId(window, &foregroundProcessId);
if (foregroundProcessId != winState.processId)
MsgWaitForMultipleObjects(0, NULL, false, getBackgroundSleepTime(), QS_ALLINPUT);
}
Input::process();
}
extern U32 calculateCRC(void * buffer, S32 len, U32 crcVal );
#if defined(TORQUE_DEBUG) || defined(INTERNAL_RELEASE)
static U32 stubCRC = 0;
#else
static U32 stubCRC = 0xEA63F56C;
#endif
//--------------------------------------
static void InitWindowClass()
{
WNDCLASS wc;
dMemset(&wc, 0, sizeof(wc));
wc.style = CS_OWNDC;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = winState.appInstance;
wc.hIcon = LoadIcon(winState.appInstance, MAKEINTRESOURCE(IDI_ICON2));
wc.hCursor = LoadCursor (NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = windowClassName;
RegisterClass( &wc );
// Curtain window class:
wc.lpfnWndProc = DefWindowProc;
wc.hCursor = NULL;
wc.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
wc.lpszClassName = dT("Curtain");
RegisterClass( &wc );
}
//--------------------------------------
static void GetDesktopState()
{
HWND hDesktop = GetDesktopWindow();
HDC hDeskDC = GetDC( hDesktop );
winState.desktopBitsPixel = GetDeviceCaps( hDeskDC, BITSPIXEL );
winState.desktopWidth = GetDeviceCaps( hDeskDC, HORZRES );
winState.desktopHeight = GetDeviceCaps( hDeskDC, VERTRES );
ReleaseDC( hDesktop, hDeskDC );
}
//--------------------------------------
HWND CreateOpenGLWindow( U32 width, U32 height, bool fullScreen )
{
S32 windowStyle = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
S32 exWindowStyle = 0;
#ifdef TGE_RPG
if ( fullScreen )
windowStyle |= ( WS_POPUP | WS_MAXIMIZE );
else
windowStyle |= ( WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_THICKFRAME);
#else
if ( fullScreen )
windowStyle |= ( WS_POPUP | WS_MAXIMIZE );
else
windowStyle |= ( WS_OVERLAPPED | WS_CAPTION );
#endif
return CreateWindowEx(
exWindowStyle,
windowClassName,
windowName,
windowStyle,
0, 0, width, height,
NULL, NULL,
winState.appInstance,
NULL);
}
//--------------------------------------
HWND CreateCurtain( U32 width, U32 height )
{
return CreateWindow(
dT("Curtain"),
dT(""),
( WS_POPUP | WS_MAXIMIZE | WS_VISIBLE ),
0, 0,
width, height,
NULL, NULL,
winState.appInstance,
NULL );
}
//--------------------------------------
void CreatePixelFormat( PIXELFORMATDESCRIPTOR *pPFD, S32 colorBits, S32 depthBits, S32 stencilBits, bool stereo )
{
PIXELFORMATDESCRIPTOR src =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
colorBits, // color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
depthBits, // z-buffer
stencilBits, // stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
if ( stereo )
{
//ri.Printf( PRINT_ALL, "...attempting to use stereo\n" );
src.dwFlags |= PFD_STEREO;
//glConfig.stereoEnabled = true;
}
else
{
//glConfig.stereoEnabled = qfalse;
}
*pPFD = src;
}
//--------------------------------------
enum WinConstants { MAX_PFDS = 256 };
#ifndef PFD_GENERIC_ACCELERATED
#define PFD_GENERIC_ACCELERATED 0x00001000
#endif
S32 ChooseBestPixelFormat(HDC hDC, PIXELFORMATDESCRIPTOR *pPFD)
{
PIXELFORMATDESCRIPTOR pfds[MAX_PFDS+1];
S32 i;
S32 bestMatch = 0;
S32 maxPFD = dwglDescribePixelFormat(hDC, 1, sizeof(PIXELFORMATDESCRIPTOR), &pfds[0]);
if(maxPFD > MAX_PFDS)
maxPFD = MAX_PFDS;
bool accelerated = false;
for(i = 1; i <= maxPFD; i++)
{
dwglDescribePixelFormat(hDC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfds[i]);
// make sure this has hardware acceleration:
if ( ( pfds[i].dwFlags & PFD_GENERIC_FORMAT ) != 0 )
continue;
// verify pixel type
if ( pfds[i].iPixelType != PFD_TYPE_RGBA )
continue;
// verify proper flags
if ( ( ( pfds[i].dwFlags & pPFD->dwFlags ) & pPFD->dwFlags ) != pPFD->dwFlags )
continue;
accelerated = !(pfds[i].dwFlags & PFD_GENERIC_FORMAT);
//
// selection criteria (in order of priority):
//
// PFD_STEREO
// colorBits
// depthBits
// stencilBits
//
if ( bestMatch )
{
// check stereo
if ( ( pfds[i].dwFlags & PFD_STEREO ) && ( !( pfds[bestMatch].dwFlags & PFD_STEREO ) ) && ( pPFD->dwFlags & PFD_STEREO ) )
{
bestMatch = i;
continue;
}
if ( !( pfds[i].dwFlags & PFD_STEREO ) && ( pfds[bestMatch].dwFlags & PFD_STEREO ) && ( pPFD->dwFlags & PFD_STEREO ) )
{
bestMatch = i;
continue;
}
// check color
if ( pfds[bestMatch].cColorBits != pPFD->cColorBits )
{
// prefer perfect match
if ( pfds[i].cColorBits == pPFD->cColorBits )
{
bestMatch = i;
continue;
}
// otherwise if this PFD has more bits than our best, use it
else if ( pfds[i].cColorBits > pfds[bestMatch].cColorBits )
{
bestMatch = i;
continue;
}
}
// check depth
if ( pfds[bestMatch].cDepthBits != pPFD->cDepthBits )
{
// prefer perfect match
if ( pfds[i].cDepthBits == pPFD->cDepthBits )
{
bestMatch = i;
continue;
}
// otherwise if this PFD has more bits than our best, use it
else if ( pfds[i].cDepthBits > pfds[bestMatch].cDepthBits )
{
bestMatch = i;
continue;
}
}
// check stencil
if ( pfds[bestMatch].cStencilBits != pPFD->cStencilBits )
{
// prefer perfect match
if ( pfds[i].cStencilBits == pPFD->cStencilBits )
{
bestMatch = i;
continue;
}
// otherwise if this PFD has more bits than our best, use it
else if ( ( pfds[i].cStencilBits > pfds[bestMatch].cStencilBits ) &&
( pPFD->cStencilBits > 0 ) )
{
bestMatch = i;
continue;
}
}
}
else
{
bestMatch = i;
}
}
if ( !bestMatch )
return 0;
else if ( pfds[bestMatch].dwFlags & PFD_GENERIC_ACCELERATED )
{
// MCD
}
else
{
// ICD
}
*pPFD = pfds[bestMatch];
return bestMatch;
}
//--------------------------------------
//
// This function exists so DirectInput can communicate with the Windows mouse
// in windowed mode.
//
//--------------------------------------
void setModifierKeys( S32 modKeys )
{
modifierKeys = modKeys;
}
//--------------------------------------
const Point2I &Platform::getWindowSize()
{
return windowSize;
}
//--------------------------------------
void Platform::setWindowSize( U32 newWidth, U32 newHeight )
{
windowSize.set( newWidth, newHeight );
}
//--------------------------------------
static void InitWindow(const Point2I &initialSize)
{
windowSize = initialSize;
// The window is created when the display device is activated. BH
winState.processId = GetCurrentProcessId();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -