diff --git a/src/base/geometry/Transform.h b/src/base/geometry/Transform.h index a0d0687..10ee88b 100644 --- a/src/base/geometry/Transform.h +++ b/src/base/geometry/Transform.h @@ -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); diff --git a/src/rendering/visual_elements/basic_shapes/CircleNode.cpp b/src/rendering/visual_elements/basic_shapes/CircleNode.cpp index 795cb2a..7bc4c96 100644 --- a/src/rendering/visual_elements/basic_shapes/CircleNode.cpp +++ b/src/rendering/visual_elements/basic_shapes/CircleNode.cpp @@ -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 CircleNode::createGeometryPrimitive() const +{ + auto circle = std::make_unique(Point{ 0, 0 }, mRadius); + circle->setMinorRadius(mMinorRadius); + return circle; +} + +std::unique_ptr 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(Point{ 0, 0 }, unit_circle_radius); - circle->setMinorRadius(unit_circle_radius*mMinorRadius/mRadius); - mBackgroundItem = std::make_unique(std::move(circle)); + if (sceneInfo->mSupportsGeometryPrimitives) + { + mBackgroundItem = std::make_unique(createGeometryPrimitive()); + } + else + { + mBackgroundItem = std::make_unique(createMeshPrimitive()); + mBackgroundItem->setMeshTransform(Transform({}, mRadius, mRadius)); + } + mBackgroundItem->setName(mName + "_Model"); } else { - auto mesh = MeshPrimitives::buildCircleAsTriMesh(); - mBackgroundItem = std::make_unique(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 }); } diff --git a/src/rendering/visual_elements/basic_shapes/CircleNode.h b/src/rendering/visual_elements/basic_shapes/CircleNode.h index 546ac5f..6f8dfea 100644 --- a/src/rendering/visual_elements/basic_shapes/CircleNode.h +++ b/src/rendering/visual_elements/basic_shapes/CircleNode.h @@ -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 createGeometryPrimitive() const; + std::unique_ptr createMeshPrimitive() const; double mRadius{1.0}; double mMinorRadius{ 1.0 }; diff --git a/src/rendering/visual_elements/basic_shapes/LineNode.cpp b/src/rendering/visual_elements/basic_shapes/LineNode.cpp index 87a2c81..1761bfd 100644 --- a/src/rendering/visual_elements/basic_shapes/LineNode.cpp +++ b/src/rendering/visual_elements/basic_shapes/LineNode.cpp @@ -1,7 +1,9 @@ #include "LineNode.h" -LineNode::LineNode(const Point& location, const std::vector& points) - : GeometryNode(location), +#include "SceneModel.h" + +LineNode::LineNode(const Transform& transform, const std::vector& points) + : GeometryNode(transform), mPoints(points) { @@ -20,9 +22,4 @@ void LineNode::createOrUpdateGeometry(SceneInfo* sceneInfo) mBackgroundItem = std::make_unique(std::move(line)); } mBackgroundItem->setName(mName + "_Model"); -} - -void LineNode::updateTransform() -{ - mBackgroundItem->updateTransform({ mLocation }); } \ No newline at end of file diff --git a/src/rendering/visual_elements/basic_shapes/LineNode.h b/src/rendering/visual_elements/basic_shapes/LineNode.h index 3123ee9..bb932ed 100644 --- a/src/rendering/visual_elements/basic_shapes/LineNode.h +++ b/src/rendering/visual_elements/basic_shapes/LineNode.h @@ -10,14 +10,12 @@ class LineNode : public GeometryNode { public: - LineNode(const Point& location, const std::vector& points); + LineNode(const Transform& transform, const std::vector& points); Type getType(); private: void createOrUpdateGeometry(SceneInfo* sceneInfo) override; - void updateTransform() override; - std::vector mPoints; }; \ No newline at end of file diff --git a/src/rendering/visual_elements/basic_shapes/RectangleNode.cpp b/src/rendering/visual_elements/basic_shapes/RectangleNode.cpp index a9e8f85..abc8f25 100644 --- a/src/rendering/visual_elements/basic_shapes/RectangleNode.cpp +++ b/src/rendering/visual_elements/basic_shapes/RectangleNode.cpp @@ -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::Create(const Point& loc, double width, double height) +std::unique_ptr RectangleNode::Create(const Transform& transform, double width, double height) { - return std::make_unique(loc, width, height); + return std::make_unique(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 }); } \ No newline at end of file diff --git a/src/rendering/visual_elements/basic_shapes/RectangleNode.h b/src/rendering/visual_elements/basic_shapes/RectangleNode.h index 57a5756..c365142 100644 --- a/src/rendering/visual_elements/basic_shapes/RectangleNode.h +++ b/src/rendering/visual_elements/basic_shapes/RectangleNode.h @@ -7,8 +7,8 @@ class RectangleNode : public GeometryNode { public: - RectangleNode(const Point& loc, double width, double height); - static std::unique_ptr Create(const Point& loc, double width, double height); + RectangleNode(const Transform& transform, double width, double height); + static std::unique_ptr 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}; diff --git a/src/rendering/visual_elements/nodes/AbstractVisualNode.cpp b/src/rendering/visual_elements/nodes/AbstractVisualNode.cpp index ad254aa..c75ebfa 100644 --- a/src/rendering/visual_elements/nodes/AbstractVisualNode.cpp +++ b/src/rendering/visual_elements/nodes/AbstractVisualNode.cpp @@ -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& 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; } } diff --git a/src/rendering/visual_elements/nodes/AbstractVisualNode.h b/src/rendering/visual_elements/nodes/AbstractVisualNode.h index 7a4d003..85e30dd 100644 --- a/src/rendering/visual_elements/nodes/AbstractVisualNode.h +++ b/src/rendering/visual_elements/nodes/AbstractVisualNode.h @@ -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 - -#include +#include +#include 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& getChildren() const; const std::string& getName() const; - Image* getImage() const; - bool getIsVisible() const; + const Transform& getTransform() const; + void syncChildren(const std::vector& 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 > mSceneItems; - std::unique_ptr mImage; std::vector mChildren; diff --git a/src/rendering/visual_elements/nodes/GeometryNode.cpp b/src/rendering/visual_elements/nodes/GeometryNode.cpp index 2ac897a..f97ad14 100644 --- a/src/rendering/visual_elements/nodes/GeometryNode.cpp +++ b/src/rendering/visual_elements/nodes/GeometryNode.cpp @@ -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(); diff --git a/src/rendering/visual_elements/nodes/GeometryNode.h b/src/rendering/visual_elements/nodes/GeometryNode.h index 2a04cc4..1219e33 100644 --- a/src/rendering/visual_elements/nodes/GeometryNode.h +++ b/src/rendering/visual_elements/nodes/GeometryNode.h @@ -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; diff --git a/src/rendering/visual_elements/nodes/GridNode.cpp b/src/rendering/visual_elements/nodes/GridNode.cpp index 569f3f2..417d677 100644 --- a/src/rendering/visual_elements/nodes/GridNode.cpp +++ b/src/rendering/visual_elements/nodes/GridNode.cpp @@ -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(size), static_cast(size)}); - mOutlineModel->updateTransform({mLocation, static_cast(size), static_cast(size)}); + //mBackgroundModel->updateTransform({mLocation, static_cast(size), static_cast(size)}); + //mOutlineModel->updateTransform({mLocation, static_cast(size), static_cast(size)}); mTransformIsDirty = false; } diff --git a/src/rendering/visual_elements/nodes/GridNode.h b/src/rendering/visual_elements/nodes/GridNode.h index 81ae1bb..fcd9995 100644 --- a/src/rendering/visual_elements/nodes/GridNode.h +++ b/src/rendering/visual_elements/nodes/GridNode.h @@ -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 mData; std::unique_ptr mBackgroundModel; diff --git a/src/rendering/visual_elements/nodes/MaterialNode.cpp b/src/rendering/visual_elements/nodes/MaterialNode.cpp index e64106e..6aaecd1 100644 --- a/src/rendering/visual_elements/nodes/MaterialNode.cpp +++ b/src/rendering/visual_elements/nodes/MaterialNode.cpp @@ -1,9 +1,7 @@ #include "MaterialNode.h" -#include - -MaterialNode::MaterialNode(const Point& location) - : AbstractVisualNode(location), +MaterialNode::MaterialNode(const Transform& transform) + : AbstractVisualNode(transform), mFillColor(Color(255, 255, 255)), mStrokeColor(Color(0, 0, 0)) { diff --git a/src/rendering/visual_elements/nodes/MaterialNode.h b/src/rendering/visual_elements/nodes/MaterialNode.h index 82d720e..953cbe4 100644 --- a/src/rendering/visual_elements/nodes/MaterialNode.h +++ b/src/rendering/visual_elements/nodes/MaterialNode.h @@ -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; diff --git a/src/rendering/visual_elements/nodes/MeshNode.cpp b/src/rendering/visual_elements/nodes/MeshNode.cpp index da00c75..cb540b9 100644 --- a/src/rendering/visual_elements/nodes/MeshNode.cpp +++ b/src/rendering/visual_elements/nodes/MeshNode.cpp @@ -1,9 +1,10 @@ #include "MeshNode.h" -#include +#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(size), static_cast(size)}); + //mModel->updateTransform({mLocation, static_cast(size), static_cast(size)}); mTransformIsDirty = false; } diff --git a/src/rendering/visual_elements/nodes/MeshNode.h b/src/rendering/visual_elements/nodes/MeshNode.h index 2b31718..6f8096e 100644 --- a/src/rendering/visual_elements/nodes/MeshNode.h +++ b/src/rendering/visual_elements/nodes/MeshNode.h @@ -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; diff --git a/src/rendering/visual_elements/nodes/PathNode.cpp b/src/rendering/visual_elements/nodes/PathNode.cpp index e382129..3e84d52 100644 --- a/src/rendering/visual_elements/nodes/PathNode.cpp +++ b/src/rendering/visual_elements/nodes/PathNode.cpp @@ -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::Create(const Point& loc, const std::string& psPath) +std::unique_ptr PathNode::Create(const Transform& transform, const std::string& psPath) { - return std::make_unique(loc, psPath); + return std::make_unique(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 }); } \ No newline at end of file diff --git a/src/rendering/visual_elements/nodes/PathNode.h b/src/rendering/visual_elements/nodes/PathNode.h index ae016ef..b9edf37 100644 --- a/src/rendering/visual_elements/nodes/PathNode.h +++ b/src/rendering/visual_elements/nodes/PathNode.h @@ -7,8 +7,8 @@ class PathNode : public GeometryNode { public: - PathNode(const Point& loc, const std::string& psPath); - static std::unique_ptr Create(const Point& loc, const std::string& psPath); + PathNode(const Transform& transform, const std::string& psPath); + static std::unique_ptr 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; }; \ No newline at end of file diff --git a/src/rendering/visual_elements/nodes/RootNode.h b/src/rendering/visual_elements/nodes/RootNode.h index 9109846..768ca4c 100644 --- a/src/rendering/visual_elements/nodes/RootNode.h +++ b/src/rendering/visual_elements/nodes/RootNode.h @@ -6,7 +6,7 @@ class RootNode : public AbstractVisualNode { public: RootNode() - : AbstractVisualNode(DiscretePoint(0, 0)) + : AbstractVisualNode(Transform()) { } diff --git a/src/rendering/visual_elements/nodes/TextNode.cpp b/src/rendering/visual_elements/nodes/TextNode.cpp index 56a7d83..46cdf25 100644 --- a/src/rendering/visual_elements/nodes/TextNode.cpp +++ b/src/rendering/visual_elements/nodes/TextNode.cpp @@ -14,10 +14,8 @@ #include "StringUtils.h" -#include - -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::Create(const std::string& content, const Point& loc) +std::unique_ptr TextNode::Create(const std::string& content, const Transform& transform) { - return std::make_unique(content, loc); + return std::make_unique(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) diff --git a/src/rendering/visual_elements/nodes/TextNode.h b/src/rendering/visual_elements/nodes/TextNode.h index 42e7da9..1c82adb 100644 --- a/src/rendering/visual_elements/nodes/TextNode.h +++ b/src/rendering/visual_elements/nodes/TextNode.h @@ -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 Create(const std::string& content, const Point& loc); + static std::unique_ptr Create(const std::string& content, const Transform& transform); std::string getContent() const; std::string getFontLabel() const; diff --git a/src/rendering/visual_elements/nodes/TransformNode.h b/src/rendering/visual_elements/nodes/TransformNode.h index d28e0d6..ec17073 100644 --- a/src/rendering/visual_elements/nodes/TransformNode.h +++ b/src/rendering/visual_elements/nodes/TransformNode.h @@ -7,7 +7,7 @@ class TransformNode : public AbstractVisualNode public: TransformNode() - : AbstractVisualNode(DiscretePoint(0, 0)) + : AbstractVisualNode(Transform()) { } diff --git a/src/rendering/visual_elements/scene/Scene.cpp b/src/rendering/visual_elements/scene/Scene.cpp index 8cfd5f5..509700f 100644 --- a/src/rendering/visual_elements/scene/Scene.cpp +++ b/src/rendering/visual_elements/scene/Scene.cpp @@ -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); } } diff --git a/src/rendering/visual_elements/scene/Scene.h b/src/rendering/visual_elements/scene/Scene.h index 6d54161..4210983 100644 --- a/src/rendering/visual_elements/scene/Scene.h +++ b/src/rendering/visual_elements/scene/Scene.h @@ -3,6 +3,7 @@ #include "TextData.h" #include "SceneInfo.h" #include "Color.h" +#include "Transform.h" #include #include @@ -38,7 +39,7 @@ public: void update(); private: - void updateNode(AbstractVisualNode* node); + void updateNode(AbstractVisualNode* node, const Transform& transform); Color mBackGroundColor; std::unique_ptr mRootNode; diff --git a/src/rendering/visual_elements/scene/SceneModel.cpp b/src/rendering/visual_elements/scene/SceneModel.cpp index 0b0faa4..b0e484e 100644 --- a/src/rendering/visual_elements/scene/SceneModel.cpp +++ b/src/rendering/visual_elements/scene/SceneModel.cpp @@ -55,6 +55,15 @@ void SceneModel::updateMesh(std::unique_ptr mesh) mGeometryIsDirty = true; } +void SceneModel::setMeshTransform(const Transform& transform) +{ + if (mMeshTransform != transform) + { + mMeshTransform = transform; + mGeometryIsDirty = true; + } +} + void SceneModel::updateGeometry(std::unique_ptr geometry) { mGeometry = std::move(geometry); diff --git a/src/rendering/visual_elements/scene/SceneModel.h b/src/rendering/visual_elements/scene/SceneModel.h index 08d85e8..3bbf6e0 100644 --- a/src/rendering/visual_elements/scene/SceneModel.h +++ b/src/rendering/visual_elements/scene/SceneModel.h @@ -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 geometry); @@ -32,6 +33,8 @@ public: private: AbstractMesh* mRawMesh{nullptr}; std::unique_ptr mMesh; + Transform mMeshTransform; + std::unique_ptr mColorMap; std::unique_ptr mGeometry; diff --git a/src/rendering/visual_elements/svg/SvgNode.cpp b/src/rendering/visual_elements/svg/SvgNode.cpp index dd77c85..0cb7774 100644 --- a/src/rendering/visual_elements/svg/SvgNode.cpp +++ b/src/rendering/visual_elements/svg/SvgNode.cpp @@ -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 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) diff --git a/src/rendering/visual_elements/svg/SvgNode.h b/src/rendering/visual_elements/svg/SvgNode.h index 8251fc1..ea655f6 100644 --- a/src/rendering/visual_elements/svg/SvgNode.h +++ b/src/rendering/visual_elements/svg/SvgNode.h @@ -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 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& node); void onPath(XmlElement* element, std::unique_ptr& node); - unsigned mWidth{ 0 }; - unsigned mHeight{ 0 }; - bool mContentDirty{ true }; + unsigned mContentWidth{ 1 }; + unsigned mContentHeight{ 1 }; + std::vector > mGeometryNodes; std::unique_ptr mContent; }; diff --git a/src/ui/ui_controls/Button.cpp b/src/ui/ui_controls/Button.cpp index 141a53b..c9a6464 100644 --- a/src/ui/ui_controls/Button.cpp +++ b/src/ui/ui_controls/Button.cpp @@ -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(mLocation); + mIconNode = std::make_unique(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); diff --git a/src/ui/ui_controls/Label.cpp b/src/ui/ui_controls/Label.cpp index bc1886b..c596c88 100644 --- a/src/ui/ui_controls/Label.cpp +++ b/src/ui/ui_controls/Label.cpp @@ -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); diff --git a/src/ui/ui_controls/TextBox.cpp b/src/ui/ui_controls/TextBox.cpp index 70a4754..b95bef9 100644 --- a/src/ui/ui_controls/TextBox.cpp +++ b/src/ui/ui_controls/TextBox.cpp @@ -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); } diff --git a/src/ui/ui_elements/IconNode.cpp b/src/ui/ui_elements/IconNode.cpp index 975d9ea..f15e17c 100644 --- a/src/ui/ui_elements/IconNode.cpp +++ b/src/ui/ui_elements/IconNode.cpp @@ -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 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(mContent.get())->setStrokeColor(color); + mSvgContent->setStrokeColor(color); } } \ No newline at end of file diff --git a/src/ui/ui_elements/IconNode.h b/src/ui/ui_elements/IconNode.h index ca3a287..74c5aa8 100644 --- a/src/ui/ui_elements/IconNode.h +++ b/src/ui/ui_elements/IconNode.h @@ -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); diff --git a/src/ui/ui_elements/style/MediaResourceManager.cpp b/src/ui/ui_elements/style/MediaResourceManager.cpp index 0b36924..634a0e2 100644 --- a/src/ui/ui_elements/style/MediaResourceManager.cpp +++ b/src/ui/ui_elements/style/MediaResourceManager.cpp @@ -11,7 +11,7 @@ Path MediaResourceManager::getSvgIconPath(Resource::Icon::Svg icon) return mResourceLocation / MediaResources::getPath(icon); } -std::unique_ptr MediaResourceManager::getSvgIconNode(Resource::Icon::Svg icon) +std::unique_ptr MediaResourceManager::getSvgIconNode(Resource::Icon::Svg icon) { const auto path = getSvgIconPath(icon); diff --git a/src/ui/ui_elements/style/MediaResourceManager.h b/src/ui/ui_elements/style/MediaResourceManager.h index 03cd32a..ceb3dc8 100644 --- a/src/ui/ui_elements/style/MediaResourceManager.h +++ b/src/ui/ui_elements/style/MediaResourceManager.h @@ -1,7 +1,7 @@ #pragma once #include "MediaResources.h" -#include "AbstractVisualNode.h" +#include "SvgNode.h" #include @@ -10,7 +10,7 @@ using Path = std::filesystem::path; class MediaResourceManager { public: - static std::unique_ptr getSvgIconNode(Resource::Icon::Svg icon); + static std::unique_ptr getSvgIconNode(Resource::Icon::Svg icon); static Path getSvgIconPath(Resource::Icon::Svg icon); diff --git a/src/ui/ui_elements/widgets/Widget.cpp b/src/ui/ui_elements/widgets/Widget.cpp index 89b619d..5196164 100644 --- a/src/ui/ui_elements/widgets/Widget.cpp +++ b/src/ui/ui_elements/widgets/Widget.cpp @@ -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(DiscretePoint(locX, locY), deltaX, deltaY); + Point margin_offset(mMargin.mLeft, mMargin.mTop); + + mBackgroundNode = std::make_unique(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