ClanLib  2.3.7
quad.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Mark Page
28 */
29 
32 
33 #pragma once
34 
35 #include "../api_core.h"
36 #include "rect.h"
37 #include "size.h"
38 #include "point.h"
39 #include "origin.h"
40 
46 template<typename Type>
48 {
51 
52 public:
54  CL_Quadx() { }
55 
62  CL_Quadx(const CL_Vec2<Type> &new_p, const CL_Vec2<Type> &new_q, const CL_Vec2<Type> &new_r, const CL_Vec2<Type> &new_s)
63  { p = new_p; q = new_q; r = new_r; s = new_s; }
64 
76  CL_Quadx(const CL_Rectx<Type> &rect)
77  { p.x = rect.left; p.y = rect.top; q.x = rect.right; q.y = rect.top;
78  r.x = rect.right; r.y = rect.bottom; s.x = rect.left; s.y = rect.bottom;
79  }
80 
84  CL_Quadx(const CL_Quadx<Type> &quad)
85  { p = quad.p; q = quad.q; r = quad.r; s = quad.s; }
86 
89  { p += quad.p; q += quad.q; r += quad.r; s += quad.s; return *this; }
90 
93  { p -= quad.p; q -= quad.q; r -= quad.r; s -= quad.s; return *this; }
94 
97  { p += point; q += point; r += point; s += point; return *this; }
98 
101  { p -= point; q -= point; r -= point; s -= point; return *this; }
102 
105  { return CL_Quadx(p + quad.p, q + quad.q, r + quad.r, s + quad.s); }
106 
109  { return CL_Quadx(p - quad.p, q - quad.q, r - quad.r, s - quad.s); }
110 
113  { return CL_Quadx(p + point, q + point, r + point, s + point); }
114 
117  { return CL_Quadx(p - point, q - point, r - point, s - point); }
118 
120  bool operator==(const CL_Quadx<Type> &quad) const
121  { return (p == quad.p && q == quad.q && r == quad.r && s == quad.s); }
122 
124  bool operator!=(const CL_Quadx<Type> &quad) const
125  { return (p != quad.p || q != quad.q || r != quad.r || s != quad.s); }
126 
130 
131 public:
134 
137 
140 
143 
145  Type get_width() const;
146 
148  Type get_height() const;
149 
151  CL_Sizex<Type> get_size() const { return CL_Sizex<Type>(get_width(), get_height()); }
152 
154  CL_Rect get_bounds() const;
155 
159 
160 public:
167  CL_Quadx<Type> &rotate(const CL_Vec2<Type> &hotspot, const CL_Angle &angle);
168 
175  CL_Quadx<Type> &scale(float sx, float sy);
176 
184  CL_Quadx<Type> &scale(const CL_Vec2<Type> &hotspot, float sx, float sy);
185 
187  CL_Vec2<Type> center() const;
188 
195  CL_Quadx<Type> &apply_alignment(CL_Origin origin, Type x, Type y);
196 
198 };
199 
203 class CL_Quad : public CL_Quadx<int>
204 {
205 public:
206  CL_Quad() : CL_Quadx<int>() {}
207  CL_Quad(const CL_Vec2<int> &new_p, const CL_Vec2<int> &new_q, const CL_Vec2<int> &new_r, const CL_Vec2<int> &new_s) : CL_Quadx<int>(new_p, new_q, new_r, new_s) {}
208  CL_Quad(const CL_Rect &rect) : CL_Quadx<int>(rect) {}
209  CL_Quad(const CL_Quadx<int> &quad) : CL_Quadx<int>(quad) {}
210 };
211 
215 class CL_Quadf : public CL_Quadx<float>
216 {
217 public:
218  CL_Quadf() : CL_Quadx<float>() {}
219  CL_Quadf(const CL_Vec2<float> &new_p, const CL_Vec2<float> &new_q, const CL_Vec2<float> &new_r, const CL_Vec2<float> &new_s) : CL_Quadx<float>(new_p, new_q, new_r, new_s) {}
220  CL_Quadf(const CL_Rectf &rect) : CL_Quadx<float>(rect) {}
221  CL_Quadf(const CL_Quadx<float> &quad) : CL_Quadx<float>(quad) {}
222 };
223 
227 class CL_Quadd : public CL_Quadx<double>
228 {
229 public:
230  CL_Quadd() : CL_Quadx<double>() {}
231  CL_Quadd(const CL_Vec2<double> &new_p, const CL_Vec2<double> &new_q, const CL_Vec2<double> &new_r, const CL_Vec2<double> &new_s) : CL_Quadx<double>(new_p, new_q, new_r, new_s) {}
232  CL_Quadd(const CL_Rectd &rect) : CL_Quadx<double>(rect) {}
233  CL_Quadd(const CL_Quadx<double> &quad) : CL_Quadx<double>(quad) {}
234 };
235