Skip to content

Commit d4cd433

Browse files
committed
Use old mouse binding handling when in multiscreen fullscreen splitscreen screenscreen (followup to d803a45)
1 parent d803a45 commit d4cd433

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

Managers/UInputMan.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -385,18 +385,33 @@ namespace RTE {
385385
int rightMostPos = m_PlayerScreenMouseBounds.x + m_PlayerScreenMouseBounds.w;
386386
int bottomMostPos = m_PlayerScreenMouseBounds.y + m_PlayerScreenMouseBounds.h;
387387

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);
398414
}
399-
SDL_SetWindowMouseRect(g_WindowMan.GetWindow(), &newMouseBounds);
400415
}
401416
}
402417

@@ -434,7 +449,11 @@ namespace RTE {
434449
}
435450

436451
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+
}
438457
} else {
439458
// 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.
440459
m_PlayerScreenMouseBounds = { 0, 0, g_WindowMan.GetResX() * resMultiplier, g_WindowMan.GetResY() * resMultiplier };

System/RTETools.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ namespace RTE {
153153

154154
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
155155

156-
bool WithinBox(Vector &point, float left, float top, float right, float bottom) {
156+
bool WithinBox(const Vector &point, float left, float top, float right, float bottom) {
157157
return point.m_X >= left && point.m_X < right && point.m_Y >= top && point.m_Y < bottom;
158158
}
159159

160160
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
161161

162-
bool WithinBox(Vector &point, Vector &boxPos, float width, float height) {
162+
bool WithinBox(const Vector &point, const Vector &boxPos, float width, float height) {
163163
return point.m_X >= boxPos.m_X && point.m_X < (boxPos.m_X + width) && point.m_Y >= boxPos.m_Y && point.m_Y < (boxPos.m_Y + height);
164164
}
165165

System/RTETools.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ namespace RTE {
203203
/// <param name="width">Width of the box.</param>
204204
/// <param name="height">Height of the box.</param>
205205
/// <returns>True if point is inside box bounds.</returns>
206-
bool WithinBox(Vector &point, Vector &boxPos, float width, float height);
206+
bool WithinBox(const Vector &point, const Vector &boxPos, float width, float height);
207207

208208
/// <summary>
209209
/// Tells whether a point is within a specified box.
@@ -214,7 +214,7 @@ namespace RTE {
214214
/// <param name="right">Position of box right plane (X end).</param>
215215
/// <param name="bottom">Position of box bottom plane (Y end).</param>
216216
/// <returns>True if point is inside box bounds.</returns>
217-
bool WithinBox(Vector &point, float left, float top, float right, float bottom);
217+
bool WithinBox(const Vector &point, float left, float top, float right, float bottom);
218218
#pragma endregion
219219

220220
#pragma region Conversion

0 commit comments

Comments
 (0)