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.paintengine;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.flags;
19 import qt.core.global;
20 import qt.core.line;
21 import qt.core.namespace;
22 import qt.core.point;
23 import qt.core.rect;
24 import qt.core.scopedpointer;
25 import qt.core.string;
26 import qt.core.typeinfo;
27 import qt.gui.brush;
28 import qt.gui.font;
29 import qt.gui.image;
30 import qt.gui.matrix;
31 import qt.gui.paintdevice;
32 import qt.gui.painter;
33 import qt.gui.painterpath;
34 import qt.gui.pen;
35 import qt.gui.pixmap;
36 import qt.gui.region;
37 import qt.gui.transform;
38 import qt.helpers;
39 
40 /+ class QFontEngine;
41 class QLineF;
42 class QPaintDevice; +/
43 extern(C++, class) struct QPaintEnginePrivate;
44 /+ class QPainterPath;
45 class QPointF;
46 class QPolygonF;
47 class QRectF; +/
48 struct QGlyphLayout;
49 extern(C++, class) struct QTextItemInt;
50 /+ class QPaintEngineState; +/
51 
52 @Q_PRIMITIVE_TYPE extern(C++, class) struct /+ Q_GUI_EXPORT +/ QTextItem {
53 public:
54     enum RenderFlag {
55         RightToLeft = 0x1,
56         Overline = 0x10,
57         Underline = 0x20,
58         StrikeOut = 0x40,
59 
60         Dummy = 0xffffffff
61     }
62     /+ Q_DECLARE_FLAGS(RenderFlags, RenderFlag) +/
63 alias RenderFlags = QFlags!(RenderFlag);    qreal descent() const;
64     qreal ascent() const;
65     qreal width() const;
66 
67     RenderFlags renderFlags() const;
68     QString text() const;
69     QFont font() const;
70 }
71 /+ Q_DECLARE_TYPEINFO(QTextItem, Q_PRIMITIVE_TYPE); +/
72 
73 
74 class /+ Q_GUI_EXPORT +/ QPaintEngine
75 {
76 private:
77     /+ Q_DECLARE_PRIVATE(QPaintEngine) +/
78 public:
79     enum PaintEngineFeature {
80         PrimitiveTransform          = 0x00000001, // Can transform primitives brushes
81         PatternTransform            = 0x00000002, // Can transform pattern brushes
82         PixmapTransform             = 0x00000004, // Can transform pixmaps
83         PatternBrush                = 0x00000008, // Can fill with pixmaps and standard patterns
84         LinearGradientFill          = 0x00000010, // Can fill gradient areas
85         RadialGradientFill          = 0x00000020, // Can render radial gradients
86         ConicalGradientFill         = 0x00000040, // Can render conical gradients
87         AlphaBlend                  = 0x00000080, // Can do source over alpha blend
88         PorterDuff                  = 0x00000100, // Can do general porter duff compositions
89         PainterPaths                = 0x00000200, // Can fill, outline and clip paths
90         Antialiasing                = 0x00000400, // Can antialias lines
91         BrushStroke                 = 0x00000800, // Can render brush based pens
92         ConstantOpacity             = 0x00001000, // Can render at constant opacity
93         MaskedBrush                 = 0x00002000, // Can fill with textures that has an alpha channel or mask
94         PerspectiveTransform        = 0x00004000, // Can do perspective transformations
95         BlendModes                  = 0x00008000, // Can do extended Porter&Duff composition
96         ObjectBoundingModeGradients = 0x00010000, // Can do object bounding mode gradients
97         RasterOpModes               = 0x00020000, // Can do logical raster operations
98         PaintOutsidePaintEvent      = 0x20000000, // Engine is capable of painting outside paint events
99         /*                          0x10000000, // Used for emulating
100                                     QGradient::StretchToDevice,
101                                     defined in qpainter.cpp
102 
103                                     0x40000000, // Used internally for emulating opaque backgrounds
104         */
105 
106         AllFeatures               = 0xffffffff  // For convenience
107     }
108     /+ Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature) +/
109 alias PaintEngineFeatures = QFlags!(PaintEngineFeature);
110     enum DirtyFlag {
111         DirtyPen                = 0x0001,
112         DirtyBrush              = 0x0002,
113         DirtyBrushOrigin        = 0x0004,
114         DirtyFont               = 0x0008,
115         DirtyBackground         = 0x0010,
116         DirtyBackgroundMode     = 0x0020,
117         DirtyTransform          = 0x0040,
118         DirtyClipRegion         = 0x0080,
119         DirtyClipPath           = 0x0100,
120         DirtyHints              = 0x0200,
121         DirtyCompositionMode    = 0x0400,
122         DirtyClipEnabled        = 0x0800,
123         DirtyOpacity            = 0x1000,
124 
125         AllDirty                = 0xffff
126     }
127     /+ Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag) +/
128 alias DirtyFlags = QFlags!(DirtyFlag);
129     enum PolygonDrawMode {
130         OddEvenMode,
131         WindingMode,
132         ConvexMode,
133         PolylineMode
134     }
135 
136     /+ explicit +/this(PaintEngineFeatures features=PaintEngineFeatures());
137     /+ virtual +/~this();
138 
139     final bool isActive() const { return (active) != 0; }
140     final void setActive(bool newState) { active = newState; }
141 
142     /+ virtual +/ abstract bool begin(QPaintDevice pdev);
143     /+ virtual +/ abstract bool end();
144 
145     /+ virtual +/ abstract void updateState(ref const(QPaintEngineState) state);
146 
147     /+ virtual +/ void drawRects(const(QRect)* rects, int rectCount);
148     /+ virtual +/ void drawRects(const(QRectF)* rects, int rectCount);
149 
150     /+ virtual +/ void drawLines(const(QLine)* lines, int lineCount);
151     /+ virtual +/ void drawLines(const(QLineF)* lines, int lineCount);
152 
153     /+ virtual +/ void drawEllipse(ref const(QRectF) r);
154     /+ virtual +/ void drawEllipse(ref const(QRect) r);
155 
156     /+ virtual +/ void drawPath(ref const(QPainterPath) path);
157 
158     /+ virtual +/ void drawPoints(const(QPointF)* points, int pointCount);
159     /+ virtual +/ void drawPoints(const(QPoint)* points, int pointCount);
160 
161     /+ virtual +/ void drawPolygon(const(QPointF)* points, int pointCount, PolygonDrawMode mode);
162     /+ virtual +/ void drawPolygon(const(QPoint)* points, int pointCount, PolygonDrawMode mode);
163 
164     /+ virtual +/ abstract void drawPixmap(ref const(QRectF) r, ref const(QPixmap) pm, ref const(QRectF) sr);
165     /+ virtual +/ void drawTextItem(ref const(QPointF) p, ref const(QTextItem) textItem);
166     /+ virtual +/ void drawTiledPixmap(ref const(QRectF) r, ref const(QPixmap) pixmap, ref const(QPointF) s);
167     /+ virtual +/ void drawImage(ref const(QRectF) r, ref const(QImage) pm, ref const(QRectF) sr,
168                                /+ Qt:: +/qt.core.namespace.ImageConversionFlags flags = /+ Qt:: +/qt.core.namespace.ImageConversionFlag.AutoColor);
169 
170     final void setPaintDevice(QPaintDevice device);
171     final QPaintDevice paintDevice() const;
172 
173     final void setSystemClip(ref const(QRegion) baseClip);
174     final QRegion systemClip() const;
175 
176     final void setSystemRect(ref const(QRect) rect);
177     final QRect systemRect() const;
178 
179 
180     /+ virtual +/ QPoint coordinateOffset() const;
181 
182     enum Type {
183         X11,
184         Windows,
185         QuickDraw, CoreGraphics, MacPrinter,
186         QWindowSystem,
187         PostScript,   // ### Qt 6: Remove, update documentation
188         OpenGL,
189         Picture,
190         SVG,
191         Raster,
192         Direct3D,
193         Pdf,
194         OpenVG,
195         OpenGL2,
196         PaintBuffer,
197         Blitter,
198         Direct2D,
199 
200         User = 50,    // first user type id
201         MaxUser = 100 // last user type id
202     }
203     /+ virtual +/ abstract Type type() const;
204 
205     pragma(inline, true) final void fix_neg_rect(int* x, int* y, int* w, int* h)
206     {
207         if (*w < 0) {
208             *w = -*w;
209             *x -= *w - 1;
210         }
211         if (*h < 0) {
212             *h = -*h;
213             *y -= *h - 1;
214         }
215     }
216 
217     pragma(inline, true) final bool testDirty(DirtyFlags df) {
218         (mixin(Q_ASSERT(q{QPaintEngine.state})));
219         return (state.dirtyFlags & df) != 0;
220     }
221     pragma(inline, true) final void setDirty(DirtyFlags df) {
222         (mixin(Q_ASSERT(q{QPaintEngine.state})));
223         state.dirtyFlags |= df;
224     }
225     pragma(inline, true) final void clearDirty(DirtyFlags df)
226     {
227         (mixin(Q_ASSERT(q{QPaintEngine.state})));
228         state.dirtyFlags &= ~static_cast!(uint)(df);
229     }
230 
231     //final bool hasFeature(PaintEngineFeatures feature) const { return cast(bool)(gccaps & feature); }
232 
233     final QPainter* painter() const;
234 
235     final void syncState();
236     pragma(inline, true) final bool isExtended() const { return (extended) != 0; }
237 
238 protected:
239     this(ref QPaintEnginePrivate data, PaintEngineFeatures devcaps=PaintEngineFeatures());
240 
241     QPaintEngineState* state;
242     PaintEngineFeatures gccaps;
243 
244     /+ uint active : 1; +/
245     ubyte bitfieldData_active;
246     uint active() const
247     {
248         return (bitfieldData_active >> 0) & 0x1;
249     }
250     uint active(uint value)
251     {
252         bitfieldData_active = (bitfieldData_active & ~0x1) | ((value & 0x1) << 0);
253         return value;
254     }
255     /+ uint selfDestruct : 1; +/
256     uint selfDestruct() const
257     {
258         return (bitfieldData_active >> 1) & 0x1;
259     }
260     uint selfDestruct(uint value)
261     {
262         bitfieldData_active = (bitfieldData_active & ~0x2) | ((value & 0x1) << 1);
263         return value;
264     }
265     /+ uint extended : 1; +/
266     uint extended() const
267     {
268         return (bitfieldData_active >> 2) & 0x1;
269     }
270     uint extended(uint value)
271     {
272         bitfieldData_active = (bitfieldData_active & ~0x4) | ((value & 0x1) << 2);
273         return value;
274     }
275 
276     QScopedPointer!(QPaintEnginePrivate) d_ptr;
277 
278 private:
279     final void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; }
280     final bool autoDestruct() const { return (selfDestruct) != 0; }
281     /+ Q_DISABLE_COPY(QPaintEngine) +/
282 
283     /+ friend class QPainterReplayer; +/
284     /+ friend class QFontEngineBox; +/
285     /+ friend class QFontEngineMac; +/
286     /+ friend class QFontEngineWin; +/
287     /+ friend class QMacPrintEngine; +/
288     /+ friend class QMacPrintEnginePrivate; +/
289     /+ friend class QFontEngineQPF2; +/
290     /+ friend class QPainter; +/
291     /+ friend class QPainterPrivate; +/
292     /+ friend class QWidget; +/
293     /+ friend class QWidgetPrivate; +/
294     /+ friend class QWin32PaintEngine; +/
295     /+ friend class QWin32PaintEnginePrivate; +/
296     /+ friend class QMacCGContext; +/
297     /+ friend class QPreviewPaintEngine; +/
298     /+ friend class QX11GLPlatformPixmap; +/
299 }
300 
301 
302 extern(C++, class) struct /+ Q_GUI_EXPORT +/ QPaintEngineState
303 {
304 public:
305     QPaintEngine.DirtyFlags state() const { return dirtyFlags; }
306 
307     QPen pen() const;
308     QBrush brush() const;
309     QPointF brushOrigin() const;
310     QBrush backgroundBrush() const;
311     /+ Qt:: +/qt.core.namespace.BGMode backgroundMode() const;
312     QFont font() const;
313 /+ #if QT_DEPRECATED_SINCE(5, 15) +/
314     /+ QT_DEPRECATED_X("Use transform()") +/ QMatrix matrix() const;
315 /+ #endif +/ // QT_DEPRECATED_SINCE(5, 15)
316     QTransform transform() const;
317 
318     /+ Qt:: +/qt.core.namespace.ClipOperation clipOperation() const;
319     QRegion clipRegion() const;
320     QPainterPath clipPath() const;
321     bool isClipEnabled() const;
322 
323     QPainter.RenderHints renderHints() const;
324     QPainter.CompositionMode compositionMode() const;
325     qreal opacity() const;
326 
327     QPainter* painter() const;
328 
329     bool brushNeedsResolving() const;
330     bool penNeedsResolving() const;
331 
332 protected:
333     /+ friend class QPaintEngine; +/
334     /+ friend class QRasterPaintEngine; +/
335     /+ friend class QWidget; +/
336     /+ friend class QPainter; +/
337     /+ friend class QPainterPrivate; +/
338     /+ friend class QMacPrintEnginePrivate; +/
339 
340     QPaintEngine.DirtyFlags dirtyFlags;
341 }
342 
343 //
344 // inline functions
345 //
346 /+pragma(inline, true) QFlags!(QTextItem.RenderFlags.enum_type) operator |(QTextItem.RenderFlags.enum_type f1, QTextItem.RenderFlags.enum_type f2)/+noexcept+/{return QFlags!(QTextItem.RenderFlags.enum_type)(f1)|f2;}+/
347 /+pragma(inline, true) QFlags!(QTextItem.RenderFlags.enum_type) operator |(QTextItem.RenderFlags.enum_type f1, QFlags!(QTextItem.RenderFlags.enum_type) f2)/+noexcept+/{return f2|f1;}+/
348 /+pragma(inline, true) QIncompatibleFlag operator |(QTextItem.RenderFlags.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
349 
350 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QTextItem::RenderFlags) +/
351 /+pragma(inline, true) QFlags!(QPaintEngine.PaintEngineFeatures.enum_type) operator |(QPaintEngine.PaintEngineFeatures.enum_type f1, QPaintEngine.PaintEngineFeatures.enum_type f2)/+noexcept+/{return QFlags!(QPaintEngine.PaintEngineFeatures.enum_type)(f1)|f2;}+/
352 /+pragma(inline, true) QFlags!(QPaintEngine.PaintEngineFeatures.enum_type) operator |(QPaintEngine.PaintEngineFeatures.enum_type f1, QFlags!(QPaintEngine.PaintEngineFeatures.enum_type) f2)/+noexcept+/{return f2|f1;}+/
353 /+pragma(inline, true) QIncompatibleFlag operator |(QPaintEngine.PaintEngineFeatures.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
354 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::PaintEngineFeatures) +/
355 /+pragma(inline, true) QFlags!(QPaintEngine.DirtyFlags.enum_type) operator |(QPaintEngine.DirtyFlags.enum_type f1, QPaintEngine.DirtyFlags.enum_type f2)/+noexcept+/{return QFlags!(QPaintEngine.DirtyFlags.enum_type)(f1)|f2;}+/
356 /+pragma(inline, true) QFlags!(QPaintEngine.DirtyFlags.enum_type) operator |(QPaintEngine.DirtyFlags.enum_type f1, QFlags!(QPaintEngine.DirtyFlags.enum_type) f2)/+noexcept+/{return f2|f1;}+/
357 /+pragma(inline, true) QIncompatibleFlag operator |(QPaintEngine.DirtyFlags.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
358 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::DirtyFlags) +/