@@ -434,8 +434,13 @@ void UInputMan::TrapMousePos(bool trap, int whichPlayer) {
434
434
m_TrapMousePos = trap;
435
435
SDL_SetWindowRelativeMouseMode (g_WindowMan.GetWindow (), trap);
436
436
} else if (m_ControlScheme.at (whichPlayer).GetDevice () == InputDevice::DEVICE_MOUSE_KEYB) {
437
- m_TrapMousePos = trap || m_EnableMultiMouseKeyboard;
438
- SDL_SetWindowRelativeMouseMode (g_WindowMan.GetWindow (), m_TrapMousePos);
437
+ m_TrapMousePos = trap;
438
+ SDL_SetWindowRelativeMouseMode (g_WindowMan.GetWindow (), m_TrapMousePos||m_EnableMultiMouseKeyboard);
439
+ if (m_EnableMultiMouseKeyboard) {
440
+ if (auto mouse = m_MouseStates.find (m_ControlScheme.at (whichPlayer).GetDeviceID ().mouseKeyboard .mouse ); mouse != m_MouseStates.end ()) {
441
+ mouse->second .relativeMode = trap;
442
+ }
443
+ }
439
444
}
440
445
}
441
446
@@ -444,7 +449,6 @@ void UInputMan::ForceMouseWithinBox(int x, int y, int width, int height, int whi
444
449
int rightMostPos = m_PlayerScreenMouseBounds.x + m_PlayerScreenMouseBounds.w ;
445
450
int bottomMostPos = m_PlayerScreenMouseBounds.y + m_PlayerScreenMouseBounds.h ;
446
451
if (g_WindowMan.AnyWindowHasFocus () && !m_DisableMouseMoving && !m_TrapMousePos && (whichPlayer == Players::NoPlayer || (m_ControlScheme[whichPlayer].GetDevice () == InputDevice::DEVICE_MOUSE_KEYB && !m_EnableMultiMouseKeyboard))) {
447
-
448
452
if (g_WindowMan.FullyCoversAllDisplays ()) {
449
453
int leftPos = std::clamp (m_PlayerScreenMouseBounds.x + x, m_PlayerScreenMouseBounds.x , rightMostPos);
450
454
int topPos = std::clamp (m_PlayerScreenMouseBounds.y + y, m_PlayerScreenMouseBounds.y , bottomMostPos);
@@ -471,7 +475,7 @@ void UInputMan::ForceMouseWithinBox(int x, int y, int width, int height, int whi
471
475
}
472
476
SDL_SetWindowMouseRect (g_WindowMan.GetWindow (), &newMouseBounds);
473
477
}
474
- } else if (m_ControlScheme[whichPlayer].GetDevice () == InputDevice::DEVICE_MOUSE_KEYB && m_EnableMultiMouseKeyboard) {
478
+ } else if (whichPlayer != Players::NoPlayer && m_ControlScheme[whichPlayer].GetDevice () == InputDevice::DEVICE_MOUSE_KEYB && m_EnableMultiMouseKeyboard) {
475
479
if (auto mouse = m_MouseStates.find (m_ControlScheme[whichPlayer].GetDeviceID ().mouseKeyboard .mouse ); mouse != m_MouseStates.end ()) {
476
480
Vector& position = mouse->second .position ;
477
481
position.m_X = std::clamp (position.GetFloorIntX (), m_PlayerScreenMouseBounds.x , rightMostPos);
@@ -513,7 +517,7 @@ void UInputMan::ForceMouseWithinPlayerScreen(bool force, int whichPlayer) {
513
517
514
518
if (force) {
515
519
if (g_WindowMan.FullyCoversAllDisplays () || m_EnableMultiMouseKeyboard) {
516
- ForceMouseWithinBox (0 , 0 , m_PlayerScreenMouseBounds.w , m_PlayerScreenMouseBounds.h );
520
+ ForceMouseWithinBox (0 , 0 , m_PlayerScreenMouseBounds.w , m_PlayerScreenMouseBounds.h , whichPlayer );
517
521
} else {
518
522
SDL_SetWindowMouseRect (g_WindowMan.GetWindow (), &m_PlayerScreenMouseBounds);
519
523
}
@@ -615,8 +619,16 @@ bool UInputMan::GetInputElementState(int whichPlayer, int whichElement, InputSta
615
619
if (!elementState && device == InputDevice::DEVICE_KEYB_ONLY || (device == InputDevice::DEVICE_MOUSE_KEYB && !(whichElement == InputElements::INPUT_AIM_UP || whichElement == InputElements::INPUT_AIM_DOWN))) {
616
620
elementState = GetKeyboardButtonState (static_cast <SDL_Scancode>(element->GetKey ()), whichState);
617
621
}
618
- if (!elementState && device == InputDevice::DEVICE_MOUSE_KEYB && m_TrapMousePos) {
619
- elementState = GetMouseButtonState (whichPlayer, element->GetMouseButton (), whichState);
622
+ if (!elementState && device == InputDevice::DEVICE_MOUSE_KEYB) {
623
+ bool trapMouse = m_TrapMousePos;
624
+ if (m_EnableMultiMouseKeyboard) {
625
+ if (auto mouse = m_MouseStates.find (m_ControlScheme.at (whichPlayer).GetDeviceID ().mouseKeyboard .mouse ); mouse != m_MouseStates.end ()) {
626
+ trapMouse = mouse->second .relativeMode ;
627
+ }
628
+ }
629
+ if (trapMouse) {
630
+ elementState = GetMouseButtonState (whichPlayer, element->GetMouseButton (), whichState);
631
+ }
620
632
}
621
633
622
634
if (!elementState && device >= InputDevice::DEVICE_GAMEPAD_1) {
@@ -671,7 +683,6 @@ bool UInputMan::GetMouseButtonState(int whichPlayer, int whichButton, InputState
671
683
InputDevice playerDevice = InputDevice::DEVICE_COUNT;
672
684
if (whichPlayer != Players::NoPlayer) {
673
685
playerDevice = m_ControlScheme.at (whichPlayer).GetDevice ();
674
- std::cout << " Player" << whichPlayer << " device " << playerDevice << std::endl;
675
686
}
676
687
if (mouse == 0 && (whichPlayer == Players::NoPlayer || (playerDevice != InputDevice::DEVICE_MOUSE_KEYB))) {
677
688
switch (whichState) {
@@ -692,12 +703,7 @@ bool UInputMan::GetMouseButtonState(int whichPlayer, int whichButton, InputState
692
703
}
693
704
SDL_MouseID mouseID = mouse == 0 ? playerMouseID : mouse;
694
705
auto mouseIterator = m_MouseStates.find (mouseID);
695
- std::cout << " Player mouseID " << mouseID << std::endl;
696
706
if (mouseIterator != m_MouseStates.end ()) {
697
- for (int i = 0 ; i < MAX_MOUSE_BUTTONS; i++) {
698
- std::cout << mouseIterator->second .state [i] << " :" << mouseIterator->second .change [i] << " " ;
699
- }
700
- std::cout << std::endl;
701
707
switch (whichState) {
702
708
case InputState::Held:
703
709
return mouseIterator->second .state [whichButton];
@@ -1043,32 +1049,30 @@ void UInputMan::HandleSpecialInput() {
1043
1049
void UInputMan::UpdateMouseInput () {
1044
1050
// Detect and store mouse movement input, translated to analog stick emulation
1045
1051
// TODO: Figure out a less shit solution to updating the mouse in GUIs when there are no mouse players configured, i.e. no player input scheme is using mouse+keyboard. For not just check if we're out of Activity.
1046
- if (!g_ActivityMan.IsInActivity ()) {
1047
- m_AnalogMouseData.m_X += m_RawMouseMovement.m_X * 3 ;
1048
- m_AnalogMouseData.m_Y += m_RawMouseMovement.m_Y * 3 ;
1049
- m_AnalogMouseData.CapMagnitude (m_MouseTrapRadius);
1050
- for (auto & [mouseID, mouse]: m_MouseStates) {
1051
- mouse.analogAim += mouse.relativeMotion * 3 ;
1052
- mouse.analogAim .CapMagnitude (m_MouseTrapRadius);
1053
- }
1052
+ m_AnalogMouseData.m_X += m_RawMouseMovement.m_X * 3 ;
1053
+ m_AnalogMouseData.m_Y += m_RawMouseMovement.m_Y * 3 ;
1054
+ m_AnalogMouseData.CapMagnitude (m_MouseTrapRadius);
1055
+ for (auto & [mouseID, mouse]: m_MouseStates) {
1056
+ mouse.analogAim += mouse.relativeMotion * 3 ;
1057
+ mouse.analogAim .CapMagnitude (m_MouseTrapRadius);
1058
+ }
1054
1059
1055
- // Only mess with the mouse pos if the original mouse position is not above the screen and may be grabbing the title bar of the game window
1056
- if (g_WindowMan.AnyWindowHasFocus () && !m_DisableMouseMoving && (!m_TrapMousePos || m_EnableMultiMouseKeyboard)) {
1057
- // The mouse cursor is visible and can move about the screen/window, but it should still be contained within the mouse player's part of the window
1058
- for (int player = PlayerOne; player < MaxPlayerCount; player++) {
1059
- if (m_ControlScheme[player].GetDevice () == InputDevice::DEVICE_MOUSE_KEYB) {
1060
- ForceMouseWithinPlayerScreen (g_ActivityMan.IsInActivity (), player);
1061
- }
1060
+ // Only mess with the mouse pos if the original mouse position is not above the screen and may be grabbing the title bar of the game window
1061
+ if (g_WindowMan.AnyWindowHasFocus () && !m_DisableMouseMoving && (!m_TrapMousePos || m_EnableMultiMouseKeyboard)) {
1062
+ // The mouse cursor is visible and can move about the screen/window, but it should still be contained within the mouse player's part of the window
1063
+ for (int player = PlayerOne; player < MaxPlayerCount; player++) {
1064
+ if (m_ControlScheme[player].GetDevice () == InputDevice::DEVICE_MOUSE_KEYB) {
1065
+ ForceMouseWithinPlayerScreen (g_ActivityMan.IsInActivity (), player);
1062
1066
}
1063
1067
}
1068
+ }
1064
1069
1065
- // Enable the mouse cursor positioning again after having been disabled. Only do this when the mouse is within the drawing area so it
1066
- // won't cause the whole window to move if the user clicks the title bar and unintentionally drags it due to programmatic positioning.
1067
- int mousePosX = m_AbsoluteMousePos.m_X / g_WindowMan.GetResMultiplier ();
1068
- int mousePosY = m_AbsoluteMousePos.m_Y / g_WindowMan.GetResMultiplier ();
1069
- if (m_DisableMouseMoving && m_PrepareToEnableMouseMoving && (mousePosX >= 0 && mousePosX < g_WindowMan.GetResX () && mousePosY >= 0 && mousePosY < g_WindowMan.GetResY ())) {
1070
- m_DisableMouseMoving = m_PrepareToEnableMouseMoving = false ;
1071
- }
1070
+ // Enable the mouse cursor positioning again after having been disabled. Only do this when the mouse is within the drawing area so it
1071
+ // won't cause the whole window to move if the user clicks the title bar and unintentionally drags it due to programmatic positioning.
1072
+ int mousePosX = m_AbsoluteMousePos.m_X / g_WindowMan.GetResMultiplier ();
1073
+ int mousePosY = m_AbsoluteMousePos.m_Y / g_WindowMan.GetResMultiplier ();
1074
+ if (m_DisableMouseMoving && m_PrepareToEnableMouseMoving && (mousePosX >= 0 && mousePosX < g_WindowMan.GetResX () && mousePosY >= 0 && mousePosY < g_WindowMan.GetResY ())) {
1075
+ m_DisableMouseMoving = m_PrepareToEnableMouseMoving = false ;
1072
1076
}
1073
1077
}
1074
1078
0 commit comments