From 2fa80f7d42574ca57da0baa6e1a6662014657522 Mon Sep 17 00:00:00 2001 From: Ousmane Traore Date: Sun, 30 Apr 2017 10:40:31 -0400 Subject: [PATCH] Add ability to hide the cursor --- pixelgl/window.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pixelgl/window.go b/pixelgl/window.go index 8b12876..1e3551c 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -42,9 +42,10 @@ type WindowConfig struct { type Window struct { window *glfw.Window - bounds pixel.Rect - canvas *Canvas - vsync bool + bounds pixel.Rect + canvas *Canvas + vsync bool + cursorVisible bool // need to save these to correctly restore a fullscreen window restore struct { @@ -291,6 +292,24 @@ func (w *Window) VSync() bool { return w.vsync } +// SetCursorVisible sets the visibility of the mouse cursor inside the window client area +func (w *Window) SetCursorVisible(visible bool) { + w.cursorVisible = visible + mainthread.Call(func() { + if visible && w.window.GetInputMode(glfw.CursorMode) != glfw.CursorNormal { + w.window.SetInputMode(glfw.CursorMode, glfw.CursorNormal) + } + if !visible && w.window.GetInputMode(glfw.CursorMode) != glfw.CursorHidden { + w.window.SetInputMode(glfw.CursorMode, glfw.CursorHidden) + } + }) +} + +// CursorVisible returns the visibility status of the mouse cursor +func (w *Window) CursorVisible() bool { + return w.cursorVisible +} + // Note: must be called inside the main thread. func (w *Window) begin() { if currWin != w {