ClanLib  2.3.7
size.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 ** Kenneth Gangstoe
28 */
29 
32 
33 #pragma once
34 
35 #include "../api_core.h"
36 
37 template<typename Type>
38 class CL_Vec2;
39 
40 template<typename Type>
41 class CL_Vec3;
42 
43 template<typename Type>
44 class CL_Vec4;
45 
51 template<typename Type>
53 {
56 
57 public:
59  CL_Sizex() : width(0), height(0) { return; }
60 
65  CL_Sizex(Type width, Type height)
66  : width(width), height(height) { }
67 
72  { width = s.width; height = s.height; }
73 
77 
78 public:
80  Type width;
81 
83  Type height;
84 
88 
89 public:
92  { width += s.width; height += s.height; return *this; }
93 
96  { width -= s.width; height -= s.height; return *this; }
97 
100  { return CL_Sizex<Type>(width + s.width, height + s.height); }
101 
104  { return CL_Sizex<Type>(width - s.width, height - s.height); }
105 
107  CL_Sizex<Type> &operator+=(const Type &s)
108  { width += s; height += s; return *this; }
109 
111  CL_Sizex<Type> &operator-=(const Type &s)
112  { width -= s; height -= s; return *this; }
113 
115  CL_Sizex<Type> &operator*=(const Type &s)
116  { width *= s; height *= s; return *this; }
117 
119  CL_Sizex<Type> &operator/=(const Type &s)
120  { width /= s; height /= s; return *this; }
121 
123  CL_Sizex<Type> operator+(const Type &s) const
124  { return CL_Sizex<Type>(width + s, height + s); }
125 
127  CL_Sizex<Type> operator-(const Type &s) const
128  { return CL_Sizex<Type>(width - s, height - s); }
129 
131  CL_Sizex<Type> operator*(const Type &s) const
132  { return CL_Sizex<Type>(width * s, height * s); }
133 
135  CL_Sizex<Type> operator/(const Type &s) const
136  { return CL_Sizex<Type>(width / s, height / s); }
137 
139  bool operator==(const CL_Sizex<Type> &s) const
140  { return (width == s.width) && (height == s.height); }
141 
143  bool operator!=(const CL_Sizex<Type> &s) const
144  { return (width != s.width) || (height != s.height); }
146 };
147 
151 class CL_Size : public CL_Sizex<int>
152 {
153 public:
154  CL_Size() : CL_Sizex<int>() {}
155  CL_Size(int width, int height) : CL_Sizex<int>(width, height) {}
156  CL_Size(const CL_Sizex<int> &s) : CL_Sizex<int>(s) {}
157 
158  explicit CL_Size(const CL_Sizex<float> &copy) { width = (int)(copy.width+0.5f); height = (int)(copy.height+0.5f); }
159  explicit CL_Size(const CL_Sizex<double> &copy) { width = (int)(copy.width+0.5); height = (int)(copy.height+0.5); }
160 };
161 
165 class CL_Sizef : public CL_Sizex<float>
166 {
167 public:
168  CL_Sizef() : CL_Sizex<float>() {}
169  CL_Sizef(float width, float height) : CL_Sizex<float>(width, height) {}
170  CL_Sizef(const CL_Sizex<float> &s) : CL_Sizex<float>(s) {}
171 
172  CL_Sizef(const CL_Sizex<int> &copy) { width = (float)copy.width; height = (float)copy.height; }
173  explicit CL_Sizef(const CL_Sizex<double> &copy) { width = (float)copy.width; height = (float)copy.height; }
174 };
175 
179 class CL_Sized : public CL_Sizex<double>
180 {
181 public:
182  CL_Sized() : CL_Sizex<double>() {}
183  CL_Sized(double width, double height) : CL_Sizex<double>(width, height) {}
184  CL_Sized(const CL_Sizex<double> &s) : CL_Sizex<double>(s) {}
185 
186  CL_Sized(const CL_Sizex<int> &copy) { width = (double)copy.width; height = (double)copy.height; }
187  CL_Sized(const CL_Sizex<float> &copy) { width = (double)copy.width; height = (double)copy.height; }
188 };
189 
191