JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_BubbleComponent.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30 : allowablePlacements (above | below | left | right)
31{
32 setInterceptsMouseClicks (false, false);
34}
35
37
38//==============================================================================
43
45{
46 getLookAndFeel().drawBubble (g, *this, arrowTip.toFloat(), content.toFloat());
47
48 g.reduceClipRegion (content);
49 g.setOrigin (content.getPosition());
50
51 paintContent (g, content.getWidth(), content.getHeight());
52}
53
55{
56 allowablePlacements = newPlacement;
57}
58
59//==============================================================================
61{
62 jassert (componentToPointTo != nullptr);
63
64 Rectangle<int> target;
65
67 target = p->getLocalArea (componentToPointTo, componentToPointTo->getLocalBounds());
68 else
69 target = componentToPointTo->getScreenBounds().transformedBy (getTransform().inverted());
70
72}
73
78
81{
82 {
83 int contentW = 150, contentH = 30;
86 }
87
88 const int totalW = content.getWidth() + distanceFromTarget * 2;
89 const int totalH = content.getHeight() + distanceFromTarget * 2;
90
93
94 int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
95 int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
96 int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
97 int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
98
99 // look at whether the component is elongated, and if so, try to position next to its longer dimension.
100 if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
101 && (spaceAbove > totalH + 20 || spaceBelow > totalH + 20))
102 {
103 spaceLeft = spaceRight = 0;
104 }
105 else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
106 && (spaceLeft > totalW + 20 || spaceRight > totalW + 20))
107 {
109 }
110
111 int targetX, targetY;
112
114 {
115 targetX = rectangleToPointTo.getCentre().x;
116 arrowTip.x = totalW / 2;
117
118 if (spaceAbove >= spaceBelow)
119 {
120 // above
122 arrowTip.y = content.getBottom() + arrowLength;
123 }
124 else
125 {
126 // below
127 targetY = rectangleToPointTo.getBottom();
128 arrowTip.y = content.getY() - arrowLength;
129 }
130 }
131 else
132 {
133 targetY = rectangleToPointTo.getCentre().y;
134 arrowTip.y = totalH / 2;
135
136 if (spaceLeft > spaceRight)
137 {
138 // on the left
140 arrowTip.x = content.getRight() + arrowLength;
141 }
142 else
143 {
144 // on the right
145 targetX = rectangleToPointTo.getRight();
146 arrowTip.x = content.getX() - arrowLength;
147 }
148 }
149
150 setBounds (targetX - arrowTip.x, targetY - arrowTip.y, totalW, totalH);
151}
152
153} // namespace juce
BubbleComponent()
Creates a BubbleComponent.
void setPosition(Component *componentToPointTo, int distanceFromTarget=15, int arrowLength=10)
Moves and resizes the bubble to point at a given component.
virtual void paintContent(Graphics &g, int width, int height)=0
Subclasses should override this to draw their bubble's contents.
~BubbleComponent() override
Destructor.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
void paint(Graphics &) override
Components can override this method to draw their content.
void setAllowedPlacement(int newPlacement)
Tells the bubble which positions it's allowed to put itself in, relative to the point at which it's p...
virtual void getContentSize(int &width, int &height)=0
Subclasses should override this to return the size of the content they want to draw inside the bubble...
The base class for all JUCE user-interface objects.
AffineTransform getTransform() const
Returns the transform that is currently being applied to this component.
void setInterceptsMouseClicks(bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
Changes the default return value for the hitTest() method.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
Rectangle< int > getParentMonitorArea() const
Returns the screen coordinates of the monitor that contains this component.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
A graphics context, used for drawing a component or image.
bool reduceClipRegion(int x, int y, int width, int height)
Intersects the current clipping region with another region.
void setOrigin(Point< int > newOrigin)
Moves the position of the context's origin.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
constexpr Point< float > toFloat() const noexcept
Casts this point to a Point<float> object.
Definition juce_Point.h:239
ValueType y
The point's Y coordinate.
Definition juce_Point.h:252
ValueType x
The point's X coordinate.
Definition juce_Point.h:251
Manages a rectangle and allows geometric operations to be performed on it.
ValueType getRight() const noexcept
Returns the x coordinate of the rectangle's right-hand-side.
Rectangle< float > toFloat() const noexcept
Casts this rectangle to a Rectangle<float>.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
Point< ValueType > getPosition() const noexcept
Returns the rectangle's top-left position as a Point.
ValueType getBottom() const noexcept
Returns the y coordinate of the rectangle's bottom edge.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
ValueType getY() const noexcept
Returns the y coordinate of the rectangle's top edge.
Rectangle transformedBy(const AffineTransform &transform) const noexcept
Returns the smallest rectangle that can contain the shape created by applying a transform to this rec...
ValueType getHeight() const noexcept
Returns the height of the rectangle.
void setBounds(ValueType newX, ValueType newY, ValueType newWidth, ValueType newHeight) noexcept
Changes all the rectangle's coordinates.
#define jassert(expression)
Platform-independent assertion macro.
JUCE Namespace.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
virtual void drawBubble(Graphics &g, BubbleComponent &bubbleComponent, const Point< float > &positionOfTip, const Rectangle< float > &body)=0
Override this method to draw a speech-bubble pointing at a specific location on the screen.
virtual void setComponentEffectForBubbleComponent(BubbleComponent &bubbleComponent)=0
Override this method to set effects, such as a drop-shadow, on a BubbleComponent.