faithtools/faith/size.h

Go to the documentation of this file.
00001 #ifndef KDE__SIZE_H
00002 #define KDE__SIZE_H
00003 
00004 #include <faith/tools.h>
00005 
00006 
00007 
00008 
00009 namespace Faith
00010 {
00011 
00012 class FAITH_TOOLS_EXPORT Size
00013 {
00014         int mW, mH;
00015 public:
00016         Size(int w, int h)
00017                 : mW(w), mH(h)
00018         { }
00019         Size()
00020                 : mW(0), mH(0)
00021         { }
00022 
00023         inline int width() const { return mW; }
00024         inline int height() const { return mH; }
00025 
00026         inline void setWidth(int w) { mW = w; }
00027         inline void setHeight(int h) { mH = h; }
00028 
00029         inline void resize(int w, int h) { mW = w; mH = h; }
00030         
00031         bool operator ==(const Size &other) const
00032         {
00033                 return mW == other.mW && mH == other.mH;
00034         }
00035 
00036         bool operator !=(const Size &other) const { return !operator==(other); }
00037 
00038         Faith::Size expandedTo(const Faith::Size &sz) const
00039         {
00040                 return Faith::Size(MAX(sz.width(), width()), MAX(sz.height(), height()));
00041         }
00042         
00043         Faith::Size expandedTo(int w, int h) const
00044         {
00045                 return Faith::Size(MAX(w, width()), MAX(h, height()));
00046         }
00047         
00052         bool isValid() const
00053         {
00054                 return mW >=0 && mH >= 0;
00055         }
00056         
00060         bool isInvalid() const
00061         {
00062                 return !isValid();
00063         }
00064 
00065         Size operator -(const Size &other) const
00066         {
00067                 Size copy(*this);
00068                 copy.mW -= other.mW;
00069                 copy.mH -= other.mH;
00070                 return copy;
00071         }
00072         
00073         Size operator+ (const Size &other) const
00074         {
00075                 Size s(*this);
00076                 s += other;
00077                 return s;
00078         }
00079         
00080         Size &operator +=(const Size &other)
00081         {
00082                 mW += other.mW;
00083                 mH += other.mH;
00084                 return *this;
00085         }
00086         
00087         Size &operator *=(int s)
00088         {
00089                 mW *= s;
00090                 mH *= s;
00091                 return *this;
00092         }
00093         
00094         Size operator *(int s) const
00095         {
00096                 Size o(*this);
00097                 o *= s;
00098                 return o;
00099         }
00100         
00101         Size &operator /=(int s)
00102         {
00103                 mW /= s;
00104                 mH /= s;
00105                 return *this;
00106         }
00107         
00108         Size operator /(int s) const
00109         {
00110                 Size o(*this);
00111                 o /= s;
00112                 return o;
00113         }
00114         
00115 };
00116 
00117 }
00118 
00119 #endif

Generated on Fri Sep 1 00:23:07 2006 for Faith by  doxygen 1.4.7