input: Move Touch to driver package

This commit is contained in:
Hajime Hoshi 2019-03-31 18:55:46 +09:00
parent e273618081
commit c21fb4d390
5 changed files with 29 additions and 12 deletions

22
internal/driver/input.go Normal file
View File

@ -0,0 +1,22 @@
// 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
// TODO: Remove this for API simplicity.
type Touch struct {
ID int
X int
Y int
}

View File

@ -120,9 +120,3 @@ type gamePad struct {
buttonNum int
buttonPressed [256]bool
}
type Touch struct {
ID int
X int
Y int
}

View File

@ -46,7 +46,7 @@ func (i *Input) IsMouseButtonPressed(key driver.MouseButton) bool {
return false
}
func (i *Input) SetTouches(touches []*Touch) {
func (i *Input) SetTouches(touches []*driver.Touch) {
i.m.Lock()
i.touches = map[int]pos{}
for _, t := range touches {

View File

@ -95,7 +95,7 @@ func getDeviceScale() float64 {
// appMain is the main routine for gomobile-build mode.
func appMain(a app.App) {
var glctx gl.Context
touches := map[touch.Sequence]*input.Touch{}
touches := map[touch.Sequence]*driver.Touch{}
for e := range a.Events() {
switch e := a.Filter(e).(type) {
case lifecycle.Event:
@ -128,7 +128,7 @@ func appMain(a app.App) {
s := getDeviceScale()
x, y := float64(e.X)/s, float64(e.Y)/s
// TODO: Is it ok to cast from int64 to int here?
touches[e.Sequence] = &input.Touch{
touches[e.Sequence] = &driver.Touch{
ID: int(e.Sequence),
X: int(x),
Y: int(y),
@ -136,7 +136,7 @@ func appMain(a app.App) {
case touch.TypeEnd:
delete(touches, e.Sequence)
}
ts := []*input.Touch{}
ts := []*driver.Touch{}
for _, t := range touches {
ts = append(ts, t)
}

View File

@ -17,6 +17,7 @@
package mobile
import (
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/input"
)
@ -30,9 +31,9 @@ var (
)
func updateTouches() {
ts := []*input.Touch{}
ts := []*driver.Touch{}
for id, position := range touches {
ts = append(ts, &input.Touch{
ts = append(ts, &driver.Touch{
ID: id,
X: position.x,
Y: position.y,