mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
internal/ui: bug fix: recover the cursor shape when the cursor is visible
Closes #2527
This commit is contained in:
parent
86fa9366f7
commit
95f1ef0fb9
@ -21,6 +21,7 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||
)
|
||||
|
||||
@ -36,13 +37,24 @@ type Game struct {
|
||||
|
||||
func (g *Game) Update() error {
|
||||
pt := image.Pt(ebiten.CursorPosition())
|
||||
cursor := ebiten.CursorShapeDefault
|
||||
for r, c := range g.grids {
|
||||
if pt.In(r) {
|
||||
ebiten.SetCursorShape(c)
|
||||
return nil
|
||||
cursor = c
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -614,6 +614,9 @@ func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
|
||||
}
|
||||
u.mainThread.Call(func() {
|
||||
u.window.SetInputMode(glfw.CursorMode, driverCursorModeToGLFWCursorMode(mode))
|
||||
if mode == CursorModeVisible {
|
||||
u.setNativeCursor(u.getCursorShape())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user