diff --git a/example/blocks/game.go b/example/blocks/game.go index d4b1de451..9798ba325 100644 --- a/example/blocks/game.go +++ b/example/blocks/game.go @@ -65,7 +65,7 @@ func (game *Game) Update(state ui.InputState) { if !game.isInitialized() { return } - game.input.Update(state.PressedKeys()) + game.input.Update(state) game.sceneManager.Update(&GameState{ SceneManager: game.sceneManager, Input: game.input, diff --git a/example/blocks/input.go b/example/blocks/input.go index 9a399e363..17536379b 100644 --- a/example/blocks/input.go +++ b/example/blocks/input.go @@ -22,9 +22,9 @@ func (i *Input) StateForKey(key ui.Key) int { return i.states[key] } -func (i *Input) Update(keys ui.Keys) { +func (i *Input) Update(inputState ui.InputState) { for key := range i.states { - if !keys.Includes(key) { + if !inputState.IsPressedKey(key) { i.states[key] = 0 continue } diff --git a/ui/glfw/inputstate.go b/ui/glfw/inputstate.go index ce931364d..9b447cdb7 100644 --- a/ui/glfw/inputstate.go +++ b/ui/glfw/inputstate.go @@ -38,8 +38,8 @@ func newInputState() *InputState { } } -func (i *InputState) PressedKeys() ui.Keys { - return i.pressedKeys +func (i *InputState) IsPressedKey(key ui.Key) bool { + return i.pressedKeys.Includes(key) } func (i *InputState) MouseX() int { diff --git a/ui/glfw/ui.go b/ui/glfw/ui.go index 51baf5052..3a03bf91b 100644 --- a/ui/glfw/ui.go +++ b/ui/glfw/ui.go @@ -2,7 +2,6 @@ package glfw import ( glfw "github.com/go-gl/glfw3" - "github.com/hajimehoshi/ebiten/graphics" "github.com/hajimehoshi/ebiten/ui" "log" ) @@ -17,13 +16,13 @@ type UI struct { canvas *Canvas } -func (u *UI) Start(width, height, scale int, title string) (ui.Canvas, graphics.TextureFactory) { +func (u *UI) Start(width, height, scale int, title string) ui.Canvas { if !glfw.Init() { panic("glfw.Init() fails") } glfw.WindowHint(glfw.Resizable, glfw.False) u.canvas = NewCanvas(width, height, scale, title) - return u.canvas, u.canvas + return u.canvas } func (u *UI) DoEvents() { diff --git a/ui/run.go b/ui/run.go index ca610b157..3028e97d5 100644 --- a/ui/run.go +++ b/ui/run.go @@ -15,8 +15,8 @@ type Game interface { } func Run(u UI, game Game, width, height, scale int, title string, fps int) { - canvas, textureFactory := u.Start(width, height, scale, title) - game.SetTextureFactory(textureFactory) + canvas := u.Start(width, height, scale, title) + game.SetTextureFactory(canvas) frameTime := time.Duration(int64(time.Second) / int64(fps)) tick := time.Tick(frameTime) diff --git a/ui/ui.go b/ui/ui.go index f13198d48..4fdea5892 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -16,22 +16,19 @@ const ( ) type UI interface { - Start(widht, height, scale int, title string) (Canvas, graphics.TextureFactory) + Start(widht, height, scale int, title string) Canvas DoEvents() Terminate() } -type Keys interface { - Includes(key Key) bool -} - type InputState interface { - PressedKeys() Keys + IsPressedKey(key Key) bool MouseX() int MouseY() int } type Canvas interface { + graphics.TextureFactory Draw(func(graphics.Context)) IsClosed() bool InputState() InputState