Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXSize.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                               S i z e    C l a s s                            *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1994,2010 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXSIZE_H
00022 #define FXSIZE_H
00023 
00024 
00025 namespace FX {
00026 
00027 
00028 /// Size
00029 class FXAPI FXSize {
00030 public:
00031   FXshort w;
00032   FXshort h;
00033 public:
00034 
00035   /// Constructors
00036   FXSize(){ }
00037   FXSize(const FXSize& s):w(s.w),h(s.h){ }
00038   FXSize(FXshort ww,FXshort hh):w(ww),h(hh){ }
00039 
00040   /// Test if empty
00041   FXbool empty() const { return w<=0 || h<=0; }
00042 
00043   /// Test if zero
00044   FXbool operator!() const { return w==0 && h==0; }
00045 
00046   /// Equality
00047   FXbool operator==(const FXSize& s) const { return w==s.w && h==s.h; }
00048   FXbool operator!=(const FXSize& s) const { return w!=s.w || h!=s.h; }
00049 
00050   /// Grow by amount
00051   FXSize& grow(FXshort margin);
00052   FXSize& grow(FXshort hormargin,FXshort vermargin);
00053   FXSize& grow(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
00054 
00055   /// Shrink by amount
00056   FXSize& shrink(FXshort margin);
00057   FXSize& shrink(FXshort hormargin,FXshort vermargin);
00058   FXSize& shrink(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
00059 
00060   /// Assignment
00061   FXSize& operator=(const FXSize& s){ w=s.w; h=s.h; return *this; }
00062 
00063   /// Set value from another size
00064   FXSize& set(const FXSize& s){ w=s.w; h=s.h; return *this; }
00065 
00066   /// Set value from components
00067   FXSize& set(FXshort ww,FXshort hh){ w=ww; h=hh; return *this; }
00068 
00069   /// Assignment operators
00070   FXSize& operator+=(const FXSize& s){ w+=s.w; h+=s.h; return *this; }
00071   FXSize& operator-=(const FXSize& s){ w-=s.w; h-=s.h; return *this; }
00072   FXSize& operator*=(FXshort c){ w*=c; h*=c; return *this; }
00073   FXSize& operator/=(FXshort c){ w/=c; h/=c; return *this; }
00074 
00075   /// Negation
00076   FXSize operator-(){ return FXSize(-w,-h); }
00077 
00078   /// Addition operators
00079   FXSize operator+(const FXSize& s) const { return FXSize(w+s.w,h+s.h); }
00080   FXSize operator-(const FXSize& s) const { return FXSize(w-s.w,h-s.h); }
00081   };
00082 
00083 
00084 /// Scale operators
00085 inline FXSize operator*(const FXSize& s,FXshort c){ return FXSize(s.w*c,s.h*c); }
00086 inline FXSize operator*(FXshort c,const FXSize& s){ return FXSize(c*s.w,c*s.h); }
00087 inline FXSize operator/(const FXSize& s,FXshort c){ return FXSize(s.w/c,s.h/c); }
00088 inline FXSize operator/(FXshort c,const FXSize& s){ return FXSize(c/s.w,c/s.h); }
00089 
00090 /// Save object to a stream
00091 extern FXAPI FXStream& operator<<(FXStream& store,const FXSize& s);
00092 
00093 /// Load object from a stream
00094 extern FXAPI FXStream& operator>>(FXStream& store,FXSize& s);
00095 
00096 }
00097 
00098 #endif

Copyright © 1997-2010 Jeroen van der Zijp