Slightly More Complex Cursor Logic
This commit is contained in:
parent
bc898ce1ee
commit
3f65b2c0c8
|
@ -59,6 +59,7 @@ type Window struct {
|
||||||
canvas *Canvas
|
canvas *Canvas
|
||||||
vsync bool
|
vsync bool
|
||||||
cursorVisible bool
|
cursorVisible bool
|
||||||
|
cursorDisabled 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 {
|
||||||
|
@ -320,6 +321,7 @@ func (w *Window) VSync() bool {
|
||||||
|
|
||||||
// SetCursorVisible sets the visibility of the mouse cursor inside the Window client area.
|
// SetCursorVisible sets the visibility of the mouse cursor inside the Window client area.
|
||||||
func (w *Window) SetCursorVisible(visible bool) {
|
func (w *Window) SetCursorVisible(visible bool) {
|
||||||
|
if !w.cursorDisabled {
|
||||||
w.cursorVisible = visible
|
w.cursorVisible = visible
|
||||||
mainthread.Call(func() {
|
mainthread.Call(func() {
|
||||||
if visible {
|
if visible {
|
||||||
|
@ -328,18 +330,7 @@ func (w *Window) SetCursorVisible(visible bool) {
|
||||||
w.window.SetInputMode(glfw.CursorMode, glfw.CursorHidden)
|
w.window.SetInputMode(glfw.CursorMode, glfw.CursorHidden)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
// SetCursorDisabled both hides the cursor, as well as limits cursor movement to the Window client area.
|
|
||||||
func (w *Window) SetCursorDisabled(disabled bool) {
|
|
||||||
w.cursorVisible = !disabled
|
|
||||||
mainthread.Call(func() {
|
|
||||||
if disabled {
|
|
||||||
w.window.SetInputMode(glfw.CursorMode, glfw.CursorDisabled)
|
|
||||||
} else {
|
|
||||||
w.window.SetInputMode(glfw.CursorMode, glfw.CursorNormal)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorVisible returns the visibility status of the mouse cursor.
|
// CursorVisible returns the visibility status of the mouse cursor.
|
||||||
|
@ -347,6 +338,28 @@ func (w *Window) CursorVisible() bool {
|
||||||
return w.cursorVisible
|
return w.cursorVisible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetCursorDisabled both hides the cursor, as well as limits cursor movement to the Window client area.
|
||||||
|
func (w *Window) SetCursorDisabled(disabled bool) {
|
||||||
|
w.cursorDisabled = disabled
|
||||||
|
mainthread.Call(func() {
|
||||||
|
if disabled {
|
||||||
|
w.cursorVisible = false
|
||||||
|
w.window.SetInputMode(glfw.CursorMode, glfw.CursorDisabled)
|
||||||
|
} else {
|
||||||
|
if w.cursorVisible {
|
||||||
|
w.window.SetInputMode(glfw.CursorMode, glfw.CursorNormal)
|
||||||
|
} else {
|
||||||
|
w.window.SetInputMode(glfw.CursorMode, glfw.CursorHidden)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CursorDisabled returns the disabled status of the mouse cursor.
|
||||||
|
func (w *Window) CursorDisabled() bool {
|
||||||
|
return w.cursorDisabled
|
||||||
|
}
|
||||||
|
|
||||||
// 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 {
|
||||||
|
|
Loading…
Reference in New Issue