Replaced SetCursorMode() with SetCursorDisabled()

This commit is contained in:
theGeekPirate 2017-10-27 13:19:59 -07:00 committed by GitHub
parent bec153a1b5
commit ec0dbe4fc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 32 deletions

View File

@ -318,41 +318,14 @@ func (w *Window) VSync() bool {
return w.vsync
}
// cursorMode uses magic numbers from https://github.com/glfw/glfw/blob/32e78aeb2edb5cb5add36ae575fc914f6c4fc7e5/include/GLFW/glfw3.h#L966
type cursorMode int
const (
// CursorNormal displays the regular cursor (or another set with glfw.SetCursor()), and
// does not limit cursor motion.
CursorNormal cursorMode = 0x00034001
// CursorHidden hides the cursor, and does not limit cursor motion.
CursorHidden cursorMode = 0x00034002
// CursorDisabled both hides the cursor, as well as limits cursor movement to the window.
CursorDisabled cursorMode = 0x00034003
)
// SetCursorMode determines how the mouse cursor appears and behaves.
func (w *Window) SetCursorMode(cm cursorMode) {
// SetCursorDisabled both hides the cursor, as well as limits cursor movement to the Window client area.
func (w *Window) SetCursorDisabled(disabled bool) {
w.cursorVisible = false
mainthread.Call(func() {
switch cm {
case CursorNormal:
w.window.SetInputMode(glfw.CursorMode, glfw.CursorNormal)
case CursorHidden:
w.window.SetInputMode(glfw.CursorMode, glfw.CursorHidden)
case CursorDisabled:
if disabled {
w.window.SetInputMode(glfw.CursorMode, glfw.CursorDisabled)
}
})
}
// 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.SetInputMode(glfw.CursorMode, glfw.CursorNormal)
} else {
w.window.SetInputMode(glfw.CursorMode, glfw.CursorHidden)
w.window.SetInputMode(glfw.CursorMode, glfw.CursorNormal)
}
})
}