LMMS
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 (w == 0.0 || 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
Type jmin(const Type a, const Type b)
Definition MathsFunctions.h:60
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
Definition juce_AffineTransform.h:43
static AffineTransform translation(float deltaX, float deltaY) noexcept
Definition juce_AffineTransform.cpp:81
Definition juce_Rectangle.h:67
AffineTransform getTransformToFit(const Rectangle< float > &source, const Rectangle< float > &destination) const noexcept
Definition juce_RectanglePlacement.cpp:82
void applyTo(double &sourceX, double &sourceY, double &sourceW, double &sourceH, double destinationX, double destinationY, double destinationW, double destinationH) const noexcept
Definition juce_RectanglePlacement.cpp:39
RectanglePlacement(int placementFlags) noexcept
Definition juce_RectanglePlacement.h:44
@ onlyReduceInSize
Definition juce_RectanglePlacement.h:106
@ fillDestination
Definition juce_RectanglePlacement.h:101
@ onlyIncreaseInSize
Definition juce_RectanglePlacement.h:111
@ yTop
Definition juce_RectanglePlacement.h:76
@ xRight
Definition juce_RectanglePlacement.h:67
@ stretchToFit
Definition juce_RectanglePlacement.h:90
@ yBottom
Definition juce_RectanglePlacement.h:80
@ xLeft
Definition juce_RectanglePlacement.h:64
int flags
Definition juce_RectanglePlacement.h:171
UINT_D64 w
Definition inflate.c:942
int y
Definition inflate.c:1588
unsigned x[BMAX+1]
Definition inflate.c:1586
Definition carla_juce.cpp:31
constexpr Type jmax(Type a, Type b)
Definition juce_MathsFunctions.h:94
uch h[RAND_HEAD_LEN]
Definition crypt.c:459
dy
Definition zipinfo.c:2288