QskFillNode::Hints added

This commit is contained in:
Uwe Rathmann 2024-09-17 13:40:58 +02:00
parent f0f17b3cb5
commit 58344c0c4e
3 changed files with 77 additions and 2 deletions

View File

@ -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"

View File

@ -8,12 +8,15 @@
#include "QskGlobal.h"
#include <qsgnode.h>
#include <qcolor.h>
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

View File

@ -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