input: Move MouseButton and GamepadButton to driver package

This commit is contained in:
Hajime Hoshi 2019-03-30 23:19:52 +09:00
parent 35ac61056c
commit c5a8c88e2d
7 changed files with 53 additions and 47 deletions

View File

@ -15,7 +15,7 @@
package ebiten package ebiten
import ( import (
"github.com/hajimehoshi/ebiten/internal/input" "github.com/hajimehoshi/ebiten/internal/driver"
) )
// A GamepadButton represents a gamepad button. // A GamepadButton represents a gamepad button.
@ -23,37 +23,37 @@ type GamepadButton int
// GamepadButtons // GamepadButtons
const ( const (
GamepadButton0 GamepadButton = GamepadButton(input.GamepadButton0) GamepadButton0 GamepadButton = GamepadButton(driver.GamepadButton0)
GamepadButton1 GamepadButton = GamepadButton(input.GamepadButton1) GamepadButton1 GamepadButton = GamepadButton(driver.GamepadButton1)
GamepadButton2 GamepadButton = GamepadButton(input.GamepadButton2) GamepadButton2 GamepadButton = GamepadButton(driver.GamepadButton2)
GamepadButton3 GamepadButton = GamepadButton(input.GamepadButton3) GamepadButton3 GamepadButton = GamepadButton(driver.GamepadButton3)
GamepadButton4 GamepadButton = GamepadButton(input.GamepadButton4) GamepadButton4 GamepadButton = GamepadButton(driver.GamepadButton4)
GamepadButton5 GamepadButton = GamepadButton(input.GamepadButton5) GamepadButton5 GamepadButton = GamepadButton(driver.GamepadButton5)
GamepadButton6 GamepadButton = GamepadButton(input.GamepadButton6) GamepadButton6 GamepadButton = GamepadButton(driver.GamepadButton6)
GamepadButton7 GamepadButton = GamepadButton(input.GamepadButton7) GamepadButton7 GamepadButton = GamepadButton(driver.GamepadButton7)
GamepadButton8 GamepadButton = GamepadButton(input.GamepadButton8) GamepadButton8 GamepadButton = GamepadButton(driver.GamepadButton8)
GamepadButton9 GamepadButton = GamepadButton(input.GamepadButton9) GamepadButton9 GamepadButton = GamepadButton(driver.GamepadButton9)
GamepadButton10 GamepadButton = GamepadButton(input.GamepadButton10) GamepadButton10 GamepadButton = GamepadButton(driver.GamepadButton10)
GamepadButton11 GamepadButton = GamepadButton(input.GamepadButton11) GamepadButton11 GamepadButton = GamepadButton(driver.GamepadButton11)
GamepadButton12 GamepadButton = GamepadButton(input.GamepadButton12) GamepadButton12 GamepadButton = GamepadButton(driver.GamepadButton12)
GamepadButton13 GamepadButton = GamepadButton(input.GamepadButton13) GamepadButton13 GamepadButton = GamepadButton(driver.GamepadButton13)
GamepadButton14 GamepadButton = GamepadButton(input.GamepadButton14) GamepadButton14 GamepadButton = GamepadButton(driver.GamepadButton14)
GamepadButton15 GamepadButton = GamepadButton(input.GamepadButton15) GamepadButton15 GamepadButton = GamepadButton(driver.GamepadButton15)
GamepadButton16 GamepadButton = GamepadButton(input.GamepadButton16) GamepadButton16 GamepadButton = GamepadButton(driver.GamepadButton16)
GamepadButton17 GamepadButton = GamepadButton(input.GamepadButton17) GamepadButton17 GamepadButton = GamepadButton(driver.GamepadButton17)
GamepadButton18 GamepadButton = GamepadButton(input.GamepadButton18) GamepadButton18 GamepadButton = GamepadButton(driver.GamepadButton18)
GamepadButton19 GamepadButton = GamepadButton(input.GamepadButton19) GamepadButton19 GamepadButton = GamepadButton(driver.GamepadButton19)
GamepadButton20 GamepadButton = GamepadButton(input.GamepadButton20) GamepadButton20 GamepadButton = GamepadButton(driver.GamepadButton20)
GamepadButton21 GamepadButton = GamepadButton(input.GamepadButton21) GamepadButton21 GamepadButton = GamepadButton(driver.GamepadButton21)
GamepadButton22 GamepadButton = GamepadButton(input.GamepadButton22) GamepadButton22 GamepadButton = GamepadButton(driver.GamepadButton22)
GamepadButton23 GamepadButton = GamepadButton(input.GamepadButton23) GamepadButton23 GamepadButton = GamepadButton(driver.GamepadButton23)
GamepadButton24 GamepadButton = GamepadButton(input.GamepadButton24) GamepadButton24 GamepadButton = GamepadButton(driver.GamepadButton24)
GamepadButton25 GamepadButton = GamepadButton(input.GamepadButton25) GamepadButton25 GamepadButton = GamepadButton(driver.GamepadButton25)
GamepadButton26 GamepadButton = GamepadButton(input.GamepadButton26) GamepadButton26 GamepadButton = GamepadButton(driver.GamepadButton26)
GamepadButton27 GamepadButton = GamepadButton(input.GamepadButton27) GamepadButton27 GamepadButton = GamepadButton(driver.GamepadButton27)
GamepadButton28 GamepadButton = GamepadButton(input.GamepadButton28) GamepadButton28 GamepadButton = GamepadButton(driver.GamepadButton28)
GamepadButton29 GamepadButton = GamepadButton(input.GamepadButton29) GamepadButton29 GamepadButton = GamepadButton(driver.GamepadButton29)
GamepadButton30 GamepadButton = GamepadButton(input.GamepadButton30) GamepadButton30 GamepadButton = GamepadButton(driver.GamepadButton30)
GamepadButton31 GamepadButton = GamepadButton(input.GamepadButton31) GamepadButton31 GamepadButton = GamepadButton(driver.GamepadButton31)
GamepadButtonMax GamepadButton = GamepadButton31 GamepadButtonMax GamepadButton = GamepadButton31
) )

