mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/ui: call updateInputState after layoutGame
The cursor position is affected by the current layout. Then, input states should be updated after layoutGame is called. Updates #2763
This commit is contained in:
parent
a62b8a00e7
commit
8c25b07336
@ -118,6 +118,11 @@ func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, update
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update the input state after the layout is updated as a cursor position is affected by the layout.
|
||||
if err := ui.updateInputState(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Ensure that Update is called once before Draw so that Update can be used for initialization.
|
||||
if !c.updateCalled && updateCount == 0 {
|
||||
updateCount = 1
|
||||
|
@ -224,3 +224,8 @@ func (u *userInterfaceImpl) keyName(key Key) string {
|
||||
func UpdateInputFromEvent(e js.Value) {
|
||||
theUI.updateInputFromEvent(e)
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) updateInputState() error {
|
||||
// TODO: Adjust cursor and touch positions based on the latest layout.
|
||||
return nil
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ type TouchForInput struct {
|
||||
Y float64
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) updateInputState(keys map[Key]struct{}, runes []rune, touches []TouchForInput) {
|
||||
func (u *userInterfaceImpl) updateInputStateFromOutside(keys map[Key]struct{}, runes []rune, touches []TouchForInput) {
|
||||
u.m.Lock()
|
||||
defer u.m.Unlock()
|
||||
|
||||
@ -48,6 +48,11 @@ func (u *userInterfaceImpl) updateInputState(keys map[Key]struct{}, runes []rune
|
||||
}
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) updateInputState() error {
|
||||
// TODO: Adjust cursor and touch positions based on the latest layout.
|
||||
return nil
|
||||
}
|
||||
|
||||
func KeyName(key Key) string {
|
||||
// TODO: Implement this.
|
||||
return ""
|
||||
|
@ -25,7 +25,23 @@ package ui
|
||||
// const int kScreenHeight = 1080;
|
||||
import "C"
|
||||
|
||||
func (u *userInterfaceImpl) updateInputState() {
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
||||
)
|
||||
|
||||
func (u *userInterfaceImpl) updateInputState() error {
|
||||
var ferr error
|
||||
u.mainThread.Call(func() {
|
||||
if err := gamepad.Update(); err != nil {
|
||||
ferr = err
|
||||
return
|
||||
}
|
||||
u.updateInputStateImpl()
|
||||
})
|
||||
return ferr
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) updateInputStateImpl() {
|
||||
C.ebitengine_UpdateTouches()
|
||||
|
||||
u.nativeTouches = u.nativeTouches[:0]
|
||||
|
@ -1140,9 +1140,6 @@ func (u *userInterfaceImpl) update() (float64, float64, error) {
|
||||
} else {
|
||||
glfw.WaitEvents()
|
||||
}
|
||||
if err := u.updateInputState(); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
// In the initial state on macOS, the window is not shown (#2620).
|
||||
for u.window.GetAttrib(glfw.Visible) != 0 && !u.isRunnableOnUnfocused() && u.window.GetAttrib(glfw.Focused) == 0 && !u.window.ShouldClose() {
|
||||
|
@ -219,7 +219,7 @@ func (u *userInterfaceImpl) appMain(a app.App) {
|
||||
for _, t := range touches {
|
||||
ts = append(ts, t)
|
||||
}
|
||||
u.updateInputState(keys, runes, ts)
|
||||
u.updateInputStateFromOutside(keys, runes, ts)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -451,7 +451,7 @@ func (u *userInterfaceImpl) Monitor() *Monitor {
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) UpdateInput(keys map[Key]struct{}, runes []rune, touches []TouchForInput) {
|
||||
u.updateInputState(keys, runes, touches)
|
||||
u.updateInputStateFromOutside(keys, runes, touches)
|
||||
if u.fpsMode == FPSModeVsyncOffMinimum {
|
||||
u.renderRequester.RequestRenderIfNeeded()
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import (
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
||||
@ -117,11 +116,6 @@ func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
|
||||
for {
|
||||
recordProfilerHeartbeat()
|
||||
|
||||
u.mainThread.Call(func() {
|
||||
gamepad.Update()
|
||||
u.updateInputState()
|
||||
})
|
||||
|
||||
if err := u.context.updateFrame(u.graphicsDriver, float64(C.kScreenWidth), float64(C.kScreenHeight), deviceScaleFactor, u, func() {
|
||||
u.egl.swapBuffers()
|
||||
}); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user