loop: Refactoring: Create updater struct

This commit is contained in:
Hajime Hoshi 2017-08-05 21:06:25 +09:00
parent eef8289854
commit 4ee0c9b482

18
run.go
View File

@ -65,7 +65,7 @@ type runner struct {
} }
func (r *runner) Run(width, height int, scale float64, title string) error { func (r *runner) Run(width, height int, scale float64, title string) error {
if err := ui.Run(width, height, scale, title, r); err != nil { if err := ui.Run(width, height, scale, title, &updater{r.g}); err != nil {
if _, ok := err.(*ui.RegularTermination); ok { if _, ok := err.(*ui.RegularTermination); ok {
return nil return nil
} }
@ -74,16 +74,20 @@ func (r *runner) Run(width, height int, scale float64, title string) error {
return nil return nil
} }
func (r *runner) SetSize(width, height int, scale float64) { type updater struct {
r.g.SetSize(width, height, scale) g *graphicsContext
} }
func (r *runner) Update() error { func (u *updater) SetSize(width, height int, scale float64) {
return loop.Update(r.g) u.g.SetSize(width, height, scale)
} }
func (r *runner) Invalidate() { func (u *updater) Update() error {
r.g.Invalidate() return loop.Update(u.g)
}
func (u *updater) Invalidate() {
u.g.Invalidate()
} }
// Run runs the game. // Run runs the game.