LMMS
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
116 Rectangle<ValueType> addedTo (const Rectangle<ValueType>& original) const noexcept
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
#define noexcept
Definition DistrhoDefines.h:72
ValueType right
Definition juce_BorderSize.h:164
void setTop(ValueType newTopGap) noexcept
Definition juce_BorderSize.h:88
void setRight(ValueType newRightGap) noexcept
Definition juce_BorderSize.h:97
BorderSize()=default
ValueType getTopAndBottom() const noexcept
Definition juce_BorderSize.h:78
BorderSize(ValueType topGap, ValueType leftGap, ValueType bottomGap, ValueType rightGap) noexcept
Definition juce_BorderSize.h:53
BorderSize(ValueType allGaps) noexcept
Definition juce_BorderSize.h:59
ValueType getTop() const noexcept
Definition juce_BorderSize.h:66
bool isEmpty() const noexcept
Definition juce_BorderSize.h:84
BorderSize< ValueType > addedTo(const BorderSize< ValueType > &other) const noexcept
Definition juce_BorderSize.h:140
ValueType getLeft() const noexcept
Definition juce_BorderSize.h:69
BorderSize< ValueType > subtractedFrom(const BorderSize< ValueType > &other) const noexcept
Definition juce_BorderSize.h:131
Rectangle< ValueType > addedTo(const Rectangle< ValueType > &original) const noexcept
Definition juce_BorderSize.h:116
BorderSize< ValueType > multipliedBy(ScalarType scalar) const noexcept
Definition juce_BorderSize.h:150
ValueType left
Definition juce_BorderSize.h:164
Rectangle< ValueType > subtractedFrom(const Rectangle< ValueType > &original) const noexcept
Definition juce_BorderSize.h:101
ValueType getLeftAndRight() const noexcept
Definition juce_BorderSize.h:81
void subtractFrom(Rectangle< ValueType > &rectangle) const noexcept
Definition juce_BorderSize.h:110
ValueType getRight() const noexcept
Definition juce_BorderSize.h:75
void addTo(Rectangle< ValueType > &rectangle) const noexcept
Definition juce_BorderSize.h:125
void setBottom(ValueType newBottomGap) noexcept
Definition juce_BorderSize.h:94
ValueType top
Definition juce_BorderSize.h:164
auto tie() const
Definition juce_BorderSize.h:43
ValueType bottom
Definition juce_BorderSize.h:164
void setLeft(ValueType newLeftGap) noexcept
Definition juce_BorderSize.h:91
ValueType getBottom() const noexcept
Definition juce_BorderSize.h:72
Definition juce_Rectangle.h:67
struct @113205115357366127300225113341150224053346037032::@137033172036070230260373056156374243321245367362 left
struct @113205115357366127300225113341150224053346037032::@137033172036070230260373056156374243321245367362 right
Definition carla_juce.cpp:31
#define const
Definition zconf.h:137