void MLMultiSlider::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel) { // filter out zero motions from trackpad if ((wheel.deltaX == 0.) && (wheel.deltaY == 0.)) return; if(mCurrDragSlider >= 0) return; bool doFineAdjust = e.mods.isShiftDown(); float wheelSpeed = doFineAdjust ? 0.1f : 1.f; float wheelDirection = (wheel.isReversed) ? -1.f : 1.f; if (isEnabled()) { int s = getSliderUnderPoint(Vec2(e.x, e.y)); if ((s >= 0) && ! isMouseButtonDownAnywhere()) { float currentVal = getFloatProperty(ml::textUtils::addFinalNumber(ml::Symbol("value"), s)); float minPosDelta = 0.01f; float deltaDir = (wheel.deltaY > 0.f) ? 1.f : -1.f; float posDelta = (wheel.deltaY + deltaDir*minPosDelta)*wheelSpeed*wheelDirection; const float currentPos = valueToProportionOfLength (currentVal); const float newPos = ml::clamp (currentPos + posDelta, 0.f, 1.f); float newValue = proportionOfLengthToValue (newPos); if(newValue != currentVal) { if(!isMouseWheelMoving) { isMouseWheelMoving = true; beginGesture(); } mpTimer->startTimer(kWheelTimeoutDuration); mCurrDragSlider = s; sendSliderAction(snapValue (newValue, false), s); mpTimer->startTimer(kWheelTimeoutDuration); mCurrDragSlider = -1; } } } else { Component::mouseWheelMove (e, wheel); } }
// This is copied from the Slider::Pimpl::handleAbsoluteDrag() and only here for reference. void MoveAwayForFineAdjustmentSlider::handleAbsoluteDrag (const MouseEvent& e) { const float mousePos = e.position.y; // The newPos is the current mouse position measured from the top of the // slider. newPos /in [0.0, 1.0] double newPos = (mousePos - sliderRegionStart) / (double) sliderRegionSize; if (!getSliderSnapsToMousePosition()) { const float mouseDiff = mouseDragStartPos.y - e.position.y; newPos = valueToProportionOfLength (valueOnMouseDown) + mouseDiff * (1.0 / getMouseDragSensitivity()); } else { if (isVertical()) // Now, newPos is measured from the bottom of the slider. newPos = 1.0 - newPos; } valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos)); }