mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-16 02:59:49 +01:00
Input: Report mouse wheel deltas as 120 per notch on every backend
Windows sent 120 per notch, SDL and Android 30, and UWP nothing, and ScrollView scaled the delta by a fudge factor. It now scrolls 150 pixels per notch everywhere, which is what Windows did; SDL and Android scrolled a quarter of that. The game browser's icon zoom uses the shortcut modifier now (Cmd on Apple platforms, where Ctrl+scroll is the system's accessibility zoom), and also takes Ctrl/Cmd with Plus and Minus. It keeps the focused game focused when the icons are resized. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1df7557dda
commit
edc085eb05
6 files changed
+69
-27
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+2
-1
@@ -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);
|
||||
|
||||
+46
-18
@@ -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<GameButton *>(gameList_->GetViewByIndex(i));
|
||||
if (button && button->HasFocus()) {
|
||||
focusPath_ = button->GetPath();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasDropShadow_) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user