diff --git a/src/nodes/QskFillNode.cpp b/src/nodes/QskFillNode.cpp index bdb6ddc5..08930df3 100644 --- a/src/nodes/QskFillNode.cpp +++ b/src/nodes/QskFillNode.cpp @@ -115,7 +115,7 @@ void QskFillNode::setColoring( Coloring coloring ) QskFillNode::Coloring QskFillNode::coloring() const { - return d_func()->coloring; + return static_cast< QskFillNode::Coloring >( d_func()->coloring ); } void QskFillNode::setColoring( const QColor& color ) @@ -147,7 +147,34 @@ void QskFillNode::setColoring( const QRectF& rect, const QskGradient& gradient ) } } +void QskFillNode::setHint( Hint hint, bool on ) +{ + Q_D( QskFillNode ); + + if ( on ) + d->hints |= hint; + else + d->hints &= ~hint; +} + +void QskFillNode::setHints( Hints hints ) +{ + d_func()->hints = hints; +} + +QskFillNode::Hints QskFillNode::hints() const +{ + return static_cast< QskFillNode::Hints >( d_func()->hints ); +} + +bool QskFillNode::hasHint( Hint hint ) const +{ + return d_func()->hints & hint; +} + bool QskFillNode::isGeometryColored() const { return d_func()->geometry.attributeCount() != 1; } + +#include "moc_QskFillNode.cpp" diff --git a/src/nodes/QskFillNode.h b/src/nodes/QskFillNode.h index a2d7abac..2630bb0b 100644 --- a/src/nodes/QskFillNode.h +++ b/src/nodes/QskFillNode.h @@ -8,12 +8,15 @@ #include "QskGlobal.h" #include +#include class QskFillNodePrivate; class QskGradient; class QSK_EXPORT QskFillNode : public QSGGeometryNode { + Q_GADGET + using Inherited = QSGGeometryNode; public: @@ -27,6 +30,28 @@ class QSK_EXPORT QskFillNode : public QSGGeometryNode Conic }; + enum Hint + { + /* + Colors might be defined in the material ( QskGradientMaterial, + QSGFlatColorMaterial ) or attached to each point ( QSGVertexColorMaterial ). + + The main advantage of using colored points is, that the material becomes + independent of the coloring and the scene graph is able to batch the nodes + ( https://doc.qt.io/qt-6/qtquick-visualcanvas-scenegraph.html ). + + However adding the color information for each point increases the memory + footprint. + + The default setting is to use colored points where possible. Note, that + this is what is also done in the Qt/Quick code. + */ + PreferColoredGeometry = 1 + }; + + Q_ENUM( Hint ) + Q_DECLARE_FLAGS( Hints, Hint ) + QskFillNode(); ~QskFillNode() override; @@ -35,11 +60,20 @@ class QSK_EXPORT QskFillNode : public QSGGeometryNode void setColoring( Coloring ); Coloring coloring() const; + void setColoring( QRgb ); void setColoring( const QColor& ); + void setColoring( Qt::GlobalColor ); + void setColoring( const QRectF&, const QskGradient& ); bool isGeometryColored() const; + void setHints( Hints ); + Hints hints() const; + + void setHint( Hint, bool on = true ); + bool hasHint( Hint ) const; + protected: QskFillNode( QskFillNodePrivate& ); @@ -47,4 +81,14 @@ class QSK_EXPORT QskFillNode : public QSGGeometryNode Q_DECLARE_PRIVATE( QskFillNode ) }; +inline void QskFillNode::setColoring( QRgb rgb ) +{ + setColoring( QColor::fromRgba( rgb ) ); +} + +inline void QskFillNode::setColoring( Qt::GlobalColor color ) +{ + setColoring( QColor( color ) ); +} + #endif diff --git a/src/nodes/QskFillNodePrivate.h b/src/nodes/QskFillNodePrivate.h index 2da5784b..93b48a35 100644 --- a/src/nodes/QskFillNodePrivate.h +++ b/src/nodes/QskFillNodePrivate.h @@ -19,6 +19,8 @@ class QskFillNodePrivate : public QSGGeometryNodePrivate public: inline QskFillNodePrivate() : geometry( QSGGeometry::defaultAttributes_ColoredPoint2D(), 0 ) + , coloring( QskFillNode::Polychrome ) + , hints( QskFillNode::PreferColoredGeometry ) { } @@ -26,7 +28,9 @@ class QskFillNodePrivate : public QSGGeometryNodePrivate friend class QskFillNode; QSGGeometry geometry; - QskFillNode::Coloring coloring = QskFillNode::Polychrome; + + uint coloring : 5; + uint hints : 3; }; #endif