From b2d7d776405c19aef5c0fe930c56f13fdf8fe415 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 23 Sep 2022 17:49:49 +0200 Subject: [PATCH] QskStrokeNode introduced ( untested so far ) --- src/nodes/QskStrokeNode.cpp | 88 +++++++++++++++++++++++++++++++++++++ src/nodes/QskStrokeNode.h | 28 ++++++++++++ src/src.pro | 2 + 3 files changed, 118 insertions(+) create mode 100644 src/nodes/QskStrokeNode.cpp create mode 100644 src/nodes/QskStrokeNode.h diff --git a/src/nodes/QskStrokeNode.cpp b/src/nodes/QskStrokeNode.cpp new file mode 100644 index 00000000..671c3c71 --- /dev/null +++ b/src/nodes/QskStrokeNode.cpp @@ -0,0 +1,88 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * This file may be used under the terms of the QSkinny License, Version 1.0 + *****************************************************************************/ + +#include "QskStrokeNode.h" +#include + +QSK_QT_PRIVATE_BEGIN +#include +#include +QSK_QT_PRIVATE_END + +class QskStrokeNodePrivate final : public QSGGeometryNodePrivate +{ + public: + QskStrokeNodePrivate() + : geometry( QSGGeometry::defaultAttributes_Point2D(), 0 ) + { + geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip ); + } + + QSGGeometry geometry; + QSGFlatColorMaterial material; +}; + +QskStrokeNode::QskStrokeNode() + : QSGGeometryNode( *new QskStrokeNodePrivate ) +{ + Q_D( QskStrokeNode ); + + setGeometry( &d->geometry ); + setMaterial( &d->material ); +} + +void QskStrokeNode::updateNode( const QPainterPath& path, const QPen& pen ) +{ + Q_D( QskStrokeNode ); + + if ( path.isEmpty() || ( pen.style() == Qt::NoPen ) || ( pen.color().alpha() == 0 ) ) + { + if ( d->geometry.vertexCount() > 0 ) + { + d->geometry.allocate( 0 ); + markDirty( QSGNode::DirtyGeometry ); + } + + return; + } + + if ( true ) // For the moment we always update the geometry. TODO ... + { + const QVectorPath& vectorPath = qtVectorPathForPath(path); + + QTriangulatingStroker stroker; + + if ( pen.style() == Qt::SolidLine ) + { + // clipRect, renderHint are ignored in QTriangulatingStroker::process + stroker.process( vectorPath, pen, {}, {} ); + } + else + { + QDashedStrokeProcessor dashStroker; + dashStroker.process( vectorPath, pen, QRectF(), {} ); // empty rect: no clipping + + const QVectorPath dashedVectorPath( dashStroker.points(), + dashStroker.elementCount(), dashStroker.elementTypes(), 0 ); + + stroker.process( dashedVectorPath, pen, {}, {} ); + } + + d->geometry.allocate( stroker.vertexCount() ); + + memcpy( d->geometry.vertexData(), stroker.vertices(), + stroker.vertexCount() * sizeof( float ) ); + + markDirty( QSGNode::DirtyGeometry ); + } + + const auto color = pen.color().toRgb(); + + if ( d->material.color() != color ) + { + d->material.setColor( color ); + markDirty( QSGNode::DirtyMaterial ); + } +} diff --git a/src/nodes/QskStrokeNode.h b/src/nodes/QskStrokeNode.h new file mode 100644 index 00000000..86984473 --- /dev/null +++ b/src/nodes/QskStrokeNode.h @@ -0,0 +1,28 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * This file may be used under the terms of the QSkinny License, Version 1.0 + *****************************************************************************/ + +#ifndef QSK_STROKE_NODE_H +#define QSK_STROKE_NODE_H + +#include "QskGlobal.h" +#include + +class QPen; +class QPainterPath; + +class QskStrokeNodePrivate; + +class QSK_EXPORT QskStrokeNode : public QSGGeometryNode +{ + public: + QskStrokeNode(); + + void updateNode( const QPainterPath&, const QPen& ); + + private: + Q_DECLARE_PRIVATE( QskStrokeNode ) +}; + +#endif diff --git a/src/src.pro b/src/src.pro index 959b2c36..d468fe27 100644 --- a/src/src.pro +++ b/src/src.pro @@ -111,6 +111,7 @@ HEADERS += \ nodes/QskScaleRenderer.h \ nodes/QskSGNode.h \ nodes/QskShadedBoxNode.h \ + nodes/QskStrokeNode.h \ nodes/QskTextNode.h \ nodes/QskTextRenderer.h \ nodes/QskTextureRenderer.h \ @@ -133,6 +134,7 @@ SOURCES += \ nodes/QskScaleRenderer.cpp \ nodes/QskSGNode.cpp \ nodes/QskShadedBoxNode.cpp \ + nodes/QskStrokeNode.cpp \ nodes/QskTextNode.cpp \ nodes/QskTextRenderer.cpp \ nodes/QskTextureRenderer.cpp \