Skip to content

Commit 88c5e55

Browse files
committed
allow multiple gui cursor positions; fix dual action on mouse button press
1 parent 449244b commit 88c5e55

File tree

5 files changed

+43
-51
lines changed

5 files changed

+43
-51
lines changed

Source/GUI/GUIControlManager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ void GUIControlManager::DrawMouse(GUIScreen* guiScreen) {
298298
int MouseX;
299299
int MouseY;
300300
m_Input->GetMousePosition(&MouseX, &MouseY);
301-
302301
switch (m_CursorType) {
303302
// Pointer
304303
case Pointer:

Source/GUI/Wrappers/GUIInputWrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void GUIInputWrapper::Update() {
5757
}
5858

5959
// Update the mouse position of this GUIInput, based on the SDL mouse vars (which may have been altered by joystick or keyboard input).
60-
Vector mousePos = g_UInputMan.GetAbsoluteMousePosition();
60+
Vector mousePos = g_UInputMan.GetAbsoluteMousePosition(m_Player);
6161
m_MouseX = static_cast<int>(mousePos.GetX() / static_cast<float>(g_WindowMan.GetResMultiplier()));
6262
m_MouseY = static_cast<int>(mousePos.GetY() / static_cast<float>(g_WindowMan.GetResMultiplier()));
6363
}
@@ -115,8 +115,8 @@ void GUIInputWrapper::UpdateMouseInput() {
115115
const auto& buttonChange = g_UInputMan.GetMouseChange(m_Player);
116116
Vector mousePos = g_UInputMan.GetAbsoluteMousePosition(m_Player);
117117

118-
m_LastFrameMouseX = mousePos.GetFloorIntX();
119-
m_LastFrameMouseY = mousePos.GetFloorIntY();
118+
m_MouseX = mousePos.GetFloorIntX();
119+
m_MouseY = mousePos.GetFloorIntY();
120120

121121
for (int button = 0; button < 3; button++) {
122122
m_MouseButtonsStates[button] = buttonStates[button + 1] ? Down : Up;

Source/Managers/UInputMan.cpp

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,13 @@ void UInputMan::TrapMousePos(bool trap, int whichPlayer) {
434434
m_TrapMousePos = trap;
435435
SDL_SetWindowRelativeMouseMode(g_WindowMan.GetWindow(), trap);
436436
} 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+
}
439444
}
440445
}
441446

