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

/home/jeroen/FOX/fox/fox-1.7.33/include/FXSize.h
00001 /********************************************************************************
00002 *                                                                               *
00003 *                               S i z e    C l a s s                            *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1994,2012 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 
00029 class FXAPI FXSize {
00030 public:
00031   FXshort w;
00032   FXshort h;
00033 public:
00034 
00036   FXSize(){ }
00037   FXSize(const FXSize& s):w(s.w),h(s.h){ }
00038   FXSize(FXshort ww,FXshort hh):w(ww),h(hh){ }
00039 
00041   FXshort& operator[](FXint i){return (&w)[i];}
00042 
00044   const FXshort& operator[](FXint i) const {return (&w)[i];}
00045 
00047   FXbool empty() const { return w<=0 || h<=0; }
00048 
00050   FXSize& grow(FXshort margin);
00051   FXSize& grow(FXshort hormargin,FXshort vermargin);
00052   FXSize& grow(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
00053 
00055   FXSize& shrink(FXshort margin);
00056   FXSize& shrink(FXshort hormargin,FXshort vermargin);
00057   FXSize& shrink(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
00058 
00060   FXSize& operator=(const FXSize& s){ w=s.w; h=s.h; return *this; }
00061 
00063   FXSize& set(const FXSize& s){ w=s.w; h=s.h; return *this; }
00064 
00066   FXSize& set(FXshort ww,FXshort hh){ w=ww; h=hh; return *this; }
00067 
00069   FXSize& operator*=(FXshort c){ w*=c; h*=c; return *this; }
00070   FXSize& operator/=(FXshort c){ w/=c; h/=c; return *this; }
00071   FXSize& operator+=(const FXSize& s){ w+=s.w; h+=s.h; return *this; }
00072   FXSize& operator-=(const FXSize& s){ w-=s.w; h-=s.h; return *this; }
00073 
00075   FXbool operator!() const { return w==0 && h==0; }
00076 
00078   FXSize operator+() const { return *this; }
00079   FXSize operator-(){ return FXSize(-w,-h); }
00080   };
00081 
00082 
00084 inline FXSize operator*(const FXSize& s,FXshort c){ return FXSize(s.w*c,s.h*c); }
00085 inline FXSize operator*(FXshort c,const FXSize& s){ return FXSize(c*s.w,c*s.h); }
00086 inline FXSize operator/(const FXSize& s,FXshort c){ return FXSize(s.w/c,s.h/c); }
00087 inline FXSize operator/(FXshort c,const FXSize& s){ return FXSize(c/s.w,c/s.h); }
00088 
00090 inline FXSize operator+(const FXSize& a,const FXSize& b){ return FXSize(a.w+b.w,a.h+b.h); }
00091 inline FXSize operator-(const FXSize& a,const FXSize& b){ return FXSize(a.w-b.w,a.h-b.h); }
00092 
00094 inline FXbool operator==(const FXSize& a,FXshort n){ return a.w==n && a.h==n; }
00095 inline FXbool operator!=(const FXSize& a,FXshort n){ return a.w!=n || a.h!=n; }
00096 inline FXbool operator==(FXshort n,const FXSize& a){ return n==a.w && n==a.h; }
00097 inline FXbool operator!=(FXshort n,const FXSize& a){ return n!=a.w || n!=a.h; }
00098 
00100 inline FXbool operator==(const FXSize& a,const FXSize& b){ return a.w==b.w && a.h==b.h; }
00101 inline FXbool operator!=(const FXSize& a,const FXSize& b){ return a.w!=b.w || a.h!=b.h; }
00102 
00104 inline FXbool operator<(const FXSize& a,FXshort n){ return a.w<n && a.h<n; }
00105 inline FXbool operator<=(const FXSize& a,FXshort n){ return a.w<=n && a.h<=n; }
00106 inline FXbool operator>(const FXSize& a,FXshort n){ return a.w>n && a.h>n; }
00107 inline FXbool operator>=(const FXSize& a,FXshort n){ return a.w>=n && a.h>=n; }
00108 
00110 inline FXbool operator<(FXshort n,const FXSize& a){ return n<a.w && n<a.h; }
00111 inline FXbool operator<=(FXshort n,const FXSize& a){ return n<=a.w && n<=a.h; }
00112 inline FXbool operator>(FXshort n,const FXSize& a){ return n>a.w && n>a.h; }
00113 inline FXbool operator>=(FXshort n,const FXSize& a){ return n>=a.w && n>=a.h; }
00114 
00116 inline FXbool operator<(const FXSize& a,const FXSize& b){ return a.w<b.h && a.w<b.h; }
00117 inline FXbool operator<=(const FXSize& a,const FXSize& b){ return a.w<=b.h && a.w<=b.h; }
00118 inline FXbool operator>(const FXSize& a,const FXSize& b){ return a.w>b.h && a.w>b.h; }
00119 inline FXbool operator>=(const FXSize& a,const FXSize& b){ return a.w>=b.h && a.w>=b.h; }
00120 
00122 inline FXSize lo(const FXSize& a,const FXSize& b){ return FXSize(FXMIN(a.w,b.w),FXMIN(a.h,b.h)); }
00123 inline FXSize hi(const FXSize& a,const FXSize& b){ return FXSize(FXMAX(a.w,b.w),FXMAX(a.h,b.h)); }
00124 
00126 extern FXAPI FXStream& operator<<(FXStream& store,const FXSize& s);
00127 
00129 extern FXAPI FXStream& operator>>(FXStream& store,FXSize& s);
00130 
00131 }
00132 
00133 #endif

Copyright © 1997-2011 Jeroen van der Zijp