ui: Remove AdjustedTouches

This commit is contained in:
Hajime Hoshi 2019-03-31 02:00:22 +09:00
parent 5d6f66935a
commit dec6be1a11
4 changed files with 24 additions and 39 deletions

View File

@ -127,7 +127,7 @@ func IsGamepadButtonPressed(id int, button GamepadButton) bool {
// TouchIDs is concurrent-safe.
func TouchIDs() []int {
var ids []int
for _, t := range ui.AdjustedTouches() {
for _, t := range adjustedTouches() {
ids = append(ids, t.ID)
}
return ids
@ -139,7 +139,7 @@ func TouchIDs() []int {
//
// TouchPosition is cuncurrent-safe.
func TouchPosition(id int) (int, int) {
for _, t := range ui.AdjustedTouches() {
for _, t := range adjustedTouches() {
if t.ID == id {
return t.X, t.Y
}
@ -170,10 +170,24 @@ func (t *touch) Position() (x, y int) {
// Touches is deprecated as of 1.7.0. Use TouchIDs instead.
func Touches() []Touch {
touches := ui.AdjustedTouches()
touches := adjustedTouches()
var copies []Touch
for _, t := range touches {
copies = append(copies, &touch{t})
}
return copies
}
func adjustedTouches() []*input.Touch {
ts := input.Get().Touches()
adjusted := make([]*input.Touch, len(ts))
for i, t := range ts {
x, y := ui.AdjustPosition(t.X, t.Y)
adjusted[i] = &input.Touch{
ID: t.ID,
X: x,
Y: y,
}
}
return adjusted
}

View File

@ -452,10 +452,10 @@ func ScreenPadding() (x0, y0, x1, y1 float64) {
}
func AdjustedCursorPosition() (x, y int) {
return adjustCursorPosition(input.Get().CursorPosition())
return AdjustPosition(input.Get().CursorPosition())
}
func adjustCursorPosition(x, y int) (int, int) {
func AdjustPosition(x, y int) (int, int) {
u := currentUI
if !u.isRunning() {
return x, y
@ -469,11 +469,6 @@ func adjustCursorPosition(x, y int) (int, int) {
return x - int(ox/s), y - int(oy/s)
}
func AdjustedTouches() []*input.Touch {
// TODO: Apply adjustCursorPosition
return input.Get().Touches()
}
func IsCursorVisible() bool {
u := currentUI
if !u.isRunning() {

View File

@ -106,7 +106,7 @@ func ScreenPadding() (x0, y0, x1, y1 float64) {
return 0, 0, 0, 0
}
func adjustPosition(x, y int) (int, int) {
func AdjustPosition(x, y int) (int, int) {
rect := canvas.Call("getBoundingClientRect")
x -= rect.Get("left").Int()
y -= rect.Get("top").Int()
@ -115,21 +115,7 @@ func adjustPosition(x, y int) (int, int) {
}
func AdjustedCursorPosition() (x, y int) {
return adjustPosition(input.Get().CursorPosition())
}
func AdjustedTouches() []*input.Touch {
ts := input.Get().Touches()
adjusted := make([]*input.Touch, len(ts))
for i, t := range ts {
x, y := adjustPosition(t.X, t.Y)
adjusted[i] = &input.Touch{
ID: t.ID,
X: x,
Y: y,
}
}
return adjusted
return AdjustPosition(input.Get().CursorPosition())
}
func IsCursorVisible() bool {

View File

@ -352,21 +352,11 @@ func (u *userInterface) screenPaddingImpl() (x0, y0, x1, y1 float64) {
}
func AdjustedCursorPosition() (x, y int) {
return currentUI.adjustPosition(input.Get().CursorPosition())
return AdjustPosition(input.Get().CursorPosition())
}
func AdjustedTouches() []*input.Touch {
ts := input.Get().Touches()
adjusted := make([]*input.Touch, len(ts))
for i, t := range ts {
x, y := currentUI.adjustPosition(t.X, t.Y)
adjusted[i] = &input.Touch{
ID: t.ID,
X: x,
Y: y,
}
}
return adjusted
func AdjustPosition(x, y int) (int, int) {
return currentUI.adjustPosition(x, y)
}
func (u *userInterface) adjustPosition(x, y int) (int, int) {