How can I detect if the mouse wheel is rolling upward or downward in
this function?
`
func doButton(ops *op.Ops, q event.Queue) {
// Process events that arrived between the last frame and this one.
for _, ev := range q.Events(tag) {
if x, ok := ev.(pointer.Event); ok {
switch x.Type {
case pointer.Press:
pressed = true
case pointer.Release:
pressed = false
case pointer.Scroll:
log.Println("Scroll", ev.(pointer.Event))
pressed = !pressed
}
}
}
// Confine the area of interest to a 100x100 rectangle.
area := clip.Rect(image.Rect(0, 0, 100, 100)).Push(ops)
// Declare the tag.
pointer.InputOp{
Tag: tag,
Types: pointer.Press | pointer.Release | pointer.Scroll,
}.Add(ops)
area.Pop()
defer clip.Rect{Max: image.Pt(100, 100)}.Push(ops).Pop()
var c color.NRGBA
if pressed {
c = color.NRGBA{R: 0xFF, A: 0xFF}
} else {
c = color.NRGBA{G: 0xFF, A: 0xFF}
}
paint.ColorOp{Color: c}.Add(ops)
paint.PaintOp{}.Add(ops)
}
`
On Sun Jan 23, 2022 at 01:25, R D wrote:
> How can I detect if the mouse wheel is rolling upward or downward in
> this function?
> `
> func doButton(ops *op.Ops, q event.Queue) {
> // Process events that arrived between the last frame and this one.
>
> for _, ev := range q.Events(tag) {
> if x, ok := ev.(pointer.Event); ok {
> switch x.Type {
> case pointer.Press:
> pressed = true
> case pointer.Release:
> pressed = false
> case pointer.Scroll:
> log.Println("Scroll", ev.(pointer.Event))
What's missing from this? We don't have a way to know the physical direction
of a mouse wheel, in part because pointer.Scrolls are not always initiated
by a scroll wheel.
Can you describe your need in more detail? For example, why is the physical
direction important?
> pressed = !pressed
> }
> }
> }
>
> // Confine the area of interest to a 100x100 rectangle.
> area := clip.Rect(image.Rect(0, 0, 100, 100)).Push(ops)
> // Declare the tag.
> pointer.InputOp{
> Tag: tag,
> Types: pointer.Press | pointer.Release | pointer.Scroll,
> }.Add(ops)
> area.Pop()
>
> defer clip.Rect{Max: image.Pt(100, 100)}.Push(ops).Pop()
> var c color.NRGBA
> if pressed {
> c = color.NRGBA{R: 0xFF, A: 0xFF}
> } else {
> c = color.NRGBA{G: 0xFF, A: 0xFF}
> }
> paint.ColorOp{Color: c}.Add(ops)
> paint.PaintOp{}.Add(ops)
> }
>
>
> `
Elias