TGUI  0.8-dev
Outline.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 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/AbsoluteOrRelativeValue.hpp>
30 #include <SFML/System/Vector2.hpp>
31 
33 
34 namespace 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 
163  TGUI_CONSTEXPR bool operator==(const Outline& outline) const
164  {
165  return (getLeft() == outline.getLeft()) && (getTop() == outline.getTop()) && (getRight() == outline.getRight()) && (getBottom() == outline.getBottom());
166  }
167 
168 
177  TGUI_CONSTEXPR bool operator!=(const Outline& outline) const
178  {
179  return !(*this == outline);
180  }
181 
182 
190  void updateParentSize(sf::Vector2f newParentSize)
191  {
192  m_left.updateParentSize(newParentSize.x);
193  m_top.updateParentSize(newParentSize.y);
194  m_right.updateParentSize(newParentSize.x);
195  m_bottom.updateParentSize(newParentSize.y);
196  }
197 
198 
206  std::string toString() const
207  {
208  return "(" + m_left.toString() + ", " + m_top.toString() + ", " + m_right.toString() + ", " + m_bottom.toString() + ")";
209  }
210 
211 
213  private:
214 
215  AbsoluteOrRelativeValue m_left = 0;
216  AbsoluteOrRelativeValue m_top = 0;
217  AbsoluteOrRelativeValue m_right = 0;
218  AbsoluteOrRelativeValue m_bottom = 0;
219  };
220 
221 
223 
224  using Borders = Outline;
225  using Padding = Outline;
226 
228 }
229 
231 
232 #endif // TGUI_OUTLINE_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
TGUI_CONSTEXPR Outline(T size)
Constructor that initializes the outline.
Definition: Outline.hpp:64
TGUI_CONSTEXPR float getTop() const
Returnes the height of the top border.
Definition: Outline.hpp:125
TGUI_CONSTEXPR Outline(AbsoluteOrRelativeValue width, AbsoluteOrRelativeValue height)
Constructor that initializes the outline.
Definition: Outline.hpp:80
TGUI_CONSTEXPR bool operator!=(const Outline &outline) const
Compares two outlines.
Definition: Outline.hpp:177
Class to store the a value that is either a constant or a ratio.
Definition: AbsoluteOrRelativeValue.hpp:43
TGUI_CONSTEXPR float getRight() const
Returnes the width of the right border.
Definition: Outline.hpp:137
TGUI_CONSTEXPR float getBottom() const
Returnes the height of the bottom border.
Definition: Outline.hpp:149
Definition: Outline.hpp:38
TGUI_CONSTEXPR Outline(AbsoluteOrRelativeValue leftBorderWidth, AbsoluteOrRelativeValue topBorderHeight, AbsoluteOrRelativeValue rightBorderWidth, AbsoluteOrRelativeValue bottomBorderHeight)
Constructor that initializes the outline.
Definition: Outline.hpp:98
TGUI_CONSTEXPR bool operator==(const Outline &outline) const
Compares two outlines.
Definition: Outline.hpp:163
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