size.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 
30 
31 #pragma once
32 
33 #include "../api_core.h"
34 #include "vec2.h"
35 
36 namespace clan
37 {
40 
41 template<typename Type>
42 class Vec2;
43 
44 template<typename Type>
45 class Vec3;
46 
47 template<typename Type>
48 class Vec4;
49 
54 template<typename Type>
55 class CL_API_CORE Sizex
56 {
59 
60 public:
62  Sizex() : width(0), height(0) { return; }
63 
68  Sizex(Type width, Type height)
69  : width(width), height(height) { }
70 
74  Sizex(const Sizex<Type> &s)
75  { width = s.width; height = s.height; }
76 
80 
81 public:
83  Type width;
84 
86  Type height;
87 
91 
92 public:
93  operator Vec2<Type>() const
94  {
95  return Vec2<Type>(width, height);
96  }
97 
100  { width += s.width; height += s.height; return *this; }
101 
104  { width -= s.width; height -= s.height; return *this; }
105 
108  { return Sizex<Type>(width + s.width, height + s.height); }
109 
112  { return Sizex<Type>(width - s.width, height - s.height); }
113 
115  Sizex<Type> &operator+=(const Type &s)
116  { width += s; height += s; return *this; }
117 
119  Sizex<Type> &operator-=(const Type &s)
120  { width -= s; height -= s; return *this; }
121 
123  Sizex<Type> &operator*=(const Type &s)
124  { width *= s; height *= s; return *this; }
125 
127  Sizex<Type> &operator/=(const Type &s)
128  { width /= s; height /= s; return *this; }
129 
131  Sizex<Type> operator+(const Type &s) const
132  { return Sizex<Type>(width + s, height + s); }
133 
135  Sizex<Type> operator-(const Type &s) const
136  { return Sizex<Type>(width - s, height - s); }
137 
139  Sizex<Type> operator*(const Type &s) const
140  { return Sizex<Type>(width * s, height * s); }
141 
143  Sizex<Type> operator/(const Type &s) const
144  { return Sizex<Type>(width / s, height / s); }
145 
147  bool operator==(const Sizex<Type> &s) const
148  { return (width == s.width) && (height == s.height); }
149 
151  bool operator!=(const Sizex<Type> &s) const
152  { return (width != s.width) || (height != s.height); }
154 };
155 
157 class Size : public Sizex<int>
158 {
159 public:
160  Size() : Sizex<int>() {}
161  Size(int width, int height) : Sizex<int>(width, height) {}
162  Size(const Sizex<int> &s) : Sizex<int>(s) {}
163  Size(const Vec2<int> &s) : Sizex<int>(s.x, s.y) {}
164 
165  explicit Size(const Sizex<float> &copy) { width = (int)(copy.width+0.5f); height = (int)(copy.height+0.5f); }
166  explicit Size(const Sizex<double> &copy) { width = (int)(copy.width+0.5); height = (int)(copy.height+0.5); }
167 };
168 
170 class Sizef : public Sizex<float>
171 {
172 public:
173  Sizef() : Sizex<float>() {}
174  Sizef(float width, float height) : Sizex<float>(width, height) {}
175  Sizef(const Sizex<float> &s) : Sizex<float>(s) {}
176  Sizef(const Vec2<float> &s) : Sizex<float>(s.x, s.y) {}
177 
178  Sizef(const Sizex<int> &copy) { width = (float)copy.width; height = (float)copy.height; }
179  explicit Sizef(const Sizex<double> &copy) { width = (float)copy.width; height = (float)copy.height; }
180 };
181 
183 class Sized : public Sizex<double>
184 {
185 public:
186  Sized() : Sizex<double>() {}
187  Sized(double width, double height) : Sizex<double>(width, height) {}
188  Sized(const Sizex<double> &s) : Sizex<double>(s) {}
189  Sized(const Vec2<double> &s) : Sizex<double>(s.x, s.y) {}
190 
191  Sized(const Sizex<int> &copy) { width = (double)copy.width; height = (double)copy.height; }
192  Sized(const Sizex<float> &copy) { width = (double)copy.width; height = (double)copy.height; }
193 };
194 
195 }
196 
Size(const Sizex< float > &copy)
Definition: size.h:165
Type width
Size width.
Definition: size.h:83
Sizex(Type width, Type height)
Constructs a size structure.
Definition: size.h:68
Sized(const Sizex< float > &copy)
Definition: size.h:192
Sized(const Sizex< double > &s)
Definition: size.h:188
Sizex(const Sizex< Type > &s)
Constructs a size structure.
Definition: size.h:74
Sized(const Sizex< int > &copy)
Definition: size.h:191
Sizex< Type > & operator-=(const Sizex< Type > &s)
Size -= Size operator.
Definition: size.h:103
Sizef(float width, float height)
Definition: size.h:174
Sizef(const Sizex< float > &s)
Definition: size.h:175
Type height
Size height.
Definition: size.h:86
Sizex< Type > operator+(const Sizex< Type > &s) const
Size + Size operator.
Definition: size.h:107
Sizef(const Sizex< double > &copy)
Definition: size.h:179
Sized(double width, double height)
Definition: size.h:187
Sizex< Type > & operator*=(const Type &s)
Size *= operator.
Definition: size.h:123
Size(const Sizex< double > &copy)
Definition: size.h:166
Sizef()
Definition: size.h:173
Size(const Sizex< int > &s)
Definition: size.h:162
bool operator!=(const Sizex< Type > &s) const
Size != Size operator (deep compare).
Definition: size.h:151
Sizex()
Constructs a size structure.
Definition: size.h:62
Sized(const Vec2< double > &s)
Definition: size.h:189
Size()
Definition: size.h:160
2D (width,height) size structure - Double
Definition: size.h:183
Sizex< Type > operator-(const Type &s) const
Size - operator.
Definition: size.h:135
2D vector
Definition: line.h:49
Sized()
Definition: size.h:186
Size(int width, int height)
Definition: size.h:161
Sizef(const Vec2< float > &s)
Definition: size.h:176
Sizex< Type > & operator+=(const Sizex< Type > &s)
Size += Size operator.
Definition: size.h:99
Sizex< Type > operator/(const Type &s) const
Size / operator.
Definition: size.h:143
Size(const Vec2< int > &s)
Definition: size.h:163
Sizef(const Sizex< int > &copy)
Definition: size.h:178
Sizex< Type > operator*(const Type &s) const
Size * operator.
Definition: size.h:139
2D (width,height) size structure - Integer
Definition: size.h:157
Sizex< Type > operator+(const Type &s) const
Size + operator.
Definition: size.h:131
Sizex< Type > & operator-=(const Type &s)
Size -= operator.
Definition: size.h:119
4D vector
Definition: size.h:48
bool operator==(const Sizex< Type > &s) const
Size == Size operator (deep compare).
Definition: size.h:147
Sizex< Type > operator-(const Sizex< Type > &s) const
Size - Size operator.
Definition: size.h:111
Sizex< Type > & operator+=(const Type &s)
Size += operator.
Definition: size.h:115
2D (width,height) size structure.
Definition: size.h:55
2D (width,height) size structure - Float
Definition: size.h:170
Sizex< Type > & operator/=(const Type &s)
Size /= operator.
Definition: size.h:127