Skip to content

Commit aed42f0

Browse files
committed
refactor(mouse): Apply minor refactoring and whitespace tweaks in WinMain, Mouse, HeaderTemplate (#1939)
1 parent 2b1bcee commit aed42f0

File tree

14 files changed

+177
-201
lines changed

14 files changed

+177
-201
lines changed

Generals/Code/GameEngine/Include/GameClient/HeaderTemplate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class HeaderTemplateManager
9494
HeaderTemplate *getFirstHeader( void );
9595
HeaderTemplate *getNextHeader( HeaderTemplate *ht );
9696

97-
void headerNotifyResolutionChange(void);
97+
void onResolutionChanged(void);
9898

9999
private:
100100
void populateGameFonts( void );

Generals/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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,8 @@ void DeclineResolution()
708708
TheWritableGlobalData->m_xResolution = newDispSettings.xRes;
709709
TheWritableGlobalData->m_yResolution = newDispSettings.yRes;
710710

711-
TheHeaderTemplateManager->headerNotifyResolutionChange();
712-
TheMouse->mouseNotifyResolutionChange();
711+
TheHeaderTemplateManager->onResolutionChanged();
712+
TheMouse->onResolutionChanged();
713713

714714
AsciiString prefString;
715715
prefString.format("%d %d", newDispSettings.xRes, newDispSettings.yRes);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,8 +1540,8 @@ static void saveOptions( void )
15401540
TheWritableGlobalData->m_xResolution = xres;
15411541
TheWritableGlobalData->m_yResolution = yres;
15421542

1543-
TheHeaderTemplateManager->headerNotifyResolutionChange();
1544-
TheMouse->mouseNotifyResolutionChange();
1543+
TheHeaderTemplateManager->onResolutionChanged();
1544+
TheMouse->onResolutionChanged();
15451545

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

Generals/Code/GameEngine/Source/GameClient/GUI/HeaderTemplate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ HeaderTemplate *HeaderTemplateManager::getNextHeader( HeaderTemplate *ht )
206206

207207
}
208208

209-
void HeaderTemplateManager::headerNotifyResolutionChange( void )
209+
void HeaderTemplateManager::onResolutionChanged( void )
210210
{
211211
populateGameFonts();
212212
}

Generals/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);

Generals/Code/Main/WinMain.cpp

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

7575
const Char *g_strFile = "data\\Generals.str";
@@ -315,77 +315,59 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
315315
{
316316
//-------------------------------------------------------------------------
317317
case WM_NCHITTEST:
318-
// Prevent the user from selecting the menu in fullscreen mode
319-
if( !TheGlobalData->m_windowed )
320-
return HTCLIENT;
321-
break;
318+
// Prevent the user from selecting the menu in fullscreen mode
319+
if( !TheGlobalData->m_windowed )
320+
return HTCLIENT;
321+
break;
322322

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

364364
// ------------------------------------------------------------------------
365365
case WM_CLOSE:
366-
TheGameEngine->checkAbnormalQuitting();
367-
TheGameEngine->reset();
368-
TheGameEngine->setQuitting(TRUE);
369-
_exit(EXIT_SUCCESS);
370-
return 0;
371-
372-
// ------------------------------------------------------------------------
373-
case WM_SETFOCUS:
374-
{
375-
376-
//
377-
// reset the state of our keyboard cause we haven't been paying
378-
// attention to the keys while focus was away
379-
//
380-
if( TheKeyboard )
381-
TheKeyboard->resetKeys();
382-
383-
if (TheMouse)
384-
TheMouse->regainFocus();
385-
386-
break;
387-
388-
}
366+
TheGameEngine->checkAbnormalQuitting();
367+
TheGameEngine->reset();
368+
TheGameEngine->setQuitting(TRUE);
369+
_exit(EXIT_SUCCESS);
370+
return 0;
389371

390372
//-------------------------------------------------------------------------
391373
case WM_MOVE:
@@ -409,6 +391,22 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
409391
break;
410392
}
411393

