mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
ui: Remove AdjustedTouches
This commit is contained in:
parent
5d6f66935a
commit
dec6be1a11
20
input.go
20
input.go
@ -127,7 +127,7 @@ func IsGamepadButtonPressed(id int, button GamepadButton) bool {
|
|||||||
// TouchIDs is concurrent-safe.
|
// TouchIDs is concurrent-safe.
|
||||||
func TouchIDs() []int {
|
func TouchIDs() []int {
|
||||||
var ids []int
|
var ids []int
|
||||||
for _, t := range ui.AdjustedTouches() {
|
for _, t := range adjustedTouches() {
|
||||||
ids = append(ids, t.ID)
|
ids = append(ids, t.ID)
|
||||||
}
|
}
|
||||||
return ids
|
return ids
|
||||||
@ -139,7 +139,7 @@ func TouchIDs() []int {
|
|||||||
//
|
//
|
||||||
// TouchPosition is cuncurrent-safe.
|
// TouchPosition is cuncurrent-safe.
|
||||||
func TouchPosition(id int) (int, int) {
|
func TouchPosition(id int) (int, int) {
|
||||||
for _, t := range ui.AdjustedTouches() {
|
for _, t := range adjustedTouches() {
|
||||||
if t.ID == id {
|
if t.ID == id {
|
||||||
return t.X, t.Y
|
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.
|
// Touches is deprecated as of 1.7.0. Use TouchIDs instead.
|
||||||
func Touches() []Touch {
|
func Touches() []Touch {
|
||||||
touches := ui.AdjustedTouches()
|
touches := adjustedTouches()
|
||||||
var copies []Touch
|
var copies []Touch
|
||||||
for _, t := range touches {
|
for _, t := range touches {
|
||||||
copies = append(copies, &touch{t})
|
copies = append(copies, &touch{t})
|
||||||
}
|
}
|
||||||
return copies
|
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
|
||||||
|
}
|
||||||
|
@ -452,10 +452,10 @@ func ScreenPadding() (x0, y0, x1, y1 float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AdjustedCursorPosition() (x, y int) {
|
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
|
u := currentUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return x, y
|
return x, y
|
||||||
@ -469,11 +469,6 @@ func adjustCursorPosition(x, y int) (int, int) {
|
|||||||
return x - int(ox/s), y - int(oy/s)
|
return x - int(ox/s), y - int(oy/s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AdjustedTouches() []*input.Touch {
|
|
||||||
// TODO: Apply adjustCursorPosition
|
|
||||||
return input.Get().Touches()
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsCursorVisible() bool {
|
func IsCursorVisible() bool {
|
||||||
u := currentUI
|
u := currentUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
|
@ -106,7 +106,7 @@ func ScreenPadding() (x0, y0, x1, y1 float64) {
|
|||||||
return 0, 0, 0, 0
|
return 0, 0, 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func adjustPosition(x, y int) (int, int) {
|
func AdjustPosition(x, y int) (int, int) {
|
||||||
rect := canvas.Call("getBoundingClientRect")
|
rect := canvas.Call("getBoundingClientRect")
|
||||||
x -= rect.Get("left").Int()
|
x -= rect.Get("left").Int()
|
||||||
y -= rect.Get("top").Int()
|
y -= rect.Get("top").Int()
|
||||||
@ -115,21 +115,7 @@ func adjustPosition(x, y int) (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AdjustedCursorPosition() (x, y int) {
|
func AdjustedCursorPosition() (x, y int) {
|
||||||
return 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 := adjustPosition(t.X, t.Y)
|
|
||||||
adjusted[i] = &input.Touch{
|
|
||||||
ID: t.ID,
|
|
||||||
X: x,
|
|
||||||
Y: y,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return adjusted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsCursorVisible() bool {
|
func IsCursorVisible() bool {
|
||||||
|
@ -352,21 +352,11 @@ func (u *userInterface) screenPaddingImpl() (x0, y0, x1, y1 float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AdjustedCursorPosition() (x, y int) {
|
func AdjustedCursorPosition() (x, y int) {
|
||||||
return currentUI.adjustPosition(input.Get().CursorPosition())
|
return AdjustPosition(input.Get().CursorPosition())
|
||||||
}
|
}
|
||||||
|
|
||||||
func AdjustedTouches() []*input.Touch {
|
func AdjustPosition(x, y int) (int, int) {
|
||||||
ts := input.Get().Touches()
|
return currentUI.adjustPosition(x, y)
|
||||||
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 (u *userInterface) adjustPosition(x, y int) (int, int) {
|
func (u *userInterface) adjustPosition(x, y int) (int, int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user