stuff-from-scratch/apps/notes_tk/mesh_viewer/MeshViewerView.cpp
2023-01-17 13:01:59 +00:00

68 lines
1.4 KiB
C++

#include "MeshViewerView.h"
#include "MeshNode.h"
#include "TransformNode.h"
#include "AbstractMesh.h"
#include "MeshPrimitives.h"
#include "ThemeManager.h"
#include "PaintEvent.h"
#include <iostream>
std::unique_ptr<MeshViewerView> MeshViewerView::Create()
{
return std::make_unique<MeshViewerView>();
}
MeshViewerView::~MeshViewerView()
{
}
MeshViewerView::MeshViewerView()
{
mName = "MeshViewerView";
mBackground = ThemeToken::SystemToken::Background;
}
void MeshViewerView::doPaint(const PaintEvent* event)
{
if (!mVisible)
{
return;
}
if (!mMeshNode)
{
mMeshNode = std::make_unique<MeshNode>(mLocation);
mMeshNode->setName(mName + "_MeshNode");
mMeshNode->setWidth(mSize.mWidth);
mMeshNode->setHeight(mSize.mHeight);
mMeshNode->setFillColor(event->getThemesManager()->getColor(mBackground));
mRootNode->addChild(mMeshNode.get());
}
if (mTransformDirty)
{
mMeshNode->setLocation(mLocation);
mMeshNode->setWidth(mSize.mWidth);
mMeshNode->setHeight(mSize.mHeight);
}
if (mMaterialDirty)
{
mMeshNode->setFillColor(event->getThemesManager()->getColor(mBackground));
}
if (!mMesh)
{
auto mesh = MeshPrimitives::buildRectangleAsTriMesh();
mMesh = std::move(mesh);
mMeshNode->setMesh(mMesh.get());
}
}