mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 17:32:02 +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.
|
||||
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.
|
||||
@ -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()
|
||||
defer i.m.Unlock()
|
||||
return i.state.CursorX, i.state.CursorY
|
||||
|
@ -41,8 +41,8 @@ type Touch struct {
|
||||
type InputState struct {
|
||||
KeyPressed [KeyMax + 1]bool
|
||||
MouseButtonPressed [MouseButtonMax + 1]bool
|
||||
CursorX int
|
||||
CursorY int
|
||||
CursorX float64
|
||||
CursorY float64
|
||||
WheelX float64
|
||||
WheelY float64
|
||||
Touches []Touch
|
||||
|
@ -68,7 +68,7 @@ func (u *userInterfaceImpl) updateInputState() error {
|
||||
|
||||
// AdjustPosition can return NaN at the initialization.
|
||||
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 {
|
||||
|
@ -114,17 +114,16 @@ func (u *userInterfaceImpl) setMouseCursorFromEvent(e js.Value) {
|
||||
|
||||
s := u.DeviceScaleFactor()
|
||||
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 {
|
||||
dx, dy := e.Get("movementX").Float()/s, e.Get("movementY").Float()/s
|
||||
// TODO: Keep float64 values.
|
||||
u.inputState.CursorX += int(dx)
|
||||
u.inputState.CursorY += int(dy)
|
||||
u.inputState.CursorX += dx
|
||||
u.inputState.CursorY += dy
|
||||
return
|
||||
}
|
||||
|
||||
u.inputState.CursorX, u.inputState.CursorY = int(x), int(y)
|
||||
u.inputState.CursorX, u.inputState.CursorY = x, y
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) recoverCursorPosition() {
|
||||
|
@ -100,8 +100,8 @@ type userInterfaceImpl struct {
|
||||
|
||||
context *context
|
||||
inputState InputState
|
||||
origCursorX int
|
||||
origCursorY int
|
||||
origCursorX float64
|
||||
origCursorY float64
|
||||
|
||||
keyboardLayoutMap js.Value
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user