Start adding grid
This commit is contained in:
parent
9301769d58
commit
f04d86e0ad
37 changed files with 709 additions and 211 deletions
78
src/visual_elements/AbstractVisualNode.cpp
Normal file
78
src/visual_elements/AbstractVisualNode.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
#include "AbstractVisualNode.h"
|
||||
|
||||
AbstractVisualNode::AbstractVisualNode(const DiscretePoint& location, const std::string& name)
|
||||
: mLocation(location),
|
||||
mName(name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SceneItem* AbstractVisualNode::getSceneItem(std::size_t idx) const
|
||||
{
|
||||
return mSceneItems[idx].get();
|
||||
}
|
||||
|
||||
unsigned AbstractVisualNode::getNumSceneItems() const
|
||||
{
|
||||
return mSceneItems.size();
|
||||
}
|
||||
|
||||
void AbstractVisualNode::update(FontsManager* fontsManager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Image<unsigned char>* AbstractVisualNode::getImage() const
|
||||
{
|
||||
return mImage.get();
|
||||
}
|
||||
|
||||
void AbstractVisualNode::syncChildren(const std::vector<AbstractVisualNode*>& children)
|
||||
{
|
||||
mChildren = children;
|
||||
}
|
||||
|
||||
void AbstractVisualNode::addChild(AbstractVisualNode* child)
|
||||
{
|
||||
mChildren.push_back(child);
|
||||
}
|
||||
|
||||
const std::vector<AbstractVisualNode*>& AbstractVisualNode::getChildren() const
|
||||
{
|
||||
return mChildren;
|
||||
}
|
||||
|
||||
void AbstractVisualNode::setIsVisible(bool isVisible)
|
||||
{
|
||||
//std::cout << "Setting " << mName << " visibility to " << isVisible << std::endl;
|
||||
mIsVisible = isVisible;
|
||||
}
|
||||
|
||||
unsigned AbstractVisualNode::getNumChildren() const
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
|
||||
void AbstractVisualNode::setName(const std::string& name)
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
const std::string& AbstractVisualNode::getName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
bool AbstractVisualNode::getIsVisible() const
|
||||
{
|
||||
return mIsVisible;
|
||||
}
|
||||
|
||||
void AbstractVisualNode::setLocation(const DiscretePoint& loc)
|
||||
{
|
||||
if (mLocation != loc)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mLocation = loc;
|
||||
}
|
||||
}
|
|
@ -15,83 +15,39 @@ class FontsManager;
|
|||
class AbstractVisualNode
|
||||
{
|
||||
public:
|
||||
AbstractVisualNode(const DiscretePoint& location, const std::string& name = {})
|
||||
: mLocation(location),
|
||||
mName(name)
|
||||
{
|
||||
|
||||
}
|
||||
AbstractVisualNode(const DiscretePoint& location, const std::string& name = {});
|
||||
|
||||
virtual ~AbstractVisualNode() = default;
|
||||
|
||||
SceneItem* getSceneItem() const
|
||||
{
|
||||
return mSceneItem.get();
|
||||
}
|
||||
void addChild(AbstractVisualNode* child);
|
||||
|
||||
virtual void update(FontsManager* fontsManager)
|
||||
{
|
||||
virtual SceneItem* getSceneItem(std::size_t idx) const;
|
||||
|
||||
}
|
||||
virtual unsigned getNumSceneItems() const;
|
||||
|
||||
Image<unsigned char>* getImage() const
|
||||
{
|
||||
return mImage.get();
|
||||
}
|
||||
unsigned getNumChildren() const;
|
||||
|
||||
void syncChildren(const std::vector<AbstractVisualNode*>& children)
|
||||
{
|
||||
mChildren = children;
|
||||
}
|
||||
const std::vector<AbstractVisualNode*>& getChildren() const;
|
||||
|
||||
void addChild(AbstractVisualNode* child)
|
||||
{
|
||||
mChildren.push_back(child);
|
||||
}
|
||||
const std::string& getName() const;
|
||||
|
||||
const std::vector<AbstractVisualNode*>& getChildren() const
|
||||
{
|
||||
return mChildren;
|
||||
}
|
||||
Image<unsigned char>* getImage() const;
|
||||
|
||||
void setIsVisible(bool isVisible)
|
||||
{
|
||||
//std::cout << "Setting " << mName << " visibility to " << isVisible << std::endl;
|
||||
mIsVisible = isVisible;
|
||||
}
|
||||
bool getIsVisible() const;
|
||||
|
||||
unsigned getNumChildren() const
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
virtual void update(FontsManager* fontsManager);
|
||||
|
||||
void setName(const std::string& name)
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
void syncChildren(const std::vector<AbstractVisualNode*>& children);
|
||||
|
||||
const std::string& getName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
void setIsVisible(bool isVisible);
|
||||
|
||||
bool getIsVisible() const
|
||||
{
|
||||
return mIsVisible;
|
||||
}
|
||||
void setName(const std::string& name);
|
||||
|
||||
void setLocation(const DiscretePoint& loc)
|
||||
{
|
||||
if (mLocation != loc)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mLocation = loc;
|
||||
}
|
||||
}
|
||||
void setLocation(const DiscretePoint& loc);
|
||||
|
||||
protected:
|
||||
DiscretePoint mLocation;
|
||||
std::unique_ptr<SceneItem> mSceneItem;
|
||||
std::vector<std::unique_ptr<SceneItem> > mSceneItems;
|
||||
std::unique_ptr<Image<unsigned char> > mImage;
|
||||
|
||||
std::vector<AbstractVisualNode*> mChildren;
|
||||
|
|
|
@ -9,6 +9,9 @@ list(APPEND visual_elements_LIB_INCLUDES
|
|||
SceneText.cpp
|
||||
Transform.cpp
|
||||
Texture.cpp
|
||||
GridNode.cpp
|
||||
AbstractVisualNode.cpp
|
||||
|
||||
)
|
||||
|
||||
add_library(visual_elements SHARED ${visual_elements_LIB_INCLUDES})
|
||||
|
|
123
src/visual_elements/GridNode.cpp
Normal file
123
src/visual_elements/GridNode.cpp
Normal file
|
@ -0,0 +1,123 @@
|
|||
#include "GridNode.h"
|
||||
|
||||
#include "MeshPrimitives.h"
|
||||
|
||||
GridNode::GridNode(const DiscretePoint& location)
|
||||
: MaterialNode(location)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GridNode::setNumX(unsigned numX)
|
||||
{
|
||||
if (mNumberX != numX)
|
||||
{
|
||||
mNumberX = numX;
|
||||
mDataDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void GridNode::setNumY(unsigned numY)
|
||||
{
|
||||
if (mNumberY != numY)
|
||||
{
|
||||
mNumberY = numY;
|
||||
mDataDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void GridNode::setWidth(unsigned width)
|
||||
{
|
||||
if (mWidth != width)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mWidth = width;
|
||||
}
|
||||
}
|
||||
|
||||
void GridNode::setHeight(unsigned height)
|
||||
{
|
||||
if (mHeight != height)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mHeight = height;
|
||||
}
|
||||
}
|
||||
|
||||
void GridNode::setData(const std::vector<Color>& colors)
|
||||
{
|
||||
if (mData != colors)
|
||||
{
|
||||
mData = colors;
|
||||
mDataDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
SceneItem* GridNode::getSceneItem(std::size_t idx) const
|
||||
{
|
||||
if (idx == 0)
|
||||
{
|
||||
return mBackgroundModel.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return mOutlineModel.get();
|
||||
}
|
||||
}
|
||||
|
||||
unsigned GridNode::getNumSceneItems() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void GridNode::update(FontsManager* fontsManager)
|
||||
{
|
||||
if (!mBackgroundModel || mDataDirty)
|
||||
{
|
||||
auto mesh = MeshPrimitives::buildExplodedGrid(mNumberX, mNumberY);
|
||||
|
||||
if (mHeight > mWidth)
|
||||
{
|
||||
mesh->scale(mWidth, mWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
mesh->scale(mHeight, mHeight);
|
||||
}
|
||||
|
||||
|
||||
if (!mBackgroundModel)
|
||||
{
|
||||
std::cout << "Setting up background model for grid node " << std::endl;
|
||||
mBackgroundModel = std::make_unique<SceneModel>(std::move(mesh));
|
||||
mBackgroundModel->setName(mName + "_Model");
|
||||
mBackgroundModel->updateUniformColor({200, 200, 200, 1.0});
|
||||
}
|
||||
else
|
||||
{
|
||||
mBackgroundModel.get()->updateMesh(std::move(mesh));
|
||||
mBackgroundModel->updateUniformColor({200, 200, 200, 1.0});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (!mOutlineModel || mDataDirty)
|
||||
{
|
||||
const auto rect = Rectangle(Point(), 1, 1);
|
||||
auto mesh = MeshPrimitives::build(rect);
|
||||
|
||||
if (!mOutlineModel)
|
||||
{
|
||||
mOutlineModel = std::make_unique<SceneModel>(std::move(mesh));
|
||||
mOutlineModel->setName(mName + "_Model");
|
||||
}
|
||||
else
|
||||
{
|
||||
mOutlineModel.get()->updateMesh(std::move(mesh));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
mDataDirty = false;
|
||||
}
|
||||
|
36
src/visual_elements/GridNode.h
Normal file
36
src/visual_elements/GridNode.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include "MaterialNode.h"
|
||||
#include "Color.h"
|
||||
|
||||
class GridNode : public MaterialNode
|
||||
{
|
||||
|
||||
public:
|
||||
GridNode(const DiscretePoint& location);
|
||||
|
||||
void setNumX(unsigned numX);
|
||||
|
||||
void setNumY(unsigned numY);
|
||||
|
||||
void setData(const std::vector<Color>& colors);
|
||||
|
||||
SceneItem* getSceneItem(std::size_t idx) const override;
|
||||
unsigned getNumSceneItems() const override;
|
||||
|
||||
void update(FontsManager* fontsManager) override;
|
||||
|
||||
void setWidth(unsigned width);
|
||||
void setHeight(unsigned height);
|
||||
|
||||
private:
|
||||
unsigned mNumberX{5};
|
||||
unsigned mNumberY{5};
|
||||
unsigned mWidth{1};
|
||||
unsigned mHeight{1};
|
||||
bool mDataDirty = true;
|
||||
std::vector<Color> mData;
|
||||
|
||||
std::unique_ptr<SceneModel> mBackgroundModel;
|
||||
std::unique_ptr<SceneModel> mOutlineModel;
|
||||
};
|
|
@ -24,6 +24,23 @@ GeometryNode::Type RectangleNode::getType()
|
|||
return GeometryNode::Type::Rectangle;
|
||||
}
|
||||
|
||||
SceneItem* RectangleNode::getSceneItem(std::size_t idx) const
|
||||
{
|
||||
if (idx == 0)
|
||||
{
|
||||
return mBackgroundItem.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned RectangleNode::getNumSceneItems() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned RectangleNode::getWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
|
@ -54,32 +71,32 @@ void RectangleNode::setHeight(unsigned height)
|
|||
|
||||
void RectangleNode::update(FontsManager* fontsManager)
|
||||
{
|
||||
if (!mSceneItem || mGeometryIsDirty)
|
||||
if (!mBackgroundItem || mGeometryIsDirty)
|
||||
{
|
||||
const auto rect = Rectangle(Point(), 1, 1);
|
||||
auto mesh = MeshPrimitives::build(rect);
|
||||
|
||||
if (!mSceneItem)
|
||||
if (!mBackgroundItem)
|
||||
{
|
||||
mSceneItem = std::make_unique<SceneModel>(std::move(mesh));
|
||||
mSceneItem->setName(mName + "_Model");
|
||||
mBackgroundItem = std::make_unique<SceneModel>(std::move(mesh));
|
||||
mBackgroundItem->setName(mName + "_Model");
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamic_cast<SceneModel*>(mSceneItem.get())->updateMesh(std::move(mesh));
|
||||
mBackgroundItem->updateMesh(std::move(mesh));
|
||||
}
|
||||
mGeometryIsDirty = false;
|
||||
}
|
||||
|
||||
if (mTransformIsDirty)
|
||||
{
|
||||
mSceneItem->updateTransform({mLocation, static_cast<double>(mWidth), static_cast<double>(mHeight)});
|
||||
mBackgroundItem->updateTransform({mLocation, static_cast<double>(mWidth), static_cast<double>(mHeight)});
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
if (mMaterialIsDirty)
|
||||
{
|
||||
mSceneItem->updateUniformColor(mFillColor);
|
||||
mBackgroundItem->updateUniformColor(mFillColor);
|
||||
mMaterialIsDirty = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,9 @@ public:
|
|||
unsigned getWidth() const;
|
||||
unsigned getHeight() const;
|
||||
|
||||
SceneItem* getSceneItem(std::size_t idx) const override;
|
||||
unsigned getNumSceneItems() const override;
|
||||
|
||||
void setWidth(unsigned width);
|
||||
void setHeight(unsigned height);
|
||||
|
||||
|
@ -22,6 +25,9 @@ public:
|
|||
private:
|
||||
unsigned mWidth{1};
|
||||
unsigned mHeight{1};
|
||||
|
||||
std::unique_ptr<SceneModel> mBackgroundItem;
|
||||
std::unique_ptr<SceneModel> mOutlineItem;
|
||||
};
|
||||
|
||||
using RectangleNodePtr = std::unique_ptr<RectangleNode>;
|
||||
|
|
|
@ -30,9 +30,12 @@ void Scene::updateNode(AbstractVisualNode* node, FontsManager* fontsManager)
|
|||
|
||||
node->update(fontsManager);
|
||||
|
||||
if(auto item = node->getSceneItem())
|
||||
for (std::size_t idx=0; idx< node->getNumSceneItems(); idx++)
|
||||
{
|
||||
mSceneItems.push_back(node->getSceneItem());
|
||||
if (auto item = node->getSceneItem(idx))
|
||||
{
|
||||
mSceneItems.push_back(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,23 @@ void TextNode::setContent(const std::string& content)
|
|||
}
|
||||
}
|
||||
|
||||
SceneItem* TextNode::getSceneItem(std::size_t idx) const
|
||||
{
|
||||
if (idx == 0)
|
||||
{
|
||||
return mTextItem.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned TextNode::getNumSceneItems() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void TextNode::updateLines(FontsManager* fontsManager)
|
||||
{
|
||||
auto original_count = mTextData.mLines.size();
|
||||
|
@ -116,10 +133,10 @@ void TextNode::updateLines(FontsManager* fontsManager)
|
|||
|
||||
void TextNode::update(FontsManager* fontsManager)
|
||||
{
|
||||
if (!mSceneItem)
|
||||
if (!mTextItem)
|
||||
{
|
||||
mSceneItem = std::make_unique<SceneText>();
|
||||
mSceneItem->setName(mName + "_SceneText");
|
||||
mTextItem = std::make_unique<SceneText>();
|
||||
mTextItem->setName(mName + "_SceneText");
|
||||
}
|
||||
|
||||
if (mTransformIsDirty || mContentIsDirty)
|
||||
|
@ -129,20 +146,20 @@ void TextNode::update(FontsManager* fontsManager)
|
|||
|
||||
if (mContentIsDirty || mLinesAreDirty)
|
||||
{
|
||||
dynamic_cast<SceneText*>(mSceneItem.get())->setTextData(mTextData);
|
||||
dynamic_cast<SceneText*>(mTextItem.get())->setTextData(mTextData);
|
||||
mContentIsDirty = false;
|
||||
mLinesAreDirty = false;
|
||||
}
|
||||
|
||||
if (mTransformIsDirty)
|
||||
{
|
||||
mSceneItem->updateTransform({mLocation});
|
||||
mTextItem->updateTransform({mLocation});
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
if (mMaterialIsDirty)
|
||||
{
|
||||
mSceneItem->updateUniformColor(mFillColor);
|
||||
mTextItem->updateUniformColor(mFillColor);
|
||||
mMaterialIsDirty = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ public:
|
|||
std::string getContent() const;
|
||||
std::string getFontLabel() const;
|
||||
|
||||
SceneItem* getSceneItem(std::size_t idx) const override;
|
||||
unsigned getNumSceneItems() const override;
|
||||
|
||||
unsigned getWidth() const;
|
||||
unsigned getHeight() const;
|
||||
|
||||
|
@ -39,6 +42,8 @@ private:
|
|||
|
||||
unsigned mWidth{1};
|
||||
unsigned mHeight{1};
|
||||
|
||||
std::unique_ptr<SceneItem> mTextItem;
|
||||
};
|
||||
|
||||
using TextNodetr = std::unique_ptr<TextNode>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue