Skip to content

Commit e1555bc

Browse files
authored
tweak(scrolling): Disable edge scrolling when the mouse cursor is not captured (#1462)
1 parent fbe3ba5 commit e1555bc

File tree

8 files changed

+80
-30
lines changed

8 files changed

+80
-30
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ class Mouse : public SubsystemInterface
291291

292292
void setCursorCaptureMode(CursorCaptureMode mode); ///< set the rules for the mouse capture
293293
void refreshCursorCapture(); ///< refresh the mouse capture
294+
Bool isCursorCaptured(); ///< true if the mouse is captured in the game window
294295

295296
// access methods for the mouse data
296297
const MouseIO *getMouseStatus( void ) { return &m_currMouse; } ///< get current mouse status
@@ -348,12 +349,13 @@ class Mouse : public SubsystemInterface
348349
protected:
349350

350351
void initCapture();
351-
Bool canCapture() const;
352-
void unblockCapture(CursorCaptureBlockReason reason);
353-
void blockCapture(CursorCaptureBlockReason reason);
352+
Bool canCapture() const; ///< true if the mouse can be captured
353+
void unblockCapture(CursorCaptureBlockReason reason); // unset a reason to block mouse capture
354+
void blockCapture(CursorCaptureBlockReason reason); // set a reason to block mouse capture
355+
void onCursorCaptured(Bool captured); ///< called when the mouse was successfully captured or released
354356

355-
virtual void capture( void ) = 0; ///< capture the mouse
356-
virtual void releaseCapture( void ) = 0; ///< release mouse capture
357+
virtual void capture( void ) = 0; ///< capture the mouse in the game window
358+
virtual void releaseCapture( void ) = 0; ///< release the mouse capture
357359

358360
/// you must implement getting a buffered mouse event from you device here
359361
virtual UnsignedByte getMouseEvent( MouseIO *result, Bool flush ) = 0;
@@ -398,6 +400,7 @@ class Mouse : public SubsystemInterface
398400
relative coordinate changes */
399401

400402
Bool m_visible; // visibility status
403+
Bool m_isCursorCaptured;
401404

402405
MouseCursor m_currentCursor; ///< current mouse cursor
403406

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ Mouse::Mouse( void )
500500
else
501501
m_currentRedrawMode = RM_W3D;//RM_WINDOWS;
502502
m_visible = FALSE;
503+
m_isCursorCaptured = FALSE;
503504
m_tooltipFontName = "Times New Roman";
504505
m_tooltipFontSize = 12;
505506
m_tooltipFontIsBold = FALSE;
@@ -1039,6 +1040,12 @@ void Mouse::refreshCursorCapture()
10391040
}
10401041
}
10411042

1043+
// ------------------------------------------------------------------------------------------------
1044+
Bool Mouse::isCursorCaptured()
1045+
{
1046+
return m_isCursorCaptured;
1047+
}
1048+
10421049
// ------------------------------------------------------------------------------------------------
10431050
void Mouse::loseFocus()
10441051
{
@@ -1118,6 +1125,12 @@ void Mouse::blockCapture(CursorCaptureBlockReason reason)
11181125
CursorCaptureBlockReasonNames[reason], m_captureBlockReasonBits, (Int)canCapture()));
11191126
}
11201127

1128+
// ------------------------------------------------------------------------------------------------
1129+
void Mouse::onCursorCaptured( Bool captured )
1130+
{
1131+
m_isCursorCaptured = captured;
1132+
}
1133+
11211134
//-------------------------------------------------------------------------------------------------
11221135
/** Draw the mouse */
11231136
//-------------------------------------------------------------------------------------------------

Generals/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,21 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
308308
}
309309

