Skip to content

Commit 293cec5

Browse files
committed
refactor(mouse): Apply minor refactoring and whitespace tweaks in WinMain, Mouse
1 parent d81e743 commit 293cec5

File tree

5 files changed

+88
-100
lines changed

5 files changed

+88
-100
lines changed

GeneralsMD/Code/GameEngine/Include/GameClient/Mouse.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ class Mouse : public SubsystemInterface
310310
Int getCursorIndex( const AsciiString& name );
311311
void resetTooltipDelay( void );
312312

313-
virtual void loseFocus();
314-
virtual void regainFocus();
313+
virtual void loseFocus(); ///< called when window has lost focus
314+
virtual void regainFocus(); ///< called when window has regained focus
315315

316-
void mouseNotifyResolutionChange(void);
316+
void onResolutionChanged(void);
317317
void onGameModeChanged(GameMode prev, GameMode next);
318318
void onGamePaused(Bool paused);
319319

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ void DeclineResolution()
746746
TheWritableGlobalData->m_yResolution = newDispSettings.yRes;
747747

748748
TheHeaderTemplateManager->headerNotifyResolutionChange();
749-
TheMouse->mouseNotifyResolutionChange();
749+
TheMouse->onResolutionChanged();
750750

751751
AsciiString prefString;
752752
prefString.format("%d %d", newDispSettings.xRes, newDispSettings.yRes);

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ static void saveOptions( void )
16011601
TheWritableGlobalData->m_yResolution = yres;
16021602

16031603
TheHeaderTemplateManager->headerNotifyResolutionChange();
1604-
TheMouse->mouseNotifyResolutionChange();
1604+
TheMouse->onResolutionChanged();
16051605

16061606
//Save new settings for a dialog box confirmation after options are accepted
16071607
newDispSettings.xRes = xres;

GeneralsMD/Code/GameEngine/Source/GameClient/Input/Mouse.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ void Mouse::init( void )
575575
m_numButtons = 2; // by default just have 2 buttons
576576
m_numAxes = 2; // by default a normal mouse moves in a 2d plane
577577
m_forceFeedback = FALSE;
578-
mouseNotifyResolutionChange();
578+
onResolutionChanged();
579579
m_tooltipString.clear(); // redundant
580580
m_displayTooltip = FALSE;
581581

