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