From 95f1ef0fb9d2477038717d0260a1860cd78aba33 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 7 Jan 2023 20:03:17 +0900 Subject: [PATCH] internal/ui: bug fix: recover the cursor shape when the cursor is visible Closes #2527 --- examples/cursor/main.go | 18 +++++++++++++++--- internal/ui/ui_glfw.go | 3 +++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/examples/cursor/main.go b/examples/cursor/main.go index 841ad6244..48e1cd9ed 100644 --- a/examples/cursor/main.go +++ b/examples/cursor/main.go @@ -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 } diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 16c8e84ca..78ef7ca97 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -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()) + } }) }