394+
// ------------------------------------------------------------------------
395+
case WM_SETFOCUS:
396+
{
397+
//
398+
// reset the state of our keyboard cause we haven't been paying
399+
// attention to the keys while focus was away
400+
//
401+
if( TheKeyboard )
402+
TheKeyboard->resetKeys();
403+
404+
if (TheMouse)
405+
TheMouse->regainFocus();
406+
407+
break;
408+
}
409+
412410
//-------------------------------------------------------------------------
413411
case WM_KILLFOCUS:
414412
{
@@ -439,13 +437,15 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
439437
TheGameEngine->setIsActive(isWinMainActive);
440438

441439
if (isWinMainActive)
442-
{ //restore mouse cursor to our custom version.
440+
{
441+
//restore mouse cursor to our custom version.
443442
if (TheWin32Mouse)
444443
TheWin32Mouse->setCursor(TheWin32Mouse->getMouseCursor());
445444
}
446445
}
447446
return 0;
448447
}
448+
449449
//-------------------------------------------------------------------------
450450
case WM_ACTIVATE:
451451
{
@@ -466,7 +466,6 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
466466
TheMouse->refreshCursorCapture();
467467
}
468468
break;
469-
470469
}
471470

472471
//-------------------------------------------------------------------------
@@ -476,21 +475,13 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
476475

477476
switch( key )
478477
{
479-
480-
//---------------------------------------------------------------------
481478
case VK_ESCAPE:
482479
{
483-
484480
PostQuitMessage( 0 );
485481
break;
486-
487482
}
488-
489-
490483
}
491-
492484
return 0;
493-
494485
}
495486

496487
//-------------------------------------------------------------------------
@@ -506,17 +497,18 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
506497
case WM_RBUTTONUP:
507498
case WM_RBUTTONDBLCLK:
508499
{
509-
510500
if( TheWin32Mouse )
511501
TheWin32Mouse->addWin32Event( message, wParam, lParam, TheMessageTime );
512502

513503
return 0;
514-
515504
}
516505

517506
//-------------------------------------------------------------------------
518507
case 0x020A: // WM_MOUSEWHEEL
519508
{
509+
if( TheWin32Mouse == NULL )
510+
return 0;
511+
520512
long x = (long) LOWORD(lParam);
521513
long y = (long) HIWORD(lParam);
522514
RECT rect;
@@ -526,32 +518,28 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
526518
if( x < rect.left || x > rect.right || y < rect.top || y > rect.bottom )
527519
return 0;
528520

529-
if( TheWin32Mouse )
530-
TheWin32Mouse->addWin32Event( message, wParam, lParam, TheMessageTime );
531-
521+
TheWin32Mouse->addWin32Event( message, wParam, lParam, TheMessageTime );
532522
return 0;
533-
534523
}
535524

536-
537525
//-------------------------------------------------------------------------
538526
case WM_MOUSEMOVE:
539527
{
528+
if( TheWin32Mouse == NULL )
529+
return 0;
530+
540531
Int x = (Int)LOWORD( lParam );
541532
Int y = (Int)HIWORD( lParam );
542533
RECT rect;
543-
// Int keys = wParam;
544534

545535
// ignore when outside of client area
546536
GetClientRect( ApplicationHWnd, &rect );
547537
if( x < rect.left || x > rect.right || y < rect.top || y > rect.bottom )
548538
return 0;
549539

550-
if( TheWin32Mouse )
551-
TheWin32Mouse->addWin32Event( message, wParam, lParam, TheMessageTime );
552540

541+
TheWin32Mouse->addWin32Event( message, wParam, lParam, TheMessageTime );
553542
return 0;
554-
555543
}
556544

557545
//-------------------------------------------------------------------------

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class HeaderTemplateManager
9494
HeaderTemplate *getFirstHeader( void );
9595
HeaderTemplate *getNextHeader( HeaderTemplate *ht );
9696

97-
void headerNotifyResolutionChange(void);
97+
void onResolutionChanged(void);
9898

9999
private:
100100
void populateGameFonts( void );

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,8 @@ void DeclineResolution()
745745
TheWritableGlobalData->m_xResolution = newDispSettings.xRes;
746746
TheWritableGlobalData->m_yResolution = newDispSettings.yRes;
747747

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

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

0 commit comments

Comments
 (0)