~eliasnaur/gio

1

Detecting mouse wheel

Details
Message ID
<CALXE8p-jLcJou+wOoAiCFgt9W50aEYWMQ+5Hztf4hQLz2Bwnxw@mail.gmail.com>
DKIM signature
pass
Download raw message
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)
}


`
Details
Message ID
<CHEMRAMNVSNP.38Z1SDH5WRIKQ@themachine>
In-Reply-To
<CALXE8p-jLcJou+wOoAiCFgt9W50aEYWMQ+5Hztf4hQLz2Bwnxw@mail.gmail.com> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
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
Reply to thread Export thread (mbox)