Clean up of scene nodes to support 2d and non int positioning.

This commit is contained in:
jmsgrogan 2023-01-11 10:21:18 +00:00
parent 1eeaebd0a9
commit 672b31b603
45 changed files with 341 additions and 200 deletions

View file

@ -2,7 +2,7 @@
#include "CircleNode.h"
BlochSphereNode::BlochSphereNode(const DiscretePoint& location)
BlochSphereNode::BlochSphereNode(const Point& location)
: AbstractVisualNode(location, "BlochSphereNode")
{
@ -23,7 +23,7 @@ void BlochSphereNode::setSize(double size)
}
}
void BlochSphereNode::update(FontsManager* fontsManager)
void BlochSphereNode::update(SceneInfo* sceneInfo)
{
if (!mContentDirty)
{

View file

@ -11,11 +11,11 @@ class LineNode;
class BlochSphereNode : public AbstractVisualNode
{
public:
BlochSphereNode(const DiscretePoint& location);
BlochSphereNode(const Point& location);
void setContent(BlochSphere* content);
void update(FontsManager* fontsManager) override;
void update(SceneInfo* sceneInfo) override;
void setSize(double size);
private:

View file

@ -13,7 +13,7 @@
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 });

View file

@ -13,6 +13,7 @@ public:
virtual ~AbstractPainter() = default;
virtual void paint() = 0;
virtual bool supportsGeometryPrimitives() const { return false; };
protected:
DrawingContext* mDrawingContext{ nullptr };

View file

@ -21,6 +21,7 @@ list(APPEND graphics_HEADERS
DrawingContext.h
PainterFactory.h
AbstractPainter.h
DrawingSurface.h
)
if(UNIX)
set(OpenGL_GL_PREFERENCE "GLVND")

View file

@ -45,3 +45,8 @@ AbstractPainter* DrawingContext::getPainter() const
{
return mPainter.get();
}
bool DrawingContext::painterSupportsGeometryPrimitives() const
{
return mPainter->supportsGeometryPrimitives();
}

View file

@ -16,7 +16,7 @@ enum class DrawingMode
class DrawingContext
{
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);
@ -28,6 +28,8 @@ public:
AbstractPainter* getPainter() const;
bool painterSupportsGeometryPrimitives() const;
private:
DrawingMode mDrawingMode;
FontsManager* mFontsManager{nullptr};

View file

@ -39,7 +39,7 @@ void DirectXMesh::update(DrawingContext* context, ID3D12Device* device)
y = 2 * y - 1;
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]);
MLOG_INFO("Adding vert: " << x << " | " << y);
mVertexBuffer.push_back(vert);
@ -94,7 +94,7 @@ void DirectXMesh::createD3dVertexBuffer(ID3D12Device* device)
mVertexBufferView.BufferLocation = mD3dVertexBuffer->GetGPUVirtualAddress();
mVertexBufferView.StrideInBytes = sizeof(Vertex);
mVertexBufferView.SizeInBytes = buffer_size;
mVertexBufferView.SizeInBytes = static_cast<UINT>(buffer_size);
}
void DirectXMesh::uploadVertexBuffer(unsigned char* pBuffer) const
@ -116,7 +116,7 @@ void DirectXMesh::createD3dIndexBuffer(ID3D12Device* device)
mD3dIndexBuffer->Unmap(0, nullptr);
mIndexBufferView.BufferLocation = mD3dIndexBuffer->GetGPUVirtualAddress();
mIndexBufferView.SizeInBytes = buffer_size;
mIndexBufferView.SizeInBytes = static_cast<UINT>(buffer_size);
mIndexBufferView.Format = DXGI_FORMAT_R16_UINT;
}

View file

