mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
internal/driver: remove Input
This commit is contained in:
parent
6f72b15912
commit
2fbfa5444b
2
input.go
2
input.go
@ -324,7 +324,7 @@ func UpdateStandardGamepadLayoutMappings(mappings string) (bool, error) {
|
||||
}
|
||||
|
||||
// TouchID represents a touch's identifier.
|
||||
type TouchID = driver.TouchID
|
||||
type TouchID = ui.TouchID
|
||||
|
||||
// AppendTouchIDs appends the current touch states to touches, and returns the extended buffer.
|
||||
// Giving a slice that already has enough capacity works efficiently.
|
||||
|
@ -66,8 +66,6 @@ import (
|
||||
"reflect"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
)
|
||||
|
||||
type Gamepad struct {
|
||||
@ -81,7 +79,7 @@ type Gamepad struct {
|
||||
}
|
||||
|
||||
type Touch struct {
|
||||
ID driver.TouchID
|
||||
ID ui.TouchID
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
@ -153,7 +151,7 @@ func AppendTouches(touches []Touch) []Touch {
|
||||
|
||||
for _, t := range cTouches {
|
||||
touches = append(touches, Touch{
|
||||
ID: driver.TouchID(t.id),
|
||||
ID: ui.TouchID(t.id),
|
||||
X: int(t.x),
|
||||
Y: int(t.y),
|
||||
})
|
||||
|
@ -1,27 +0,0 @@
|
||||
// Copyright 2019 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package driver
|
||||
|
||||
type TouchID int
|
||||
|
||||
type Input interface {
|
||||
AppendInputChars(runes []rune) []rune
|
||||
AppendTouchIDs(touchIDs []TouchID) []TouchID
|
||||
CursorPosition() (x, y int)
|
||||
IsKeyPressed(key Key) bool
|
||||
IsMouseButtonPressed(button MouseButton) bool
|
||||
TouchPosition(id TouchID) (x, y int)
|
||||
Wheel() (xoff, yoff float64)
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Copyright 2015 Hajime Hoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package driver
|
||||
|
||||
type MouseButton int
|
||||
|
||||
const (
|
||||
MouseButtonLeft MouseButton = iota
|
||||
MouseButtonRight
|
||||
MouseButtonMiddle
|
||||
)
|
@ -52,7 +52,7 @@ func (i *Input) AppendInputChars(runes []rune) []rune {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Input) AppendTouchIDs(touchIDs []driver.TouchID) []driver.TouchID {
|
||||
func (i *Input) AppendTouchIDs(touchIDs []TouchID) []TouchID {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
|
||||
@ -70,11 +70,11 @@ func (i *Input) IsKeyPressed(key driver.Key) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (i *Input) IsMouseButtonPressed(button driver.MouseButton) bool {
|
||||
func (i *Input) IsMouseButtonPressed(button MouseButton) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (i *Input) TouchPosition(id driver.TouchID) (x, y int) {
|
||||
func (i *Input) TouchPosition(id TouchID) (x, y int) {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
|
||||
|
@ -35,7 +35,7 @@ type Input struct {
|
||||
scrollY float64
|
||||
cursorX int
|
||||
cursorY int
|
||||
touches map[driver.TouchID]pos // TODO: Implement this (#417)
|
||||
touches map[TouchID]pos // TODO: Implement this (#417)
|
||||
runeBuffer []rune
|
||||
ui *UserInterface
|
||||
}
|
||||
@ -55,7 +55,7 @@ func (i *Input) CursorPosition() (x, y int) {
|
||||
return i.cursorX, i.cursorY
|
||||
}
|
||||
|
||||
func (i *Input) AppendTouchIDs(touchIDs []driver.TouchID) []driver.TouchID {
|
||||
func (i *Input) AppendTouchIDs(touchIDs []TouchID) []TouchID {
|
||||
if !i.ui.isRunning() {
|
||||
return nil
|
||||
}
|
||||
@ -68,7 +68,7 @@ func (i *Input) AppendTouchIDs(touchIDs []driver.TouchID) []driver.TouchID {
|
||||
return touchIDs
|
||||
}
|
||||
|
||||
func (i *Input) TouchPosition(id driver.TouchID) (x, y int) {
|
||||
func (i *Input) TouchPosition(id TouchID) (x, y int) {
|
||||
if !i.ui.isRunning() {
|
||||
return 0, 0
|
||||
}
|
||||
@ -118,7 +118,7 @@ func (i *Input) IsKeyPressed(key driver.Key) bool {
|
||||
return ok && i.keyPressed[gk]
|
||||
}
|
||||
|
||||
func (i *Input) IsMouseButtonPressed(button driver.MouseButton) bool {
|
||||
func (i *Input) IsMouseButtonPressed(button MouseButton) bool {
|
||||
if !i.ui.isRunning() {
|
||||
return false
|
||||
}
|
||||
@ -149,10 +149,10 @@ func (i *Input) Wheel() (xoff, yoff float64) {
|
||||
return i.scrollX, i.scrollY
|
||||
}
|
||||
|
||||
var glfwMouseButtonToMouseButton = map[glfw.MouseButton]driver.MouseButton{
|
||||
glfw.MouseButtonLeft: driver.MouseButtonLeft,
|
||||
glfw.MouseButtonRight: driver.MouseButtonRight,
|
||||
glfw.MouseButtonMiddle: driver.MouseButtonMiddle,
|
||||
var glfwMouseButtonToMouseButton = map[glfw.MouseButton]MouseButton{
|
||||
glfw.MouseButtonLeft: MouseButtonLeft,
|
||||
glfw.MouseButtonRight: MouseButtonRight,
|
||||
glfw.MouseButtonMiddle: MouseButtonMiddle,
|
||||
}
|
||||
|
||||
// update must be called from the main thread.
|
||||
|
@ -68,7 +68,7 @@ type Input struct {
|
||||
origCursorY int
|
||||
wheelX float64
|
||||
wheelY float64
|
||||
touches map[driver.TouchID]pos
|
||||
touches map[TouchID]pos
|
||||
runeBuffer []rune
|
||||
ui *UserInterface
|
||||
}
|
||||
@ -81,14 +81,14 @@ func (i *Input) CursorPosition() (x, y int) {
|
||||
return int(xf), int(yf)
|
||||
}
|
||||
|
||||
func (i *Input) AppendTouchIDs(touchIDs []driver.TouchID) []driver.TouchID {
|
||||
func (i *Input) AppendTouchIDs(touchIDs []TouchID) []TouchID {
|
||||
for id := range i.touches {
|
||||
touchIDs = append(touchIDs, id)
|
||||
}
|
||||
return touchIDs
|
||||
}
|
||||
|
||||
func (i *Input) TouchPosition(id driver.TouchID) (x, y int) {
|
||||
func (i *Input) TouchPosition(id TouchID) (x, y int) {
|
||||
d := i.ui.DeviceScaleFactor()
|
||||
for tid, pos := range i.touches {
|
||||
if id == tid {
|
||||
@ -128,13 +128,13 @@ func (i *Input) IsKeyPressed(key driver.Key) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var codeToMouseButton = map[int]driver.MouseButton{
|
||||
0: driver.MouseButtonLeft,
|
||||
1: driver.MouseButtonMiddle,
|
||||
2: driver.MouseButtonRight,
|
||||
var codeToMouseButton = map[int]MouseButton{
|
||||
0: MouseButtonLeft,
|
||||
1: MouseButtonMiddle,
|
||||
2: MouseButtonRight,
|
||||
}
|
||||
|
||||
func (i *Input) IsMouseButtonPressed(button driver.MouseButton) bool {
|
||||
func (i *Input) IsMouseButtonPressed(button MouseButton) bool {
|
||||
if i.mouseButtonPressed == nil {
|
||||
i.mouseButtonPressed = map[int]bool{}
|
||||
}
|
||||
@ -282,9 +282,9 @@ func (in *Input) updateTouchesFromEvent(e js.Value) {
|
||||
}
|
||||
for i := 0; i < j.Length(); i++ {
|
||||
jj := j.Call("item", i)
|
||||
id := driver.TouchID(jj.Get("identifier").Int())
|
||||
id := TouchID(jj.Get("identifier").Int())
|
||||
if in.touches == nil {
|
||||
in.touches = map[driver.TouchID]pos{}
|
||||
in.touches = map[TouchID]pos{}
|
||||
}
|
||||
in.touches[id] = pos{
|
||||
X: jj.Get("clientX").Int(),
|
||||
@ -307,9 +307,9 @@ func (i *Input) updateForGo2Cpp() {
|
||||
x := go2cpp.Call("getTouchX", idx)
|
||||
y := go2cpp.Call("getTouchY", idx)
|
||||
if i.touches == nil {
|
||||
i.touches = map[driver.TouchID]pos{}
|
||||
i.touches = map[TouchID]pos{}
|
||||
}
|
||||
i.touches[driver.TouchID(id.Int())] = pos{
|
||||
i.touches[TouchID(id.Int())] = pos{
|
||||
X: x.Int(),
|
||||
Y: y.Int(),
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func (i *Input) CursorPosition() (x, y int) {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
func (i *Input) AppendTouchIDs(touchIDs []driver.TouchID) []driver.TouchID {
|
||||
func (i *Input) AppendTouchIDs(touchIDs []TouchID) []TouchID {
|
||||
i.ui.m.RLock()
|
||||
defer i.ui.m.RUnlock()
|
||||
|
||||
@ -43,7 +43,7 @@ func (i *Input) AppendTouchIDs(touchIDs []driver.TouchID) []driver.TouchID {
|
||||
return touchIDs
|
||||
}
|
||||
|
||||
func (i *Input) TouchPosition(id driver.TouchID) (x, y int) {
|
||||
func (i *Input) TouchPosition(id TouchID) (x, y int) {
|
||||
i.ui.m.RLock()
|
||||
defer i.ui.m.RUnlock()
|
||||
|
||||
@ -73,7 +73,7 @@ func (i *Input) Wheel() (xoff, yoff float64) {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
func (i *Input) IsMouseButtonPressed(key driver.MouseButton) bool {
|
||||
func (i *Input) IsMouseButtonPressed(key MouseButton) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,16 @@ type Context interface {
|
||||
AdjustPosition(x, y float64, deviceScaleFactor float64) (float64, float64)
|
||||
}
|
||||
|
||||
type MouseButton int
|
||||
|
||||
const (
|
||||
MouseButtonLeft MouseButton = iota
|
||||
MouseButtonRight
|
||||
MouseButtonMiddle
|
||||
)
|
||||
|
||||
type TouchID int
|
||||
|
||||
// RegularTermination represents a regular termination.
|
||||
// Run can return this error, and if this error is received,
|
||||
// the game loop should be terminated as soon as possible.
|
||||
|
@ -128,7 +128,7 @@ func (*UserInterface) SetInitFocused(focused bool) {
|
||||
func (*UserInterface) Vibrate(duration time.Duration, magnitude float64) {
|
||||
}
|
||||
|
||||
func (*UserInterface) Input() driver.Input {
|
||||
func (*UserInterface) Input() *Input {
|
||||
return &theUserInterface.input
|
||||
}
|
||||
|
||||
|
@ -1431,7 +1431,7 @@ func (u *UserInterface) SetInitFocused(focused bool) {
|
||||
u.setInitFocused(focused)
|
||||
}
|
||||
|
||||
func (u *UserInterface) Input() driver.Input {
|
||||
func (u *UserInterface) Input() *Input {
|
||||
return &u.input
|
||||
}
|
||||
|
||||
|
@ -661,7 +661,7 @@ func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UserInterface) Input() driver.Input {
|
||||
func (u *UserInterface) Input() *Input {
|
||||
return &u.input
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ func (u *UserInterface) appMain(a app.App) {
|
||||
x, y := float64(e.X)/s, float64(e.Y)/s
|
||||
// TODO: Is it ok to cast from int64 to int here?
|
||||
touches[e.Sequence] = Touch{
|
||||
ID: driver.TouchID(e.Sequence),
|
||||
ID: TouchID(e.Sequence),
|
||||
X: int(x),
|
||||
Y: int(y),
|
||||
}
|
||||
@ -446,7 +446,7 @@ func (u *UserInterface) SetInitFocused(focused bool) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
func (u *UserInterface) Input() driver.Input {
|
||||
func (u *UserInterface) Input() *Input {
|
||||
return &u.input
|
||||
}
|
||||
|
||||
@ -455,7 +455,7 @@ func (u *UserInterface) Window() driver.Window {
|
||||
}
|
||||
|
||||
type Touch struct {
|
||||
ID driver.TouchID
|
||||
ID TouchID
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ type position struct {
|
||||
var (
|
||||
keys = map[driver.Key]struct{}{}
|
||||
runes []rune
|
||||
touches = map[driver.TouchID]position{}
|
||||
touches = map[ui.TouchID]position{}
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
"math"
|
||||
"unicode"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||
)
|
||||
|
||||
// https://developer.android.com/reference/android/view/KeyEvent
|
||||
@ -183,10 +183,10 @@ var androidAxisIDToHatID2 = map[int]int{
|
||||
func UpdateTouchesOnAndroid(action int, id int, x, y int) {
|
||||
switch action {
|
||||
case 0x00, 0x05, 0x02: // ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_MOVE
|
||||
touches[driver.TouchID(id)] = position{x, y}
|
||||
touches[ui.TouchID(id)] = position{x, y}
|
||||
updateInput()
|
||||
case 0x01, 0x06: // ACTION_UP, ACTION_POINTER_UP
|
||||
delete(touches, driver.TouchID(id))
|
||||
delete(touches, ui.TouchID(id))
|
||||
updateInput()
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ package ebitenmobileview
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||
)
|
||||
|
||||
// #cgo CFLAGS: -x objective-c
|
||||
@ -50,12 +50,12 @@ func UpdateTouchesOnIOS(phase int, ptr int64, x, y int) {
|
||||
switch phase {
|
||||
case C.UITouchPhaseBegan, C.UITouchPhaseMoved, C.UITouchPhaseStationary:
|
||||
id := getIDFromPtr(ptr)
|
||||
touches[driver.TouchID(id)] = position{x, y}
|
||||
touches[ui.TouchID(id)] = position{x, y}
|
||||
updateInput()
|
||||
case C.UITouchPhaseEnded, C.UITouchPhaseCancelled:
|
||||
id := getIDFromPtr(ptr)
|
||||
delete(ptrToID, ptr)
|
||||
delete(touches, driver.TouchID(id))
|
||||
delete(touches, ui.TouchID(id))
|
||||
updateInput()
|
||||
default:
|
||||
panic(fmt.Sprintf("ebitenmobileview: invalid phase: %d", phase))
|
||||
|
@ -15,15 +15,15 @@
|
||||
package ebiten
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||
)
|
||||
|
||||
// A MouseButton represents a mouse button.
|
||||
type MouseButton = driver.MouseButton
|
||||
type MouseButton = ui.MouseButton
|
||||
|
||||
// MouseButtons
|
||||
const (
|
||||
MouseButtonLeft MouseButton = driver.MouseButtonLeft
|
||||
MouseButtonRight MouseButton = driver.MouseButtonRight
|
||||
MouseButtonMiddle MouseButton = driver.MouseButtonMiddle
|
||||
MouseButtonLeft MouseButton = ui.MouseButtonLeft
|
||||
MouseButtonRight MouseButton = ui.MouseButtonRight
|
||||
MouseButtonMiddle MouseButton = ui.MouseButtonMiddle
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user