stuff-from-scratch/apps/notes_tk/mesh_viewer/MeshViewerView.cpp

69 lines
1.4 KiB
C++
Raw Normal View History

2022-11-18 17:05:33 +00:00
#include "MeshViewerView.h"
#include "MeshNode.h"
#include "TransformNode.h"
#include "AbstractMesh.h"
#include "MeshPrimitives.h"
2023-01-17 13:01:59 +00:00
#include "ThemeManager.h"
#include "PaintEvent.h"
2022-11-18 17:05:33 +00:00
#include <iostream>
std::unique_ptr<MeshViewerView> MeshViewerView::Create()
{
return std::make_unique<MeshViewerView>();
}
MeshViewerView::~MeshViewerView()
{
}
MeshViewerView::MeshViewerView()
{
mName = "MeshViewerView";
2023-01-17 13:01:59 +00:00
mBackground = ThemeToken::SystemToken::Background;
2022-11-18 17:05:33 +00:00
}
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);
2023-01-17 13:01:59 +00:00
mMeshNode->setFillColor(event->getThemesManager()->getColor(mBackground));
2022-11-18 17:05:33 +00:00
mRootNode->addChild(mMeshNode.get());
}
if (mTransformDirty)
{
mMeshNode->setLocation(mLocation);
mMeshNode->setWidth(mSize.mWidth);
mMeshNode->setHeight(mSize.mHeight);
}
if (mMaterialDirty)
{
2023-01-17 13:01:59 +00:00
mMeshNode->setFillColor(event->getThemesManager()->getColor(mBackground));
2022-11-18 17:05:33 +00:00
}
if (!mMesh)
{
auto mesh = MeshPrimitives::buildRectangleAsTriMesh();
mMesh = std::move(mesh);
mMeshNode->setMesh(mMesh.get());
}
}