How can I get this behavior out of juce::Slider?

I am trying to make it so that when a modifier key is pressed, the mouse sensitivity is decreased, but without adding a velocity curve. Simply take the input as it is, and reduce the range the movement creates.

I don’t think this is possible via setVelocityModeParameters(), but please correct me if I am wrong, and enlighten me.

This kind of works:

if (realtimeShiftStatus)
	setMouseDragSensitivity(1000);
else 
	setMouseDragSensitivity(250);

but if shift is pressed/released during a drag, the drag calculation method still takes the start position relative to the current position and then applies this value, so releasing the modifier key causes the slider to jump to where it would have been without the modifier.

Any input is greatly appreciated!

I think this might be what you’re looking for.

unfortunately this would not stop the slider from jumping when the sensitivity mode is changed during a drag if it’s true that it still uses dragDistanceFromMouseDown for its value calculation. That method is flawed because sensitivity can only be implemented as some sort of gain on the whole drag operation then. it’s better to use the difference between the current and last mouse.position.y as the defining thing for how the value changes. then you can change the sensitivity mode within a drag without a problem. Does juce::Slider not do that? I haven’t used it in a while, but would be kinda crazy

Got rid of the slider jumps with this workaround:

void mouseDrag (const juce::MouseEvent& e) override
{
	if (modifierKeyChanged)
	{
		// simulate up and down of mouse to reset mouse down position on shift change
		modifierKeyChanged = false;
		mouseUp (e);
		mouseDown (e);
	}
	Slider::mouseDrag (e);
}

void modifierKeysChanged (const juce::ModifierKeys& modifierKeys) override
{
	Slider::modifierKeysChanged (modifierKeys);

	// set drag sensitivity
	const auto sensitivity = modifierKeys.isShiftDown() ? originalSensitivity * 4 : originalSensitivity;
	setMouseDragSensitivity (sensitivity);

	modifierKeyChanged = true;
}


const int originalSensitivity;
bool modifierKeyChanged { false };

Maybe there are better solutions to the problem, couldn’t come up with anything better on the fly.

Thank you for this workaround.

It has has some side effects (like calling onDragEnd callback, hide/show popup display).
But this is still better than having the slider