TGUI  0.10-beta
RelFloatRect.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_REL_FLOAT_RECT_HPP
27#define TGUI_REL_FLOAT_RECT_HPP
28
29
30#include <TGUI/AbsoluteOrRelativeValue.hpp>
31#include <TGUI/Rect.hpp>
32
34
35namespace tgui
36{
41 {
45 TGUI_CONSTEXPR RelFloatRect()
46 {
47 // Constructor isn't defined as "= default" because this leads to an IntelliSense error
48 }
49
50
61 m_left{left},
62 m_top{top},
63 m_width{width},
64 m_height{height}
65 {
66 }
67
68
72 TGUI_CONSTEXPR float getLeft() const
73 {
74 return m_left.getValue();
75 }
76
77
81 TGUI_CONSTEXPR float getTop() const
82 {
83 return m_top.getValue();
84 }
85
86
90 TGUI_CONSTEXPR float getWidth() const
91 {
92 return m_width.getValue();
93 }
94
95
99 TGUI_CONSTEXPR float getHeight() const
100 {
101 return m_height.getValue();
102 }
103
107 TGUI_CONSTEXPR Vector2f getPosition() const
108 {
109 return {m_left.getValue(), m_top.getValue()};
110 }
111
112
116 TGUI_CONSTEXPR Vector2f getSize() const
117 {
118 return {m_width.getValue(), m_height.getValue()};
119 }
120
121
125 TGUI_CONSTEXPR FloatRect getRect() const
126 {
127 return {m_left.getValue(), m_top.getValue(), m_width.getValue(), m_height.getValue()};
128 }
129
130
137 TGUI_CONSTEXPR void updateParentSize(Vector2f newParentSize)
138 {
139 m_left.updateParentSize(newParentSize.x);
140 m_top.updateParentSize(newParentSize.y);
141 m_width.updateParentSize(newParentSize.x);
142 m_height.updateParentSize(newParentSize.y);
143 }
144
146 private:
147
148 AbsoluteOrRelativeValue m_left;
149 AbsoluteOrRelativeValue m_top;
150 AbsoluteOrRelativeValue m_width;
151 AbsoluteOrRelativeValue m_height;
152 };
153}
154
156
157#endif // TGUI_REL_FLOAT_RECT_HPP
Class to store the a value that is either a constant or a ratio.
Definition: AbsoluteOrRelativeValue.hpp:43
TGUI_CONSTEXPR float getValue() const
Returns the value.
Definition: AbsoluteOrRelativeValue.hpp:104
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
FloatRect that can contain absolute values or values relative to the parent size.
Definition: RelFloatRect.hpp:41
TGUI_CONSTEXPR float getTop() const
Returns the top position of the rect as an absolute value.
Definition: RelFloatRect.hpp:81
TGUI_CONSTEXPR Vector2f getPosition() const
Returns the size of the rect as an absolute value.
Definition: RelFloatRect.hpp:107
TGUI_CONSTEXPR RelFloatRect()
Default constructor.
Definition: RelFloatRect.hpp:45
TGUI_CONSTEXPR FloatRect getRect() const
Returns the the rectangle as an absolute value.
Definition: RelFloatRect.hpp:125
TGUI_CONSTEXPR float getLeft() const
Returns the left position of the rect as an absolute value.
Definition: RelFloatRect.hpp:72
TGUI_CONSTEXPR float getWidth() const
Returns the width of the rect as an absolute value.
Definition: RelFloatRect.hpp:90
TGUI_CONSTEXPR float getHeight() const
Returns the height of the rect as an absolute value.
Definition: RelFloatRect.hpp:99
TGUI_CONSTEXPR Vector2f getSize() const
Returns the size of the rect as an absolute value.
Definition: RelFloatRect.hpp:116
TGUI_CONSTEXPR RelFloatRect(AbsoluteOrRelativeValue left, AbsoluteOrRelativeValue top, AbsoluteOrRelativeValue width, AbsoluteOrRelativeValue height)
Constructs the rectangle from its position and size.
Definition: RelFloatRect.hpp:59