diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2016-09-24 20:32:47 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2016-09-24 20:41:40 +0200 |
commit | b4cf40e52f220f4d934468c8b99e2509ebc1a549 (patch) | |
tree | 7863cd0056265bc5c7d04d547833d1b4fbfc9f6e /vcl/inc/SceneGraphNodes.hxx | |
parent | 7ac5ccde2d7332b926df509d840f775a65d0c9dd (diff) |
scenegraph: shared_ptr, findByName, SceneGraphFactoryfeature/sgexperiment
The change includes:
* Use shared_ptr for the child nodes.
* Every node can have a name and we can search for the node with
findByName.
* SceneGraphFactory class for easier initial construction of the
scene graph.
* RootNode has been removed as we can just use a simple empty Node
with type ROOT.
Change-Id: I7bee98cff6b46abb5c6baef25fc6f9bc084d4073
Diffstat (limited to 'vcl/inc/SceneGraphNodes.hxx')
-rw-r--r-- | vcl/inc/SceneGraphNodes.hxx | 139 |
1 files changed, 118 insertions, 21 deletions
diff --git a/vcl/inc/SceneGraphNodes.hxx b/vcl/inc/SceneGraphNodes.hxx index 70e09218d836..8c08a108b4a1 100644 --- a/vcl/inc/SceneGraphNodes.hxx +++ b/vcl/inc/SceneGraphNodes.hxx @@ -15,6 +15,7 @@ #include <glm/glm.hpp> #include <basegfx/range/b2drange.hxx> +#include <o3tl/make_unique.hxx> namespace vcl { @@ -25,7 +26,7 @@ class VCL_DLLPUBLIC ClippingNode : public Node { public: ClippingNode() - : Node("ClippingNode", NodeType::CLIPPING) + : Node(NodeType::CLIPPING) {} basegfx::B2DRange maClipBox; @@ -37,7 +38,7 @@ public: glm::mat4 maMatrix; TransformNode(glm::mat4 aMatrix) - : Node("TransformNode", NodeType::TRANSFORM) + : Node(NodeType::TRANSFORM) , maMatrix(aMatrix) {} }; @@ -53,45 +54,89 @@ class VCL_DLLPUBLIC GeometryNode : public Node { public: GeometryNodeType meGeometryType; + bool mbNormalized; GeometryNode(GeometryNodeType eGeometryType) - : Node("GeometryNode", NodeType::GEOMETRY) + : Node(NodeType::GEOMETRY) , meGeometryType(eGeometryType) + , mbNormalized(false) + {} + + +protected: + void markAsModified() {} }; -class VCL_DLLPUBLIC RectangleNode : public GeometryNode +struct GeometryAttributes { -public: - basegfx::B2DRange maRectangle; SalColor maLineColor; SalColor maFillColor; - bool mbNormalized; - RectangleNode(basegfx::B2DRange aRectangle, SalColor aLineColor = SALCOLOR_NONE, SalColor aFillColor = SALCOLOR_NONE) - : GeometryNode(GeometryNodeType::RECTANGLE) - , maRectangle(aRectangle) - , maLineColor(aLineColor) + GeometryAttributes(SalColor aLineColor = SALCOLOR_NONE, SalColor aFillColor = SALCOLOR_NONE) + : maLineColor(aLineColor) , maFillColor(aFillColor) - , mbNormalized(false) {} }; -class VCL_DLLPUBLIC PolyPolygonNode : public GeometryNode +class VCL_DLLPUBLIC RectangleNode : public GeometryNode { +private: + basegfx::B2DRange maRectangle; + GeometryAttributes maAttributes; + public: + RectangleNode(const basegfx::B2DRange& rRectangle, const GeometryAttributes& rAttributes) + : GeometryNode(GeometryNodeType::RECTANGLE) + , maRectangle(rRectangle) + , maAttributes(rAttributes) + {} + + const GeometryAttributes& getAttributes() + { + return maAttributes; + } + + const basegfx::B2DRange& getRectangle() + { + return maRectangle; + } + + void modifyAttributes(GeometryAttributes& rAttributes) + { + maAttributes = rAttributes; + markAsModified(); + } +}; + +class VCL_DLLPUBLIC PolyPolygonNode : public GeometryNode +{ +private: basegfx::B2DPolyPolygon maPolyPolygon; - SalColor maLineColor; - SalColor maFillColor; - bool mbNormalized; + GeometryAttributes maAttributes; - PolyPolygonNode(basegfx::B2DPolyPolygon aPolyPolygon, SalColor aLineColor = SALCOLOR_NONE, SalColor aFillColor = SALCOLOR_NONE) +public: + PolyPolygonNode(const basegfx::B2DPolyPolygon& rPolyPolygon, const GeometryAttributes& rAttributes) : GeometryNode(GeometryNodeType::POLYPOLYGON) - , maPolyPolygon(aPolyPolygon) - , maLineColor(aLineColor) - , maFillColor(aFillColor) - , mbNormalized(false) + , maPolyPolygon(rPolyPolygon) + , maAttributes(rAttributes) {} + + const GeometryAttributes& getAttributes() + { + return maAttributes; + } + + const basegfx::B2DPolyPolygon& getPolyPolygon() + { + return maPolyPolygon; + } + + void modifyAttributes(GeometryAttributes& rAttributes) + { + maAttributes = rAttributes; + markAsModified(); + } }; class VCL_DLLPUBLIC BitmapNode : public GeometryNode @@ -107,6 +152,58 @@ public: {} }; +class SceneGraphFactory +{ +private: + std::vector<std::shared_ptr<Node>> maNodeStack; + +public: + SceneGraphFactory(const std::shared_ptr<Node>& pRootNode) + : maNodeStack({pRootNode}) + {} + + Node& getCurrent() + { + return *maNodeStack.back().get(); + } + + void pushTransform(glm::mat4 aMatrix, const OUString& rName) + { + auto pTransformNode = std::make_shared<vcl::sg::TransformNode>(aMatrix); + pTransformNode->setName(rName); + getCurrent().mChildren.push_back(pTransformNode); + maNodeStack.push_back(pTransformNode); + } + + void pop() + { + maNodeStack.pop_back(); + } + + void addRectangle(const basegfx::B2DRange& rRange, SalColor nLineColor, SalColor nFillColor) + { + GeometryAttributes aAttributes(nLineColor, nFillColor); + getCurrent().mChildren.push_back(std::make_shared<RectangleNode>(rRange, aAttributes)); + } + + void addNormalizedRectangle(const basegfx::B2DRange& rRange, SalColor nLineColor, SalColor nFillColor) + { + addRectangle(rRange, nLineColor, nFillColor); + std::static_pointer_cast<RectangleNode>(getCurrent().mChildren.back())->mbNormalized = true; + } + + void addBitmap(Bitmap& rBitmap, const basegfx::B2DRange& rRange) + { + getCurrent().mChildren.push_back(std::make_shared<BitmapNode>(rBitmap, rRange)); + } + + void addPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon, SalColor nLineColor, SalColor nFillColor) + { + GeometryAttributes aAttributes(nLineColor, nFillColor); + getCurrent().mChildren.push_back(std::make_shared<PolyPolygonNode>(rPolyPolygon, aAttributes)); + } +}; + }} // end vcl::sg namespace #endif // INCLUDED_VCL_INC_SCENEGRAPH_HXX |