SDL analog mouse input

This commit is contained in:
iota97 committed 2020-02-04 05:11:07 +01:00
1 parent 81118454fd
commit 4b28482479
2 files changed
+32 -1

No files matched your search

+31
View File
@@ -67,6 +67,9 @@ static int g_DesktopWidth = 0;
static int g_DesktopHeight = 0;
static int g_RefreshRate = 60000;
static float g_mouseDeltaX = 0;
static float g_mouseDeltaY = 0;
int getDisplayNumber(void) {
int displayNumber = 0;
char * displayNumberStr;
@@ -894,6 +897,13 @@ int main(int argc, char *argv[]) {
input.id = 0;
NativeTouch(input);
}
if (g_Config.bMouseControl && ((GetUIState() == UISTATE_INGAME && g_Config.bMouseConfine) || g_Config.bMapMouse)) {
g_mouseDeltaX = event.motion.xrel;
g_mouseDeltaY = event.motion.yrel;
SDL_SetRelativeMouseMode(SDL_TRUE);
} else {
SDL_SetRelativeMouseMode(SDL_FALSE);
}
break;
case SDL_MOUSEBUTTONUP:
switch (event.button.button) {
@@ -968,6 +978,27 @@ 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, g_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, g_mouseDeltaY * scaleFactor_y));
if (GetUIState() == UISTATE_INGAME || g_Config.bMapMouse) {
NativeAxis(axisX);
NativeAxis(axisY);
}
g_mouseDeltaX *= g_Config.fMouseSmoothing;
g_mouseDeltaY *= g_Config.fMouseSmoothing;
}
if (framecount % 60 == 0) {
// glsl_refresh(); // auto-reloads modified GLSL shaders once per second.
}
+1 -1
View File
@@ -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) {