Switching native mouse cursor to hand


I’m using custom GUI image buttons i have made.
When the mouse is over the button i would need to switch the windows native mouse cursor to the hand instead of the default arrow.
It seems that OF only knows the default native arrow cursor :frowning:

I have tried using custom ofImage as cursor but i have zindex problems (ofImage cursor showing under the image button instead of the above)

Thanks for your help !

You could definitely do ofHideCursor and then use images.

To have your image draw on top of everything have it be the last thing in your draw() function and make sure ofDisableDepthTesting(); is called just before.

You might also want to use ofImage’s setAnchorPercent(0.5, 0.5); which lets you have the image draw from the center of the position.

You could also use the glfw mouse functions but that might be a bit more complex.

Thanks Theo but i find a more “native” way to display hand cursor.

In ofAppGLFWWindow.cpp i have created a new method called : SwitchCursorToHandCursor()
with that code inside :

GLFWcursor* cursor = glfwCreateStandardCursor(GLFW_HAND_CURSOR);|
glfwSetCursor(windowP, cursor);|

It works but i don’t know how to call SwitchCursorToHandCursor() from my ofApp.cpp class because i don’t know how to retreive the instance of the ofAppGLFWWindow window :frowning:

Thanks for your help !

here is a way:

auto window = static_cast<ofAppGLFWWindow*>(ofGetWindowPtr())->getGLFWWindow();
auto cursor = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
glfwSetCursor(window, cursor);

you can do that in your app code where needed (no need to alter ofAppGLFWWindow.cpp)

(to prevent leaks i guess you should call the glfwCreateStandardCursor() function once per desired type in setup() and hold onto the pointers over the lifetime of your app.)

((a “correct” OF-way of providing the functionality would be to implement a generalized ofSetCursorShape(...) method that would handle the cast across window types and create/hold the various cursors as OF_CURSOR_*))

1 Like

Thanks a lot !
Going to test !