@@ -444,7 +449,6 @@ void UInputMan::ForceMouseWithinBox(int x, int y, int width, int height, int whi
444449
int rightMostPos = m_PlayerScreenMouseBounds.x + m_PlayerScreenMouseBounds.w;
445450
int bottomMostPos = m_PlayerScreenMouseBounds.y + m_PlayerScreenMouseBounds.h;
446451
if (g_WindowMan.AnyWindowHasFocus() && !m_DisableMouseMoving && !m_TrapMousePos && (whichPlayer == Players::NoPlayer || (m_ControlScheme[whichPlayer].GetDevice() == InputDevice::DEVICE_MOUSE_KEYB && !m_EnableMultiMouseKeyboard))) {
447-
448452
if (g_WindowMan.FullyCoversAllDisplays()) {
449453
int leftPos = std::clamp(m_PlayerScreenMouseBounds.x + x, m_PlayerScreenMouseBounds.x, rightMostPos);
450454
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
471475
}
472476
SDL_SetWindowMouseRect(g_WindowMan.GetWindow(), &newMouseBounds);
473477
}
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) {
475479
if (auto mouse = m_MouseStates.find(m_ControlScheme[whichPlayer].GetDeviceID().mouseKeyboard.mouse); mouse != m_MouseStates.end()) {
476480
Vector& position = mouse->second.position;
477481
position.m_X = std::clamp(position.GetFloorIntX(), m_PlayerScreenMouseBounds.x, rightMostPos);
@@ -513,7 +517,7 @@ void UInputMan::ForceMouseWithinPlayerScreen(bool force, int whichPlayer) {
513517

514518
if (force) {
515519
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);
517521
} else {
518522
SDL_SetWindowMouseRect(g_WindowMan.GetWindow(), &m_PlayerScreenMouseBounds);
519523
}
@@ -615,8 +619,16 @@ bool UInputMan::GetInputElementState(int whichPlayer, int whichElement, InputSta
615619
if (!elementState && device == InputDevice::DEVICE_KEYB_ONLY || (device == InputDevice::DEVICE_MOUSE_KEYB && !(whichElement == InputElements::INPUT_AIM_UP || whichElement == InputElements::INPUT_AIM_DOWN))) {
616620
elementState = GetKeyboardButtonState(static_cast<SDL_Scancode>(element->GetKey()), whichState);
617621
}
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+
}
620632
}
621633

622634
if (!elementState && device >= InputDevice::DEVICE_GAMEPAD_1) {
@@ -671,7 +683,6 @@ bool UInputMan::GetMouseButtonState(int whichPlayer, int whichButton, InputState
671683
InputDevice playerDevice = InputDevice::DEVICE_COUNT;
672684
if (whichPlayer != Players::NoPlayer) {
673685
playerDevice = m_ControlScheme.at(whichPlayer).GetDevice();
674-
std::cout << "Player" << whichPlayer << " device " << playerDevice << std::endl;
675686
}
676687
if (mouse == 0 && (whichPlayer == Players::NoPlayer || (playerDevice != InputDevice::DEVICE_MOUSE_KEYB))) {
677688
switch (whichState) {
@@ -692,12 +703,7 @@ bool UInputMan::GetMouseButtonState(int whichPlayer, int whichButton, InputState
692703
}
693704
SDL_MouseID mouseID = mouse == 0 ? playerMouseID : mouse;
694705
auto mouseIterator = m_MouseStates.find(mouseID);
695-
std::cout << "Player mouseID " << mouseID << std::endl;
696706
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;
701707
switch (whichState) {
702708
case InputState::Held:
703709
return mouseIterator->second.state[whichButton];
@@ -1043,32 +1049,30 @@ void UInputMan::HandleSpecialInput() {
10431049
void UInputMan::UpdateMouseInput() {
10441050
// Detect and store mouse movement input, translated to analog stick emulation
10451051
// 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+
}
10541059

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);
10621066
}
10631067
}
1068+
}
10641069

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;
10721076
}
10731077
}
10741078

Source/Managers/UInputMan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ namespace RTE {
476476
Vector relativeMotion{};
477477
Vector analogAim{};
478478
float wheelChange{0.0f};
479+
bool relativeMode{};
479480
};
480481
std::unordered_map<SDL_MouseID, Mouse> m_MouseStates; //!< Mouse states when multi mouse support is enabled.
481482

Source/Menus/SettingsInputGUI.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,6 @@ void SettingsInputGUI::ShowDeviceCaptureBox(bool keyboard, int player) {
218218
}
219219
m_DeviceCaptureDialog.SelectorTextLabel->SetText(selectorText);
220220
m_DeviceCaptureDialog.Player = player;
221-
222-
int mouseCount{0};
223-
SDL_MouseID* mice = SDL_GetMice(&mouseCount);
224-
for(int i = 0; i < mouseCount; i++) {
225-
std::cout << mice[i] << " " << SDL_GetMouseNameForID(mice[i]) << std::endl;
226-
}
227-
228-
int keyboardCount{0};
229-
SDL_KeyboardID* keybs = SDL_GetKeyboards(&keyboardCount);
230-
for (int i = 0; i < keyboardCount; i++) {
231-
std::cout << keybs[i] << " " << SDL_GetKeyboardNameForID(keybs[i]) << std::endl;
232-
}
233221
}
234222

235223
void SettingsInputGUI::HideDeviceCaptureBox() {

0 commit comments

Comments
 (0)