mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
driver: Remove UI.AdjustPosition
This commit is contained in:
parent
26c32d36b5
commit
0aa3135082
4
input.go
4
input.go
@ -48,7 +48,7 @@ func IsKeyPressed(key Key) bool {
|
||||
//
|
||||
// CursorPosition is concurrent-safe.
|
||||
func CursorPosition() (x, y int) {
|
||||
return uiDriver().AdjustPosition(uiDriver().Input().CursorPosition())
|
||||
return uiDriver().Input().CursorPosition()
|
||||
}
|
||||
|
||||
// Wheel returns the x and y offset of the mouse wheel or touchpad scroll.
|
||||
@ -144,7 +144,7 @@ func TouchPosition(id int) (int, int) {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
return uiDriver().AdjustPosition(uiDriver().Input().TouchPosition(id))
|
||||
return uiDriver().Input().TouchPosition(id)
|
||||
}
|
||||
|
||||
// Touch is deprecated as of 1.7.0. Use TouchPosition instead.
|
||||
|
@ -30,7 +30,6 @@ type GraphicsContext interface {
|
||||
var RegularTermination = errors.New("regular termination")
|
||||
|
||||
type UI interface {
|
||||
AdjustPosition(x, y int) (int, int)
|
||||
DeviceScaleFactor() float64
|
||||
IsCursorVisible() bool
|
||||
IsFullscreen() bool
|
||||
|
@ -46,6 +46,7 @@ type Input struct {
|
||||
gamepads [16]gamePad
|
||||
touches map[int]pos // This is not updated until GLFW 3.3 is available (#417)
|
||||
runeBuffer []rune
|
||||
ui *UserInterface
|
||||
m sync.RWMutex
|
||||
}
|
||||
|
||||
@ -57,7 +58,7 @@ type pos struct {
|
||||
func (i *Input) CursorPosition() (x, y int) {
|
||||
i.m.RLock()
|
||||
defer i.m.RUnlock()
|
||||
return i.cursorX, i.cursorY
|
||||
return i.ui.adjustPosition(i.cursorX, i.cursorY)
|
||||
}
|
||||
|
||||
func (i *Input) GamepadIDs() []int {
|
||||
@ -132,7 +133,7 @@ func (i *Input) TouchPosition(id int) (x, y int) {
|
||||
|
||||
for tid, pos := range i.touches {
|
||||
if id == tid {
|
||||
return pos.X, pos.Y
|
||||
return i.ui.adjustPosition(pos.X, pos.Y)
|
||||
}
|
||||
}
|
||||
return 0, 0
|
||||
|
@ -86,6 +86,10 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
theUI.input.ui = theUI
|
||||
}
|
||||
|
||||
func Get() *UserInterface {
|
||||
return theUI
|
||||
}
|
||||
@ -442,7 +446,7 @@ func (u *UserInterface) ScreenPadding() (x0, y0, x1, y1 float64) {
|
||||
return ox, oy, (mx - sx) - ox, (my - sy) - oy
|
||||
}
|
||||
|
||||
func (u *UserInterface) AdjustPosition(x, y int) (int, int) {
|
||||
func (u *UserInterface) adjustPosition(x, y int) (int, int) {
|
||||
if !u.isRunning() {
|
||||
return x, y
|
||||
}
|
||||
|
@ -48,10 +48,11 @@ type Input struct {
|
||||
gamepads [16]gamePad
|
||||
touches map[int]pos
|
||||
runeBuffer []rune
|
||||
ui *UserInterface
|
||||
}
|
||||
|
||||
func (i *Input) CursorPosition() (x, y int) {
|
||||
return i.cursorX, i.cursorY
|
||||
return i.ui.adjustPosition(i.cursorX, i.cursorY)
|
||||
}
|
||||
|
||||
func (i *Input) GamepadIDs() []int {
|
||||
@ -110,7 +111,7 @@ func (i *Input) TouchIDs() []int {
|
||||
func (i *Input) TouchPosition(id int) (x, y int) {
|
||||
for tid, pos := range i.touches {
|
||||
if id == tid {
|
||||
return pos.X, pos.Y
|
||||
return i.ui.adjustPosition(pos.X, pos.Y)
|
||||
}
|
||||
}
|
||||
return 0, 0
|
||||
|
@ -56,6 +56,10 @@ var theUI = &UserInterface{
|
||||
vsync: true,
|
||||
}
|
||||
|
||||
func init() {
|
||||
theUI.input.ui = theUI
|
||||
}
|
||||
|
||||
func Get() *UserInterface {
|
||||
return theUI
|
||||
}
|
||||
@ -111,7 +115,7 @@ func (u *UserInterface) ScreenPadding() (x0, y0, x1, y1 float64) {
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
|
||||
func (u *UserInterface) AdjustPosition(x, y int) (int, int) {
|
||||
func (u *UserInterface) adjustPosition(x, y int) (int, int) {
|
||||
rect := canvas.Call("getBoundingClientRect")
|
||||
x -= rect.Get("left").Int()
|
||||
y -= rect.Get("top").Int()
|
||||
|
@ -31,13 +31,14 @@ type Input struct {
|
||||
cursorX int
|
||||
cursorY int
|
||||
touches map[int]pos
|
||||
ui *UserInterface
|
||||
m sync.RWMutex
|
||||
}
|
||||
|
||||
func (i *Input) CursorPosition() (x, y int) {
|
||||
i.m.RLock()
|
||||
defer i.m.RUnlock()
|
||||
return i.cursorX, i.cursorY
|
||||
return i.ui.adjustPosition(i.cursorX, i.cursorY)
|
||||
}
|
||||
|
||||
func (i *Input) GamepadIDs() []int {
|
||||
@ -81,7 +82,7 @@ func (i *Input) TouchPosition(id int) (x, y int) {
|
||||
|
||||
for tid, pos := range i.touches {
|
||||
if id == tid {
|
||||
return pos.X, pos.Y
|
||||
return i.ui.adjustPosition(pos.X, pos.Y)
|
||||
}
|
||||
}
|
||||
return 0, 0
|
||||
|
@ -43,6 +43,10 @@ var (
|
||||
theUI = &UserInterface{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
theUI.input.ui = theUI
|
||||
}
|
||||
|
||||
func Get() *UserInterface {
|
||||
return theUI
|
||||
}
|
||||
@ -332,7 +336,7 @@ func (u *UserInterface) screenPaddingImpl() (x0, y0, x1, y1 float64) {
|
||||
return ox, oy, ox, oy
|
||||
}
|
||||
|
||||
func (u *UserInterface) AdjustPosition(x, y int) (int, int) {
|
||||
func (u *UserInterface) adjustPosition(x, y int) (int, int) {
|
||||
u.m.Lock()
|
||||
ox, oy, _, _ := u.screenPaddingImpl()
|
||||
s := u.scaleImpl()
|
||||
|
Loading…
Reference in New Issue
Block a user