0016 - Scroll-wheel and More Button Stuff
Tracking the Scroll-wheel
Time to get down to the nitty gritty of harnessing the mouse wheel.
Got a 3D object you need to zoom in on? How about lines and lines of text that need to be scrolled through? Yeah, that’s what we’re laying groundwork for today. Here’s the constructor:
This should be pretty familiar by now, hook up a signal to a callback using one of the
addOnXxxxx() functions, in this case
addOnScroll() and here’s the callback:
Again, we have to dig a bit to find the data we want: the direction the mouse wheel is turning. The
ScrollDirection enum in
gtk.c.types (that’s generated/gtkd/gtk/c/types.d if you want to see for yourself) provides us with
DOWN so we can check. Makes it easy. I’ve added in a bit of return value roughage so we know for sure we’re done with any signal chain that might end up being processed at the same time.
Left, Middle, & Right Mouse Buttons
Let’s throw caution to the wind and put a
Button back in the window, just one, and give it something interesting to do…
When I was writing out these examples, I’d forgotten I’d already talked about differentiating between mouse buttons, so I wrote this one. This one, though, does process things in a different way:
From here, you could look at the button data, a uint, to see which button was pressed. We handle this with the
Which translates the uint to plain English using the
mouseButtons array defined at the top of the
You may wonder why there’s a
“None” element in this array, but it’s there because there is no mouse button #0. It keeps us from having to subtract ‘1’ each time to find our way to the correct array element.
And so we come to the end of another blog post. Be kind to each other and we’ll talk again soon.
If you'd like to leave a comment...
Until I get time to research and install a commenting system, I ask that you try one of these options:
- come on over to the D Language Forum and look for one of the gtkDcoding announcement posts,
- drop by the gtkD Forum,
- follow the link below to email me, or
- go to the gtkDcoding Facebook page.
You can also subscribe via RSS so you won't miss anything.
© Copyright 2019 Ron Tarrant