I am working on the gui for a new app. I have built a floating toolbox window that, much like any editor program, changes the cursor once a tool button has been clicked. I have created a singleton class which keeps track of the global state of the app and sets the cursor accordingly.
However, there is a strange bug:
When I click on my toolbox button (a separate document window from the main document window) then click on my main document, the mouse cursor changes back to the default cursor on mouseDown and won’t change to my desired custom cursor UNTIL I move the mouse outside of the component, then back in. This happens even though I am desperately trying to intercept every mouse action (mouseMove, mouseDown, etc), every focus change, everything I can think of to manually set and/or update the cursor. Also, every component in my app implements the getMouseCursor method. I even made my application class a globalFocusListener of my main document class, trying to manually change the cursor on every global focus change.
It’s a bit hard to describe so it’s best seen. I’ve made a compiled version (Mac OSX 10.5, leopard) of my gui and posted it at:
I decided on posting the compiled app rather than the code because the code would probably take a LOT longer to figure out as there are many classes/objects involved and I don’t have time to make a toy, simple version. You can also see the problem immediately when you use the app.
Is this a bug in JUCE or is it in my code? Is there a way to globally set the mouse cursor rather than per-component?
Sounds like you’re trying to use a sledgehammer to crack a nut! What’s wrong with just calling setMouseCursor on the components where you want the cursor to show?
Thanks for the response.
I refactored my code so no component uses their own getMouseCursor() method and instead, a singleton application state class keeps a list of components that need to have their mouse cursor set when I change my toolbar…
HOWEVER, the bug (as described above) persists!!! I have no idea where to even begin looking for it as I suspect its somewhere inside JUCE.
Here is the bug:
The important components:
- Toolbar window with buttons that change application state (and cursor)
- Main document window: contains menu bar, tabbed component with children components.
When I click on a toolbar button, everything works as it should – the mouse cursor changes, my app-state changes, etc.
Then when I click on the component inside my tabbed component, the mouse inexplicably changes to the default cursor.
The cursor remains default (no matter how much I drag or click) UNTIL I move the mouse outside of the main document window (don’t click) and move it back in. Then the mouse behaves as it should…
This problem does not occur again (after having dragged the mouse back into the main document window) if I create new tabbed components, etc.
I’ve uploaded a new version (with the refactored code) of my compiled app so you can see the bug (if you care to) at:
Is there some place in JUCE where you set the cursor to the default cursor when a document window comes into focus?
I should clarify: the problem DOES occur again after clicking on a new toolbar button (and thus, changing app-states/mouse-cursor) and the clicking back on the main document window.
I actually checked-in a mouse-cursor fix yesterday, though not sure if it relates to what you’re seeing. (The fix just made sre that it returns to the arrow cursor when you move outside a juce window)
It does seem like you’re doing it a bit oddly though. When I click on a toolbar, I wouldn’t expect to see the cursor change immediately - I’d just expect to see the appropriate cursor when I move across to a component that uses that tool.
Yeah, you are right. I ended up doing a redesign and instead of a floating toolbar, it’s a side-panel component that slides out (via Animator) and I made it so the cursor doesn’t change until you are over the editing view…
And it works…