@@ -607,7 +607,7 @@ void Mouse::init( void )
607607
//-------------------------------------------------------------------------------------------------
608608
/** Tell mouse system display resolution changed. */
609609
//-------------------------------------------------------------------------------------------------
610-
void Mouse::mouseNotifyResolutionChange( void )
610+
void Mouse::onResolutionChanged( void )
611611
{
612612
if(m_tooltipDisplayString)
613613
TheDisplayStringManager->freeDisplayString(m_tooltipDisplayString);

GeneralsMD/Code/Main/WinMain.cpp

Lines changed: 81 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
// GLOBALS ////////////////////////////////////////////////////////////////////
7373
HINSTANCE ApplicationHInstance = NULL; ///< our application instance
7474
HWND ApplicationHWnd = NULL; ///< our application window handle
75-
Win32Mouse *TheWin32Mouse= NULL; ///< for the WndProc() only
75+
Win32Mouse *TheWin32Mouse = NULL; ///< for the WndProc() only
7676
DWORD TheMessageTime = 0; ///< For getting the time that a message was posted from Windows.
7777

7878
const Char *g_strFile = "data\\Generals.str";
@@ -319,50 +319,50 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
319319
//-------------------------------------------------------------------------
320320
case WM_NCHITTEST:
321321
// Prevent the user from selecting the menu in fullscreen mode
322-
if( !TheGlobalData->m_windowed )
323-
return HTCLIENT;
324-
break;
322+
if( !TheGlobalData->m_windowed )
323+
return HTCLIENT;
324+
break;
325325

326326
//-------------------------------------------------------------------------
327327
case WM_POWERBROADCAST:
328-
switch( wParam )
329-
{
330-
#ifndef PBT_APMQUERYSUSPEND
331-
#define PBT_APMQUERYSUSPEND 0x0000
332-
#endif
333-
case PBT_APMQUERYSUSPEND:
334-
// At this point, the app should save any data for open
335-
// network connections, files, etc., and prepare to go into
336-
// a suspended mode.
337-
return TRUE;
338-
339-
#ifndef PBT_APMRESUMESUSPEND
340-
#define PBT_APMRESUMESUSPEND 0x0007
341-
#endif
342-
case PBT_APMRESUMESUSPEND:
343-
// At this point, the app should recover any data, network
344-
// connections, files, etc., and resume running from when
345-
// the app was suspended.
346-
return TRUE;
347-
}
348-
break;
328+
switch( wParam )
329+
{
330+
#ifndef PBT_APMQUERYSUSPEND
331+
#define PBT_APMQUERYSUSPEND 0x0000
332+
#endif
333+
case PBT_APMQUERYSUSPEND:
334+
// At this point, the app should save any data for open
335+
// network connections, files, etc., and prepare to go into
336+
// a suspended mode.
337+
return TRUE;
338+
339+
#ifndef PBT_APMRESUMESUSPEND
340+
#define PBT_APMRESUMESUSPEND 0x0007
341+
#endif
342+
case PBT_APMRESUMESUSPEND:
343+
// At this point, the app should recover any data, network
344+
// connections, files, etc., and resume running from when
345+
// the app was suspended.
346+
return TRUE;
347+
}
348+
break;
349349
//-------------------------------------------------------------------------
350350
case WM_SYSCOMMAND:
351-
// Prevent moving/sizing and power loss in fullscreen mode
352-
switch( wParam )
353-
{
354-
case SC_KEYMENU:
355-
// TheSuperHackers @bugfix Mauller 10/05/2025 Always handle this command to prevent halting the game when left Alt is pressed.
356-
return 1;
357-
case SC_MOVE:
358-
case SC_SIZE:
359-
case SC_MAXIMIZE:
360-
case SC_MONITORPOWER:
361-
if( !TheGlobalData->m_windowed )
362-
return 1;
363-
break;
364-
}
365-
break;
351+
// Prevent moving/sizing and power loss in fullscreen mode
352+
switch( wParam )
353+
{
354+
case SC_KEYMENU:
355+
// TheSuperHackers @bugfix Mauller 10/05/2025 Always handle this command to prevent halting the game when left Alt is pressed.
356+
return 1;
357+
case SC_MOVE:
358+
case SC_SIZE:
359+
case SC_MAXIMIZE:
360+
case SC_MONITORPOWER:
361+
if( !TheGlobalData->m_windowed )
362+
return 1;
363+
break;
364+
}
365+
break;
366366

367367
case WM_QUERYENDSESSION:
368368
{
@@ -372,42 +372,24 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
372372

373373
// ------------------------------------------------------------------------
374374
case WM_CLOSE:
375-
if (!TheGameEngine->getQuitting())
376-
{
377-
//user is exiting without using the menus
375+
if (!TheGameEngine->getQuitting())
376+
{
377+
//user is exiting without using the menus
378378

379-
//This method didn't work in cinematics because we don't process messages.
380-
//But it's the cleanest way to exit that's similar to using menus.
381-
TheMessageStream->appendMessage(GameMessage::MSG_META_DEMO_INSTANT_QUIT);
379+
//This method didn't work in cinematics because we don't process messages.
380+
//But it's the cleanest way to exit that's similar to using menus.
381+
TheMessageStream->appendMessage(GameMessage::MSG_META_DEMO_INSTANT_QUIT);
382382

383-
//This method used to disable quitting. We just put up the options screen instead.
384-
//TheMessageStream->appendMessage(GameMessage::MSG_META_OPTIONS);
383+
//This method used to disable quitting. We just put up the options screen instead.
384+
//TheMessageStream->appendMessage(GameMessage::MSG_META_OPTIONS);
385385

386-
//This method works everywhere but isn't as clean at shutting down.
387-
//TheGameEngine->checkAbnormalQuitting(); //old way to log disconnections for ALT-F4
388-
//TheGameEngine->reset();
389-
//TheGameEngine->setQuitting(TRUE);
390-
//_exit(EXIT_SUCCESS);
386+
//This method works everywhere but isn't as clean at shutting down.
387+
//TheGameEngine->checkAbnormalQuitting(); //old way to log disconnections for ALT-F4
388+
//TheGameEngine->reset();
389+
//TheGameEngine->setQuitting(TRUE);
390+
//_exit(EXIT_SUCCESS);
391+
}
391392
return 0;
392-
}
393-
394-
// ------------------------------------------------------------------------
395-
case WM_SETFOCUS:
396-
{
397-
398-
//
399-
// reset the state of our keyboard cause we haven't been paying
400-
// attention to the keys while focus was away
401-
//
402-
if( TheKeyboard )
403-
TheKeyboard->resetKeys();
404-
405-
if (TheMouse)
406-
TheMouse->regainFocus();
407-
408-
break;
409-
410-
}
411393

412394
//-------------------------------------------------------------------------
413395
case WM_MOVE:
@@ -431,6 +413,22 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
431413
break;
432414
}
433415

416+
// ------------------------------------------------------------------------
417+
case WM_SETFOCUS:
418+
{
419+
//
420+
// reset the state of our keyboard cause we haven't been paying
421+
// attention to the keys while focus was away
422+
//
423+
if( TheKeyboard )
424+
TheKeyboard->resetKeys();
425+
426+
if (TheMouse)
427+
TheMouse->regainFocus();
428+
429+
break;
430+
}
431+
434432
//-------------------------------------------------------------------------
435433
case WM_KILLFOCUS:
436434
{
@@ -461,13 +459,15 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
461459
TheGameEngine->setIsActive(isWinMainActive);
462460

463461
if (isWinMainActive)
464-
{ //restore mouse cursor to our custom version.
462+
{
463+
//restore mouse cursor to our custom version.
465464
if (TheWin32Mouse)
466465
TheWin32Mouse->setCursor(TheWin32Mouse->getMouseCursor());
467466
}
468467
}
469468
return 0;
470469
}
470+
471471
//-------------------------------------------------------------------------
472472
case WM_ACTIVATE:
473473
{
@@ -488,7 +488,6 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
488488
TheMouse->refreshCursorCapture();
489489
}
490490
break;
491-
492491
}
493492

