diff --git a/Common/Input/InputState.h b/Common/Input/InputState.h index 5580ca79e6..a1d727d653 100644 --- a/Common/Input/InputState.h +++ b/Common/Input/InputState.h @@ -190,6 +190,10 @@ constexpr KeyInputFlags KEY_MOD_SHORTCUT = KeyInputFlags::ModMeta; constexpr KeyInputFlags KEY_MOD_SHORTCUT = KeyInputFlags::ModCtrl; #endif +// What one notch of a mouse wheel reports as its delta, on every backend (Windows' WHEEL_DELTA). +// Touchpads and high resolution wheels send fractions of it. +constexpr int WHEEL_DELTA_PER_NOTCH = 120; + struct KeyInput { KeyInput() {} // These utility constructors are used a lot in SDL. @@ -202,7 +206,8 @@ struct KeyInput { }; KeyInputFlags flags; - // Used by mousewheel events. The delta is packed in the upper 16 bits of flags. + // Used by mousewheel events. The delta is packed in the upper 16 bits of flags, in units of + // WHEEL_DELTA_PER_NOTCH, and is always positive (the key code gives the direction). // TODO: Move mousewheel events to TouchInput? int Delta() const { return (s32)flags >> 16; diff --git a/Common/UI/ScrollView.cpp b/Common/UI/ScrollView.cpp index a5c9e88fad..8eaa09d6c2 100644 --- a/Common/UI/ScrollView.cpp +++ b/Common/UI/ScrollView.cpp @@ -143,11 +143,12 @@ bool ScrollView::Key(const KeyInput &input) { break; } - // Ctrl+wheel is left for the children to zoom with (see GameBrowser::Key). - if ((input.flags & KeyInputFlags::DOWN) && mouseHover_ && !(input.flags & KeyInputFlags::ModCtrl)) { + // Ctrl+wheel (Cmd on Apple platforms) is left for the children to zoom with (see GameBrowser::Key). + if ((input.flags & KeyInputFlags::DOWN) && mouseHover_ && !(input.flags & KEY_MOD_SHORTCUT)) { if ((input.keyCode == NKCODE_EXT_MOUSEWHEEL_UP || input.keyCode == NKCODE_EXT_MOUSEWHEEL_DOWN) && (input.flags & KeyInputFlags::HAS_WHEEL_DELTA)) { - scrollSpeed = (float)((s32)input.flags >> 16) * 1.25f; // Fudge factor. TODO: Should be moved to the backends. + constexpr float pixelsPerNotch = 150.0f; + scrollSpeed = input.Delta() * (pixelsPerNotch / WHEEL_DELTA_PER_NOTCH); } switch (input.keyCode) { diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index d2f266a219..f366bd4cea 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -1830,7 +1830,8 @@ static void ProcessSDLEvent(SDL_Window *window, const SDL_Event &event, InputSta // it did), so don't undo it. const float wheelY = event.wheel.y; if (wheelY != 0.0f) { - const float scale = 30.0f; + // wheel.y is in notches. + const float scale = (float)WHEEL_DELTA_PER_NOTCH; key.keyCode = wheelY > 0 ? NKCODE_EXT_MOUSEWHEEL_UP : NKCODE_EXT_MOUSEWHEEL_DOWN; key.flags |= KeyInputFlags::HAS_WHEEL_DELTA; int wheelDelta = (int)(fabsf(wheelY) * scale); diff --git a/UI/GameBrowser.cpp b/UI/GameBrowser.cpp index 2947060bc7..4fe7537f6b 100644 --- a/UI/GameBrowser.cpp +++ b/UI/GameBrowser.cpp @@ -104,22 +104,25 @@ bool GameBrowser::Touch(const TouchInput &input) { return LinearLayout::Touch(input); } +// Draw notices the change and refreshes every browser. +static void StepIconSize(bool bigger) { + if (bigger) { + g_Config.fGameGridScale = std::min(g_Config.fGameGridScale * 1.25f, MAX_GAME_GRID_SCALE); + } else { + g_Config.fGameGridScale = std::max(g_Config.fGameGridScale / 1.25f, MIN_GAME_GRID_SCALE); + } +} + bool GameBrowser::Key(const KeyInput &input) { - // Ctrl+wheel changes the icon size, like zooming in a file manager. The plain list doesn't scale. - if ((input.flags & KeyInputFlags::DOWN) && (input.flags & KeyInputFlags::ModCtrl) && mouseHover_ && - (input.keyCode == NKCODE_EXT_MOUSEWHEEL_UP || input.keyCode == NKCODE_EXT_MOUSEWHEEL_DOWN)) { + // Ctrl+wheel and Ctrl+Plus/Minus (Cmd on Apple platforms) change the icon size, like zooming in a + // file manager. The plain list doesn't scale. + const bool zoomMod = (input.flags & KeyInputFlags::DOWN) && (input.flags & KEY_MOD_SHORTCUT); + if (zoomMod && mouseHover_ && (input.keyCode == NKCODE_EXT_MOUSEWHEEL_UP || input.keyCode == NKCODE_EXT_MOUSEWHEEL_DOWN)) { if (ViewMode() == GameBrowserViewMode::LIST) { return false; } // A touchpad sends a stream of small deltas, so add them up and step once per notch's worth. - // The units are the backend's: WM_MOUSEWHEEL's 120 per notch on Windows, 30 per notch from - // SDL and Android. UWP sends no delta, so each event is a notch. -#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP) - constexpr int deltaPerNotch = 120; -#else - constexpr int deltaPerNotch = 30; -#endif - int delta = (input.flags & KeyInputFlags::HAS_WHEEL_DELTA) ? ((u32)input.flags >> 16) : deltaPerNotch; + int delta = (input.flags & KeyInputFlags::HAS_WHEEL_DELTA) ? input.Delta() : WHEEL_DELTA_PER_NOTCH; if (input.keyCode == NKCODE_EXT_MOUSEWHEEL_DOWN) { delta = -delta; } @@ -130,17 +133,32 @@ bool GameBrowser::Key(const KeyInput &input) { } lastWheelZoomTime_ = now; wheelZoomAccum_ += delta; - while (wheelZoomAccum_ >= deltaPerNotch) { - g_Config.fGameGridScale = std::min(g_Config.fGameGridScale * 1.25f, MAX_GAME_GRID_SCALE); - wheelZoomAccum_ -= deltaPerNotch; + while (wheelZoomAccum_ >= WHEEL_DELTA_PER_NOTCH) { + StepIconSize(true); + wheelZoomAccum_ -= WHEEL_DELTA_PER_NOTCH; } - while (wheelZoomAccum_ <= -deltaPerNotch) { - g_Config.fGameGridScale = std::max(g_Config.fGameGridScale / 1.25f, MIN_GAME_GRID_SCALE); - wheelZoomAccum_ += deltaPerNotch; + while (wheelZoomAccum_ <= -WHEEL_DELTA_PER_NOTCH) { + StepIconSize(false); + wheelZoomAccum_ += WHEEL_DELTA_PER_NOTCH; } - // Draw notices the change and refreshes every browser. return true; } + if (zoomMod && ViewMode() != GameBrowserViewMode::LIST) { + // Plus is shifted on most layouts, so accept the key it shares (Equals on US layouts) too. + switch (input.keyCode) { + case NKCODE_PLUS: + case NKCODE_EQUALS: + case NKCODE_NUMPAD_ADD: + StepIconSize(true); + return true; + case NKCODE_MINUS: + case NKCODE_NUMPAD_SUBTRACT: + StepIconSize(false); + return true; + default: + break; + } + } // Alt+Up goes to the parent directory, as in file managers. if ((input.flags & KeyInputFlags::DOWN) && (input.flags & KeyInputFlags::ModAlt) && input.keyCode == NKCODE_DPAD_UP && input.deviceId == DEVICE_ID_KEYBOARD) { @@ -288,6 +306,16 @@ void GameBrowser::Draw(UIContext &dc) { if (lastScale_ != g_Config.fGameGridScale || lastViewMode_ != ViewMode()) { refreshPending_ = true; + // Keep the focus on the same game, as a keyboard zoom leaves it there. + if (gameList_ && focusPath_.empty()) { + for (int i = 0; i < gameList_->GetNumSubviews(); i++) { + GameButton *button = dynamic_cast(gameList_->GetViewByIndex(i)); + if (button && button->HasFocus()) { + focusPath_ = button->GetPath(); + break; + } + } + } } if (hasDropShadow_) { diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 0db5b8247b..edb22d363a 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -241,7 +241,12 @@ void PPSSPP_UWPMain::OnMouseWheel(float delta) { KeyInput keyInput{}; keyInput.keyCode = key; keyInput.deviceId = DEVICE_ID_MOUSE; - keyInput.flags = KeyInputFlags::DOWN; + // MouseWheelDelta is already in WHEEL_DELTA_PER_NOTCH units. + int wheelDelta = (int)(delta < 0 ? -delta : delta); + if (wheelDelta > 16 * WHEEL_DELTA_PER_NOTCH) { + wheelDelta = 16 * WHEEL_DELTA_PER_NOTCH; + } + keyInput.flags = (KeyInputFlags)((u32)KeyInputFlags::DOWN | (u32)KeyInputFlags::HAS_WHEEL_DELTA | (wheelDelta << 16)); NativeKey(keyInput); // KeyInputFlags::UP is now sent automatically afterwards for mouse wheel events, see NativeKey. diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 2b0f450f7f..8df90b0f21 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -1404,9 +1404,11 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_mouseWheelEvent( if (!renderer_inited) return false; // TODO: Mousewheel should probably be an axis instead. - int wheelDelta = y * 30.0f; - if (wheelDelta > 500) wheelDelta = 500; - if (wheelDelta < -500) wheelDelta = -500; + // AXIS_VSCROLL is in notches. + const int maxDelta = 16 * WHEEL_DELTA_PER_NOTCH; + int wheelDelta = y * (float)WHEEL_DELTA_PER_NOTCH; + if (wheelDelta > maxDelta) wheelDelta = maxDelta; + if (wheelDelta < -maxDelta) wheelDelta = -maxDelta; KeyInput key; key.deviceId = DEVICE_ID_MOUSE;