mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/ui: merge a window-closing state into an input state
This commit is contained in:
parent
d37aadd064
commit
d53803615a
7
input.go
7
input.go
@ -476,3 +476,10 @@ func (i *inputState) touchPosition(id TouchID) (int, int) {
|
|||||||
}
|
}
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *inputState) windowBeingClosed() bool {
|
||||||
|
i.m.Lock()
|
||||||
|
defer i.m.Unlock()
|
||||||
|
|
||||||
|
return i.state.WindowBeingClosed
|
||||||
|
}
|
||||||
|
@ -143,8 +143,6 @@ func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, update
|
|||||||
if err := theGlobalState.error(); err != nil {
|
if err := theGlobalState.error(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.resetForTick()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update window icons during a frame, since an icon might be *ebiten.Image and
|
// Update window icons during a frame, since an icon might be *ebiten.Image and
|
||||||
|
@ -48,12 +48,14 @@ type InputState struct {
|
|||||||
Touches [16]Touch
|
Touches [16]Touch
|
||||||
Runes [16]rune
|
Runes [16]rune
|
||||||
RunesCount int
|
RunesCount int
|
||||||
|
WindowBeingClosed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *InputState) resetForTick() {
|
func (i *InputState) reset() {
|
||||||
i.WheelX = 0
|
i.WheelX = 0
|
||||||
i.WheelY = 0
|
i.WheelY = 0
|
||||||
i.RunesCount = 0
|
i.RunesCount = 0
|
||||||
|
i.WindowBeingClosed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *InputState) appendRune(r rune) {
|
func (i *InputState) appendRune(r rune) {
|
||||||
|
@ -66,7 +66,6 @@ type userInterfaceImpl struct {
|
|||||||
iconImages []image.Image
|
iconImages []image.Image
|
||||||
cursorShape CursorShape
|
cursorShape CursorShape
|
||||||
windowClosingHandled bool
|
windowClosingHandled bool
|
||||||
windowBeingClosed bool
|
|
||||||
windowResizingMode WindowResizingMode
|
windowResizingMode WindowResizingMode
|
||||||
inFrame uint32
|
inFrame uint32
|
||||||
|
|
||||||
@ -472,13 +471,6 @@ func (u *userInterfaceImpl) setWindowClosingHandled(handled bool) {
|
|||||||
u.m.Unlock()
|
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) {
|
func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return u.initFullscreenWidthInDIP, u.initFullscreenHeightInDIP
|
return u.initFullscreenWidthInDIP, u.initFullscreenHeightInDIP
|
||||||
@ -713,7 +705,7 @@ func (u *userInterfaceImpl) registerWindowCloseCallback() {
|
|||||||
if u.closeCallback == nil {
|
if u.closeCallback == nil {
|
||||||
u.closeCallback = glfw.ToCloseCallback(func(_ *glfw.Window) {
|
u.closeCallback = glfw.ToCloseCallback(func(_ *glfw.Window) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
u.windowBeingClosed = true
|
u.inputState.WindowBeingClosed = true
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
|
|
||||||
if !u.isWindowClosingHandled() {
|
if !u.isWindowClosingHandled() {
|
||||||
@ -1346,17 +1338,11 @@ func monitorFromWindow(window *glfw.Window) *glfw.Monitor {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) resetForTick() {
|
|
||||||
u.m.Lock()
|
|
||||||
defer u.m.Unlock()
|
|
||||||
u.windowBeingClosed = false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
|
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
*inputState = u.inputState
|
*inputState = u.inputState
|
||||||
u.inputState.resetForTick()
|
u.inputState.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) Window() Window {
|
func (u *userInterfaceImpl) Window() Window {
|
||||||
|
@ -677,10 +677,7 @@ func (u *userInterfaceImpl) updateScreenSize() {
|
|||||||
|
|
||||||
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
|
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
|
||||||
*inputState = u.inputState
|
*inputState = u.inputState
|
||||||
u.inputState.resetForTick()
|
u.inputState.reset()
|
||||||
}
|
|
||||||
|
|
||||||
func (u *userInterfaceImpl) resetForTick() {
|
|
||||||
u.keyboardLayoutMap = js.Value{}
|
u.keyboardLayoutMap = js.Value{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,10 +422,7 @@ func (u *userInterfaceImpl) readInputState(inputState *InputState) {
|
|||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
*inputState = u.inputState
|
*inputState = u.inputState
|
||||||
u.inputState.resetForTick()
|
u.inputState.reset()
|
||||||
}
|
|
||||||
|
|
||||||
func (u *userInterfaceImpl) resetForTick() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) Window() Window {
|
func (u *userInterfaceImpl) Window() Window {
|
||||||
|
@ -150,10 +150,7 @@ func (*userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
|
|||||||
|
|
||||||
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
|
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
|
||||||
*inputState = u.inputState
|
*inputState = u.inputState
|
||||||
u.inputState.resetForTick()
|
u.inputState.reset()
|
||||||
}
|
|
||||||
|
|
||||||
func (u *userInterfaceImpl) resetForTick() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*userInterfaceImpl) CursorMode() CursorMode {
|
func (*userInterfaceImpl) CursorMode() CursorMode {
|
||||||
|
@ -38,7 +38,6 @@ type Window interface {
|
|||||||
SetIcon(iconImages []image.Image)
|
SetIcon(iconImages []image.Image)
|
||||||
SetTitle(title string)
|
SetTitle(title string)
|
||||||
Restore()
|
Restore()
|
||||||
IsBeingClosed() bool
|
|
||||||
SetClosingHandled(handled bool)
|
SetClosingHandled(handled bool)
|
||||||
IsClosingHandled() bool
|
IsClosingHandled() bool
|
||||||
}
|
}
|
||||||
@ -110,10 +109,6 @@ func (*nullWindow) SetTitle(title string) {
|
|||||||
func (*nullWindow) Restore() {
|
func (*nullWindow) Restore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*nullWindow) IsBeingClosed() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*nullWindow) SetClosingHandled(handled bool) {
|
func (*nullWindow) SetClosingHandled(handled bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
func (w *glfwWindow) SetClosingHandled(handled bool) {
|
||||||
w.ui.setWindowClosingHandled(handled)
|
w.ui.setWindowClosingHandled(handled)
|
||||||
}
|
}
|
||||||
|
@ -294,7 +294,7 @@ func RestoreWindow() {
|
|||||||
//
|
//
|
||||||
// IsWindowBeingClosed is concurrent-safe.
|
// IsWindowBeingClosed is concurrent-safe.
|
||||||
func IsWindowBeingClosed() bool {
|
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.
|
// SetWindowClosingHandled sets whether the window closing is handled or not on desktops. The default state is false.
|
||||||
|
Loading…
Reference in New Issue
Block a user