Pyrogenesis  trunk
Rect.h
Go to the documentation of this file.
1 /* Copyright (C) 2021 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 
21 class CSize2D;
22 class 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  */
30 class CRect
31 {
32 public:
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  /**
62  * @return Width of Rectangle
63  */
64  float GetWidth() const;
65 
66  /**
67  * @return Height of Rectangle
68  */
69  float GetHeight() const;
70 
71  /**
72  * Get Size
73  */
74  CSize2D GetSize() const;
75 
76  /**
77  * Get Position equivalent to top/left corner
78  */
79  CVector2D TopLeft() const;
80 
81  /**
82  * Get Position equivalent to top/right corner
83  */
84  CVector2D TopRight() const;
85 
86  /**
87  * Get Position equivalent to bottom/left corner
88  */
89  CVector2D BottomLeft() const;
90 
91  /**
92  * Get Position equivalent to bottom/right corner
93  */
94  CVector2D BottomRight() const;
95 
96  /**
97  * Get Position equivalent to the center of the rectangle
98  */
99  CVector2D CenterPoint() const;
100 
101  /**
102  * Evalutates if point is within the rectangle
103  * @param point CVector2D representing point
104  * @return true if inside.
105  */
106  bool PointInside(const CVector2D &point) const;
107 
108  CRect Scale(float x, float y) const;
109 
110  /**
111  * Returning CVector2D representing each corner.
112  */
113 
114 public:
115  /**
116  * Dimensions
117  */
118  float left, top, right, bottom;
119 };
120 
121 #endif // INCLUDED_RECT
float top
Definition: Rect.h:118
float left
Returning CVector2D representing each corner.
Definition: Rect.h:118
void operator-=(const CRect &a)
Definition: Rect.cpp:146
CVector2D BottomLeft() const
Get Position equivalent to bottom/left corner.
Definition: Rect.cpp:195
bool PointInside(const CVector2D &point) const
Evalutates if point is within the rectangle.
Definition: Rect.cpp:210
Definition: Size2D.h:24
CRect Scale(float x, float y) const
Definition: Rect.cpp:218
CVector2D TopLeft() const
Get Position equivalent to top/left corner.
Definition: Rect.cpp:185
CSize2D GetSize() const
Get Size.
Definition: Rect.cpp:180
bool operator!=(const CRect &a) const
Definition: Rect.cpp:77
CRect operator+() const
Definition: Rect.cpp:87
CVector2D CenterPoint() const
Get Position equivalent to the center of the rectangle.
Definition: Rect.cpp:205
CRect operator-() const
Definition: Rect.cpp:82
Definition: Vector2D.h:31
float right
Definition: Rect.h:118
CVector2D BottomRight() const
Get Position equivalent to bottom/right corner.
Definition: Rect.cpp:200
float bottom
Definition: Rect.h:118
void operator+=(const CRect &a)
Definition: Rect.cpp:122
CVector2D TopRight() const
Get Position equivalent to top/right corner.
Definition: Rect.cpp:190
float GetHeight() const
Definition: Rect.cpp:175
CRect & operator=(const CRect &a)
Definition: Rect.cpp:60
CRect()
Definition: Rect.cpp:25
float GetWidth() const
Definition: Rect.cpp:170
Rectangle class used for screen rectangles.
Definition: Rect.h:30
bool operator==(const CRect &a) const
Definition: Rect.cpp:69