Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward Mouse input to Makie #162

Open
rasmushenningsson opened this issue May 12, 2023 · 0 comments
Open

Forward Mouse input to Makie #162

rasmushenningsson opened this issue May 12, 2023 · 0 comments

Comments

@rasmushenningsson
Copy link
Contributor

It would be useful to forward mouse (and keyboard) input to Makie. E.g. to be able to spin 3d plots using the mouse.

The proper way to do this would probably to adapt the code at https://github.com/jwahlstrand/GtkMakie.jl/blob/main/src/events.jl

At the moment, I have a workaround, by putting a MouseArea over the Makie viewport.
Here's an example of how it can be done, it might be useful to someone in the meantime. 🙂

MouseArea {
	anchors.fill: parent
	acceptedButtons: Qt.AllButtons

	onPressed: mouse=>Julia.mouse_press_callback(mouse.x,height-mouse.y-1,mouse.button)
	onReleased: mouse=>Julia.mouse_release_callback(mouse.x,height-mouse.y-1,mouse.button)
	onPositionChanged: mouse=>Julia.mouse_position_callback(mouse.x,height-mouse.y-1)
	onWheel: wheel=>Julia.mouse_wheel_callback(wheel.x, wheel.y, wheel.angleDelta.x, wheel.angleDelta.y)
}

and in the callbacks we update the Observables in scene.events:

function mouse_button_qt2makie(button)
	button == 1 && return Makie.Mouse.left
	button == 2 && return Makie.Mouse.right
	button == 4 && return Makie.Mouse.middle
	Makie.Mouse.none
end

function mouse_press_callback(mouseX, mouseY, button)
	scene.events.mouseposition[] = (mouseX,mouseY)
	b = mouse_button_qt2makie(button)
	if b != Makie.Mouse.none
		scene.events.mousebutton[] = Makie.MouseButtonEvent(b, Makie.Mouse.press)
	end
end
function mouse_release_callback(mouseX, mouseY, button)
	scene.events.mouseposition[] = (mouseX,mouseY)
	b = mouse_button_qt2makie(button)
	if b != Makie.Mouse.none
		scene.events.mousebutton[] = Makie.MouseButtonEvent(b, Makie.Mouse.release)
	end
end
function mouse_position_callback(mouseX, mouseY)
	scene.events.mouseposition[] = (mouseX,mouseY)
end
function mouse_wheel_callback(mouseX, mouseY, angleDeltaX, angleDeltaY)
	scene.events.mouseposition[] = (mouseX,mouseY)
	scene.events.scroll[] = (angleDeltaX/120,angleDeltaY/120)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants