OpenMoHAA 0.82.1
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
29{
30public:
31 UIPoint2D pos;
32 UISize2D size;
33
34public:
35 UIRect2D();
36 UIRect2D(float x, float y, float width, float height);
37 UIRect2D(const UIPoint2D& pos, const UISize2D& size);
38
39 float getMinX() const;
40 float getMinY() const;
41 float getMaxX() const;
42 float getMaxY() const;
43 UIPoint2D getUpperLeft() const;
44 UIPoint2D getUpperRight() const;
45 UIPoint2D getLowerLeft() const;
46 UIPoint2D getLowerRight() const;
47
48 bool contains(const UIPoint2D& pos) const;
49 bool contains(float x, float y) const;
50 bool contains(int x, int y) const;
51 bool contains(const UIRect2D& pos) const;
52 bool intersects(const UIRect2D& pos) const;
53};
54
55inline UIRect2D::UIRect2D() {}
56
57inline UIRect2D::UIRect2D(float x, float y, float width, float height)
58{
59 pos = UIPoint2D(x, y);
60 size = UISize2D(width, height);
61}
62
63inline UIRect2D::UIRect2D(const UIPoint2D& pos, const UISize2D& size)
64{
65 this->pos = pos;
66 this->size = size;
67}
68
69inline float UIRect2D::getMinX(void) const
70{
71 return pos.x;
72}
73
74inline float UIRect2D::getMinY(void) const
75{
76 return pos.y;
77}
78
79inline float UIRect2D::getMaxX(void) const
80{
81 return pos.x + size.width;
82}
83
84inline float UIRect2D::getMaxY(void) const
85{
86 return pos.y + size.height;
87}
88
89inline UIPoint2D UIRect2D::getUpperLeft(void) const
90{
91 return UIPoint2D(getMinX(), getMinY());
92}
93
94inline UIPoint2D UIRect2D::getUpperRight(void) const
95{
96 return UIPoint2D(getMaxX(), getMinY());
97}
98
99inline UIPoint2D UIRect2D::getLowerLeft(void) const
100{
101 return UIPoint2D(getMinX(), getMaxY());
102}
103
104inline UIPoint2D UIRect2D::getLowerRight(void) const
105{
106 return UIPoint2D(getMaxX(), getMaxY());
107}
108
109inline bool UIRect2D::contains(const UIPoint2D& pos) const
110{
111 return pos.x >= this->pos.x && pos.x <= this->pos.x + size.width && pos.y >= this->pos.y
112 && pos.y <= this->pos.y + size.height;
113}
114
115inline bool UIRect2D::contains(float x, float y) const
116{
117 return x >= this->pos.x && x <= this->pos.x + size.width && y >= this->pos.y && y <= this->pos.y + size.height;
118}
119
120inline bool UIRect2D::contains(int x, int y) const
121{
122 return x >= this->pos.x && x <= this->pos.x + size.width && y >= this->pos.y && y <= this->pos.y + size.height;
123}
124
125inline bool UIRect2D::contains(const UIRect2D& pos) const
126{
127 return pos.pos.x >= this->pos.x && pos.pos.x <= this->pos.x + size.width && pos.pos.y >= this->pos.y
128 && pos.pos.y <= this->pos.y + size.height;
129}
130
131inline bool UIRect2D::intersects(const UIRect2D& pos) const
132{
133 // FIXME: stub
134 return false;
135}
Definition uipoint2d.h:26
Definition uirect2d.h:29
Definition uisize2d.h:26