size.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore 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 UICore 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 uicore
36 {
37  template<typename Type>
38  class Vec2;
39 
40  template<typename Type>
41  class Vec3;
42 
43  template<typename Type>
44  class Vec4;
45 
50  template<typename Type>
51  class Sizex
52  {
53  public:
55  Sizex() : width(0), height(0) { return; }
56 
61  Sizex(Type width, Type height)
62  : width(width), height(height) { }
63 
68  : width(s.width), height(s.height) {}
69 
71  Type width;
72 
74  Type height;
75 
76  operator Vec2<Type>() const
77  {
78  return Vec2<Type>(width, height);
79  }
80 
83  {
84  width += s.width; height += s.height; return *this;
85  }
86 
89  {
90  width -= s.width; height -= s.height; return *this;
91  }
92 
95  {
96  return Sizex<Type>(width + s.width, height + s.height);
97  }
98 
101  {
102  return Sizex<Type>(width - s.width, height - s.height);
103  }
104 
106  Sizex<Type> &operator+=(const Type &s)
107  {
108  width += s; height += s; return *this;
109  }
110 
112  Sizex<Type> &operator-=(const Type &s)
113  {
114  width -= s; height -= s; return *this;
115  }
116 
118  Sizex<Type> &operator*=(const Type &s)
119  {
120  width *= s; height *= s; return *this;
121  }
122 
124  Sizex<Type> &operator/=(const Type &s)
125  {
126  width /= s; height /= s; return *this;
127  }
128 
130  Sizex<Type> operator+(const Type &s) const
131  {
132  return Sizex<Type>(width + s, height + s);
133  }
134 
136  Sizex<Type> operator-(const Type &s) const
137  {
138  return Sizex<Type>(width - s, height - s);
139  }
140 
142  Sizex<Type> operator*(const Type &s) const
143  {
144  return Sizex<Type>(width * s, height * s);
145  }
146 
148  Sizex<Type> operator/(const Type &s) const
149  {
150  return Sizex<Type>(width / s, height / s);
151  }
152 
154  bool operator==(const Sizex<Type> &s) const
155  {
156  return (width == s.width) && (height == s.height);
157  }
158 
160  bool operator!=(const Sizex<Type> &s) const
161  {
162  return (width != s.width) || (height != s.height);
163  }
164  };
165 
167  class Size : public Sizex<int>
168  {
169  public:
170  Size() : Sizex<int>() {}
171  Size(int width, int height) : Sizex<int>(width, height) {}
172  Size(const Sizex<int> &s) : Sizex<int>(s) {}
173  Size(const Vec2<int> &s) : Sizex<int>(s.x, s.y) {}
174 
175  explicit Size(const Sizex<float> &copy) { width = (int)(copy.width + 0.5f); height = (int)(copy.height + 0.5f); }
176  explicit Size(const Sizex<double> &copy) { width = (int)(copy.width + 0.5); height = (int)(copy.height + 0.5); }
177  };
178 
180  class Sizef : public Sizex<float>
181  {
182  public:
183  Sizef() : Sizex<float>() {}
184  Sizef(float width, float height) : Sizex<float>(width, height) {}
185  Sizef(const Sizex<float> &s) : Sizex<float>(s) {}
186  Sizef(const Vec2<float> &s) : Sizex<float>(s.x, s.y) {}
187 
188  Sizef(const Sizex<int> &copy) { width = (float)copy.width; height = (float)copy.height; }
189  explicit Sizef(const Sizex<double> &copy) { width = (float)copy.width; height = (float)copy.height; }
190  };
191 
193  class Sized : public Sizex<double>
194  {
195  public:
196  Sized() : Sizex<double>() {}
197  Sized(double width, double height) : Sizex<double>(width, height) {}
198  Sized(const Sizex<double> &s) : Sizex<double>(s) {}
199  Sized(const Vec2<double> &s) : Sizex<double>(s.x, s.y) {}
200 
201  Sized(const Sizex<int> &copy) { width = (double)copy.width; height = (double)copy.height; }
202  Sized(const Sizex<float> &copy) { width = (double)copy.width; height = (double)copy.height; }
203  };
204 }
Sizex< Type > & operator/=(const Type &s)
Size /= operator.
Definition: size.h:124
Size()
Definition: size.h:170
Sizex< Type > operator/(const Type &s) const
Size / operator.
Definition: size.h:148
Sizef(const Sizex< float > &s)
Definition: size.h:185
Sizex< Type > operator-(const Type &s) const
Size - operator.
Definition: size.h:136
2D (width,height) size structure - Integer
Definition: size.h:167
Sizex()
Constructs a size structure.
Definition: size.h:55
2D (width,height) size structure - Double
Definition: size.h:193
2D vector
Definition: line.h:43
Sizef(float width, float height)
Definition: size.h:184
2D (width,height) size structure.
Definition: size.h:51
Sizex< Type > & operator-=(const Sizex< Type > &s)
Size -= Size operator.
Definition: size.h:88
Size(const Sizex< int > &s)
Definition: size.h:172
Sized(const Sizex< float > &copy)
Definition: size.h:202
bool operator!=(const Sizex< Type > &s) const
Size != Size operator (deep compare).
Definition: size.h:160
Sizef(const Vec2< float > &s)
Definition: size.h:186
Size(const Vec2< int > &s)
Definition: size.h:173
Sizex(const Sizex< Type > &s)
Constructs a size structure.
Definition: size.h:67
Sizex< Type > operator-(const Sizex< Type > &s) const
Size - Size operator.
Definition: size.h:100
Sizex< Type > operator*(const Type &s) const
Size * operator.
Definition: size.h:142
Sized()
Definition: size.h:196
Sizef(const Sizex< int > &copy)
Definition: size.h:188
Sized(const Sizex< double > &s)
Definition: size.h:198
Sized(const Vec2< double > &s)
Definition: size.h:199
2D (width,height) size structure - Float
Definition: size.h:180
Type height
Size height.
Definition: size.h:74
Size(int width, int height)
Definition: size.h:171
bool operator==(const Sizex< Type > &s) const
Size == Size operator (deep compare).
Definition: size.h:154
Sizex(Type width, Type height)
Constructs a size structure.
Definition: size.h:61
Size(const Sizex< double > &copy)
Definition: size.h:176
Type width
Size width.
Definition: size.h:71
Sizex< Type > operator+(const Sizex< Type > &s) const
Size + Size operator.
Definition: size.h:94
Sized(const Sizex< int > &copy)
Definition: size.h:201
Sizex< Type > & operator-=(const Type &s)
Size -= operator.
Definition: size.h:112
Sizex< Type > & operator+=(const Sizex< Type > &s)
Size += Size operator.
Definition: size.h:82
Sizef()
Definition: size.h:183
Sized(double width, double height)
Definition: size.h:197
Sizex< Type > operator+(const Type &s) const
Size + operator.
Definition: size.h:130
Size(const Sizex< float > &copy)
Definition: size.h:175
Sizex< Type > & operator*=(const Type &s)
Size *= operator.
Definition: size.h:118
Definition: Application/application.h:35
Sizex< Type > & operator+=(const Type &s)
Size += operator.
Definition: size.h:106
4D vector
Definition: size.h:44
Sizef(const Sizex< double > &copy)
Definition: size.h:189