Simple drawing example.
This commit is contained in:
parent
d7fe11913f
commit
f0091f9e04
27 changed files with 450 additions and 68 deletions
|
@ -1,6 +1,8 @@
|
|||
list(APPEND visual_elements_LIB_INCLUDES
|
||||
GeometryNode.cpp
|
||||
RectangleNode.cpp
|
||||
basic_shapes/RectangleNode.cpp
|
||||
basic_shapes/CircleNode.cpp
|
||||
basic_shapes/LineNode.cpp
|
||||
MaterialNode.cpp
|
||||
MeshNode.cpp
|
||||
TextNode.cpp
|
||||
|
@ -17,7 +19,8 @@ list(APPEND visual_elements_LIB_INCLUDES
|
|||
add_library(visual_elements SHARED ${visual_elements_LIB_INCLUDES})
|
||||
|
||||
target_include_directories(visual_elements PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/basic_shapes
|
||||
)
|
||||
|
||||
target_link_libraries(visual_elements PUBLIC core geometry fonts mesh image)
|
||||
|
|
|
@ -10,7 +10,9 @@ public:
|
|||
Path,
|
||||
Rectangle,
|
||||
Circle,
|
||||
Arc
|
||||
Arc,
|
||||
Line,
|
||||
Polyline
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -29,4 +31,19 @@ protected:
|
|||
bool mGeometryIsDirty{true};
|
||||
};
|
||||
|
||||
class LineNode : public GeometryNode
|
||||
{
|
||||
public:
|
||||
LineNode(const DiscretePoint& location)
|
||||
: GeometryNode(location)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Type getType()
|
||||
{
|
||||
return Type::Line;
|
||||
}
|
||||
};
|
||||
|
||||
using GeometryNodePtr = std::unique_ptr<GeometryNode>;
|
||||
|
|
83
src/visual_elements/basic_shapes/CircleNode.cpp
Normal file
83
src/visual_elements/basic_shapes/CircleNode.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
#include "CircleNode.h"
|
||||
|
||||
#include "FontsManager.h"
|
||||
#include "SceneModel.h"
|
||||
#include "AbstractMesh.h"
|
||||
#include "MeshPrimitives.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
CircleNode::CircleNode(const DiscretePoint& location, unsigned radius)
|
||||
: GeometryNode(location),
|
||||
mRadius(radius)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CircleNode::Type CircleNode::getType()
|
||||
{
|
||||
return Type::Circle;
|
||||
}
|
||||
|
||||
unsigned CircleNode::getRadius() const
|
||||
{
|
||||
return mRadius;
|
||||
}
|
||||
|
||||
SceneItem* CircleNode::getSceneItem(std::size_t idx) const
|
||||
{
|
||||
if (idx == 0)
|
||||
{
|
||||
return mBackgroundItem.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned CircleNode::getNumSceneItems() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void CircleNode::setRadius(unsigned radius)
|
||||
{
|
||||
if (mRadius != radius)
|
||||
{
|
||||
mRadius = radius;
|
||||
mTransformIsDirty = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CircleNode::update(FontsManager* fontsManager)
|
||||
{
|
||||
if (!mBackgroundItem || mGeometryIsDirty)
|
||||
{
|
||||
auto mesh = MeshPrimitives::buildCircleAsTriMesh();
|
||||
|
||||
if (!mBackgroundItem)
|
||||
{
|
||||
mBackgroundItem = std::make_unique<SceneModel>(std::move(mesh));
|
||||
mBackgroundItem->setName(mName + "_Model");
|
||||
}
|
||||
else
|
||||
{
|
||||
mBackgroundItem->updateMesh(std::move(mesh));
|
||||
}
|
||||
mGeometryIsDirty = false;
|
||||
}
|
||||
|
||||
if (mTransformIsDirty)
|
||||
{
|
||||
mBackgroundItem->updateTransform({mLocation, static_cast<double>(2*mRadius), static_cast<double>(2*mRadius)});
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
if (mMaterialIsDirty)
|
||||
{
|
||||
mBackgroundItem->updateUniformColor(mFillColor);
|
||||
mMaterialIsDirty = false;
|
||||
}
|
||||
}
|
25
src/visual_elements/basic_shapes/CircleNode.h
Normal file
25
src/visual_elements/basic_shapes/CircleNode.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include "GeometryNode.h"
|
||||
|
||||
class CircleNode : public GeometryNode
|
||||
{
|
||||
public:
|
||||
CircleNode(const DiscretePoint& location, unsigned radius);
|
||||
|
||||
Type getType();
|
||||
|
||||
unsigned getRadius() const;
|
||||
|
||||
SceneItem* getSceneItem(std::size_t idx) const override;
|
||||
unsigned getNumSceneItems() const override;
|
||||
|
||||
void setRadius(unsigned radius);
|
||||
|
||||
void update(FontsManager* fontsManager) override;
|
||||
private:
|
||||
unsigned mRadius{1};
|
||||
|
||||
std::unique_ptr<SceneModel> mBackgroundItem;
|
||||
std::unique_ptr<SceneModel> mOutlineItem;
|
||||
};
|
0
src/visual_elements/basic_shapes/LineNode.cpp
Normal file
0
src/visual_elements/basic_shapes/LineNode.cpp
Normal file
0
src/visual_elements/basic_shapes/LineNode.cppcd
Normal file
0
src/visual_elements/basic_shapes/LineNode.cppcd
Normal file
0
src/visual_elements/basic_shapes/LineNode.h
Normal file
0
src/visual_elements/basic_shapes/LineNode.h
Normal file
|
@ -1,9 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "GeometryNode.h"
|
||||
#include "DiscretePoint.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class RectangleNode : public GeometryNode
|
||||
{
|
Loading…
Add table
Add a link
Reference in a new issue