Should hitTest() and mouseWheelMove() use atomic variables?

Hello,
when I start move wheel mouse (so in method mouseWheelMove) I want to change varaibles that are used in hitTest(). And I wonder if it’s safe?
Is it possible that hitTest() and mouseWheelMove() are called simultunously?
Maybe should I define those variables as std::atomic?

I am not good in understanding mouse events and threads that use and share mouse events.
I see that in all virtual methods like mouseDrag, mouseDown, mouseWheelMove, etc, MouseEvent comes as const.

That’s why I think maybe I should be carefull with those methods, when changing it dinamically?

For any help thanks in advance.

All of the GUI stuff is done on the main thread for JUCE, so unless you’re seriously deviating from that paradigm (ie: using threads to manipulate GUI things!) nothing special is necessary.

1 Like

The events are const references because you can’t do anything useful by modifying them yourself in the event handler methods.

1 Like

Thanks for all answers. But:

Yes I can’t because it’s const, but if it’s not I can imagine a lot of useful things like eg. hide cursor or change it’s position, it would be great :slight_smile:

The Mouse Events don’t handle that kind of stuff, but there are other ways you can do those things.

1 Like

I know it’s not that subject, but if you’ve just started, maybe could you tell something more about those “other ways”? :slight_smile:

I am not sure if the mouse cursor moving is supported in the Juce public API at all but at least setting the mouse cursor, including setting it to an invisible cursor, is a method of Component.

void MainComponent::mouseDown(const MouseEvent & ev)
{
	setMouseCursor(MouseCursor::NoCursor);
}

void MainComponent::mouseUp(const MouseEvent & ev)
{
	setMouseCursor(MouseCursor::NormalCursor);
}
1 Like

To force the mouse to a new position you have to grab the input source from the Desktop instance:

void MainComponent::mouseDown(const MouseEvent & ev)
{
    Desktop::getInstance().getMouseSource(e.source.getIndex())->setScreenPosition(...);
}
2 Likes