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,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (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 GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXSize.h,v 1.15 2006/01/22 17:58:09 fox Exp $                            *
00023 ********************************************************************************/
00024 #ifndef FXSIZE_H
00025 #define FXSIZE_H
00026 
00027 
00028 namespace FX {
00029 
00030 
00031 /// Size
00032 class FXAPI FXSize {
00033 public:
00034   FXshort w;
00035   FXshort h;
00036 public:
00037 
00038   /// Constructors
00039   FXSize(){ }
00040   FXSize(const FXSize& s):w(s.w),h(s.h){ }
00041   FXSize(FXshort ww,FXshort hh):w(ww),h(hh){ }
00042 
00043   /// Test if empty
00044   bool empty() const { return w<=0 || h<=0; }
00045 
00046   /// Test if zero
00047   bool operator!() const { return w==0 && h==0; }
00048 
00049   /// Equality
00050   bool operator==(const FXSize& s) const { return w==s.w && h==s.h; }
00051   bool operator!=(const FXSize& s) const { return w!=s.w || h!=s.h; }
00052 
00053   /// Grow by amount
00054   FXSize& grow(FXshort margin);
00055   FXSize& grow(FXshort hormargin,FXshort vermargin);
00056   FXSize& grow(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
00057 
00058   /// Shrink by amount
00059   FXSize& shrink(FXshort margin);
00060   FXSize& shrink(FXshort hormargin,FXshort vermargin);
00061   FXSize& shrink(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
00062 
00063   /// Assignment
00064   FXSize& operator=(const FXSize& s){ w=s.w; h=s.h; return *this; }
00065 
00066   /// Set value from another size
00067   FXSize& set(const FXSize& s){ w=s.w; h=s.h; return *this; }
00068 
00069   /// Set value from components
00070   FXSize& set(FXshort ww,FXshort hh){ w=ww; h=hh; return *this; }
00071 
00072   /// Assignment operators
00073   FXSize& operator+=(const FXSize& s){ w+=s.w; h+=s.h; return *this; }
00074   FXSize& operator-=(const FXSize& s){ w-=s.w; h-=s.h; return *this; }
00075   FXSize& operator*=(FXshort c){ w*=c; h*=c; return *this; }
00076   FXSize& operator/=(FXshort c){ w/=c; h/=c; return *this; }
00077 
00078   /// Negation
00079   FXSize operator-(){ return FXSize(-w,-h); }
00080 
00081   /// Addition operators
00082   FXSize operator+(const FXSize& s) const { return FXSize(w+s.w,h+s.h); }
00083   FXSize operator-(const FXSize& s) const { return FXSize(w-s.w,h-s.h); }
00084 
00085   /// Scale operators
00086   friend inline FXSize operator*(const FXSize& s,FXshort c);
00087   friend inline FXSize operator*(FXshort c,const FXSize& s);
00088   friend inline FXSize operator/(const FXSize& s,FXshort c);
00089   friend inline FXSize operator/(FXshort c,const FXSize& s);
00090 
00091   /// Save object to a stream
00092   friend FXAPI FXStream& operator<<(FXStream& store,const FXSize& s);
00093 
00094   /// Load object from a stream
00095   friend FXAPI FXStream& operator>>(FXStream& store,FXSize& s);
00096   };
00097 
00098 inline FXSize operator*(const FXSize& s,FXshort c){ return FXSize(s.w*c,s.h*c); }
00099 inline FXSize operator*(FXshort c,const FXSize& s){ return FXSize(c*s.w,c*s.h); }
00100 inline FXSize operator/(const FXSize& s,FXshort c){ return FXSize(s.w/c,s.h/c); }
00101 inline FXSize operator/(FXshort c,const FXSize& s){ return FXSize(c/s.w,c/s.h); }
00102 
00103 extern FXAPI FXStream& operator<<(FXStream& store,const FXSize& s);
00104 extern FXAPI FXStream& operator>>(FXStream& store,FXSize& s);
00105 
00106 }
00107 
00108 #endif

Copyright © 1997-2005 Jeroen van der Zijp