replacing old style Component::enableUnboundedMouseMovement


#1

I’m updating some old code that used enableUnboundedMouseMovement this way:

[code]void HeaderPanel::sliderDragStarted(Slider* slider)
{
if(slider == outLevelSlider)
{
filter->beginParameterChangeGesture(hostIndex_OutLevel);
}

// do other stuff…

slider->enableUnboundedMouseMovement(slider->getSliderStyle() != Slider::Rotary);

}

void HeaderPanel::sliderDragEnded(Slider* slider)
{
slider->enableUnboundedMouseMovement(false);
}
[/code]

This stopped being compiled since the unbounded mouse movement handling has been moved into MouseInputSource. What’s the cleanest way to achieve the same effect as before with the new refactoring?


#2

Probably Desktop::getInstance().getDraggingMouseSource (0)->enableUnboundedMouseMovement (true). (better check that it’s not a null pointer though).

You don’t really need to worry about disabling it, as that’ll happen when they let go anyway.


#3

Some code needs to be changed regarding this subject:

Line 377 of juce_MouseInputSource.cpp

Desktop::setMousePosition (current->getScreenBounds() .getConstrainedPoint (current->getMouseXYRelative()));

is not conceptually correct, should be replaced with

Desktop::setMousePosition (current->relativePositionToGlobal (current->getLocalBounds() .getConstrainedPoint (current->getMouseXYRelative())));

Do you agree?


#4

Ah yes, you’re right. I think what I probably meant to write was actually just:

Desktop::setMousePosition (current->getScreenBounds().getConstrainedPoint (lastScreenPos));