Compare commits

..

2 Commits

Author SHA1 Message Date
Hajime Hoshi
6f3f567b58 internal/ui: bug fix: recover the cursor mode when capturing fails
Closes #2764
2024-09-15 18:34:13 +09:00
Hajime Hoshi
429e0d8183 ebiten: refactoring 2024-09-15 18:01:53 +09:00
3 changed files with 22 additions and 18 deletions

View File

@ -44,3 +44,21 @@ const (
CursorShapeMove CursorShapeType = CursorShapeType(ui.CursorShapeMove) CursorShapeMove CursorShapeType = CursorShapeType(ui.CursorShapeMove)
CursorShapeNotAllowed CursorShapeType = CursorShapeType(ui.CursorShapeNotAllowed) CursorShapeNotAllowed CursorShapeType = CursorShapeType(ui.CursorShapeNotAllowed)
) )
// CursorShape returns the current cursor shape.
//
// CursorShape returns CursorShapeDefault on mobiles.
//
// CursorShape is concurrent-safe.
func CursorShape() CursorShapeType {
return CursorShapeType(ui.Get().CursorShape())
}
// SetCursorShape sets the cursor shape.
//
// If the platform doesn't implement the given shape, the default cursor shape is used.
//
// SetCursorShape is concurrent-safe.
func SetCursorShape(shape CursorShapeType) {
ui.Get().SetCursorShape(ui.CursorShape(shape))
}

View File

@ -539,6 +539,10 @@ func (u *UserInterface) init() error {
})) }))
document.Call("addEventListener", "pointerlockerror", js.FuncOf(func(this js.Value, args []js.Value) any { document.Call("addEventListener", "pointerlockerror", js.FuncOf(func(this js.Value, args []js.Value) any {
js.Global().Get("console").Call("error", "pointerlockerror event is fired. 'sandbox=\"allow-pointer-lock\"' might be required at an iframe. This function on browsers must be called as a result of a gestural interaction or orientation change.") js.Global().Get("console").Call("error", "pointerlockerror event is fired. 'sandbox=\"allow-pointer-lock\"' might be required at an iframe. This function on browsers must be called as a result of a gestural interaction or orientation change.")
if u.cursorMode == CursorModeCaptured {
u.recoverCursorMode()
}
u.recoverCursorPosition()
return nil return nil
})) }))
document.Call("addEventListener", "fullscreenerror", js.FuncOf(func(this js.Value, args []js.Value) any { document.Call("addEventListener", "fullscreenerror", js.FuncOf(func(this js.Value, args []js.Value) any {

18
run.go
View File

@ -409,24 +409,6 @@ func SetCursorMode(mode CursorModeType) {
ui.Get().SetCursorMode(ui.CursorMode(mode)) ui.Get().SetCursorMode(ui.CursorMode(mode))
} }
// CursorShape returns the current cursor shape.
//
// CursorShape returns CursorShapeDefault on mobiles.
//
// CursorShape is concurrent-safe.
func CursorShape() CursorShapeType {
return CursorShapeType(ui.Get().CursorShape())
}
// SetCursorShape sets the cursor shape.
//
// If the platform doesn't implement the given shape, the default cursor shape is used.
//
// SetCursorShape is concurrent-safe.
func SetCursorShape(shape CursorShapeType) {
ui.Get().SetCursorShape(ui.CursorShape(shape))
}
// IsFullscreen reports whether the current mode is fullscreen or not. // IsFullscreen reports whether the current mode is fullscreen or not.
// //
// IsFullscreen always returns false on mobiles. // IsFullscreen always returns false on mobiles.