| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qsgrhiinternaltextnode_p.h" |
| 5 | |
| 6 | #include <private/qquadpath_p.h> |
| 7 | #include <private/qsgcurvefillnode_p.h> |
| 8 | #include <private/qsgcurvestrokenode_p.h> |
| 9 | #include <private/qsgcurveprocessor_p.h> |
| 10 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | QSGRhiInternalTextNode::QSGRhiInternalTextNode(QSGRenderContext *renderContext) |
| 14 | : QSGInternalTextNode(renderContext) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | void QSGRhiInternalTextNode::addDecorationNode(const QRectF &rect, const QColor &color) |
| 19 | { |
| 20 | QSGCurveStrokeNode *node = new QSGCurveStrokeNode; |
| 21 | node->setColor(color); |
| 22 | node->setStrokeWidth(rect.height()); |
| 23 | |
| 24 | QQuadPath path; |
| 25 | QPointF c = rect.center(); |
| 26 | path.moveTo(to: QVector2D(rect.left(), c.y())); |
| 27 | path.lineTo(to: QVector2D(rect.right(), c.y())); |
| 28 | |
| 29 | QSGCurveProcessor::processStroke(strokePath: path, miterLimit: 2, penWidth: rect.height(), joinStyle: Qt::MiterJoin, capStyle: Qt::FlatCap, |
| 30 | addTriangle: [&node](const std::array<QVector2D, 3> &s, |
| 31 | const std::array<QVector2D, 3> &p, |
| 32 | const std::array<QVector2D, 3> &n, |
| 33 | bool isLine) { |
| 34 | Q_ASSERT(isLine); |
| 35 | node->appendTriangle(v: s, p: std::array<QVector2D, 2>{p.at(n: 0), p.at(n: 2)}, n); |
| 36 | }); |
| 37 | node->cookGeometry(); |
| 38 | appendChildNode(node); |
| 39 | } |
| 40 | |
| 41 | QT_END_NAMESPACE |
| 42 | |