310310
// TheSuperHackers @tweak Ayumi/xezon 26/07/2025 Enables edge scrolling in windowed mode.
311-
if (m_isScrolling)
311+
if (TheMouse->isCursorCaptured())
312312
{
313-
if ( m_scrollType == SCROLL_SCREENEDGE && (m_currentPos.x >= edgeScrollSize && m_currentPos.y >= edgeScrollSize && m_currentPos.y < height-edgeScrollSize && m_currentPos.x < width-edgeScrollSize) )
313+
if (m_isScrolling)
314314
{
315-
stopScrolling();
315+
if ( m_scrollType == SCROLL_SCREENEDGE && (m_currentPos.x >= edgeScrollSize && m_currentPos.y >= edgeScrollSize && m_currentPos.y < height-edgeScrollSize && m_currentPos.x < width-edgeScrollSize) )
316+
{
317+
stopScrolling();
318+
}
316319
}
317-
}
318-
else
319-
{
320-
if ( m_currentPos.x < edgeScrollSize || m_currentPos.y < edgeScrollSize || m_currentPos.y >= height-edgeScrollSize || m_currentPos.x >= width-edgeScrollSize )
320+
else
321321
{
322-
setScrolling(SCROLL_SCREENEDGE);
322+
if ( m_currentPos.x < edgeScrollSize || m_currentPos.y < edgeScrollSize || m_currentPos.y >= height-edgeScrollSize || m_currentPos.x >= width-edgeScrollSize )
323+
{
324+
setScrolling(SCROLL_SCREENEDGE);
325+
}
323326
}
324327
}
325328

Generals/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32Mouse.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,10 @@ void Win32Mouse::capture( void )
472472
rect.right = rightBottom.x;
473473
rect.bottom = rightBottom.y;
474474

475-
::ClipCursor(&rect);
475+
if (::ClipCursor(&rect))
476+
{
477+
onCursorCaptured(true);
478+
}
476479

477480
} // end capture
478481

@@ -482,6 +485,9 @@ void Win32Mouse::capture( void )
482485
void Win32Mouse::releaseCapture( void )
483486
{
484487

485-
::ClipCursor(NULL);
488+
if (::ClipCursor(NULL))
489+
{
490+
onCursorCaptured(false);
491+
}
486492

487493
} // end releaseCapture

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ class Mouse : public SubsystemInterface
291291

292292
void setCursorCaptureMode(CursorCaptureMode mode); ///< set the rules for the mouse capture
293293
void refreshCursorCapture(); ///< refresh the mouse capture
294+
Bool isCursorCaptured(); ///< true if the mouse is captured in the game window
294295

295296
// access methods for the mouse data
296297
const MouseIO *getMouseStatus( void ) { return &m_currMouse; } ///< get current mouse status
@@ -349,12 +350,13 @@ class Mouse : public SubsystemInterface
349350
protected:
350351

351352
void initCapture();
352-
Bool canCapture() const;
353-
void unblockCapture(CursorCaptureBlockReason reason);
354-
void blockCapture(CursorCaptureBlockReason reason);
353+
Bool canCapture() const; ///< true if the mouse can be captured
354+
void unblockCapture(CursorCaptureBlockReason reason); // unset a reason to block mouse capture
355+
void blockCapture(CursorCaptureBlockReason reason); // set a reason to block mouse capture
356+
void onCursorCaptured(Bool captured); ///< called when the mouse was successfully captured or released
355357

356-
virtual void capture( void ) = 0; ///< capture the mouse
357-
virtual void releaseCapture( void ) = 0; ///< release mouse capture
358+
virtual void capture( void ) = 0; ///< capture the mouse in the game window
359+
virtual void releaseCapture( void ) = 0; ///< release the mouse capture
358360

359361
/// you must implement getting a buffered mouse event from you device here
360362
virtual UnsignedByte getMouseEvent( MouseIO *result, Bool flush ) = 0;
@@ -399,6 +401,7 @@ class Mouse : public SubsystemInterface
399401
relative coordinate changes */
400402

401403
Bool m_visible; // visibility status
404+
Bool m_isCursorCaptured;
402405

