0015 - Entering and Leaving
Today’s code also takes place in an unadorned TestRigWindow, not because Buttons would confuse things, but because we only need a window to illustrate the
LEAVE_NOTIFY events, what happens when the mouse pointer enters or leaves a designated area.
The example uses a
MainWindow derivative, but it can be used with any object derived from a
Button, even a
MenuItem, or if a container of some kind. Pretty much anything you need to do with it.
And let’s have a look…
At first glance, it looks like we’re setting up a signal chain like we did before, but these signals won’t be firing at the same time. As you might expect, one fires as the mouse enters the window, the other as it leaves.
And notice, too, that both signals are set up to trigger the same callback,
onEvent(), so let’s have a look at that:
Well, ain’t that fancy. This function even takes care of the grammar. The
messageStart, defined at the top of the
TestRigWindow class, looks like this:
onEvent()’s if’s, and’s and but’s, we get messages like:
We’ve experienced an
We’ve experienced a
Okay, that’s all we need to look at here. Let’s move on.
Mouse Pointer Tracking
In the constructor, we hook up the
MOTION_NOTIFY signal by calling
onMotion() callback does the tracking:
Yup, you’ve got to dig down a little to find those coordinates. As you may imagine, this would give you raw data for drawing with the mouse or perhaps for pulling a noodle from one node to another.
And there we have it, two more examples of harnessing Events to do our bidding.
Until next time…
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