TGUI  1.6.1
Loading...
Searching...
No Matches
Outline.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef TGUI_OUTLINE_HPP
26#define TGUI_OUTLINE_HPP
27
28#include <TGUI/Vector2.hpp>
29#include <TGUI/AbsoluteOrRelativeValue.hpp>
30
32
33TGUI_MODULE_EXPORT namespace tgui
34{
36
37 class TGUI_API Outline
38 {
39 public:
40
46 constexpr Outline(AbsoluteOrRelativeValue size = 0) :
47 m_left {size},
48 m_top {size},
49 m_right {size},
50 m_bottom{size}
51 {
52 }
53
59 template <typename T, typename = typename std::enable_if_t<std::is_arithmetic<T>::value, T>>
60 constexpr Outline(T size) :
61 m_left {size},
62 m_top {size},
63 m_right {size},
64 m_bottom{size}
65 {
66 }
67
75 m_left {width},
76 m_top {height},
77 m_right {width},
78 m_bottom{height}
79 {
80 }
81
90 constexpr Outline(AbsoluteOrRelativeValue leftBorderWidth, AbsoluteOrRelativeValue topBorderHeight, AbsoluteOrRelativeValue rightBorderWidth, AbsoluteOrRelativeValue bottomBorderHeight) :
91 m_left {leftBorderWidth},
92 m_top {topBorderHeight},
93 m_right {rightBorderWidth},
94 m_bottom{bottomBorderHeight}
95 {
96 }
97
103 TGUI_NODISCARD constexpr float getLeft() const
104 {
105 return m_left.getValue();
106 }
107
113 TGUI_NODISCARD constexpr float getTop() const
114 {
115 return m_top.getValue();
116 }
117
123 TGUI_NODISCARD constexpr float getRight() const
124 {
125 return m_right.getValue();
126 }
127
133 TGUI_NODISCARD constexpr float getBottom() const
134 {
135 return m_bottom.getValue();
136 }
137
142 TGUI_NODISCARD constexpr Vector2f getOffset() const
143 {
144 return {getLeft(), getTop()};
145 }
146
154 TGUI_NODISCARD constexpr bool operator==(const Outline& outline) const
155 {
156 return (getLeft() == outline.getLeft()) && (getTop() == outline.getTop()) && (getRight() == outline.getRight()) && (getBottom() == outline.getBottom());
157 }
158
166 TGUI_NODISCARD constexpr bool operator!=(const Outline& outline) const
167 {
168 return !(*this == outline);
169 }
170
176 TGUI_NODISCARD constexpr Outline operator+(const Outline& other) const
177 {
178 return {getLeft() + other.getLeft(),
179 getTop() + other.getTop(),
180 getRight() + other.getRight(),
181 getBottom() + other.getBottom()};
182 }
183
189 TGUI_NODISCARD constexpr Outline operator-(const Outline& other) const
190 {
191 return {getLeft() - other.getLeft(),
192 getTop() - other.getTop(),
193 getRight() - other.getRight(),
194 getBottom() - other.getBottom()};
195 }
196
202 constexpr Outline& operator+=(const Outline& other)
203 {
204 m_left = getLeft() + other.getLeft();
205 m_top = getTop() + other.getTop();
206 m_right = getRight() + other.getRight();
207 m_bottom = getBottom() + other.getBottom();
208 return *this;
209 }
210
216 constexpr Outline& operator-=(const Outline& other)
217 {
218 m_left = getLeft() - other.getLeft();
219 m_top = getTop() - other.getTop();
220 m_right = getRight() - other.getRight();
221 m_bottom = getBottom() - other.getBottom();
222 return *this;
223 }
224
231 constexpr void updateParentSize(Vector2f newParentSize)
232 {
233 m_left.updateParentSize(newParentSize.x);
234 m_top.updateParentSize(newParentSize.y);
235 m_right.updateParentSize(newParentSize.x);
236 m_bottom.updateParentSize(newParentSize.y);
237 }
238
245 TGUI_NODISCARD String toString() const
246 {
247 return U"(" + m_left.toString() + U", " + m_top.toString() + U", " + m_right.toString() + U", " + m_bottom.toString() + U")";
248 }
249
251 private:
252
253 AbsoluteOrRelativeValue m_left = 0;
254 AbsoluteOrRelativeValue m_top = 0;
255 AbsoluteOrRelativeValue m_right = 0;
256 AbsoluteOrRelativeValue m_bottom = 0;
257 };
258
260
261 using Borders = Outline;
262 using Padding = Outline;
263
265}
266
268
269#endif // TGUI_OUTLINE_HPP
Class to store the a value that is either a constant or a ratio.
Definition AbsoluteOrRelativeValue.hpp:45
Definition Outline.hpp:38
constexpr Outline operator+(const Outline &other) const
Adds two outlines together (e.g. to add padding and borders)
Definition Outline.hpp:176
constexpr bool operator!=(const Outline &outline) const
Compares two outlines.
Definition Outline.hpp:166
constexpr Outline & operator-=(const Outline &other)
Subtracts an outline from this instance.
Definition Outline.hpp:216
constexpr Outline(AbsoluteOrRelativeValue leftBorderWidth, AbsoluteOrRelativeValue topBorderHeight, AbsoluteOrRelativeValue rightBorderWidth, AbsoluteOrRelativeValue bottomBorderHeight)
Constructor that initializes the outline.
Definition Outline.hpp:90
constexpr float getTop() const
Returnes the height of the top border.
Definition Outline.hpp:113
constexpr Outline(AbsoluteOrRelativeValue width, AbsoluteOrRelativeValue height)
Constructor that initializes the outline.
Definition Outline.hpp:74
constexpr Vector2f getOffset() const
Returnes the width of the left and top borders.
Definition Outline.hpp:142
constexpr float getRight() const
Returnes the width of the right border.
Definition Outline.hpp:123
constexpr Outline & operator+=(const Outline &other)
Adds an outline to this instance (e.g. to add padding and borders)
Definition Outline.hpp:202
constexpr Outline(T size)
Constructor that initializes the outline.
Definition Outline.hpp:60
constexpr float getLeft() const
Returnes the width of the left border.
Definition Outline.hpp:103
constexpr Outline(AbsoluteOrRelativeValue size=0)
Default constructor that initializes the outline.
Definition Outline.hpp:46
constexpr bool operator==(const Outline &outline) const
Compares two outlines.
Definition Outline.hpp:154
constexpr float getBottom() const
Returnes the height of the bottom border.
Definition Outline.hpp:133
constexpr Outline operator-(const Outline &other) const
Subtracts two outlines from each other.
Definition Outline.hpp:189
T y
Y coordinate of the vector.
Definition Vector2.hpp:136
T x
X coordinate of the vector.
Definition Vector2.hpp:135
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38