Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL analog mouse input #12612

Merged
merged 6 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@ int main(int argc, char *argv[]) {
}
graphicsContext->ThreadStart();

float mouseDeltaX;
iota97 marked this conversation as resolved.
Show resolved Hide resolved
float mouseDeltaY;
bool mouseCaptured = false;
bool windowHidden = false;
while (true) {
double startTime = time_now_d();
Expand Down Expand Up @@ -894,6 +897,10 @@ int main(int argc, char *argv[]) {
input.id = 0;
NativeTouch(input);
}
if (g_Config.bMouseControl) {
iota97 marked this conversation as resolved.
Show resolved Hide resolved
mouseDeltaX = event.motion.xrel;
mouseDeltaY = event.motion.yrel;
}
break;
case SDL_MOUSEBUTTONUP:
switch (event.button.button) {
Expand Down Expand Up @@ -968,6 +975,35 @@ int main(int argc, char *argv[]) {
}
#endif

// Disabled by default, needs a workaround to map to psp keys.
if (g_Config.bMouseControl) {
float scaleFactor_x = g_dpi_scale_x * 0.1 * g_Config.fMouseSensitivity;
float scaleFactor_y = g_dpi_scale_y * 0.1 * g_Config.fMouseSensitivity;

AxisInput axisX, axisY;
axisX.axisId = JOYSTICK_AXIS_MOUSE_REL_X;
axisX.deviceId = DEVICE_ID_MOUSE;
axisX.value = std::max(-1.0f, std::min(1.0f, mouseDeltaX * scaleFactor_x));
axisY.axisId = JOYSTICK_AXIS_MOUSE_REL_Y;
axisY.deviceId = DEVICE_ID_MOUSE;
axisY.value = std::max(-1.0f, std::min(1.0f, mouseDeltaY * scaleFactor_y));

if (GetUIState() == UISTATE_INGAME || g_Config.bMapMouse) {
NativeAxis(axisX);
NativeAxis(axisY);
}
mouseDeltaX *= g_Config.fMouseSmoothing;
mouseDeltaY *= g_Config.fMouseSmoothing;
}
bool captureMouseCondition = g_Config.bMouseControl && ((GetUIState() == UISTATE_INGAME && g_Config.bMouseConfine) || g_Config.bMapMouse);
if (mouseCaptured != captureMouseCondition) {
mouseCaptured = captureMouseCondition;
if (captureMouseCondition)
SDL_SetRelativeMouseMode(SDL_TRUE);
else
SDL_SetRelativeMouseMode(SDL_FALSE);
}

if (framecount % 60 == 0) {
// glsl_refresh(); // auto-reloads modified GLSL shaders once per second.
}
Expand Down
2 changes: 1 addition & 1 deletion UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ void GameSettingsScreen::CreateViews() {
settingInfo_->Show(co->T("AnalogLimiter Tip", "When the analog limiter button is pressed"), e.v);
return UI::EVENT_CONTINUE;
});
#if defined(USING_WIN_UI)
#if defined(USING_WIN_UI) || defined(SDL)
controlsSettings->Add(new ItemHeader(co->T("Mouse", "Mouse settings")));
CheckBox *mouseControl = controlsSettings->Add(new CheckBox(&g_Config.bMouseControl, co->T("Use Mouse Control")));
mouseControl->OnClick.Add([=](EventParams &e) {
Expand Down