yes! ich habs kaputt gemacht! (doesn't compile anymore, doesn't work anymore,
[vuplus_dvbapp] / lib / gdi / erect.h
1 #ifndef ERECT_H
2 #define ERECT_H
3
4 #include <lib/gdi/esize.h>
5 #include <lib/gdi/epoint.h>
6
7
8 // x2 = x1 + width  (AND NOT, NEVER, NEVER EVER +1 or -1 !!!!)
9
10 class eRect // rectangle class
11 {
12         friend class gRegion;
13 public:
14         eRect() { x1 = y1 = x2 = y2 = 0; }
15         eRect( const ePoint &topleft, const ePoint &bottomright );
16
17         // we use this contructor very often... do it inline...
18         eRect( const ePoint &topleft, const eSize &size )
19         {
20                 x1 = topleft.x();
21                 y1 = topleft.y();
22                 x2 = (x1+size.width());
23                 y2 = (y1+size.height());
24         }
25
26         eRect( int left, int top, int width, int height );
27
28         bool isNull()   const;
29         bool isEmpty()  const;
30         bool isValid()  const;
31         eRect normalize()       const;
32
33         int left()      const;
34         int top()       const;
35         int right()     const;
36         int  bottom()   const;
37         int &rLeft();
38         int &rTop();
39         int &rRight();
40         int &rBottom();
41
42         int x() const;
43         int y() const;
44         void setLeft( int pos );
45         void setTop( int pos );
46         void setRight( int pos );
47         void setBottom( int pos );
48         void setX( int x );
49         void setY( int y );
50
51         ePoint topLeft()         const;
52         ePoint bottomRight() const;
53         ePoint topRight()        const;
54         ePoint bottomLeft()      const;
55         ePoint center()  const;
56
57         void rect( int *x, int *y, int *w, int *h ) const;
58         void coords( int *x1, int *y1, int *x2, int *y2 ) const;
59
60         void moveTopLeft( const ePoint &p );
61         void moveBottomRight( const ePoint &p );
62         void moveTopRight( const ePoint &p );
63         void moveBottomLeft( const ePoint &p );
64         void moveCenter( const ePoint &p );
65
66         void moveBy( int dx, int dy )
67         {
68                 x1 += dx;
69                 y1 += dy;
70                 x2 += dx;
71                 y2 += dy;
72         }
73
74         void setRect( int x, int y, int w, int h );
75         void setCoords( int x1, int y1, int x2, int y2 );
76
77         eSize size()    const;
78         int width()     const;
79         int height()    const;
80         void setWidth( int w );
81         void setHeight( int h );
82         void setSize( const eSize &s );
83
84         eRect operator|(const eRect &r) const;
85         eRect operator&(const eRect &r) const;
86         eRect& operator|=(const eRect &r);
87         eRect& operator&=(const eRect &r);
88
89         bool contains( const ePoint &p) const;
90         bool contains( int x, int y) const;
91         bool contains( const eRect &r) const;
92         eRect unite( const eRect &r ) const;
93         eRect intersect( const eRect &r ) const;
94         bool intersects( const eRect &r ) const;
95
96         friend bool operator==( const eRect &, const eRect & );
97         friend bool operator!=( const eRect &, const eRect & );
98
99 private:
100         int x1;
101         int y1;
102         int x2;
103         int y2;
104 };
105
106 bool operator==( const eRect &, const eRect & );
107 bool operator!=( const eRect &, const eRect & );
108
109
110 /*****************************************************************************
111   eRect stream functions
112  *****************************************************************************/
113 namespace std
114 {
115         inline ostream &operator<<( ostream & s, const eRect & r )
116         {
117                 s << r.left()  << r.top()
118                   << r.right() << r.bottom();
119
120                 return s;
121         }
122
123         inline istream &operator>>( istream & s, eRect & r )
124         {
125                 int x1, y1, x2, y2;
126                 s >> x1 >> y1 >> x2 >> y2;
127                 r.setCoords( x1, y1, x2, y2 );
128                 return s;
129         }
130 }
131
132 /*****************************************************************************
133   eRect inline member functions
134  *****************************************************************************/
135
136 inline eRect::eRect( int left, int top, int width, int height )
137 {
138         x1 = left;
139         y1 = top;
140         x2 = left+width;
141         y2 = top+height;
142 }
143
144 inline bool eRect::isNull() const
145 { return x2 == x1 && y2 == y1; }
146
147 inline bool eRect::isEmpty() const
148 { return x1 >= x2 || y1 >= y2; }
149
150 inline bool eRect::isValid() const
151 { return x1 <= x2 && y1 <= y2; }
152
153 inline int eRect::left() const
154 { return x1; }
155
156 inline int eRect::top() const
157 { return y1; }
158
159 inline int eRect::right() const
160 { return x2; }
161
162 inline int eRect::bottom() const
163 { return y2; }
164
165 inline int &eRect::rLeft()
166 { return x1; }
167
168 inline int & eRect::rTop()
169 { return y1; }
170
171 inline int & eRect::rRight()
172 { return x2; }
173
174 inline int & eRect::rBottom()
175 { return y2; }
176
177 inline int eRect::x() const
178 { return x1; }
179
180 inline int eRect::y() const
181 { return y1; }
182
183 inline void eRect::setLeft( int pos )
184 { x1 = pos; }
185
186 inline void eRect::setTop( int pos )
187 { y1 = pos; }
188
189 inline void eRect::setRight( int pos )
190 { x2 = pos; }
191
192 inline void eRect::setBottom( int pos )
193 { y2 = pos; }
194
195 inline void eRect::setX( int x )
196 { x1 = x; }
197
198 inline void eRect::setY( int y )
199 { y1 = y; }
200
201 inline ePoint eRect::topLeft() const
202 { return ePoint(x1, y1); }
203
204 inline ePoint eRect::bottomRight() const
205 { return ePoint(x2, y2); }
206
207 inline ePoint eRect::topRight() const
208 { return ePoint(x2, y1); }
209
210 inline ePoint eRect::bottomLeft() const
211 { return ePoint(x1, y2); }
212
213 inline ePoint eRect::center() const
214 { return ePoint((x1+x2)/2, (y1+y2)/2); }
215
216 inline int eRect::width() const
217 { return  x2 - x1; }
218
219 inline int eRect::height() const
220 { return  y2 - y1; }
221
222 inline eSize eRect::size() const
223 { return eSize(x2-x1, y2-y1); }
224
225 inline bool eRect::contains( int x, int y) const
226 {
227         return x >= x1 && x < x2 && y >= y1 && y < y2;
228 }
229
230 #endif // eRect_H