comparison d1/qt/core/QRect.d @ 344:96a75b1e5b26

project structure changes
author Max Samukha <maxter@spambox.com>
date Fri, 14 May 2010 12:14:37 +0300
parents qt/d1/qt/core/QRect.d@34a37904ff77
children
comparison
equal deleted inserted replaced
343:552647ec0f82 344:96a75b1e5b26
1 module qt.core.QRect;
2
3 public import qt.QGlobal;
4 public import qt.core.Qt;
5
6 public import qt.core.QDataStream;
7 public import qt.core.QSize;
8 public import qt.core.QPoint;
9
10
11 public struct QRect
12 {
13 public static QRect opCall() {
14 QRect rt;
15 rt.x1 = rt.y1 = 0;
16 rt.x2 = rt.y2 = -1;
17 return rt;
18 }
19
20 public static QRect opCall(int aleft, int atop, int awidth, int aheight)
21 {
22 QRect rt;
23 rt.x1 = aleft;
24 rt.y1 = atop;
25 rt.x2 = (aleft + awidth - 1);
26 rt.y2 = (atop + aheight - 1);
27 return rt;
28 }
29
30 public static QRect opCall(in QPoint atopLeft, in QPoint abottomRight)
31 {
32 QRect rt;
33 rt.x1 = atopLeft.x();
34 rt.y1 = atopLeft.y();
35 rt.x2 = abottomRight.x();
36 rt.y2 = abottomRight.y();
37 return rt;
38 }
39
40 public static QRect opCall(in QPoint atopLeft, in QSize asize)
41 {
42 QRect rt;
43 rt.x1 = atopLeft.x();
44 rt.y1 = atopLeft.y();
45 rt.x2 = (rt.x1+asize.width() - 1);
46 rt.y2 = (rt.y1+asize.height() - 1);
47 return rt;
48 }
49
50 bool isNull() // const
51 { return x2 == x1 - 1 && y2 == y1 - 1; }
52
53 bool isEmpty() // const
54 { return x1 > x2 || y1 > y2; }
55
56 bool isValid() // const
57 { return x1 <= x2 && y1 <= y2; }
58
59 int left() // const
60 { return x1; }
61
62 int top() // const
63 { return y1; }
64
65 int right() // const
66 { return x2; }
67
68 int bottom() // const
69 { return y2; }
70
71 int x() // const
72 { return x1; }
73
74 int y() // const
75 { return y1; }
76
77 void left(int pos)
78 { x1 = pos; }
79
80 void top(int pos)
81 { y1 = pos; }
82
83 void right(int pos)
84 { x2 = pos; }
85
86 void bottom(int pos)
87 { y2 = pos; }
88
89 void setLeft(int pos)
90 { x1 = pos; }
91
92 void setTop(int pos)
93 { y1 = pos; }
94
95 void setRight(int pos)
96 { x2 = pos; }
97
98 void setBottom(int pos)
99 { y2 = pos; }
100
101 void setTopLeft(in QPoint p)
102 { x1 = p.x(); y1 = p.y(); }
103
104 void setBottomRight(in QPoint p)
105 { x2 = p.x(); y2 = p.y(); }
106
107 void setTopRight(in QPoint p)
108 { x2 = p.x(); y1 = p.y(); }
109
110 void setBottomLeft(in QPoint p)
111 { x1 = p.x(); y2 = p.y(); }
112
113 void setX(int ax)
114 { x1 = ax; }
115
116 void setY(int ay)
117 { y1 = ay; }
118
119 QPoint topLeft() // const
120 { return QPoint(x1, y1); }
121
122 QPoint bottomRight() // const
123 { return QPoint(x2, y2); }
124
125 QPoint topRight() // const
126 { return QPoint(x2, y1); }
127
128 QPoint bottomLeft() // const
129 { return QPoint(x1, y2); }
130
131 QPoint center() // const
132 { return QPoint((x1+x2)/2, (y1+y2)/2); }
133
134 int width() // const
135 { return x2 - x1 + 1; }
136
137 int height() // const
138 { return y2 - y1 + 1; }
139
140 QSize size() // const
141 { return QSize(width(), height()); }
142
143 void translate(int dx, int dy)
144 {
145 x1 += dx;
146 y1 += dy;
147 x2 += dx;
148 y2 += dy;
149 }
150
151 void translate(in QPoint p)
152 {
153 x1 += p.x();
154 y1 += p.y();
155 x2 += p.x();
156 y2 += p.y();
157 }
158
159 QRect translated(int dx, int dy) // const
160 { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); }
161
162 QRect translated(in QPoint p) // const
163 { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); }
164
165 void moveTo(int ax, int ay)
166 {
167 x2 += ax - x1;
168 y2 += ay - y1;
169 x1 = ax;
170 y1 = ay;
171 }
172
173 void moveTo(in QPoint p)
174 {
175 x2 += p.x() - x1;
176 y2 += p.y() - y1;
177 x1 = p.x();
178 y1 = p.y();
179 }
180
181 void moveLeft(int pos)
182 { x2 += (pos - x1); x1 = pos; }
183
184 void moveTop(int pos)
185 { y2 += (pos - y1); y1 = pos; }
186
187 void moveRight(int pos)
188 {
189 x1 += (pos - x2);
190 x2 = pos;
191 }
192
193 void moveBottom(int pos)
194 {
195 y1 += (pos - y2);
196 y2 = pos;
197 }
198
199 void moveTopLeft(in QPoint p)
200 {
201 moveLeft(p.x());
202 moveTop(p.y());
203 }
204
205 void moveBottomRight(in QPoint p)
206 {
207 moveRight(p.x());
208 moveBottom(p.y());
209 }
210
211 void moveTopRight(in QPoint p)
212 {
213 moveRight(p.x());
214 moveTop(p.y());
215 }
216
217 void moveBottomLeft(in QPoint p)
218 {
219 moveLeft(p.x());
220 moveBottom(p.y());
221 }
222
223 void getRect(int *ax, int *ay, int *aw, int *ah) // const
224 {
225 *ax = x1;
226 *ay = y1;
227 *aw = x2 - x1 + 1;
228 *ah = y2 - y1 + 1;
229 }
230
231 void setRect(int ax, int ay, int aw, int ah)
232 {
233 x1 = ax;
234 y1 = ay;
235 x2 = (ax + aw - 1);
236 y2 = (ay + ah - 1);
237 }
238
239 void getCoords(int *xp1, int *yp1, int *xp2, int *yp2) // const
240 {
241 *xp1 = x1;
242 *yp1 = y1;
243 *xp2 = x2;
244 *yp2 = y2;
245 }
246
247 void setCoords(int xp1, int yp1, int xp2, int yp2)
248 {
249 x1 = xp1;
250 y1 = yp1;
251 x2 = xp2;
252 y2 = yp2;
253 }
254
255 QRect adjusted(int xp1, int yp1, int xp2, int yp2) // const
256 { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); }
257
258 void adjust(int dx1, int dy1, int dx2, int dy2)
259 {
260 x1 += dx1;
261 y1 += dy1;
262 x2 += dx2;
263 y2 += dy2;
264 }
265
266 void setWidth(int w)
267 { x2 = (x1 + w - 1); }
268
269 void setHeight(int h)
270 { y2 = (y1 + h - 1); }
271
272 void setSize(in QSize s)
273 {
274 x2 = (s.width() + x1 - 1);
275 y2 = (s.height() + y1 - 1);
276 }
277
278 bool contains(int ax, int ay, bool aproper) // const
279 {
280 return contains(QPoint(ax, ay), aproper);
281 }
282
283 bool contains(int ax, int ay) // const
284 {
285 return contains(QPoint(ax, ay), false);
286 }
287
288 QRect opOrAssign(in QRect r)
289 {
290 *this = *this | r;
291 return *this;
292 }
293
294 QRect opAndAssign(in QRect r)
295 {
296 *this = *this & r;
297 return *this;
298 }
299
300 QRect intersected(in QRect other) // const
301 {
302 return *this & other;
303 }
304
305 QRect united(in QRect r) // const
306 {
307 return *this | r;
308 }
309
310 bool opEquals(in QRect r)
311 {
312 return x1==r.x1 && x2==r.x2 && y1==r.y1 && y2==r.y2;
313 }
314
315 public final void writeTo(QDataStream arg__1) {
316 qtd_QRect_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId);
317 }
318
319 public final void readFrom(QDataStream arg__1) {
320 qtd_QRect_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId);
321 }
322
323 public final QRect opAnd(in QRect r) {
324 return qtd_QRect_operator_and_QRect(this, &r);
325 }
326
327 public final QRect opOr(in QRect r) {
328 return qtd_QRect_operator_or_QRect(this, &r);
329 }
330
331 public final bool contains(QPoint p, bool proper = false) {
332 return qtd_QRect_contains_QPoint_bool(this, &p, proper);
333 }
334
335 public final bool contains(QRect r, bool proper = false) {
336 return qtd_QRect_contains_QRect_bool(this, &r, proper);
337 }
338
339 public final bool intersects(QRect r) {
340 return qtd_QRect_intersects_QRect(this, &r);
341 }
342
343 public final QRect normalized() {
344 return qtd_QRect_normalized(this);
345 }
346
347 private:
348 version(OSX)
349 {
350 int y1;
351 int x1;
352 int y2;
353 int x2;
354 }
355 else
356 {
357 int x1;
358 int y1;
359 int x2;
360 int y2;
361 }
362 }
363
364
365 // C wrappers
366 private extern(C) bool qtd_QRect_contains_QPoint_bool(void* __this_nativeId,
367 void* p0,
368 bool proper1);
369 private extern(C) bool qtd_QRect_contains_QRect_bool(void* __this_nativeId,
370 void* r0,
371 bool proper1);
372 private extern(C) bool qtd_QRect_intersects_QRect(void* __this_nativeId,
373 void* r0);
374 private extern(C) QRect qtd_QRect_normalized(void* __this_nativeId);
375 private extern(C) void qtd_QRect_writeTo_QDataStream(void* __this_nativeId,
376 void* arg__1);
377 private extern(C) void qtd_QRect_readFrom_QDataStream(void* __this_nativeId,
378 void* arg__1);
379 private extern(C) QRect qtd_QRect_operator_and_QRect(void* __this_nativeId,
380 void* r0);
381 private extern(C) QRect qtd_QRect_operator_or_QRect(void* __this_nativeId,
382 void* r0);