Clean up use of transforms in scene graph.
This commit is contained in:
parent
3915a40c96
commit
f26ee2ebc4
37 changed files with 238 additions and 242 deletions
|
@ -4,10 +4,11 @@
|
|||
#include "AbstractMesh.h"
|
||||
#include "MeshPrimitives.h"
|
||||
#include "SceneInfo.h"
|
||||
|
||||
#include "Circle.h"
|
||||
|
||||
CircleNode::CircleNode(const Point& location, double radius)
|
||||
: GeometryNode(location),
|
||||
CircleNode::CircleNode(const Transform& transform, double radius)
|
||||
: GeometryNode(transform),
|
||||
mRadius(radius)
|
||||
{
|
||||
mMinorRadius = mRadius;
|
||||
|
@ -28,7 +29,7 @@ void CircleNode::setRadius(double radius)
|
|||
if (mRadius != radius)
|
||||
{
|
||||
mRadius = radius;
|
||||
mTransformIsDirty = true;
|
||||
mGeometryIsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,28 +38,47 @@ void CircleNode::setMinorRadius(double radius)
|
|||
if (mMinorRadius != radius)
|
||||
{
|
||||
mMinorRadius = radius;
|
||||
mTransformIsDirty = true;
|
||||
mGeometryIsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractGeometricItem> CircleNode::createGeometryPrimitive() const
|
||||
{
|
||||
auto circle = std::make_unique<Circle>(Point{ 0, 0 }, mRadius);
|
||||
circle->setMinorRadius(mMinorRadius);
|
||||
return circle;
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractMesh> CircleNode::createMeshPrimitive() const
|
||||
{
|
||||
return MeshPrimitives::buildCircleAsTriMesh();
|
||||
}
|
||||
|
||||
void CircleNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
||||
{
|
||||
if (sceneInfo->mSupportsGeometryPrimitives)
|
||||
if (!mBackgroundItem)
|
||||
{
|
||||
double unit_circle_radius = 0.5;
|
||||
auto circle = std::make_unique<Circle>(Point{ 0, 0 }, unit_circle_radius);
|
||||
circle->setMinorRadius(unit_circle_radius*mMinorRadius/mRadius);
|
||||
mBackgroundItem = std::make_unique<SceneModel>(std::move(circle));
|
||||
if (sceneInfo->mSupportsGeometryPrimitives)
|
||||
{
|
||||
mBackgroundItem = std::make_unique<SceneModel>(createGeometryPrimitive());
|
||||
}
|
||||
else
|
||||
{
|
||||
mBackgroundItem = std::make_unique<SceneModel>(createMeshPrimitive());
|
||||
mBackgroundItem->setMeshTransform(Transform({}, mRadius, mRadius));
|
||||
}
|
||||
mBackgroundItem->setName(mName + "_Model");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto mesh = MeshPrimitives::buildCircleAsTriMesh();
|
||||
mBackgroundItem = std::make_unique<SceneModel>(std::move(mesh));
|
||||
if (sceneInfo->mSupportsGeometryPrimitives)
|
||||
{
|
||||
mBackgroundItem->updateGeometry(createGeometryPrimitive());
|
||||
}
|
||||
else
|
||||
{
|
||||
mBackgroundItem->updateMesh(createMeshPrimitive());
|
||||
mBackgroundItem->setMeshTransform(Transform({}, mRadius, mRadius));
|
||||
}
|
||||
}
|
||||
mBackgroundItem->setName(mName + "_Model");
|
||||
}
|
||||
|
||||
void CircleNode::updateTransform()
|
||||
{
|
||||
mBackgroundItem->updateTransform({ mLocation, 2 * mRadius, 2 * mRadius });
|
||||
}
|
||||
|
|
|
@ -2,10 +2,13 @@
|
|||
|
||||
#include "GeometryNode.h"
|
||||
|
||||
class AbstractGeometricItem;
|
||||
class AbstractMesh;
|
||||
|
||||
class CircleNode : public GeometryNode
|
||||
{
|
||||
public:
|
||||
CircleNode(const Point& location, double radius);
|
||||
CircleNode(const Transform& transform, double radius);
|
||||
|
||||
Type getType() override;
|
||||
double getRadius() const;
|
||||
|
@ -14,7 +17,9 @@ public:
|
|||
void setRadius(double radius);
|
||||
private:
|
||||
void createOrUpdateGeometry(SceneInfo* sceneInfo) override;
|
||||
void updateTransform() override;
|
||||
|
||||
std::unique_ptr<AbstractGeometricItem> createGeometryPrimitive() const;
|
||||
std::unique_ptr<AbstractMesh> createMeshPrimitive() const;
|
||||
|
||||
double mRadius{1.0};
|
||||
double mMinorRadius{ 1.0 };
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include "LineNode.h"
|
||||
|
||||
LineNode::LineNode(const Point& location, const std::vector<Point>& points)
|
||||
: GeometryNode(location),
|
||||
#include "SceneModel.h"
|
||||
|
||||
LineNode::LineNode(const Transform& transform, const std::vector<Point>& points)
|
||||
: GeometryNode(transform),
|
||||
mPoints(points)
|
||||
{
|
||||
|
||||
|
@ -20,9 +22,4 @@ void LineNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
|||
mBackgroundItem = std::make_unique<SceneModel>(std::move(line));
|
||||
}
|
||||
mBackgroundItem->setName(mName + "_Model");
|
||||
}
|
||||
|
||||
void LineNode::updateTransform()
|
||||
{
|
||||
mBackgroundItem->updateTransform({ mLocation });
|
||||
}
|
|
@ -10,14 +10,12 @@
|
|||
class LineNode : public GeometryNode
|
||||
{
|
||||
public:
|
||||
LineNode(const Point& location, const std::vector<Point>& points);
|
||||
LineNode(const Transform& transform, const std::vector<Point>& points);
|
||||
|
||||
Type getType();
|
||||
|
||||
private:
|
||||
void createOrUpdateGeometry(SceneInfo* sceneInfo) override;
|
||||
|
||||
void updateTransform() override;
|
||||
|
||||
std::vector<Point> mPoints;
|
||||
};
|
|
@ -3,19 +3,21 @@
|
|||
#include "Rectangle.h"
|
||||
|
||||
#include "MeshPrimitives.h"
|
||||
#include "SceneInfo.h"
|
||||
|
||||
RectangleNode::RectangleNode(const Point& loc, double width, double height)
|
||||
: GeometryNode(loc),
|
||||
#include "SceneInfo.h"
|
||||
#include "SceneModel.h"
|
||||
|
||||
RectangleNode::RectangleNode(const Transform& transform, double width, double height)
|
||||
: GeometryNode(transform),
|
||||
mWidth(width),
|
||||
mHeight(height)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<RectangleNode> RectangleNode::Create(const Point& loc, double width, double height)
|
||||
std::unique_ptr<RectangleNode> RectangleNode::Create(const Transform& transform, double width, double height)
|
||||
{
|
||||
return std::make_unique<RectangleNode>(loc, width, height);
|
||||
return std::make_unique<RectangleNode>(transform, width, height);
|
||||
}
|
||||
|
||||
GeometryNode::Type RectangleNode::getType()
|
||||
|
@ -92,9 +94,4 @@ void RectangleNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
|||
mBackgroundItem->updateGeometry(std::move(rect));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RectangleNode::updateTransform()
|
||||
{
|
||||
mBackgroundItem->updateTransform({ mLocation });
|
||||
}
|
|
@ -7,8 +7,8 @@
|
|||
class RectangleNode : public GeometryNode
|
||||
{
|
||||
public:
|
||||
RectangleNode(const Point& loc, double width, double height);
|
||||
static std::unique_ptr<RectangleNode> Create(const Point& loc, double width, double height);
|
||||
RectangleNode(const Transform& transform, double width, double height);
|
||||
static std::unique_ptr<RectangleNode> Create(const Transform& transform, double width, double height);
|
||||
|
||||
GeometryNode::Type getType() override;
|
||||
|
||||
|
@ -22,7 +22,6 @@ public:
|
|||
|
||||
private:
|
||||
void createOrUpdateGeometry(SceneInfo* sceneInfo) override;
|
||||
void updateTransform() override;
|
||||
|
||||
double mWidth{1};
|
||||
double mHeight{1};
|
||||
|
|
|
@ -1,15 +1,27 @@
|
|||
#include "AbstractVisualNode.h"
|
||||
|
||||
AbstractVisualNode::AbstractVisualNode(const Point& location, const std::string& name)
|
||||
: mLocation(location),
|
||||
AbstractVisualNode::AbstractVisualNode(const Transform& transform, const std::string& name)
|
||||
: mTransform(transform),
|
||||
mName(name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AbstractVisualNode::~AbstractVisualNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SceneItem* AbstractVisualNode::getSceneItem(std::size_t idx) const
|
||||
{
|
||||
return mSceneItems[idx].get();
|
||||
if (idx < mSceneItems.size())
|
||||
{
|
||||
return mSceneItems[idx].get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t AbstractVisualNode::getNumSceneItems() const
|
||||
|
@ -22,11 +34,6 @@ void AbstractVisualNode::update(SceneInfo* sceneInfo)
|
|||
|
||||
}
|
||||
|
||||
Image* AbstractVisualNode::getImage() const
|
||||
{
|
||||
return mImage.get();
|
||||
}
|
||||
|
||||
void AbstractVisualNode::syncChildren(const std::vector<AbstractVisualNode*>& children)
|
||||
{
|
||||
mChildren = children;
|
||||
|
@ -47,11 +54,6 @@ void AbstractVisualNode::setIsVisible(bool isVisible)
|
|||
mIsVisible = isVisible;
|
||||
}
|
||||
|
||||
std::size_t AbstractVisualNode::getNumChildren() const
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
|
||||
void AbstractVisualNode::setName(const std::string& name)
|
||||
{
|
||||
mName = name;
|
||||
|
@ -67,11 +69,16 @@ bool AbstractVisualNode::getIsVisible() const
|
|||
return mIsVisible;
|
||||
}
|
||||
|
||||
void AbstractVisualNode::setLocation(const Point& loc)
|
||||
const Transform& AbstractVisualNode::getTransform() const
|
||||
{
|
||||
if (mLocation != loc)
|
||||
return mTransform;
|
||||
}
|
||||
|
||||
void AbstractVisualNode::setTransform(const Transform& transform)
|
||||
{
|
||||
if (mTransform != transform)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mLocation = loc;
|
||||
mTransform = transform;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include "SceneModel.h"
|
||||
#include "AbstractMesh.h"
|
||||
|
||||
#include "Image.h"
|
||||
#include "Point.h"
|
||||
#include "SceneItem.h"
|
||||
#include "Transform.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct SceneInfo;
|
||||
|
||||
class AbstractVisualNode
|
||||
{
|
||||
public:
|
||||
AbstractVisualNode(const Point& location, const std::string& name = {});
|
||||
AbstractVisualNode(const Transform& transform = {}, const std::string& name = {});
|
||||
|
||||
virtual ~AbstractVisualNode() = default;
|
||||
virtual ~AbstractVisualNode();
|
||||
|
||||
void addChild(AbstractVisualNode* child);
|
||||
|
||||
|
@ -25,30 +22,27 @@ public:
|
|||
|
||||
virtual std::size_t getNumSceneItems() const;
|
||||
|
||||
std::size_t getNumChildren() const;
|
||||
|
||||
const std::vector<AbstractVisualNode*>& getChildren() const;
|
||||
|
||||
const std::string& getName() const;
|
||||
|
||||
Image* getImage() const;
|
||||
|
||||
bool getIsVisible() const;
|
||||
|
||||
const Transform& getTransform() const;
|
||||
|
||||
void syncChildren(const std::vector<AbstractVisualNode*>& children);
|
||||
|
||||
void setIsVisible(bool isVisible);
|
||||
|
||||
void setName(const std::string& name);
|
||||
|
||||
virtual void setLocation(const Point& loc);
|
||||
virtual void setTransform(const Transform& transform);
|
||||
|
||||
virtual void update(SceneInfo* sceneInfo);
|
||||
|
||||
protected:
|
||||
Point mLocation;
|
||||
Transform mTransform;
|
||||
std::vector<std::unique_ptr<SceneItem> > mSceneItems;
|
||||
std::unique_ptr<Image> mImage;
|
||||
|
||||
std::vector<AbstractVisualNode*> mChildren;
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include "SceneInfo.h"
|
||||
#include "SceneModel.h"
|
||||
|
||||
GeometryNode::GeometryNode(const Point& location)
|
||||
: MaterialNode(location),
|
||||
GeometryNode::GeometryNode(const Transform& transform)
|
||||
: MaterialNode(transform),
|
||||
mStrokeThickness(1.0),
|
||||
mType(Type::Path)
|
||||
{
|
||||
|
@ -75,12 +75,6 @@ void GeometryNode::update(SceneInfo* sceneInfo)
|
|||
mGeometryIsDirty = false;
|
||||
}
|
||||
|
||||
if (mTransformIsDirty)
|
||||
{
|
||||
updateTransform();
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
if (mMaterialIsDirty)
|
||||
{
|
||||
updateMaterial();
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
GeometryNode(const Point& location);
|
||||
GeometryNode(const Transform& transform);
|
||||
virtual ~GeometryNode();
|
||||
|
||||
virtual Type getType() = 0;
|
||||
|
@ -34,7 +34,6 @@ public:
|
|||
protected:
|
||||
virtual void createOrUpdateGeometry(SceneInfo* sceneInfo) = 0;
|
||||
virtual void updateMaterial();
|
||||
virtual void updateTransform() = 0;
|
||||
|
||||
double mStrokeThickness{0};
|
||||
Type mType;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include "GridNode.h"
|
||||
|
||||
#include "MeshPrimitives.h"
|
||||
#include "SceneModel.h"
|
||||
|
||||
GridNode::GridNode(const Point& location)
|
||||
: MaterialNode(location)
|
||||
GridNode::GridNode(const Transform& transform)
|
||||
: MaterialNode(transform)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -30,7 +31,7 @@ void GridNode::setWidth(double width)
|
|||
{
|
||||
if (mWidth != width)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mGeometryIsDirty = true;
|
||||
mWidth = width;
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +40,7 @@ void GridNode::setHeight(double height)
|
|||
{
|
||||
if (mHeight != height)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mGeometryIsDirty = true;
|
||||
mHeight = height;
|
||||
}
|
||||
}
|
||||
|
@ -124,8 +125,8 @@ void GridNode::update(SceneInfo* sceneInfo)
|
|||
{
|
||||
auto size = mHeight > mWidth ? mWidth : mHeight;
|
||||
|
||||
mBackgroundModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
mOutlineModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
//mBackgroundModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
//mOutlineModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
#include "MaterialNode.h"
|
||||
#include "Color.h"
|
||||
|
||||
class SceneModel;
|
||||
|
||||
class GridNode : public MaterialNode
|
||||
{
|
||||
|
||||
public:
|
||||
GridNode(const Point& location);
|
||||
GridNode(const Transform& transform);
|
||||
|
||||
void setNumX(std::size_t numX);
|
||||
|
||||
|
@ -28,7 +29,10 @@ private:
|
|||
std::size_t mNumberY{5};
|
||||
double mWidth{1};
|
||||
double mHeight{1};
|
||||
|
||||
bool mDataDirty = true;
|
||||
bool mGeometryIsDirty = true;
|
||||
|
||||
std::vector<Color> mData;
|
||||
|
||||
std::unique_ptr<SceneModel> mBackgroundModel;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
#include "MaterialNode.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
MaterialNode::MaterialNode(const Point& location)
|
||||
: AbstractVisualNode(location),
|
||||
MaterialNode::MaterialNode(const Transform& transform)
|
||||
: AbstractVisualNode(transform),
|
||||
mFillColor(Color(255, 255, 255)),
|
||||
mStrokeColor(Color(0, 0, 0))
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
class MaterialNode : public AbstractVisualNode
|
||||
{
|
||||
public:
|
||||
MaterialNode(const Point& location);
|
||||
MaterialNode(const Transform& transform);
|
||||
|
||||
const Color& getFillColor() const;
|
||||
const Color& getStrokeColor() const;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include "MeshNode.h"
|
||||
|
||||
#include <iostream>
|
||||
#include "SceneModel.h"
|
||||
#include "AbstractMesh.h"
|
||||
|
||||
MeshNode::MeshNode(const Point& location)
|
||||
: MaterialNode(location)
|
||||
MeshNode::MeshNode(const Transform& transform)
|
||||
: MaterialNode(transform)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -69,7 +70,6 @@ void MeshNode::update(SceneInfo* sceneInfo)
|
|||
|
||||
if (mWorkingMesh && mMeshIsDirty)
|
||||
{
|
||||
std::cout << "Updating mesh with " << mWorkingMesh->getNumNodes() << std::endl;
|
||||
mModel->updateMesh(mWorkingMesh);
|
||||
mMeshIsDirty = false;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ void MeshNode::update(SceneInfo* sceneInfo)
|
|||
if (mTransformIsDirty)
|
||||
{
|
||||
auto size = mHeight > mWidth ? mWidth : mHeight;
|
||||
mModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
//mModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
#include "MaterialNode.h"
|
||||
|
||||
class SceneModel;
|
||||
class AbstractMesh;
|
||||
|
||||
class MeshNode : public MaterialNode
|
||||
{
|
||||
public:
|
||||
MeshNode(const Point& location);
|
||||
MeshNode(const Transform& transform);
|
||||
void setMesh(AbstractMesh* mesh);
|
||||
|
||||
SceneItem* getSceneItem(std::size_t idx) const override;
|
||||
|
|
|
@ -3,16 +3,18 @@
|
|||
#include "Path.h"
|
||||
#include "SceneInfo.h"
|
||||
|
||||
PathNode::PathNode(const Point& loc, const std::string& psPath)
|
||||
: GeometryNode(loc),
|
||||
#include "SceneModel.h"
|
||||
|
||||
PathNode::PathNode(const Transform& transform, const std::string& psPath)
|
||||
: GeometryNode(transform),
|
||||
mPathString(psPath)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<PathNode> PathNode::Create(const Point& loc, const std::string& psPath)
|
||||
std::unique_ptr<PathNode> PathNode::Create(const Transform& transform, const std::string& psPath)
|
||||
{
|
||||
return std::make_unique<PathNode>(loc, psPath);
|
||||
return std::make_unique<PathNode>(transform, psPath);
|
||||
}
|
||||
|
||||
GeometryNode::Type PathNode::getType()
|
||||
|
@ -51,9 +53,4 @@ void PathNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
|||
mBackgroundItem->updateGeometry(std::move(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PathNode::updateTransform()
|
||||
{
|
||||
mBackgroundItem->updateTransform({ mLocation });
|
||||
}
|
|
@ -7,8 +7,8 @@
|
|||
class PathNode : public GeometryNode
|
||||
{
|
||||
public:
|
||||
PathNode(const Point& loc, const std::string& psPath);
|
||||
static std::unique_ptr<PathNode> Create(const Point& loc, const std::string& psPath);
|
||||
PathNode(const Transform& transform, const std::string& psPath);
|
||||
static std::unique_ptr<PathNode> Create(const Transform& transform, const std::string& psPath);
|
||||
|
||||
GeometryNode::Type getType() override;
|
||||
|
||||
|
@ -18,7 +18,6 @@ public:
|
|||
|
||||
private:
|
||||
void createOrUpdateGeometry(SceneInfo* sceneInfo) override;
|
||||
void updateTransform() override;
|
||||
|
||||
std::string mPathString;
|
||||
};
|
|
@ -6,7 +6,7 @@ class RootNode : public AbstractVisualNode
|
|||
{
|
||||
public:
|
||||
RootNode()
|
||||
: AbstractVisualNode(DiscretePoint(0, 0))
|
||||
: AbstractVisualNode(Transform())
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -14,10 +14,8 @@
|
|||
|
||||
#include "StringUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
TextNode::TextNode(const std::string& content, const Point& loc)
|
||||
: MaterialNode(loc)
|
||||
TextNode::TextNode(const std::string& content, const Transform& transform)
|
||||
: MaterialNode(transform)
|
||||
{
|
||||
mTextData.mContent= content;
|
||||
}
|
||||
|
@ -27,9 +25,9 @@ TextNode::~TextNode()
|
|||
|
||||
}
|
||||
|
||||
std::unique_ptr<TextNode> TextNode::Create(const std::string& content, const Point& loc)
|
||||
std::unique_ptr<TextNode> TextNode::Create(const std::string& content, const Transform& transform)
|
||||
{
|
||||
return std::make_unique<TextNode>(content, loc);
|
||||
return std::make_unique<TextNode>(content, transform);
|
||||
}
|
||||
|
||||
std::string TextNode::getFontLabel() const
|
||||
|
@ -168,10 +166,10 @@ void TextNode::update(SceneInfo* sceneInfo)
|
|||
|
||||
if (mTransformIsDirty)
|
||||
{
|
||||
mTextItem->updateTransform({mLocation});
|
||||
mTextItem->setTextWidth(mWidth);
|
||||
mTextItem->setTextHeight(mHeight);
|
||||
mTransformIsDirty = false;
|
||||
//mTextItem->updateTransform({mLocation});
|
||||
//mTextItem->setTextWidth(mWidth);
|
||||
//mTextItem->setTextHeight(mHeight);
|
||||
//mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
if (mMaterialIsDirty)
|
||||
|
|
|
@ -15,11 +15,11 @@ class FontsManager;
|
|||
class TextNode : public MaterialNode
|
||||
{
|
||||
public:
|
||||
TextNode(const std::string& content, const Point& loc);
|
||||
TextNode(const std::string& content, const Transform& transform);
|
||||
|
||||
~TextNode();
|
||||
|
||||
static std::unique_ptr<TextNode> Create(const std::string& content, const Point& loc);
|
||||
static std::unique_ptr<TextNode> Create(const std::string& content, const Transform& transform);
|
||||
|
||||
std::string getContent() const;
|
||||
std::string getFontLabel() const;
|
||||
|
|
|
@ -7,7 +7,7 @@ class TransformNode : public AbstractVisualNode
|
|||
public:
|
||||
|
||||
TransformNode()
|
||||
: AbstractVisualNode(DiscretePoint(0, 0))
|
||||
: AbstractVisualNode(Transform())
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -19,12 +19,6 @@ Scene::~Scene()
|
|||
|
||||
}
|
||||
|
||||
void Scene::update()
|
||||
{
|
||||
mSceneItems.clear();
|
||||
updateNode(mRootNode.get());
|
||||
}
|
||||
|
||||
void Scene::addNode(AbstractVisualNode* node)
|
||||
{
|
||||
mRootNode->addChild(node);
|
||||
|
@ -32,7 +26,7 @@ void Scene::addNode(AbstractVisualNode* node)
|
|||
|
||||
bool Scene::isEmpty() const
|
||||
{
|
||||
return mRootNode->getNumChildren() == 0;
|
||||
return mRootNode->getChildren().empty();
|
||||
}
|
||||
|
||||
const Color& Scene::getBackgroundColor() const
|
||||
|
@ -45,15 +39,24 @@ void Scene::setBackgroundColor(const Color& color)
|
|||
mBackGroundColor = color;
|
||||
}
|
||||
|
||||
void Scene::updateNode(AbstractVisualNode* node)
|
||||
void Scene::update()
|
||||
{
|
||||
mSceneItems.clear();
|
||||
updateNode(mRootNode.get(), Transform());
|
||||
}
|
||||
|
||||
void Scene::updateNode(AbstractVisualNode* node, const Transform& transform)
|
||||
{
|
||||
node->update(mSceneInfo.get());
|
||||
|
||||
auto node_transform = node->getTransform();
|
||||
node_transform.applyPre(transform);
|
||||
|
||||
for (auto child : node->getChildren())
|
||||
{
|
||||
if (child->getIsVisible())
|
||||
{
|
||||
updateNode(child);
|
||||
updateNode(child, node_transform);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,6 +64,7 @@ void Scene::updateNode(AbstractVisualNode* node)
|
|||
{
|
||||
if (auto item = node->getSceneItem(idx))
|
||||
{
|
||||
item->updateTransform(node_transform);
|
||||
mSceneItems.push_back(item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "TextData.h"
|
||||
#include "SceneInfo.h"
|
||||
#include "Color.h"
|
||||
#include "Transform.h"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
@ -38,7 +39,7 @@ public:
|
|||
|
||||
void update();
|
||||
private:
|
||||
void updateNode(AbstractVisualNode* node);
|
||||
void updateNode(AbstractVisualNode* node, const Transform& transform);
|
||||
|
||||
Color mBackGroundColor;
|
||||
std::unique_ptr<RootNode> mRootNode;
|
||||
|
|
|
@ -55,6 +55,15 @@ void SceneModel::updateMesh(std::unique_ptr<AbstractMesh> mesh)
|
|||
mGeometryIsDirty = true;
|
||||
}
|
||||
|
||||
void SceneModel::setMeshTransform(const Transform& transform)
|
||||
{
|
||||
if (mMeshTransform != transform)
|
||||
{
|
||||
mMeshTransform = transform;
|
||||
mGeometryIsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SceneModel::updateGeometry(std::unique_ptr<AbstractGeometricItem> geometry)
|
||||
{
|
||||
mGeometry = std::move(geometry);
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
bool getShowOutline() const;
|
||||
Type getType() const override;
|
||||
|
||||
void setMeshTransform(const Transform& transform);
|
||||
void setShowOutline(bool showOutline);
|
||||
|
||||
void updateGeometry(std::unique_ptr<AbstractGeometricItem> geometry);
|
||||
|
@ -32,6 +33,8 @@ public:
|
|||
private:
|
||||
AbstractMesh* mRawMesh{nullptr};
|
||||
std::unique_ptr<AbstractMesh> mMesh;
|
||||
Transform mMeshTransform;
|
||||
|
||||
std::unique_ptr<Texture> mColorMap;
|
||||
|
||||
std::unique_ptr<AbstractGeometricItem> mGeometry;
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include "SvgElement.h"
|
||||
#include "SvgShapeElements.h"
|
||||
|
||||
SvgNode::SvgNode(const Point& location)
|
||||
: MaterialNode(location)
|
||||
SvgNode::SvgNode(const Transform& transform)
|
||||
: MaterialNode(transform)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -21,27 +21,14 @@ void SvgNode::setContent(std::unique_ptr<SvgDocument> doc)
|
|||
mGeometryNodes.clear();
|
||||
}
|
||||
|
||||
void SvgNode::setWidth(unsigned width)
|
||||
unsigned SvgNode::getContentWidth() const
|
||||
{
|
||||
if (mWidth != width)
|
||||
{
|
||||
mWidth = width;
|
||||
mTransformIsDirty = true;
|
||||
}
|
||||
return mContentWidth;
|
||||
}
|
||||
|
||||
void SvgNode::setHeight(unsigned height)
|
||||
unsigned SvgNode::getContentHeight() const
|
||||
{
|
||||
if (mHeight != height)
|
||||
{
|
||||
mHeight = height;
|
||||
mTransformIsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SvgNode::updateTransform()
|
||||
{
|
||||
|
||||
return mContentHeight;
|
||||
}
|
||||
|
||||
void SvgNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
||||
|
@ -72,7 +59,11 @@ void SvgNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
|||
raw_node = geom_node.get();
|
||||
mGeometryNodes.push_back(std::move(geom_node));
|
||||
}
|
||||
addChild(raw_node);
|
||||
|
||||
if (raw_node)
|
||||
{
|
||||
addChild(raw_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,12 +75,6 @@ void SvgNode::update(SceneInfo* sceneInfo)
|
|||
mContentDirty = false;
|
||||
}
|
||||
|
||||
if (mTransformIsDirty)
|
||||
{
|
||||
updateTransform();
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
if (mMaterialIsDirty)
|
||||
{
|
||||
if (mHasFillColor)
|
||||
|
|
|
@ -10,26 +10,25 @@
|
|||
class SvgNode : public MaterialNode
|
||||
{
|
||||
public:
|
||||
SvgNode(const Point& location);
|
||||
SvgNode(const Transform& transform);
|
||||
|
||||
unsigned getContentWidth() const;
|
||||
unsigned getContentHeight() const;
|
||||
|
||||
void setContent(std::unique_ptr<SvgDocument> doc);
|
||||
|
||||
void setWidth(unsigned width);
|
||||
void setHeight(unsigned height);
|
||||
|
||||
void update(SceneInfo* sceneInfo);
|
||||
private:
|
||||
void createOrUpdateGeometry(SceneInfo* sceneInfo);
|
||||
void updateTransform();
|
||||
|
||||
void onCircle(XmlElement* element, std::unique_ptr<GeometryNode>& node);
|
||||
void onPath(XmlElement* element, std::unique_ptr<GeometryNode>& node);
|
||||
|
||||
unsigned mWidth{ 0 };
|
||||
unsigned mHeight{ 0 };
|
||||
|
||||
bool mContentDirty{ true };
|
||||
|
||||
unsigned mContentWidth{ 1 };
|
||||
unsigned mContentHeight{ 1 };
|
||||
|
||||
std::vector<std::unique_ptr<GeometryNode> > mGeometryNodes;
|
||||
std::unique_ptr<SvgDocument> mContent;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue