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_DrawableRectangle.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
29DrawableRectangle::DrawableRectangle() {}
31
32DrawableRectangle::DrawableRectangle (const DrawableRectangle& other)
34 bounds (other.bounds),
35 cornerSize (other.cornerSize)
36{
37 rebuildPath();
38}
39
41{
42 return std::make_unique<DrawableRectangle> (*this);
43}
44
45//==============================================================================
47{
48 if (bounds != newBounds)
49 {
50 bounds = newBounds;
51 rebuildPath();
52 }
53}
54
56{
57 if (cornerSize != newSize)
58 {
59 cornerSize = newSize;
60 rebuildPath();
61 }
62}
63
64void DrawableRectangle::rebuildPath()
65{
66 auto w = bounds.getWidth();
67 auto h = bounds.getHeight();
68
70
71 if (cornerSize.x > 0 && cornerSize.y > 0)
72 newPath.addRoundedRectangle (0, 0, w, h, cornerSize.x, cornerSize.y);
73 else
74 newPath.addRectangle (0, 0, w, h);
75
76 newPath.applyTransform (AffineTransform::fromTargetPoints (Point<float>(), bounds.topLeft,
77 Point<float> (w, 0), bounds.topRight,
78 Point<float> (0, h), bounds.bottomLeft));
79
80 if (path != newPath)
81 {
82 path.swapWithPath (newPath);
84 }
85}
86
87} // 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.
A Drawable object which draws a rectangle.
void setRectangle(Parallelogram< float > newBounds)
Sets the rectangle's bounds.
~DrawableRectangle() override
Destructor.
std::unique_ptr< Drawable > createCopy() const override
Creates a deep copy of this Drawable object.
void setCornerSize(Point< float > newSize)
Sets a new corner size for the rectangle.
A base class implementing common functionality for Drawable classes which consist of some kind of fil...
void pathChanged()
Called when the cached path should be updated.
Represents a parallelogram that is defined by 3 points.
ValueType getWidth() const noexcept
Returns the width of the parallelogram (i.e.
ValueType getHeight() const noexcept
Returns the height of the parallelogram (i.e.
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 addRoundedRectangle(float x, float y, float width, float height, float cornerSize)
Adds a rectangle with rounded corners to the path.
void swapWithPath(Path &) noexcept
Swaps the contents of this path with another one.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
ValueType y
The point's Y coordinate.
Definition juce_Point.h:252
ValueType x
The point's X coordinate.
Definition juce_Point.h:251
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