mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-02 22:14:29 +01:00
internal/ui: use float64 for cursor positions internally
This commit is contained in:
parent
226497a8a9
commit
a62b8a00e7
5
input.go
5
input.go
@ -88,7 +88,8 @@ func KeyName(key Key) string {
|
|||||||
//
|
//
|
||||||
// CursorPosition is concurrent-safe.
|
// CursorPosition is concurrent-safe.
|
||||||
func CursorPosition() (x, y int) {
|
func CursorPosition() (x, y int) {
|
||||||
return theInputState.cursorPosition()
|
cx, cy := theInputState.cursorPosition()
|
||||||
|
return int(cx), int(cy)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wheel returns x and y offsets of the mouse wheel or touchpad scroll.
|
// Wheel returns x and y offsets of the mouse wheel or touchpad scroll.
|
||||||
@ -427,7 +428,7 @@ func (i *inputState) isKeyPressed(key Key) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *inputState) cursorPosition() (int, int) {
|
func (i *inputState) cursorPosition() (float64, float64) {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
return i.state.CursorX, i.state.CursorY
|
return i.state.CursorX, i.state.CursorY
|
||||||
|
@ -41,8 +41,8 @@ type Touch struct {
|
|||||||
type InputState struct {
|
type InputState struct {
|
||||||
KeyPressed [KeyMax + 1]bool
|
KeyPressed [KeyMax + 1]bool
|
||||||
MouseButtonPressed [MouseButtonMax + 1]bool
|
MouseButtonPressed [MouseButtonMax + 1]bool
|
||||||
CursorX int
|
CursorX float64
|
||||||
CursorY int
|
CursorY float64
|
||||||
WheelX float64
|
WheelX float64
|
||||||
WheelY float64
|
WheelY float64
|
||||||
Touches []Touch
|
Touches []Touch
|
||||||
|
@ -68,7 +68,7 @@ func (u *userInterfaceImpl) updateInputState() error {
|
|||||||
|
|
||||||
// AdjustPosition can return NaN at the initialization.
|
// AdjustPosition can return NaN at the initialization.
|
||||||
if !math.IsNaN(cx) && !math.IsNaN(cy) {
|
if !math.IsNaN(cx) && !math.IsNaN(cy) {
|
||||||
u.inputState.CursorX, u.inputState.CursorY = int(cx), int(cy)
|
u.inputState.CursorX, u.inputState.CursorY = cx, cy
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gamepad.Update(); err != nil {
|
if err := gamepad.Update(); err != nil {
|
||||||
|
@ -114,17 +114,16 @@ func (u *userInterfaceImpl) setMouseCursorFromEvent(e js.Value) {
|
|||||||
|
|
||||||
s := u.DeviceScaleFactor()
|
s := u.DeviceScaleFactor()
|
||||||
x, y := u.context.clientPositionToLogicalPosition(e.Get("clientX").Float(), e.Get("clientY").Float(), s)
|
x, y := u.context.clientPositionToLogicalPosition(e.Get("clientX").Float(), e.Get("clientY").Float(), s)
|
||||||
u.origCursorX, u.origCursorY = int(x), int(y)
|
u.origCursorX, u.origCursorY = x, y
|
||||||
|
|
||||||
if u.cursorMode == CursorModeCaptured {
|
if u.cursorMode == CursorModeCaptured {
|
||||||
dx, dy := e.Get("movementX").Float()/s, e.Get("movementY").Float()/s
|
dx, dy := e.Get("movementX").Float()/s, e.Get("movementY").Float()/s
|
||||||
// TODO: Keep float64 values.
|
u.inputState.CursorX += dx
|
||||||
u.inputState.CursorX += int(dx)
|
u.inputState.CursorY += dy
|
||||||
u.inputState.CursorY += int(dy)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
u.inputState.CursorX, u.inputState.CursorY = int(x), int(y)
|
u.inputState.CursorX, u.inputState.CursorY = x, y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) recoverCursorPosition() {
|
func (u *userInterfaceImpl) recoverCursorPosition() {
|
||||||
|
@ -100,8 +100,8 @@ type userInterfaceImpl struct {
|
|||||||
|
|
||||||
context *context
|
context *context
|
||||||
inputState InputState
|
inputState InputState
|
||||||
origCursorX int
|
origCursorX float64
|
||||||
origCursorY int
|
origCursorY float64
|
||||||
|
|
||||||
keyboardLayoutMap js.Value
|
keyboardLayoutMap js.Value
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user