| @@ -1493,12 +1493,17 @@ int LookAndFeel_V2::getSliderPopupPlacement (Slider&) | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| void LookAndFeel_V2::getTooltipSize (const String& tipText, int& width, int& height) | |||||
| Rectangle<int> LookAndFeel_V2::getTooltipBounds (const String& tipText, Point<int> screenPos, Rectangle<int> parentArea) | |||||
| { | { | ||||
| const TextLayout tl (LookAndFeelHelpers::layoutTooltipText (tipText, Colours::black)); | const TextLayout tl (LookAndFeelHelpers::layoutTooltipText (tipText, Colours::black)); | ||||
| width = (int) (tl.getWidth() + 14.0f); | |||||
| height = (int) (tl.getHeight() + 6.0f); | |||||
| const int w = (int) (tl.getWidth() + 14.0f); | |||||
| const int h = (int) (tl.getHeight() + 6.0f); | |||||
| return Rectangle<int> (screenPos.x > parentArea.getCentreX() ? screenPos.x - (w + 12) : screenPos.x + 24, | |||||
| screenPos.y > parentArea.getCentreY() ? screenPos.y - (h + 6) : screenPos.y + 6, | |||||
| w, h) | |||||
| .constrainedWithin (parentArea); | |||||
| } | } | ||||
| void LookAndFeel_V2::drawTooltip (Graphics& g, const String& text, int width, int height) | void LookAndFeel_V2::drawTooltip (Graphics& g, const String& text, int width, int height) | ||||
| @@ -195,7 +195,7 @@ public: | |||||
| int getSliderPopupPlacement (Slider&) override; | int getSliderPopupPlacement (Slider&) override; | ||||
| //============================================================================== | //============================================================================== | ||||
| void getTooltipSize (const String& tipText, int& width, int& height) override; | |||||
| Rectangle<int> getTooltipBounds (const String& tipText, Point<int> screenPos, Rectangle<int> parentArea) override; | |||||
| void drawTooltip (Graphics&, const String& text, int width, int height) override; | void drawTooltip (Graphics&, const String& text, int width, int height) override; | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -60,16 +60,9 @@ void TooltipWindow::mouseEnter (const MouseEvent&) | |||||
| hideTip(); | hideTip(); | ||||
| } | } | ||||
| void TooltipWindow::updatePosition (const String& tip, Point<int> pos, const Rectangle<int>& parentArea) | |||||
| void TooltipWindow::updatePosition (const String& tip, Point<int> pos, Rectangle<int> parentArea) | |||||
| { | { | ||||
| int w, h; | |||||
| getLookAndFeel().getTooltipSize (tip, w, h); | |||||
| setBounds (Rectangle<int> (pos.x > parentArea.getCentreX() ? pos.x - (w + 12) : pos.x + 24, | |||||
| pos.y > parentArea.getCentreY() ? pos.y - (h + 6) : pos.y + 6, | |||||
| w, h) | |||||
| .constrainedWithin (parentArea)); | |||||
| setBounds (getLookAndFeel().getTooltipBounds (tip, pos, parentArea)); | |||||
| setVisible (true); | setVisible (true); | ||||
| } | } | ||||
| @@ -112,7 +105,7 @@ String TooltipWindow::getTipFor (Component* const c) | |||||
| && Process::isForegroundProcess() | && Process::isForegroundProcess() | ||||
| && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()) | && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()) | ||||
| { | { | ||||
| if (TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c)) | |||||
| if (TooltipClient* const ttc = dynamic_cast<TooltipClient*> (c)) | |||||
| if (! c->isCurrentlyBlockedByAnotherModalComponent()) | if (! c->isCurrentlyBlockedByAnotherModalComponent()) | ||||
| return ttc->getTooltip(); | return ttc->getTooltip(); | ||||
| } | } | ||||
| @@ -61,7 +61,7 @@ public: | |||||
| @param millisecondsBeforeTipAppears the time for which the mouse has to stay still | @param millisecondsBeforeTipAppears the time for which the mouse has to stay still | ||||
| before a tooltip will be shown | before a tooltip will be shown | ||||
| @see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipSize | |||||
| @see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipBounds | |||||
| */ | */ | ||||
| explicit TooltipWindow (Component* parentComponent = nullptr, | explicit TooltipWindow (Component* parentComponent = nullptr, | ||||
| int millisecondsBeforeTipAppears = 700); | int millisecondsBeforeTipAppears = 700); | ||||
| @@ -104,8 +104,14 @@ public: | |||||
| { | { | ||||
| virtual ~LookAndFeelMethods() {} | virtual ~LookAndFeelMethods() {} | ||||
| virtual void getTooltipSize (const String& tipText, int& width, int& height) = 0; | |||||
| /** returns the bounds for a tooltip at the given screen coordinate, constrained within the given desktop area. */ | |||||
| virtual Rectangle<int> getTooltipBounds (const String& tipText, Point<int> screenPos, Rectangle<int> parentArea) = 0; | |||||
| virtual void drawTooltip (Graphics&, const String& text, int width, int height) = 0; | virtual void drawTooltip (Graphics&, const String& text, int width, int height) = 0; | ||||
| #if JUCE_CATCH_DEPRECATED_CODE_MISUSE | |||||
| // This method has been replaced by getTooltipBounds() | |||||
| virtual int getTooltipSize (const String&, int&, int&) { return 0; } | |||||
| #endif | |||||
| }; | }; | ||||
| private: | private: | ||||
| @@ -121,7 +127,7 @@ private: | |||||
| void paint (Graphics&) override; | void paint (Graphics&) override; | ||||
| void mouseEnter (const MouseEvent&) override; | void mouseEnter (const MouseEvent&) override; | ||||
| void timerCallback() override; | void timerCallback() override; | ||||
| void updatePosition (const String&, Point<int>, const Rectangle<int>&); | |||||
| void updatePosition (const String&, Point<int>, Rectangle<int>); | |||||
| static String getTipFor (Component*); | static String getTipFor (Component*); | ||||