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
|
@ -7,6 +7,14 @@ class Transform
|
|||
public:
|
||||
Transform(const Point& location = {}, double scaleX = 1.0, double scaleY = 1.0, double scaleZ = 1.0);
|
||||
|
||||
void applyPre(const Transform& transform)
|
||||
{
|
||||
mLocation.move(transform.getLocation().getX(), transform.getLocation().getY(), transform.getLocation().getZ());
|
||||
mScaleX *= transform.getScaleX();
|
||||
mScaleY *= transform.getScaleY();
|
||||
mScaleZ *= transform.getScaleZ();
|
||||
}
|
||||
|
||||
void setLocation(const Point& loc);
|
||||
|
||||
void setScale(double scaleX, double scaleY = 1.0, double scaleZ = 1.0);
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -203,9 +203,14 @@ bool Button::isDirty() const
|
|||
|
||||
void Button::doPaint(const PaintEvent* event)
|
||||
{
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mRootNode->setTransform(Transform(mLocation));
|
||||
mTransformDirty = false;
|
||||
}
|
||||
|
||||
updateBackground(event);
|
||||
updateLabel(event);
|
||||
|
||||
updateIcon(event);
|
||||
|
||||
mContentDirty = false;
|
||||
|
@ -215,17 +220,12 @@ void Button::updateLabel(const PaintEvent* event)
|
|||
{
|
||||
if (!mTextNode)
|
||||
{
|
||||
mTextNode = TextNode::Create(mLabel, mLocation);
|
||||
mTextNode = TextNode::Create(mLabel, Transform({ mSize.mWidth /2.0, mSize.mHeight / 2.0 }));
|
||||
mTextNode->setName(mName + "_TextNode");
|
||||
mTextNode->setContent(mLabel);
|
||||
mRootNode->addChild(mTextNode.get());
|
||||
}
|
||||
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mTextNode->setLocation(mLocation);
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
mRootNode->addChild(mTextNode.get());
|
||||
}
|
||||
|
||||
if (mMaterialDirty)
|
||||
|
@ -255,14 +255,14 @@ void Button::updateIcon(const PaintEvent* event)
|
|||
{
|
||||
if (!mIconNode && mIcon != Resource::Icon::Svg::NONE)
|
||||
{
|
||||
mIconNode = std::make_unique<IconNode>(mLocation);
|
||||
mIconNode = std::make_unique<IconNode>(Transform());
|
||||
mIconNode->setName(mName + "_IconNode");
|
||||
mIconNode->setContent(IconNode::IconType::Svg, MediaResourceManager::getSvgIconNode(mIcon));
|
||||
mIconNode->setSvgContent(MediaResourceManager::getSvgIconNode(mIcon));
|
||||
mRootNode->addChild(mIconNode.get());
|
||||
}
|
||||
else if (mContentDirty && mIcon != Resource::Icon::Svg::NONE)
|
||||
{
|
||||
mIconNode->setContent(IconNode::IconType::Svg, MediaResourceManager::getSvgIconNode(mIcon));
|
||||
mIconNode->setSvgContent(MediaResourceManager::getSvgIconNode(mIcon));
|
||||
}
|
||||
|
||||
if (!mIconNode)
|
||||
|
@ -270,11 +270,6 @@ void Button::updateIcon(const PaintEvent* event)
|
|||
return;
|
||||
}
|
||||
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mIconNode->setLocation(mLocation);
|
||||
}
|
||||
|
||||
if (mMaterialDirty)
|
||||
{
|
||||
auto icon_fill = event->getThemesManager()->getColor(mIconColor);
|
||||
|
|
|
@ -46,7 +46,7 @@ void Label::updateLabel(const PaintEvent* event)
|
|||
|
||||
if (!mTextNode)
|
||||
{
|
||||
mTextNode = TextNode::Create(mLabel, middle);
|
||||
mTextNode = TextNode::Create(mLabel, Transform());
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
mRootNode->addChild(mTextNode.get());
|
||||
|
@ -57,13 +57,6 @@ void Label::updateLabel(const PaintEvent* event)
|
|||
mTextNode->setFillColor(event->getThemesManager()->getColor(mBackground));
|
||||
}
|
||||
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mTextNode->setLocation(middle);
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
}
|
||||
|
||||
if (mContentDirty)
|
||||
{
|
||||
mTextNode->setContent(mLabel);
|
||||
|
|
|
@ -86,11 +86,9 @@ void TextBox::doPaint(const PaintEvent* event)
|
|||
|
||||
void TextBox::updateLabel(const PaintEvent* event)
|
||||
{
|
||||
auto loc = DiscretePoint(mLocation.getX() + mPadding.mLeft, mLocation.getY() + mPadding.mTop + unsigned(0));
|
||||
|
||||
if (!mTextNode)
|
||||
{
|
||||
mTextNode = TextNode::Create(mContent, loc);
|
||||
mTextNode = TextNode::Create(mContent, Transform());
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
mRootNode->addChild(mTextNode.get());
|
||||
|
@ -103,7 +101,6 @@ void TextBox::updateLabel(const PaintEvent* event)
|
|||
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mTextNode->setLocation(loc);
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
}
|
||||
|
|
|
@ -2,12 +2,22 @@
|
|||
|
||||
#include "SvgNode.h"
|
||||
|
||||
IconNode::IconNode(const Point& loc)
|
||||
: AbstractVisualNode(loc)
|
||||
IconNode::IconNode(const Transform& transform)
|
||||
: AbstractVisualNode(transform)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
unsigned IconNode::getContentWidth() const
|
||||
{
|
||||
return mSvgContent->getContentWidth();
|
||||
}
|
||||
|
||||
unsigned IconNode::getContentHeight() const
|
||||
{
|
||||
return mSvgContent->getContentHeight();
|
||||
}
|
||||
|
||||
void IconNode::setSvgContent(std::unique_ptr<SvgNode> svg_node)
|
||||
{
|
||||
mChildren.clear();
|
||||
|
@ -29,27 +39,10 @@ void IconNode::setFillColor(const Color& color)
|
|||
}
|
||||
}
|
||||
|
||||
void IconNode::setWidth(unsigned width)
|
||||
{
|
||||
if (mType == IconType::Svg)
|
||||
{
|
||||
mSvgContent->setWidth(width);
|
||||
}
|
||||
}
|
||||
|
||||
void IconNode::setHeight(unsigned height)
|
||||
{
|
||||
if (mType == IconType::Svg)
|
||||
{
|
||||
mSvgContent->setFillColor(height);
|
||||
mSvgContent->setHasStrokeColor(false);
|
||||
}
|
||||
}
|
||||
|
||||
void IconNode::setOutlineColor(const Color& color)
|
||||
{
|
||||
if (mType == IconType::Svg)
|
||||
{
|
||||
dynamic_cast<SvgNode*>(mContent.get())->setStrokeColor(color);
|
||||
mSvgContent->setStrokeColor(color);
|
||||
}
|
||||
}
|
|
@ -14,13 +14,11 @@ public:
|
|||
Svg
|
||||
};
|
||||
|
||||
IconNode(const Point& loc);
|
||||
IconNode(const Transform& transform = {});
|
||||
|
||||
void setLocation(const Point& loc) override;
|
||||
unsigned getContentWidth() const;
|
||||
|
||||
void setWidth(unsigned width);
|
||||
|
||||
void setHeight(unsigned height);
|
||||
unsigned getContentHeight() const;
|
||||
|
||||
void setFillColor(const Color& color);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ Path MediaResourceManager::getSvgIconPath(Resource::Icon::Svg icon)
|
|||
return mResourceLocation / MediaResources::getPath(icon);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractVisualNode> MediaResourceManager::getSvgIconNode(Resource::Icon::Svg icon)
|
||||
std::unique_ptr<SvgNode> MediaResourceManager::getSvgIconNode(Resource::Icon::Svg icon)
|
||||
{
|
||||
const auto path = getSvgIconPath(icon);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "MediaResources.h"
|
||||
#include "AbstractVisualNode.h"
|
||||
#include "SvgNode.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
|
@ -10,7 +10,7 @@ using Path = std::filesystem::path;
|
|||
class MediaResourceManager
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<AbstractVisualNode> getSvgIconNode(Resource::Icon::Svg icon);
|
||||
static std::unique_ptr<SvgNode> getSvgIconNode(Resource::Icon::Svg icon);
|
||||
|
||||
static Path getSvgIconPath(Resource::Icon::Svg icon);
|
||||
|
||||
|
|
|
@ -317,9 +317,9 @@ void Widget::createOrUpdateGeometry()
|
|||
const auto deltaY = mSize.mHeight - mMargin.mTop - mMargin.mBottom;
|
||||
if (!mBackgroundNode)
|
||||
{
|
||||
const auto locX = mLocation.getX() + mMargin.mLeft;
|
||||
const auto locY = mLocation.getY() + mMargin.mTop;
|
||||
mBackgroundNode = std::make_unique<RectangleNode>(DiscretePoint(locX, locY), deltaX, deltaY);
|
||||
Point margin_offset(mMargin.mLeft, mMargin.mTop);
|
||||
|
||||
mBackgroundNode = std::make_unique<RectangleNode>(Transform(margin_offset), deltaX, deltaY);
|
||||
mBackgroundNode->setRadius(mRadius);
|
||||
|
||||
mBackgroundNode->setName(mName + "_BackgroundNode");
|
||||
|
@ -335,9 +335,7 @@ void Widget::createOrUpdateGeometry()
|
|||
|
||||
void Widget::updateTransform()
|
||||
{
|
||||
const auto locX = mLocation.getX() + mMargin.mLeft;
|
||||
const auto locY = mLocation.getY() + mMargin.mTop;
|
||||
mBackgroundNode->setLocation(DiscretePoint(locX, locY));
|
||||
mRootNode->setTransform({ mLocation });
|
||||
}
|
||||
|
||||
void Widget::updateMaterial(const PaintEvent* event)
|
||||
|
@ -401,25 +399,30 @@ mt::Window* Widget::getTopLevelWindow() const
|
|||
return mWindow;
|
||||
}
|
||||
|
||||
std::cout << "I am " << getName() << std::endl;
|
||||
|
||||
auto lastParent = mParent;
|
||||
auto nextParent = mParent;
|
||||
while(nextParent)
|
||||
{
|
||||
auto temp = lastParent;
|
||||
lastParent = nextParent;
|
||||
nextParent = lastParent->getParent();
|
||||
std::cout << "Checking if " << lastParent->getName() << std::endl;
|
||||
nextParent = temp->getParent();
|
||||
if (nextParent)
|
||||
{
|
||||
std::cout << "Next is " << nextParent->getName() << std::endl;
|
||||
//std::cout << "Next is " << nextParent->getName() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "no next" << std::endl;
|
||||
//std::cout << "no next" << std::endl;
|
||||
}
|
||||
}
|
||||
return lastParent->getTopLevelWindow();
|
||||
if (lastParent)
|
||||
{
|
||||
return lastParent->getTopLevelWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Widget* Widget::getParent() const
|
||||
|
|
Loading…
Reference in a new issue