Makie mouse click position

question

#1

Can someone please show me how to get the location of a mouse left click on a Makie.jl scene ?
Here’s what I have now:

using Makie
img = rand(100,100)
scene = Scene(resolution = (100, 100))
heatmap(img)
Makie.add_mousebuttons(scene)
pos = lift_node(scene, :mouseposition) do mpos
    if ispressed(scene, Mouse.left)
        return mpos
    end
end

Thanks a lot!


#2

Have you seen:https://github.com/JuliaPlots/Makie.jl/blob/master/docs/src/examples/scattermouse.jl ?

So I guess you’re looking for something like:

using Makie, GeometryTypes, Colors

img = rand(100,100)
scene = Scene()
heatmap(img)
center!(scene, 0.2)
cam = scene[:screen].cameras[:orthographic_pixel]
Makie.add_mousebuttons(scene)
pos = lift_node(scene, :mouseposition) do mpos
    if ispressed(scene, Mouse.left)
        return to_world(Point2f0(mpos), cam)
    end
    Point2f0(Inf)
end
scatter(lift_node(x-> Point2f0[x], pos), markersize = 10)

#3

I have, but I couldn’t figure out how to get the mouse position from just one click.

Also, in your example here (thank you btw), I can’t get the position without needing to move the mouse first, while holding down the mouse button. All I want is to click somewhere on the image and get the location of that click (in some variable I can access - a Signal perhaps).


#4

Ah!
You need to turn around on what node you “listen” to:

using Makie, GeometryTypes, Colors

img = rand(100,100)
scene = Scene()
heatmap(img)
center!(scene, 0.2)
cam = scene[:screen].cameras[:orthographic_pixel]
Makie.add_mousebuttons(scene)
clicks = to_node(Point2f0[])
pos = lift_node(scene, :mousebuttons) do buttons
    if length(buttons) == 1 && first(buttons) == Mouse.left
        pos = to_world(Point2f0(to_value(scene, :mouseposition)), cam)
        # awkward! one push! for adding to clicks, another to update the node!
        push!(clicks, push!(to_value(clicks), pos))
    end
    return 
end
scatter(clicks, markersize = 10)

#5

Awesome opossum!!

Thank you!