openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
esize.h
Go to the documentation of this file.
1 #ifndef ESIZE_H
2 #define ESIZE_H
3 
4 #define MIN(a,b) (a < b ? a : b)
5 #define MAX(a,b) (a > b ? a : b)
6 
7 class eSize
8 {
9 public:
10  eSize();
11  eSize( int w, int h );
12 
13  bool isNull() const;
14  bool isEmpty() const;
15  bool isValid() const;
16 
17  int width() const;
18  int height() const;
19  void setWidth( int w );
20  void setHeight( int h );
21  void transpose();
22 
23  eSize expandedTo( const eSize & ) const;
24  eSize boundedTo( const eSize & ) const;
25 
26  int &rwidth();
27  int &rheight();
28 
29  eSize &operator+=( const eSize & );
30  eSize &operator-=( const eSize & );
31  eSize &operator*=( int c );
32  eSize &operator*=( double c );
33  eSize &operator/=( int c );
34  eSize &operator/=( double c );
35 
36  friend inline bool operator==( const eSize &, const eSize & );
37  friend inline bool operator!=( const eSize &, const eSize & );
38  friend inline eSize operator+( const eSize &, const eSize & );
39  friend inline eSize operator-( const eSize &, const eSize & );
40  friend inline eSize operator*( const eSize &, int );
41  friend inline eSize operator*( int, const eSize & );
42  friend inline eSize operator*( const eSize &, double );
43  friend inline eSize operator*( double, const eSize & );
44  friend inline eSize operator/( const eSize &, int );
45  friend inline eSize operator/( const eSize &, double );
46 
47 private:
48  int wd;
49  int ht;
50 };
51 
52 
53 /*****************************************************************************
54  eSize inline functions
55  *****************************************************************************/
56 
57 inline eSize::eSize()
58 { wd = ht = -1; }
59 
60 inline eSize::eSize( int w, int h )
61 { wd=w; ht=h; }
62 
63 inline bool eSize::isNull() const
64 { return wd==0 && ht==0; }
65 
66 inline bool eSize::isEmpty() const
67 { return wd<1 || ht<1; }
68 
69 inline bool eSize::isValid() const
70 { return wd>=0 && ht>=0; }
71 
72 inline int eSize::width() const
73 { return wd; }
74 
75 inline int eSize::height() const
76 { return ht; }
77 
78 inline void eSize::setWidth( int w )
79 { wd=w; }
80 
81 inline void eSize::setHeight( int h )
82 { ht=h; }
83 
84 inline int &eSize::rwidth()
85 { return wd; }
86 
87 inline int &eSize::rheight()
88 { return ht; }
89 
90 inline eSize &eSize::operator+=( const eSize &s )
91 { wd+=s.wd; ht+=s.ht; return *this; }
92 
93 inline eSize &eSize::operator-=( const eSize &s )
94 { wd-=s.wd; ht-=s.ht; return *this; }
95 
96 inline eSize &eSize::operator*=( int c )
97 { wd*=c; ht*=c; return *this; }
98 
99 inline eSize &eSize::operator*=( double c )
100 { wd=(int)(wd*c); ht=(int)(ht*c); return *this; }
101 
102 inline bool operator==( const eSize &s1, const eSize &s2 )
103 { return s1.wd == s2.wd && s1.ht == s2.ht; }
104 
105 inline bool operator!=( const eSize &s1, const eSize &s2 )
106 { return s1.wd != s2.wd || s1.ht != s2.ht; }
107 
108 inline eSize operator+( const eSize & s1, const eSize & s2 )
109 { return eSize(s1.wd+s2.wd, s1.ht+s2.ht); }
110 
111 inline eSize operator-( const eSize &s1, const eSize &s2 )
112 { return eSize(s1.wd-s2.wd, s1.ht-s2.ht); }
113 
114 inline eSize operator*( const eSize &s, int c )
115 { return eSize(s.wd*c, s.ht*c); }
116 
117 inline eSize operator*( int c, const eSize &s )
118 { return eSize(s.wd*c, s.ht*c); }
119 
120 inline eSize operator*( const eSize &s, double c )
121 { return eSize((int)(s.wd*c), (int)(s.ht*c)); }
122 
123 inline eSize operator*( double c, const eSize &s )
124 { return eSize((int)(s.wd*c), (int)(s.ht*c)); }
125 
126 inline eSize &eSize::operator/=( int c )
127 {
128  wd/=c; ht/=c;
129  return *this;
130 }
131 
132 inline eSize &eSize::operator/=( double c )
133 {
134  wd=(int)(wd/c); ht=(int)(ht/c);
135  return *this;
136 }
137 
138 inline eSize operator/( const eSize &s, int c )
139 {
140  return eSize(s.wd/c, s.ht/c);
141 }
142 
143 inline eSize operator/( const eSize &s, double c )
144 {
145  return eSize((int)(s.wd/c), (int)(s.ht/c));
146 }
147 
148 inline eSize eSize::expandedTo( const eSize & otherSize ) const
149 {
150  return eSize( MAX(wd,otherSize.wd), MAX(ht,otherSize.ht) );
151 }
152 
153 inline eSize eSize::boundedTo( const eSize & otherSize ) const
154 {
155  return eSize( MIN(wd,otherSize.wd), MIN(ht,otherSize.ht) );
156 }
157 
158 inline void eSize::transpose()
159 {
160  int tmp = wd;
161  wd = ht;
162  ht = tmp;
163 }
164 
165 #endif // ESIZE_H
Definition: esize.h:8
void setWidth(int w)
Definition: esize.h:78
eSize & operator/=(int c)
Definition: esize.h:126
int width() const
Definition: esize.h:72
eSize & operator-=(const eSize &)
Definition: esize.h:93
void setHeight(int h)
Definition: esize.h:81
eSize boundedTo(const eSize &) const
Definition: esize.h:153
int & rheight()
Definition: esize.h:87
int & rwidth()
Definition: esize.h:84
eSize & operator*=(int c)
Definition: esize.h:96
eSize expandedTo(const eSize &) const
Definition: esize.h:148
friend eSize operator-(const eSize &, const eSize &)
Definition: esize.h:111
friend eSize operator*(const eSize &, int)
Definition: esize.h:114
friend eSize operator/(const eSize &, int)
Definition: esize.h:138
void transpose()
Definition: esize.h:158
bool isEmpty() const
Definition: esize.h:66
bool isNull() const
Definition: esize.h:63
friend bool operator!=(const eSize &, const eSize &)
Definition: esize.h:105
int height() const
Definition: esize.h:75
bool isValid() const
Definition: esize.h:69
eSize & operator+=(const eSize &)
Definition: esize.h:90
friend eSize operator+(const eSize &, const eSize &)
Definition: esize.h:108
eSize()
Definition: esize.h:57
friend bool operator==(const eSize &, const eSize &)
Definition: esize.h:102
eSize operator-(const eSize &s1, const eSize &s2)
Definition: esize.h:111
bool operator!=(const eSize &s1, const eSize &s2)
Definition: esize.h:105
#define MIN(a, b)
Definition: esize.h:4
bool operator==(const eSize &s1, const eSize &s2)
Definition: esize.h:102
eSize operator*(const eSize &s, int c)
Definition: esize.h:114
eSize operator/(const eSize &s, int c)
Definition: esize.h:138
eSize operator+(const eSize &s1, const eSize &s2)
Definition: esize.h:108
#define MAX(a, b)
Definition: esize.h:5