quad.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Mark Page
00028 */
00029 
00032 
00033 #pragma once
00034 
00035 #include "../api_core.h"
00036 #include "rect.h"
00037 #include "size.h"
00038 #include "point.h"
00039 #include "origin.h"
00040 
00046 template<typename Type>
00047 class CL_API_CORE CL_Quadx
00048 {
00051 
00052 public:
00054         CL_Quadx() { }
00055 
00062         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)
00063         { p = new_p; q = new_q; r = new_r; s = new_s; }
00064 
00076         CL_Quadx(const CL_Rectx<Type> &rect)
00077         { p.x = rect.left; p.y = rect.top; q.x = rect.right; q.y = rect.top;
00078                 r.x = rect.right; r.y = rect.bottom; s.x = rect.left; s.y = rect.bottom;
00079         }
00080 
00084         CL_Quadx(const CL_Quadx<Type> &quad)
00085         { p = quad.p; q = quad.q; r = quad.r; s = quad.s; }
00086 
00088         CL_Quadx<Type> &operator+=(const CL_Quadx<Type> &quad)
00089         { p += quad.p; q += quad.q;  r += quad.r; s += quad.s; return *this; }
00090 
00092         CL_Quadx<Type> &operator-=(const CL_Quadx<Type> &quad)
00093         { p -= quad.p; q -= quad.q;  r -= quad.r; s -= quad.s; return *this; }
00094 
00096         CL_Quadx<Type> &operator+=(const CL_Vec2<Type> &point)
00097         { p += point; q += point; r += point; s += point; return *this; }
00098 
00100         CL_Quadx<Type> &operator-=(const CL_Vec2<Type> &point)
00101         { p -= point; q -= point; r -= point; s -= point; return *this; }
00102 
00104         CL_Quadx<Type> operator+(const CL_Quadx<Type> &quad) const
00105         { return CL_Quadx(p + quad.p, q + quad.q, r + quad.r, s + quad.s); }
00106 
00108         CL_Quadx<Type> operator-(const CL_Quadx<Type> &quad) const
00109         { return CL_Quadx(p - quad.p, q - quad.q, r - quad.r, s - quad.s); }
00110 
00112         CL_Quadx<Type> operator+(const CL_Vec2<Type>  &point) const
00113         { return CL_Quadx(p + point, q + point,  r + point, s + point); }
00114 
00116         CL_Quadx<Type> operator-(const CL_Vec2<Type>  &point) const
00117         { return CL_Quadx(p - point, q - point,  r - point, s - point); }
00118 
00120         bool operator==(const CL_Quadx<Type> &quad) const
00121         { return (p == quad.p && q == quad.q && r == quad.r && s == quad.s); }
00122 
00124         bool operator!=(const CL_Quadx<Type> &quad) const
00125         { return (p != quad.p || q != quad.q || r != quad.r || s != quad.s); }
00126 
00130 
00131 public:
00133         CL_Vec2<Type> p;
00134 
00136         CL_Vec2<Type> q;
00137 
00139         CL_Vec2<Type> r;
00140 
00142         CL_Vec2<Type> s;
00143 
00145         Type get_width() const;
00146 
00148         Type get_height() const;
00149 
00151         CL_Sizex<Type> get_size() const { return CL_Sizex<Type>(get_width(), get_height()); }
00152 
00154         CL_Rect get_bounds() const;
00155 
00159 
00160 public:
00167         CL_Quadx<Type> &rotate(const CL_Vec2<Type>  &hotspot, const CL_Angle &angle);
00168 
00175         CL_Quadx<Type> &scale(float sx, float sy);
00176 
00184         CL_Quadx<Type> &scale(const CL_Vec2<Type>  &hotspot, float sx, float sy);
00185 
00187         CL_Vec2<Type> center() const;
00188 
00195         CL_Quadx<Type> &apply_alignment(CL_Origin origin, Type x, Type y);
00196 
00198 };
00199 
00203 class CL_Quad : public CL_Quadx<int>
00204 {
00205 public:
00206         CL_Quad() : CL_Quadx<int>() {}
00207         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) {}
00208         CL_Quad(const CL_Rect &rect) : CL_Quadx<int>(rect) {}
00209         CL_Quad(const CL_Quadx<int> &quad) : CL_Quadx<int>(quad) {}
00210 };
00211 
00215 class CL_Quadf : public CL_Quadx<float>
00216 {
00217 public:
00218         CL_Quadf() : CL_Quadx<float>() {}
00219         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) {}
00220         CL_Quadf(const CL_Rectf &rect) : CL_Quadx<float>(rect) {}
00221         CL_Quadf(const CL_Quadx<float> &quad) : CL_Quadx<float>(quad) {}
00222 };
00223 
00227 class CL_Quadd : public CL_Quadx<double>
00228 {
00229 public:
00230         CL_Quadd() : CL_Quadx<double>() {}
00231         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) {}
00232         CL_Quadd(const CL_Rectd &rect) : CL_Quadx<double>(rect) {}
00233         CL_Quadd(const CL_Quadx<double> &quad) : CL_Quadx<double>(quad) {}
00234 };
00235