src/math/size.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef HEADER_SUPERTUX_MATH_SIZE_HPP
00018 #define HEADER_SUPERTUX_MATH_SIZE_HPP
00019 
00020 #include <iosfwd>
00021 
00022 class Sizef;
00023 
00024 class Size
00025 {
00026 public:
00027   Size() :
00028     width(0), 
00029     height(0)
00030   {}
00031 
00032   Size(int width_, int height_) :
00033     width(width_), 
00034     height(height_) 
00035   {}
00036 
00037   Size(const Size& rhs) :
00038     width(rhs.width),
00039     height(rhs.height)
00040   {}
00041 
00042   explicit Size(const Sizef& rhs);
00043 
00044   Size& operator*=(int factor)
00045   {
00046     width  *= factor;
00047     height *= factor;
00048     return *this;
00049   }
00050 
00051   Size& operator/=(int divisor)
00052   {
00053     width  /= divisor;
00054     height /= divisor;
00055     return *this;
00056   }
00057 
00058   Size& operator+=(const Size& rhs)
00059   {
00060     width  += rhs.width; 
00061     height += rhs.height; 
00062     return *this; 
00063   }
00064 
00065   Size& operator-=(const Size& rhs)
00066   { 
00067     width  -= rhs.width;
00068     height -= rhs.height; 
00069     return *this; 
00070   }
00071 
00072 public:
00073   int width;
00074   int height;
00075 };
00076 
00077 inline Size operator*(const Size& lhs, int factor)
00078 { 
00079   return Size(lhs.width  * factor, 
00080               lhs.height * factor); 
00081 }
00082 
00083 inline Size operator*(int factor, const Size& rhs)
00084 { 
00085   return Size(rhs.width  * factor, 
00086               rhs.height * factor); 
00087 }
00088 
00089 inline Size operator/(const Size& lhs, int divisor)
00090 { 
00091   return Size(lhs.width  / divisor, 
00092               lhs.height / divisor); 
00093 }
00094 
00095 inline Size operator+(const Size& lhs, const Size& rhs)
00096 { 
00097   return Size(lhs.width  + rhs.width, 
00098               lhs.height + rhs.height); 
00099 }
00100 
00101 inline Size operator-(const Size& lhs, const Size& rhs)
00102 {
00103   return Size(lhs.width  - rhs.width, 
00104               lhs.height - rhs.height); 
00105 }
00106 
00107 inline bool operator==(const Size& lhs, const Size& rhs)
00108 {
00109   return (lhs.width == rhs.width) && (lhs.height == rhs.height); 
00110 }
00111 
00112 inline bool operator!=(const Size& lhs, const Size& rhs)
00113 { 
00114   return (lhs.width != rhs.width) || (lhs.height != rhs.height); 
00115 }
00116 
00117 std::ostream& operator<<(std::ostream& s, const Size& size);
00118 
00119 #endif

Generated on Mon Jun 9 03:38:18 2014 for SuperTux by  doxygen 1.5.1