internal/uidriver/glfw: Add WheelDelta

This commit is contained in:
Hajime Hoshi 2021-10-09 21:44:43 +09:00
parent d4b5d17e75
commit 7d1810b0d7
9 changed files with 30 additions and 1 deletions

View File

@ -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

View File

@ -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,

View File

@ -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)
}

View File

@ -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,

View File

@ -194,3 +194,5 @@ func (u *UserInterface) adjustViewSize() {
func initializeWindowAfterCreation(w *glfw.Window) {
}
const wheelFactor = 10

View File

@ -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

View File

@ -193,3 +193,5 @@ func (u *UserInterface) adjustViewSize() {
func initializeWindowAfterCreation(w *glfw.Window) {
}
const wheelFactor = 120

View File

@ -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{}

View File

@ -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
}