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.matrix;
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.painterpath;
27 import qt.gui.polygon;
28 import qt.gui.region;
29 import qt.helpers;
30 
31 /+ class QPainterPath;
32 class QVariant; +/
33 
34 @Q_MOVABLE_TYPE @(QMetaType.Type.QMatrix) extern(C++, class) struct /+ Q_GUI_EXPORT +/ QMatrix // 2D transform matrix
35 {
36 public:
37     /+ explicit +/pragma(inline, true) this(/+ Qt:: +/qt.core.namespace.Initialization) {}
38     /+this();+/
39 
40     this(qreal m11, qreal m12, qreal m21, qreal m22,
41                 qreal dx, qreal dy);
42 
43 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/
44     // ### Qt 6: remove; the compiler-generated ones are fine!
45     /+ QMatrix &operator=(QMatrix &&other) noexcept // = default
46     { memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(QMatrix)); return *this; } +/
47     /+ref QMatrix operator =(ref const(QMatrix) )/+ noexcept+/;+/ // = default
48     /+ QMatrix(QMatrix &&other) noexcept // = default
49     { memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(QMatrix)); } +/
50     @disable this(this);
51     this(ref const(QMatrix) other)/+ noexcept+/; // = default
52 /+ #endif +/
53 
54     void setMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
55                        qreal dx, qreal dy);
56 
57     qreal m11() const { return _m11; }
58     qreal m12() const { return _m12; }
59     qreal m21() const { return _m21; }
60     qreal m22() const { return _m22; }
61     qreal dx() const { return _dx; }
62     qreal dy() const { return _dy; }
63 
64     void map(int x, int y, int* tx, int* ty) const;
65     void map(qreal x, qreal y, qreal* tx, qreal* ty) const;
66     QRect mapRect(ref const(QRect) ) const;
67     QRectF mapRect(ref const(QRectF) ) const;
68 
69     QPoint map(ref const(QPoint) p) const;
70     QPointF map(ref const(QPointF) p) const;
71     QLine map(ref const(QLine) l) const;
72     QLineF map(ref const(QLineF) l) const;
73     QPolygonF map(ref const(QPolygonF) a) const;
74     QPolygon map(ref const(QPolygon) a) const;
75     QRegion map(ref const(QRegion) r) const;
76     QPainterPath map(ref const(QPainterPath) p) const;
77     QPolygon mapToPolygon(ref const(QRect) r) const;
78 
79     void reset();
80     pragma(inline, true) bool isIdentity() const
81     {
82         return qFuzzyIsNull(_m11 - 1) && qFuzzyIsNull(_m22 - 1) && qFuzzyIsNull(_m12)
83                && qFuzzyIsNull(_m21) && qFuzzyIsNull(_dx) && qFuzzyIsNull(_dy);
84     }
85 
86     ref QMatrix translate(qreal dx, qreal dy);
87     ref QMatrix scale(qreal sx, qreal sy);
88     ref QMatrix shear(qreal sh, qreal sv);
89     ref QMatrix rotate(qreal a);
90 
91     bool isInvertible() const { return !qFuzzyIsNull(_m11*_m22 - _m12*_m21); }
92     qreal determinant() const { return _m11*_m22 - _m12*_m21; }
93 
94     /+ Q_REQUIRED_RESULT +/ QMatrix inverted(bool* invertible = null) const;
95 
96     /+bool operator ==(ref const(QMatrix) ) const;+/
97     /+bool operator !=(ref const(QMatrix) ) const;+/
98 
99     /+ref QMatrix operator *=(ref const(QMatrix) );+/
100     /+QMatrix operator *(ref const(QMatrix) o) const;+/
101 
102     /+auto opCast(T : QVariant)() const;+/
103 
104 package:
105     pragma(inline, true) this(bool)
106     {
107         this._m11 = 1.;
108         this._m12 = 0.;
109         this._m21 = 0.;
110         this._m22 = 1.;
111         this._dx = 0.;
112         this._dy = 0.;
113     }
114     pragma(inline, true) this(qreal am11, qreal am12, qreal am21, qreal am22, qreal adx, qreal ady, bool)
115     {
116         this._m11 = am11;
117         this._m12 = am12;
118         this._m21 = am21;
119         this._m22 = am22;
120         this._dx = adx;
121         this._dy = ady;
122     }
123     /+ friend class QTransform; +/
124     qreal _m11 = 1; qreal _m12 = 0;
125     qreal _m21 = 0; qreal _m22 = 1;
126     qreal _dx = 0; qreal _dy = 0;
127 }
128 /+ Q_DECLARE_TYPEINFO(QMatrix, Q_MOVABLE_TYPE);
129 
130 Q_GUI_EXPORT Q_DECL_CONST_FUNCTION uint qHash(const QMatrix &key, uint seed = 0) noexcept; +/
131 
132 // mathematical semantics
133 /+pragma(inline, true) QPoint operator *(ref const(QPoint) p, ref const(QMatrix) m)
134 { return m.map(p); }+/
135 /+pragma(inline, true) QPointF operator *(ref const(QPointF) p, ref const(QMatrix) m)
136 { return m.map(p); }+/
137 /+pragma(inline, true) QLineF operator *(ref const(QLineF) l, ref const(QMatrix) m)
138 { return m.map(l); }+/
139 /+pragma(inline, true) QLine operator *(ref const(QLine) l, ref const(QMatrix) m)
140 { return m.map(l); }+/
141 /+pragma(inline, true) QPolygon operator *(ref const(QPolygon) a, ref const(QMatrix) m)
142 { return m.map(a); }+/
143 /+pragma(inline, true) QPolygonF operator *(ref const(QPolygonF) a, ref const(QMatrix) m)
144 { return m.map(a); }+/
145 /+pragma(inline, true) QRegion operator *(ref const(QRegion) r, ref const(QMatrix) m)
146 { return m.map(r); }+/
147 /+/+ Q_GUI_EXPORT +/ QPainterPath operator *(ref const(QPainterPath) p, ref const(QMatrix) m);+/
148 
149 pragma(inline, true) bool qFuzzyCompare(ref const(QMatrix) m1, ref const(QMatrix) m2)
150 {
151     return qt.core.global.qFuzzyCompare(m1.m11(), m2.m11())
152         && qt.core.global.qFuzzyCompare(m1.m12(), m2.m12())
153         && qt.core.global.qFuzzyCompare(m1.m21(), m2.m21())
154         && qt.core.global.qFuzzyCompare(m1.m22(), m2.m22())
155         && qt.core.global.qFuzzyCompare(m1.dx(), m2.dx())
156         && qt.core.global.qFuzzyCompare(m1.dy(), m2.dy());
157 }
158 
159 
160 /*****************************************************************************
161  QMatrix stream functions
162  *****************************************************************************/
163 
164 /+ #ifndef QT_NO_DATASTREAM
165 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QMatrix &);
166 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QMatrix &);
167 #endif
168 
169 #ifndef QT_NO_DEBUG_STREAM
170 Q_GUI_EXPORT QDebug operator<<(QDebug, const QMatrix &);
171 #endif +/
172