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_BorderSize.h
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
29//==============================================================================
40template <typename ValueType>
42{
43 auto tie() const { return std::tie (top, left, bottom, right); }
44
45public:
46 //==============================================================================
50 BorderSize() = default;
51
53 BorderSize (ValueType topGap, ValueType leftGap, ValueType bottomGap, ValueType rightGap) noexcept
54 : top (topGap), left (leftGap), bottom (bottomGap), right (rightGap)
55 {
56 }
57
59 explicit BorderSize (ValueType allGaps) noexcept
60 : top (allGaps), left (allGaps), bottom (allGaps), right (allGaps)
61 {
62 }
63
64 //==============================================================================
66 ValueType getTop() const noexcept { return top; }
67
69 ValueType getLeft() const noexcept { return left; }
70
72 ValueType getBottom() const noexcept { return bottom; }
73
75 ValueType getRight() const noexcept { return right; }
76
78 ValueType getTopAndBottom() const noexcept { return top + bottom; }
79
81 ValueType getLeftAndRight() const noexcept { return left + right; }
82
84 bool isEmpty() const noexcept { return left + right + top + bottom == ValueType(); }
85
86 //==============================================================================
88 void setTop (ValueType newTopGap) noexcept { top = newTopGap; }
89
91 void setLeft (ValueType newLeftGap) noexcept { left = newLeftGap; }
92
94 void setBottom (ValueType newBottomGap) noexcept { bottom = newBottomGap; }
95
97 void setRight (ValueType newRightGap) noexcept { right = newRightGap; }
98
99 //==============================================================================
102 {
103 return { original.getX() + left,
104 original.getY() + top,
105 original.getWidth() - (left + right),
106 original.getHeight() - (top + bottom) };
107 }
108
110 void subtractFrom (Rectangle<ValueType>& rectangle) const noexcept
111 {
112 rectangle = subtractedFrom (rectangle);
113 }
114
117 {
118 return { original.getX() - left,
119 original.getY() - top,
120 original.getWidth() + (left + right),
121 original.getHeight() + (top + bottom) };
122 }
123
125 void addTo (Rectangle<ValueType>& rectangle) const noexcept
126 {
127 rectangle = addedTo (rectangle);
128 }
129
132 {
133 return { other.top - top,
134 other.left - left,
135 other.bottom - bottom,
136 other.right - right };
137 }
138
141 {
142 return { other.top + top,
143 other.left + left,
144 other.bottom + bottom,
145 other.right + right };
146 }
147
149 template <typename ScalarType>
150 BorderSize<ValueType> multipliedBy (ScalarType scalar) const noexcept
151 {
152 return { static_cast<ValueType> (scalar * top),
153 static_cast<ValueType> (scalar * left),
154 static_cast<ValueType> (scalar * bottom),
155 static_cast<ValueType> (scalar * right) };
156 }
157
158 //==============================================================================
159 bool operator== (const BorderSize& other) const noexcept { return tie() == other.tie(); }
160 bool operator!= (const BorderSize& other) const noexcept { return tie() != other.tie(); }
161
162private:
163 //==============================================================================
164 ValueType top{}, left{}, bottom{}, right{};
165};
166
167} // namespace juce
Specifies a set of gaps to be left around the sides of a rectangle.
void setTop(ValueType newTopGap) noexcept
Changes the top gap.
void setRight(ValueType newRightGap) noexcept
Changes the right gap.
BorderSize()=default
Creates a null border.
ValueType getTopAndBottom() const noexcept
Returns the sum of the top and bottom gaps.
BorderSize(ValueType topGap, ValueType leftGap, ValueType bottomGap, ValueType rightGap) noexcept
Creates a border with the given gaps.
BorderSize(ValueType allGaps) noexcept
Creates a border with the given gap on all sides.
ValueType getTop() const noexcept
Returns the gap that should be left at the top of the region.
bool isEmpty() const noexcept
Returns true if this border has no thickness along any edge.
BorderSize< ValueType > addedTo(const BorderSize< ValueType > &other) const noexcept
Adds this border to another border.
ValueType getLeft() const noexcept
Returns the gap that should be left at the left of the region.
BorderSize< ValueType > subtractedFrom(const BorderSize< ValueType > &other) const noexcept
Removes this border from another border.
Rectangle< ValueType > addedTo(const Rectangle< ValueType > &original) const noexcept
Returns a rectangle with these borders added around it.
BorderSize< ValueType > multipliedBy(ScalarType scalar) const noexcept
Multiplies each member of the border by a scalar.
Rectangle< ValueType > subtractedFrom(const Rectangle< ValueType > &original) const noexcept
Returns a rectangle with these borders removed from it.
ValueType getLeftAndRight() const noexcept
Returns the sum of the left and right gaps.
void subtractFrom(Rectangle< ValueType > &rectangle) const noexcept
Removes this border from a given rectangle.
ValueType getRight() const noexcept
Returns the gap that should be left at the right of the region.
void addTo(Rectangle< ValueType > &rectangle) const noexcept
Adds this border around a given rectangle.
void setBottom(ValueType newBottomGap) noexcept
Changes the bottom gap.
void setLeft(ValueType newLeftGap) noexcept
Changes the left gap.
ValueType getBottom() const noexcept
Returns the gap that should be left at the bottom of the region.
Manages a rectangle and allows geometric operations to be performed on it.
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
T tie(T... args)