@ -35,7 +35,7 @@ void DirectXTextPainter::initializeBrush(ID2D1DeviceContext2* d2dContext)
d2dContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &mTextBrush);
}
void DirectXTextPainter::updateTextFormat(IDWriteFactory* directWriteFactory, unsigned fontSize)
void DirectXTextPainter::updateTextFormat(IDWriteFactory* directWriteFactory, float fontSize)
{
directWriteFactory->CreateTextFormat(
L"Verdana",
@ -54,9 +54,9 @@ void DirectXTextPainter::updateTextFormat(IDWriteFactory* directWriteFactory, un
void DirectXTextPainter::paint(SceneText* text, DrawingContext* context, ID2D1DeviceContext2* d2dContext, IDWriteFactory* directWriteFactory)
{
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);

View file

@ -30,7 +30,7 @@ public:
private:
void initializeBrush(ID2D1DeviceContext2* d2dContext);
void updateTextFormat(IDWriteFactory* directWriteFactory, unsigned fontSize);
void updateTextFormat(IDWriteFactory* directWriteFactory, float fontSize);
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> mTextBrush;
Microsoft::WRL::ComPtr<IDWriteTextFormat> mTextFormat;

View file

@ -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())
{
@ -170,9 +170,9 @@ void PngWriter::write(const std::unique_ptr<Image<unsigned char> >& image)
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();
mInStream = std::move(image_bit_stream);
@ -221,3 +221,8 @@ void PngWriter::write(const std::unique_ptr<Image<unsigned char> >& image)
mWorkingFile->close();
}
}
void PngWriter::write(const std::unique_ptr<Image<unsigned char> >& image)
{
write(image.get());
}

View file

@ -29,6 +29,7 @@ public:
void setPngInfo(const PngInfo& info);
void write(const std::unique_ptr<Image<unsigned char> >& image);
void write(Image<unsigned char>* image);
private:
void writeSignature();

View file

@ -1,25 +1,34 @@
set(MODULE_NAME visual_elements)
list(APPEND visual_elements_LIB_INCLUDES
GeometryNode.cpp
basic_shapes/RectangleNode.h
basic_shapes/RectangleNode.cpp
basic_shapes/CircleNode.h
basic_shapes/CircleNode.cpp
basic_shapes/LineNode.h
basic_shapes/LineNode.cpp
MaterialNode.cpp
MeshNode.cpp
TextNode.cpp
Scene.cpp
SceneModel.cpp
SceneItem.cpp
SceneText.cpp
scene/Scene.h
scene/Scene.cpp
scene/SceneInfo.h
scene/SceneModel.h
scene/SceneModel.cpp
scene/SceneItem.h
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
GridNode.cpp
AbstractVisualNode.h
AbstractVisualNode.cpp
)
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
${CMAKE_CURRENT_SOURCE_DIR}
${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)

View file

@ -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;
}

View file

