mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
ui: Add SetCursorVisibility (#258)
This commit is contained in:
parent
417112c586
commit
cd885ce7c5
@ -142,6 +142,20 @@ func ScreenScale() float64 {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetCursorVisibility(visible bool) {
|
||||||
|
// This can be called before Run: change the state asyncly.
|
||||||
|
go func() {
|
||||||
|
_ = currentUI.runOnMainThread(func() error {
|
||||||
|
c := glfw.CursorNormal
|
||||||
|
if !visible {
|
||||||
|
c = glfw.CursorHidden
|
||||||
|
}
|
||||||
|
currentUI.window.SetInputMode(glfw.CursorMode, c)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func Run(width, height int, scale float64, title string, g GraphicsContext) error {
|
func Run(width, height int, scale float64, title string, g GraphicsContext) error {
|
||||||
u := currentUI
|
u := currentUI
|
||||||
// GLContext must be created before setting the screen size, which requires
|
// GLContext must be created before setting the screen size, which requires
|
||||||
|
@ -57,6 +57,14 @@ func ScreenScale() float64 {
|
|||||||
return currentUI.scale
|
return currentUI.scale
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetCursorVisibility(visibility bool) {
|
||||||
|
if visibility {
|
||||||
|
canvas.Get("style").Set("cursor", "auto")
|
||||||
|
} else {
|
||||||
|
canvas.Get("style").Set("cursor", "none")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (u *userInterface) actualScreenScale() float64 {
|
func (u *userInterface) actualScreenScale() float64 {
|
||||||
return u.scale * u.deviceScale
|
return u.scale * u.deviceScale
|
||||||
}
|
}
|
||||||
|
@ -112,6 +112,10 @@ func ScreenScale() float64 {
|
|||||||
return currentUI.scale
|
return currentUI.scale
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetCursorVisibility(visibility bool) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
func (u *userInterface) actualScreenScale() float64 {
|
func (u *userInterface) actualScreenScale() float64 {
|
||||||
return u.scale * deviceScale()
|
return u.scale * deviceScale()
|
||||||
}
|
}
|
||||||
|
7
run.go
7
run.go
@ -153,3 +153,10 @@ func ScreenScale() float64 {
|
|||||||
}
|
}
|
||||||
return ui.ScreenScale()
|
return ui.ScreenScale()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetCursorVisibility changes the state of cursor visiblity.
|
||||||
|
//
|
||||||
|
// This function is concurrent-safe.
|
||||||
|
func SetCursorVisibility(visible bool) {
|
||||||
|
ui.SetCursorVisibility(visible)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user