I don't think clipping is the right approach here. In fact, on previous software package that I wrote, I got complaints from customers who have some fancy mice on Windows which have a deliberate button/wheel to increment two/four/etc. notches and clipping makes these mice work incorrectly.
However, after some testing with a standard external USB mouse on all OS, I agree that JUCE is inconsistent on the way it handles mouse wheel data. The correct delta for a single notch turn on a standard USB mouse should be 1/256 in JUCE. This is also what JUCE currently does on OS X. The windows code, however, currently returns 60/256 and linux does 50/256. For example, to make JUCE consistent with OS X, doMouseWheel needs to be changed in modules/juce_gui_basics/native/juce_win32_Windowing.cpp
line 1817:
static float convertWheelDeltaUnitsFromWParam (const WPARAM wParam)
{
const short hiword = (short) HIWORD (wParam);
return jlimit (-1000.0f, 1000.0f, static_cast<float> (hiword) / WHEEL_DELTA);
}
void doMouseWheel (const WPARAM wParam, const bool isVertical)
{
updateKeyModifiers();
const float amount = convertWheelDeltaUnitsFromWParam (wParam);
MouseWheelDetails wheel;
wheel.deltaX = isVertical ? 0.0f : amount / -256.0f;
wheel.deltaY = isVertical ? amount / 256.0f : 0.0f;
wheel.isReversed = false;
wheel.isSmooth = false;
wheel.isInertial = false;
Point<float> localPos;
if (ComponentPeer* const peer = findPeerUnderMouse (localPos))
peer->handleMouseWheel (0, localPos, getMouseEventTime(), wheel);
}
The following ifndef
is also needed somewhere at the top of juce_win32_Windowing.cpp
for some older Visual Studio versions:
#ifndef WHEEL_DELTA
#define WHEEL_DELTA 120 // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms645617(v=vs.85).aspx
#endif
On linux lines 2230/2231 of modules/juce_gui_basics/native/juce_linux_Windowing.cpp
needs to be changed.
However, I fear that these changes will not only break existing code but also result in large inconsistencies when trackpad gestures are used for scrolling. Jules put in these conversions so that scrolling speed on track pads is roughly the same on all OSes. What JUCE really needs to do is to figure out if the mouse wheel change is coming from a "real" mouse wheel or if it is a two-finger scroll etc. If it is coming from a real notched mouse wheel then the above changes need to be used, otherwise the current code is the correct conversion.
On OS X, it is possible to use hasPreciseScrollingDeltas
to distinguish between the two, but I am not sure how to do this on Windows/Linux. Any suggestions?