include fixes from ohnobinki, video_systems.cpp should fall back to SDL now if GL...
[supertux.git] / src / math / sizef.hpp
1 //  SuperTux
2 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_MATH_SIZEF_HPP
18 #define HEADER_SUPERTUX_MATH_SIZEF_HPP
19
20 #include <iosfwd>
21
22 #include "math/vector.hpp"
23
24 class Size;
25
26 class Sizef
27 {
28 public:
29   Sizef() :
30     width(0.0f),
31     height(0.0f)
32   {}
33
34   Sizef(float width_, float height_) :
35     width(width_), 
36     height(height_) 
37   {}
38
39   Sizef(const Sizef& rhs) :
40     width(rhs.width),
41     height(rhs.height)
42   {}
43
44   Sizef(const Size& rhs);
45
46   Sizef& operator*=(float factor)
47   {
48     width  *= factor;
49     height *= factor;
50     return *this;
51   }
52
53   Sizef& operator/=(float divisor)
54   {
55     width  /= divisor;
56     height /= divisor;
57     return *this;
58   }
59
60   Sizef& operator+=(const Sizef& rhs)
61   { 
62     width  += rhs.width; 
63     height += rhs.height; 
64     return *this; 
65   }
66
67   Sizef& operator-=(const Sizef& rhs)
68   { 
69     width  -= rhs.width; 
70     height -= rhs.height; 
71     return *this; 
72   }
73
74 public:
75   float width;
76   float height;
77 };
78
79 inline Sizef operator*(const Sizef& lhs, float factor)
80
81   return Sizef(lhs.width  * factor, 
82                lhs.height * factor); 
83 }
84
85 inline Sizef operator*(float factor, const Sizef& rhs)
86
87   return Sizef(rhs.width  * factor, 
88                rhs.height * factor); 
89 }
90
91 inline Sizef operator/(const Sizef& lhs, float divisor)
92
93   return Sizef(lhs.width  / divisor, 
94                lhs.height / divisor); 
95 }
96
97 inline Sizef operator+(const Sizef& lhs, const Sizef& rhs)
98
99   return Sizef(lhs.width  + rhs.width, 
100                lhs.height + rhs.height); 
101 }
102
103 inline Vector operator+(const Vector& lhs, const Sizef& rhs) const
104
105   return Vector(lhs.x + rhs.width, 
106                 lhs.y + rhs.height); 
107 }
108
109 inline Vector operator*(const Vector& lhs, const Sizef& rhs) const
110
111   return Vector(lhs.x * rhs.width, 
112                 lhs.y * rhs.height); 
113 }
114
115 inline Vector operator*(const Sizefr& lhs, const Vector& rhs) const
116
117   return Vector(lhs.width  * rhs.x, 
118                 lhs.height * rhs.y); 
119 }
120
121 inline Sizef operator-(const Sizef& lhs, const Sizef& rhs)
122 {
123   return Sizef(lhs.width  - rhs.width, 
124                lhs.height - rhs.height); 
125 }
126
127 inline bool operator==(const Sizef& lhs, const Sizef& rhs)
128 {
129   return (lhs.width == rhs.width) && (rhs.height == rhs.height); 
130 }
131
132 inline bool operator!=(const Sizef& lhs, const Sizef& rhs)
133
134   return (lhs.width != rhs.width) || (lhs.height != rhs.height); 
135 }
136
137 std::ostream& operator<<(std::ostream& s, const Sizef& size);
138
139 #endif
140
141 /* EOF */