openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
erect.h
Go to the documentation of this file.
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() constructs an INVALID rectangle. */
15  eRect(): x1(0), y1(0), x2(-1), y2(-1) {}
16  eRect( int left, int top, int width, int height ):
17  x1(left), y1(top), x2(left+width), y2(top+height)
18  {}
19  eRect( const ePoint &topleft, const ePoint &bottomright ):
20  x1(topleft.x()), y1(topleft.y()), x2(bottomright.x()), y2(bottomright.y())
21  {}
22  eRect( const ePoint &topleft, const eSize &size ):
23  x1(topleft.x()), y1(topleft.y()),
24  x2(x1+size.width()), y2(y1+size.height())
25  {}
26 
27  bool empty() const;
28  bool valid() const;
29  eRect normalize() const;
30 
31  int left() const;
32  int top() const;
33  int right() const;
34  int bottom() const;
35  int &rLeft();
36  int &rTop();
37  int &rRight();
38  int &rBottom();
39 
40  int x() const;
41  int y() const;
42  void setLeft( int pos );
43  void setTop( int pos );
44  void setRight( int pos );
45  void setBottom( int pos );
46  void setX( int x );
47  void setY( int y );
48 
49  ePoint topLeft() const;
50  ePoint bottomRight() const;
51  ePoint topRight() const;
52  ePoint bottomLeft() const;
53 
54  /* the sole intention of these functions
55  is to allow painting frames without
56  messing around with the coordinates.
57  they point to the last pixel included
58  in the rectangle (which means that 1 is
59  subtracted from the right and bottom
60  coordinates */
61  ePoint topLeft1() const;
62  ePoint bottomRight1() const;
63  ePoint topRight1() const;
64  ePoint bottomLeft1() const;
65  ePoint center() const;
66 
67  void rect( int *x, int *y, int *w, int *h ) const;
68  void coords( int *x1, int *y1, int *x2, int *y2 ) const;
69 
70  void moveTopLeft( const ePoint &p );
71  void moveBottomRight( const ePoint &p );
72  void moveTopRight( const ePoint &p );
73  void moveBottomLeft( const ePoint &p );
74  void moveCenter( const ePoint &p );
75 
76  void moveBy( int dx, int dy )
77  {
78  x1 += dx;
79  y1 += dy;
80  x2 += dx;
81  y2 += dy;
82  }
83 
84  void moveBy(ePoint r)
85  {
86  x1 += r.x();
87  y1 += r.y();
88  x2 += r.x();
89  y2 += r.y();
90  }
91 
92  void setRect( int x, int y, int w, int h );
93  void setCoords( int x1, int y1, int x2, int y2 );
94 
95  eSize size() const;
96  int width() const;
97  int height() const;
98  int surface() const { return width() * height(); }
99  void setWidth( int w );
100  void setHeight( int h );
101  void setSize( const eSize &s );
102 
103  eRect operator|(const eRect &r) const;
104  eRect operator&(const eRect &r) const;
105  eRect& operator|=(const eRect &r);
106  eRect& operator&=(const eRect &r);
107 
108  bool contains( const ePoint &p) const;
109  bool contains( int x, int y) const;
110  bool contains( const eRect &r) const;
111  eRect unite( const eRect &r ) const;
112  eRect intersect( const eRect &r ) const;
113  bool intersects( const eRect &r ) const;
114 
115  friend bool operator==( const eRect &, const eRect & );
116  friend bool operator!=( const eRect &, const eRect & );
117 
118  static eRect emptyRect() { return eRect(0, 0, 0, 0); }
119  static eRect invalidRect() { return eRect(); }
120 
121  void scale(int x_n, int x_d, int y_n, int y_d);
122 
123 private:
124  int x1;
125  int y1;
126  int x2;
127  int y2;
128 };
129 
130 bool operator==( const eRect &, const eRect & );
131 bool operator!=( const eRect &, const eRect & );
132 
133 
134 /*****************************************************************************
135  eRect inline member functions
136  *****************************************************************************/
137 
138 inline bool eRect::empty() const
139 { return x1 >= x2 || y1 >= y2; }
140 
141 inline bool eRect::valid() const
142 { return x1 <= x2 && y1 <= y2; }
143 
144 inline int eRect::left() const
145 { return x1; }
146 
147 inline int eRect::top() const
148 { return y1; }
149 
150 inline int eRect::right() const
151 { return x2; }
152 
153 inline int eRect::bottom() const
154 { return y2; }
155 
156 inline int &eRect::rLeft()
157 { return x1; }
158 
159 inline int & eRect::rTop()
160 { return y1; }
161 
162 inline int & eRect::rRight()
163 { return x2; }
164 
165 inline int & eRect::rBottom()
166 { return y2; }
167 
168 inline int eRect::x() const
169 { return x1; }
170 
171 inline int eRect::y() const
172 { return y1; }
173 
174 inline void eRect::setLeft( int pos )
175 { x1 = pos; }
176 
177 inline void eRect::setTop( int pos )
178 { y1 = pos; }
179 
180 inline void eRect::setRight( int pos )
181 { x2 = pos; }
182 
183 inline void eRect::setBottom( int pos )
184 { y2 = pos; }
185 
186 inline void eRect::setX( int x )
187 { x1 = x; }
188 
189 inline void eRect::setY( int y )
190 { y1 = y; }
191 
192 inline ePoint eRect::topLeft() const
193 { return ePoint(x1, y1); }
194 
196 { return ePoint(x2, y2); }
197 
198 inline ePoint eRect::topRight() const
199 { return ePoint(x2, y1); }
200 
201 inline ePoint eRect::bottomLeft() const
202 { return ePoint(x1, y2); }
203 
204 inline ePoint eRect::topLeft1() const
205 { return ePoint(x1, y1); }
206 
208 { return ePoint(x2-1, y2-1); }
209 
210 inline ePoint eRect::topRight1() const
211 { return ePoint(x2-1, y1); }
212 
214 { return ePoint(x1, y2-1); }
215 
216 inline ePoint eRect::center() const
217 { return ePoint((x1+x2)/2, (y1+y2)/2); }
218 
219 inline int eRect::width() const
220 { return x2 - x1; }
221 
222 inline int eRect::height() const
223 { return y2 - y1; }
224 
225 inline eSize eRect::size() const
226 { return eSize(x2-x1, y2-y1); }
227 
228 inline bool eRect::contains( int x, int y) const
229 {
230  return (x >= x1) && (x < x2) && (y >= y1) && (y < y2);
231 }
232 
233 #endif // eRect_H
Definition: epoint.h:9
int y() const
Definition: epoint.h:86
int x() const
Definition: epoint.h:83
Definition: erect.h:11
eRect(const ePoint &topleft, const eSize &size)
Definition: erect.h:22
int width() const
Definition: erect.h:219
ePoint bottomLeft1() const
Definition: erect.h:213
bool contains(const ePoint &p) const
Definition: erect.cpp:118
eRect(const ePoint &topleft, const ePoint &bottomright)
Definition: erect.h:19
eRect normalize() const
Definition: erect.cpp:8
eRect intersect(const eRect &r) const
Definition: erect.cpp:177
ePoint topLeft() const
Definition: erect.h:192
void moveBottomRight(const ePoint &p)
Definition: erect.cpp:52
void moveBy(int dx, int dy)
Definition: erect.h:76
eSize size() const
Definition: erect.h:225
eRect unite(const eRect &r) const
Definition: erect.cpp:162
void moveTopRight(const ePoint &p)
Definition: erect.cpp:60
void setBottom(int pos)
Definition: erect.h:183
int & rBottom()
Definition: erect.h:165
void moveTopLeft(const ePoint &p)
Definition: erect.cpp:44
int left() const
Definition: erect.h:144
static eRect invalidRect()
Definition: erect.h:119
int surface() const
Definition: erect.h:98
int bottom() const
Definition: erect.h:153
ePoint topRight1() const
Definition: erect.h:210
int & rLeft()
Definition: erect.h:156
int height() const
Definition: erect.h:222
bool valid() const
Definition: erect.h:141
eRect()
Definition: erect.h:15
void scale(int x_n, int x_d, int y_n, int y_d)
Definition: erect.cpp:198
int & rTop()
Definition: erect.h:159
int & rRight()
Definition: erect.h:162
eRect(int left, int top, int width, int height)
Definition: erect.h:16
void setRect(int x, int y, int w, int h)
Definition: erect.cpp:86
void moveBy(ePoint r)
Definition: erect.h:84
static eRect emptyRect()
Definition: erect.h:118
int y() const
Definition: erect.h:171
ePoint bottomLeft() const
Definition: erect.h:201
int top() const
Definition: erect.h:147
void setY(int y)
Definition: erect.h:189
void moveCenter(const ePoint &p)
Definition: erect.cpp:76
void rect(int *x, int *y, int *w, int *h) const
Definition: erect.cpp:28
void setSize(const eSize &s)
Definition: erect.cpp:112
bool empty() const
Definition: erect.h:138
eRect & operator&=(const eRect &r)
Definition: erect.cpp:138
void setX(int x)
Definition: erect.h:186
friend bool operator!=(const eRect &, const eRect &)
Definition: erect.cpp:193
int x() const
Definition: erect.h:168
void setLeft(int pos)
Definition: erect.h:174
ePoint center() const
Definition: erect.h:216
ePoint topRight() const
Definition: erect.h:198
friend bool operator==(const eRect &, const eRect &)
Definition: erect.cpp:188
void setCoords(int x1, int y1, int x2, int y2)
Definition: erect.cpp:94
eRect operator|(const eRect &r) const
Definition: erect.cpp:144
void moveBottomLeft(const ePoint &p)
Definition: erect.cpp:68
eRect & operator|=(const eRect &r)
Definition: erect.cpp:132
void setRight(int pos)
Definition: erect.h:180
void setTop(int pos)
Definition: erect.h:177
int right() const
Definition: erect.h:150
bool intersects(const eRect &r) const
Definition: erect.cpp:182
void setHeight(int h)
Definition: erect.cpp:107
void setWidth(int w)
Definition: erect.cpp:102
ePoint bottomRight() const
Definition: erect.h:195
eRect operator&(const eRect &r) const
Definition: erect.cpp:167
ePoint topLeft1() const
Definition: erect.h:204
ePoint bottomRight1() const
Definition: erect.h:207
void coords(int *x1, int *y1, int *x2, int *y2) const
Definition: erect.cpp:36
Definition: esize.h:8
Definition: region.h:9
bool operator!=(const eRect &, const eRect &)
Definition: erect.cpp:193
bool operator==(const eRect &, const eRect &)
Definition: erect.cpp:188
pos
Definition: enigma_py_patcher.py:16
p
Definition: upgrade.py:63
std::string int int y
Definition: picload.cpp:1503
std::string int x
Definition: picload.cpp:1503