Add ability to hide the cursor

This commit is contained in:
Ousmane Traore 2017-04-30 10:40:31 -04:00
parent d37ad8f1ba
commit 29fe3b16ca
1 changed files with 22 additions and 3 deletions

View File

@ -45,6 +45,7 @@ type Window struct {
bounds pixel.Rect bounds pixel.Rect
canvas *Canvas canvas *Canvas
vsync bool vsync bool
cursorVisible bool
// need to save these to correctly restore a fullscreen window // need to save these to correctly restore a fullscreen window
restore struct { restore struct {
@ -291,6 +292,24 @@ func (w *Window) VSync() bool {
return w.vsync 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. // Note: must be called inside the main thread.
func (w *Window) begin() { func (w *Window) begin() {
if currWin != w { if currWin != w {