iPlug2 Forum

How to detect MouseOver in general

Hi.

I am a bit confused about how to attach a MouseOver / MouseLeave event detector to a single control.

Like for example , I might attach three ITextToggleControls like this

pGraphics->AttachControl(new ITextToggleControl(
                                                           settingWidgetBounds.GetGridCell(0, 0, 1, 3),
                                                           showHideAddresses,
                                                           ICON_FK_CIRCLE_O,
                                                           ICON_FK_QUESTION_CIRCLE_O,
                                                           forkAwesomeText
                                                         )
                                  , kCtrlShowInfo, "prefs");

But how would I then attach a MouseOver action/callback to each one? I can’t seem to find a clear example in the Examples folder, and I don’t really understand how the float x and float y in the method signature are supposed to be used

Could someone demonstrate the pattern?

IControl::OnMouseOver is a virtual method you can use to detect mouse overs.

The default is to set a flag and set the control to redraw, and you can then draw differently according to whether there is a mouseover or not. A example of an override can be found on line 423 of IControls.cpp (note the “s” - it’s IControls.cpp not IControl.cpp) - this is for IVTabSwitchControl::OnMouseOver.

Details of what you do in your override will depend on what you wish to achieve.

Thanks @AlexHarker - I guess I was stuck because I instantiate and attach a control using the Lambda pattern that is demonstrated throughout the examples ( as in my code clip above ) - the intuitive thing is to then attach a mouseOver call back lambda.

But if I understand it correctly, I need to make a user defined class that is ( in my case ) an ITextToggleControl inherting from the ITextToggleControl base class , which I think is ITextControl ?

Then override the mouse virtual function

That sounds about right - I’m not so familiar with all of the built-in controls as I commonly build from scratch, just using Control as a base, so I’m not sure of the details of ITextToggleControl. For much basic stuff you can use the pre-rolled controls, but if you want to get really detailed interactions, at some point you will need to inherit from a suitable base and override methods as needed.

got it , brilliant. Thanks!