@ -4,10 +4,11 @@
#include "SceneModel.h"
#include "AbstractMesh.h"
#include "MeshPrimitives.h"
#include "SceneInfo.h"
#include <iostream>
CircleNode::CircleNode(const DiscretePoint& location, unsigned radius)
CircleNode::CircleNode(const Point& location, double radius)
: GeometryNode(location),
mRadius(radius)
{
@ -19,7 +20,7 @@ CircleNode::Type CircleNode::getType()
return Type::Circle;
}
unsigned CircleNode::getRadius() const
double CircleNode::getRadius() const
{
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;
}
void CircleNode::setRadius(unsigned radius)
void CircleNode::setRadius(double radius)
{
if (mRadius != radius)
{
mRadius = radius;
mTransformIsDirty = true;
}
}
void CircleNode::update(FontsManager* fontsManager)
void CircleNode::update(SceneInfo* sceneInfo)
{
if (!mBackgroundItem || mGeometryIsDirty)
{
@ -72,7 +72,7 @@ void CircleNode::update(FontsManager* fontsManager)
if (mTransformIsDirty)
{
mBackgroundItem->updateTransform({mLocation, static_cast<double>(2*mRadius), static_cast<double>(2*mRadius)});
mBackgroundItem->updateTransform({mLocation, 2*mRadius, 2*mRadius});
mTransformIsDirty = false;
}

View file

@ -5,20 +5,20 @@
class CircleNode : public GeometryNode
{
public:
CircleNode(const DiscretePoint& location, unsigned radius);
CircleNode(const Point& location, double radius);
Type getType();
unsigned getRadius() const;
double getRadius() const;
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:
unsigned mRadius{1};
double mRadius{1};
std::unique_ptr<SceneModel> mBackgroundItem;
std::unique_ptr<SceneModel> mOutlineItem;

View file

@ -6,7 +6,7 @@
#include <iostream>
RectangleNode::RectangleNode(const DiscretePoint& loc, unsigned width, unsigned height)
RectangleNode::RectangleNode(const Point& loc, double width, double height)
: GeometryNode(loc),
mWidth(width),
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);
}
@ -36,22 +36,22 @@ SceneItem* RectangleNode::getSceneItem(std::size_t idx) const
}
}
unsigned RectangleNode::getNumSceneItems() const
std::size_t RectangleNode::getNumSceneItems() const
{
return 1;
}
unsigned RectangleNode::getWidth() const
double RectangleNode::getWidth() const
{
return mWidth;
}
unsigned RectangleNode::getHeight() const
double RectangleNode::getHeight() const
{
return mHeight;
}
void RectangleNode::setWidth(unsigned width)
void RectangleNode::setWidth(double 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)
{
@ -69,7 +69,7 @@ void RectangleNode::setHeight(unsigned height)
}
}
void RectangleNode::update(FontsManager* fontsManager)
void RectangleNode::update(SceneInfo* sceneInfo)
{
if (!mBackgroundItem || mGeometryIsDirty)
{

View file

@ -7,23 +7,23 @@
class RectangleNode : public GeometryNode
{
public:
RectangleNode(const DiscretePoint& loc, unsigned width, unsigned height);
static std::unique_ptr<RectangleNode> Create(const DiscretePoint& loc, unsigned width, unsigned height);
RectangleNode(const Point& loc, double width, double height);
static std::unique_ptr<RectangleNode> Create(const Point& loc, double width, double height);
GeometryNode::Type getType() override;
unsigned getWidth() const;
unsigned getHeight() const;
double getWidth() const;
double getHeight() const;
SceneItem* getSceneItem(std::size_t idx) const override;
unsigned getNumSceneItems() const override;
std::size_t getNumSceneItems() const override;
void setWidth(unsigned width);
void setHeight(unsigned height);
void setWidth(double width);
void setHeight(double height);
void update(FontsManager* fontsManager) override;
void update(SceneInfo* sceneInfo) override;
private:
unsigned mWidth{1};
unsigned mHeight{1};
double mWidth{1};
double mHeight{1};
std::unique_ptr<SceneModel> mBackgroundItem;
std::unique_ptr<SceneModel> mOutlineItem;

View file

@ -1,6 +1,6 @@
#include "AbstractVisualNode.h"
AbstractVisualNode::AbstractVisualNode(const DiscretePoint& location, const std::string& name)
AbstractVisualNode::AbstractVisualNode(const Point& location, const std::string& name)
: mLocation(location),
mName(name)
{
@ -12,12 +12,12 @@ SceneItem* AbstractVisualNode::getSceneItem(std::size_t idx) const
return mSceneItems[idx].get();
}
unsigned AbstractVisualNode::getNumSceneItems() const
std::size_t AbstractVisualNode::getNumSceneItems() const
{
return mSceneItems.size();
}
void AbstractVisualNode::update(FontsManager* fontsManager)
void AbstractVisualNode::update(SceneInfo* sceneInfo)
{
}
@ -47,7 +47,7 @@ void AbstractVisualNode::setIsVisible(bool isVisible)
mIsVisible = isVisible;
}
unsigned AbstractVisualNode::getNumChildren() const
std::size_t AbstractVisualNode::getNumChildren() const
{
return mChildren.size();
}
@ -67,7 +67,7 @@ bool AbstractVisualNode::getIsVisible() const
return mIsVisible;
}
void AbstractVisualNode::setLocation(const DiscretePoint& loc)
void AbstractVisualNode::setLocation(const Point& loc)
{
if (mLocation != loc)
{

View file

@ -4,18 +4,18 @@
#include "AbstractMesh.h"
#include "Image.h"
#include "DiscretePoint.h"
#include "Point.h"
#include <memory>
#include <iostream>
class FontsManager;
struct SceneInfo;
class AbstractVisualNode
{
public:
AbstractVisualNode(const DiscretePoint& location, const std::string& name = {});
AbstractVisualNode(const Point& location, const std::string& name = {});
virtual ~AbstractVisualNode() = default;
@ -23,9 +23,9 @@ public:
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;
@ -35,18 +35,18 @@ public:
bool getIsVisible() const;
virtual void update(FontsManager* fontsManager);
void syncChildren(const std::vector<AbstractVisualNode*>& children);
void setIsVisible(bool isVisible);
void setName(const std::string& name);
void setLocation(const DiscretePoint& loc);
void setLocation(const Point& loc);
virtual void update(SceneInfo* sceneInfo);
protected:
DiscretePoint mLocation;
Point mLocation;
std::vector<std::unique_ptr<SceneItem> > mSceneItems;
std::unique_ptr<Image<unsigned char> > mImage;

View file

@ -1,6 +1,6 @@
#include "GeometryNode.h"
GeometryNode::GeometryNode(const DiscretePoint& location)
GeometryNode::GeometryNode(const Point& location)
: MaterialNode(location),
mStrokeThickness(1),
mType(Type::Path)

View file

@ -16,7 +16,7 @@ public:
};
public:
GeometryNode(const DiscretePoint& location);
GeometryNode(const Point& location);
virtual ~GeometryNode() = default;
virtual Type getType() = 0;
@ -34,7 +34,7 @@ protected:
class LineNode : public GeometryNode
{
public:
LineNode(const DiscretePoint& location)
LineNode(const Point& location)
: GeometryNode(location)
{

View file

@ -2,7 +2,7 @@
#include "MeshPrimitives.h"
GridNode::GridNode(const DiscretePoint& location)
GridNode::GridNode(const Point& 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)
{
@ -35,7 +35,7 @@ void GridNode::setWidth(unsigned width)
}
}
void GridNode::setHeight(unsigned height)
void GridNode::setHeight(double 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;
}
void GridNode::update(FontsManager* fontsManager)
void GridNode::update(SceneInfo* sceneInfo)
{
if (!mBackgroundModel || mDataDirty)
{

View file

@ -7,7 +7,7 @@ class GridNode : public MaterialNode
{
public:
GridNode(const DiscretePoint& location);
GridNode(const Point& location);
void setNumX(unsigned numX);
@ -16,18 +16,18 @@ public:
void setData(const std::vector<Color>& colors);
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 setHeight(unsigned height);
void setWidth(double width);
void setHeight(double height);
private:
unsigned mNumberX{5};
unsigned mNumberY{5};
unsigned mWidth{1};
unsigned mHeight{1};
double mWidth{1};
double mHeight{1};
bool mDataDirty = true;
std::vector<Color> mData;

View file

@ -2,7 +2,7 @@
#include <iostream>
MaterialNode::MaterialNode(const DiscretePoint& location)
MaterialNode::MaterialNode(const Point& location)
: AbstractVisualNode(location),
mFillColor(Color(255, 255, 255)),
mStrokeColor(Color(0, 0, 0))

View file

@ -7,7 +7,7 @@
class MaterialNode : public AbstractVisualNode
{
public:
MaterialNode(const DiscretePoint& location);
MaterialNode(const Point& location);
const Color& getFillColor() const;
const Color& getStrokeColor() const;

View file

@ -2,13 +2,13 @@
#include <iostream>
MeshNode::MeshNode(const DiscretePoint& location)
MeshNode::MeshNode(const Point& location)
: MaterialNode(location)
{
}
void MeshNode::setWidth(unsigned width)
void MeshNode::setWidth(double 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)
{
@ -37,7 +37,7 @@ SceneItem* MeshNode::getSceneItem(std::size_t idx) const
return mModel.get();
}
unsigned MeshNode::getNumSceneItems() const
std::size_t MeshNode::getNumSceneItems() const
{
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)
{
mModel = std::make_unique<SceneModel>(nullptr);
mModel = std::make_unique<SceneModel>();
mModel->setName(mName + "_MeshModel");
mModel->setShowOutline(true);
}

View file

@ -7,22 +7,22 @@ class AbstractMesh;
class MeshNode : public MaterialNode
{
public:
MeshNode(const DiscretePoint& location);
MeshNode(const Point& location);
void setMesh(AbstractMesh* mesh);
SceneItem* getSceneItem(std::size_t idx) const override;
unsigned getNumSceneItems() const override;
std::size_t getNumSceneItems() const override;
void setWidth(unsigned width);
void setHeight(unsigned height);
void setWidth(double width);
void setHeight(double height);
void update(FontsManager* fontsManager) override;
void update(SceneInfo* sceneInfo) override;
private:
bool mMeshIsDirty{true};
AbstractMesh* mWorkingMesh{nullptr};
unsigned mWidth{1};
unsigned mHeight{1};
double mWidth{1};
double mHeight{1};
std::unique_ptr<SceneModel> mModel;
};

View file

@ -6,6 +6,7 @@
#include "MeshPrimitives.h"
#include "FontItem.h"
#include "FontGlyph.h"
#include "SceneInfo.h"
#include "SceneText.h"
@ -15,7 +16,7 @@
#include <iostream>
TextNode::TextNode(const std::string& content, const DiscretePoint& loc)
TextNode::TextNode(const std::string& content, const Point& loc)
: MaterialNode(loc)
{
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);
}
@ -41,17 +42,17 @@ std::string TextNode::getContent() const
return mTextData.mContent;
}
unsigned TextNode::getWidth() const
double TextNode::getWidth() const
{
return mWidth;
}
unsigned TextNode::getHeight() const
double TextNode::getHeight() const
{
return mHeight;
}
void TextNode::setWidth(unsigned width)
void TextNode::setWidth(double 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)
{
@ -90,7 +91,7 @@ SceneItem* TextNode::getSceneItem(std::size_t idx) const
}
}
unsigned TextNode::getNumSceneItems() const
std::size_t TextNode::getNumSceneItems() const
{
return 1;
}
@ -136,7 +137,7 @@ void TextNode::updateLines(FontsManager* fontsManager)
}
}
void TextNode::update(FontsManager* fontsManager)
void TextNode::update(SceneInfo* sceneInfo)
{
if (!mTextItem)
{
@ -146,7 +147,7 @@ void TextNode::update(FontsManager* fontsManager)
if (mTransformIsDirty || mContentIsDirty)
{
updateLines(fontsManager);
updateLines(sceneInfo->mFontsManager);
}
if (mContentIsDirty || mLinesAreDirty)

View file

@ -8,30 +8,32 @@
#include <memory>
#include <string>
class FontsManager;
class TextNode : public MaterialNode
{
public:
TextNode(const std::string& content, const DiscretePoint& loc);
TextNode(const std::string& content, const Point& loc);
~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 getFontLabel() const;
SceneItem* getSceneItem(std::size_t idx) const override;
unsigned getNumSceneItems() const override;
std::size_t getNumSceneItems() const override;
unsigned getWidth() const;
unsigned getHeight() const;
double getWidth() const;
double getHeight() const;
void setWidth(unsigned width);
void setHeight(unsigned height);
void setWidth(double width);
void setHeight(double height);
void setContent(const std::string& content);
void update(FontsManager* fontsManager) override;
void update(SceneInfo* sceneInfo) override;
private:
void updateLines(FontsManager* fontsManager);
@ -40,8 +42,8 @@ private:
bool mContentIsDirty{true};
bool mLinesAreDirty{true};
unsigned mWidth{1};
unsigned mHeight{1};
double mWidth{1};
double mHeight{1};
std::unique_ptr<SceneItem> mTextItem;
};

View file

@ -7,7 +7,8 @@
#include <iostream>
Scene::Scene()
: mRootNode(std::make_unique<RootNode>())
: mRootNode(std::make_unique<RootNode>()),
mSceneInfo(std::make_unique<SceneInfo>())
{
mRootNode->setName("Scene_RootNode");
}
@ -19,8 +20,10 @@ Scene::~Scene()
void Scene::update(FontsManager* fontsManager)
{
mSceneInfo->mFontsManager = fontsManager;
mSceneItems.clear();
updateNode(mRootNode.get(), fontsManager);
updateNode(mRootNode.get());
}
void Scene::addNode(AbstractVisualNode* node)
@ -33,17 +36,17 @@ bool Scene::isEmpty() const
return mRootNode->getNumChildren() == 0;
}
void Scene::updateNode(AbstractVisualNode* node, FontsManager* fontsManager)
void Scene::updateNode(AbstractVisualNode* node)
{
for (auto child : node->getChildren())
{
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++)
{
@ -58,3 +61,13 @@ const std::vector<SceneItem*>& Scene::getItems() const
{
return mSceneItems;
}
bool Scene::shouldShowMeshOutline() const
{
return mSceneInfo->mShowMeshOutline;
}
void Scene::setShowMeshOutline(bool shouldShow)
{
mSceneInfo->mShowMeshOutline = shouldShow;
}

View file

@ -1,6 +1,7 @@
#pragma once
#include "TextData.h"
#include "SceneInfo.h"
#include <vector>
#include <memory>
@ -8,7 +9,6 @@
class RootNode;
class AbstractVisualNode;
class SceneItem;
class FontsManager;
class Scene
{
@ -23,21 +23,15 @@ public:
bool isEmpty() const;
bool shouldShowMeshOutline() const
{
return mShowMeshOutline;
}
bool shouldShowMeshOutline() const;
void setShowMeshOutline(bool shouldShow)
{
mShowMeshOutline = shouldShow;
}
void setShowMeshOutline(bool shouldShow);
void update(FontsManager* fontsManager = nullptr);
private:
void updateNode(AbstractVisualNode* node, FontsManager* fontsManager);
void updateNode(AbstractVisualNode* node);
std::unique_ptr<RootNode> mRootNode;
std::vector<SceneItem*> mSceneItems;
bool mShowMeshOutline{false};
std::unique_ptr<SceneInfo> mSceneInfo;
};

View file

@ -0,0 +1,10 @@
#pragma once
#include "FontsManager.h"
struct SceneInfo
{
bool mSupportsGeometryPrimitives{ false };
bool mShowMeshOutline{ false };
FontsManager* mFontsManager{ nullptr };
};

View 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;
}

View file

@ -1,6 +1,7 @@
#pragma once
#include "SceneItem.h"
#include "AbstractGeometricItem.h"
#include "Texture.h"
#include <vector>
@ -9,37 +10,33 @@
#include <memory>
class AbstractMesh;
//class Texture;
class SceneModel : public SceneItem
{
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;
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(AbstractMesh* mesh);
void setShowOutline(bool showOutline)
{
mShowOutline = showOutline;
}
bool getShowOutline() const
{
return mShowOutline;
}
Type getType() const override;
private:
AbstractMesh* mRawMesh{nullptr};
std::unique_ptr<AbstractMesh> mMesh;
std::unique_ptr<Texture> mColorMap;
bool mMeshIsDirty{true};
std::unique_ptr<AbstractGeometricItem> mGeometry;
bool mGeometryIsDirty{true};
bool mColorMapIsDirty{true};
bool mShowOutline{false};
};

View file

@ -8,15 +8,15 @@ set(PLATFORM_UNIT_TEST_FILES
)
endif()
set(GRAPHICS_UNIT_TEST_FILES
graphics/TestRasterizer.cpp
${PLATFORM_UNIT_TEST_FILES}
PARENT_SCOPE
)
if(WIN32)
list(APPEND PLATFORM_UNIT_TEST_FILES
graphics/TestD2DOffScreenRendering.cpp
)
set(GRAPHICS_UI_TEST_FILES
graphics/TestDirectXRendering.cpp
graphics/TestD2DRendering.cpp
PARENT_SCOPE
)
endif()
@ -29,4 +29,10 @@ set(GRAPHICS_UNIT_TEST_DEPENDENCIES
set(GRAPHICS_UI_TEST_DEPENDENCIES
graphics client
PARENT_SCOPE
)
set(GRAPHICS_UNIT_TEST_FILES
graphics/TestRasterizer.cpp
${PLATFORM_UNIT_TEST_FILES}
PARENT_SCOPE
)

View 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);
};

View 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")
{
};