size.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 **    Kenneth Gangstoe
00028 */
00029 
00032 
00033 #pragma once
00034 
00035 #include "../api_core.h"
00036 
00037 template<typename Type>
00038 class CL_Vec2;
00039 
00040 template<typename Type>
00041 class CL_Vec3;
00042 
00043 template<typename Type>
00044 class CL_Vec4;
00045 
00051 template<typename Type>
00052 class CL_API_CORE CL_Sizex
00053 {
00056 
00057 public:
00059         CL_Sizex() : width(0), height(0) { return; }
00060 
00065         CL_Sizex(Type width, Type height)
00066         : width(width), height(height) { }
00067 
00071         CL_Sizex(const CL_Sizex<Type> &s)
00072         { width = s.width; height = s.height; }
00073 
00077 
00078 public:
00080         Type width;
00081 
00083         Type height;
00084 
00088 
00089 public:
00091         CL_Sizex<Type> &operator+=(const CL_Sizex<Type> &s)
00092         { width += s.width; height += s.height; return *this; }
00093 
00095         CL_Sizex<Type> &operator-=(const CL_Sizex<Type> &s)
00096         { width -= s.width; height -= s.height; return *this; }
00097 
00099         CL_Sizex<Type> operator+(const CL_Sizex<Type> &s) const
00100         { return CL_Sizex<Type>(width + s.width, height + s.height); }
00101 
00103         CL_Sizex<Type> operator-(const CL_Sizex<Type> &s) const
00104         { return CL_Sizex<Type>(width - s.width, height - s.height); }
00105 
00107         CL_Sizex<Type> &operator+=(const Type &s)
00108         { width += s; height += s; return *this; }
00109 
00111         CL_Sizex<Type> &operator-=(const Type &s)
00112         { width -= s; height -= s; return *this; }
00113 
00115         CL_Sizex<Type> &operator*=(const Type &s)
00116         { width *= s; height *= s; return *this; }
00117 
00119         CL_Sizex<Type> &operator/=(const Type &s)
00120         { width /= s; height /= s; return *this; }
00121 
00123         CL_Sizex<Type> operator+(const Type &s) const
00124         { return CL_Sizex<Type>(width + s, height + s); }
00125 
00127         CL_Sizex<Type> operator-(const Type &s) const
00128         { return CL_Sizex<Type>(width - s, height - s); }
00129 
00131         CL_Sizex<Type> operator*(const Type &s) const
00132         { return CL_Sizex<Type>(width * s, height * s); }
00133 
00135         CL_Sizex<Type> operator/(const Type &s) const
00136         { return CL_Sizex<Type>(width / s, height / s); }
00137 
00139         bool operator==(const CL_Sizex<Type> &s) const
00140         { return (width == s.width) && (height == s.height); }
00141 
00143         bool operator!=(const CL_Sizex<Type> &s) const
00144         { return (width != s.width) || (height != s.height); }
00146 };
00147 
00151 class CL_Size : public CL_Sizex<int>
00152 {
00153 public:
00154         CL_Size() : CL_Sizex<int>() {}
00155         CL_Size(int width, int height) : CL_Sizex<int>(width, height) {}
00156         CL_Size(const CL_Sizex<int> &s) : CL_Sizex<int>(s) {}
00157 
00158         explicit CL_Size(const CL_Sizex<float> &copy) { width = (int)(copy.width+0.5f); height = (int)(copy.height+0.5f); }
00159         explicit CL_Size(const CL_Sizex<double> &copy) { width = (int)(copy.width+0.5); height = (int)(copy.height+0.5); }
00160 };
00161 
00165 class CL_Sizef : public CL_Sizex<float>
00166 {
00167 public:
00168         CL_Sizef() : CL_Sizex<float>() {}
00169         CL_Sizef(float width, float height) : CL_Sizex<float>(width, height) {}
00170         CL_Sizef(const CL_Sizex<float> &s) : CL_Sizex<float>(s) {}
00171 
00172         CL_Sizef(const CL_Sizex<int> &copy) { width = (float)copy.width; height = (float)copy.height; }
00173         explicit CL_Sizef(const CL_Sizex<double> &copy) { width = (float)copy.width; height = (float)copy.height; }
00174 };
00175 
00179 class CL_Sized : public CL_Sizex<double>
00180 {
00181 public:
00182         CL_Sized() : CL_Sizex<double>() {}
00183         CL_Sized(double width, double height) : CL_Sizex<double>(width, height) {}
00184         CL_Sized(const CL_Sizex<double> &s) : CL_Sizex<double>(s) {}
00185 
00186         CL_Sized(const CL_Sizex<int> &copy) { width = (double)copy.width; height = (double)copy.height; }
00187         CL_Sized(const CL_Sizex<float> &copy) { width = (double)copy.width; height = (double)copy.height; }
00188 };
00189 
00191