@@ -385,18 +385,33 @@ namespace RTE {
385
385
int rightMostPos = m_PlayerScreenMouseBounds.x + m_PlayerScreenMouseBounds.w ;
386
386
int bottomMostPos = m_PlayerScreenMouseBounds.y + m_PlayerScreenMouseBounds.h ;
387
387
388
- SDL_Rect newMouseBounds = {
389
- std::clamp (m_PlayerScreenMouseBounds.x + x, m_PlayerScreenMouseBounds.x , rightMostPos),
390
- std::clamp (m_PlayerScreenMouseBounds.y + y, m_PlayerScreenMouseBounds.y , bottomMostPos),
391
- std::clamp (width, 0 , rightMostPos - x),
392
- std::clamp (height, 0 , bottomMostPos - y)
393
- };
394
-
395
- if (newMouseBounds.x >= rightMostPos || newMouseBounds.y >= bottomMostPos) {
396
- g_ConsoleMan.PrintString (" ERROR: Trying to force mouse wihin a box that is outside the player screen bounds!" );
397
- newMouseBounds = m_PlayerScreenMouseBounds;
388
+ if (g_WindowMan.FullyCoversAllDisplays ()) {
389
+ int leftPos = std::clamp (m_PlayerScreenMouseBounds.x + x, m_PlayerScreenMouseBounds.x , rightMostPos);
390
+ int topPos = std::clamp (m_PlayerScreenMouseBounds.y + y, m_PlayerScreenMouseBounds.y , bottomMostPos);
391
+
392
+ // The max mouse position inside the window is -1 its dimensions so we have to -1 for this to work on the right and bottom edges of the window.
393
+ rightMostPos = std::clamp (leftPos + width, leftPos, rightMostPos - 1 );
394
+ bottomMostPos = std::clamp (topPos + height, topPos, bottomMostPos - 1 );
395
+
396
+ if (!WithinBox (m_AbsoluteMousePos, static_cast <float >(leftPos), static_cast <float >(topPos), static_cast <float >(rightMostPos), static_cast <float >(bottomMostPos))) {
397
+ int limitX = std::clamp (m_AbsoluteMousePos.GetFloorIntX (), leftPos, rightMostPos);
398
+ int limitY = std::clamp (m_AbsoluteMousePos.GetFloorIntY (), topPos, bottomMostPos);
399
+ SDL_WarpMouseInWindow (g_WindowMan.GetWindow (), limitX, limitY);
400
+ }
401
+ } else {
402
+ SDL_Rect newMouseBounds = {
403
+ std::clamp (m_PlayerScreenMouseBounds.x + x, m_PlayerScreenMouseBounds.x , rightMostPos),
404
+ std::clamp (m_PlayerScreenMouseBounds.y + y, m_PlayerScreenMouseBounds.y , bottomMostPos),
405
+ std::clamp (width, 0 , rightMostPos - x),
406
+ std::clamp (height, 0 , bottomMostPos - y)
407
+ };
408
+
409
+ if (newMouseBounds.x >= rightMostPos || newMouseBounds.y >= bottomMostPos) {
410
+ g_ConsoleMan.PrintString (" ERROR: Trying to force mouse wihin a box that is outside the player screen bounds!" );
411
+ newMouseBounds = m_PlayerScreenMouseBounds;
412
+ }
413
+ SDL_SetWindowMouseRect (g_WindowMan.GetWindow (), &newMouseBounds);
398
414
}
399
- SDL_SetWindowMouseRect (g_WindowMan.GetWindow (), &newMouseBounds);
400
415
}
401
416
}
402
417
@@ -434,7 +449,11 @@ namespace RTE {
434
449
}
435
450
436
451
if (force) {
437
- SDL_SetWindowMouseRect (g_WindowMan.GetWindow (), &m_PlayerScreenMouseBounds);
452
+ if (g_WindowMan.FullyCoversAllDisplays ()) {
453
+ ForceMouseWithinBox (0 , 0 , m_PlayerScreenMouseBounds.w , m_PlayerScreenMouseBounds.h );
454
+ } else {
455
+ SDL_SetWindowMouseRect (g_WindowMan.GetWindow (), &m_PlayerScreenMouseBounds);
456
+ }
438
457
} else {
439
458
// Set the mouse bounds to the whole window so ForceMouseWithinBox is not stuck being relative to some player screen, because it can still bind the mouse even if this doesn't.
440
459
m_PlayerScreenMouseBounds = { 0 , 0 , g_WindowMan.GetResX () * resMultiplier, g_WindowMan.GetResY () * resMultiplier };
0 commit comments