SharedResourcePointer and TooltipWindow example?


#1

I’m trying to follow the advice in TooltipWindow to use a SharedResourcePointer, but I can’t figure out exactly how to change my code to work with that. Currently, I have a TooltipWindow* that I create using “tooltipWindow = new TooltipWindow(this);” in my editor’s constructor. If I define it in my class as “SharedResourcePointer<TooltipWindow> tooltipWindow;”, then how do I create it? I get an error on the “new” that I have currently, saying there is no “=” operator for that. I’ve looked for examples, but none of the ones I’ve seen actually show how/where it is created, only a definition in the class. I tried that (not calling new), and my plug-in crashes when it tries to call the window’s setMillisecondsBeforeTipAppears(), because it hasn’t been created. I’m confused!


#2

It’s a class template, so you need to declare instances of it as

   SharedResourcePointer<TooltipWindow> tipWindow;

…and all of the allocation details are handled for you. On first execution, that template will create a new instance of the template parameter class; on subsequent instantiations, that already existing instance will be used, and that instance is guaranteed to exist until the last SharedResourcePointer object goes out of scope.


#3

That’s what I did. (I edited the post to show the part in angle brackets; requires using backslash to escape that, I guess). But it crashes when it executes the call to set the time before showing. Plus, there is no way to set “this” as the parent component when using that. Just found another post that suggest that the use of SharedResourcePointer is no longer recommended? Instead, I can define it as “TooltipWindow tooltipWindow {this};” Is that the way I should do this (for an audio plug-in)?


#4

Well, that idea doesn’t fly, because then I get multiple tooltip windows, just as the docs said.


#5

Looks like your advice works after all. I don’t understand why it crashed the first time I tried it. Now it’s no longer crashing, and is behaving properly. Never mind!


#6

Jeez, didn’t look at the TooltipWindow docs. Yeah, not sure, because SharedResourcePointer says clearly “The SharedObjectType template type indicates the class to use for the shared object - the only requirements on this class are that it must have a public default constructor and destructor.”

I’ve only been working on host apps of late, so I just create a ScopedPointer<TooltipWindow> in my main window, which isn’t helpful to you.


#7

Well, I have it working, but now have a requirement that the user be able to turn tooltips on and off! Any idea how I can do that? There is nothing in the Look&Feel or the TooltipWindow that suggests the ability to enable or disable the tooltip. Given that I need to use a SharedResourcePointer in my audio plug-in, how can I turn the tooltips on and off (for this instance of the plug-in)? Is it even possible?


#8

The easiest way is probably just to stop the timer of the TooltipWindow:

if (enableTooltips)
{
    if (Desktop::getInstance().getMainMouseSource().canHover())
        tipWindow.startTimer (123);
}
else
{
    tipWindow.stopTimer();
    tipWindow.hideTip();
}

but maybe not the nicest way to do it…


#9

I tried using a container object for the SharedResourcePointer, and creating and destroying that (using std::unique_ptr), but that doesn’t work as expected with multiple plug-in instances. I have to destroy my container object in all instances of the plug-in before the tooltip turns off. I just don’t see any way to accomplish turning on and off tooltips.


#10

Timer is a private base class of TooltipWindow, so I can’t access startTimer() and stopTimer() from an instance of the TooltipWindow, unfortunately.


#11

Oh, I thought I checked it inherits public, but you are right, it’s private inheritance (like it should).
I must have been too tired, sorry…


#12

Hmm, I suppose I could set the delay to INT_MAX milliseconds, which works out to over 596 hours! :slight_smile:


#13

Thought that was working, but on Windows when I disabled the tooltips this way, they appeared immediately! This line of code is why:

&& now > lastCompChangeTime + (uint32) millisecondsBeforeTipAppears

On my pc, "lastCompChangeTime " is returning (currently) as 4fxxxxxx, which when adding INT_MAX to it, wraps to less than “now” every time.

I need a reliable way to disable the tooltips. Anyone?


#14

Ah, now that I have put my TooltipWindow into a container object, and create that container objects using the SharedResourcePointer (instead of creating the TooltipWindow using a SharedResourcePointer directly), I can simply create and delete the TooltipWindow to turn it on or off! That turns it on or off for all current instances of my plug-in, but that’s probably what a user would want, anyway!