1 /*
2  * DQt - D bindings for the Qt Toolkit
3  *
4  * GNU Lesser General Public License Usage
5  * This file may be used under the terms of the GNU Lesser
6  * General Public License version 3 as published by the Free Software
7  * Foundation and appearing in the file LICENSE.LGPL3 included in the
8  * packaging of this file. Please review the following information to
9  * ensure the GNU Lesser General Public License version 3 requirements
10  * will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
11  */
12 module qt.gui.region;
13 extern(C++):
14 
15 import qt.config;
16 import qt.core.namespace;
17 import qt.core.point;
18 import qt.core.rect;
19 import qt.core.refcount;
20 import qt.core.typeinfo;
21 import qt.core.variant;
22 import qt.gui.bitmap;
23 import qt.gui.polygon;
24 import qt.helpers;
25 version(Cygwin){}else
26 version(Windows)
27     import qt.gui.windowdefs_win;
28 version(QT_NO_DATASTREAM){}else
29 {
30     import qt.core.bytearray;
31     import qt.core.datastream;
32 }
33 
34 /+ #ifndef QT_NO_DATASTREAM
35 #endif +/
36 
37 
38 
39 
40 struct QRegionPrivate;
41 
42 
43 /// Binding for C++ class [QRegion](https://doc.qt.io/qt-6/qregion.html).
44 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_GUI_EXPORT +/ QRegion
45 {
46 public:
47     enum RegionType { Rectangle, Ellipse }
48 
49     version(Windows)
50     {
51         @disable this();
52         pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this))))
53         ref typeof(this) rawConstructor();
54         static typeof(this) create()
55         {
56             typeof(this) r = typeof(this).init;
57             r.rawConstructor();
58             return r;
59         }
60     }
61     else
62     {
63         static typeof(this) create()
64         {
65             return typeof(this).init;
66         }
67     }
68 
69     this(int x, int y, int w, int h, RegionType t = RegionType.Rectangle);
70     this(ref const(QRect) r, RegionType t = RegionType.Rectangle);
71     this(ref const(QPolygon) pa, /+ Qt:: +/qt.core.namespace.FillRule fillRule = /+ Qt:: +/qt.core.namespace.FillRule.OddEvenFill);
72     @disable this(this);
73     this(ref const(QRegion) region);
74     /+ QRegion(QRegion &&other) noexcept
75         : d(qExchange(other.d, const_cast<QRegionData*>(&shared_empty))) {} +/
76     this(ref const(QBitmap) bitmap);
77     ~this();
78     /+ref QRegion operator =(ref const(QRegion) );+/
79     /+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QRegion) +//+ ; +/
80     /+ inline void swap(QRegion &other) noexcept { qSwap(d, other.d); } +/
81     bool isEmpty() const;
82     bool isNull() const;
83 
84     alias const_iterator = const(QRect)*;
85     /+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator; +/
86 
87     const_iterator begin()  const/+ noexcept+/;
88     const_iterator cbegin() const/+ noexcept+/ { return begin(); }
89     const_iterator end()    const/+ noexcept+/;
90     const_iterator cend()   const/+ noexcept+/ { return end(); }
91     /+ const_reverse_iterator rbegin()  const noexcept { return const_reverse_iterator(end()); } +/
92     /+ const_reverse_iterator crbegin() const noexcept { return rbegin(); } +/
93     /+ const_reverse_iterator rend()    const noexcept { return const_reverse_iterator(begin()); } +/
94     /+ const_reverse_iterator crend()   const noexcept { return rend(); } +/
95 
96     bool contains(ref const(QPoint) p) const;
97     bool contains(ref const(QRect) r) const;
98 
99     void translate(int dx, int dy);
100     pragma(inline, true) void translate(ref const(QPoint) p) { translate(p.x(), p.y()); }
101     /+ [[nodiscard]] +/ QRegion translated(int dx, int dy) const;
102     /+ [[nodiscard]] +/ pragma(inline, true) QRegion translated(ref const(QPoint) p) const { return translated(p.x(), p.y()); }
103 
104     /+ [[nodiscard]] +/ QRegion united(ref const(QRegion) r) const;
105     /+ [[nodiscard]] +/ QRegion united(ref const(QRect) r) const;
106     /+ [[nodiscard]] +/ QRegion intersected(ref const(QRegion) r) const;
107     /+ [[nodiscard]] +/ QRegion intersected(ref const(QRect) r) const;
108     /+ [[nodiscard]] +/ QRegion subtracted(ref const(QRegion) r) const;
109     /+ [[nodiscard]] +/ QRegion xored(ref const(QRegion) r) const;
110 
111     bool intersects(ref const(QRegion) r) const;
112     bool intersects(ref const(QRect) r) const;
113 
114     QRect boundingRect() const/+ noexcept+/;
115     void setRects(const(QRect)* rect, int num);
116     int rectCount() const/+ noexcept+/;
117 
118     QRegion opBinary(string op)(ref const(QRegion) r) const if(op == "|");
119     QRegion opBinary(string op)(ref const(QRegion) r) const if(op == "+");
120     QRegion opBinary(string op)(ref const(QRect) r) const if(op == "+");
121     QRegion opBinary(string op)(ref const(QRegion) r) const if(op == "&");
122     QRegion opBinary(string op)(ref const(QRect) r) const if(op == "&");
123     QRegion opBinary(string op)(ref const(QRegion) r) const if(op == "-");
124     /+QRegion operator ^(ref const(QRegion) r) const;+/
125 
126     ref QRegion opOpAssign(string op)(ref const(QRegion) r) if(op == "|");
127     ref QRegion opOpAssign(string op)(ref const(QRegion) r) if(op == "+");
128     ref QRegion opOpAssign(string op)(ref const(QRect) r) if(op == "+");
129     ref QRegion opOpAssign(string op)(ref const(QRegion) r) if(op == "&");
130     ref QRegion opOpAssign(string op)(ref const(QRect) r) if(op == "&");
131     ref QRegion opOpAssign(string op)(ref const(QRegion) r) if(op == "-");
132     /+ref QRegion operator ^=(ref const(QRegion) r);+/
133 
134     /+bool operator ==(ref const(QRegion) r) const;+/
135     /+pragma(inline, true) bool operator !=(ref const(QRegion) r) const { return !(operator==(r)); }+/
136     /+auto opCast(T : QVariant)() const;+/
137 
138     // Platform specific conversion functions
139 /+ #if defined(Q_OS_WIN) || defined(Q_QDOC) +/
140     static if((versionIsSet!("Windows") && !versionIsSet!("Cygwin")))
141     {
142         HRGN toHRGN() const;
143         static QRegion fromHRGN(HRGN hrgn);
144     }
145 /+ #endif
146 
147 #ifndef QT_NO_DATASTREAM +/
148     version(QT_NO_DATASTREAM){}else
149     {
150         /+ friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &); +/
151         /+ friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &); +/
152     }
153 /+ #endif +/
154 private:
155     /+ QRegion copy() const; +/   // helper of detach.
156     void detach();
157 /+ Q_GUI_EXPORT
158     friend bool qt_region_strictContains(const QRegion &region,
159                                          const QRect &rect); +/
160     /+ friend struct QRegionPrivate; +/
161 
162     version(QT_NO_DATASTREAM){}else
163     {
164         void exec(ref const(QByteArray) ba, int ver = 0, QDataStream.ByteOrder byteOrder = QDataStream.ByteOrder.BigEndian);
165     }
166     // Workaround for https://issues.dlang.org/show_bug.cgi?id=20701
167     extern(C++, struct) struct QRegionData {
168         /+ QtPrivate:: +/qt.core.refcount.RefCount ref_;
169         QRegionPrivate* qt_rgn;
170     }
171     version(Windows)
172         QRegionData* d;
173     else
174     {
175         union
176         {
177             const(QRegionData)* d2 = &shared_empty;
178             QRegionData* d;
179         }
180     }
181     mixin(mangleWindows("?shared_empty@QRegion@@0UQRegionData@1@B", exportOnWindows ~ q{
182     extern static __gshared const(QRegionData) shared_empty;
183     }));
184     static void cleanUp(QRegionData* x);
185     mixin(CREATE_CONVENIENCE_WRAPPERS);
186 }
187 /+ Q_DECLARE_SHARED(QRegion)
188 
189 /*****************************************************************************
190   QRegion stream functions
191  *****************************************************************************/
192 
193 #ifndef QT_NO_DATASTREAM
194 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QRegion &);
195 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QRegion &);
196 #endif
197 
198 #ifndef QT_NO_DEBUG_STREAM
199 Q_GUI_EXPORT QDebug operator<<(QDebug, const QRegion &);
200 #endif +/
201