5
5
#include " UInputMan.h"
6
6
#include " Timer.h"
7
7
#include < SDL3/SDL.h>
8
+ #include < iostream>
8
9
9
10
using namespace RTE ;
10
11
@@ -110,103 +111,20 @@ void GUIInputWrapper::UpdateKeyboardInput(float keyElapsedTime) {
110
111
}
111
112
112
113
void GUIInputWrapper::UpdateMouseInput () {
113
- float discard;
114
- Uint32 buttonState = SDL_GetMouseState (&discard, &discard);
115
- Vector mousePos = g_UInputMan.GetAbsoluteMousePosition ();
116
-
117
- if (m_OverrideInput) {
118
- mousePos.SetXY (static_cast <float >(m_LastFrameMouseX), static_cast <float >(m_LastFrameMouseY));
119
-
120
- if (m_Player >= 0 && m_Player < 4 ) {
121
- if (m_NetworkMouseX[m_Player] != 0 ) {
122
- if (m_NetworkMouseX[m_Player] < 0 ) {
123
- m_NetworkMouseX[m_Player] = 1 ;
124
- }
125
- if (m_NetworkMouseX[m_Player] >= g_FrameMan.GetPlayerFrameBufferWidth (m_Player)) {
126
- m_NetworkMouseX[m_Player] = g_FrameMan.GetPlayerFrameBufferWidth (m_Player) - 2 ;
127
- }
128
- mousePos.SetX (static_cast <float >(m_NetworkMouseX[m_Player]));
129
- }
130
- if (m_NetworkMouseY[m_Player] != 0 ) {
131
- if (m_NetworkMouseY[m_Player] < 0 ) {
132
- m_NetworkMouseY[m_Player] = 1 ;
133
- }
134
- if (m_NetworkMouseY[m_Player] >= g_FrameMan.GetPlayerFrameBufferHeight (m_Player)) {
135
- m_NetworkMouseY[m_Player] = g_FrameMan.GetPlayerFrameBufferHeight (m_Player) - 2 ;
136
- }
137
- mousePos.SetY (static_cast <float >(m_NetworkMouseY[m_Player]));
138
- }
139
- } else {
140
- if (m_NetworkMouseX[0 ] != 0 ) {
141
- if (m_NetworkMouseX[0 ] < 0 ) {
142
- m_NetworkMouseX[0 ] = 1 ;
143
- }
144
- if (m_NetworkMouseX[0 ] >= g_FrameMan.GetPlayerFrameBufferWidth (0 )) {
145
- m_NetworkMouseX[0 ] = g_FrameMan.GetPlayerFrameBufferWidth (0 ) - 2 ;
146
- }
147
- mousePos.SetX (static_cast <float >(m_NetworkMouseX[0 ]));
148
- }
149
- if (m_NetworkMouseY[0 ] != 0 ) {
150
- if (m_NetworkMouseY[0 ] < 0 ) {
151
- m_NetworkMouseY[0 ] = 1 ;
152
- }
153
- if (m_NetworkMouseY[0 ] >= g_FrameMan.GetPlayerFrameBufferHeight (0 )) {
154
- m_NetworkMouseY[0 ] = g_FrameMan.GetPlayerFrameBufferHeight (0 ) - 2 ;
155
- }
156
- mousePos.SetY (static_cast <float >(m_NetworkMouseY[0 ]));
157
- }
158
- }
159
- g_UInputMan.SetAbsoluteMousePosition (mousePos);
160
- }
114
+ const auto & buttonStates = g_UInputMan.GetMouseState (m_Player);
115
+ const auto & buttonChange = g_UInputMan.GetMouseChange (m_Player);
116
+ Vector mousePos = g_UInputMan.GetAbsoluteMousePosition (m_Player);
161
117
162
118
m_LastFrameMouseX = mousePos.GetFloorIntX ();
163
119
m_LastFrameMouseY = mousePos.GetFloorIntY ();
164
120
165
- if (!m_OverrideInput) {
166
- if (!m_KeyJoyMouseCursor) {
167
- if (buttonState & SDL_BUTTON_LMASK) {
168
- m_MouseButtonsEvents[0 ] = (m_MouseButtonsStates[0 ] == GUIInput::Up) ? GUIInput::Pushed : GUIInput::Repeat;
169
- m_MouseButtonsStates[0 ] = GUIInput::Down;
170
- } else {
171
- m_MouseButtonsEvents[0 ] = (m_MouseButtonsStates[0 ] == GUIInput::Down) ? GUIInput::Released : GUIInput::None;
172
- m_MouseButtonsStates[0 ] = GUIInput::Up;
173
- }
174
- }
175
- if (buttonState & SDL_BUTTON_MMASK) {
176
- m_MouseButtonsEvents[1 ] = (m_MouseButtonsStates[1 ] == GUIInput::Up) ? GUIInput::Pushed : GUIInput::Repeat;
177
- m_MouseButtonsStates[1 ] = GUIInput::Down;
178
- } else {
179
- m_MouseButtonsEvents[1 ] = (m_MouseButtonsStates[1 ] == GUIInput::Down) ? GUIInput::Released : GUIInput::None;
180
- m_MouseButtonsStates[1 ] = GUIInput::Up;
181
- }
182
- if (buttonState & SDL_BUTTON_RMASK) {
183
- m_MouseButtonsEvents[2 ] = (m_MouseButtonsStates[2 ] == GUIInput::Up) ? GUIInput::Pushed : GUIInput::Repeat;
184
- m_MouseButtonsStates[2 ] = GUIInput::Down;
185
- } else {
186
- m_MouseButtonsEvents[2 ] = (m_MouseButtonsStates[2 ] == GUIInput::Down) ? GUIInput::Released : GUIInput::None;
187
- m_MouseButtonsStates[2 ] = GUIInput::Up;
188
- }
189
-
190
- if (m_Player <= Players::NoPlayer || m_Player >= Players::MaxPlayerCount) {
191
- for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; player++) {
192
- m_MouseWheelChange = g_UInputMan.MouseWheelMovedByPlayer (player);
193
- if (m_MouseWheelChange) {
194
- break ;
195
- }
196
- }
121
+ for (int button = 0 ; button < 3 ; button++) {
122
+ m_MouseButtonsStates[button] = buttonStates[button + 1 ] ? Down : Up;
123
+ if (m_MouseButtonsStates[button] == Down) {
124
+ m_MouseButtonsEvents[button] = buttonChange[button + 1 ] ? Pushed : Repeat;
197
125
} else {
198
- m_MouseWheelChange = g_UInputMan. MouseWheelMovedByPlayer (m_Player) ;
126
+ m_MouseButtonsEvents[button] = buttonChange[button + 1 ] ? Released : None ;
199
127
}
200
- } else {
201
- int player = (m_Player <= Players::NoPlayer || m_Player >= Players::MaxPlayerCount) ? 0 : m_Player;
202
-
203
- m_NetworkMouseButtonsEvents[player][0 ] = m_NetworkMouseButtonsStates[player][0 ] == GUIInput::Down ? (m_PrevNetworkMouseButtonsStates[player][0 ] == GUIInput::Up ? GUIInput::Pushed : GUIInput::Repeat) : (m_PrevNetworkMouseButtonsStates[player][0 ] == GUIInput::Down ? GUIInput::Released : GUIInput::None);
204
- m_NetworkMouseButtonsEvents[player][1 ] = m_NetworkMouseButtonsStates[player][1 ] == GUIInput::Down ? (m_PrevNetworkMouseButtonsStates[player][1 ] == GUIInput::Up ? GUIInput::Pushed : GUIInput::Repeat) : (m_PrevNetworkMouseButtonsStates[player][1 ] == GUIInput::Down ? GUIInput::Released : GUIInput::None);
205
- m_NetworkMouseButtonsEvents[player][2 ] = m_NetworkMouseButtonsStates[player][2 ] == GUIInput::Down ? (m_PrevNetworkMouseButtonsStates[player][2 ] == GUIInput::Up ? GUIInput::Pushed : GUIInput::Repeat) : (m_PrevNetworkMouseButtonsStates[player][2 ] == GUIInput::Down ? GUIInput::Released : GUIInput::None);
206
-
207
- m_PrevNetworkMouseButtonsStates[player][0 ] = m_NetworkMouseButtonsEvents[player][0 ];
208
- m_PrevNetworkMouseButtonsStates[player][1 ] = m_NetworkMouseButtonsEvents[player][1 ];
209
- m_PrevNetworkMouseButtonsStates[player][2 ] = m_NetworkMouseButtonsEvents[player][2 ];
210
128
}
211
129
}
212
130
@@ -221,7 +139,7 @@ void GUIInputWrapper::UpdateKeyJoyMouseInput(float keyElapsedTime) {
221
139
}
222
140
223
141
float acceleration = 0 .25F + static_cast <float >(std::min (m_CursorAccelTimer->GetElapsedRealTimeS (), 0.5 )) * 20 .0F ;
224
- Vector newMousePos = g_UInputMan.GetAbsoluteMousePosition ();
142
+ Vector newMousePos = g_UInputMan.GetAbsoluteMousePosition (m_Player );
225
143
226
144
// Manipulate the mouse position with the joysticks or keys.
227
145
newMousePos.m_X += joyKeyDirectional.GetX () * static_cast <float >(mouseDenominator) * keyElapsedTime * 15 .0F * acceleration;
@@ -231,7 +149,7 @@ void GUIInputWrapper::UpdateKeyJoyMouseInput(float keyElapsedTime) {
231
149
newMousePos.m_X = std::clamp (newMousePos.m_X , 0 .0F , static_cast <float >(g_WindowMan.GetResX () * mouseDenominator) - 3 .0F );
232
150
newMousePos.m_Y = std::clamp (newMousePos.m_Y , 0 .0F , static_cast <float >(g_WindowMan.GetResY () * mouseDenominator) - 3 .0F );
233
151
234
- g_UInputMan.SetAbsoluteMousePosition (newMousePos);
152
+ g_UInputMan.SetAbsoluteMousePosition (newMousePos, m_Player );
235
153
236
154
// Update mouse button states and presses. In the menu, either left or mouse button works.
237
155
if (g_UInputMan.MenuButtonHeld (UInputMan::MenuCursorButtons::MENU_EITHER)) {
0 commit comments