examples/windowsize: Enable to switch CursorMode

This commit is contained in:
Hajime Hoshi 2021-04-11 03:33:02 +09:00
parent 7934c3b22b
commit 3043c6cb8e

View File

@ -119,7 +119,7 @@ func (g *game) Update() error {
fullscreen := ebiten.IsFullscreen() fullscreen := ebiten.IsFullscreen()
runnableOnUnfocused := ebiten.IsRunnableOnUnfocused() runnableOnUnfocused := ebiten.IsRunnableOnUnfocused()
cursorVisible := ebiten.CursorMode() == ebiten.CursorModeVisible cursorMode := ebiten.CursorMode()
vsyncEnabled := ebiten.IsVsyncEnabled() vsyncEnabled := ebiten.IsVsyncEnabled()
tps := ebiten.MaxTPS() tps := ebiten.MaxTPS()
decorated := ebiten.IsWindowDecorated() decorated := ebiten.IsWindowDecorated()
@ -186,7 +186,14 @@ func (g *game) Update() error {
runnableOnUnfocused = !runnableOnUnfocused runnableOnUnfocused = !runnableOnUnfocused
} }
if inpututil.IsKeyJustPressed(ebiten.KeyC) { if inpututil.IsKeyJustPressed(ebiten.KeyC) {
cursorVisible = !cursorVisible switch cursorMode {
case ebiten.CursorModeVisible:
cursorMode = ebiten.CursorModeHidden
case ebiten.CursorModeHidden:
cursorMode = ebiten.CursorModeCaptured
case ebiten.CursorModeCaptured:
cursorMode = ebiten.CursorModeVisible
}
} }
if inpututil.IsKeyJustPressed(ebiten.KeyV) { if inpututil.IsKeyJustPressed(ebiten.KeyV) {
vsyncEnabled = !vsyncEnabled vsyncEnabled = !vsyncEnabled
@ -231,11 +238,7 @@ func (g *game) Update() error {
} }
ebiten.SetFullscreen(fullscreen) ebiten.SetFullscreen(fullscreen)
ebiten.SetRunnableOnUnfocused(runnableOnUnfocused) ebiten.SetRunnableOnUnfocused(runnableOnUnfocused)
if cursorVisible { ebiten.SetCursorMode(cursorMode)
ebiten.SetCursorMode(ebiten.CursorModeVisible)
} else {
ebiten.SetCursorMode(ebiten.CursorModeHidden)
}
// Set vsync enabled only when this is needed. // Set vsync enabled only when this is needed.
// This makes a bug around vsync initialization more explicit (#1364). // This makes a bug around vsync initialization more explicit (#1364).
@ -306,7 +309,7 @@ func (g *game) Draw(screen *ebiten.Image) {
%s %s
[F] Switch the fullscreen state (only for desktops) [F] Switch the fullscreen state (only for desktops)
[U] Switch the runnable-on-unfocused state [U] Switch the runnable-on-unfocused state
[C] Switch the cursor visibility [C] Switch the cursor mode (visible, hidden, or captured)
[I] Change the window icon (only for desktops) [I] Change the window icon (only for desktops)
[V] Switch vsync [V] Switch vsync
[T] Switch TPS (ticks per second) [T] Switch TPS (ticks per second)