403406
MouseCursor m_currentCursor; ///< current mouse cursor
404407

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ Mouse::Mouse( void )
500500
else
501501
m_currentRedrawMode = RM_W3D;//RM_WINDOWS;
502502
m_visible = FALSE;
503+
m_isCursorCaptured = FALSE;
503504
m_tooltipFontName = "Times New Roman";
504505
m_tooltipFontSize = 12;
505506
m_tooltipFontIsBold = FALSE;
@@ -1039,6 +1040,12 @@ void Mouse::refreshCursorCapture()
10391040
}
10401041
}
10411042

1043+
// ------------------------------------------------------------------------------------------------
1044+
Bool Mouse::isCursorCaptured()
1045+
{
1046+
return m_isCursorCaptured;
1047+
}
1048+
10421049
// ------------------------------------------------------------------------------------------------
10431050
void Mouse::loseFocus()
10441051
{
@@ -1118,6 +1125,12 @@ void Mouse::blockCapture(CursorCaptureBlockReason reason)
11181125
CursorCaptureBlockReasonNames[reason], m_captureBlockReasonBits, (Int)canCapture()));
11191126
}
11201127

1128+
// ------------------------------------------------------------------------------------------------
1129+
void Mouse::onCursorCaptured( Bool captured )
1130+
{
1131+
m_isCursorCaptured = captured;
1132+
}
1133+
11211134
//-------------------------------------------------------------------------------------------------
11221135
/** Draw the mouse */
11231136
//-------------------------------------------------------------------------------------------------

GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,18 +307,21 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
307307
}
308308

309309
// TheSuperHackers @tweak Ayumi/xezon 26/07/2025 Enables edge scrolling in windowed mode.
310-
if (m_isScrolling)
310+
if (TheMouse->isCursorCaptured())
311311
{
312-
if ( m_scrollType == SCROLL_SCREENEDGE && (m_currentPos.x >= edgeScrollSize && m_currentPos.y >= edgeScrollSize && m_currentPos.y < height-edgeScrollSize && m_currentPos.x < width-edgeScrollSize) )
312+
if (m_isScrolling)
313313
{
314-
stopScrolling();
314+
if ( m_scrollType == SCROLL_SCREENEDGE && (m_currentPos.x >= edgeScrollSize && m_currentPos.y >= edgeScrollSize && m_currentPos.y < height-edgeScrollSize && m_currentPos.x < width-edgeScrollSize) )
315+
{
316+
stopScrolling();
317+
}
315318
}
316-
}
317-
else
318-
{
319-
if ( m_currentPos.x < edgeScrollSize || m_currentPos.y < edgeScrollSize || m_currentPos.y >= height-edgeScrollSize || m_currentPos.x >= width-edgeScrollSize )
319+
else
320320
{
321-
setScrolling(SCROLL_SCREENEDGE);
321+
if ( m_currentPos.x < edgeScrollSize || m_currentPos.y < edgeScrollSize || m_currentPos.y >= height-edgeScrollSize || m_currentPos.x >= width-edgeScrollSize )
322+
{
323+
setScrolling(SCROLL_SCREENEDGE);
324+
}
322325
}
323326
}
324327

GeneralsMD/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32Mouse.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,10 @@ void Win32Mouse::capture( void )
472472
rect.right = rightBottom.x;
473473
rect.bottom = rightBottom.y;
474474

475-
::ClipCursor(&rect);
475+
if (::ClipCursor(&rect))
476+
{
477+
onCursorCaptured(true);
478+
}
476479

477480
} // end capture
478481

@@ -482,6 +485,9 @@ void Win32Mouse::capture( void )
482485
void Win32Mouse::releaseCapture( void )
483486
{
484487

485-
::ClipCursor(NULL);
488+
if (::ClipCursor(NULL))
489+
{
490+
onCursorCaptured(false);
491+
}
486492

487493
} // end releaseCapture

0 commit comments

Comments
 (0)