diff --git a/Core/Config.cpp b/Core/Config.cpp index c1d1ecb029..83d7a58ff7 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -695,6 +695,11 @@ static ConfigSetting controlSettings[] = { #endif ConfigSetting("AnalogLimiterDeadzone", &g_Config.fAnalogLimiterDeadzone, 0.6f, true, true), + ConfigSetting("UseMouse", &g_Config.bMouseControl, false, true, true), + ConfigSetting("MapMouse", &g_Config.bMapMouse, false, true, true), + ConfigSetting("MouseSensitivity", &g_Config.fMouseSensitivity, 0.1, true, true), + ConfigSetting("MouseSmoothing", &g_Config.fMouseSmoothing, 0.9, true, true), + ConfigSetting(false), }; diff --git a/Core/Config.h b/Core/Config.h index 1c5acee0ec..ca1f7f1088 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -393,6 +393,11 @@ public: float fAnalogLimiterDeadzone; + bool bMouseControl; + bool bMapMouse; // Workaround for mapping screen:| + float fMouseSensitivity; + float fMouseSmoothing; + // Use the hardware scaler to scale up the image to save fillrate. Similar to Windows' window size, really. int iAndroidHwScale; // 0 = device resolution. 1 = 480x272 (extended to correct aspect), 2 = 960x544 etc. diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index beda8e560b..0d3e9ed32c 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -168,6 +168,7 @@ void ControlMapper::MappedCallback(KeyDef kdf) { default: ; } + g_Config.bMapMouse = false; refresh_ = true; ctrlScreen_->KeyMapped(pspKey_); // After this, we do not exist any more. So the refresh_ = true is probably irrelevant. @@ -217,6 +218,8 @@ void ControlMappingScreen::CreateViews() { leftColumn->Add(new Choice(km->T("Autoconfigure")))->OnClick.Handle(this, &ControlMappingScreen::OnAutoConfigure); } leftColumn->Add(new Choice(km->T("Test Analogs")))->OnClick.Handle(this, &ControlMappingScreen::OnTestAnalogs); + if (g_Config.bMouseControl) + leftColumn->Add(new CheckBox(&g_Config.bMapMouse, km->T("Map Mouse"))); leftColumn->Add(new Spacer(new LinearLayoutParams(1.0f))); AddStandardBack(leftColumn); @@ -306,7 +309,7 @@ bool KeyMappingNewKeyDialog::key(const KeyInput &key) { if (mapped_) return false; if (key.flags & KEY_DOWN) { - if (key.keyCode == NKCODE_EXT_MOUSEBUTTON_1) { + if (key.keyCode == NKCODE_EXT_MOUSEBUTTON_1 && !g_Config.bMapMouse) { return true; } diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index fe805bc123..ad92d22a9c 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013- PPSSPP Project. +// Copyright (c) 2013- PPSSPP Project. // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -575,6 +575,12 @@ 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) + controlsSettings->Add(new ItemHeader(co->T("Mouse", "Mouse Control Settings"))); + controlsSettings->Add(new CheckBox(&g_Config.bMouseControl, co->T("Use Mouse Control"))); + controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fMouseSensitivity, 0.01f, 1.0f, co->T("Mouse sensitivity"), 0.01f, screenManager(), "x")); + controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fMouseSmoothing, 0.0f, 0.95f, co->T("Mouse smoothing"), 0.05f, screenManager(), "x")); +#endif ViewGroup *networkingSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); networkingSettingsScroll->SetTag("GameSettingsNetworking"); diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index 30a30fe97b..0fb38581da 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -228,8 +228,8 @@ namespace MainWindow } void CorrectCursor() { - bool autoHide = g_Config.bFullScreen && !mouseButtonDown && GetUIState() == UISTATE_INGAME; - if (autoHide && hideCursor) { + bool autoHide = ((g_Config.bFullScreen && !mouseButtonDown) || g_Config.bMouseControl) && GetUIState() == UISTATE_INGAME; + if (autoHide && (hideCursor || g_Config.bMouseControl)) { while (cursorCounter >= 0) { cursorCounter = ShowCursor(FALSE); } @@ -566,7 +566,7 @@ namespace MainWindow static double lastMouseDown; double now = real_time_now(); if ((now - lastMouseDown) < 0.001 * GetDoubleClickTime()) { - if (!g_Config.bShowTouchControls && GetUIState() == UISTATE_INGAME && g_Config.bFullscreenOnDoubleclick) { + if (!g_Config.bShowTouchControls && !g_Config.bMouseControl && GetUIState() == UISTATE_INGAME && g_Config.bFullscreenOnDoubleclick) { SendToggleFullscreen(!g_Config.bFullScreen); } lastMouseDown = 0.0; diff --git a/Windows/RawInput.cpp b/Windows/RawInput.cpp index d14aa45bbf..713b61ea63 100644 --- a/Windows/RawInput.cpp +++ b/Windows/RawInput.cpp @@ -61,6 +61,7 @@ namespace WindowsRawInput { static size_t rawInputBufferSize; static bool menuActive; static bool focused = true; + static bool mouseLeftDown = false; static bool mouseRightDown = false; static float mouseX = 0.0f; static float mouseY = 0.0f; @@ -206,6 +207,36 @@ namespace WindowsRawInput { g_mouseDeltaX += raw->data.mouse.lLastX; g_mouseDeltaY += raw->data.mouse.lLastY; + if (g_Config.bMouseControl && (GetUIState() == UISTATE_INGAME || g_Config.bMapMouse)) { + if (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) { + key.flags = KEY_DOWN; + key.keyCode = windowsTransTable[VK_LBUTTON]; + NativeTouch(touch); + if (MouseInWindow(hWnd)) { + NativeKey(key); + } + mouseLeftDown = true; + } else if (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP) { + key.flags = KEY_UP; + key.keyCode = windowsTransTable[VK_LBUTTON]; + NativeTouch(touch); + if (MouseInWindow(hWnd)) { + if (!mouseLeftDown) { + // This means they were focused outside, and left clicked inside. + // Seems intentional, so send a down first. + key.flags = KEY_DOWN; + NativeKey(key); + key.flags = KEY_UP; + NativeKey(key); + } + else { + NativeKey(key); + } + } + mouseLeftDown = false; + } + } + if (raw->data.mouse.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN) { key.flags = KEY_DOWN; key.keyCode = windowsTransTable[VK_RBUTTON]; diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index 01fee1cea2..614cd9aeb3 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -211,11 +211,7 @@ void WindowsHost::PollControllers() { doPad = false; } - g_mouseDeltaX *= 0.9f; - g_mouseDeltaY *= 0.9f; - - // TODO: Tweak! - float scaleFactor = g_dpi_scale * 0.01f; + float scaleFactor = g_dpi_scale * 0.1 * g_Config.fMouseSensitivity; float mx = std::max(-1.0f, std::min(1.0f, g_mouseDeltaX * scaleFactor)); float my = std::max(-1.0f, std::min(1.0f, g_mouseDeltaY * scaleFactor)); @@ -227,9 +223,16 @@ void WindowsHost::PollControllers() { axisY.deviceId = DEVICE_ID_MOUSE; axisY.value = my; - // Disabled for now as it makes the mapping dialog unusable! - //if (fabsf(mx) > 0.1f) NativeAxis(axisX); - //if (fabsf(my) > 0.1f) NativeAxis(axisY); + // Disabled by default, needs a workaround to map to psp keys. + if (g_Config.bMouseControl){ + if (GetUIState() == UISTATE_INGAME || g_Config.bMapMouse) { + if (fabsf(mx) > 0.01f) NativeAxis(axisX); + if (fabsf(my) > 0.01f) NativeAxis(axisY); + } + } + + g_mouseDeltaX *= g_Config.fMouseSmoothing; + g_mouseDeltaY *= g_Config.fMouseSmoothing; } void WindowsHost::BootDone() {