diff --git a/examples/wheel/main.go b/examples/wheel/main.go index 9fb67c337..a50c6f752 100644 --- a/examples/wheel/main.go +++ b/examples/wheel/main.go @@ -43,7 +43,7 @@ type Game struct { } func (g *Game) Update() error { - dx, dy := ebiten.Wheel() + dx, dy := ebiten.WheelDelta() g.x += dx g.y += dy return nil diff --git a/input.go b/input.go index e585c7b52..c03ecca2a 100644 --- a/input.go +++ b/input.go @@ -106,6 +106,10 @@ func Wheel() (xoff, yoff float64) { return uiDriver().Input().Wheel() } +func WheelDelta() (xoff, yoff float64) { + return uiDriver().Input().WheelDelta() +} + // IsMouseButtonPressed returns a boolean indicating whether mouseButton is pressed. // // If you want to know whether the mouseButton started being pressed in the current frame, diff --git a/internal/driver/input.go b/internal/driver/input.go index c9f1db278..ce9c525bf 100644 --- a/internal/driver/input.go +++ b/internal/driver/input.go @@ -37,4 +37,5 @@ type Input interface { StandardGamepadButtonValue(id GamepadID, button StandardGamepadButton) float64 TouchPosition(id TouchID) (x, y int) Wheel() (xoff, yoff float64) + WheelDelta() (xoff, yoff float64) } diff --git a/internal/uidriver/glfw/input.go b/internal/uidriver/glfw/input.go index f9873bfbe..6293043b0 100644 --- a/internal/uidriver/glfw/input.go +++ b/internal/uidriver/glfw/input.go @@ -260,6 +260,16 @@ func (i *Input) Wheel() (xoff, yoff float64) { return i.scrollX, i.scrollY } +func (i *Input) WheelDelta() (xoff, yoff float64) { + if !i.ui.isRunning() { + return 0, 0 + } + + i.ui.m.RLock() + defer i.ui.m.RUnlock() + return i.scrollX * wheelFactor, i.scrollY * wheelFactor +} + var glfwMouseButtonToMouseButton = map[glfw.MouseButton]driver.MouseButton{ glfw.MouseButtonLeft: driver.MouseButtonLeft, glfw.MouseButtonRight: driver.MouseButtonRight, diff --git a/internal/uidriver/glfw/ui_darwin.go b/internal/uidriver/glfw/ui_darwin.go index 4fdc3fe60..4dae192e0 100644 --- a/internal/uidriver/glfw/ui_darwin.go +++ b/internal/uidriver/glfw/ui_darwin.go @@ -194,3 +194,5 @@ func (u *UserInterface) adjustViewSize() { func initializeWindowAfterCreation(w *glfw.Window) { } + +const wheelFactor = 10 diff --git a/internal/uidriver/glfw/ui_unix.go b/internal/uidriver/glfw/ui_unix.go index 1c6e4dd41..a318cf76d 100644 --- a/internal/uidriver/glfw/ui_unix.go +++ b/internal/uidriver/glfw/ui_unix.go @@ -179,3 +179,5 @@ func initializeWindowAfterCreation(w *glfw.Window) { // Apparently the window state is inconsistent just after the window is created, but we are not sure. // For more details, see the discussion in #1829. } + +const wheelFactor = 53 diff --git a/internal/uidriver/glfw/ui_windows.go b/internal/uidriver/glfw/ui_windows.go index 0f3c937a7..56fd2bbaa 100644 --- a/internal/uidriver/glfw/ui_windows.go +++ b/internal/uidriver/glfw/ui_windows.go @@ -193,3 +193,5 @@ func (u *UserInterface) adjustViewSize() { func initializeWindowAfterCreation(w *glfw.Window) { } + +const wheelFactor = 120 diff --git a/internal/uidriver/js/input_js.go b/internal/uidriver/js/input_js.go index d0721027d..9ec60f217 100644 --- a/internal/uidriver/js/input_js.go +++ b/internal/uidriver/js/input_js.go @@ -245,6 +245,10 @@ func (i *Input) Wheel() (xoff, yoff float64) { return i.wheelX, i.wheelY } +func (i *Input) WheelDelta() (xoff, yoff float64) { + return i.wheelX, i.wheelY +} + func (i *Input) keyDown(code js.Value) { if i.keyPressed == nil { i.keyPressed = map[int]bool{} diff --git a/internal/uidriver/mobile/input.go b/internal/uidriver/mobile/input.go index 8b3e6fb00..9542b6e3a 100644 --- a/internal/uidriver/mobile/input.go +++ b/internal/uidriver/mobile/input.go @@ -195,6 +195,10 @@ func (i *Input) Wheel() (xoff, yoff float64) { return 0, 0 } +func (i *Input) WheelDelta() (xoff, yoff float64) { + return 0, 0 +} + func (i *Input) IsMouseButtonPressed(key driver.MouseButton) bool { return false }