Clean up of scene nodes to support 2d and non int positioning.
This commit is contained in:
parent
1eeaebd0a9
commit
672b31b603
45 changed files with 341 additions and 200 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "CircleNode.h"
|
#include "CircleNode.h"
|
||||||
|
|
||||||
BlochSphereNode::BlochSphereNode(const DiscretePoint& location)
|
BlochSphereNode::BlochSphereNode(const Point& location)
|
||||||
: AbstractVisualNode(location, "BlochSphereNode")
|
: AbstractVisualNode(location, "BlochSphereNode")
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ void BlochSphereNode::setSize(double size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlochSphereNode::update(FontsManager* fontsManager)
|
void BlochSphereNode::update(SceneInfo* sceneInfo)
|
||||||
{
|
{
|
||||||
if (!mContentDirty)
|
if (!mContentDirty)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,11 +11,11 @@ class LineNode;
|
||||||
class BlochSphereNode : public AbstractVisualNode
|
class BlochSphereNode : public AbstractVisualNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BlochSphereNode(const DiscretePoint& location);
|
BlochSphereNode(const Point& location);
|
||||||
|
|
||||||
void setContent(BlochSphere* content);
|
void setContent(BlochSphere* content);
|
||||||
|
|
||||||
void update(FontsManager* fontsManager) override;
|
void update(SceneInfo* sceneInfo) override;
|
||||||
|
|
||||||
void setSize(double size);
|
void setSize(double size);
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
TEST_CASE(TestBlochSphereNode, "quantum_computing")
|
TEST_CASE(TestBlochSphereNode, "quantum_computing")
|
||||||
{
|
{
|
||||||
auto node = std::make_unique<BlochSphereNode>(DiscretePoint(0.5, 0.5));
|
auto node = std::make_unique<BlochSphereNode>(Point(0.5, 0.5));
|
||||||
|
|
||||||
Qubit state({ 1.0, 0.0 }, { 0.0, 0.0 });
|
Qubit state({ 1.0, 0.0 }, { 0.0, 0.0 });
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ public:
|
||||||
|
|
||||||
virtual ~AbstractPainter() = default;
|
virtual ~AbstractPainter() = default;
|
||||||
virtual void paint() = 0;
|
virtual void paint() = 0;
|
||||||
|
virtual bool supportsGeometryPrimitives() const { return false; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DrawingContext* mDrawingContext{ nullptr };
|
DrawingContext* mDrawingContext{ nullptr };
|
||||||
|
|
|
@ -21,6 +21,7 @@ list(APPEND graphics_HEADERS
|
||||||
DrawingContext.h
|
DrawingContext.h
|
||||||
PainterFactory.h
|
PainterFactory.h
|
||||||
AbstractPainter.h
|
AbstractPainter.h
|
||||||
|
DrawingSurface.h
|
||||||
)
|
)
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
set(OpenGL_GL_PREFERENCE "GLVND")
|
set(OpenGL_GL_PREFERENCE "GLVND")
|
||||||
|
|
|
@ -45,3 +45,8 @@ AbstractPainter* DrawingContext::getPainter() const
|
||||||
{
|
{
|
||||||
return mPainter.get();
|
return mPainter.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DrawingContext::painterSupportsGeometryPrimitives() const
|
||||||
|
{
|
||||||
|
return mPainter->supportsGeometryPrimitives();
|
||||||
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ enum class DrawingMode
|
||||||
class DrawingContext
|
class DrawingContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DrawingContext(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode);
|
DrawingContext(DrawingSurface* surface, FontsManager* fontsManager = nullptr, DrawingMode requestedDrawingMode = DrawingMode::GRAPH);
|
||||||
|
|
||||||
static std::unique_ptr<DrawingContext> Create(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode);
|
static std::unique_ptr<DrawingContext> Create(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode);
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ public:
|
||||||
|
|
||||||
AbstractPainter* getPainter() const;
|
AbstractPainter* getPainter() const;
|
||||||
|
|
||||||
|
bool painterSupportsGeometryPrimitives() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DrawingMode mDrawingMode;
|
DrawingMode mDrawingMode;
|
||||||
FontsManager* mFontsManager{nullptr};
|
FontsManager* mFontsManager{nullptr};
|
||||||
|
|
|
@ -39,7 +39,7 @@ void DirectXMesh::update(DrawingContext* context, ID3D12Device* device)
|
||||||
y = 2 * y - 1;
|
y = 2 * y - 1;
|
||||||
|
|
||||||
Vertex vert;
|
Vertex vert;
|
||||||
vert.position = DirectX::XMFLOAT3(x, y, 0.0);
|
vert.position = DirectX::XMFLOAT3(static_cast<float>(x), static_cast<float>(y), 0.0);
|
||||||
vert.color = DirectX::XMFLOAT4(color[0], color[1], color[2], color[3]);
|
vert.color = DirectX::XMFLOAT4(color[0], color[1], color[2], color[3]);
|
||||||
MLOG_INFO("Adding vert: " << x << " | " << y);
|
MLOG_INFO("Adding vert: " << x << " | " << y);
|
||||||
mVertexBuffer.push_back(vert);
|
mVertexBuffer.push_back(vert);
|
||||||
|
@ -94,7 +94,7 @@ void DirectXMesh::createD3dVertexBuffer(ID3D12Device* device)
|
||||||
|
|
||||||
mVertexBufferView.BufferLocation = mD3dVertexBuffer->GetGPUVirtualAddress();
|
mVertexBufferView.BufferLocation = mD3dVertexBuffer->GetGPUVirtualAddress();
|
||||||
mVertexBufferView.StrideInBytes = sizeof(Vertex);
|
mVertexBufferView.StrideInBytes = sizeof(Vertex);
|
||||||
mVertexBufferView.SizeInBytes = buffer_size;
|
mVertexBufferView.SizeInBytes = static_cast<UINT>(buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectXMesh::uploadVertexBuffer(unsigned char* pBuffer) const
|
void DirectXMesh::uploadVertexBuffer(unsigned char* pBuffer) const
|
||||||
|
@ -116,7 +116,7 @@ void DirectXMesh::createD3dIndexBuffer(ID3D12Device* device)
|
||||||
mD3dIndexBuffer->Unmap(0, nullptr);
|
mD3dIndexBuffer->Unmap(0, nullptr);
|
||||||
|
|
||||||
mIndexBufferView.BufferLocation = mD3dIndexBuffer->GetGPUVirtualAddress();
|
mIndexBufferView.BufferLocation = mD3dIndexBuffer->GetGPUVirtualAddress();
|
||||||
mIndexBufferView.SizeInBytes = buffer_size;
|
mIndexBufferView.SizeInBytes = static_cast<UINT>(buffer_size);
|
||||||
mIndexBufferView.Format = DXGI_FORMAT_R16_UINT;
|
mIndexBufferView.Format = DXGI_FORMAT_R16_UINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ void DirectXTextPainter::initializeBrush(ID2D1DeviceContext2* d2dContext)
|
||||||
d2dContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &mTextBrush);
|
d2dContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &mTextBrush);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectXTextPainter::updateTextFormat(IDWriteFactory* directWriteFactory, unsigned fontSize)
|
void DirectXTextPainter::updateTextFormat(IDWriteFactory* directWriteFactory, float fontSize)
|
||||||
{
|
{
|
||||||
directWriteFactory->CreateTextFormat(
|
directWriteFactory->CreateTextFormat(
|
||||||
L"Verdana",
|
L"Verdana",
|
||||||
|
@ -54,9 +54,9 @@ void DirectXTextPainter::updateTextFormat(IDWriteFactory* directWriteFactory, un
|
||||||
void DirectXTextPainter::paint(SceneText* text, DrawingContext* context, ID2D1DeviceContext2* d2dContext, IDWriteFactory* directWriteFactory)
|
void DirectXTextPainter::paint(SceneText* text, DrawingContext* context, ID2D1DeviceContext2* d2dContext, IDWriteFactory* directWriteFactory)
|
||||||
{
|
{
|
||||||
const auto location = text->getTransform().getLocation();
|
const auto location = text->getTransform().getLocation();
|
||||||
D2D1_RECT_F textRect = D2D1::RectF(location.getX(), location.getY(), location.getX() + 200, location.getY() + 100);
|
D2D1_RECT_F textRect = D2D1::RectF(static_cast<float>(location.getX()), static_cast<float>(location.getY()), static_cast<float>(location.getX() + 200), static_cast<float>(location.getY() + 100));
|
||||||
|
|
||||||
updateTextFormat(directWriteFactory, text->getTextData().mFont.getSize());
|
updateTextFormat(directWriteFactory, static_cast<float>(text->getTextData().mFont.getSize()));
|
||||||
|
|
||||||
auto content = StringUtils::convert(text->getTextData().mContent);
|
auto content = StringUtils::convert(text->getTextData().mContent);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initializeBrush(ID2D1DeviceContext2* d2dContext);
|
void initializeBrush(ID2D1DeviceContext2* d2dContext);
|
||||||
void updateTextFormat(IDWriteFactory* directWriteFactory, unsigned fontSize);
|
void updateTextFormat(IDWriteFactory* directWriteFactory, float fontSize);
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> mTextBrush;
|
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> mTextBrush;
|
||||||
Microsoft::WRL::ComPtr<IDWriteTextFormat> mTextFormat;
|
Microsoft::WRL::ComPtr<IDWriteTextFormat> mTextFormat;
|
||||||
|
|
|
@ -157,7 +157,7 @@ void PngWriter::writeDataChunks(const BufferBitStream& buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PngWriter::write(const std::unique_ptr<Image<unsigned char> >& image)
|
void PngWriter::write(Image<unsigned char>* image)
|
||||||
{
|
{
|
||||||
if (!mPath.empty())
|
if (!mPath.empty())
|
||||||
{
|
{
|
||||||
|
@ -170,9 +170,9 @@ void PngWriter::write(const std::unique_ptr<Image<unsigned char> >& image)
|
||||||
mOutStream = std::make_unique<BufferBitStream>();
|
mOutStream = std::make_unique<BufferBitStream>();
|
||||||
}
|
}
|
||||||
|
|
||||||
mWorkingImage = image.get();
|
mWorkingImage = image;
|
||||||
|
|
||||||
auto image_bit_stream = std::make_unique<ImageBitStream>(image.get());
|
auto image_bit_stream = std::make_unique<ImageBitStream>(image);
|
||||||
auto raw_image_stream = image_bit_stream.get();
|
auto raw_image_stream = image_bit_stream.get();
|
||||||
|
|
||||||
mInStream = std::move(image_bit_stream);
|
mInStream = std::move(image_bit_stream);
|
||||||
|
@ -221,3 +221,8 @@ void PngWriter::write(const std::unique_ptr<Image<unsigned char> >& image)
|
||||||
mWorkingFile->close();
|
mWorkingFile->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PngWriter::write(const std::unique_ptr<Image<unsigned char> >& image)
|
||||||
|
{
|
||||||
|
write(image.get());
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
void setPngInfo(const PngInfo& info);
|
void setPngInfo(const PngInfo& info);
|
||||||
|
|
||||||
void write(const std::unique_ptr<Image<unsigned char> >& image);
|
void write(const std::unique_ptr<Image<unsigned char> >& image);
|
||||||
|
void write(Image<unsigned char>* image);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeSignature();
|
void writeSignature();
|
||||||
|
|
|
@ -1,25 +1,34 @@
|
||||||
set(MODULE_NAME visual_elements)
|
set(MODULE_NAME visual_elements)
|
||||||
|
|
||||||
list(APPEND visual_elements_LIB_INCLUDES
|
list(APPEND visual_elements_LIB_INCLUDES
|
||||||
GeometryNode.cpp
|
|
||||||
basic_shapes/RectangleNode.h
|
basic_shapes/RectangleNode.h
|
||||||
basic_shapes/RectangleNode.cpp
|
basic_shapes/RectangleNode.cpp
|
||||||
basic_shapes/CircleNode.h
|
basic_shapes/CircleNode.h
|
||||||
basic_shapes/CircleNode.cpp
|
basic_shapes/CircleNode.cpp
|
||||||
basic_shapes/LineNode.h
|
basic_shapes/LineNode.h
|
||||||
basic_shapes/LineNode.cpp
|
basic_shapes/LineNode.cpp
|
||||||
MaterialNode.cpp
|
scene/Scene.h
|
||||||
MeshNode.cpp
|
scene/Scene.cpp
|
||||||
TextNode.cpp
|
scene/SceneInfo.h
|
||||||
Scene.cpp
|
scene/SceneModel.h
|
||||||
SceneModel.cpp
|
scene/SceneModel.cpp
|
||||||
SceneItem.cpp
|
scene/SceneItem.h
|
||||||
SceneText.cpp
|
scene/SceneItem.cpp
|
||||||
|
scene/SceneText.h
|
||||||
|
scene/SceneText.cpp
|
||||||
|
nodes/MaterialNode.h
|
||||||
|
nodes/MaterialNode.cpp
|
||||||
|
nodes/MeshNode.h
|
||||||
|
nodes/MeshNode.cpp
|
||||||
|
nodes/TextNode.h
|
||||||
|
nodes/TextNode.cpp
|
||||||
|
nodes/GridNode.h
|
||||||
|
nodes/GridNode.cpp
|
||||||
|
nodes/GeometryNode.h
|
||||||
|
nodes/GeometryNode.cpp
|
||||||
|
nodes/AbstractVisualNode.h
|
||||||
|
nodes/AbstractVisualNode.cpp
|
||||||
Texture.cpp
|
Texture.cpp
|
||||||
GridNode.cpp
|
|
||||||
AbstractVisualNode.h
|
|
||||||
AbstractVisualNode.cpp
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(${MODULE_NAME} SHARED ${visual_elements_LIB_INCLUDES})
|
add_library(${MODULE_NAME} SHARED ${visual_elements_LIB_INCLUDES})
|
||||||
|
@ -27,6 +36,8 @@ add_library(${MODULE_NAME} SHARED ${visual_elements_LIB_INCLUDES})
|
||||||
target_include_directories(${MODULE_NAME} PUBLIC
|
target_include_directories(${MODULE_NAME} PUBLIC
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/basic_shapes
|
${CMAKE_CURRENT_SOURCE_DIR}/basic_shapes
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/scene
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/nodes
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${MODULE_NAME} PUBLIC core geometry fonts mesh image)
|
target_link_libraries(${MODULE_NAME} PUBLIC core geometry fonts mesh image)
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
#include "SceneModel.h"
|
|
||||||
|
|
||||||
#include "AbstractMesh.h"
|
|
||||||
|
|
||||||
SceneModel::SceneModel(std::unique_ptr<AbstractMesh> mesh)
|
|
||||||
: SceneItem(),
|
|
||||||
mMesh(std::move(mesh))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractMesh* SceneModel::getMesh() const
|
|
||||||
{
|
|
||||||
if (mMesh)
|
|
||||||
{
|
|
||||||
return mMesh.get();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return mRawMesh;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneModel::updateMesh(std::unique_ptr<AbstractMesh> mesh)
|
|
||||||
{
|
|
||||||
mMesh = std::move(mesh);
|
|
||||||
mMeshIsDirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneModel::updateMesh(AbstractMesh* mesh)
|
|
||||||
{
|
|
||||||
mRawMesh = mesh;
|
|
||||||
mMeshIsDirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneItem::Type SceneModel::getType() const
|
|
||||||
{
|
|
||||||
return SceneItem::Type::MODEL;
|
|
||||||
}
|
|
|
@ -4,10 +4,11 @@
|
||||||
#include "SceneModel.h"
|
#include "SceneModel.h"
|
||||||
#include "AbstractMesh.h"
|
#include "AbstractMesh.h"
|
||||||
#include "MeshPrimitives.h"
|
#include "MeshPrimitives.h"
|
||||||
|
#include "SceneInfo.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
CircleNode::CircleNode(const DiscretePoint& location, unsigned radius)
|
CircleNode::CircleNode(const Point& location, double radius)
|
||||||
: GeometryNode(location),
|
: GeometryNode(location),
|
||||||
mRadius(radius)
|
mRadius(radius)
|
||||||
{
|
{
|
||||||
|
@ -19,7 +20,7 @@ CircleNode::Type CircleNode::getType()
|
||||||
return Type::Circle;
|
return Type::Circle;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned CircleNode::getRadius() const
|
double CircleNode::getRadius() const
|
||||||
{
|
{
|
||||||
return mRadius;
|
return mRadius;
|
||||||
}
|
}
|
||||||
|
@ -36,22 +37,21 @@ SceneItem* CircleNode::getSceneItem(std::size_t idx) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned CircleNode::getNumSceneItems() const
|
std::size_t CircleNode::getNumSceneItems() const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircleNode::setRadius(unsigned radius)
|
void CircleNode::setRadius(double radius)
|
||||||
{
|
{
|
||||||
if (mRadius != radius)
|
if (mRadius != radius)
|
||||||
{
|
{
|
||||||
mRadius = radius;
|
mRadius = radius;
|
||||||
mTransformIsDirty = true;
|
mTransformIsDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircleNode::update(FontsManager* fontsManager)
|
void CircleNode::update(SceneInfo* sceneInfo)
|
||||||
{
|
{
|
||||||
if (!mBackgroundItem || mGeometryIsDirty)
|
if (!mBackgroundItem || mGeometryIsDirty)
|
||||||
{
|
{
|
||||||
|
@ -72,7 +72,7 @@ void CircleNode::update(FontsManager* fontsManager)
|
||||||
|
|
||||||
if (mTransformIsDirty)
|
if (mTransformIsDirty)
|
||||||
{
|
{
|
||||||
mBackgroundItem->updateTransform({mLocation, static_cast<double>(2*mRadius), static_cast<double>(2*mRadius)});
|
mBackgroundItem->updateTransform({mLocation, 2*mRadius, 2*mRadius});
|
||||||
mTransformIsDirty = false;
|
mTransformIsDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
class CircleNode : public GeometryNode
|
class CircleNode : public GeometryNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CircleNode(const DiscretePoint& location, unsigned radius);
|
CircleNode(const Point& location, double radius);
|
||||||
|
|
||||||
Type getType();
|
Type getType();
|
||||||
|
|
||||||
unsigned getRadius() const;
|
double getRadius() const;
|
||||||
|
|
||||||
SceneItem* getSceneItem(std::size_t idx) const override;
|
SceneItem* getSceneItem(std::size_t idx) const override;
|
||||||
unsigned getNumSceneItems() const override;
|
std::size_t getNumSceneItems() const override;
|
||||||
|
|
||||||
void setRadius(unsigned radius);
|
void setRadius(double radius);
|
||||||
|
|
||||||
void update(FontsManager* fontsManager) override;
|
void update(SceneInfo* sceneInfo) override;
|
||||||
private:
|
private:
|
||||||
unsigned mRadius{1};
|
double mRadius{1};
|
||||||
|
|
||||||
std::unique_ptr<SceneModel> mBackgroundItem;
|
std::unique_ptr<SceneModel> mBackgroundItem;
|
||||||
std::unique_ptr<SceneModel> mOutlineItem;
|
std::unique_ptr<SceneModel> mOutlineItem;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
RectangleNode::RectangleNode(const DiscretePoint& loc, unsigned width, unsigned height)
|
RectangleNode::RectangleNode(const Point& loc, double width, double height)
|
||||||
: GeometryNode(loc),
|
: GeometryNode(loc),
|
||||||
mWidth(width),
|
mWidth(width),
|
||||||
mHeight(height)
|
mHeight(height)
|
||||||
|
@ -14,7 +14,7 @@ RectangleNode::RectangleNode(const DiscretePoint& loc, unsigned width, unsigned
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<RectangleNode> RectangleNode::Create(const DiscretePoint& loc, unsigned width, unsigned height)
|
std::unique_ptr<RectangleNode> RectangleNode::Create(const Point& loc, double width, double height)
|
||||||
{
|
{
|
||||||
return std::make_unique<RectangleNode>(loc, width, height);
|
return std::make_unique<RectangleNode>(loc, width, height);
|
||||||
}
|
}
|
||||||
|
@ -36,22 +36,22 @@ SceneItem* RectangleNode::getSceneItem(std::size_t idx) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned RectangleNode::getNumSceneItems() const
|
std::size_t RectangleNode::getNumSceneItems() const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned RectangleNode::getWidth() const
|
double RectangleNode::getWidth() const
|
||||||
{
|
{
|
||||||
return mWidth;
|
return mWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned RectangleNode::getHeight() const
|
double RectangleNode::getHeight() const
|
||||||
{
|
{
|
||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RectangleNode::setWidth(unsigned width)
|
void RectangleNode::setWidth(double width)
|
||||||
{
|
{
|
||||||
if (mWidth != width)
|
if (mWidth != width)
|
||||||
{
|
{
|
||||||
|
@ -60,7 +60,7 @@ void RectangleNode::setWidth(unsigned width)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RectangleNode::setHeight(unsigned height)
|
void RectangleNode::setHeight(double height)
|
||||||
{
|
{
|
||||||
if (mHeight != height)
|
if (mHeight != height)
|
||||||
{
|
{
|
||||||
|
@ -69,7 +69,7 @@ void RectangleNode::setHeight(unsigned height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RectangleNode::update(FontsManager* fontsManager)
|
void RectangleNode::update(SceneInfo* sceneInfo)
|
||||||
{
|
{
|
||||||
if (!mBackgroundItem || mGeometryIsDirty)
|
if (!mBackgroundItem || mGeometryIsDirty)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,23 +7,23 @@
|
||||||
class RectangleNode : public GeometryNode
|
class RectangleNode : public GeometryNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RectangleNode(const DiscretePoint& loc, unsigned width, unsigned height);
|
RectangleNode(const Point& loc, double width, double height);
|
||||||
static std::unique_ptr<RectangleNode> Create(const DiscretePoint& loc, unsigned width, unsigned height);
|
static std::unique_ptr<RectangleNode> Create(const Point& loc, double width, double height);
|
||||||
GeometryNode::Type getType() override;
|
GeometryNode::Type getType() override;
|
||||||
|
|
||||||
unsigned getWidth() const;
|
double getWidth() const;
|
||||||
unsigned getHeight() const;
|
double getHeight() const;
|
||||||
|
|
||||||
SceneItem* getSceneItem(std::size_t idx) const override;
|
SceneItem* getSceneItem(std::size_t idx) const override;
|
||||||
unsigned getNumSceneItems() const override;
|
std::size_t getNumSceneItems() const override;
|
||||||
|
|
||||||
void setWidth(unsigned width);
|
void setWidth(double width);
|
||||||
void setHeight(unsigned height);
|
void setHeight(double height);
|
||||||
|
|
||||||
void update(FontsManager* fontsManager) override;
|
void update(SceneInfo* sceneInfo) override;
|
||||||
private:
|
private:
|
||||||
unsigned mWidth{1};
|
double mWidth{1};
|
||||||
unsigned mHeight{1};
|
double mHeight{1};
|
||||||
|
|
||||||
std::unique_ptr<SceneModel> mBackgroundItem;
|
std::unique_ptr<SceneModel> mBackgroundItem;
|
||||||
std::unique_ptr<SceneModel> mOutlineItem;
|
std::unique_ptr<SceneModel> mOutlineItem;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "AbstractVisualNode.h"
|
#include "AbstractVisualNode.h"
|
||||||
|
|
||||||
AbstractVisualNode::AbstractVisualNode(const DiscretePoint& location, const std::string& name)
|
AbstractVisualNode::AbstractVisualNode(const Point& location, const std::string& name)
|
||||||
: mLocation(location),
|
: mLocation(location),
|
||||||
mName(name)
|
mName(name)
|
||||||
{
|
{
|
||||||
|
@ -12,12 +12,12 @@ SceneItem* AbstractVisualNode::getSceneItem(std::size_t idx) const
|
||||||
return mSceneItems[idx].get();
|
return mSceneItems[idx].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned AbstractVisualNode::getNumSceneItems() const
|
std::size_t AbstractVisualNode::getNumSceneItems() const
|
||||||
{
|
{
|
||||||
return mSceneItems.size();
|
return mSceneItems.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractVisualNode::update(FontsManager* fontsManager)
|
void AbstractVisualNode::update(SceneInfo* sceneInfo)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ void AbstractVisualNode::setIsVisible(bool isVisible)
|
||||||
mIsVisible = isVisible;
|
mIsVisible = isVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned AbstractVisualNode::getNumChildren() const
|
std::size_t AbstractVisualNode::getNumChildren() const
|
||||||
{
|
{
|
||||||
return mChildren.size();
|
return mChildren.size();
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ bool AbstractVisualNode::getIsVisible() const
|
||||||
return mIsVisible;
|
return mIsVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractVisualNode::setLocation(const DiscretePoint& loc)
|
void AbstractVisualNode::setLocation(const Point& loc)
|
||||||
{
|
{
|
||||||
if (mLocation != loc)
|
if (mLocation != loc)
|
||||||
{
|
{
|
|
@ -4,18 +4,18 @@
|
||||||
#include "AbstractMesh.h"
|
#include "AbstractMesh.h"
|
||||||
|
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "DiscretePoint.h"
|
#include "Point.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class FontsManager;
|
struct SceneInfo;
|
||||||
|
|
||||||
class AbstractVisualNode
|
class AbstractVisualNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AbstractVisualNode(const DiscretePoint& location, const std::string& name = {});
|
AbstractVisualNode(const Point& location, const std::string& name = {});
|
||||||
|
|
||||||
virtual ~AbstractVisualNode() = default;
|
virtual ~AbstractVisualNode() = default;
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ public:
|
||||||
|
|
||||||
virtual SceneItem* getSceneItem(std::size_t idx) const;
|
virtual SceneItem* getSceneItem(std::size_t idx) const;
|
||||||
|
|
||||||
virtual unsigned getNumSceneItems() const;
|
virtual std::size_t getNumSceneItems() const;
|
||||||
|
|
||||||
unsigned getNumChildren() const;
|
std::size_t getNumChildren() const;
|
||||||
|
|
||||||
const std::vector<AbstractVisualNode*>& getChildren() const;
|
const std::vector<AbstractVisualNode*>& getChildren() const;
|
||||||
|
|
||||||
|
@ -35,18 +35,18 @@ public:
|
||||||
|
|
||||||
bool getIsVisible() const;
|
bool getIsVisible() const;
|
||||||
|
|
||||||
virtual void update(FontsManager* fontsManager);
|
|
||||||
|
|
||||||
void syncChildren(const std::vector<AbstractVisualNode*>& children);
|
void syncChildren(const std::vector<AbstractVisualNode*>& children);
|
||||||
|
|
||||||
void setIsVisible(bool isVisible);
|
void setIsVisible(bool isVisible);
|
||||||
|
|
||||||
void setName(const std::string& name);
|
void setName(const std::string& name);
|
||||||
|
|
||||||
void setLocation(const DiscretePoint& loc);
|
void setLocation(const Point& loc);
|
||||||
|
|
||||||
|
virtual void update(SceneInfo* sceneInfo);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DiscretePoint mLocation;
|
Point mLocation;
|
||||||
std::vector<std::unique_ptr<SceneItem> > mSceneItems;
|
std::vector<std::unique_ptr<SceneItem> > mSceneItems;
|
||||||
std::unique_ptr<Image<unsigned char> > mImage;
|
std::unique_ptr<Image<unsigned char> > mImage;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "GeometryNode.h"
|
#include "GeometryNode.h"
|
||||||
|
|
||||||
GeometryNode::GeometryNode(const DiscretePoint& location)
|
GeometryNode::GeometryNode(const Point& location)
|
||||||
: MaterialNode(location),
|
: MaterialNode(location),
|
||||||
mStrokeThickness(1),
|
mStrokeThickness(1),
|
||||||
mType(Type::Path)
|
mType(Type::Path)
|
|
@ -16,7 +16,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GeometryNode(const DiscretePoint& location);
|
GeometryNode(const Point& location);
|
||||||
virtual ~GeometryNode() = default;
|
virtual ~GeometryNode() = default;
|
||||||
|
|
||||||
virtual Type getType() = 0;
|
virtual Type getType() = 0;
|
||||||
|
@ -34,7 +34,7 @@ protected:
|
||||||
class LineNode : public GeometryNode
|
class LineNode : public GeometryNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LineNode(const DiscretePoint& location)
|
LineNode(const Point& location)
|
||||||
: GeometryNode(location)
|
: GeometryNode(location)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "MeshPrimitives.h"
|
#include "MeshPrimitives.h"
|
||||||
|
|
||||||
GridNode::GridNode(const DiscretePoint& location)
|
GridNode::GridNode(const Point& location)
|
||||||
: MaterialNode(location)
|
: MaterialNode(location)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ void GridNode::setNumY(unsigned numY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridNode::setWidth(unsigned width)
|
void GridNode::setWidth(double width)
|
||||||
{
|
{
|
||||||
if (mWidth != width)
|
if (mWidth != width)
|
||||||
{
|
{
|
||||||
|
@ -35,7 +35,7 @@ void GridNode::setWidth(unsigned width)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridNode::setHeight(unsigned height)
|
void GridNode::setHeight(double height)
|
||||||
{
|
{
|
||||||
if (mHeight != height)
|
if (mHeight != height)
|
||||||
{
|
{
|
||||||
|
@ -65,12 +65,12 @@ SceneItem* GridNode::getSceneItem(std::size_t idx) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GridNode::getNumSceneItems() const
|
std::size_t GridNode::getNumSceneItems() const
|
||||||
{
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridNode::update(FontsManager* fontsManager)
|
void GridNode::update(SceneInfo* sceneInfo)
|
||||||
{
|
{
|
||||||
if (!mBackgroundModel || mDataDirty)
|
if (!mBackgroundModel || mDataDirty)
|
||||||
{
|
{
|
|
@ -7,7 +7,7 @@ class GridNode : public MaterialNode
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GridNode(const DiscretePoint& location);
|
GridNode(const Point& location);
|
||||||
|
|
||||||
void setNumX(unsigned numX);
|
void setNumX(unsigned numX);
|
||||||
|
|
||||||
|
@ -16,18 +16,18 @@ public:
|
||||||
void setData(const std::vector<Color>& colors);
|
void setData(const std::vector<Color>& colors);
|
||||||
|
|
||||||
SceneItem* getSceneItem(std::size_t idx) const override;
|
SceneItem* getSceneItem(std::size_t idx) const override;
|
||||||
unsigned getNumSceneItems() const override;
|
std::size_t getNumSceneItems() const override;
|
||||||
|
|
||||||
void update(FontsManager* fontsManager) override;
|
void update(SceneInfo* sceneInfo) override;
|
||||||
|
|
||||||
void setWidth(unsigned width);
|
void setWidth(double width);
|
||||||
void setHeight(unsigned height);
|
void setHeight(double height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned mNumberX{5};
|
unsigned mNumberX{5};
|
||||||
unsigned mNumberY{5};
|
unsigned mNumberY{5};
|
||||||
unsigned mWidth{1};
|
double mWidth{1};
|
||||||
unsigned mHeight{1};
|
double mHeight{1};
|
||||||
bool mDataDirty = true;
|
bool mDataDirty = true;
|
||||||
std::vector<Color> mData;
|
std::vector<Color> mData;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
MaterialNode::MaterialNode(const DiscretePoint& location)
|
MaterialNode::MaterialNode(const Point& location)
|
||||||
: AbstractVisualNode(location),
|
: AbstractVisualNode(location),
|
||||||
mFillColor(Color(255, 255, 255)),
|
mFillColor(Color(255, 255, 255)),
|
||||||
mStrokeColor(Color(0, 0, 0))
|
mStrokeColor(Color(0, 0, 0))
|
|
@ -7,7 +7,7 @@
|
||||||
class MaterialNode : public AbstractVisualNode
|
class MaterialNode : public AbstractVisualNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MaterialNode(const DiscretePoint& location);
|
MaterialNode(const Point& location);
|
||||||
|
|
||||||
const Color& getFillColor() const;
|
const Color& getFillColor() const;
|
||||||
const Color& getStrokeColor() const;
|
const Color& getStrokeColor() const;
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
MeshNode::MeshNode(const DiscretePoint& location)
|
MeshNode::MeshNode(const Point& location)
|
||||||
: MaterialNode(location)
|
: MaterialNode(location)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshNode::setWidth(unsigned width)
|
void MeshNode::setWidth(double width)
|
||||||
{
|
{
|
||||||
if (mWidth != width)
|
if (mWidth != width)
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ void MeshNode::setWidth(unsigned width)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshNode::setHeight(unsigned height)
|
void MeshNode::setHeight(double height)
|
||||||
{
|
{
|
||||||
if (mHeight != height)
|
if (mHeight != height)
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ SceneItem* MeshNode::getSceneItem(std::size_t idx) const
|
||||||
return mModel.get();
|
return mModel.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned MeshNode::getNumSceneItems() const
|
std::size_t MeshNode::getNumSceneItems() const
|
||||||
{
|
{
|
||||||
if (mWorkingMesh)
|
if (mWorkingMesh)
|
||||||
{
|
{
|
||||||
|
@ -49,13 +49,13 @@ unsigned MeshNode::getNumSceneItems() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshNode::update(FontsManager* fontsManager)
|
void MeshNode::update(SceneInfo* sceneInfo)
|
||||||
{
|
{
|
||||||
if (!mModel || mMeshIsDirty)
|
if (!mModel || mMeshIsDirty)
|
||||||
{
|
{
|
||||||
if (!mModel)
|
if (!mModel)
|
||||||
{
|
{
|
||||||
mModel = std::make_unique<SceneModel>(nullptr);
|
mModel = std::make_unique<SceneModel>();
|
||||||
mModel->setName(mName + "_MeshModel");
|
mModel->setName(mName + "_MeshModel");
|
||||||
mModel->setShowOutline(true);
|
mModel->setShowOutline(true);
|
||||||
}
|
}
|
|
@ -7,22 +7,22 @@ class AbstractMesh;
|
||||||
class MeshNode : public MaterialNode
|
class MeshNode : public MaterialNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MeshNode(const DiscretePoint& location);
|
MeshNode(const Point& location);
|
||||||
void setMesh(AbstractMesh* mesh);
|
void setMesh(AbstractMesh* mesh);
|
||||||
|
|
||||||
SceneItem* getSceneItem(std::size_t idx) const override;
|
SceneItem* getSceneItem(std::size_t idx) const override;
|
||||||
unsigned getNumSceneItems() const override;
|
std::size_t getNumSceneItems() const override;
|
||||||
|
|
||||||
void setWidth(unsigned width);
|
void setWidth(double width);
|
||||||
void setHeight(unsigned height);
|
void setHeight(double height);
|
||||||
|
|
||||||
void update(FontsManager* fontsManager) override;
|
void update(SceneInfo* sceneInfo) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mMeshIsDirty{true};
|
bool mMeshIsDirty{true};
|
||||||
AbstractMesh* mWorkingMesh{nullptr};
|
AbstractMesh* mWorkingMesh{nullptr};
|
||||||
|
|
||||||
unsigned mWidth{1};
|
double mWidth{1};
|
||||||
unsigned mHeight{1};
|
double mHeight{1};
|
||||||
std::unique_ptr<SceneModel> mModel;
|
std::unique_ptr<SceneModel> mModel;
|
||||||
};
|
};
|
|
@ -6,6 +6,7 @@
|
||||||
#include "MeshPrimitives.h"
|
#include "MeshPrimitives.h"
|
||||||
#include "FontItem.h"
|
#include "FontItem.h"
|
||||||
#include "FontGlyph.h"
|
#include "FontGlyph.h"
|
||||||
|
#include "SceneInfo.h"
|
||||||
|
|
||||||
#include "SceneText.h"
|
#include "SceneText.h"
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
TextNode::TextNode(const std::string& content, const DiscretePoint& loc)
|
TextNode::TextNode(const std::string& content, const Point& loc)
|
||||||
: MaterialNode(loc)
|
: MaterialNode(loc)
|
||||||
{
|
{
|
||||||
mTextData.mContent= content;
|
mTextData.mContent= content;
|
||||||
|
@ -26,7 +27,7 @@ TextNode::~TextNode()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<TextNode> TextNode::Create(const std::string& content, const DiscretePoint& loc)
|
std::unique_ptr<TextNode> TextNode::Create(const std::string& content, const Point& loc)
|
||||||
{
|
{
|
||||||
return std::make_unique<TextNode>(content, loc);
|
return std::make_unique<TextNode>(content, loc);
|
||||||
}
|
}
|
||||||
|
@ -41,17 +42,17 @@ std::string TextNode::getContent() const
|
||||||
return mTextData.mContent;
|
return mTextData.mContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned TextNode::getWidth() const
|
double TextNode::getWidth() const
|
||||||
{
|
{
|
||||||
return mWidth;
|
return mWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned TextNode::getHeight() const
|
double TextNode::getHeight() const
|
||||||
{
|
{
|
||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextNode::setWidth(unsigned width)
|
void TextNode::setWidth(double width)
|
||||||
{
|
{
|
||||||
if (mWidth != width)
|
if (mWidth != width)
|
||||||
{
|
{
|
||||||
|
@ -60,7 +61,7 @@ void TextNode::setWidth(unsigned width)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextNode::setHeight(unsigned height)
|
void TextNode::setHeight(double height)
|
||||||
{
|
{
|
||||||
if (mHeight != height)
|
if (mHeight != height)
|
||||||
{
|
{
|
||||||
|
@ -90,7 +91,7 @@ SceneItem* TextNode::getSceneItem(std::size_t idx) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned TextNode::getNumSceneItems() const
|
std::size_t TextNode::getNumSceneItems() const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +137,7 @@ void TextNode::updateLines(FontsManager* fontsManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextNode::update(FontsManager* fontsManager)
|
void TextNode::update(SceneInfo* sceneInfo)
|
||||||
{
|
{
|
||||||
if (!mTextItem)
|
if (!mTextItem)
|
||||||
{
|
{
|
||||||
|
@ -146,7 +147,7 @@ void TextNode::update(FontsManager* fontsManager)
|
||||||
|
|
||||||
if (mTransformIsDirty || mContentIsDirty)
|
if (mTransformIsDirty || mContentIsDirty)
|
||||||
{
|
{
|
||||||
updateLines(fontsManager);
|
updateLines(sceneInfo->mFontsManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mContentIsDirty || mLinesAreDirty)
|
if (mContentIsDirty || mLinesAreDirty)
|
|
@ -8,30 +8,32 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
class FontsManager;
|
||||||
|
|
||||||
class TextNode : public MaterialNode
|
class TextNode : public MaterialNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextNode(const std::string& content, const DiscretePoint& loc);
|
TextNode(const std::string& content, const Point& loc);
|
||||||
|
|
||||||
~TextNode();
|
~TextNode();
|
||||||
|
|
||||||
static std::unique_ptr<TextNode> Create(const std::string& content, const DiscretePoint& loc);
|
static std::unique_ptr<TextNode> Create(const std::string& content, const Point& loc);
|
||||||
|
|
||||||
std::string getContent() const;
|
std::string getContent() const;
|
||||||
std::string getFontLabel() const;
|
std::string getFontLabel() const;
|
||||||
|
|
||||||
SceneItem* getSceneItem(std::size_t idx) const override;
|
SceneItem* getSceneItem(std::size_t idx) const override;
|
||||||
unsigned getNumSceneItems() const override;
|
std::size_t getNumSceneItems() const override;
|
||||||
|
|
||||||
unsigned getWidth() const;
|
double getWidth() const;
|
||||||
unsigned getHeight() const;
|
double getHeight() const;
|
||||||
|
|
||||||
void setWidth(unsigned width);
|
void setWidth(double width);
|
||||||
void setHeight(unsigned height);
|
void setHeight(double height);
|
||||||
|
|
||||||
void setContent(const std::string& content);
|
void setContent(const std::string& content);
|
||||||
|
|
||||||
void update(FontsManager* fontsManager) override;
|
void update(SceneInfo* sceneInfo) override;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void updateLines(FontsManager* fontsManager);
|
void updateLines(FontsManager* fontsManager);
|
||||||
|
@ -40,8 +42,8 @@ private:
|
||||||
bool mContentIsDirty{true};
|
bool mContentIsDirty{true};
|
||||||
bool mLinesAreDirty{true};
|
bool mLinesAreDirty{true};
|
||||||
|
|
||||||
unsigned mWidth{1};
|
double mWidth{1};
|
||||||
unsigned mHeight{1};
|
double mHeight{1};
|
||||||
|
|
||||||
std::unique_ptr<SceneItem> mTextItem;
|
std::unique_ptr<SceneItem> mTextItem;
|
||||||
};
|
};
|
|
@ -7,7 +7,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Scene::Scene()
|
Scene::Scene()
|
||||||
: mRootNode(std::make_unique<RootNode>())
|
: mRootNode(std::make_unique<RootNode>()),
|
||||||
|
mSceneInfo(std::make_unique<SceneInfo>())
|
||||||
{
|
{
|
||||||
mRootNode->setName("Scene_RootNode");
|
mRootNode->setName("Scene_RootNode");
|
||||||
}
|
}
|
||||||
|
@ -19,8 +20,10 @@ Scene::~Scene()
|
||||||
|
|
||||||
void Scene::update(FontsManager* fontsManager)
|
void Scene::update(FontsManager* fontsManager)
|
||||||
{
|
{
|
||||||
|
mSceneInfo->mFontsManager = fontsManager;
|
||||||
|
|
||||||
mSceneItems.clear();
|
mSceneItems.clear();
|
||||||
updateNode(mRootNode.get(), fontsManager);
|
updateNode(mRootNode.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::addNode(AbstractVisualNode* node)
|
void Scene::addNode(AbstractVisualNode* node)
|
||||||
|
@ -33,17 +36,17 @@ bool Scene::isEmpty() const
|
||||||
return mRootNode->getNumChildren() == 0;
|
return mRootNode->getNumChildren() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::updateNode(AbstractVisualNode* node, FontsManager* fontsManager)
|
void Scene::updateNode(AbstractVisualNode* node)
|
||||||
{
|
{
|
||||||
for (auto child : node->getChildren())
|
for (auto child : node->getChildren())
|
||||||
{
|
{
|
||||||
if (child->getIsVisible())
|
if (child->getIsVisible())
|
||||||
{
|
{
|
||||||
updateNode(child, fontsManager);
|
updateNode(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node->update(fontsManager);
|
node->update(mSceneInfo.get());
|
||||||
|
|
||||||
for (std::size_t idx=0; idx< node->getNumSceneItems(); idx++)
|
for (std::size_t idx=0; idx< node->getNumSceneItems(); idx++)
|
||||||
{
|
{
|
||||||
|
@ -58,3 +61,13 @@ const std::vector<SceneItem*>& Scene::getItems() const
|
||||||
{
|
{
|
||||||
return mSceneItems;
|
return mSceneItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Scene::shouldShowMeshOutline() const
|
||||||
|
{
|
||||||
|
return mSceneInfo->mShowMeshOutline;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scene::setShowMeshOutline(bool shouldShow)
|
||||||
|
{
|
||||||
|
mSceneInfo->mShowMeshOutline = shouldShow;
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "TextData.h"
|
#include "TextData.h"
|
||||||
|
#include "SceneInfo.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -8,7 +9,6 @@
|
||||||
class RootNode;
|
class RootNode;
|
||||||
class AbstractVisualNode;
|
class AbstractVisualNode;
|
||||||
class SceneItem;
|
class SceneItem;
|
||||||
class FontsManager;
|
|
||||||
|
|
||||||
class Scene
|
class Scene
|
||||||
{
|
{
|
||||||
|
@ -23,21 +23,15 @@ public:
|
||||||
|
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
|
||||||
bool shouldShowMeshOutline() const
|
bool shouldShowMeshOutline() const;
|
||||||
{
|
|
||||||
return mShowMeshOutline;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setShowMeshOutline(bool shouldShow)
|
void setShowMeshOutline(bool shouldShow);
|
||||||
{
|
|
||||||
mShowMeshOutline = shouldShow;
|
|
||||||
}
|
|
||||||
|
|
||||||
void update(FontsManager* fontsManager = nullptr);
|
void update(FontsManager* fontsManager = nullptr);
|
||||||
private:
|
private:
|
||||||
void updateNode(AbstractVisualNode* node, FontsManager* fontsManager);
|
void updateNode(AbstractVisualNode* node);
|
||||||
|
|
||||||
std::unique_ptr<RootNode> mRootNode;
|
std::unique_ptr<RootNode> mRootNode;
|
||||||
std::vector<SceneItem*> mSceneItems;
|
std::vector<SceneItem*> mSceneItems;
|
||||||
|
std::unique_ptr<SceneInfo> mSceneInfo;
|
||||||
bool mShowMeshOutline{false};
|
|
||||||
};
|
};
|
10
src/visual_elements/scene/SceneInfo.h
Normal file
10
src/visual_elements/scene/SceneInfo.h
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "FontsManager.h"
|
||||||
|
|
||||||
|
struct SceneInfo
|
||||||
|
{
|
||||||
|
bool mSupportsGeometryPrimitives{ false };
|
||||||
|
bool mShowMeshOutline{ false };
|
||||||
|
FontsManager* mFontsManager{ nullptr };
|
||||||
|
};
|
70
src/visual_elements/scene/SceneModel.cpp
Normal file
70
src/visual_elements/scene/SceneModel.cpp
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
#include "SceneModel.h"
|
||||||
|
|
||||||
|
#include "AbstractGeometricItem.h"
|
||||||
|
#include "AbstractMesh.h"
|
||||||
|
|
||||||
|
SceneModel::SceneModel(std::unique_ptr<AbstractMesh> mesh)
|
||||||
|
: SceneItem(),
|
||||||
|
mMesh(std::move(mesh))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SceneModel::SceneModel(std::unique_ptr<AbstractGeometricItem> geometry)
|
||||||
|
: SceneItem(),
|
||||||
|
mGeometry(std::move(geometry))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractMesh* SceneModel::getMesh() const
|
||||||
|
{
|
||||||
|
if (mMesh)
|
||||||
|
{
|
||||||
|
return mMesh.get();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return mRawMesh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractGeometricItem* SceneModel::getGeometry() const
|
||||||
|
{
|
||||||
|
return mGeometry.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
SceneItem::Type SceneModel::getType() const
|
||||||
|
{
|
||||||
|
return SceneItem::Type::MODEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneModel::setShowOutline(bool showOutline)
|
||||||
|
{
|
||||||
|
mShowOutline = showOutline;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SceneModel::getShowOutline() const
|
||||||
|
{
|
||||||
|
return mShowOutline;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneModel::updateMesh(std::unique_ptr<AbstractMesh> mesh)
|
||||||
|
{
|
||||||
|
mMesh = std::move(mesh);
|
||||||
|
mGeometryIsDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneModel::updateGeometry(std::unique_ptr<AbstractGeometricItem> geometry)
|
||||||
|
{
|
||||||
|
mGeometry = std::move(geometry);
|
||||||
|
mGeometryIsDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneModel::updateMesh(AbstractMesh* mesh)
|
||||||
|
{
|
||||||
|
mRawMesh = mesh;
|
||||||
|
mGeometryIsDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SceneItem.h"
|
#include "SceneItem.h"
|
||||||
|
#include "AbstractGeometricItem.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -9,37 +10,33 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class AbstractMesh;
|
class AbstractMesh;
|
||||||
//class Texture;
|
|
||||||
|
|
||||||
class SceneModel : public SceneItem
|
class SceneModel : public SceneItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SceneModel(std::unique_ptr<AbstractMesh> mesh);
|
SceneModel() = default;
|
||||||
|
explicit SceneModel(std::unique_ptr<AbstractMesh> mesh);
|
||||||
|
explicit SceneModel(std::unique_ptr<AbstractGeometricItem> geometry);
|
||||||
|
|
||||||
|
AbstractGeometricItem* getGeometry() const;
|
||||||
AbstractMesh* getMesh() const;
|
AbstractMesh* getMesh() const;
|
||||||
|
bool getShowOutline() const;
|
||||||
|
Type getType() const override;
|
||||||
|
|
||||||
|
void setShowOutline(bool showOutline);
|
||||||
|
|
||||||
|
void updateGeometry(std::unique_ptr<AbstractGeometricItem> geometry);
|
||||||
void updateMesh(std::unique_ptr<AbstractMesh> mesh);
|
void updateMesh(std::unique_ptr<AbstractMesh> mesh);
|
||||||
void updateMesh(AbstractMesh* mesh);
|
void updateMesh(AbstractMesh* mesh);
|
||||||
|
|
||||||
void setShowOutline(bool showOutline)
|
|
||||||
{
|
|
||||||
mShowOutline = showOutline;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getShowOutline() const
|
|
||||||
{
|
|
||||||
return mShowOutline;
|
|
||||||
}
|
|
||||||
|
|
||||||
Type getType() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
AbstractMesh* mRawMesh{nullptr};
|
AbstractMesh* mRawMesh{nullptr};
|
||||||
std::unique_ptr<AbstractMesh> mMesh;
|
std::unique_ptr<AbstractMesh> mMesh;
|
||||||
std::unique_ptr<Texture> mColorMap;
|
std::unique_ptr<Texture> mColorMap;
|
||||||
|
|
||||||
bool mMeshIsDirty{true};
|
std::unique_ptr<AbstractGeometricItem> mGeometry;
|
||||||
|
|
||||||
|
bool mGeometryIsDirty{true};
|
||||||
bool mColorMapIsDirty{true};
|
bool mColorMapIsDirty{true};
|
||||||
bool mShowOutline{false};
|
bool mShowOutline{false};
|
||||||
};
|
};
|
|
@ -8,15 +8,15 @@ set(PLATFORM_UNIT_TEST_FILES
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(GRAPHICS_UNIT_TEST_FILES
|
|
||||||
graphics/TestRasterizer.cpp
|
|
||||||
${PLATFORM_UNIT_TEST_FILES}
|
|
||||||
PARENT_SCOPE
|
|
||||||
)
|
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
|
||||||
|
list(APPEND PLATFORM_UNIT_TEST_FILES
|
||||||
|
graphics/TestD2DOffScreenRendering.cpp
|
||||||
|
)
|
||||||
set(GRAPHICS_UI_TEST_FILES
|
set(GRAPHICS_UI_TEST_FILES
|
||||||
graphics/TestDirectXRendering.cpp
|
graphics/TestDirectXRendering.cpp
|
||||||
|
graphics/TestD2DRendering.cpp
|
||||||
PARENT_SCOPE
|
PARENT_SCOPE
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
@ -30,3 +30,9 @@ set(GRAPHICS_UI_TEST_DEPENDENCIES
|
||||||
graphics client
|
graphics client
|
||||||
PARENT_SCOPE
|
PARENT_SCOPE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(GRAPHICS_UNIT_TEST_FILES
|
||||||
|
graphics/TestRasterizer.cpp
|
||||||
|
${PLATFORM_UNIT_TEST_FILES}
|
||||||
|
PARENT_SCOPE
|
||||||
|
)
|
39
test/graphics/TestD2dOffScreenRendering.cpp
Normal file
39
test/graphics/TestD2dOffScreenRendering.cpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#include "TestCase.h"
|
||||||
|
#include "TestCaseRunner.h"
|
||||||
|
|
||||||
|
#include "TestUiApplication.h"
|
||||||
|
|
||||||
|
#include "TestFramework.h"
|
||||||
|
#include "TestUtils.h"
|
||||||
|
|
||||||
|
#include "DrawingSurface.h"
|
||||||
|
#include "DrawingContext.h"
|
||||||
|
#include "AbstractPainter.h"
|
||||||
|
#include "Image.h"
|
||||||
|
#include "PngWriter.h"
|
||||||
|
|
||||||
|
#include "RectangleNode.h"
|
||||||
|
#include "Scene.h"
|
||||||
|
|
||||||
|
TEST_CASE(TestD2dOffScreenRendering, "graphics")
|
||||||
|
{
|
||||||
|
auto surface = std::make_unique<DrawingSurface>();
|
||||||
|
surface->setSize(100, 100);
|
||||||
|
|
||||||
|
auto drawing_context = std::make_unique<DrawingContext>(surface.get());
|
||||||
|
|
||||||
|
auto rect = std::make_unique<RectangleNode>(DiscretePoint(10, 10), 10.0, 20.0);
|
||||||
|
|
||||||
|
auto scene = surface->getScene();
|
||||||
|
|
||||||
|
scene->addNode(rect.get());
|
||||||
|
scene->update();
|
||||||
|
|
||||||
|
drawing_context->paint();
|
||||||
|
|
||||||
|
auto image = surface->getImage();
|
||||||
|
|
||||||
|
PngWriter writer;
|
||||||
|
writer.setPath(TestUtils::getTestOutputDir(__FILE__) / "out.png");
|
||||||
|
//writer.write(image);
|
||||||
|
};
|
22
test/graphics/TestD2dRendering.cpp
Normal file
22
test/graphics/TestD2dRendering.cpp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#include "TestCase.h"
|
||||||
|
#include "TestCaseRunner.h"
|
||||||
|
|
||||||
|
#include "TestUiApplication.h"
|
||||||
|
|
||||||
|
#include "TestFramework.h"
|
||||||
|
|
||||||
|
#include "DesktopManager.h"
|
||||||
|
#include "MeshPrimitives.h"
|
||||||
|
#include "MeshNode.h"
|
||||||
|
#include "TextNode.h"
|
||||||
|
#include "Scene.h"
|
||||||
|
#include "Widget.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
TEST_CASE(TestD2dRendering, "graphics")
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
Loading…
Reference in a new issue