Browse Source

Made TooltipWindow::getTipFor() a public virtual method

tags/2021-05-28
jules 8 years ago
parent
commit
9ac2fae469
2 changed files with 30 additions and 32 deletions
  1. +21
    -26
      modules/juce_gui_basics/windows/juce_TooltipWindow.cpp
  2. +9
    -6
      modules/juce_gui_basics/windows/juce_TooltipWindow.h

+ 21
- 26
modules/juce_gui_basics/windows/juce_TooltipWindow.cpp View File

@@ -24,22 +24,18 @@
==============================================================================
*/
TooltipWindow::TooltipWindow (Component* const parentComp, const int delayMs)
TooltipWindow::TooltipWindow (Component* parentComp, int delayMs)
: Component ("tooltip"),
lastComponentUnderMouse (nullptr),
millisecondsBeforeTipAppears (delayMs),
mouseClicks (0), mouseWheelMoves (0),
lastCompChangeTime (0), lastHideTime (0),
reentrant (false)
millisecondsBeforeTipAppears (delayMs)
{
if (Desktop::getInstance().getMainMouseSource().canHover())
startTimer (123);
setAlwaysOnTop (true);
setOpaque (true);
if (parentComp != nullptr)
parentComp->addChildComponent (this);
if (Desktop::getInstance().getMainMouseSource().canHover())
startTimer (123);
}
TooltipWindow::~TooltipWindow()
@@ -102,14 +98,13 @@ void TooltipWindow::displayTip (Point<int> screenPos, const String& tip)
}
}
String TooltipWindow::getTipFor (Component* const c)
String TooltipWindow::getTipFor (Component& c)
{
if (c != nullptr
&& Process::isForegroundProcess()
if (Process::isForegroundProcess()
&& ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
{
if (TooltipClient* const ttc = dynamic_cast<TooltipClient*> (c))
if (! c->isCurrentlyBlockedByAnotherModalComponent())
if (auto* ttc = dynamic_cast<TooltipClient*> (&c))
if (! c.isCurrentlyBlockedByAnotherModalComponent())
return ttc->getTooltip();
}
@@ -128,24 +123,24 @@ void TooltipWindow::hideTip()
void TooltipWindow::timerCallback()
{
Desktop& desktop = Desktop::getInstance();
const MouseInputSource mouseSource (desktop.getMainMouseSource());
const unsigned int now = Time::getApproximateMillisecondCounter();
auto& desktop = Desktop::getInstance();
auto mouseSource = desktop.getMainMouseSource();
auto now = Time::getApproximateMillisecondCounter();
Component* const newComp = ! mouseSource.isTouch() ? mouseSource.getComponentUnderMouse() : nullptr;
const String newTip (getTipFor (newComp));
const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
auto* newComp = mouseSource.isTouch() ? nullptr : mouseSource.getComponentUnderMouse();
auto newTip = newComp != nullptr ? getTipFor (*newComp) : String();
bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
lastComponentUnderMouse = newComp;
lastTipUnderMouse = newTip;
const int clickCount = desktop.getMouseButtonClickCounter();
const int wheelCount = desktop.getMouseWheelMoveCounter();
const bool mouseWasClicked = (clickCount > mouseClicks || wheelCount > mouseWheelMoves);
auto clickCount = desktop.getMouseButtonClickCounter();
auto wheelCount = desktop.getMouseWheelMoveCounter();
bool mouseWasClicked = (clickCount > mouseClicks || wheelCount > mouseWheelMoves);
mouseClicks = clickCount;
mouseWheelMoves = wheelCount;
const Point<float> mousePos (mouseSource.getScreenPosition());
const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
auto mousePos = mouseSource.getScreenPosition();
bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
lastMousePos = mousePos;
if (tipChanged || mouseWasClicked || mouseMovedQuickly)
@@ -174,7 +169,7 @@ void TooltipWindow::timerCallback()
// appear after a timeout..
if (newTip.isNotEmpty()
&& newTip != tipShowing
&& now > lastCompChangeTime + (unsigned int) millisecondsBeforeTipAppears)
&& now > lastCompChangeTime + (uint32) millisecondsBeforeTipAppears)
{
displayTip (mousePos.roundToInt(), newTip);
}


+ 9
- 6
modules/juce_gui_basics/windows/juce_TooltipWindow.h View File

@@ -85,6 +85,11 @@ public:
/** Can be called to manually hide the tip if it's showing. */
void hideTip();
/** Asks a component for its tooltip.
This can be overridden if you need custom lookup behaviour or to modify the strings.
*/
virtual String getTipFor (Component&);
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the tooltip.
@@ -121,19 +126,17 @@ public:
private:
//==============================================================================
Point<float> lastMousePos;
Component* lastComponentUnderMouse;
Component* lastComponentUnderMouse = nullptr;
String tipShowing, lastTipUnderMouse;
int millisecondsBeforeTipAppears;
int mouseClicks, mouseWheelMoves;
unsigned int lastCompChangeTime, lastHideTime;
bool reentrant;
int mouseClicks = 0, mouseWheelMoves = 0;
unsigned int lastCompChangeTime = 0, lastHideTime = 0;
bool reentrant = false;
void paint (Graphics&) override;
void mouseEnter (const MouseEvent&) override;
void timerCallback() override;
void updatePosition (const String&, Point<int>, Rectangle<int>);
static String getTipFor (Component*);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TooltipWindow)
};

Loading…
Cancel
Save