size.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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 "vec2.h"
34
35 namespace clan
36 {
39
40 template<typename Type>
41 class Vec2;
42
43 template<typename Type>
44 class Vec3;
45
46 template<typename Type>
47 class Vec4;
48
53 template<typename Type>
54 class Sizex
55 {
58
59 public:
61 Sizex() : width(0), height(0) { return; }
62
67 Sizex(Type width, Type height)
68 : width(width), height(height) { }
69
73 Sizex(const Sizex<Type> &s)
74 : width(s.width), height(s.height) {}
75
79
80 public:
82 Type width;
83
85 Type height;
86
90
91 public:
92 operator Vec2<Type>() const
93 {
94 return Vec2<Type>(width, height);
95 }
96
98 Sizex<Type> &operator+=(const Sizex<Type> &s)
99 { width += s.width; height += s.height; return *this; }
100
102 Sizex<Type> &operator-=(const Sizex<Type> &s)
103 { width -= s.width; height -= s.height; return *this; }
104
106 Sizex<Type> operator+(const Sizex<Type> &s) const
107 { return Sizex<Type>(width + s.width, height + s.height); }
108
110 Sizex<Type> operator-(const Sizex<Type> &s) const
111 { return Sizex<Type>(width - s.width, height - s.height); }
112
114 Sizex<Type> &operator+=(const Type &s)
115 { width += s; height += s; return *this; }
116
118 Sizex<Type> &operator-=(const Type &s)
119 { width -= s; height -= s; return *this; }
120
122 Sizex<Type> &operator*=(const Type &s)
123 { width *= s; height *= s; return *this; }
124
126 Sizex<Type> &operator/=(const Type &s)
127 { width /= s; height /= s; return *this; }
128
130 Sizex<Type> operator+(const Type &s) const
131 { return Sizex<Type>(width + s, height + s); }
132
134 Sizex<Type> operator-(const Type &s) const
135 { return Sizex<Type>(width - s, height - s); }
136
138 Sizex<Type> operator*(const Type &s) const
139 { return Sizex<Type>(width * s, height * s); }
140
142 Sizex<Type> operator/(const Type &s) const
143 { return Sizex<Type>(width / s, height / s); }
144
146 bool operator==(const Sizex<Type> &s) const
147 { return (width == s.width) && (height == s.height); }
148
150 bool operator!=(const Sizex<Type> &s) const
151 { return (width != s.width) || (height != s.height); }
153 };
154
156 class Size : public Sizex<int>
157 {
158 public:
159 Size() : Sizex<int>() {}
160 Size(int width, int height) : Sizex<int>(width, height) {}
161 Size(const Sizex<int> &s) : Sizex<int>(s) {}
162 Size(const Vec2<int> &s) : Sizex<int>(s.x, s.y) {}
163
164 explicit Size(const Sizex<float> &copy) { width = (int)(copy.width+0.5f); height = (int)(copy.height+0.5f); }
165 explicit Size(const Sizex<double> &copy) { width = (int)(copy.width+0.5); height = (int)(copy.height+0.5); }
166 };
167
169 class Sizef : public Sizex<float>
170 {
171 public:
172 Sizef() : Sizex<float>() {}
173 Sizef(float width, float height) : Sizex<float>(width, height) {}
174 Sizef(const Sizex<float> &s) : Sizex<float>(s) {}
175 Sizef(const Vec2<float> &s) : Sizex<float>(s.x, s.y) {}
176
177 Sizef(const Sizex<int> &copy) { width = (float)copy.width; height = (float)copy.height; }
178 explicit Sizef(const Sizex<double> &copy) { width = (float)copy.width; height = (float)copy.height; }
179 };
180
182 class Sized : public Sizex<double>
183 {
184 public:
185 Sized() : Sizex<double>() {}
186 Sized(double width, double height) : Sizex<double>(width, height) {}
187 Sized(const Sizex<double> &s) : Sizex<double>(s) {}
188 Sized(const Vec2<double> &s) : Sizex<double>(s.x, s.y) {}
189
190 Sized(const Sizex<int> &copy) { width = (double)copy.width; height = (double)copy.height; }
191 Sized(const Sizex<float> &copy) { width = (double)copy.width; height = (double)copy.height; }
192 };
193
194 }
195
clan::Size::Size
Size(const Sizex< float > &copy)
Definition: size.h:164
clan
Definition: clanapp.h:35
clan::Sizex::width
Type width
Size width.
Definition: size.h:82
clan::Sizex::Sizex
Sizex(Type width, Type height)
Constructs a size structure.
Definition: size.h:67
clan::Key::s
clan::Sized::Sized
Sized(const Sizex< float > &copy)
Definition: size.h:191
clan::Sized::Sized
Sized(const Sizex< double > &s)
Definition: size.h:187
clan::Sizex::Sizex
Sizex(const Sizex< Type > &s)
Constructs a size structure.
Definition: size.h:73
clan::Sized::Sized
Sized(const Sizex< int > &copy)
Definition: size.h:190
clan::Sizex::operator-=
Sizex< Type > & operator-=(const Sizex< Type > &s)
Size -= Size operator.
Definition: size.h:102
clan::Key::x
clan::Sizef::Sizef
Sizef(float width, float height)
Definition: size.h:173
clan::Sizef::Sizef
Sizef(const Sizex< float > &s)
Definition: size.h:174
clan::Sizex::height
Type height
Size height.
Definition: size.h:85
clan::Sizex::operator+
Sizex< Type > operator+(const Sizex< Type > &s) const
Size + Size operator.
Definition: size.h:106
clan::Sizef::Sizef
Sizef(const Sizex< double > &copy)
Definition: size.h:178
clan::Sized::Sized
Sized(double width, double height)
Definition: size.h:186
clan::Sizex::operator*=
Sizex< Type > & operator*=(const Type &s)
Size *= operator.
Definition: size.h:122
clan::Size::Size
Size(const Sizex< double > &copy)
Definition: size.h:165
clan::Sizef::Sizef
Sizef()
Definition: size.h:172
clan::Size::Size
Size(const Sizex< int > &s)
Definition: size.h:161
clan::Sizex::operator!=
bool operator!=(const Sizex< Type > &s) const
Size != Size operator (deep compare).
Definition: size.h:150
clan::Key::y
clan::Sizex::Sizex
Sizex()
Constructs a size structure.
Definition: size.h:61
clan::Sized::Sized
Sized(const Vec2< double > &s)
Definition: size.h:188
clan::Size::Size
Size()
Definition: size.h:159
clan::Sized
2D (width,height) size structure - Double
Definition: size.h:182
clan::Sizex::operator-
Sizex< Type > operator-(const Type &s) const
Size - operator.
Definition: size.h:134
clan::Vec2
2D vector
Definition: line.h:48
clan::Sized::Sized
Sized()
Definition: size.h:185
clan::Size::Size
Size(int width, int height)
Definition: size.h:160
clan::Sizef::Sizef
Sizef(const Vec2< float > &s)
Definition: size.h:175
clan::Sizex::operator+=
Sizex< Type > & operator+=(const Sizex< Type > &s)
Size += Size operator.
Definition: size.h:98
clan::Sizex::operator/
Sizex< Type > operator/(const Type &s) const
Size / operator.
Definition: size.h:142
clan::Size::Size
Size(const Vec2< int > &s)
Definition: size.h:162
clan::Sizef::Sizef
Sizef(const Sizex< int > &copy)
Definition: size.h:177
clan::Sizex::operator*
Sizex< Type > operator*(const Type &s) const
Size * operator.
Definition: size.h:138
clan::Size
2D (width,height) size structure - Integer
Definition: size.h:156
clan::Sizex::operator+
Sizex< Type > operator+(const Type &s) const
Size + operator.
Definition: size.h:130
clan::Sizex::operator-=
Sizex< Type > & operator-=(const Type &s)
Size -= operator.
Definition: size.h:118
clan::Vec4
4D vector
Definition: size.h:47
clan::Sizex::operator==
bool operator==(const Sizex< Type > &s) const
Size == Size operator (deep compare).
Definition: size.h:146
clan::Sizex::operator-
Sizex< Type > operator-(const Sizex< Type > &s) const
Size - Size operator.
Definition: size.h:110
clan::Sizex::operator+=
Sizex< Type > & operator+=(const Type &s)
Size += operator.
Definition: size.h:114
clan::Sizex
2D (width,height) size structure.
Definition: size.h:54
clan::Sizef
2D (width,height) size structure - Float
Definition: size.h:169
clan::Sizex::operator/=
Sizex< Type > & operator/=(const Type &s)
Size /= operator.
Definition: size.h:126