internal/ui: merge a window-closing state into an input state

This commit is contained in:
Hajime Hoshi 2023-01-21 23:34:20 +09:00
parent d37aadd064
commit d53803615a
10 changed files with 16 additions and 41 deletions

View File

@ -476,3 +476,10 @@ func (i *inputState) touchPosition(id TouchID) (int, int) {
}
return 0, 0
}
func (i *inputState) windowBeingClosed() bool {
i.m.Lock()
defer i.m.Unlock()
return i.state.WindowBeingClosed
}

View File

@ -143,8 +143,6 @@ func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, update
if err := theGlobalState.error(); err != nil {
return err
}
ui.resetForTick()
}
// Update window icons during a frame, since an icon might be *ebiten.Image and

View File

@ -48,12 +48,14 @@ type InputState struct {
Touches [16]Touch
Runes [16]rune
RunesCount int
WindowBeingClosed bool
}
func (i *InputState) resetForTick() {
func (i *InputState) reset() {
i.WheelX = 0
i.WheelY = 0
i.RunesCount = 0
i.WindowBeingClosed = false
}
func (i *InputState) appendRune(r rune) {

View File

@ -66,7 +66,6 @@ type userInterfaceImpl struct {
iconImages []image.Image
cursorShape CursorShape
windowClosingHandled bool
windowBeingClosed bool
windowResizingMode WindowResizingMode
inFrame uint32
@ -472,13 +471,6 @@ func (u *userInterfaceImpl) setWindowClosingHandled(handled bool) {
u.m.Unlock()
}
func (u *userInterfaceImpl) isWindowBeingClosed() bool {
u.m.RLock()
v := u.windowBeingClosed
u.m.RUnlock()
return v
}
func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
if !u.isRunning() {
return u.initFullscreenWidthInDIP, u.initFullscreenHeightInDIP
@ -713,7 +705,7 @@ func (u *userInterfaceImpl) registerWindowCloseCallback() {
if u.closeCallback == nil {
u.closeCallback = glfw.ToCloseCallback(func(_ *glfw.Window) {
u.m.Lock()
u.windowBeingClosed = true
u.inputState.WindowBeingClosed = true
u.m.Unlock()
if !u.isWindowClosingHandled() {
@ -1346,17 +1338,11 @@ func monitorFromWindow(window *glfw.Window) *glfw.Monitor {
return nil
}
func (u *userInterfaceImpl) resetForTick() {
u.m.Lock()
defer u.m.Unlock()
u.windowBeingClosed = false
}
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
u.m.Lock()
defer u.m.Unlock()
*inputState = u.inputState
u.inputState.resetForTick()
u.inputState.reset()
}
func (u *userInterfaceImpl) Window() Window {

View File

@ -677,10 +677,7 @@ func (u *userInterfaceImpl) updateScreenSize() {
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
*inputState = u.inputState
u.inputState.resetForTick()
}
func (u *userInterfaceImpl) resetForTick() {
u.inputState.reset()
u.keyboardLayoutMap = js.Value{}
}

View File

@ -422,10 +422,7 @@ func (u *userInterfaceImpl) readInputState(inputState *InputState) {
u.m.Lock()
defer u.m.Unlock()
*inputState = u.inputState
u.inputState.resetForTick()
}
func (u *userInterfaceImpl) resetForTick() {
u.inputState.reset()
}
func (u *userInterfaceImpl) Window() Window {

View File

@ -150,10 +150,7 @@ func (*userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
*inputState = u.inputState
u.inputState.resetForTick()
}
func (u *userInterfaceImpl) resetForTick() {
u.inputState.reset()
}
func (*userInterfaceImpl) CursorMode() CursorMode {

View File

@ -38,7 +38,6 @@ type Window interface {
SetIcon(iconImages []image.Image)
SetTitle(title string)
Restore()
IsBeingClosed() bool
SetClosingHandled(handled bool)
IsClosingHandled() bool
}
@ -110,10 +109,6 @@ func (*nullWindow) SetTitle(title string) {
func (*nullWindow) Restore() {
}
func (*nullWindow) IsBeingClosed() bool {
return false
}
func (*nullWindow) SetClosingHandled(handled bool) {
}

View File

@ -253,10 +253,6 @@ func (w *glfwWindow) SetTitle(title string) {
})
}
func (w *glfwWindow) IsBeingClosed() bool {
return w.ui.isWindowBeingClosed()
}
func (w *glfwWindow) SetClosingHandled(handled bool) {
w.ui.setWindowClosingHandled(handled)
}

View File

@ -294,7 +294,7 @@ func RestoreWindow() {
//
// IsWindowBeingClosed is concurrent-safe.
func IsWindowBeingClosed() bool {
return ui.Get().Window().IsBeingClosed()
return theInputState.windowBeingClosed()
}
// SetWindowClosingHandled sets whether the window closing is handled or not on desktops. The default state is false.