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.paintdevice;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.global;
19 import qt.core.point;
20 import qt.gui.paintengine;
21 import qt.gui.painter;
22 import qt.helpers;
23 
24 /+ class QPaintEngine; +/
25 extern(C++, class) struct QPaintDevicePrivate;
26 
27 interface QPaintDeviceInterface
28 {
29     alias PaintDeviceMetric = QPaintDevice.PaintDeviceMetric;
30 
31   //  /+ virtual +/~this();
32     /+ virtual +/ int devType() const;
33     /+ virtual +/ QPaintEngine paintEngine() const /+ = 0 +/;
34 protected:
35     /+ virtual +/ int metric(PaintDeviceMetric metric) const;
36     /+ virtual +/ void initPainter(QPainter * painter) const;
37     /+ virtual +/ QPaintDevice redirected(QPoint * offset) const;
38     /+ virtual +/ QPainter * sharedPainter() const;
39 }
40 
41 class /+ Q_GUI_EXPORT +/ QPaintDevice//: QPaintDeviceInterface                                // device for QPainter
42 {
43 public:
44     enum PaintDeviceMetric {
45         PdmWidth = 1,
46         PdmHeight,
47         PdmWidthMM,
48         PdmHeightMM,
49         PdmNumColors,
50         PdmDepth,
51         PdmDpiX,
52         PdmDpiY,
53         PdmPhysicalDpiX,
54         PdmPhysicalDpiY,
55         PdmDevicePixelRatio,
56         PdmDevicePixelRatioScaled
57     }
58 
59     /+ virtual +/~this();
60 
61     /+ virtual +/ pragma(inline, true) int devType() const
62     {
63         import qt.core.namespace;
64         return QInternal.PaintDeviceFlags.UnknownDevice;
65     }
66     pragma(inline, true) final bool paintingActive() const
67     { return painters != 0; }
68     /+ virtual +/ abstract QPaintEngine paintEngine() const;
69 
70     final int width() const { return metric(PaintDeviceMetric.PdmWidth); }
71     final int height() const { return metric(PaintDeviceMetric.PdmHeight); }
72     final int widthMM() const { return metric(PaintDeviceMetric.PdmWidthMM); }
73     final int heightMM() const { return metric(PaintDeviceMetric.PdmHeightMM); }
74     final int logicalDpiX() const { return metric(PaintDeviceMetric.PdmDpiX); }
75     final int logicalDpiY() const { return metric(PaintDeviceMetric.PdmDpiY); }
76     final int physicalDpiX() const { return metric(PaintDeviceMetric.PdmPhysicalDpiX); }
77     final int physicalDpiY() const { return metric(PaintDeviceMetric.PdmPhysicalDpiY); }
78     final int devicePixelRatio() const { return metric(PaintDeviceMetric.PdmDevicePixelRatio); }
79     final qreal devicePixelRatioF()  const { return metric(PaintDeviceMetric.PdmDevicePixelRatioScaled) / devicePixelRatioFScale(); }
80     final int colorCount() const { return metric(PaintDeviceMetric.PdmNumColors); }
81     final int depth() const { return metric(PaintDeviceMetric.PdmDepth); }
82 
83     pragma(inline, true) static qreal devicePixelRatioFScale() { return 0x10000; }
84 protected:
85     this()/+ noexcept+/;
86     /+ virtual +/ int metric(PaintDeviceMetric metric) const;
87     package /+ virtual +/ void initPainter(QPainter* painter) const;
88     package /+ virtual +/ QPaintDevice redirected(QPoint* offset) const;
89     package /+ virtual +/ QPainter* sharedPainter() const;
90 
91     ushort        painters;                        // refcount
92 private:
93     /+ Q_DISABLE_COPY(QPaintDevice) +/
94 
95     QPaintDevicePrivate* reserved;
96 
97     /+ friend class QPainter; +/
98     /+ friend class QPainterPrivate; +/
99     /+ friend class QFontEngineMac; +/
100     /+ friend class QX11PaintEngine; +/
101     /+ friend Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, PaintDeviceMetric metric); +/
102 }
103 
104 /*****************************************************************************
105   Inline functions
106  *****************************************************************************/
107 
108 static assert(__traits(classInstanceSize, QPaintDevice) == (void*).sizeof * 3);
109 struct QPaintDeviceFakeInheritance
110 {
111     static assert(__traits(classInstanceSize, QPaintDevice) % (void*).sizeof == 0);
112     void*[__traits(classInstanceSize, QPaintDevice) / (void*).sizeof - 1] data;
113 }