Hi!
I’m trying to hide the cursor while dragging a slider and then returning it to the same position after the mouse has been released. I figured MouseInputSource:: enableUnboundedMouseMovement() might help. How do I initialize a MouseInputSource object?
You don’t initialise it. It is there from the framework.
But you have access in the MouseEvent, which makes sense, since you can have multiple MouseInputSources (physical, virtual, multi touch).
Ok thank you.
So, if I add a mouseListener to my Slider with .addMouseListener(), where am I able to specify the mouseDown function? I am working within the PluginEditor.
Ah, that is annoying… it’s a result of the const MouseEvent reference…
You could use a const_cast, but that is actually frowned upon.
It seems to be legit from my point of view, but would want confirmation from one of the API authors.
In a situation without multiple mouse sources you can either use Desktop::setMousePosition() or ::getMainMouseSource() to get a non-const MouseInputSource.
That’s not really better than a const_cast IMHO, it already breaks on touch screens and will expose subtle bugs in other unforeseen situations.
Absolute worst case would be to iterate through the MouseInputSources until you find the one that triggered and use that pointer from the list, which is not const.
But that sounds like a horrible workaround.
EDIT: let me rephrase: what could go wrong using a const_cast?
Well, it’s not undefined behaviour at least. If you’re really concerned about working on multi-touch systems then using a combination of Desktop::getNumDraggingMouseSources() and Desktop::getDraggingMouseSource() will give you the correct MouseInputSource