View File

@ -15,6 +15,7 @@
package ebiten package ebiten
import ( import (
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/input" "github.com/hajimehoshi/ebiten/internal/input"
"github.com/hajimehoshi/ebiten/internal/ui" "github.com/hajimehoshi/ebiten/internal/ui"
) )
@ -67,7 +68,7 @@ func Wheel() (xoff, yoff float64) {
// Note that touch events not longer affect IsMouseButtonPressed's result as of 1.4.0-alpha. // Note that touch events not longer affect IsMouseButtonPressed's result as of 1.4.0-alpha.
// Use Touches instead. // Use Touches instead.
func IsMouseButtonPressed(mouseButton MouseButton) bool { func IsMouseButtonPressed(mouseButton MouseButton) bool {
return input.Get().IsMouseButtonPressed(input.MouseButton(mouseButton)) return input.Get().IsMouseButtonPressed(driver.MouseButton(mouseButton))
} }
// GamepadIDs returns a slice indicating available gamepad IDs. // GamepadIDs returns a slice indicating available gamepad IDs.
@ -115,7 +116,7 @@ func GamepadButtonNum(id int) int {
// //
// IsGamepadButtonPressed always returns false on mobiles. // IsGamepadButtonPressed always returns false on mobiles.
func IsGamepadButtonPressed(id int, button GamepadButton) bool { func IsGamepadButtonPressed(id int, button GamepadButton) bool {
return input.Get().IsGamepadButtonPressed(id, input.GamepadButton(button)) return input.Get().IsGamepadButtonPressed(id, driver.GamepadButton(button))
} }
// TouchIDs returns the current touch states. // TouchIDs returns the current touch states.

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package input package driver
type GamepadButton int type GamepadButton int

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package input package driver
type MouseButton int type MouseButton int

View File

@ -14,6 +14,10 @@
package input package input
import (
"github.com/hajimehoshi/ebiten/internal/driver"
)
var theInput = &Input{} var theInput = &Input{}
func Get() *Input { func Get() *Input {
@ -68,7 +72,7 @@ func (i *Input) GamepadButtonNum(id int) int {
return i.gamepads[id].buttonNum return i.gamepads[id].buttonNum
} }
func (i *Input) IsGamepadButtonPressed(id int, button GamepadButton) bool { func (i *Input) IsGamepadButtonPressed(id int, button driver.GamepadButton) bool {
i.m.RLock() i.m.RLock()
defer i.m.RUnlock() defer i.m.RUnlock()
if len(i.gamepads) <= id { if len(i.gamepads) <= id {

View File

@ -23,6 +23,7 @@ import (
"sync" "sync"
"unicode" "unicode"
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/glfw" "github.com/hajimehoshi/ebiten/internal/glfw"
) )
@ -75,7 +76,7 @@ func (i *Input) IsKeyPressed(key Key) bool {
return false return false
} }
func (i *Input) IsMouseButtonPressed(button MouseButton) bool { func (i *Input) IsMouseButtonPressed(button driver.MouseButton) bool {
i.m.RLock() i.m.RLock()
defer i.m.RUnlock() defer i.m.RUnlock()
if i.mouseButtonPressed == nil { if i.mouseButtonPressed == nil {
@ -98,10 +99,10 @@ func (i *Input) Wheel() (xoff, yoff float64) {
return i.scrollX, i.scrollY return i.scrollX, i.scrollY
} }
var glfwMouseButtonToMouseButton = map[glfw.MouseButton]MouseButton{ var glfwMouseButtonToMouseButton = map[glfw.MouseButton]driver.MouseButton{
glfw.MouseButtonLeft: MouseButtonLeft, glfw.MouseButtonLeft: driver.MouseButtonLeft,
glfw.MouseButtonRight: MouseButtonRight, glfw.MouseButtonRight: driver.MouseButtonRight,
glfw.MouseButtonMiddle: MouseButtonMiddle, glfw.MouseButtonMiddle: driver.MouseButtonMiddle,
} }
func (i *Input) Update(window *glfw.Window, scale float64) { func (i *Input) Update(window *glfw.Window, scale float64) {

View File

@ -15,7 +15,7 @@
package ebiten package ebiten
import ( import (
"github.com/hajimehoshi/ebiten/internal/input" "github.com/hajimehoshi/ebiten/internal/driver"
) )
// A MouseButton represents a mouse button. // A MouseButton represents a mouse button.
@ -23,7 +23,7 @@ type MouseButton int
// MouseButtons // MouseButtons
const ( const (
MouseButtonLeft MouseButton = MouseButton(input.MouseButtonLeft) MouseButtonLeft MouseButton = MouseButton(driver.MouseButtonLeft)
MouseButtonRight MouseButton = MouseButton(input.MouseButtonRight) MouseButtonRight MouseButton = MouseButton(driver.MouseButtonRight)
MouseButtonMiddle MouseButton = MouseButton(input.MouseButtonMiddle) MouseButtonMiddle MouseButton = MouseButton(driver.MouseButtonMiddle)
) )