input: Bug fix: runeBuffer should be reset on each frame

This commit is contained in:
Hajime Hoshi 2017-11-10 01:18:41 +09:00
parent 4b83a060fe
commit cea9bd5a19
6 changed files with 12 additions and 9 deletions

View File

@ -97,7 +97,7 @@ func drawWithFittingScale(dst *Image, src *Image) {
_ = dst.DrawImage(src, op) _ = dst.DrawImage(src, op)
} }
func (c *graphicsContext) Update(updateCount int) error { func (c *graphicsContext) Update(updateCount int, afterFrameUpdate func()) error {
if err := c.initializeIfNeeded(); err != nil { if err := c.initializeIfNeeded(); err != nil {
return err return err
} }
@ -107,6 +107,7 @@ func (c *graphicsContext) Update(updateCount int) error {
if err := c.f(c.offscreen); err != nil { if err := c.f(c.offscreen); err != nil {
return err return err
} }
afterFrameUpdate()
} }
if 0 < updateCount { if 0 < updateCount {
drawWithFittingScale(c.offscreen2, c.offscreen) drawWithFittingScale(c.offscreen2, c.offscreen)

View File

@ -16,7 +16,7 @@ package ui
type GraphicsContext interface { type GraphicsContext interface {
SetSize(width, height int, scale float64) SetSize(width, height int, scale float64)
Update() error Update(afterFrameUpdate func()) error
Invalidate() Invalidate()
} }

View File

@ -476,10 +476,11 @@ func (u *userInterface) update(g GraphicsContext) error {
} }
return nil return nil
}) })
if err := g.Update(); err != nil { if err := g.Update(func() {
currentInput.runeBuffer = currentInput.runeBuffer[:0]
}); err != nil {
return err return err
} }
currentInput.runeBuffer = currentInput.runeBuffer[:0]
return nil return nil
} }

View File

@ -136,10 +136,11 @@ func (u *userInterface) update(g GraphicsContext) error {
g.SetSize(u.width, u.height, u.actualScreenScale()) g.SetSize(u.width, u.height, u.actualScreenScale())
return nil return nil
} }
if err := g.Update(); err != nil { if err := g.Update(func() {
currentInput.runeBuffer = nil
}); err != nil {
return err return err
} }
currentInput.runeBuffer = nil
return nil return nil
} }

View File

@ -87,7 +87,7 @@ func (u *userInterface) update(g GraphicsContext) error {
g.SetSize(u.width, u.height, u.actualScreenScale()) g.SetSize(u.width, u.height, u.actualScreenScale())
return nil return nil
} }
if err := g.Update(); err != nil { if err := g.Update(func() {}); err != nil {
return err return err
} }
return nil return nil

4
run.go
View File

@ -78,9 +78,9 @@ func (u *updater) SetSize(width, height int, scale float64) {
u.g.SetSize(width, height, scale) u.g.SetSize(width, height, scale)
} }
func (u *updater) Update() error { func (u *updater) Update(afterFrameUpdate func()) error {
n := clock.Update() n := clock.Update()
if err := u.g.Update(n); err != nil { if err := u.g.Update(n, afterFrameUpdate); err != nil {
return err return err
} }
return nil return nil