Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Overlay.h
Go to the documentation of this file.
1 /* Copyright (C) 2013 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 /*
19 Overlay.h
20 
21 --Overview--
22 
23  Class representing 2D screen overlays; includes functionality for overlay
24  position, color, texture and borders.
25 */
26 
27 #ifndef INCLUDED_OVERLAY
28 #define INCLUDED_OVERLAY
29 
30 #include "graphics/SColor.h"
31 
32 class CStr8;
33 
34 struct CColor
35 {
36  CColor() : r(-1.f), g(-1.f), b(-1.f), a(1.f) {}
37  CColor(float cr,float cg,float cb,float ca) : r(cr), g(cg), b(cb), a(ca) {}
38 
39  bool ParseString(const CStr8& Value, float DefaultAlpha);
40 
41  bool operator == (const CColor &color) const;
42 
43  bool operator != (const CColor &color) const
44  {
45  return !(*this==color);
46  }
47 
48  // For passing to glColor[34]fv:
49  const float* FloatArray() const { return &r; }
50 
51  // For passing to CRenderer:
53  {
54  return SColor4ub((u8)(r*255.0), (u8)(g*255.0), (u8)(b*255.0), (u8)(a*255.0));
55  }
56 
57  float r, g, b, a;
58 };
59 
60 class CPos;
61 class CSize;
62 
63 
64 /**
65  * Rectangle class used for screen rectangles. It's very similar to the MS
66  * CRect, but with FLOATS because it's meant to be used with OpenGL which
67  * takes float values.
68  *
69  * Changed to floats 2004-08-31 /GL
70  */
71 class CRect
72 {
73 public:
74  CRect();
75  CRect(const CPos &pos);
76  CRect(const CSize &size);
77  CRect(const CPos &upperleft, const CPos &bottomright);
78  CRect(const CPos &pos, const CSize &size);
79  CRect(const float l, const float t, const float r, const float b);
80 
81  // Operators
82  CRect& operator = (const CRect& a);
83  bool operator == (const CRect& a) const;
84  bool operator != (const CRect& a) const;
85  CRect operator - (void) const;
86  CRect operator + (void) const;
87 
88  CRect operator + (const CRect& a) const;
89  CRect operator + (const CPos& a) const;
90  CRect operator + (const CSize& a) const;
91  CRect operator - (const CRect& a) const;
92  CRect operator - (const CPos& a) const;
93  CRect operator - (const CSize& a) const;
94 
95  void operator += (const CRect& a);
96  void operator += (const CPos& a);
97  void operator += (const CSize& a);
98  void operator -= (const CRect& a);
99  void operator -= (const CPos& a);
100  void operator -= (const CSize& a);
101 
102  /**
103  * @return Width of Rectangle
104  */
105  float GetWidth() const;
106 
107  /**
108  * @return Height of Rectangle
109  */
110  float GetHeight() const;
111 
112  /**
113  * Get Size
114  */
115  CSize GetSize() const;
116 
117  /**
118  * Get Position equivalent to top/left corner
119  */
120  CPos TopLeft() const;
121 
122  /**
123  * Get Position equivalent to top/right corner
124  */
125  CPos TopRight() const;
126 
127  /**
128  * Get Position equivalent to bottom/left corner
129  */
130  CPos BottomLeft() const;
131 
132  /**
133  * Get Position equivalent to bottom/right corner
134  */
135  CPos BottomRight() const;
136 
137  /**
138  * Get Position equivalent to the center of the rectangle
139  */
140  CPos CenterPoint() const;
141 
142  /**
143  * Evalutates if point is within the rectangle
144  * @param point CPos representing point
145  * @return true if inside.
146  */
147  bool PointInside(const CPos &point) const;
148 
149  CRect Scale(float x, float y) const;
150 
151  /**
152  * Returning CPos representing each corner.
153  */
154 
155 public:
156  /**
157  * Dimensions
158  */
159  float left, top, right, bottom;
160 };
161 
162 /**
163  * Made to represent screen positions and delta values.
164  * @see CRect
165  * @see CSize
166  */
167 class CPos
168 {
169 public:
170  CPos();
171  CPos(const CSize &pos);
172  CPos(const float &_x, const float &_y);
173 
174  // Operators
175  CPos& operator = (const CPos& a);
176  bool operator == (const CPos& a) const;
177  bool operator != (const CPos& a) const;
178  CPos operator - (void) const;
179  CPos operator + (void) const;
180 
181  CPos operator + (const CPos& a) const;
182  CPos operator + (const CSize& a) const;
183  CPos operator - (const CPos& a) const;
184  CPos operator - (const CSize& a) const;
185 
186  void operator += (const CPos& a);
187  void operator += (const CSize& a);
188  void operator -= (const CPos& a);
189  void operator -= (const CSize& a);
190 
191 public:
192  /**
193  * Position
194  */
195  float x, y;
196 };
197 
198 /**
199  * Made to represent a screen size, should in philosophy
200  * be made of unsigned ints, but for the sake of compatibility
201  * with CRect and CPos it's not.
202  * @see CRect
203  * @see CPos
204  */
205 class CSize
206 {
207 public:
208  CSize();
209  CSize(const CRect &rect);
210  CSize(const CPos &pos);
211  CSize(const float &_cx, const float &_cy);
212 
213  // Operators
214  CSize& operator = (const CSize& a);
215  bool operator == (const CSize& a) const;
216  bool operator != (const CSize& a) const;
217  CSize operator - (void) const;
218  CSize operator + (void) const;
219 
220  CSize operator + (const CSize& a) const;
221  CSize operator - (const CSize& a) const;
222  CSize operator / (const float &a) const;
223  CSize operator * (const float &a) const;
224 
225  void operator += (const CSize& a);
226  void operator -= (const CSize& a);
227  void operator /= (const float& a);
228  void operator *= (const float& a);
229 
230 public:
231  /**
232  * Size
233  */
234  float cx, cy;
235 };
236 
237 
238 #endif
#define u8
Definition: types.h:39
CSize operator-(void) const
Definition: Overlay.cpp:422
CSize & operator=(const CSize &a)
Definition: Overlay.cpp:402
CSize operator/(const float &a) const
Definition: Overlay.cpp:446
Made to represent a screen size, should in philosophy be made of unsigned ints, but for the sake of c...
Definition: Overlay.h:205
float g
Definition: Overlay.h:57
CPos CenterPoint() const
Get Position equivalent to the center of the rectangle.
Definition: Overlay.cpp:267
float top
Definition: Overlay.h:159
CPos()
Definition: Overlay.cpp:287
CPos TopRight() const
Get Position equivalent to top/right corner.
Definition: Overlay.cpp:252
Definition: Overlay.h:34
float left
Returning CPos representing each corner.
Definition: Overlay.h:159
void operator*=(const float &a)
Definition: Overlay.cpp:479
CSize GetSize() const
Get Size.
Definition: Overlay.cpp:242
void operator-=(const CRect &a)
Definition: Overlay.cpp:206
void operator/=(const float &a)
Definition: Overlay.cpp:472
void operator+=(const CPos &a)
Definition: Overlay.cpp:356
CRect Scale(float x, float y) const
Definition: Overlay.cpp:280
bool operator!=(const CSize &a) const
Definition: Overlay.cpp:416
bool operator!=(const CPos &a) const
Definition: Overlay.cpp:314
bool ParseString(const CStr8 &Value, float DefaultAlpha)
Definition: Overlay.cpp:30
CSize operator*(const float &a) const
Definition: Overlay.cpp:452
SColor4ub AsSColor4ub() const
Definition: Overlay.h:52
float GetWidth() const
Definition: Overlay.cpp:232
float b
Definition: Overlay.h:57
CPos BottomLeft() const
Get Position equivalent to bottom/left corner.
Definition: Overlay.cpp:257
void operator+=(const CSize &a)
Definition: Overlay.cpp:458
CColor()
Definition: Overlay.h:36
float a
Definition: Overlay.h:57
void operator-=(const CSize &a)
Definition: Overlay.cpp:465
CPos BottomRight() const
Get Position equivalent to bottom/right corner.
Definition: Overlay.cpp:262
bool operator!=(const CColor &color) const
Definition: Overlay.h:43
CRect operator+(void) const
Definition: Overlay.cpp:137
Made to represent screen positions and delta values.
Definition: Overlay.h:167
bool operator==(const CSize &a) const
Definition: Overlay.cpp:410
bool operator==(const CColor &color) const
Definition: Overlay.cpp:65
CPos & operator=(const CPos &a)
Definition: Overlay.cpp:300
float right
Definition: Overlay.h:159
CPos operator-(void) const
Definition: Overlay.cpp:320
CRect operator-(void) const
Definition: Overlay.cpp:131
CSize()
Definition: Overlay.cpp:385
const float * FloatArray() const
Definition: Overlay.h:49
CColor(float cr, float cg, float cb, float ca)
Definition: Overlay.h:37
float y
Definition: Overlay.h:195
float GetHeight() const
Definition: Overlay.cpp:237
void operator-=(const CPos &a)
Definition: Overlay.cpp:370
float cy
Definition: Overlay.h:234
CSize operator+(void) const
Definition: Overlay.cpp:428
float bottom
Definition: Overlay.h:159
void operator+=(const CRect &a)
Definition: Overlay.cpp:179
CPos operator+(void) const
Definition: Overlay.cpp:326
float x
Position.
Definition: Overlay.h:195
bool PointInside(const CPos &point) const
Evalutates if point is within the rectangle.
Definition: Overlay.cpp:272
bool operator==(const CRect &a) const
Definition: Overlay.cpp:116
CRect & operator=(const CRect &a)
Definition: Overlay.cpp:106
CRect()
Definition: Overlay.cpp:75
float cx
Size.
Definition: Overlay.h:234
CPos TopLeft() const
Get Position equivalent to top/left corner.
Definition: Overlay.cpp:247
float r
Definition: Overlay.h:57
bool operator==(const CPos &a) const
Definition: Overlay.cpp:308
bool operator!=(const CRect &a) const
Definition: Overlay.cpp:125
Rectangle class used for screen rectangles.
Definition: Overlay.h:71