comparison qt/d1/qt/core/QSize.d @ 188:7dd099050621

initial commit for D2 support
author eldar
date Sun, 12 Jul 2009 18:58:03 +0000
parents
children 99e74c8a22f8
comparison
equal deleted inserted replaced
187:34fe79a9915b 188:7dd099050621
1 module qt.core.QSize;
2
3 public import qt.QGlobal;
4 public import qt.core.Qt;
5
6
7 public struct QSize
8 {
9 /* ctors, reserved for D2
10 public this()
11 { wd = ht = -1; }
12
13 public this(int w, int h)
14 { wd = w; ht = h; }
15 */
16
17 public static QSize opCall() {
18 QSize sz;
19 sz.wd = sz.ht = -1;
20 return sz;
21 }
22
23 public static QSize opCall(int w, int h) {
24 QSize sz;
25 sz.wd = w;
26 sz.ht = h;
27 return sz;
28 }
29
30 final bool isNull()
31 { return wd==0 && ht==0; }
32
33 final bool isEmpty()
34 { return wd<1 || ht<1; }
35
36 final bool isValid()
37 { return wd>=0 && ht>=0; }
38
39 final int width()
40 { return wd; }
41
42 final int height()
43 { return ht; }
44
45 final void width(int w)
46 { wd = w; }
47
48 final void height(int h)
49 { ht = h; }
50
51 final void setWidth(int w) // for convenience
52 { wd = w; }
53
54 final void setHeight(int h) // for convenience
55 { ht = h; }
56
57 void transpose() {
58 int tmp = wd;
59 wd = ht;
60 ht = tmp;
61 }
62
63 void scale(int w, int h, Qt.AspectRatioMode mode) {
64 scale(QSize(w, h), mode);
65 }
66
67 void scale(ref QSize s, Qt.AspectRatioMode mode) {
68 __qtd_QSize_scale_QSize_AspectRatioMode(this, &s, mode);
69 }
70
71 QSize expandedTo(ref QSize otherSize) {
72 return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
73 }
74
75 QSize boundedTo(ref QSize otherSize) {
76 return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
77 }
78 /*
79 public final void writeTo(QDataStream arg__1) {
80 __qtd_QSize_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.nativeId);
81 }
82
83 public final void readFrom(QDataStream arg__1) {
84 __qtd_QSize_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.nativeId);
85 }
86 */
87 QSize opAddAssign(ref QSize s)
88 { wd+=s.wd; ht+=s.ht; return *this; }
89
90 QSize opSubAssign(ref QSize s)
91 { wd-=s.wd; ht-=s.ht; return *this; }
92
93 QSize opMulAssign(qreal c)
94 { wd = qRound(wd*c); ht = qRound(ht*c); return *this; }
95
96 bool opEquals(ref QSize s)
97 { return wd == s.wd && ht == s.ht; }
98
99 QSize opAdd(ref QSize s)
100 { return QSize(this.wd+s.wd, this.ht+s.ht); }
101
102 QSize opSub(ref QSize s)
103 { return QSize(this.wd-s.wd, this.ht-s.ht); }
104
105 QSize opMul(qreal c)
106 { return QSize(qRound(this.wd*c), qRound(this.ht*c)); }
107
108 QSize opDivAssign(qreal c) {
109 assert(!qFuzzyCompare(c + 1, 1.));
110 wd = qRound(wd/c); ht = qRound(ht/c);
111 return *this;
112 }
113
114 QSize opDiv(qreal c) {
115 assert(!qFuzzyCompare(c + 1, 1.));
116 return QSize(qRound(this.wd/c), qRound(this.ht/c));
117 }
118
119 private:
120 int wd;
121 int ht;
122 }
123
124
125 public struct QSizeF
126 {
127 /* ctors, reserved for D2
128 this()
129 { wd = ht = -1.; }
130
131 this(ref QSize sz)
132 { wd = sz.width(); ht = sz.height(); }
133
134 this(qreal w, qreal h)
135 { wd = w; ht = h; }
136 */
137 public static QSizeF opCall() {
138 QSizeF sz;
139 sz.wd = sz.ht = -1.;
140 return sz;
141 }
142
143 public static QSizeF opCall(ref QSizeF s) {
144 QSizeF sz;
145 sz.wd = s.width(); sz.ht = s.height();
146 return sz;
147 }
148
149 public static QSizeF opCall(qreal w, qreal h) {
150 QSizeF sz;
151 sz.wd = w; sz.ht = h;
152 return sz;
153 }
154
155 bool isNull()
156 { return qIsNull(wd) && qIsNull(ht); }
157
158 bool isEmpty()
159 { return wd <= 0. || ht <= 0.; }
160
161 bool isValid()
162 { return wd >= 0. && ht >= 0.; }
163
164 qreal width()
165 { return wd; }
166
167 qreal height()
168 { return ht; }
169
170 void width(qreal w)
171 { wd = w; }
172
173 void height(qreal h)
174 { ht = h; }
175
176 void setWidth(qreal w)
177 { wd = w; }
178
179 void setHeight(qreal h)
180 { ht = h; }
181
182 void scale(qreal w, qreal h, Qt.AspectRatioMode mode)
183 { scale(QSizeF(w, h), mode); }
184
185 public final void scale(QSizeF s, Qt.AspectRatioMode mode)
186 { __qtd_QSizeF_scale_QSizeF_AspectRatioMode(this, &s, mode); }
187
188 void transpose() {
189 qreal tmp = wd;
190 wd = ht;
191 ht = tmp;
192 }
193
194 QSizeF expandedTo(ref QSizeF otherSize)
195 { return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht)); }
196
197 QSizeF boundedTo(ref QSizeF otherSize)
198 { return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht)); }
199
200 QSize toSize()
201 { return QSize(qRound(wd), qRound(ht)); }
202 /*
203 public final void writeTo(QDataStream arg__1) {
204 __qtd_QSizeF_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.nativeId);
205 }
206
207 public final void readFrom(QDataStream arg__1) {
208 __qtd_QSizeF_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.nativeId);
209 */
210 QSizeF opAddAssign(ref QSizeF s)
211 { wd += s.wd; ht += s.ht; return *this; }
212
213 QSizeF opSubAssign(ref QSizeF s)
214 { wd -= s.wd; ht -= s.ht; return *this; }
215
216 QSizeF opMulAssign(qreal c)
217 { wd *= c; ht *= c; return *this; }
218
219 bool opEquals(ref QSizeF s)
220 { return qFuzzyCompare(wd, s.wd) && qFuzzyCompare(ht, s.ht); }
221
222 QSizeF opAdd(ref QSizeF s)
223 { return QSizeF(this.wd+s.wd, this.ht+s.ht); }
224
225 QSizeF opSub(ref QSizeF s)
226 { return QSizeF(this.wd-s.wd, this.ht-s.ht); }
227
228 QSizeF opMul(qreal c)
229 { return QSizeF(this.wd*c, this.ht*c); }
230
231 QSizeF opDivAssign(qreal c)
232 {
233 assert(!qFuzzyCompare(c + 1, 1.));
234 wd = wd/c; ht = ht/c;
235 return *this;
236 }
237
238 QSizeF opDiv(qreal c)
239 {
240 assert(!qFuzzyCompare(c + 1, 1.));
241 return QSizeF(this.wd/c, this.ht/c);
242 }
243
244 private:
245 qreal wd;
246 qreal ht;
247 }
248
249 extern (C) void qtd_append_array_QSize(QSize[]* arr, QSize arg)
250 {
251 *arr ~= arg;
252 }
253
254 extern (C) void qtd_append_array_QSizeF(QSizeF[]* arr, QSizeF arg)
255 {
256 *arr ~= arg;
257 }
258
259 // C wrappers
260 // QSize
261 private extern(C) void __qtd_QSize_scale_QSize_AspectRatioMode(void* __this_nativeId,
262 void* s0,
263 int mode1);
264 private extern(C) void __qtd_QSize_writeTo_QDataStream(void* __this_nativeId,
265 void* arg__1);
266 private extern(C) void __qtd_QSize_readFrom_QDataStream(void* __this_nativeId,
267 void* arg__1);
268
269 // QSizeF
270 private extern(C) void __qtd_QSizeF_writeTo_QDataStream(void* __this_nativeId,
271 void* arg__1);
272 private extern(C) void __qtd_QSizeF_readFrom_QDataStream(void* __this_nativeId,
273 void* arg__1);
274 private extern(C) void __qtd_QSizeF_scale_QSizeF_AspectRatioMode(void* __this_nativeId,
275 void* s0,
276 int mode1);