TGUI  0.9.5
Loading...
Searching...
No Matches
Outline.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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
26#ifndef TGUI_OUTLINE_HPP
27#define TGUI_OUTLINE_HPP
28
29#include <TGUI/Vector2.hpp>
30#include <TGUI/AbsoluteOrRelativeValue.hpp>
31
33
34namespace tgui
35{
37
38 class TGUI_API Outline
39 {
40 public:
41
48 TGUI_CONSTEXPR Outline(AbsoluteOrRelativeValue size = 0) :
49 m_left {size},
50 m_top {size},
51 m_right {size},
52 m_bottom{size}
53 {
54 }
55
56
63 template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
64 TGUI_CONSTEXPR Outline(T size) :
65 m_left {size},
66 m_top {size},
67 m_right {size},
68 m_bottom{size}
69 {
70 }
71
72
81 m_left {width},
82 m_top {height},
83 m_right {width},
84 m_bottom{height}
85 {
86 }
87
88
98 TGUI_CONSTEXPR Outline(AbsoluteOrRelativeValue leftBorderWidth, AbsoluteOrRelativeValue topBorderHeight, AbsoluteOrRelativeValue rightBorderWidth, AbsoluteOrRelativeValue bottomBorderHeight) :
99 m_left {leftBorderWidth},
100 m_top {topBorderHeight},
101 m_right {rightBorderWidth},
102 m_bottom{bottomBorderHeight}
103 {
104 }
105
106
113 TGUI_CONSTEXPR float getLeft() const
114 {
115 return m_left.getValue();
116 }
117
118
125 TGUI_CONSTEXPR float getTop() const
126 {
127 return m_top.getValue();
128 }
129
130
137 TGUI_CONSTEXPR float getRight() const
138 {
139 return m_right.getValue();
140 }
141
142
149 TGUI_CONSTEXPR float getBottom() const
150 {
151 return m_bottom.getValue();
152 }
153
154
159 TGUI_CONSTEXPR Vector2f getOffset() const
160 {
161 return Vector2f(getLeft(), getTop());
162 }
163
164
173 TGUI_CONSTEXPR bool operator==(const Outline& outline) const
174 {
175 return (getLeft() == outline.getLeft()) && (getTop() == outline.getTop()) && (getRight() == outline.getRight()) && (getBottom() == outline.getBottom());
176 }
177
178
187 TGUI_CONSTEXPR bool operator!=(const Outline& outline) const
188 {
189 return !(*this == outline);
190 }
191
192
198 TGUI_CONSTEXPR Outline operator+(const Outline& other) const
199 {
200 return {getLeft() + other.getLeft(),
201 getTop() + other.getTop(),
202 getRight() + other.getRight(),
203 getBottom() + other.getBottom()};
204 }
205
211 TGUI_CONSTEXPR Outline operator-(const Outline& other) const
212 {
213 return {getLeft() - other.getLeft(),
214 getTop() - other.getTop(),
215 getRight() - other.getRight(),
216 getBottom() - other.getBottom()};
217 }
218
224 TGUI_CONSTEXPR Outline& operator+=(const Outline& other)
225 {
226 m_left = getLeft() + other.getLeft();
227 m_top = getTop() + other.getTop();
228 m_right = getRight() + other.getRight();
229 m_bottom = getBottom() + other.getBottom();
230 return *this;
231 }
232
238 TGUI_CONSTEXPR Outline& operator-=(const Outline& other)
239 {
240 m_left = getLeft() - other.getLeft();
241 m_top = getTop() - other.getTop();
242 m_right = getRight() - other.getRight();
243 m_bottom = getBottom() - other.getBottom();
244 return *this;
245 }
246
247
255 TGUI_CONSTEXPR void updateParentSize(Vector2f newParentSize)
256 {
257 m_left.updateParentSize(newParentSize.x);
258 m_top.updateParentSize(newParentSize.y);
259 m_right.updateParentSize(newParentSize.x);
260 m_bottom.updateParentSize(newParentSize.y);
261 }
262
263
271 String toString() const
272 {
273 return "(" + m_left.toString() + ", " + m_top.toString() + ", " + m_right.toString() + ", " + m_bottom.toString() + ")";
274 }
275
276
278 private:
279
280 AbsoluteOrRelativeValue m_left = 0;
281 AbsoluteOrRelativeValue m_top = 0;
282 AbsoluteOrRelativeValue m_right = 0;
283 AbsoluteOrRelativeValue m_bottom = 0;
284 };
285
286
288
289 using Borders = Outline;
290 using Padding = Outline;
291
293}
294
296
297#endif // TGUI_OUTLINE_HPP
Class to store the a value that is either a constant or a ratio.
Definition AbsoluteOrRelativeValue.hpp:43
Definition Outline.hpp:39
TGUI_CONSTEXPR Outline(AbsoluteOrRelativeValue size=0)
Default constructor that initializes the outline.
Definition Outline.hpp:48
TGUI_CONSTEXPR float getLeft() const
Returnes the width of the left border.
Definition Outline.hpp:113
TGUI_CONSTEXPR float getTop() const
Returnes the height of the top border.
Definition Outline.hpp:125
TGUI_CONSTEXPR bool operator!=(const Outline &outline) const
Compares two outlines.
Definition Outline.hpp:187
TGUI_CONSTEXPR float getRight() const
Returnes the width of the right border.
Definition Outline.hpp:137
TGUI_CONSTEXPR Outline(AbsoluteOrRelativeValue leftBorderWidth, AbsoluteOrRelativeValue topBorderHeight, AbsoluteOrRelativeValue rightBorderWidth, AbsoluteOrRelativeValue bottomBorderHeight)
Constructor that initializes the outline.
Definition Outline.hpp:98
TGUI_CONSTEXPR Outline operator+(const Outline &other) const
Adds two outlines together (e.g. to add padding and borders)
Definition Outline.hpp:198
TGUI_CONSTEXPR Outline(T size)
Constructor that initializes the outline.
Definition Outline.hpp:64
TGUI_CONSTEXPR bool operator==(const Outline &outline) const
Compares two outlines.
Definition Outline.hpp:173
TGUI_CONSTEXPR Outline & operator+=(const Outline &other)
Adds an outline to this instance (e.g. to add padding and borders)
Definition Outline.hpp:224
TGUI_CONSTEXPR Outline(AbsoluteOrRelativeValue width, AbsoluteOrRelativeValue height)
Constructor that initializes the outline.
Definition Outline.hpp:80
TGUI_CONSTEXPR Outline & operator-=(const Outline &other)
Subtracts an outline from this instance.
Definition Outline.hpp:238
TGUI_CONSTEXPR Outline operator-(const Outline &other) const
Subtracts two outlines from each other.
Definition Outline.hpp:211
TGUI_CONSTEXPR float getBottom() const
Returnes the height of the bottom border.
Definition Outline.hpp:149
TGUI_CONSTEXPR Vector2f getOffset() const
Returnes the width of the left and top borders.
Definition Outline.hpp:159
T y
Y coordinate of the vector.
Definition Vector2.hpp:142
T x
X coordinate of the vector.
Definition Vector2.hpp:141
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36