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

FXSize.h
1 /********************************************************************************
2 * *
3 * S i z e C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1994,2022 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXSIZE_H
22 #define FXSIZE_H
23 
24 namespace FX {
25 
26 
28 class FXAPI FXSize {
29 public:
30  FXshort w;
31  FXshort h;
32 public:
33 
35  FXSize(){ }
36  FXSize(const FXSize& s):w(s.w),h(s.h){ }
37  FXSize(FXshort ww,FXshort hh):w(ww),h(hh){ }
38 
40  FXshort& operator[](FXint i){return (&w)[i];}
41 
43  const FXshort& operator[](FXint i) const {return (&w)[i];}
44 
46  FXbool empty() const { return w<=0 || h<=0; }
47 
49  FXSize& grow(FXshort margin);
50  FXSize& grow(FXshort hormargin,FXshort vermargin);
51  FXSize& grow(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
52 
54  FXSize& shrink(FXshort margin);
55  FXSize& shrink(FXshort hormargin,FXshort vermargin);
56  FXSize& shrink(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
57 
59  FXSize& operator=(const FXSize& s){ w=s.w; h=s.h; return *this; }
60 
62  FXSize& set(const FXSize& s){ w=s.w; h=s.h; return *this; }
63 
65  FXSize& set(FXshort ww,FXshort hh){ w=ww; h=hh; return *this; }
66 
68  FXSize& operator*=(FXshort c){ w*=c; h*=c; return *this; }
69  FXSize& operator/=(FXshort c){ w/=c; h/=c; return *this; }
70  FXSize& operator+=(const FXSize& s){ w+=s.w; h+=s.h; return *this; }
71  FXSize& operator-=(const FXSize& s){ w-=s.w; h-=s.h; return *this; }
72 
74  FXbool operator!() const { return w==0 && h==0; }
75 
77  FXSize operator+() const { return *this; }
78  FXSize operator-(){ return FXSize(-w,-h); }
79  };
80 
81 
83 inline FXSize operator*(const FXSize& s,FXshort c){ return FXSize(s.w*c,s.h*c); }
84 inline FXSize operator*(FXshort c,const FXSize& s){ return FXSize(c*s.w,c*s.h); }
85 inline FXSize operator/(const FXSize& s,FXshort c){ return FXSize(s.w/c,s.h/c); }
86 inline FXSize operator/(FXshort c,const FXSize& s){ return FXSize(c/s.w,c/s.h); }
87 
89 inline FXSize operator+(const FXSize& a,const FXSize& b){ return FXSize(a.w+b.w,a.h+b.h); }
90 inline FXSize operator-(const FXSize& a,const FXSize& b){ return FXSize(a.w-b.w,a.h-b.h); }
91 
93 inline FXbool operator==(const FXSize& a,FXshort n){ return a.w==n && a.h==n; }
94 inline FXbool operator!=(const FXSize& a,FXshort n){ return a.w!=n || a.h!=n; }
95 inline FXbool operator==(FXshort n,const FXSize& a){ return n==a.w && n==a.h; }
96 inline FXbool operator!=(FXshort n,const FXSize& a){ return n!=a.w || n!=a.h; }
97 
99 inline FXbool operator==(const FXSize& a,const FXSize& b){ return a.w==b.w && a.h==b.h; }
100 inline FXbool operator!=(const FXSize& a,const FXSize& b){ return a.w!=b.w || a.h!=b.h; }
101 
103 inline FXbool operator<(const FXSize& a,FXshort n){ return a.w<n && a.h<n; }
104 inline FXbool operator<=(const FXSize& a,FXshort n){ return a.w<=n && a.h<=n; }
105 inline FXbool operator>(const FXSize& a,FXshort n){ return a.w>n && a.h>n; }
106 inline FXbool operator>=(const FXSize& a,FXshort n){ return a.w>=n && a.h>=n; }
107 
109 inline FXbool operator<(FXshort n,const FXSize& a){ return n<a.w && n<a.h; }
110 inline FXbool operator<=(FXshort n,const FXSize& a){ return n<=a.w && n<=a.h; }
111 inline FXbool operator>(FXshort n,const FXSize& a){ return n>a.w && n>a.h; }
112 inline FXbool operator>=(FXshort n,const FXSize& a){ return n>=a.w && n>=a.h; }
113 
115 inline FXbool operator<(const FXSize& a,const FXSize& b){ return a.w<b.w && a.h<b.h; }
116 inline FXbool operator<=(const FXSize& a,const FXSize& b){ return a.w<=b.w && a.h<=b.h; }
117 inline FXbool operator>(const FXSize& a,const FXSize& b){ return a.w>b.w && a.h>b.h; }
118 inline FXbool operator>=(const FXSize& a,const FXSize& b){ return a.w>=b.w && a.h>=b.h; }
119 
121 inline FXSize lo(const FXSize& a,const FXSize& b){ return FXSize(Math::imin(a.w,b.w),Math::imin(a.h,b.h)); }
122 inline FXSize hi(const FXSize& a,const FXSize& b){ return FXSize(Math::imax(a.w,b.w),Math::imax(a.h,b.h)); }
123 
125 extern FXAPI FXStream& operator<<(FXStream& store,const FXSize& s);
126 
128 extern FXAPI FXStream& operator>>(FXStream& store,FXSize& s);
129 
130 }
131 
132 #endif
Size.
Definition: FXSize.h:28
FXSize & operator*=(FXshort c)
Assignment operators.
Definition: FXSize.h:68
FXshort & operator[](FXint i)
Return a non-const reference to the ith element.
Definition: FXSize.h:40
Definition: FX4Splitter.h:28
FXbool operator!() const
Test if zero.
Definition: FXSize.h:74
FXSize()
Constructors.
Definition: FXSize.h:35
FXbool empty() const
Test if empty.
Definition: FXSize.h:46
FXSize operator+() const
Unary.
Definition: FXSize.h:77
const FXshort & operator[](FXint i) const
Return a const reference to the ith element.
Definition: FXSize.h:43
FXSize & operator=(const FXSize &s)
Assignment.
Definition: FXSize.h:59

Copyright © 1997-2022 Jeroen van der Zijp