Unify duplicate Breadth-First-Search traversing of the LayeredPainter and SmoothEleva...
[0ad.git] / source / ps / Shapes.h
blobe517aeb3adda831a7c5dbcf8be8990e92589f578
1 /* Copyright (C) 2015 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
19 Shapes.h
21 --Overview--
23 Classes mostly useful for representing 2D screen overlays;
24 includes functionality for overlay position, color, texture and borders.
26 CColor is used more widely for various game systems.
29 #ifndef INCLUDED_SHAPES
30 #define INCLUDED_SHAPES
32 #include "graphics/SColor.h"
34 class CStr8;
36 struct CColor
38 CColor() : r(-1.f), g(-1.f), b(-1.f), a(1.f) {}
39 CColor(float cr,float cg,float cb,float ca) : r(cr), g(cg), b(cb), a(ca) {}
41 bool ParseString(const CStr8& Value, int DefaultAlpha = 255);
43 bool operator == (const CColor &color) const;
45 bool operator != (const CColor &color) const
47 return !(*this==color);
50 // For passing to glColor[34]fv:
51 const float* FloatArray() const { return &r; }
53 // For passing to CRenderer:
54 SColor4ub AsSColor4ub() const
56 return SColor4ub((u8)(r*255.0), (u8)(g*255.0), (u8)(b*255.0), (u8)(a*255.0));
59 float r, g, b, a;
62 class CPos;
63 class CSize;
66 /**
67 * Rectangle class used for screen rectangles. It's very similar to the MS
68 * CRect, but with FLOATS because it's meant to be used with OpenGL which
69 * takes float values.
71 * Changed to floats 2004-08-31 /GL
73 class CRect
75 public:
76 CRect();
77 CRect(const CPos &pos);
78 CRect(const CSize &size);
79 CRect(const CPos &upperleft, const CPos &bottomright);
80 CRect(const CPos &pos, const CSize &size);
81 CRect(const float l, const float t, const float r, const float b);
83 // Operators
84 CRect& operator = (const CRect& a);
85 bool operator == (const CRect& a) const;
86 bool operator != (const CRect& a) const;
87 CRect operator - (void) const;
88 CRect operator + (void) const;
90 CRect operator + (const CRect& a) const;
91 CRect operator + (const CPos& a) const;
92 CRect operator + (const CSize& a) const;
93 CRect operator - (const CRect& a) const;
94 CRect operator - (const CPos& a) const;
95 CRect operator - (const CSize& a) const;
97 void operator += (const CRect& a);
98 void operator += (const CPos& a);
99 void operator += (const CSize& a);
100 void operator -= (const CRect& a);
101 void operator -= (const CPos& a);
102 void operator -= (const CSize& a);
105 * @return Width of Rectangle
107 float GetWidth() const;
110 * @return Height of Rectangle
112 float GetHeight() const;
115 * Get Size
117 CSize GetSize() const;
120 * Get Position equivalent to top/left corner
122 CPos TopLeft() const;
125 * Get Position equivalent to top/right corner
127 CPos TopRight() const;
130 * Get Position equivalent to bottom/left corner
132 CPos BottomLeft() const;
135 * Get Position equivalent to bottom/right corner
137 CPos BottomRight() const;
140 * Get Position equivalent to the center of the rectangle
142 CPos CenterPoint() const;
145 * Evalutates if point is within the rectangle
146 * @param point CPos representing point
147 * @return true if inside.
149 bool PointInside(const CPos &point) const;
151 CRect Scale(float x, float y) const;
154 * Returning CPos representing each corner.
157 public:
159 * Dimensions
161 float left, top, right, bottom;
165 * Made to represent screen positions and delta values.
166 * @see CRect
167 * @see CSize
169 class CPos
171 public:
172 CPos();
173 CPos(const CSize &pos);
174 CPos(const float &_x, const float &_y);
176 // Operators
177 CPos& operator = (const CPos& a);
178 bool operator == (const CPos& a) const;
179 bool operator != (const CPos& a) const;
180 CPos operator - (void) const;
181 CPos operator + (void) const;
183 CPos operator + (const CPos& a) const;
184 CPos operator + (const CSize& a) const;
185 CPos operator - (const CPos& a) const;
186 CPos operator - (const CSize& a) const;
188 void operator += (const CPos& a);
189 void operator += (const CSize& a);
190 void operator -= (const CPos& a);
191 void operator -= (const CSize& a);
193 public:
195 * Position
197 float x, y;
201 * Made to represent a screen size, should in philosophy
202 * be made of unsigned ints, but for the sake of compatibility
203 * with CRect and CPos it's not.
204 * @see CRect
205 * @see CPos
207 class CSize
209 public:
210 CSize();
211 CSize(const CRect &rect);
212 CSize(const CPos &pos);
213 CSize(const float &_cx, const float &_cy);
215 // Operators
216 CSize& operator = (const CSize& a);
217 bool operator == (const CSize& a) const;
218 bool operator != (const CSize& a) const;
219 CSize operator - (void) const;
220 CSize operator + (void) const;
222 CSize operator + (const CSize& a) const;
223 CSize operator - (const CSize& a) const;
224 CSize operator / (const float &a) const;
225 CSize operator * (const float &a) const;
227 void operator += (const CSize& a);
228 void operator -= (const CSize& a);
229 void operator /= (const float& a);
230 void operator *= (const float& a);
232 public:
234 * Size
236 float cx, cy;
240 #endif // INCLUDED_SHAPES