diff --git a/modules/juce_gui_basics/misc/juce_BubbleComponent.cpp b/modules/juce_gui_basics/misc/juce_BubbleComponent.cpp index f45c93eb87..7a547854b7 100644 --- a/modules/juce_gui_basics/misc/juce_BubbleComponent.cpp +++ b/modules/juce_gui_basics/misc/juce_BubbleComponent.cpp @@ -49,35 +49,37 @@ void BubbleComponent::setAllowedPlacement (const int newPlacement) allowablePlacements = newPlacement; } -void BubbleComponent::setPosition (Component* componentToPointTo) +//============================================================================== +void BubbleComponent::setPosition (Component* componentToPointTo, int distanceFromTarget, int arrowLength) { jassert (componentToPointTo != nullptr); + Rectangle target; + if (Component* p = getParentComponent()) - setPosition (p->getLocalArea (componentToPointTo, componentToPointTo->getLocalBounds())); + target = p->getLocalArea (componentToPointTo, componentToPointTo->getLocalBounds()); else - setPosition (componentToPointTo->getScreenBounds()); + target = componentToPointTo->getScreenBounds(); + + setPosition (target, distanceFromTarget, arrowLength); } -void BubbleComponent::setPosition (Point pos) +void BubbleComponent::setPosition (Point arrowTipPos, int arrowLength) { - setPosition (Rectangle (pos.x, pos.y, 1, 1)); + setPosition (Rectangle (arrowTipPos.x, arrowTipPos.y, 1, 1), arrowLength, arrowLength); } -//============================================================================== -void BubbleComponent::setPosition (const Rectangle& rectangleToPointTo) +void BubbleComponent::setPosition (Rectangle rectangleToPointTo, + int distanceFromTarget, int arrowLength) { - const int edgeSpace = 15; - const int arrowLength = 10; - { int contentW = 150, contentH = 30; getContentSize (contentW, contentH); - content.setBounds (edgeSpace, edgeSpace, contentW, contentH); + content.setBounds (distanceFromTarget, distanceFromTarget, contentW, contentH); } - const int totalW = content.getWidth() + edgeSpace * 2; - const int totalH = content.getHeight() + edgeSpace * 2; + const int totalW = content.getWidth() + distanceFromTarget * 2; + const int totalH = content.getHeight() + distanceFromTarget * 2; const Rectangle availableSpace (getParentComponent() != nullptr ? getParentComponent()->getLocalBounds() : getParentMonitorArea()); diff --git a/modules/juce_gui_basics/misc/juce_BubbleComponent.h b/modules/juce_gui_basics/misc/juce_BubbleComponent.h index c6c758a4ad..8536f9bd77 100644 --- a/modules/juce_gui_basics/misc/juce_BubbleComponent.h +++ b/modules/juce_gui_basics/misc/juce_BubbleComponent.h @@ -94,7 +94,8 @@ public: on where there's the most space, honouring any restrictions that were set with setAllowedPlacement(). */ - void setPosition (Component* componentToPointTo); + void setPosition (Component* componentToPointTo, + int distanceFromTarget = 15, int arrowLength = 10); /** Moves and resizes the bubble to point at a given point. @@ -107,7 +108,7 @@ public: on where there's the most space, honouring any restrictions that were set with setAllowedPlacement(). */ - void setPosition (Point arrowTipPosition); + void setPosition (Point arrowTipPosition, int arrowLength = 10); /** Moves and resizes the bubble to point at a given rectangle. @@ -119,8 +120,12 @@ public: It'll put itself either above, below, or to the side of the component depending on where there's the most space, honouring any restrictions that were set with setAllowedPlacement(). + + distanceFromTarget is the amount of space to leave between the bubble and the + target rectangle, and arrowLength is the length of the arrow that it will draw. */ - void setPosition (const Rectangle& rectangleToPointTo); + void setPosition (Rectangle rectangleToPointTo, + int distanceFromTarget = 15, int arrowLength = 10); //============================================================================== /** A set of colour IDs to use to change the colour of various aspects of the bubble component.