mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-27 02:20:05 +00:00
Allow multiple TooltipWindows as long as they do not share the same parent component
This commit is contained in:
parent
c154024641
commit
876aaf49e7
2 changed files with 53 additions and 43 deletions
|
|
@ -109,7 +109,8 @@ void TooltipWindow::displayTip (Point<int> screenPos, const String& tip)
|
||||||
if (w != this && w->tipShowing == tipShowing)
|
if (w != this && w->tipShowing == tipShowing)
|
||||||
{
|
{
|
||||||
// Looks like you have more than one TooltipWindow showing the same tip..
|
// Looks like you have more than one TooltipWindow showing the same tip..
|
||||||
// Be careful not to create more than one instance of this class!
|
// Be careful not to create more than one instance of this class with the
|
||||||
|
// same parent component!
|
||||||
jassertfalse;
|
jassertfalse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -153,50 +154,55 @@ void TooltipWindow::timerCallback()
|
||||||
auto now = Time::getApproximateMillisecondCounter();
|
auto now = Time::getApproximateMillisecondCounter();
|
||||||
|
|
||||||
auto* newComp = mouseSource.isTouch() ? nullptr : mouseSource.getComponentUnderMouse();
|
auto* newComp = mouseSource.isTouch() ? nullptr : mouseSource.getComponentUnderMouse();
|
||||||
auto newTip = newComp != nullptr ? getTipFor (*newComp) : String();
|
auto* parent = getParentComponent();
|
||||||
bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
|
|
||||||
lastComponentUnderMouse = newComp;
|
|
||||||
lastTipUnderMouse = newTip;
|
|
||||||
|
|
||||||
auto clickCount = desktop.getMouseButtonClickCounter();
|
if (newComp == nullptr || parent == nullptr || parent == newComp || parent->isParentOf (newComp))
|
||||||
auto wheelCount = desktop.getMouseWheelMoveCounter();
|
|
||||||
bool mouseWasClicked = (clickCount > mouseClicks || wheelCount > mouseWheelMoves);
|
|
||||||
mouseClicks = clickCount;
|
|
||||||
mouseWheelMoves = wheelCount;
|
|
||||||
|
|
||||||
auto mousePos = mouseSource.getScreenPosition();
|
|
||||||
bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
|
|
||||||
lastMousePos = mousePos;
|
|
||||||
|
|
||||||
if (tipChanged || mouseWasClicked || mouseMovedQuickly)
|
|
||||||
lastCompChangeTime = now;
|
|
||||||
|
|
||||||
if (isVisible() || now < lastHideTime + 500)
|
|
||||||
{
|
{
|
||||||
// if a tip is currently visible (or has just disappeared), update to a new one
|
auto newTip = newComp != nullptr ? getTipFor (*newComp) : String();
|
||||||
// immediately if needed..
|
bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
|
||||||
if (newComp == nullptr || mouseWasClicked || newTip.isEmpty())
|
lastComponentUnderMouse = newComp;
|
||||||
|
lastTipUnderMouse = newTip;
|
||||||
|
|
||||||
|
auto clickCount = desktop.getMouseButtonClickCounter();
|
||||||
|
auto wheelCount = desktop.getMouseWheelMoveCounter();
|
||||||
|
bool mouseWasClicked = (clickCount > mouseClicks || wheelCount > mouseWheelMoves);
|
||||||
|
mouseClicks = clickCount;
|
||||||
|
mouseWheelMoves = wheelCount;
|
||||||
|
|
||||||
|
auto mousePos = mouseSource.getScreenPosition();
|
||||||
|
bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
|
||||||
|
lastMousePos = mousePos;
|
||||||
|
|
||||||
|
if (tipChanged || mouseWasClicked || mouseMovedQuickly)
|
||||||
|
lastCompChangeTime = now;
|
||||||
|
|
||||||
|
if (isVisible() || now < lastHideTime + 500)
|
||||||
{
|
{
|
||||||
if (isVisible())
|
// if a tip is currently visible (or has just disappeared), update to a new one
|
||||||
|
// immediately if needed..
|
||||||
|
if (newComp == nullptr || mouseWasClicked || newTip.isEmpty())
|
||||||
{
|
{
|
||||||
lastHideTime = now;
|
if (isVisible())
|
||||||
hideTip();
|
{
|
||||||
|
lastHideTime = now;
|
||||||
|
hideTip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tipChanged)
|
||||||
|
{
|
||||||
|
displayTip (mousePos.roundToInt(), newTip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (tipChanged)
|
else
|
||||||
{
|
{
|
||||||
displayTip (mousePos.roundToInt(), newTip);
|
// if there isn't currently a tip, but one is needed, only let it
|
||||||
}
|
// appear after a timeout..
|
||||||
}
|
if (newTip.isNotEmpty()
|
||||||
else
|
&& newTip != tipShowing
|
||||||
{
|
&& now > lastCompChangeTime + (uint32) millisecondsBeforeTipAppears)
|
||||||
// if there isn't currently a tip, but one is needed, only let it
|
{
|
||||||
// appear after a timeout..
|
displayTip (mousePos.roundToInt(), newTip);
|
||||||
if (newTip.isNotEmpty()
|
}
|
||||||
&& newTip != tipShowing
|
|
||||||
&& now > lastCompChangeTime + (uint32) millisecondsBeforeTipAppears)
|
|
||||||
{
|
|
||||||
displayTip (mousePos.roundToInt(), newTip);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,15 @@ namespace juce
|
||||||
A window that displays a pop-up tooltip when the mouse hovers over another component.
|
A window that displays a pop-up tooltip when the mouse hovers over another component.
|
||||||
|
|
||||||
To enable tooltips in your app, just create a single instance of a TooltipWindow
|
To enable tooltips in your app, just create a single instance of a TooltipWindow
|
||||||
object. Note that if you instantiate more than one instance of this class, you'll
|
object. Note that if you instantiate more than one instance of this class with the
|
||||||
end up with multiple tooltips being shown! This is a common problem when compiling
|
same parentComponent (even if both TooltipWindow's parentComponent is nil), you'll
|
||||||
audio plug-ins with JUCE: depending on the way you instantiate TooltipWindow,
|
end up with multiple tooltips being shown! To avoid this use a SharedResourcePointer
|
||||||
you may end up with a TooltipWindow for each plug-in instance. To avoid this use a
|
to instantiate the TooltipWindow only once.
|
||||||
SharedResourcePointer to instantiate the TooltipWindow only once.
|
|
||||||
|
For audio plug-ins (which should not be opening native windows) it is better
|
||||||
|
to add a TooltipWindow as a member variable to the editor and ensure that the
|
||||||
|
editor is the parentComponent of your TooltipWindow. This will ensure that your
|
||||||
|
TooltipWindow is scaled according to your editor and the DAWs scaling setting.
|
||||||
|
|
||||||
The TooltipWindow object will then stay invisible, waiting until the mouse
|
The TooltipWindow object will then stay invisible, waiting until the mouse
|
||||||
hovers for the specified length of time - it will then see if it's currently
|
hovers for the specified length of time - it will then see if it's currently
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue