internal/ui: bug fix: recover the cursor shape when the cursor is visible

Closes #2527
This commit is contained in:
Hajime Hoshi 2023-01-07 20:03:17 +09:00
parent 86fa9366f7
commit 95f1ef0fb9
2 changed files with 18 additions and 3 deletions

View File

@ -21,6 +21,7 @@ import (
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/vector" "github.com/hajimehoshi/ebiten/v2/vector"
) )
@ -36,13 +37,24 @@ type Game struct {
func (g *Game) Update() error { func (g *Game) Update() error {
pt := image.Pt(ebiten.CursorPosition()) pt := image.Pt(ebiten.CursorPosition())
cursor := ebiten.CursorShapeDefault
for r, c := range g.grids { for r, c := range g.grids {
if pt.In(r) { if pt.In(r) {
ebiten.SetCursorShape(c) cursor = c
return nil break
} }
} }
ebiten.SetCursorShape(ebiten.CursorShapeDefault) ebiten.SetCursorShape(cursor)
if inpututil.IsKeyJustPressed(ebiten.KeyC) {
switch ebiten.CursorMode() {
case ebiten.CursorModeVisible:
ebiten.SetCursorMode(ebiten.CursorModeHidden)
case ebiten.CursorModeHidden:
ebiten.SetCursorMode(ebiten.CursorModeVisible)
}
}
return nil return nil
} }

View File

@ -614,6 +614,9 @@ func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
} }
u.mainThread.Call(func() { u.mainThread.Call(func() {
u.window.SetInputMode(glfw.CursorMode, driverCursorModeToGLFWCursorMode(mode)) u.window.SetInputMode(glfw.CursorMode, driverCursorModeToGLFWCursorMode(mode))
if mode == CursorModeVisible {
u.setNativeCursor(u.getCursorShape())
}
}) })
} }