OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
uirect2d.h
1/*
2===========================================================================
3Copyright (C) 2015 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23#pragma once
24
25#include "uipoint2d.h"
26#include "uisize2d.h"
27
28class UIRect2D {
29public:
30 UIPoint2D pos;
31 UISize2D size;
32
33public:
34 UIRect2D();
35 UIRect2D( float x, float y, float width, float height );
36 UIRect2D( const UIPoint2D& pos, const UISize2D& size );
37
38 float getMinX() const;
39 float getMinY() const;
40 float getMaxX() const;
41 float getMaxY() const;
42 UIPoint2D getUpperLeft() const;
43 UIPoint2D getUpperRight() const;
44 UIPoint2D getLowerLeft() const;
45 UIPoint2D getLowerRight() const;
46
47 bool contains( const UIPoint2D& pos ) const;
48 bool contains( float x, float y ) const;
49 bool contains( int x, int y ) const;
50 bool contains( const UIRect2D& pos ) const;
51 bool intersects( const UIRect2D& pos ) const;
52};
53
54inline
55UIRect2D::UIRect2D()
56{
57}
58
59inline
60UIRect2D::UIRect2D
61 (
62 float x,
63 float y,
64 float width,
65 float height
66 )
67
68{
69 pos = UIPoint2D( x, y );
70 size = UISize2D( width, height );
71}
72
73inline
74UIRect2D::UIRect2D
75 (
76 const UIPoint2D& pos,
77 const UISize2D& size
78 )
79
80{
81 this->pos = pos;
82 this->size = size;
83}
84
85inline
86float UIRect2D::getMinX
87 (
88 void
89 ) const
90
91{
92 return pos.x;
93}
94
95inline
96float UIRect2D::getMinY
97 (
98 void
99 ) const
100
101{
102 return pos.y;
103}
104
105inline
106float UIRect2D::getMaxX
107 (
108 void
109 ) const
110
111{
112 return pos.x + size.width;
113}
114
115inline
116float UIRect2D::getMaxY
117 (
118 void
119 ) const
120
121{
122 return pos.y + size.height;
123}
124
125inline
126UIPoint2D UIRect2D::getUpperLeft
127 (
128 void
129 ) const
130
131{
132 return UIPoint2D( getMinX(), getMinY() );
133}
134
135inline
136UIPoint2D UIRect2D::getUpperRight
137 (
138 void
139 ) const
140
141{
142 return UIPoint2D( getMaxX(), getMinY() );
143}
144
145inline
146UIPoint2D UIRect2D::getLowerLeft
147 (
148 void
149 ) const
150
151{
152 return UIPoint2D( getMinX(), getMaxY() );
153}
154
155inline
156UIPoint2D UIRect2D::getLowerRight
157 (
158 void
159 ) const
160
161{
162 return UIPoint2D( getMaxX(), getMaxY() );
163}
164
165inline
166bool UIRect2D::contains
167 (
168 const UIPoint2D& pos
169 ) const
170
171{
172 return pos.x >= this->pos.x && pos.x <= this->pos.x + size.width
173 && pos.y >= this->pos.y && pos.y <= this->pos.y + size.height;
174}
175
176inline
177bool UIRect2D::contains
178 (
179 float x,
180 float y
181 ) const
182
183{
184 return x >= this->pos.x && x <= this->pos.x + size.width
185 && y >= this->pos.y && y <= this->pos.y + size.height;
186}
187
188inline
189bool UIRect2D::contains
190 (
191 int x,
192 int y
193 ) const
194
195{
196 return x >= this->pos.x && x <= this->pos.x + size.width
197 && y >= this->pos.y && y <= this->pos.y + size.height;
198}
199
200inline
201bool UIRect2D::contains
202 (
203 const UIRect2D& pos
204 ) const
205
206{
207 return pos.pos.x >= this->pos.x && pos.pos.x <= this->pos.x + size.width
208 && pos.pos.y >= this->pos.y && pos.pos.y <= this->pos.y + size.height;
209}
210
211inline
212bool UIRect2D::intersects
213 (
214 const UIRect2D& pos
215 ) const
216
217{
218 // FIXME: stub
219 return false;
220}
Definition uipoint2d.h:25
Definition uirect2d.h:28
Definition uisize2d.h:25