1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.gui.transform;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.global;
19 import qt.core.line;
20 import qt.core.metatype;
21 import qt.core.namespace;
22 import qt.core.point;
23 import qt.core.rect;
24 import qt.core.typeinfo;
25 import qt.core.variant;
26 import qt.gui.matrix;
27 import qt.gui.painterpath;
28 import qt.gui.polygon;
29 import qt.gui.region;
30 import qt.helpers;
31 
32 /+ class QVariant;
33 class QPainterPath; +/
34 
35 @(QMetaType.Type.QTransform) @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_GUI_EXPORT +/ QTransform
36 {
37 public:
38     enum TransformationType {
39         TxNone      = 0x00,
40         TxTranslate = 0x01,
41         TxScale     = 0x02,
42         TxRotate    = 0x04,
43         TxShear     = 0x08,
44         TxProject   = 0x10
45     }
46 
47     /+ explicit +/pragma(inline, true) this(/+ Qt:: +/qt.core.namespace.Initialization)
48     {
49         this.affine = /+ Qt:: +/qt.core.namespace.Initialization.Uninitialized;
50     }
51     /+this();+/
52 
53     this(qreal h11, qreal h12, qreal h13,
54                    qreal h21, qreal h22, qreal h23,
55                    qreal h31, qreal h32, qreal h33 = 1.0);
56     this(qreal h11, qreal h12, qreal h21,
57                    qreal h22, qreal dx, qreal dy);
58 /+ #if QT_DEPRECATED_SINCE(5, 15) +/
59     /+ explicit +/this(ref const(QMatrix) mtx);
60 /+ #endif // QT_DEPRECATED_SINCE(5, 15)
61 
62 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/
63     // ### Qt 6: remove; the compiler-generated ones are fine!
64     /+ QTransform &operator=(QTransform &&other) noexcept // = default
65     { memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(QTransform)); return *this; } +/
66     /+ref QTransform operator =(ref const(QTransform) )/+ noexcept+/;+/ // = default
67     /+ QTransform(QTransform &&other) noexcept // = default
68         : affine(Qt::Uninitialized)
69     { memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(QTransform)); } +/
70     @disable this(this);
71     this(ref const(QTransform) other)/+ noexcept+/// = default
72 {
73     import core.stdc.string;
74     this.affine = /+ Qt:: +/qt.core.namespace.Initialization.Uninitialized;
75     memcpy(static_cast!(void*)(&this), static_cast!(const(void)*)(&other), QTransform.sizeof);
76 }
77 /+ #endif +/
78 
79     pragma(inline, true) bool isAffine() const
80     {
81         return inline_type() < TransformationType.TxProject;
82     }
83     pragma(inline, true) bool isIdentity() const
84     {
85         return inline_type() == TransformationType.TxNone;
86     }
87     pragma(inline, true) bool isInvertible() const
88     {
89         return !qFuzzyIsNull(determinant());
90     }
91     pragma(inline, true) bool isScaling() const
92     {
93         return type() >= TransformationType.TxScale;
94     }
95     pragma(inline, true) bool isRotating() const
96     {
97         return inline_type() >= TransformationType.TxRotate;
98     }
99     pragma(inline, true) bool isTranslating() const
100     {
101         return inline_type() >= TransformationType.TxTranslate;
102     }
103 
104     TransformationType type() const;
105 
106     pragma(inline, true) qreal determinant() const
107     {
108         return affine._m11*(m_33*affine._m22-affine._dy*m_23) -
109             affine._m21*(m_33*affine._m12-affine._dy*m_13)+affine._dx*(m_23*affine._m12-affine._m22*m_13);
110     }
111 /+ #if QT_DEPRECATED_SINCE(5, 13) +/
112     /+ QT_DEPRECATED_X("Use determinant() instead") +/
113         pragma(inline, true) qreal det() const
114     {
115         return determinant();
116     }
117 /+ #endif +/
118 
119     pragma(inline, true) qreal m11() const
120     {
121         return affine._m11;
122     }
123     pragma(inline, true) qreal m12() const
124     {
125         return affine._m12;
126     }
127     pragma(inline, true) qreal m13() const
128     {
129         return m_13;
130     }
131     pragma(inline, true) qreal m21() const
132     {
133         return affine._m21;
134     }
135     pragma(inline, true) qreal m22() const
136     {
137         return affine._m22;
138     }
139     pragma(inline, true) qreal m23() const
140     {
141         return m_23;
142     }
143     pragma(inline, true) qreal m31() const
144     {
145         return affine._dx;
146     }
147     pragma(inline, true) qreal m32() const
148     {
149         return affine._dy;
150     }
151     pragma(inline, true) qreal m33() const
152     {
153         return m_33;
154     }
155     pragma(inline, true) qreal dx() const
156     {
157         return affine._dx;
158     }
159     pragma(inline, true) qreal dy() const
160     {
161         return affine._dy;
162     }
163 
164     void setMatrix(qreal m11, qreal m12, qreal m13,
165                        qreal m21, qreal m22, qreal m23,
166                        qreal m31, qreal m32, qreal m33);
167 
168     /+ Q_REQUIRED_RESULT +/ QTransform inverted(bool* invertible = null) const;
169     /+ Q_REQUIRED_RESULT +/ QTransform adjoint() const;
170     /+ Q_REQUIRED_RESULT +/ QTransform transposed() const;
171 
172     ref QTransform translate(qreal dx, qreal dy);
173     ref QTransform scale(qreal sx, qreal sy);
174     ref QTransform shear(qreal sh, qreal sv);
175     ref QTransform rotate(qreal a, /+ Qt:: +/qt.core.namespace.Axis axis = /+ Qt:: +/qt.core.namespace.Axis.ZAxis);
176     ref QTransform rotateRadians(qreal a, /+ Qt:: +/qt.core.namespace.Axis axis = /+ Qt:: +/qt.core.namespace.Axis.ZAxis);
177 
178     static bool squareToQuad(ref const(QPolygonF) square, ref QTransform result);
179     static bool quadToSquare(ref const(QPolygonF) quad, ref QTransform result);
180     static bool quadToQuad(ref const(QPolygonF) one,
181                                ref const(QPolygonF) two,
182                                ref QTransform result);
183 
184     /+bool operator ==(ref const(QTransform) ) const;+/
185     /+bool operator !=(ref const(QTransform) ) const;+/
186 
187     /+ref QTransform operator *=(ref const(QTransform) );+/
188     /+QTransform operator *(ref const(QTransform) o) const;+/
189 
190     /+auto opCast(T : QVariant)() const;+/
191 
192     void reset();
193     QPoint       map(ref const(QPoint) p) const;
194     QPointF      map(ref const(QPointF) p) const;
195     QLine        map(ref const(QLine) l) const;
196     QLineF       map(ref const(QLineF) l) const;
197     QPolygonF    map(ref const(QPolygonF) a) const;
198     QPolygon     map(ref const(QPolygon) a) const;
199     QRegion      map(ref const(QRegion) r) const;
200     QPainterPath map(ref const(QPainterPath) p) const;
201     QPolygon     mapToPolygon(ref const(QRect) r) const;
202     QRect mapRect(ref const(QRect) ) const;
203     QRectF mapRect(ref const(QRectF) ) const;
204     void map(int x, int y, int* tx, int* ty) const;
205     void map(qreal x, qreal y, qreal* tx, qreal* ty) const;
206 
207 /+ #if QT_DEPRECATED_SINCE(5, 15) +/
208     ref const(QMatrix) toAffine() const;
209 /+ #endif +/ // QT_DEPRECATED_SINCE(5, 15)
210 
211     /+pragma(inline, true) ref QTransform operator *=(qreal num)
212     {
213         if (num == 1.)
214             return this;
215         affine._m11 *= num;
216         affine._m12 *= num;
217         m_13        *= num;
218         affine._m21 *= num;
219         affine._m22 *= num;
220         m_23        *= num;
221         affine._dx  *= num;
222         affine._dy  *= num;
223         m_33        *= num;
224         if (m_dirty < TransformationType.TxScale)
225             m_dirty = TransformationType.TxScale;
226         return this;
227     }+/
228     /+pragma(inline, true) ref QTransform operator /=(qreal div)
229     {
230         if (div == 0)
231             return this;
232         div = 1/div;
233         return operator*=(div);
234     }+/
235     pragma(inline, true) ref QTransform opOpAssign(string op)(qreal num) if(op == "+")
236     {
237         if (num == 0)
238             return this;
239         affine._m11 += num;
240         affine._m12 += num;
241         m_13        += num;
242         affine._m21 += num;
243         affine._m22 += num;
244         m_23        += num;
245         affine._dx  += num;
246         affine._dy  += num;
247         m_33        += num;
248         m_dirty     = TransformationType.TxProject;
249         return this;
250     }
251     pragma(inline, true) ref QTransform opOpAssign(string op)(qreal num) if(op == "-")
252     {
253         if (num == 0)
254             return this;
255         affine._m11 -= num;
256         affine._m12 -= num;
257         m_13        -= num;
258         affine._m21 -= num;
259         affine._m22 -= num;
260         m_23        -= num;
261         affine._dx  -= num;
262         affine._dy  -= num;
263         m_33        -= num;
264         m_dirty     = TransformationType.TxProject;
265         return this;
266     }
267 
268     static QTransform fromTranslate(qreal dx, qreal dy);
269     static QTransform fromScale(qreal dx, qreal dy);
270 
271 private:
272     pragma(inline, true) this(qreal h11, qreal h12, qreal h13,
273                           qreal h21, qreal h22, qreal h23,
274                           qreal h31, qreal h32, qreal h33, bool)
275     {
276         this.affine = QMatrix(h11, h12, h21, h22, h31, h32, true);
277         this.m_13 = h13; this.m_23 = h23; this.m_33 = h33;
278         this.m_type = TransformationType.TxNone;
279         this.m_dirty = TransformationType.TxProject;
280 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/
281         this.d = null;
282 /+ #endif +/
283     }
284     pragma(inline, true) this(bool)
285     {
286         this.affine = true;
287         this.m_13 = 0;
288         this.m_23 = 0;
289         this.m_33 = 1;
290         this.m_type = TransformationType.TxNone;
291         this.m_dirty = TransformationType.TxNone;
292 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/
293         this.d = null;
294 /+ #endif +/
295 }
296     /******* inlines *****/
297     pragma(inline, true) TransformationType inline_type() const
298     /+pragma(inline, true) QTransform.TransformationType inline_type() const+/
299     {
300         if (m_dirty == TransformationType.TxNone)
301             return static_cast!(TransformationType)(m_type);
302         return type();
303     }
304     QMatrix affine;
305     qreal   m_13 = 0;
306     qreal   m_23 = 0;
307     qreal   m_33 = 1;
308 
309     /+ mutable uint m_type : 5; +/
310     ushort bitfieldData_m_type;
311     final uint m_type() const
312     {
313         return (bitfieldData_m_type >> 0) & 0x1f;
314     }
315     final uint m_type(uint value)
316     {
317         bitfieldData_m_type = (bitfieldData_m_type & ~0x1f) | ((value & 0x1f) << 0);
318         return value;
319     }
320     /+ mutable uint m_dirty : 5; +/
321     final uint m_dirty() const
322     {
323         return (bitfieldData_m_type >> 5) & 0x1f;
324     }
325     final uint m_dirty(uint value)
326     {
327         bitfieldData_m_type = (bitfieldData_m_type & ~0x3e0) | ((value & 0x1f) << 5);
328         return value;
329     }
330 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/
331     extern(C++, class) struct Private;
332     Private* d;
333 /+ #endif +/
334 }
335 /+ Q_DECLARE_TYPEINFO(QTransform, Q_MOVABLE_TYPE);
336 
337 Q_GUI_EXPORT Q_DECL_CONST_FUNCTION uint qHash(const QTransform &key, uint seed = 0) noexcept;
338 #if QT_DEPRECATED_SINCE(5, 13)
339 #endif
340 
341 QT_WARNING_PUSH
342 QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
343 QT_WARNING_DISABLE_GCC("-Wfloat-equal")
344 QT_WARNING_DISABLE_INTEL(1572)
345 
346 QT_WARNING_POP +/
347 
348 pragma(inline, true) bool qFuzzyCompare(ref const(QTransform) t1, ref const(QTransform) t2)
349 {
350     return qt.core.global.qFuzzyCompare(t1.m11(), t2.m11())
351         && qt.core.global.qFuzzyCompare(t1.m12(), t2.m12())
352         && qt.core.global.qFuzzyCompare(t1.m13(), t2.m13())
353         && qt.core.global.qFuzzyCompare(t1.m21(), t2.m21())
354         && qt.core.global.qFuzzyCompare(t1.m22(), t2.m22())
355         && qt.core.global.qFuzzyCompare(t1.m23(), t2.m23())
356         && qt.core.global.qFuzzyCompare(t1.m31(), t2.m31())
357         && qt.core.global.qFuzzyCompare(t1.m32(), t2.m32())
358         && qt.core.global.qFuzzyCompare(t1.m33(), t2.m33());
359 }
360 
361 
362 /****** stream functions *******************/
363 /+ #ifndef QT_NO_DATASTREAM
364 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTransform &);
365 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTransform &);
366 #endif
367 
368 #ifndef QT_NO_DEBUG_STREAM
369 Q_GUI_EXPORT QDebug operator<<(QDebug, const QTransform &);
370 #endif +/
371 /****** end stream functions *******************/
372 
373 // mathematical semantics
374 /+pragma(inline, true) QPoint operator *(ref const(QPoint) p, ref const(QTransform) m)
375 { return m.map(p); }+/
376 /+pragma(inline, true) QPointF operator *(ref const(QPointF) p, ref const(QTransform) m)
377 { return m.map(p); }+/
378 /+pragma(inline, true) QLineF operator *(ref const(QLineF) l, ref const(QTransform) m)
379 { return m.map(l); }+/
380 /+pragma(inline, true) QLine operator *(ref const(QLine) l, ref const(QTransform) m)
381 { return m.map(l); }+/
382 /+pragma(inline, true) QPolygon operator *(ref const(QPolygon) a, ref const(QTransform) m)
383 { return m.map(a); }+/
384 /+pragma(inline, true) QPolygonF operator *(ref const(QPolygonF) a, ref const(QTransform) m)
385 { return m.map(a); }+/
386 /+pragma(inline, true) QRegion operator *(ref const(QRegion) r, ref const(QTransform) m)
387 { return m.map(r); }+/
388 
389 /+pragma(inline, true) QTransform operator *(ref const(QTransform) a, qreal n)
390 { auto t = QTransform(a); t *= n; return t; }+/
391 /+pragma(inline, true) QTransform operator /(ref const(QTransform) a, qreal n)
392 { auto t = QTransform(a); t /= n; return t; }+/
393 /+pragma(inline, true) QTransform operator +(ref const(QTransform) a, qreal n)
394 { auto t = QTransform(a); t += n; return t; }+/
395 /+pragma(inline, true) QTransform operator -(ref const(QTransform) a, qreal n)
396 { auto t = QTransform(a); t -= n; return t; }+/
397