comparison d2/qt/core/QPoint.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/QPoint.d@b460cd08041f
children 12f60887ed15 a032df77b6ab
comparison
equal deleted inserted replaced
343:552647ec0f82 344:96a75b1e5b26
1 module qt.core.QPoint;
2
3 public import qt.QGlobal;
4 public import qt.core.Qt;
5 public import qt.core.QDataStream;
6
7
8 public struct QPoint
9 {
10
11 // Functions
12 public static QPoint opCall() {
13 QPoint pt;
14 pt.xp = pt.yp = 0;
15 return pt;
16 }
17
18 public this(int xpos, int ypos) {
19 xp = xpos;
20 yp = ypos;
21 }
22
23 bool isNull() // const
24 { return xp == 0 && yp == 0; }
25
26 int x() const
27 { return xp; }
28
29 int y() const
30 { return yp; }
31
32 void x(int xpos)
33 { xp = xpos; }
34
35 void y(int ypos)
36 { yp = ypos; }
37
38 void setX(int xpos) // for convenience
39 { xp = xpos; }
40
41 void setY(int ypos) // for convenience
42 { yp = ypos; }
43
44 public final int manhattanLength() {
45 return qtd_QPoint_manhattanLength(&this);
46 }
47 /*
48 inline int &rx()
49 { return xp; }
50
51 inline int &ry()
52 { return yp; }
53 */
54
55 QPoint opAddAssign(ref QPoint p)
56 { xp+=p.xp; yp+=p.yp; return this; }
57
58 QPoint opSubAssign(ref QPoint p)
59 { xp-=p.xp; yp-=p.yp; return this; }
60
61 QPoint opMulAssign(qreal c)
62 { xp = qRound(xp*c); yp = qRound(yp*c); return this; }
63
64 bool opEquals(ref const QPoint p) const
65 { return xp == p.xp && yp == p.yp; }
66
67 QPoint opAdd(ref QPoint p)
68 { return QPoint(this.xp+p.xp, this.yp+p.yp); }
69
70 QPoint opSub(ref QPoint p)
71 { return QPoint(this.xp-p.xp, this.yp-p.yp); }
72
73 QPoint opMul(qreal c)
74 { return QPoint(qRound(this.xp*c), qRound(this.yp*c)); }
75
76 QPoint opDivAssign(qreal c)
77 {
78 xp = qRound(xp/c);
79 yp = qRound(yp/c);
80 return this;
81 }
82
83 QPoint opDiv(qreal c)
84 {
85 return QPoint(qRound(this.xp/c), qRound(this.yp/c));
86 }
87
88 public final void writeTo(QDataStream arg__1) {
89 qtd_QPoint_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
90 }
91
92 public final void readFrom(QDataStream arg__1) {
93 qtd_QPoint_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
94 }
95
96 // service stuff
97 public alias void __isNativeValueType;
98
99 struct QTypeInfo
100 {
101 enum bool isComplex = true;
102 enum bool isStatic = false;
103 enum bool isLarge = true;
104 enum bool isPointer = false;
105 enum bool isDummy = false;
106 }
107
108
109 private:
110 // ### Qt 5; remove the ifdef and just have the same order on all platforms.
111 version(OSX)
112 {
113 int yp;
114 int xp;
115 }
116 else
117 {
118 int xp;
119 int yp;
120 }
121 }
122
123
124 public struct QPointF
125 {
126 public static QPointF opCall() {
127 QPointF pt;
128 pt.xp = pt.yp = 0;
129 return pt;
130 }
131
132 public this(qreal xpos, qreal ypos) {
133 xp = xpos;
134 yp = ypos;
135 }
136
137 public this(QPoint p) {
138 xp = p.x();
139 yp = p.y();
140 }
141
142 bool isNull() //const
143 {
144 return qIsNull(xp) && qIsNull(yp);
145 }
146
147 qreal x() //const
148 {
149 return xp;
150 }
151
152 qreal y() //const
153 {
154 return yp;
155 }
156
157 void x(qreal xpos)
158 {
159 xp = xpos;
160 }
161
162 void y(qreal ypos)
163 {
164 yp = ypos;
165 }
166 /*
167 inline qreal &QPointF::rx()
168 {
169 return xp;
170 }
171
172 inline qreal &QPointF::ry()
173 {
174 return yp;
175 }
176 */
177
178 QPointF opAddAssign(ref QPointF p)
179 { xp+=p.xp; yp+=p.yp; return this; }
180
181 QPointF opSubAssign(ref QPointF p)
182 { xp-=p.xp; yp-=p.yp; return this; }
183
184 QPointF opMulAssign(qreal c)
185 { xp*=c; yp*=c; return this; }
186
187 bool opEquals(ref const QPointF p) const
188 { return qFuzzyCompare(xp, p.xp) && qFuzzyCompare(yp, p.yp); }
189
190 QPointF opAdd(ref QPointF p)
191 { return QPointF(this.xp+p.xp, this.yp+p.yp); }
192
193 QPointF opSub(ref QPointF p)
194 { return QPointF(this.xp-p.xp, this.yp-p.yp); }
195
196 QPointF opMul(qreal c)
197 { return QPointF(this.xp*c, this.yp*c); }
198
199 QPointF opDivAssign(qreal c)
200 {
201 xp/=c;
202 yp/=c;
203 return this;
204 }
205
206 QPointF opDiv(qreal c)
207 {
208 return QPointF(xp/c, yp/c);
209 }
210
211 QPoint toPoint() //const
212 {
213 return QPoint(qRound(xp), qRound(yp));
214 }
215
216 public final void writeTo(QDataStream arg__1) {
217 qtd_QPointF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
218 }
219
220 public final void readFrom(QDataStream arg__1) {
221 qtd_QPointF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
222 }
223
224 // service stuff
225 public alias void __isNativeValueType;
226
227 struct QTypeInfo
228 {
229 enum bool isComplex = true;
230 enum bool isStatic = false;
231 enum bool isLarge = true;
232 enum bool isPointer = false;
233 enum bool isDummy = false;
234 }
235
236 private:
237 qreal xp;
238 qreal yp;
239 }
240
241
242 // C wrappers
243 // QPoint
244 private extern(C) int qtd_QPoint_manhattanLength(void* __this_nativeId);
245 private extern(C) void qtd_QPoint_writeTo_QDataStream(void* __this_nativeId,
246 void* arg__1);
247 private extern(C) void qtd_QPoint_readFrom_QDataStream(void* __this_nativeId,
248 void* arg__1);
249
250 // QPointF
251 private extern(C) void qtd_QPointF_writeTo_QDataStream(void* __this_nativeId,
252 void* arg__1);
253 private extern(C) void qtd_QPointF_readFrom_QDataStream(void* __this_nativeId,
254 void* arg__1);