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_RectanglePlacement.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
29bool RectanglePlacement::operator== (const RectanglePlacement& other) const noexcept
30{
31 return flags == other.flags;
32}
33
34bool RectanglePlacement::operator!= (const RectanglePlacement& other) const noexcept
35{
36 return flags != other.flags;
37}
38
39void RectanglePlacement::applyTo (double& x, double& y, double& w, double& h,
40 const double dx, const double dy, const double dw, const double dh) const noexcept
41{
42 if (approximatelyEqual (w, 0.0) || approximatelyEqual (h, 0.0))
43 return;
44
45 if ((flags & stretchToFit) != 0)
46 {
47 x = dx;
48 y = dy;
49 w = dw;
50 h = dh;
51 }
52 else
53 {
54 double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
55 : jmin (dw / w, dh / h);
56
57 if ((flags & onlyReduceInSize) != 0)
58 scale = jmin (scale, 1.0);
59
60 if ((flags & onlyIncreaseInSize) != 0)
61 scale = jmax (scale, 1.0);
62
63 w *= scale;
64 h *= scale;
65
66 if ((flags & xLeft) != 0)
67 x = dx;
68 else if ((flags & xRight) != 0)
69 x = dx + dw - w;
70 else
71 x = dx + (dw - w) * 0.5;
72
73 if ((flags & yTop) != 0)
74 y = dy;
75 else if ((flags & yBottom) != 0)
76 y = dy + dh - h;
77 else
78 y = dy + (dh - h) * 0.5;
79 }
80}
81
83{
84 if (source.isEmpty())
85 return AffineTransform();
86
87 float newX = destination.getX();
88 float newY = destination.getY();
89
90 float scaleX = destination.getWidth() / source.getWidth();
91 float scaleY = destination.getHeight() / source.getHeight();
92
93 if ((flags & stretchToFit) == 0)
94 {
95 scaleX = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
96 : jmin (scaleX, scaleY);
97
98 if ((flags & onlyReduceInSize) != 0)
99 scaleX = jmin (scaleX, 1.0f);
100
101 if ((flags & onlyIncreaseInSize) != 0)
102 scaleX = jmax (scaleX, 1.0f);
103
104 scaleY = scaleX;
105
106 if ((flags & xRight) != 0)
107 newX += destination.getWidth() - source.getWidth() * scaleX; // right
108 else if ((flags & xLeft) == 0)
109 newX += (destination.getWidth() - source.getWidth() * scaleX) / 2.0f; // centre
110
111 if ((flags & yBottom) != 0)
112 newY += destination.getHeight() - source.getHeight() * scaleX; // bottom
113 else if ((flags & yTop) == 0)
114 newY += (destination.getHeight() - source.getHeight() * scaleX) / 2.0f; // centre
115 }
116
117 return AffineTransform::translation (-source.getX(), -source.getY())
118 .scaled (scaleX, scaleY)
119 .translated (newX, newY);
120}
121
122} // namespace juce
Represents a 2D affine-transformation matrix.
AffineTransform scaled(float factorX, float factorY) const noexcept
Returns a transform which is the same as this one followed by a re-scaling.
static AffineTransform translation(float deltaX, float deltaY) noexcept
Returns a new transform which is a translation.
AffineTransform translated(float deltaX, float deltaY) const noexcept
Returns a new transform which is the same as this one followed by a translation.
AffineTransform getTransformToFit(const Rectangle< float > &source, const Rectangle< float > &destination) const noexcept
Returns the transform that should be applied to these source coordinates to fit them into the destina...
void applyTo(double &sourceX, double &sourceY, double &sourceW, double &sourceH, double destinationX, double destinationY, double destinationW, double destinationH) const noexcept
Adjusts the position and size of a rectangle to fit it into a space.
Manages a rectangle and allows geometric operations to be performed on it.
JUCE Namespace.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.