diff --git a/example/blocks/gamescene.go b/example/blocks/gamescene.go index 3890d7245..74ac911f4 100644 --- a/example/blocks/gamescene.go +++ b/example/blocks/gamescene.go @@ -3,7 +3,7 @@ package blocks import ( "github.com/hajimehoshi/ebiten/graphics" "github.com/hajimehoshi/ebiten/graphics/matrix" - "github.com/hajimehoshi/ebiten/ui" + "github.com/hajimehoshi/ebiten/input" "image/color" "math/rand" "time" @@ -64,26 +64,26 @@ func (s *GameScene) Update(state *GameState) { y := s.currentPieceY angle := s.currentPieceAngle moved := false - if state.Input.StateForKey(ui.KeySpace) == 1 { + if state.Input.StateForKey(input.KeySpace) == 1 { s.currentPieceAngle = s.field.RotatePieceRight(piece, x, y, angle) moved = angle != s.currentPieceAngle } - if l := state.Input.StateForKey(ui.KeyLeft); l == 1 || (10 <= l && l%2 == 0) { + if l := state.Input.StateForKey(input.KeyLeft); l == 1 || (10 <= l && l%2 == 0) { s.currentPieceX = s.field.MovePieceToLeft(piece, x, y, angle) moved = x != s.currentPieceX } - if r := state.Input.StateForKey(ui.KeyRight); r == 1 || (10 <= r && r%2 == 0) { + if r := state.Input.StateForKey(input.KeyRight); r == 1 || (10 <= r && r%2 == 0) { s.currentPieceX = s.field.MovePieceToRight(piece, x, y, angle) moved = y != s.currentPieceX } - if d := state.Input.StateForKey(ui.KeyDown); (d-1)%2 == 0 { + if d := state.Input.StateForKey(input.KeyDown); (d-1)%2 == 0 { s.currentPieceY = s.field.DropPiece(piece, x, y, angle) moved = y != s.currentPieceY } if moved { s.landingCount = 0 } else if !s.field.PieceDroppable(piece, x, y, angle) { - if 0 < state.Input.StateForKey(ui.KeyDown) { + if 0 < state.Input.StateForKey(input.KeyDown) { s.landingCount += 10 } else { s.landingCount++ diff --git a/example/blocks/input.go b/example/blocks/input.go index 626e129ec..4334a95da 100644 --- a/example/blocks/input.go +++ b/example/blocks/input.go @@ -1,16 +1,16 @@ package blocks import ( - "github.com/hajimehoshi/ebiten/ui" + "github.com/hajimehoshi/ebiten/input" ) type Input struct { - states map[ui.Key]int + states map[input.Key]int } func NewInput() *Input { - states := map[ui.Key]int{} - for key := ui.Key(0); key < ui.KeyMax; key++ { + states := map[input.Key]int{} + for key := input.Key(0); key < input.KeyMax; key++ { states[key] = 0 } return &Input{ @@ -18,13 +18,13 @@ func NewInput() *Input { } } -func (i *Input) StateForKey(key ui.Key) int { +func (i *Input) StateForKey(key input.Key) int { return i.states[key] } func (i *Input) Update() { for key := range i.states { - if !ui.IsKeyPressed(key) { + if !input.IsKeyPressed(key) { i.states[key] = 0 continue } diff --git a/example/blocks/titlescene.go b/example/blocks/titlescene.go index e1bba8ac3..9bbf54aa1 100644 --- a/example/blocks/titlescene.go +++ b/example/blocks/titlescene.go @@ -3,7 +3,7 @@ package blocks import ( "github.com/hajimehoshi/ebiten/graphics" "github.com/hajimehoshi/ebiten/graphics/matrix" - "github.com/hajimehoshi/ebiten/ui" + "github.com/hajimehoshi/ebiten/input" "image/color" ) @@ -21,7 +21,7 @@ func NewTitleScene() *TitleScene { func (s *TitleScene) Update(state *GameState) { s.count++ - if state.Input.StateForKey(ui.KeySpace) == 1 { + if state.Input.StateForKey(input.KeySpace) == 1 { state.SceneManager.GoTo(NewGameScene()) } } diff --git a/ui/input.go b/input/keyboard.go similarity index 96% rename from ui/input.go rename to input/keyboard.go index 62e98e05e..459e6200d 100644 --- a/ui/input.go +++ b/input/keyboard.go @@ -1,4 +1,4 @@ -package ui +package input type Key int diff --git a/ui/glfw/canvas.go b/ui/glfw/canvas.go index 5489b67b7..b7c200719 100644 --- a/ui/glfw/canvas.go +++ b/ui/glfw/canvas.go @@ -4,6 +4,7 @@ import ( glfw "github.com/go-gl/glfw3" "github.com/hajimehoshi/ebiten/graphics" "github.com/hajimehoshi/ebiten/graphics/opengl" + "github.com/hajimehoshi/ebiten/input" "github.com/hajimehoshi/ebiten/ui" "image" "runtime" @@ -29,7 +30,7 @@ func NewCanvas(width, height, scale int, title string) *Canvas { funcsDone: make(chan struct{}), } - ui.SetKeyboard(canvas.keyboard) + input.SetKeyboard(canvas.keyboard) graphics.SetTextureFactory(canvas) // For retina displays, recalculate the scale with the framebuffer size. diff --git a/ui/glfw/keyboard.go b/ui/glfw/keyboard.go index 6f6f915a4..6af6b335c 100644 --- a/ui/glfw/keyboard.go +++ b/ui/glfw/keyboard.go @@ -2,30 +2,30 @@ package glfw import ( glfw "github.com/go-gl/glfw3" - "github.com/hajimehoshi/ebiten/ui" + "github.com/hajimehoshi/ebiten/input" ) type Keyboard struct { - pressedKeys map[ui.Key]struct{} + pressedKeys map[input.Key]struct{} } func NewKeyboard() *Keyboard { return &Keyboard{ - pressedKeys: map[ui.Key]struct{}{}, + pressedKeys: map[input.Key]struct{}{}, } } -func (k *Keyboard) IsKeyPressed(key ui.Key) bool { +func (k *Keyboard) IsKeyPressed(key input.Key) bool { _, ok := k.pressedKeys[key] return ok } -var glfwKeyCodeToKey = map[glfw.Key]ui.Key{ - glfw.KeySpace: ui.KeySpace, - glfw.KeyLeft: ui.KeyLeft, - glfw.KeyRight: ui.KeyRight, - glfw.KeyUp: ui.KeyUp, - glfw.KeyDown: ui.KeyDown, +var glfwKeyCodeToKey = map[glfw.Key]input.Key{ + glfw.KeySpace: input.KeySpace, + glfw.KeyLeft: input.KeyLeft, + glfw.KeyRight: input.KeyRight, + glfw.KeyUp: input.KeyUp, + glfw.KeyDown: input.KeyDown, } func (k *Keyboard) update(window *glfw.Window) {