Cabbage Logo
Back to Cabbage Site

Detecting mouse hover?

Would it be possible for some kinda opcode or something to send a message if the mouse is hovering over a widget? Or would this be too complicated/risky to implement?

For context, I was just thinking of the possibility for a user to toggle descriptions or other widgets’ visibility by simply hovering over a widget, since that behavior can be found in some plugins out there (Valhalla, for example).

https://cabbageaudio.com/docs/macros_and_reserved_channels/

Might find something useful here.

Oh yeah, this is very useful. Really cool features here! Thanks for pointing this page out to me, I totally overlooked it.

A new addition to that list is CURRENT_WIDGET, that will return the channel of the widget the mouse is currently hovering over. :+1:

[edit] btw, the docs need updating. The latest version of that list can be read here

1 Like

@fellusive, you can also use a custom identifiers for this. I’ve prepared a simple example.
CustomInfo.csd (798 Bytes)

[edit] you will need to use the latest version of Cabbage for this. There was a bug in the cabbageGet opcode when an empty string was passed as a channel. Fixed now.

Whoa, this is really cool. I understand what’s going on in the instrument by watching the .gif you attached, but for some reason Cabbage crashes if I try to run the instrument on my own computer (macOS, 10.14.6). I’m using the most recent version of Cabbage and Csound.

I’ll try to mess around with the ideas you’ve shown here - thanks for sharing this :slight_smile:

When you say recent, fo you mean this version, it only finished building a few hours ago.

Yep - I’m testing stuff out right now, and so far the culprit seems to be having multiple arguments in cabbageGet’s input.

So it’s not working for you with the cod I posted? let me check that version myself, maybe I forgot to push through some changes…

eh, sorry :rofl: I never pushed the bug fix I mentioned through to git! I just pushed it now. Should be ready in short while. Let me know if it works Ok!

Works ok now! Thanks for the fix

Hmm I apologize for the potentially noob question. Since cabbageGet "CURRENT_WIDGET" doesn’t seem to return anything if the mouse is hovering over something like an image/label, how would one describe this “null” value in Csound?

Basically what I’m trying to do in my instrument is send a visible(0) message to something if the mouse isn’t hovering over an interactive widget, and it’d be much more concise if I knew what to compare the output of cabbageGet "CURRENT_WIDGET" to in order to execute this. For reference…

SWidgetName cabbageGet "CURRENT_WIDGET"   

     if (SWidgetName==NULL) then 

        SIdent sprintfk "visible(0)", gkGain
        chnset SIdent, "label" 

     endif

…where “NULL” is the thing I’m trying to figure out the replacement for.

SWidgetName will always be the last widget that had a channel name. If you want to do this with the new widgets just set a custom identifier that you can query to let you know if you want to make something invisible, for example:

label bounds(34, 158, 168, 22), channel("Label1"), text("I'm a label"), _shouldHide(1)

Then:

instr 1
    SWidgetName, kTrigger cabbageGet "CURRENT_WIDGET"
    kShouldHide cabbageGet SWidgetName, "_shouldHide"
    
    if kTrigger == 1 && kShouldHide == 1 then
        cabbageSet kTrigger, SWidgetName, "visible(0)" 
    endif 
endin

CustomInfo.csd (1.1 KB)

Note this one also needs an update! But lucky for you it’s already built

Thanks for the example Rory! The instrument doesn’t seem to be working properly for me however, even though I have the latest version of Cabbage installed. Here’s what happens on my end:

Sorry @fellusive, I’m not sure why those changes didn’t propagate. Anyhow, I’ve checked the latest build and this code should work fine there. I’d recommend you use the new GUI system, unless you have already completed the development of an instrument, in which case i’d stick with the ident channels, even though you give up some of the new features.

Thanks for the update Rory - I think there’s a problem with typeface in this new version however. With typeface enabled, the text within widgets such as comboboxes or labels exhibits strange behavior or looks abnormal in size/thickness. Same goes for the text under sliders.

Thanks, I’ll take a look. My implantation of this seems to have been a little naive :roll_eyes:

Should be fixed now in GIT and available in Azure shortly.

Thanks for the update again - while the text issues in comboboxes and sliders seem to be fixed, the text in labels with typeface enabled still causes it to display strangely. Like characters missing, and random amounts of space in between characters.

I was seeing that too, but this change seemed to fix that for me? I’ll take another look tomorrow. Thanks for your patience :+1:

1 Like