Start adding grid
This commit is contained in:
parent
9301769d58
commit
f04d86e0ad
37 changed files with 709 additions and 211 deletions
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;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue