diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp index 56aa11ae11..28a9760ff6 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp @@ -1493,12 +1493,17 @@ int LookAndFeel_V2::getSliderPopupPlacement (Slider&) } //============================================================================== -void LookAndFeel_V2::getTooltipSize (const String& tipText, int& width, int& height) +Rectangle LookAndFeel_V2::getTooltipBounds (const String& tipText, Point screenPos, Rectangle parentArea) { 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 (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) diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h index 2342b7cf15..e4f25bb399 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h @@ -195,7 +195,7 @@ public: int getSliderPopupPlacement (Slider&) override; //============================================================================== - void getTooltipSize (const String& tipText, int& width, int& height) override; + Rectangle getTooltipBounds (const String& tipText, Point screenPos, Rectangle parentArea) override; void drawTooltip (Graphics&, const String& text, int width, int height) override; //============================================================================== diff --git a/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp b/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp index 4de7f9fd63..804378d195 100644 --- a/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp @@ -60,16 +60,9 @@ void TooltipWindow::mouseEnter (const MouseEvent&) hideTip(); } -void TooltipWindow::updatePosition (const String& tip, Point pos, const Rectangle& parentArea) +void TooltipWindow::updatePosition (const String& tip, Point pos, Rectangle parentArea) { - int w, h; - getLookAndFeel().getTooltipSize (tip, w, h); - - setBounds (Rectangle (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); } @@ -112,7 +105,7 @@ String TooltipWindow::getTipFor (Component* const c) && Process::isForegroundProcess() && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()) { - if (TooltipClient* const ttc = dynamic_cast (c)) + if (TooltipClient* const ttc = dynamic_cast (c)) if (! c->isCurrentlyBlockedByAnotherModalComponent()) return ttc->getTooltip(); } diff --git a/modules/juce_gui_basics/windows/juce_TooltipWindow.h b/modules/juce_gui_basics/windows/juce_TooltipWindow.h index 3688ae404d..0445a59b81 100644 --- a/modules/juce_gui_basics/windows/juce_TooltipWindow.h +++ b/modules/juce_gui_basics/windows/juce_TooltipWindow.h @@ -61,7 +61,7 @@ public: @param millisecondsBeforeTipAppears the time for which the mouse has to stay still before a tooltip will be shown - @see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipSize + @see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipBounds */ explicit TooltipWindow (Component* parentComponent = nullptr, int millisecondsBeforeTipAppears = 700); @@ -104,8 +104,14 @@ public: { 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 getTooltipBounds (const String& tipText, Point screenPos, Rectangle parentArea) = 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: @@ -121,7 +127,7 @@ private: void paint (Graphics&) override; void mouseEnter (const MouseEvent&) override; void timerCallback() override; - void updatePosition (const String&, Point, const Rectangle&); + void updatePosition (const String&, Point, Rectangle); static String getTipFor (Component*);