494493
//-------------------------------------------------------------------------
@@ -498,21 +497,13 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
498497

499498
switch( key )
500499
{
501-
502-
//---------------------------------------------------------------------
503500
case VK_ESCAPE:
504501
{
505-
506502
PostQuitMessage( 0 );
507503
break;
508-
509504
}
510-
511-
512505
}
513-
514506
return 0;
515-
516507
}
517508

518509
//-------------------------------------------------------------------------
@@ -528,17 +519,18 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
528519
case WM_RBUTTONUP:
529520
case WM_RBUTTONDBLCLK:
530521
{
531-
532522
if( TheWin32Mouse )
533523
TheWin32Mouse->addWin32Event( message, wParam, lParam, TheMessageTime );
534524

535525
return 0;
536-
537526
}
538527

539528
//-------------------------------------------------------------------------
540529
case 0x020A: // WM_MOUSEWHEEL
541530
{
531+
if( TheWin32Mouse == NULL )
532+
return 0;
533+
542534
long x = (long) LOWORD(lParam);
543535
long y = (long) HIWORD(lParam);
544536
RECT rect;
@@ -548,32 +540,28 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
548540
if( x < rect.left || x > rect.right || y < rect.top || y > rect.bottom )
549541
return 0;
550542

551-
if( TheWin32Mouse )
552-
TheWin32Mouse->addWin32Event( message, wParam, lParam, TheMessageTime );
553-
543+
TheWin32Mouse->addWin32Event( message, wParam, lParam, TheMessageTime );
554544
return 0;
555-
556545
}
557546

558-
559547
//-------------------------------------------------------------------------
560548
case WM_MOUSEMOVE:
561549
{
550+
if( TheWin32Mouse == NULL )
551+
return 0;
552+
562553
Int x = (Int)LOWORD( lParam );
563554
Int y = (Int)HIWORD( lParam );
564555
RECT rect;
565-
// Int keys = wParam;
566556

567557
// ignore when outside of client area
568558
GetClientRect( ApplicationHWnd, &rect );
569559
if( x < rect.left || x > rect.right || y < rect.top || y > rect.bottom )
570560
return 0;
571561

572-
if( TheWin32Mouse )
573-
TheWin32Mouse->addWin32Event( message, wParam, lParam, TheMessageTime );
574562

563+
TheWin32Mouse->addWin32Event( message, wParam, lParam, TheMessageTime );
575564
return 0;
576-
577565
}
578566

579567
//-------------------------------------------------------------------------

0 commit comments

Comments
 (0)