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_DrawableComposite.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 : bounds ({ 0.0f, 0.0f, 100.0f, 100.0f })
31{
32 setContentArea ({ 0.0f, 0.0f, 100.0f, 100.0f });
33}
34
36 : Drawable (other),
37 bounds (other.bounds),
38 contentArea (other.contentArea)
39{
40 for (auto* c : other.getChildren())
41 if (auto* d = dynamic_cast<const Drawable*> (c))
42 addAndMakeVisible (d->createCopy().release());
43}
44
49
51{
52 return std::make_unique<DrawableComposite> (*this);
53}
54
55//==============================================================================
57{
59
60 for (auto* c : getChildren())
61 if (auto* d = dynamic_cast<const Drawable*> (c))
62 r = r.getUnion (d->isTransformed() ? d->getDrawableBounds().transformedBy (d->getTransform())
63 : d->getDrawableBounds());
64
65 return r;
66}
67
72
77
79{
80 if (bounds != newBounds)
81 {
82 bounds = newBounds;
83
84 auto t = AffineTransform::fromTargetPoints (contentArea.getTopLeft(), bounds.topLeft,
85 contentArea.getTopRight(), bounds.topRight,
86 contentArea.getBottomLeft(), bounds.bottomLeft);
87
88 if (t.isSingularity())
89 t = {};
90
91 setTransform (t);
92 }
93}
94
99
105
107{
108 if (auto* parent = getParent())
109 originRelativeToComponent = parent->originRelativeToComponent - getPosition();
110}
111
113{
114 updateBoundsToFitChildren();
115}
116
118{
119 updateBoundsToFitChildren();
120}
121
122void DrawableComposite::updateBoundsToFitChildren()
123{
124 if (! updateBoundsReentrant)
125 {
126 const ScopedValueSetter<bool> setter (updateBoundsReentrant, true, false);
127
129
130 for (auto* c : getChildren())
131 childArea = childArea.getUnion (c->getBoundsInParent());
132
133 auto delta = childArea.getPosition();
135
136 if (childArea != getBounds())
137 {
138 if (! delta.isOrigin())
139 {
140 originRelativeToComponent -= delta;
141
142 for (auto* c : getChildren())
143 c->setBounds (c->getBounds() - delta);
144 }
145
147 }
148 }
149}
150
151//==============================================================================
153{
154 Path p;
155
156 for (auto* c : getChildren())
157 if (auto* d = dynamic_cast<Drawable*> (c))
158 p.addPath (d->getOutlineAsPath());
159
161 return p;
162}
163
164} // namespace juce
static AffineTransform fromTargetPoints(float x00, float y00, float x10, float y10, float x01, float y01) noexcept
Returns the transform that will map three known points onto three coordinates that are supplied.
The base class for all JUCE user-interface objects.
Rectangle< int > getBoundsInParent() const noexcept
Returns the area of this component's parent which this component covers.
AffineTransform getTransform() const
Returns the transform that is currently being applied to this component.
void deleteAllChildren()
Removes and deletes all of this component's children.
void setTransform(const AffineTransform &transform)
Sets a transform matrix to be applied to this component.
Point< int > getPosition() const noexcept
Returns the component's top-left position as a Point.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
Rectangle< int > getBounds() const noexcept
Returns this component's bounding box.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
const Array< Component * > & getChildren() const noexcept
Provides access to the underlying array of child components.
A drawable object which acts as a container for a set of other Drawables.
Rectangle< float > getDrawableBounds() const override
Returns the area that this drawable covers.
void setContentArea(Rectangle< float > newArea)
Changes the main content area.
~DrawableComposite() override
Destructor.
Path getOutlineAsPath() const override
Creates a path that describes the outline of this drawable.
DrawableComposite()
Creates a composite Drawable.
void resetBoundingBoxToContentArea()
Changes the bounding box transform to match the content area, so that any sub-items will be drawn at ...
void childBoundsChanged(Component *) override
Called when one of this component's children is moved or resized.
void childrenChanged() override
Subclasses can use this callback to be told when children are added or removed, or when their z-order...
void parentHierarchyChanged() override
Called to indicate that the component's parents have changed.
std::unique_ptr< Drawable > createCopy() const override
Creates a deep copy of this Drawable object.
void resetContentAreaAndBoundingBoxToFitChildren()
Resets the content area and the bounding transform to fit around the area occupied by the child compo...
void setBoundingBox(Parallelogram< float > newBoundingBox)
Sets the parallelogram that defines the target position of the content rectangle when the drawable is...
The base class for objects which can draw themselves, e.g.
DrawableComposite * getParent() const
Returns the DrawableComposite that contains this object, if there is one.
Represents a parallelogram that is defined by 3 points.
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
Definition juce_Path.h:65
void addPath(const Path &pathToAppend)
Adds another path to this one.
void applyTransform(const AffineTransform &transform) noexcept
Applies a 2D transform to all the vertices in the path.
Manages a rectangle and allows geometric operations to be performed on it.
Point< ValueType > getPosition() const noexcept
Returns the rectangle's top-left position as a Point.
Point< ValueType > getBottomLeft() const noexcept
Returns the rectangle's bottom-left position as a Point.
Point< ValueType > getTopLeft() const noexcept
Returns the rectangle's top-left position as a Point.
Point< ValueType > getTopRight() const noexcept
Returns the rectangle's top-right position as a Point.
Rectangle getUnion(Rectangle other) const noexcept
Returns the smallest rectangle that contains both this one and the one passed-in.
Helper class providing an RAII-based mechanism for temporarily setting and then re-setting a value.
JUCE Namespace.
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