Makie.jl - how to change the cursor?

How can I change the cursor to a sand clock to indicate the user to wait with MakieGL?

Makie currently doesn’t specifically expose this feature, but GLFW itself can change the window cursor. You can try to grab the underlying glfw window and directly change it.

1 Like

You get the underlying window with:
screen = display(scene)
glfw_window = GLMakie.to_native(screen)

1 Like

Thank you!

Here is a complete example

using GLMakie
using Makie
using GLMakie: GLFW
using Makie.ColorTypes: RGBA, N0f8
# TODO do not leak memory
cursor1 = GLFW.CreateStandardCursor(GLFW.CROSSHAIR_CURSOR)

img = fill(RGBA{N0f8}(0,0,0,0), 15, 15)
img[8, :] .= RGBA(1.0, 0.0, 1.0, 1.0)
img[:, 8] .= RGBA(1.0, 0.0, 1.0, 1.0)
# img[1, 1] is upper left
# img[1, end] is upper right

img_ = collect(reinterpret(NTuple{4, UInt8}, img))
hotspot = (8, 8)
cursor2 = ccall((:glfwCreateCursor, GLFW.libglfw), GLFW.Cursor, (Ref{GLFW.GLFWImage}, Cint, Cint), img_, hotspot[1], hotspot[2])

fig = Figure()
ax = Axis(fig[1, 1], title = "Demo")
ax.autolimitaspect = 1.0
scatter!(ax, [(-5, -5), (5, 5)])
screen = display(fig)
window = GLMakie.to_native(screen)

cursor_Fdata_obs = lift(events(fig).mouseposition) do mp
    # `mp` is relative to the window, throw it away.
    return mouseposition(ax.scene)

on(cursor_Fdata_obs) do cursor_Fdata
    cursor_Fraster = Tuple(round.(Int, cursor_Fdata))
    if iseven(sum(cursor_Fraster)) # checkboard pattern
        GLFW.SetCursor(window, cursor1)
        GLFW.SetCursor(window, cursor2)

The transition between cursors seems jumpy. There is also some visual ringing. None of these issues show up in the screen recording I made, though!

What you can see is that there is some scaling issue. The purple cross hair is not actually 1 pixel wide. This is probably some issue with the High DPI / Retina display scaling. Also, if I try to take a screenshot, the cursor appears in the wrong position (outside the Makie window).

Hm, that sounds like an issue for GitHub - glfw/glfw: A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input