QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskSGNode.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_SG_NODE_H
7#define QSK_SG_NODE_H
8
9#include "QskGlobal.h"
10#include <qsgnode.h>
11
12namespace QskSGNode
13{
14 enum Role : quint8
15 {
16 FirstReservedRole = 0xff - 10,
17
18 DebugRole = 0xff - 2,
19 BackgroundRole,
20
21 NoRole
22 };
23
24 inline QSGNode::Flags nodeRoleFlags( quint8 role )
25 {
26 return static_cast< QSGNode::Flags >( ( role + 1 ) << 8 );
27 }
28
29 inline quint8 nodeRole( QSGNode::Flags flags )
30 {
31 return static_cast< quint8 >( ( ( flags & 0x0ffff ) >> 8 ) - 1 );
32 }
33
34 inline quint8 nodeRole( const QSGNode* node )
35 {
36 return node ? nodeRole( node->flags() ) : 0xff;
37 }
38
39 inline void setNodeRole( QSGNode* node, quint8 role )
40 {
41 if ( node )
42 node->setFlags( node->flags() | nodeRoleFlags( role ) );
43 }
44
45 QSK_EXPORT QSGNode* findChildNode( QSGNode* parent, quint8 role );
46 QSK_EXPORT bool removeChildNode( QSGNode* parent, quint8 role );
47
48 // nodeRoles: sort order
49 QSK_EXPORT void replaceChildNode(
50 const QVector< quint8 >& roles, quint8 role,
51 QSGNode* parentNode, QSGNode* oldNode, QSGNode* newNode );
52
53 // without child
54 QSK_EXPORT void removeAllChildNodesAfter( QSGNode* parent, QSGNode* child );
55
56 // including child
57 QSK_EXPORT void removeAllChildNodesFrom( QSGNode* parent, QSGNode* child );
58
59 QSK_EXPORT void setParentNode( QSGNode* child, QSGNode* parent );
60
61 template< typename Node >
62 inline Node* createNode( quint8 role )
63 {
64 auto node = new Node();
65 setNodeRole( node, role );
66
67 return node;
68 }
69
70 template< typename Node >
71 inline Node* appendChildNode( QSGNode* parent, quint8 role )
72 {
73 auto node = createNode< Node >( role );
74 parent->appendChildNode( node );
75
76 return node;
77 }
78
79 template< typename Node >
80 inline Node* ensureNode( QSGNode* node )
81 {
82 if ( node == nullptr )
83 node = new Node();
84
85 return static_cast< Node* >( node );
86 }
87
88 QSK_EXPORT void resetGeometry( QSGGeometryNode* );
89}
90
91#endif