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.painterpath; 13 extern(C++): 14 15 import qt.config; 16 import qt.core.global; 17 import qt.core.list; 18 import qt.core.namespace; 19 import qt.core.point; 20 import qt.core.rect; 21 import qt.core.scopedpointer; 22 import qt.core.shareddata; 23 import qt.core.string; 24 import qt.core.typeinfo; 25 import qt.gui.font; 26 import qt.gui.pen; 27 import qt.gui.polygon; 28 import qt.gui.region; 29 import qt.gui.transform; 30 import qt.helpers; 31 32 extern(C++, class) struct QPainterPathPrivate; 33 struct QPainterPathPrivateDeleter; 34 extern(C++, class) struct QPainterPathStrokerPrivate; 35 extern(C++, class) struct QVectorPath; 36 37 /// Binding for C++ class [QPainterPath](https://doc.qt.io/qt-6/qpainterpath.html). 38 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_GUI_EXPORT +/ QPainterPath 39 { 40 public: 41 enum ElementType { 42 MoveToElement, 43 LineToElement, 44 CurveToElement, 45 CurveToDataElement 46 } 47 48 extern(C++, class) struct Element { 49 public: 50 qreal x; 51 qreal y; 52 ElementType type; 53 54 bool isMoveTo() const { return type == ElementType.MoveToElement; } 55 bool isLineTo() const { return type == ElementType.LineToElement; } 56 bool isCurveTo() const { return type == ElementType.CurveToElement; } 57 58 /+auto opCast(T : QPointF) () const { return QPointF(x, y); }+/ 59 60 /+bool operator ==(ref const(Element) e) const { return qt.core.global.qFuzzyCompare(x, e.x) 61 && qt.core.global.qFuzzyCompare(y, e.y) && type == e.type; }+/ 62 /+pragma(inline, true) bool operator !=(ref const(Element) e) const { return !operator==(e); }+/ 63 } 64 65 @disable this(); 66 pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this)))) 67 ref typeof(this) rawConstructor()/+ noexcept+/; 68 static typeof(this) create() 69 { 70 typeof(this) r = typeof(this).init; 71 r.rawConstructor(); 72 return r; 73 } 74 75 /+ explicit +/this(ref const(QPointF) startPoint); 76 @disable this(this); 77 this(ref const(QPainterPath) other); 78 /+ref QPainterPath operator =(ref const(QPainterPath) other);+/ 79 /+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPainterPath) +/ 80 ~this(); 81 82 /+ inline void swap(QPainterPath &other) noexcept { d_ptr.swap(other.d_ptr); } +/ 83 84 void clear(); 85 void reserve(int size); 86 int capacity() const; 87 88 void closeSubpath(); 89 90 void moveTo(ref const(QPointF) p); 91 pragma(inline, true) void moveTo(qreal x, qreal y) 92 { 93 auto tmp = QPointF(x, y); moveTo(tmp); 94 } 95 96 void lineTo(ref const(QPointF) p); 97 pragma(inline, true) void lineTo(qreal x, qreal y) 98 { 99 auto tmp = QPointF(x, y); lineTo(tmp); 100 } 101 102 void arcMoveTo(ref const(QRectF) rect, qreal angle); 103 pragma(inline, true) void arcMoveTo(qreal x, qreal y, qreal w, qreal h, qreal angle) 104 { 105 auto tmp = QRectF(x, y, w, h); arcMoveTo(tmp, angle); 106 } 107 108 void arcTo(ref const(QRectF) rect, qreal startAngle, qreal arcLength); 109 pragma(inline, true) void arcTo(qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength) 110 { 111 auto tmp = QRectF(x, y, w, h); arcTo(tmp, startAngle, arcLength); 112 } 113 114 void cubicTo(ref const(QPointF) ctrlPt1, ref const(QPointF) ctrlPt2, ref const(QPointF) endPt); 115 pragma(inline, true) void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, 116 qreal endPtx, qreal endPty) 117 { 118 auto tmp = QPointF(ctrlPt1x, ctrlPt1y); auto tmp__1 = QPointF(ctrlPt2x, ctrlPt2y); auto tmp__2 = QPointF(endPtx, endPty); cubicTo(tmp, tmp__1, 119 tmp__2); 120 } 121 void quadTo(ref const(QPointF) ctrlPt, ref const(QPointF) endPt); 122 pragma(inline, true) void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty) 123 { 124 auto tmp = QPointF(ctrlPtx, ctrlPty); auto tmp__1 = QPointF(endPtx, endPty); quadTo(tmp, tmp__1); 125 } 126 127 QPointF currentPosition() const; 128 129 void addRect(ref const(QRectF) rect); 130 pragma(inline, true) void addRect(qreal x, qreal y, qreal w, qreal h) 131 { 132 auto tmp = QRectF(x, y, w, h); addRect(tmp); 133 } 134 void addEllipse(ref const(QRectF) rect); 135 /+ pragma(inline, true) void addEllipse(qreal x, qreal y, qreal w, qreal h) 136 { 137 auto tmp = QRectF(x, y, w, h); addEllipse(tmp); 138 } 139 pragma(inline, true) void addEllipse(ref const(QPointF) center, qreal rx, qreal ry) 140 { 141 auto tmp = QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry); addEllipse(tmp); 142 }+/ 143 void addPolygon(ref const(QPolygonF) polygon); 144 void addText(ref const(QPointF) point, ref const(QFont) f, ref const(QString) text); 145 pragma(inline, true) void addText(qreal x, qreal y, ref const(QFont) f, ref const(QString) text) 146 { 147 auto tmp = QPointF(x, y); addText(tmp, f, text); 148 } 149 void addPath(ref const(QPainterPath) path); 150 void addRegion(ref const(QRegion) region); 151 152 void addRoundedRect(ref const(QRectF) rect, qreal xRadius, qreal yRadius, 153 /+ Qt:: +/qt.core.namespace.SizeMode mode = /+ Qt:: +/qt.core.namespace.SizeMode.AbsoluteSize); 154 pragma(inline, true) void addRoundedRect(qreal x, qreal y, qreal w, qreal h, 155 qreal xRadius, qreal yRadius, 156 /+ Qt:: +/qt.core.namespace.SizeMode mode = /+ Qt:: +/qt.core.namespace.SizeMode.AbsoluteSize) 157 { 158 auto tmp = QRectF(x, y, w, h); addRoundedRect(tmp, xRadius, yRadius, mode); 159 } 160 161 void connectPath(ref const(QPainterPath) path); 162 163 bool contains(ref const(QPointF) pt) const; 164 bool contains(ref const(QRectF) rect) const; 165 bool intersects(ref const(QRectF) rect) const; 166 167 void translate(qreal dx, qreal dy); 168 pragma(inline, true) void translate(ref const(QPointF) offset) 169 { translate(offset.x(), offset.y()); } 170 171 /+ [[nodiscard]] +/ QPainterPath translated(qreal dx, qreal dy) const; 172 /+ [[nodiscard]] +/ pragma(inline, true) QPainterPath translated(ref const(QPointF) offset) const 173 { return translated(offset.x(), offset.y()); } 174 175 QRectF boundingRect() const; 176 QRectF controlPointRect() const; 177 178 /+ Qt:: +/qt.core.namespace.FillRule fillRule() const; 179 void setFillRule(/+ Qt:: +/qt.core.namespace.FillRule fillRule); 180 181 bool isEmpty() const; 182 183 /+ [[nodiscard]] +/ QPainterPath toReversed() const; 184 185 QList!(QPolygonF) toSubpathPolygons(ref const(QTransform) matrix = globalInitVar!QTransform) const; 186 QList!(QPolygonF) toFillPolygons(ref const(QTransform) matrix = globalInitVar!QTransform) const; 187 QPolygonF toFillPolygon(ref const(QTransform) matrix = globalInitVar!QTransform) const; 188 189 int elementCount() const; 190 Element elementAt(int i) const; 191 void setElementPositionAt(int i, qreal x, qreal y); 192 193 qreal length() const; 194 qreal percentAtLength(qreal t) const; 195 QPointF pointAtPercent(qreal t) const; 196 qreal angleAtPercent(qreal t) const; 197 qreal slopeAtPercent(qreal t) const; 198 199 bool intersects(ref const(QPainterPath) p) const; 200 bool contains(ref const(QPainterPath) p) const; 201 /+ [[nodiscard]] +/ QPainterPath united(ref const(QPainterPath) r) const; 202 /+ [[nodiscard]] +/ QPainterPath intersected(ref const(QPainterPath) r) const; 203 /+ [[nodiscard]] +/ QPainterPath subtracted(ref const(QPainterPath) r) const; 204 205 /+ [[nodiscard]] +/ QPainterPath simplified() const; 206 207 /+bool operator ==(ref const(QPainterPath) other) const;+/ 208 /+bool operator !=(ref const(QPainterPath) other) const;+/ 209 210 QPainterPath opBinary(string op)(ref const(QPainterPath) other) const if(op == "&"); 211 QPainterPath opBinary(string op)(ref const(QPainterPath) other) const if(op == "|"); 212 QPainterPath opBinary(string op)(ref const(QPainterPath) other) const if(op == "+"); 213 QPainterPath opBinary(string op)(ref const(QPainterPath) other) const if(op == "-"); 214 ref QPainterPath opOpAssign(string op)(ref const(QPainterPath) other) if(op == "&"); 215 ref QPainterPath opOpAssign(string op)(ref const(QPainterPath) other) if(op == "|"); 216 ref QPainterPath opOpAssign(string op)(ref const(QPainterPath) other) if(op == "+"); 217 ref QPainterPath opOpAssign(string op)(ref const(QPainterPath) other) if(op == "-"); 218 219 private: 220 QExplicitlySharedDataPointer!(QPainterPathPrivate) d_ptr; 221 222 // pragma(inline, true) void ensureData() { if (!d_ptr) ensureData_helper(); } 223 void ensureData_helper(); 224 void detach(); 225 void setDirty(bool); 226 void computeBoundingRect() const; 227 void computeControlPointRect() const; 228 229 /+ QPainterPathPrivate *d_func() const { return d_ptr.data(); } +/ 230 231 /+ friend class QPainterPathStroker; +/ 232 /+ friend class QPainterPathStrokerPrivate; +/ 233 /+ friend class QTransform; +/ 234 /+ friend class QVectorPath; +/ 235 /+ friend Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &); +/ 236 237 version(QT_NO_DATASTREAM){}else 238 { 239 /+ friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); +/ 240 /+ friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); +/ 241 } 242 mixin(CREATE_CONVENIENCE_WRAPPERS); 243 } 244 245 /+ Q_DECLARE_SHARED(QPainterPath) 246 Q_DECLARE_TYPEINFO(QPainterPath::Element, Q_PRIMITIVE_TYPE); 247 248 #ifndef QT_NO_DATASTREAM 249 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); 250 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); 251 #endif +/ 252 253 /// Binding for C++ class [QPainterPathStroker](https://doc.qt.io/qt-6/qpainterpathstroker.html). 254 extern(C++, class) struct /+ Q_GUI_EXPORT +/ QPainterPathStroker 255 { 256 private: 257 /+ Q_DECLARE_PRIVATE(QPainterPathStroker) +/ 258 public: 259 @disable this(); 260 pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this)))) 261 ref typeof(this) rawConstructor(); 262 static typeof(this) create() 263 { 264 typeof(this) r = typeof(this).init; 265 r.rawConstructor(); 266 return r; 267 } 268 269 /+ explicit +/this(ref const(QPen) pen); 270 ~this(); 271 272 void setWidth(qreal width); 273 qreal width() const; 274 275 void setCapStyle(/+ Qt:: +/qt.core.namespace.PenCapStyle style); 276 /+ Qt:: +/qt.core.namespace.PenCapStyle capStyle() const; 277 278 void setJoinStyle(/+ Qt:: +/qt.core.namespace.PenJoinStyle style); 279 /+ Qt:: +/qt.core.namespace.PenJoinStyle joinStyle() const; 280 281 void setMiterLimit(qreal length); 282 qreal miterLimit() const; 283 284 void setCurveThreshold(qreal threshold); 285 qreal curveThreshold() const; 286 287 void setDashPattern(/+ Qt:: +/qt.core.namespace.PenStyle); 288 void setDashPattern(ref const(QList!(qreal)) dashPattern); 289 QList!(qreal) dashPattern() const; 290 291 void setDashOffset(qreal offset); 292 qreal dashOffset() const; 293 294 QPainterPath createStroke(ref const(QPainterPath) path) const; 295 296 private: 297 /+ Q_DISABLE_COPY(QPainterPathStroker) +/ 298 @disable this(this); 299 /+this(ref const(QPainterPathStroker));+//+ref QPainterPathStroker operator =(ref const(QPainterPathStroker));+/ 300 /+ friend class QX11PaintEngine; +/ 301 302 QScopedPointer!(QPainterPathStrokerPrivate) d_ptr; 303 mixin(CREATE_CONVENIENCE_WRAPPERS); 304 } 305 306 /+pragma(inline, true) QPainterPath operator *(ref const(QPainterPath) p, ref const(QTransform) m) 307 { return m.map(p); }+/ 308 309 /+ #ifndef QT_NO_DEBUG_STREAM 310 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPainterPath &); 311 #endif +/ 312