summaryrefslogtreecommitdiff
path: root/vcl/inc
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2016-09-24 20:32:47 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2016-09-24 20:41:40 +0200
commitb4cf40e52f220f4d934468c8b99e2509ebc1a549 (patch)
tree7863cd0056265bc5c7d04d547833d1b4fbfc9f6e /vcl/inc
parent7ac5ccde2d7332b926df509d840f775a65d0c9dd (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')
-rw-r--r--vcl/inc/SceneGraphNodes.hxx139
-rw-r--r--vcl/inc/opengl/SceneGraphRenderer.hxx4
-rw-r--r--vcl/inc/openglgdiimpl.hxx2
-rw-r--r--vcl/inc/salgdi.hxx4
-rw-r--r--vcl/inc/salgdiimpl.hxx2
-rw-r--r--vcl/inc/unx/salgdi.h2
6 files changed, 125 insertions, 28 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
diff --git a/vcl/inc/opengl/SceneGraphRenderer.hxx b/vcl/inc/opengl/SceneGraphRenderer.hxx
index 5980e6f240f9..1257a7ca1bd9 100644
--- a/vcl/inc/opengl/SceneGraphRenderer.hxx
+++ b/vcl/inc/opengl/SceneGraphRenderer.hxx
@@ -25,7 +25,7 @@
class SceneGraphRenderer
{
private:
- vcl::sg::RootNode& mrRootNode;
+ vcl::sg::Node& mrRootNode;
float mfWidth;
float mfHeight;
RenderList& mrRenderList;
@@ -42,7 +42,7 @@ private:
void runChildren(vcl::sg::Node& rNode);
public:
- SceneGraphRenderer(vcl::sg::RootNode& rRootNode, RenderList& rRenderList);
+ SceneGraphRenderer(vcl::sg::Node& rRootNode, RenderList& rRenderList);
bool render(float fWidth, float fHeight);
};
diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index 6f69711b6bc8..f6cb76eba87e 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -371,7 +371,7 @@ public:
virtual bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) override;
- virtual bool renderSceneGraph(vcl::sg::RootNode& rRootNode);
+ virtual bool renderSceneGraph(vcl::sg::Node& rRootNode);
/// queue an idle flush of contents of the back-buffer to the screen
void flush();
diff --git a/vcl/inc/salgdi.hxx b/vcl/inc/salgdi.hxx
index 7fef805a5abc..d8d0cf05056f 100644
--- a/vcl/inc/salgdi.hxx
+++ b/vcl/inc/salgdi.hxx
@@ -425,7 +425,7 @@ public:
sal_uInt8 nTransparency,
const OutputDevice *pOutDev );
- bool RenderSceneGraph(vcl::sg::RootNode& rRootNode)
+ bool RenderSceneGraph(vcl::sg::Node& rRootNode)
{
return renderSceneGraph(rRootNode);
}
@@ -616,7 +616,7 @@ protected:
long nWidth, long nHeight,
sal_uInt8 nTransparency ) = 0;
- virtual bool renderSceneGraph(vcl::sg::RootNode& /*rRootNode*/)
+ virtual bool renderSceneGraph(vcl::sg::Node& /*rRootNode*/)
{
return false;
}
diff --git a/vcl/inc/salgdiimpl.hxx b/vcl/inc/salgdiimpl.hxx
index 27dbebf43c38..f4d4c6d21e77 100644
--- a/vcl/inc/salgdiimpl.hxx
+++ b/vcl/inc/salgdiimpl.hxx
@@ -196,7 +196,7 @@ public:
virtual bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) = 0;
- virtual bool renderSceneGraph(vcl::sg::RootNode& /*rRootNode*/)
+ virtual bool renderSceneGraph(vcl::sg::Node& /*rRootNode*/)
{
return false;
}
diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h
index 35df48a9871e..59adc31577f5 100644
--- a/vcl/inc/unx/salgdi.h
+++ b/vcl/inc/unx/salgdi.h
@@ -259,7 +259,7 @@ public:
long nX, long nY, long nWidth,
long nHeight, sal_uInt8 nTransparency ) override;
- virtual bool renderSceneGraph(vcl::sg::RootNode& rRootNode) override;
+ virtual bool renderSceneGraph(vcl::sg::Node& rRootNode) override;
virtual SystemGraphicsData GetGraphicsData() const override;