Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
Rect.h
Go to the documentation of this file.
1/* Copyright (C) 2024 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_RECT
19#define INCLUDED_RECT
20
21class CSize2D;
22class CVector2D;
23
24
25/**
26 * Rectangle class used for screen rectangles. It's very similar to the MS
27 * CRect, but with FLOATS because it's meant to be used with OpenGL which
28 * takes float values.
29 */
30class CRect
31{
32public:
33 CRect();
34 CRect(const CVector2D& pos);
35 CRect(const CSize2D& size);
36 CRect(const CVector2D& upperleft, const CVector2D& bottomright);
37 CRect(const CVector2D& pos, const CSize2D& size);
38 CRect(const float l, const float t, const float r, const float b);
39 CRect(const CRect&);
40
41 CRect& operator=(const CRect& a);
42 bool operator==(const CRect& a) const;
43 bool operator!=(const CRect& a) const;
44 CRect operator-() const;
45 CRect operator+() const;
46
47 CRect operator+(const CRect& a) const;
48 CRect operator+(const CVector2D& a) const;
49 CRect operator+(const CSize2D& a) const;
50 CRect operator-(const CRect& a) const;
51 CRect operator-(const CVector2D& a) const;
52 CRect operator-(const CSize2D& a) const;
53
54 void operator+=(const CRect& a);
55 void operator+=(const CVector2D& a);
56 void operator+=(const CSize2D& a);
57 void operator-=(const CRect& a);
58 void operator-=(const CVector2D& a);
59 void operator-=(const CSize2D& a);
60
61 operator bool() const { return right - left > 0 && bottom - top > 0; }
62
63 /**
64 * @return Width of Rectangle
65 */
66 float GetWidth() const;
67
68 /**
69 * @return Height of Rectangle
70 */
71 float GetHeight() const;
72
73 /**
74 * Get Size
75 */
76 CSize2D GetSize() const;
77
78 /**
79 * Get Position equivalent to top/left corner
80 */
81 CVector2D TopLeft() const;
82
83 /**
84 * Get Position equivalent to top/right corner
85 */
86 CVector2D TopRight() const;
87
88 /**
89 * Get Position equivalent to bottom/left corner
90 */
91 CVector2D BottomLeft() const;
92
93 /**
94 * Get Position equivalent to bottom/right corner
95 */
96 CVector2D BottomRight() const;
97
98 /**
99 * Get Position equivalent to the center of the rectangle
100 */
101 CVector2D CenterPoint() const;
102
103 /**
104 * Evalutates if point is within the rectangle
105 * @param point CVector2D representing point
106 * @return true if inside.
107 */
108 bool PointInside(const CVector2D &point) const;
109
110 CRect Scale(float x, float y) const;
111
112 bool IntersectWith(const CRect& a) const;
113
114 CRect Intersection(const CRect& a) const;
115
116 /**
117 * Returning CVector2D representing each corner.
118 */
119
120public:
121 /**
122 * Dimensions
123 */
125};
126
127#endif // INCLUDED_RECT
Rectangle class used for screen rectangles.
Definition: Rect.h:31
bool PointInside(const CVector2D &point) const
Evalutates if point is within the rectangle.
Definition: Rect.cpp:212
bool operator==(const CRect &a) const
Definition: Rect.cpp:71
CRect operator-() const
Definition: Rect.cpp:84
bool IntersectWith(const CRect &a) const
Definition: Rect.cpp:225
CSize2D GetSize() const
Get Size.
Definition: Rect.cpp:182
CVector2D BottomLeft() const
Get Position equivalent to bottom/left corner.
Definition: Rect.cpp:197
void operator-=(const CRect &a)
Definition: Rect.cpp:148
CVector2D BottomRight() const
Get Position equivalent to bottom/right corner.
Definition: Rect.cpp:202
float left
Returning CVector2D representing each corner.
Definition: Rect.h:124
bool operator!=(const CRect &a) const
Definition: Rect.cpp:79
CVector2D TopLeft() const
Get Position equivalent to top/left corner.
Definition: Rect.cpp:187
float bottom
Definition: Rect.h:124
float GetHeight() const
Definition: Rect.cpp:177
CRect operator+() const
Definition: Rect.cpp:89
void operator+=(const CRect &a)
Definition: Rect.cpp:124
float top
Definition: Rect.h:124
CRect Scale(float x, float y) const
Definition: Rect.cpp:220
float GetWidth() const
Definition: Rect.cpp:172
CRect()
Definition: Rect.cpp:27
CVector2D TopRight() const
Get Position equivalent to top/right corner.
Definition: Rect.cpp:192
CRect Intersection(const CRect &a) const
Definition: Rect.cpp:230
float right
Definition: Rect.h:124
CRect & operator=(const CRect &a)
Definition: Rect.cpp:62
CVector2D CenterPoint() const
Get Position equivalent to the center of the rectangle.
Definition: Rect.cpp:207
Definition: Size2D.h:25
Definition: Vector2D.h:32