Cleaning for mesh addition.

This commit is contained in:
James Grogan 2022-11-13 17:02:09 +00:00
parent 8e0ce22b57
commit 402f381d10
67 changed files with 655 additions and 456 deletions

View file

@ -11,8 +11,6 @@ int main(int argc, char *argv[])
auto main_app = MainApplication::Create(); auto main_app = MainApplication::Create();
main_app->initialize(std::move(command_line_args)); main_app->initialize(std::move(command_line_args));
main_app->Run(); main_app->run();
main_app->ShutDown();
return 0; return 0;
} }

View file

@ -56,10 +56,10 @@ void MediaTool::initializeViews()
auto button = Button::Create(); auto button = Button::Create();
button->setLabel("Click!"); button->setLabel("Click!");
button->setBounds(100, 200); button->setBounds(100, 200);
button->setBackgroundColor(Color::Create(0, 0, 255, 0)); button->setBackgroundColor(Color(0, 0, 255, 0));
auto background_widget = Widget::Create(); auto background_widget = Widget::Create();
background_widget->setBackgroundColor(Color::Create(0, 255, 255, 0)); background_widget->setBackgroundColor(Color(0, 255, 255, 0));
auto horizontal_spacer = HorizontalSpacer::Create(); auto horizontal_spacer = HorizontalSpacer::Create();
horizontal_spacer->addWidgetWithScale(std::move(button), 1); horizontal_spacer->addWidgetWithScale(std::move(button), 1);

View file

@ -7,7 +7,7 @@ AudioEditorView::AudioEditorView()
{ {
auto label = Label::Create(); auto label = Label::Create();
label->setLabel("Audio Editor"); label->setLabel("Audio Editor");
label->setBackgroundColor(Color::Create(200, 189, 160)); label->setBackgroundColor(Color(200, 189, 160));
label->setMargin(1); label->setMargin(1);
addWidget(std::move(label)); addWidget(std::move(label));
} }

View file

@ -7,7 +7,7 @@ ImageEditorView::ImageEditorView()
{ {
auto label = Label::Create(); auto label = Label::Create();
label->setLabel("Image Editor"); label->setLabel("Image Editor");
label->setBackgroundColor(Color::Create(200, 189, 160)); label->setBackgroundColor(Color(200, 189, 160));
label->setMargin(1); label->setMargin(1);
addWidget(std::move(label)); addWidget(std::move(label));
} }

View file

@ -19,7 +19,7 @@ void TextEditorView::Initialize()
{ {
auto label = Label::Create(); auto label = Label::Create();
label->setLabel("Text Editor"); label->setLabel("Text Editor");
label->setBackgroundColor(Color::Create(181, 189, 200)); label->setBackgroundColor(Color(181, 189, 200));
label->setMargin(1); label->setMargin(1);
auto textBox = TextBox::Create(); auto textBox = TextBox::Create();
@ -27,12 +27,12 @@ void TextEditorView::Initialize()
auto saveButton = Button::Create(); auto saveButton = Button::Create();
saveButton->setLabel("Save"); saveButton->setLabel("Save");
saveButton->setBackgroundColor(Color::Create(200, 200, 200)); saveButton->setBackgroundColor(Color(200, 200, 200));
saveButton->setMargin(2); saveButton->setMargin(2);
auto onSave = [this](Widget* self){ auto onSave = [this](Widget* self){
if(this && mController && mTextBox) if(this && mController && mTextBox)
{ {
mController->SetContent(mTextBox->GetContent()); mController->SetContent(mTextBox->getContent());
mController->OnSave(); mController->OnSave();
}; };
}; };
@ -40,26 +40,26 @@ void TextEditorView::Initialize()
auto clearButton = Button::Create(); auto clearButton = Button::Create();
clearButton->setLabel("Clear"); clearButton->setLabel("Clear");
clearButton->setBackgroundColor(Color::Create(200, 200, 200)); clearButton->setBackgroundColor(Color(200, 200, 200));
clearButton->setMargin(2); clearButton->setMargin(2);
auto onClear = [this](Widget* self){ auto onClear = [this](Widget* self){
if(this && mController && mTextBox) if(this && mController && mTextBox)
{ {
mController->OnClear(); mController->OnClear();
mTextBox->SetContent(""); mTextBox->setContent("");
}; };
}; };
clearButton->setOnClickFunction(onClear); clearButton->setOnClickFunction(onClear);
auto loadButton = Button::Create(); auto loadButton = Button::Create();
loadButton->setLabel("Load"); loadButton->setLabel("Load");
loadButton->setBackgroundColor(Color::Create(200, 200, 200)); loadButton->setBackgroundColor(Color(200, 200, 200));
loadButton->setMargin(2); loadButton->setMargin(2);
auto onLoad = [this](Widget* self){ auto onLoad = [this](Widget* self){
if(this && mController && mTextBox) if(this && mController && mTextBox)
{ {
mController->OnLoad(); mController->OnLoad();
mTextBox->SetContent(mController->GetContent()); mTextBox->setContent(mController->GetContent());
}; };
}; };
loadButton->setOnClickFunction(onLoad); loadButton->setOnClickFunction(onLoad);

View file

@ -7,7 +7,7 @@ WebClientView::WebClientView()
{ {
auto label = Label::Create(); auto label = Label::Create();
label->setLabel("Web Client"); label->setLabel("Web Client");
label->setBackgroundColor(Color::Create(200, 189, 160)); label->setBackgroundColor(Color(200, 189, 160));
label->setMargin(1); label->setMargin(1);
addWidget(std::move(label)); addWidget(std::move(label));
} }

View file

@ -49,5 +49,5 @@ void GuiApplication::run()
MLOG_INFO("Window Interface Shut Down"); MLOG_INFO("Window Interface Shut Down");
mMainApplication->ShutDown(); mMainApplication->shutDown();
} }

View file

@ -4,7 +4,7 @@
StatusBar::StatusBar() StatusBar::StatusBar()
{ {
setBackgroundColor(Color::Create(200, 200, 200)); setBackgroundColor(Color(200, 200, 200));
} }
std::unique_ptr<StatusBar> StatusBar::Create() std::unique_ptr<StatusBar> StatusBar::Create()

View file

@ -35,7 +35,7 @@ void TabbedPanelWidget::AddPanel(WidgetUPtr panel, const std::string& label)
{ {
auto button = Button::Create(); auto button = Button::Create();
button->setLabel(label); button->setLabel(label);
button->setBackgroundColor(Color::Create(156, 156, 156)); button->setBackgroundColor(Color(156, 156, 156));
button->setMargin({1, 0, 0, 1}); button->setMargin({1, 0, 0, 1});
auto rawPanel = panel.get(); auto rawPanel = panel.get();
auto onClick = [this, rawPanel](Widget*){ auto onClick = [this, rawPanel](Widget*){

View file

@ -4,7 +4,7 @@
TopBar::TopBar() TopBar::TopBar()
{ {
setBackgroundColor(Color::Create(50, 50, 50)); setBackgroundColor(Color(50, 50, 50));
} }
std::unique_ptr<TopBar> TopBar::Create() std::unique_ptr<TopBar> TopBar::Create()

View file

@ -9,8 +9,9 @@
#include "Rasterizer.h" #include "Rasterizer.h"
#include "Grid.h" #include "Grid.h"
#include "Image.h" #include "Image.h"
#include "TriMesh.h"
#include "TextElement.h" #include "TextNode.h"
#include "DiscretePoint.h" #include "DiscretePoint.h"
@ -23,6 +24,12 @@ MainApplication::MainApplication()
} }
std::unique_ptr<MainApplication> MainApplication::Create()
{
return std::make_unique<MainApplication>();
}
MainApplication::~MainApplication() MainApplication::~MainApplication()
{ {
@ -53,7 +60,7 @@ void MainApplication::initialize(CommandLineArgsUPtr commandLineArgs, std::uniqu
MLOG_INFO("Created Audio Manager"); MLOG_INFO("Created Audio Manager");
} }
void MainApplication::Run() void MainApplication::run()
{ {
std::string program_type; std::string program_type;
if(mCommandLineArgs->getNumberOfArgs() > 1) if(mCommandLineArgs->getNumberOfArgs() > 1)
@ -78,22 +85,22 @@ void MainApplication::Run()
if(program_type == "-server") if(program_type == "-server")
{ {
RunServer(); runServer();
} }
else if(program_type == "-audio") else if(program_type == "-audio")
{ {
PlayAudio(); playAudio();
} }
else if(program_type == "-convert") else if(program_type == "-convert")
{ {
ConvertDocument(input_path, output_path); convertDocument(input_path, output_path);
} }
else if(program_type == "-draw") else if(program_type == "-draw")
{ {
auto drawing_manager = DrawingManager::Create(); auto drawing_manager = DrawingManager::Create();
drawing_manager->InitalizeSurface(400, 400); drawing_manager->InitalizeSurface(400, 400);
auto text = TextElement::Create("Hello World", DiscretePoint(20, 20)); auto text = TextNode::Create("Hello World", DiscretePoint(20, 20));
drawing_manager->AddText(text.get()); drawing_manager->AddText(text.get());
drawing_manager->RenderToFile("test.png"); drawing_manager->RenderToFile("test.png");
} }
@ -101,21 +108,23 @@ void MainApplication::Run()
{ {
MLOG_ERROR("Unknown program type: " + program_type); MLOG_ERROR("Unknown program type: " + program_type);
} }
shutDown();
} }
void MainApplication::RunServer() void MainApplication::runServer()
{ {
mNetworkManager->RunHttpServer(); mNetworkManager->RunHttpServer();
} }
void MainApplication::PlayAudio() void MainApplication::playAudio()
{ {
//MidiReader reader; //MidiReader reader;
//reader.Read("/home/james/sample.mid"); //reader.Read("/home/james/sample.mid");
mAudioManager->Play(); mAudioManager->Play();
} }
void MainApplication::ConvertDocument(const std::string& inputPath, const std::string& outputPath) void MainApplication::convertDocument(const std::string& inputPath, const std::string& outputPath)
{ {
auto input_file = File(std::filesystem::path(inputPath)); auto input_file = File(std::filesystem::path(inputPath));
auto output_file = File(std::filesystem::path(outputPath)); auto output_file = File(std::filesystem::path(outputPath));
@ -124,20 +133,15 @@ void MainApplication::ConvertDocument(const std::string& inputPath, const std::s
converter.Convert(&input_file, &output_file); converter.Convert(&input_file, &output_file);
} }
CommandLineArgs* MainApplication::GetCommandLineArgs() const CommandLineArgs* MainApplication::getCommandLineArgs() const
{ {
return mCommandLineArgs.get(); return mCommandLineArgs.get();
} }
void MainApplication::ShutDown() void MainApplication::shutDown()
{ {
mDatabaseManager->OnShutDown(); mDatabaseManager->OnShutDown();
mNetworkManager->ShutDown(); mNetworkManager->ShutDown();
MLOG_INFO("Shut down"); MLOG_INFO("Shut down");
FileLogger::GetInstance().Close(); FileLogger::GetInstance().Close();
} }
std::unique_ptr<MainApplication> MainApplication::Create()
{
return std::make_unique<MainApplication>();
}

View file

@ -17,22 +17,22 @@ public:
~MainApplication(); ~MainApplication();
void initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr<IApplicationContext> applicationContext=nullptr);
void Run();
void ShutDown();
CommandLineArgs* GetCommandLineArgs() const;
static std::unique_ptr<MainApplication> Create(); static std::unique_ptr<MainApplication> Create();
void initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr<IApplicationContext> applicationContext=nullptr);
void run();
void shutDown();
CommandLineArgs* getCommandLineArgs() const;
private: private:
void RunServer(); void runServer();
void PlayAudio(); void playAudio();
void ConvertDocument(const std::string& inputPath, const std::string& outputPath); void convertDocument(const std::string& inputPath, const std::string& outputPath);
CommandLineArgsUPtr mCommandLineArgs; CommandLineArgsUPtr mCommandLineArgs;
DatabaseManagerPtr mDatabaseManager; DatabaseManagerPtr mDatabaseManager;

View file

@ -15,6 +15,19 @@ public:
unsigned GetB() const; unsigned GetB() const;
double GetAlpha() const; double GetAlpha() const;
bool operator==(const Color& rhs) const
{
return (mR == rhs.mR)
&& (mG == rhs.mG)
&& (mB == rhs.mB)
&& (mAlpha == rhs.mAlpha);
}
bool operator!=(const Color& rhs) const
{
return !operator==(rhs);
}
private: private:
unsigned mR{0}; unsigned mR{0};
unsigned mG{0}; unsigned mG{0};

View file

@ -9,7 +9,7 @@ class DiscretePoint
public: public:
DiscretePoint(unsigned x, unsigned y); DiscretePoint(unsigned x = 0, unsigned y = 0);
~DiscretePoint(); ~DiscretePoint();

View file

@ -6,6 +6,13 @@ Point::Point(double x, double y)
{ {
} }
Point::Point(const Point& reference, double offSetX, double offSetY)
: mX(reference.getX() + offSetX),
mY(reference.getX() + offSetY)
{
}
Point::~Point() Point::~Point()
{ {
}; };

View file

@ -9,7 +9,7 @@ public:
Point(double x, double y); Point(double x, double y);
//Point(const Point& reference, double offSetX, double offSetY); Point(const Point& reference, double offSetX, double offSetY);
~Point(); ~Point();

View file

@ -3,32 +3,41 @@
#include "INativeDrawingContext.h" #include "INativeDrawingContext.h"
#include "AbstractGeometricItem.h" #include "AbstractGeometricItem.h"
#include "MeshBuilder.h"
#include "TriMesh.h"
std::unique_ptr<DrawingContext> DrawingContext::Create() std::unique_ptr<DrawingContext> DrawingContext::Create()
{ {
return std::make_unique<DrawingContext>(); return std::make_unique<DrawingContext>();
} }
void DrawingContext::SetNativeContext(std::unique_ptr<INativeDrawingContext> context) void DrawingContext::setNativeContext(std::unique_ptr<INativeDrawingContext> context)
{ {
mNativeDrawingContext = std::move(context); mNativeDrawingContext = std::move(context);
} }
INativeDrawingContext* DrawingContext::GetNativeContext() INativeDrawingContext* DrawingContext::getNativeContext()
{ {
return mNativeDrawingContext.get(); return mNativeDrawingContext.get();
} }
void DrawingContext::AddDrawable(AbstractGeometricItemPtr item) void DrawingContext::addDrawable(AbstractGeometricItemPtr item)
{ {
mItems.push_back(std::move(item)); mItems.push_back(std::move(item));
} }
unsigned DrawingContext::GetNumItems() const unsigned DrawingContext::getNumItems() const
{ {
return mItems.size(); return mItems.size();
} }
AbstractGeometricItem* DrawingContext::GetDrawable(unsigned idx) const AbstractGeometricItem* DrawingContext::getDrawable(unsigned idx) const
{ {
return mItems[idx].get(); return mItems[idx].get();
} }
void DrawingContext::updateMesh()
{
}

View file

@ -7,6 +7,8 @@ class INativeDrawingContext;
class AbstractGeometricItem; class AbstractGeometricItem;
using AbstractGeometricItemPtr = std::unique_ptr<AbstractGeometricItem>; using AbstractGeometricItemPtr = std::unique_ptr<AbstractGeometricItem>;
class TriMesh;
class DrawingContext class DrawingContext
{ {
public: public:
@ -14,18 +16,20 @@ public:
static std::unique_ptr<DrawingContext> Create(); static std::unique_ptr<DrawingContext> Create();
void SetNativeContext(std::unique_ptr<INativeDrawingContext> context); void setNativeContext(std::unique_ptr<INativeDrawingContext> context);
INativeDrawingContext* GetNativeContext(); INativeDrawingContext* getNativeContext();
unsigned GetNumItems() const; unsigned getNumItems() const;
void AddDrawable(AbstractGeometricItemPtr item); void addDrawable(AbstractGeometricItemPtr item);
AbstractGeometricItem* GetDrawable(unsigned idx) const; AbstractGeometricItem* getDrawable(unsigned idx) const;
private: private:
void updateMesh();
std::unique_ptr<TriMesh> mMesh;
std::vector<std::unique_ptr<AbstractGeometricItem> > mItems; std::vector<std::unique_ptr<AbstractGeometricItem> > mItems;
std::unique_ptr<INativeDrawingContext> mNativeDrawingContext; std::unique_ptr<INativeDrawingContext> mNativeDrawingContext;
}; };

View file

@ -7,6 +7,7 @@
#include "Grid.h" #include "Grid.h"
#include "Image.h" #include "Image.h"
#include "TriMesh.h"
DrawingManager::DrawingManager() DrawingManager::DrawingManager()
: mRasterizer(std::make_unique<Rasterizer>()) : mRasterizer(std::make_unique<Rasterizer>())
@ -30,7 +31,7 @@ void DrawingManager::InitializeContext()
mDrawingContext = DrawingContext::Create(); mDrawingContext = DrawingContext::Create();
} }
void DrawingManager::AddText(TextElement* text) void DrawingManager::AddText(TextNode* text)
{ {
if (!mDrawingContext) if (!mDrawingContext)
{ {

View file

@ -5,7 +5,7 @@
#include "INativeDrawingContext.h" #include "INativeDrawingContext.h"
#include "INativeDrawingSurface.h" #include "INativeDrawingSurface.h"
class TextElement; class TextNode;
class DrawingSurface; class DrawingSurface;
using DrawingSurfacePtr = std::unique_ptr<DrawingSurface>; using DrawingSurfacePtr = std::unique_ptr<DrawingSurface>;
@ -21,7 +21,7 @@ public:
static std::unique_ptr<DrawingManager> Create(); static std::unique_ptr<DrawingManager> Create();
void InitalizeSurface(unsigned width, unsigned height); void InitalizeSurface(unsigned width, unsigned height);
void InitializeContext(); void InitializeContext();
void AddText(TextElement* text); void AddText(TextNode* text);
void RenderToFile(const std::string& path); void RenderToFile(const std::string& path);
private: private:

View file

@ -16,9 +16,9 @@ void Rasterizer::Paint(DrawingSurface* surface, DrawingContext* context)
const auto height = surface->GetHeight(); const auto height = surface->GetHeight();
mGrid->ResetBounds(Rectangle(Point(0, 0), Point(width, height))); mGrid->ResetBounds(Rectangle(Point(0, 0), Point(width, height)));
for (unsigned idx=0; idx< context->GetNumItems(); idx++) for (unsigned idx=0; idx< context->getNumItems(); idx++)
{ {
context->GetDrawable(idx)->Sample(mGrid.get()); context->getDrawable(idx)->Sample(mGrid.get());
} }
surface->Paint(mGrid.get()); surface->Paint(mGrid.get());

View file

@ -5,7 +5,7 @@
#include <GL/gl.h> #include <GL/gl.h>
void OpenGlInterface::draw() void OpenGlInterface::draw(TriMesh* mesh)
{ {
glClearColor(0.4, 0.4, 0.4, 0.4); glClearColor(0.4, 0.4, 0.4, 0.4);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -13,6 +13,8 @@ void OpenGlInterface::draw()
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
glVertex3f(-0.7, 0.7, 0); glVertex3f(-0.7, 0.7, 0);
glVertex3f(0.7, 0.7, 0); glVertex3f(0.7, 0.7, 0);

View file

@ -1,10 +1,11 @@
#pragma once #pragma once
class TriMesh;
class OpenGlInterface class OpenGlInterface
{ {
public: public:
static void draw(TriMesh* mesh);
static void draw();
}; };

View file

@ -2,6 +2,7 @@ list(APPEND mesh_LIB_INCLUDES
AbstractMesh.cpp AbstractMesh.cpp
Edge.cpp Edge.cpp
Face.cpp Face.cpp
TriFace.cpp
Node.cpp Node.cpp
QuadMesh.cpp QuadMesh.cpp
TriMesh.cpp TriMesh.cpp
@ -13,5 +14,7 @@ list(APPEND mesh_LIB_INCLUDES
add_library(mesh SHARED ${mesh_LIB_INCLUDES}) add_library(mesh SHARED ${mesh_LIB_INCLUDES})
target_link_libraries(mesh core geometry) target_link_libraries(mesh core geometry)
target_include_directories(mesh PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/")
set_target_properties( mesh PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) set_target_properties( mesh PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
set_property(TARGET mesh PROPERTY FOLDER src) set_property(TARGET mesh PROPERTY FOLDER src)

View file

@ -2,8 +2,19 @@
#include "Node.h" #include "Node.h"
Edge::Edge(Node* node0, Node* node1) Edge::Edge(Node* node0, Node* node1, unsigned id)
: mNode0(node0), : mNode0(node0),
mNode1(node1) mNode1(node1),
mId(id)
{ {
} }
std::unique_ptr<Edge> Edge::Create(Node* node0, Node* node1, unsigned id)
{
return std::make_unique<Edge>(node0, node1, id);
}
Edge::~Edge()
{
}

View file

@ -2,12 +2,18 @@
class Node; class Node;
#include <memory>
class Edge class Edge
{ {
public: public:
Edge(Node* node0, Node* node1); Edge(Node* node0, Node* node1, unsigned id = 0);
~Edge();
static std::unique_ptr<Edge> Create(Node* node0, Node* node1, unsigned id = 0);
private: private:
unsigned mId{0};
Node* mNode0{nullptr}; Node* mNode0{nullptr};
Node* mNode1{nullptr}; Node* mNode1{nullptr};
}; };

View file

@ -0,0 +1,35 @@
#include "MeshBuilder.h"
#include "Node.h"
#include "Edge.h"
#include "TriFace.h"
std::unique_ptr<TriMesh> MeshBuilder::buildTriMesh(const VecPoints& locations, const EdgeIds& edgeIds, const FaceIds& faceIds)
{
auto mesh = std::make_unique<TriMesh>();
VecNodes nodes(locations.size());
for (std::size_t idx=0; idx<locations.size(); idx++)
{
nodes[idx] = Node::Create(locations[idx], idx);
}
VecEdges edges(edgeIds.size());
for (std::size_t idx=0; idx<edgeIds.size(); idx++)
{
edges[idx] = Edge::Create(nodes[edgeIds[idx].first].get(), nodes[edgeIds[idx].second].get(), idx);
}
VecFaces faces(faceIds.size());
for (std::size_t idx=0; idx<faceIds.size(); idx++)
{
faces[idx] = TriFace::Create(
edges[faceIds[idx][0]].get(),
edges[faceIds[idx][1]].get(),
edges[faceIds[idx][2]].get(),
idx);
}
mesh->populate(nodes, edges, faces);
return mesh;
}

View file

@ -0,0 +1,14 @@
#pragma once
#include "TriMesh.h"
#include "Point.h"
using EdgeIds = std::vector<std::pair<unsigned, unsigned> >;
using FaceIds = std::vector<std::vector<unsigned> >;
using VecPoints = std::vector<Point>;
class MeshBuilder
{
public:
static std::unique_ptr<TriMesh> buildTriMesh(const VecPoints& locations, const EdgeIds& edgeIds, const FaceIds& faceIds);
};

View file

@ -7,20 +7,46 @@
#include "Edge.h" #include "Edge.h"
#include "Face.h" #include "Face.h"
#include "MeshBuilder.h"
#include "AbstractGeometricItem.h"
#include <tuple>
class MeshPrimitives class MeshPrimitives
{ {
public: public:
std::unique_ptr<TriMesh> build(const Rectangle& rectangle) static std::unique_ptr<TriMesh> build(AbstractGeometricItem* item)
{ {
auto mesh = std::make_unique<TriMesh>();
}
static std::unique_ptr<TriMesh> build(const Rectangle& rectangle)
{
const auto bottom_left = rectangle.getBottomLeft(); const auto bottom_left = rectangle.getBottomLeft();
const auto width = rectangle.GetWidth(); const auto width = rectangle.GetWidth();
const auto height = rectangle.GetHeight(); const auto height = rectangle.GetHeight();
//VecNodes nodes = {Node(bottom_left), } VecPoints locations = {
return mesh; bottom_left,
Point(bottom_left, width, 0),
Point(bottom_left, width, height),
Point(bottom_left, 0, height)
};
EdgeIds edge_ids = {
{0, 1},
{1, 2},
{2, 0},
{2, 3},
{3, 0}
};
FaceIds face_ids = {
{0, 1, 2},
{2, 3, 4}
};
return MeshBuilder::buildTriMesh(locations, edge_ids, face_ids);
} }
}; };

View file

@ -1,3 +1,30 @@
#include "Node.h" #include "Node.h"
std::unique_ptr<Node> Node::Create(const Point& p, unsigned index)
{
return std::make_unique<Node>(p, index);
}
Node::~Node()
{
}
Node::Node(const Point& p, unsigned index)
: mPoint(p),
mIndex(index)
{
}
unsigned Node::getIndex() const
{
return mIndex;
}
void Node::updateIndex(unsigned index)
{
mIndex = index;
}

View file

@ -4,22 +4,16 @@
class Node class Node
{ {
Node(const Point& p, unsigned index = 0) public:
: mPoint(p), Node(const Point& p, unsigned index = 0);
mIndex(index)
{
} static std::unique_ptr<Node> Create(const Point& p, unsigned index = 0);
unsigned getIndex() const ~Node();
{
return mIndex;
}
void updateIndex(unsigned index) unsigned getIndex() const;
{
mIndex = index; void updateIndex(unsigned index);
}
private: private:
unsigned mIndex{0}; unsigned mIndex{0};

View file

@ -1,9 +1,20 @@
#include "TriFace.h" #include "TriFace.h"
TriFace::TriFace(Edge* edge0, Edge* edge1, Edge* edge2) TriFace::TriFace(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id)
: mEdge0(edge0), : mEdge0(edge0),
mEdge1(edge1), mEdge1(edge1),
mEdge2(edge2) mEdge2(edge2),
mId(id)
{
}
std::unique_ptr<TriFace> TriFace::Create(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id)
{
return std::make_unique<TriFace>(edge0, edge1, edge2, id);
}
TriFace::~TriFace()
{ {
} }

View file

@ -1,13 +1,18 @@
#pragma once #pragma once
#include <memory>
class Edge; class Edge;
class TriFace class TriFace
{ {
public: public:
TriFace(Edge* edge0, Edge* edge1, Edge* edge2); TriFace(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id=0);
~TriFace();
static std::unique_ptr<TriFace> Create(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id=0);
private: private:
unsigned mId{0};
Edge* mEdge0{nullptr}; Edge* mEdge0{nullptr};
Edge* mEdge1{nullptr}; Edge* mEdge1{nullptr};
Edge* mEdge2{nullptr}; Edge* mEdge2{nullptr};

View file

@ -1,8 +1,17 @@
#include "TriMesh.h" #include "TriMesh.h"
void TriMesh::populate(const VecNodes& nodes, const VecEdges& edges, const VecFaces& faces) #include "Node.h"
#include "Edge.h"
#include "TriFace.h"
TriMesh::~TriMesh()
{ {
//mNodes = std::move(nodes);
//mEdges = std::move(edges); }
//mFaces = std::move(faces);
void TriMesh::populate(VecNodes& nodes, VecEdges& edges, VecFaces& faces)
{
mNodes = std::move(nodes);
mEdges = std::move(edges);
mFaces = std::move(faces);
} }

View file

@ -17,9 +17,12 @@ using VecFaces = std::vector<TriFacePtr>;
class TriMesh class TriMesh
{ {
public:
TriMesh() = default; TriMesh() = default;
void populate(const VecNodes& nodes, const VecEdges& edges, const VecFaces& faces); ~TriMesh();
void populate(VecNodes& nodes, VecEdges& edges, VecFaces& faces);
private: private:
VecNodes mNodes; VecNodes mNodes;

View file

@ -1,7 +1,7 @@
#include "Button.h" #include "Button.h"
#include "TextElement.h" #include "TextNode.h"
#include "GeometryElement.h" #include "GeometryNode.h"
#include "VisualLayer.h" #include "VisualLayer.h"
#include "MouseEvent.h" #include "MouseEvent.h"
@ -11,9 +11,10 @@ Button::Button()
: Widget(), : Widget(),
mLabel(), mLabel(),
mCachedColor(255, 255, 255), mCachedColor(255, 255, 255),
mClickedColor(Color(180, 180, 180)),
mClickFunc() mClickFunc()
{ {
mClickedColor = Color::Create(180, 180, 180);
} }
std::unique_ptr<Button> Button::Create() std::unique_ptr<Button> Button::Create()
@ -39,8 +40,8 @@ void Button::onMyMouseEvent(const MouseEvent* event)
{ {
if(event->GetAction() == MouseEvent::Action::Pressed) if(event->GetAction() == MouseEvent::Action::Pressed)
{ {
mCachedColor = *mBackgroundColor; mCachedColor = mBackgroundColor;
setBackgroundColor(Color::Create(*mClickedColor)); setBackgroundColor(mClickedColor);
if(mClickFunc) if(mClickFunc)
{ {
mClickFunc(this); mClickFunc(this);
@ -48,7 +49,7 @@ void Button::onMyMouseEvent(const MouseEvent* event)
} }
else if(event->GetAction() == MouseEvent::Action::Released) else if(event->GetAction() == MouseEvent::Action::Released)
{ {
setBackgroundColor(Color::Create(mCachedColor)); setBackgroundColor(mCachedColor);
} }
} }
@ -74,9 +75,9 @@ void Button::onPaintEvent(const PaintEvent* event)
unsigned fontOffset = unsigned(mLabel.size()) * 4; unsigned fontOffset = unsigned(mLabel.size()) * 4;
auto middle = DiscretePoint(mLocation.GetX() + mSize.mWidth/2 - fontOffset, mLocation.GetY() + mSize.mHeight/2 + 4); auto middle = DiscretePoint(mLocation.GetX() + mSize.mWidth/2 - fontOffset, mLocation.GetY() + mSize.mHeight/2 + 4);
auto textLayer = VisualLayer::Create(); auto textLayer = VisualLayer::Create();
auto textElement = TextElement::Create(mLabel, middle); auto textElement = TextNode::Create(mLabel, middle);
textElement->SetFillColor(Color::Create(*mBackgroundColor)); textElement->setFillColor(mBackgroundColor);
textLayer->SetText(std::move(textElement)); textLayer->setText(std::move(textElement));
mMyLayers.push_back(std::move(textLayer)); mMyLayers.push_back(std::move(textLayer));
} }
mDirty = false; mDirty = false;

View file

@ -31,7 +31,7 @@ private:
std::string mLabel; std::string mLabel;
clickFunc mClickFunc; clickFunc mClickFunc;
Color mCachedColor; Color mCachedColor;
ColorUPtr mClickedColor; Color mClickedColor;
}; };
using ButtonUPtr = std::unique_ptr<Button>; using ButtonUPtr = std::unique_ptr<Button>;

View file

@ -1,7 +1,7 @@
#include "Label.h" #include "Label.h"
#include "TextElement.h" #include "TextNode.h"
#include "GeometryElement.h" #include "GeometryNode.h"
#include "VisualLayer.h" #include "VisualLayer.h"
Label::Label() Label::Label()
@ -44,12 +44,11 @@ void Label::onPaintEvent(const PaintEvent* event)
if(!mLabel.empty()) if(!mLabel.empty())
{ {
unsigned fontOffset = unsigned(mLabel.size()) * 4; unsigned fontOffset = unsigned(mLabel.size()) * 4;
auto middle = DiscretePoint(mLocation.GetX() + mSize.mWidth/2 - fontOffset, auto middle = DiscretePoint(mLocation.GetX() + mSize.mWidth/2 - fontOffset, mLocation.GetY() + mSize.mHeight/2 + 4);
mLocation.GetY() + mSize.mHeight/2 + 4);
auto textLayer = VisualLayer::Create(); auto textLayer = VisualLayer::Create();
auto textElement = TextElement::Create(mLabel, middle); auto textElement = TextNode::Create(mLabel, middle);
textElement->SetFillColor(Color::Create(*mBackgroundColor)); textElement->setFillColor(mBackgroundColor);
textLayer->SetText(std::move(textElement)); textLayer->setText(std::move(textElement));
mMyLayers.push_back(std::move(textLayer)); mMyLayers.push_back(std::move(textLayer));
} }
addMyLayers(); addMyLayers();

View file

@ -6,9 +6,6 @@
class Label : public Widget class Label : public Widget
{ {
private:
std::string mLabel;
public: public:
@ -19,6 +16,10 @@ public:
void setLabel(const std::string& text); void setLabel(const std::string& text);
void onPaintEvent(const PaintEvent* event) override; void onPaintEvent(const PaintEvent* event) override;
private:
std::string mLabel;
}; };
using LabelUPtr = std::unique_ptr<Label>; using LabelUPtr = std::unique_ptr<Label>;

View file

@ -1,8 +1,8 @@
#include "TextBox.h" #include "TextBox.h"
#include "TextElement.h" #include "TextNode.h"
#include "VisualLayer.h" #include "VisualLayer.h"
#include "GeometryElement.h" #include "GeometryNode.h"
#include "KeyboardEvent.h" #include "KeyboardEvent.h"
#include <sstream> #include <sstream>
@ -12,7 +12,7 @@ TextBox::TextBox()
mContent(), mContent(),
mCaps(false) mCaps(false)
{ {
mBackgroundColor = Color::Create(250, 250, 250); mBackgroundColor = Color(250, 250, 250);
mPadding = {10, 0, 10, 0}; mPadding = {10, 0, 10, 0};
} }
@ -21,17 +21,17 @@ std::unique_ptr<TextBox> TextBox::Create()
return std::make_unique<TextBox>(); return std::make_unique<TextBox>();
} }
void TextBox::SetContent(const std::string& text) void TextBox::setContent(const std::string& text)
{ {
mContent = text; mContent = text;
} }
std::string TextBox::GetContent() const std::string TextBox::getContent() const
{ {
return mContent; return mContent;
} }
void TextBox::AppendContent(const std::string& text) void TextBox::appendContent(const std::string& text)
{ {
mContent += text; mContent += text;
} }
@ -43,7 +43,7 @@ bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event)
const auto keyString = event->GetKeyString(); const auto keyString = event->GetKeyString();
if (keyString == "KEY_RETURN") if (keyString == "KEY_RETURN")
{ {
AppendContent("\n"); appendContent("\n");
} }
else if (keyString == "KEY_BACK") else if (keyString == "KEY_BACK")
{ {
@ -51,7 +51,7 @@ bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event)
} }
else if (keyString == "KEY_SPACE") else if (keyString == "KEY_SPACE")
{ {
AppendContent(" "); appendContent(" ");
} }
else if (keyString == "KEY_CAPS") else if (keyString == "KEY_CAPS")
{ {
@ -62,11 +62,11 @@ bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event)
if (mCaps && !keyString.empty()) if (mCaps && !keyString.empty())
{ {
const char c = std::toupper(keyString[0]); const char c = std::toupper(keyString[0]);
AppendContent(std::string(&c)); appendContent(std::string(&c));
} }
else else
{ {
AppendContent(keyString); appendContent(keyString);
} }
} }
return true; return true;
@ -92,9 +92,9 @@ void TextBox::onPaintEvent(const PaintEvent* event)
auto loc = DiscretePoint(mLocation.GetX() + mPadding.mLeft, auto loc = DiscretePoint(mLocation.GetX() + mPadding.mLeft,
mLocation.GetY() + mPadding.mTop + unsigned(offset)); mLocation.GetY() + mPadding.mTop + unsigned(offset));
auto textLayer = VisualLayer::Create(); auto textLayer = VisualLayer::Create();
auto textElement = TextElement::Create(line, loc); auto textElement = TextNode::Create(line, loc);
textElement->SetFillColor(Color::Create(*mBackgroundColor)); textElement->setFillColor(mBackgroundColor);
textLayer->SetText(std::move(textElement)); textLayer->setText(std::move(textElement));
mMyLayers.push_back(std::move(textLayer)); mMyLayers.push_back(std::move(textLayer));
offset += 20; offset += 20;
} }

View file

@ -6,26 +6,24 @@
class TextBox : public Widget class TextBox : public Widget
{ {
private:
std::string mContent;
bool mCaps;
public: public:
TextBox(); TextBox();
static std::unique_ptr<TextBox> Create(); static std::unique_ptr<TextBox> Create();
void SetContent(const std::string& text); void setContent(const std::string& text);
std::string GetContent() const; std::string getContent() const;
void AppendContent(const std::string& text); void appendContent(const std::string& text);
void onPaintEvent(const PaintEvent* event) override; void onPaintEvent(const PaintEvent* event) override;
bool onMyKeyboardEvent(const KeyboardEvent* event) override; bool onMyKeyboardEvent(const KeyboardEvent* event) override;
private:
std::string mContent;
bool mCaps;
}; };
using TextBoxUPtr = std::unique_ptr<TextBox>; using TextBoxUPtr = std::unique_ptr<TextBox>;

View file

@ -1,16 +1,15 @@
#include "Widget.h" #include "Widget.h"
#include "RectangleElement.h" #include "RectangleNode.h"
#include "MouseEvent.h" #include "MouseEvent.h"
#include "KeyboardEvent.h" #include "KeyboardEvent.h"
#include "PaintEvent.h" #include "PaintEvent.h"
#include "VisualLayer.h" #include "VisualLayer.h"
#include "TextElement.h" #include "TextNode.h"
#include "Color.h" #include "Color.h"
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#include <iostream>
Widget::Widget() Widget::Widget()
: mLocation(DiscretePoint(0, 0)), : mLocation(DiscretePoint(0, 0)),
@ -21,8 +20,8 @@ Widget::Widget()
mLayers(), mLayers(),
mChildren(), mChildren(),
mBorderThickness(0), mBorderThickness(0),
mBackgroundColor(Color::Create(255, 255, 255)), mBackgroundColor(Color(255, 255, 255)),
mBorderColor(Color::Create(0, 0, 0)), mBorderColor(Color(0, 0, 0)),
mVisible(true) mVisible(true)
{ {
@ -48,7 +47,7 @@ Widget::BoundedSize Widget::getSize() const
return mSize; return mSize;
} }
DiscretePoint Widget::getLocation() const const DiscretePoint& Widget::getLocation() const
{ {
return mLocation; return mLocation;
} }
@ -105,7 +104,7 @@ void Widget::setBounds(unsigned width, unsigned height)
mSize.mHeight = height; mSize.mHeight = height;
} }
void Widget::setBackgroundColor(ColorUPtr color) void Widget::setBackgroundColor(const Color& color)
{ {
if (mBackgroundColor != color) if (mBackgroundColor != color)
{ {
@ -273,16 +272,10 @@ void Widget::addBackground(const PaintEvent* event)
unsigned locY = mLocation.GetY() + mMargin.mTop; unsigned locY = mLocation.GetY() + mMargin.mTop;
unsigned deltaX = mSize.mWidth - mMargin.mLeft - mMargin.mRight; unsigned deltaX = mSize.mWidth - mMargin.mLeft - mMargin.mRight;
unsigned deltaY = mSize.mHeight - mMargin.mTop - mMargin.mBottom; unsigned deltaY = mSize.mHeight - mMargin.mTop - mMargin.mBottom;
auto shape = RectangleElement::Create(DiscretePoint(locX, locY), deltaX, deltaY);
std::cout << "Adding shape at : " << locX << " | " << locY << std::endl; auto shape = RectangleNode::Create(DiscretePoint(locX, locY), deltaX, deltaY);
std::cout << "Has dimensions : " << deltaX << " | " << deltaY << std::endl; shape->setFillColor(mBackgroundColor);
auto color = Color::Create(*mBackgroundColor);
std::cout << "Has color : " << color->GetR() << " | " << color->GetG() << " | " << color->GetB() << " | " << color->GetAlpha() << std::endl;
shape->SetFillColor(std::move(color));
auto shapeLayer = VisualLayer::Create(); auto shapeLayer = VisualLayer::Create();
shapeLayer->SetShape(std::move(shape)); shapeLayer->setShape(std::move(shape));
mMyLayers.push_back(std::move(shapeLayer)); mMyLayers.push_back(std::move(shapeLayer));
} }

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "DiscretePoint.h" #include "DiscretePoint.h"
#include "Color.h"
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -10,7 +11,6 @@ class KeyboardEvent;
class PaintEvent; class PaintEvent;
class VisualLayer; class VisualLayer;
class Color;
class Widget class Widget
{ {
@ -73,7 +73,7 @@ public:
std::vector<VisualLayer*> getLayers() const; std::vector<VisualLayer*> getLayers() const;
DiscretePoint getLocation() const; const DiscretePoint& getLocation() const;
virtual void onPaintEvent(const PaintEvent* event); virtual void onPaintEvent(const PaintEvent* event);
@ -83,7 +83,7 @@ public:
bool contains(const DiscretePoint& loc) const; bool contains(const DiscretePoint& loc) const;
void setBackgroundColor(std::unique_ptr<Color> color); void setBackgroundColor(const Color& color);
void setBounds(unsigned width, unsigned height); void setBounds(unsigned width, unsigned height);
@ -123,8 +123,8 @@ protected:
std::vector<VisualLayer*> mLayers; std::vector<VisualLayer*> mLayers;
std::vector<std::unique_ptr<Widget> > mChildren; std::vector<std::unique_ptr<Widget> > mChildren;
unsigned mBorderThickness{0}; unsigned mBorderThickness{0};
std::unique_ptr<Color> mBackgroundColor; Color mBackgroundColor;
std::unique_ptr<Color> mBorderColor; Color mBorderColor;
bool mVisible{false}; bool mVisible{false};
bool mDirty{true}; bool mDirty{true};
}; };

View file

@ -0,0 +1,36 @@
#pragma once
#include "AbstractMesh.h"
#include "Image.h"
#include "DiscretePoint.h"
#include <memory>
class AbstractVisualNode
{
public:
AbstractVisualNode(const DiscretePoint& location)
: mLocation(location)
{
}
AbstractMesh* getMesh() const
{
return mMesh.get();
}
Image<unsigned char>* getImage() const
{
return mImage.get();
}
const DiscretePoint& getLocation() const
{
return mLocation;
}
private:
DiscretePoint mLocation;
std::unique_ptr<AbstractMesh> mMesh;
std::unique_ptr<Image<unsigned char> > mImage;
};

View file

@ -1,7 +1,7 @@
list(APPEND visual_elements_LIB_INCLUDES list(APPEND visual_elements_LIB_INCLUDES
GeometryElement.cpp GeometryNode.cpp
RectangleElement.cpp RectangleNode.cpp
TextElement.cpp TextNode.cpp
VisualLayer.cpp VisualLayer.cpp
) )
@ -12,7 +12,7 @@ target_include_directories(visual_elements PUBLIC
"${PROJECT_SOURCE_DIR}/src/geometry/" "${PROJECT_SOURCE_DIR}/src/geometry/"
) )
target_link_libraries(visual_elements PUBLIC core geometry) target_link_libraries(visual_elements PUBLIC core geometry mesh image)
set_property(TARGET visual_elements PROPERTY FOLDER src) set_property(TARGET visual_elements PROPERTY FOLDER src)

View file

@ -1,39 +0,0 @@
#include "GeometryElement.h"
GeometryElement::GeometryElement()
: mFillColor(Color::Create(255, 255, 255)),
mStrokeColor(Color::Create(0, 0, 0)),
mStrokeThickness(1),
mType(Type::Path)
{
}
Color* GeometryElement::GetFillColor() const
{
return mFillColor.get();
}
Color* GeometryElement::GetStrokeColor() const
{
return mStrokeColor.get();
}
unsigned GeometryElement::GetStrokeThickness() const
{
return mStrokeThickness;
}
void GeometryElement::SetFillColor(ColorUPtr color)
{
mFillColor = std::move(color);
}
void GeometryElement::SetStrokeColor(ColorUPtr color)
{
mStrokeColor = std::move(color);
}
void GeometryElement::SetStrokeThickness(unsigned thickness)
{
mStrokeThickness = thickness;
}

View file

@ -1,37 +0,0 @@
#pragma once
#include "Color.h"
class GeometryElement
{
public:
enum class Type
{
Path,
Rectangle,
Circle,
Arc
};
private:
ColorUPtr mFillColor;
ColorUPtr mStrokeColor;
unsigned mStrokeThickness;
Type mType;
public:
GeometryElement();
virtual ~GeometryElement() = default;
Color* GetFillColor() const;
Color* GetStrokeColor() const;
unsigned GetStrokeThickness() const;
virtual Type GetType() = 0;
void SetFillColor(ColorUPtr color);
void SetStrokeColor(ColorUPtr color);
void SetStrokeThickness(unsigned thickness);
};
using GeometryElementUPtr = std::unique_ptr<GeometryElement>;

View file

@ -0,0 +1,41 @@
#include "GeometryNode.h"
GeometryNode::GeometryNode(const DiscretePoint& location)
: AbstractVisualNode(location),
mFillColor(Color(255, 255, 255)),
mStrokeColor(Color(0, 0, 0)),
mStrokeThickness(1),
mType(Type::Path)
{
}
const Color& GeometryNode::getFillColor() const
{
return mFillColor;
}
const Color& GeometryNode::getStrokeColor() const
{
return mStrokeColor;
}
unsigned GeometryNode::getStrokeThickness() const
{
return mStrokeThickness;
}
void GeometryNode::setFillColor(const Color& color)
{
mFillColor = color;
}
void GeometryNode::setStrokeColor(const Color& color)
{
mStrokeColor = std::move(color);
}
void GeometryNode::setStrokeThickness(unsigned thickness)
{
mStrokeThickness = thickness;
}

View file

@ -0,0 +1,36 @@
#pragma once
#include "AbstractVisualNode.h"
#include "Color.h"
class GeometryNode : public AbstractVisualNode
{
public:
enum class Type
{
Path,
Rectangle,
Circle,
Arc
};
public:
GeometryNode(const DiscretePoint& location);
virtual ~GeometryNode() = default;
const Color& getFillColor() const;
const Color& getStrokeColor() const;
unsigned getStrokeThickness() const;
virtual Type getType() = 0;
void setFillColor(const Color& color);
void setStrokeColor(const Color& color);
void setStrokeThickness(unsigned thickness);
private:
Color mFillColor;
Color mStrokeColor;
unsigned mStrokeThickness{0};
Type mType;
};
using GeometryNodePtr = std::unique_ptr<GeometryNode>;

View file

@ -1,36 +0,0 @@
#include "RectangleElement.h"
RectangleElement::RectangleElement(const DiscretePoint& loc,
unsigned width, unsigned height)
: mLocation(loc),
mWidth(width),
mHeight(height)
{
}
std::unique_ptr<RectangleElement> RectangleElement::Create(const DiscretePoint& loc,
unsigned width, unsigned height)
{
return std::make_unique<RectangleElement>(loc, width, height);
}
GeometryElement::Type RectangleElement::GetType()
{
return GeometryElement::Type::Rectangle;
}
DiscretePoint RectangleElement::GetLocation() const
{
return mLocation;
}
unsigned RectangleElement::GetWidth() const
{
return mWidth;
}
unsigned RectangleElement::GetHeight() const
{
return mHeight;
}

View file

@ -1,28 +0,0 @@
#pragma once
#include <memory>
#include "GeometryElement.h"
#include "DiscretePoint.h"
class RectangleElement : public GeometryElement
{
DiscretePoint mLocation;
unsigned mWidth;
unsigned mHeight;
public:
RectangleElement(const DiscretePoint& loc, unsigned width, unsigned height);
static std::unique_ptr<RectangleElement> Create(const DiscretePoint& loc,
unsigned width, unsigned height);
GeometryElement::Type GetType() override;
DiscretePoint GetLocation() const;
unsigned GetWidth() const;
unsigned GetHeight() const;
};
using RectangleElementUPtr = std::unique_ptr<RectangleElement>;

View file

@ -0,0 +1,29 @@
#include "RectangleNode.h"
RectangleNode::RectangleNode(const DiscretePoint& loc, unsigned width, unsigned height)
: GeometryNode(loc),
mWidth(width),
mHeight(height)
{
}
std::unique_ptr<RectangleNode> RectangleNode::Create(const DiscretePoint& loc, unsigned width, unsigned height)
{
return std::make_unique<RectangleNode>(loc, width, height);
}
GeometryNode::Type RectangleNode::getType()
{
return GeometryNode::Type::Rectangle;
}
unsigned RectangleNode::getWidth() const
{
return mWidth;
}
unsigned RectangleNode::getHeight() const
{
return mHeight;
}

View file

@ -0,0 +1,25 @@
#pragma once
#include <memory>
#include "GeometryNode.h"
#include "DiscretePoint.h"
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);
GeometryNode::Type getType() override;
unsigned getWidth() const;
unsigned getHeight() const;
private:
unsigned mWidth{1};
unsigned mHeight{1};
};
using RectangleNodePtr = std::unique_ptr<RectangleNode>;

View file

@ -1,62 +0,0 @@
#include "TextElement.h"
#include "Color.h"
TextElement::TextElement(const std::string& content, const DiscretePoint& loc)
: mContent(content),
mLocation(loc),
mFontLabel("fixed"),
mFillColor(Color::Create(255, 255, 255)),
mStrokeColor(Color::Create(0, 0, 0))
{
// https://en.wikipedia.org/wiki/Fixed_(typeface)#:~:text=misc%2Dfixed%20is%20a%20collection,to%20a%20single%20font%20family.
}
TextElement::~TextElement()
{
}
std::unique_ptr<TextElement> TextElement::Create(const std::string& content, const DiscretePoint& loc)
{
return std::make_unique<TextElement>(content, loc);
}
Color* TextElement::GetFillColor() const
{
return mFillColor.get();
}
Color* TextElement::GetStrokeColor() const
{
return mStrokeColor.get();
}
DiscretePoint TextElement::GetLocation() const
{
return mLocation;
}
std::string TextElement::GetFontLabel() const
{
return mFontLabel;
}
std::string TextElement::GetContent() const
{
return mContent;
}
void TextElement::SetContent(const std::string& content)
{
mContent = content;
}
void TextElement::SetFillColor(ColorUPtr color)
{
mFillColor = std::move(color);
}
void TextElement::SetStrokeColor(ColorUPtr color)
{
mStrokeColor = std::move(color);
}

View file

@ -1,37 +0,0 @@
#pragma once
#include "DiscretePoint.h"
#include <memory>
#include <string>
class Color;
class TextElement
{
std::string mContent;
DiscretePoint mLocation;
std::string mFontLabel;
std::unique_ptr<Color> mFillColor;
std::unique_ptr<Color> mStrokeColor;
public:
TextElement(const std::string& content, const DiscretePoint& loc);
~TextElement();
static std::unique_ptr<TextElement> Create(const std::string& content, const DiscretePoint& loc);
Color* GetFillColor() const;
Color* GetStrokeColor() const;
DiscretePoint GetLocation() const;
std::string GetContent() const;
std::string GetFontLabel() const;
void SetContent(const std::string& content);
void SetFillColor(std::unique_ptr<Color> color);
void SetStrokeColor(std::unique_ptr<Color> color);
};
using TextElementUPtr = std::unique_ptr<TextElement>;

View file

@ -0,0 +1,57 @@
#include "TextNode.h"
#include "Color.h"
TextNode::TextNode(const std::string& content, const DiscretePoint& loc)
: AbstractVisualNode(loc),
mContent(content),
mFontLabel("fixed"),
mFillColor(Color(255, 255, 255)),
mStrokeColor(Color(0, 0, 0))
{
// https://en.wikipedia.org/wiki/Fixed_(typeface)#:~:text=misc%2Dfixed%20is%20a%20collection,to%20a%20single%20font%20family.
}
TextNode::~TextNode()
{
}
std::unique_ptr<TextNode> TextNode::Create(const std::string& content, const DiscretePoint& loc)
{
return std::make_unique<TextNode>(content, loc);
}
const Color& TextNode::getFillColor() const
{
return mFillColor;
}
const Color& TextNode::getStrokeColor() const
{
return mStrokeColor;
}
std::string TextNode::getFontLabel() const
{
return mFontLabel;
}
std::string TextNode::getContent() const
{
return mContent;
}
void TextNode::setContent(const std::string& content)
{
mContent = content;
}
void TextNode::setFillColor(const Color& color)
{
mFillColor = color;
}
void TextNode::setStrokeColor(const Color& color)
{
mStrokeColor = color;
}

View file

@ -0,0 +1,38 @@
#pragma once
#include "DiscretePoint.h"
#include "AbstractVisualNode.h"
#include "Color.h"
#include <memory>
#include <string>
class Color;
class TextNode : public AbstractVisualNode
{
public:
TextNode(const std::string& content, const DiscretePoint& loc);
~TextNode();
static std::unique_ptr<TextNode> Create(const std::string& content, const DiscretePoint& loc);
const Color& getFillColor() const;
const Color& getStrokeColor() const;
std::string getContent() const;
std::string getFontLabel() const;
void setContent(const std::string& content);
void setFillColor(const Color& color);
void setStrokeColor(const Color& color);
private:
std::string mContent;
std::string mFontLabel;
Color mFillColor;
Color mStrokeColor;
};
using TextNodetr = std::unique_ptr<TextNode>;

View file

@ -1,7 +1,7 @@
#include "VisualLayer.h" #include "VisualLayer.h"
#include "GeometryElement.h" #include "GeometryNode.h"
#include "TextElement.h" #include "TextNode.h"
VisualLayer::VisualLayer() VisualLayer::VisualLayer()
: mShape(), : mShape(),
@ -15,32 +15,32 @@ std::unique_ptr<VisualLayer> VisualLayer::Create()
return std::make_unique<VisualLayer>(); return std::make_unique<VisualLayer>();
} }
bool VisualLayer::HasShape() const bool VisualLayer::hasShape() const
{ {
return bool(mShape); return bool(mShape);
} }
bool VisualLayer::HasText() const bool VisualLayer::hasText() const
{ {
return bool(mText); return bool(mText);
} }
GeometryElement* VisualLayer::GetShape() const GeometryNode* VisualLayer::getShape() const
{ {
return mShape.get(); return mShape.get();
} }
TextElement* VisualLayer::GetText() const TextNode* VisualLayer::getText() const
{ {
return mText.get(); return mText.get();
} }
void VisualLayer::SetShape(GeometryElementUPtr shape) void VisualLayer::setShape(GeometryNodePtr shape)
{ {
mShape = std::move(shape); mShape = std::move(shape);
} }
void VisualLayer::SetText(TextElementUPtr text) void VisualLayer::setText(std::unique_ptr<TextNode> text)
{ {
mText = std::move(text); mText = std::move(text);
} }

View file

@ -1,25 +1,26 @@
#pragma once #pragma once
#include <memory> #include <memory>
class GeometryElement; class GeometryNode;
class TextElement; class TextNode;
class VisualLayer class VisualLayer
{ {
std::unique_ptr<GeometryElement> mShape;
std::unique_ptr<TextElement> mText;
public: public:
VisualLayer(); VisualLayer();
static std::unique_ptr<VisualLayer> Create(); static std::unique_ptr<VisualLayer> Create();
GeometryElement* GetShape() const; GeometryNode* getShape() const;
TextElement* GetText() const; TextNode* getText() const;
bool HasShape() const; bool hasShape() const;
bool HasText() const; bool hasText() const;
void SetShape(std::unique_ptr<GeometryElement> shape); void setShape(std::unique_ptr<GeometryNode> shape);
void SetText(std::unique_ptr<TextElement> text); void setText(std::unique_ptr<TextNode> text);
private:
std::unique_ptr<GeometryNode> mShape;
std::unique_ptr<TextNode> mText;
}; };
using VisualLayerUPtr = std::unique_ptr<VisualLayer>; using VisualLayerUPtr = std::unique_ptr<VisualLayer>;

View file

@ -71,7 +71,7 @@ void WaylandEglWindowInterface::draw()
MLOG_ERROR("Made current failed"); MLOG_ERROR("Made current failed");
} }
OpenGlInterface::draw(); OpenGlInterface::draw(nullptr);
if (!eglSwapBuffers(mEglInterface->getDisplay(), mEglSurface)) if (!eglSwapBuffers(mEglInterface->getDisplay(), mEglSurface))
{ {

View file

@ -24,7 +24,7 @@ XcbGlWindowInterface::~XcbGlWindowInterface()
void XcbGlWindowInterface::draw() void XcbGlWindowInterface::draw()
{ {
OpenGlInterface::draw(); OpenGlInterface::draw(nullptr);
swapBuffers(); swapBuffers();
} }

View file

@ -120,7 +120,7 @@ void XcbInterface::createGraphicsContext()
auto gc = xcb_generate_id(mConnection); auto gc = xcb_generate_id(mConnection);
xcb_drawable_t window = xcb_screen->GetNativeScreen()->root; xcb_drawable_t window = xcb_screen->GetNativeScreen()->root;
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
uint32_t values[2] = {XcbLayerInterface::GetColor(240, 240, 240), 0}; uint32_t values[2] = {XcbLayerInterface::getColor(240, 240, 240), 0};
xcb_create_gc(mConnection, gc, window, mask, values); xcb_create_gc(mConnection, gc, window, mask, values);
xcb_screen->SetGraphicsContext(gc); xcb_screen->SetGraphicsContext(gc);
} }

View file

@ -1,47 +1,47 @@
#include "XcbLayerInterface.h" #include "XcbLayerInterface.h"
#include "XcbTextInterface.h" #include "XcbTextInterface.h"
#include "RectangleElement.h" #include "RectangleNode.h"
#include "VisualLayer.h" #include "VisualLayer.h"
#include <memory> #include <memory>
uint32_t XcbLayerInterface::GetColor(const Color* color) uint32_t XcbLayerInterface::getColor(const Color* color)
{ {
return XcbLayerInterface::GetColor(color->GetR(), color->GetG(), color->GetB()); return XcbLayerInterface::getColor(color->GetR(), color->GetG(), color->GetB());
} }
uint32_t XcbLayerInterface::GetColor(int r, int g, int b) uint32_t XcbLayerInterface::getColor(int r, int g, int b)
{ {
return b + (g<<8) + (r<<16); return b + (g<<8) + (r<<16);
} }
void XcbLayerInterface::ModifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc, const Color* color) void XcbLayerInterface::modifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc, const Color* color)
{ {
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
uint32_t values[2] = {XcbLayerInterface::GetColor(color), 0}; uint32_t values[2] = {XcbLayerInterface::getColor(color), 0};
xcb_change_gc(connection, gc, mask, values); xcb_change_gc(connection, gc, mask, values);
} }
void XcbLayerInterface::AddLayer(xcb_connection_t* connection, xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc, VisualLayer* layer) void XcbLayerInterface::addLayer(xcb_connection_t* connection, xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc, VisualLayer* layer)
{ {
if(layer->HasText()) if(layer->hasText())
{ {
XcbTextInterface::AddTextElement(connection, screen, window, layer->GetText()); XcbTextInterface::AddTextElement(connection, screen, window, layer->getText());
} }
else if(layer->HasShape()) else if(layer->hasShape())
{ {
auto shape = layer->GetShape(); auto shape = layer->getShape();
if(shape->GetType() == GeometryElement::Type::Rectangle) if(shape->getType() == GeometryNode::Type::Rectangle)
{ {
const auto rectangle = dynamic_cast<RectangleElement*>(shape); const auto rectangle = dynamic_cast<RectangleNode*>(shape);
const auto loc = rectangle->GetLocation(); const auto loc = rectangle->getLocation();
const auto width = static_cast<uint16_t>(rectangle->GetWidth()); const auto width = static_cast<uint16_t>(rectangle->getWidth());
const auto height = static_cast<uint16_t>(rectangle->GetHeight()); const auto height = static_cast<uint16_t>(rectangle->getHeight());
xcb_rectangle_t rectangles[] = { { static_cast<int16_t>(loc.GetX()), xcb_rectangle_t rectangles[] = { { static_cast<int16_t>(loc.GetX()),
static_cast<int16_t>(loc.GetY()), width, height} }; static_cast<int16_t>(loc.GetY()), width, height} };
XcbLayerInterface::ModifyGcColor(connection, gc, rectangle->GetFillColor()); XcbLayerInterface::modifyGcColor(connection, gc, &rectangle->getFillColor());
xcb_poly_fill_rectangle(connection, window, gc, 1, rectangles); xcb_poly_fill_rectangle(connection, window, gc, 1, rectangles);
} }
} }

View file

@ -8,12 +8,12 @@ class VisualLayer;
class XcbLayerInterface class XcbLayerInterface
{ {
public: public:
static uint32_t GetColor(const Color* color); static uint32_t getColor(const Color* color);
static uint32_t GetColor(int r, int g, int b); static uint32_t getColor(int r, int g, int b);
static void ModifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc, const Color* color); static void modifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc, const Color* color);
static void AddLayer(xcb_connection_t* connection, xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc, VisualLayer* layer); static void addLayer(xcb_connection_t* connection, xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc, VisualLayer* layer);
}; };

View file

@ -1,14 +1,14 @@
#include "XcbTextInterface.h" #include "XcbTextInterface.h"
#include "XcbLayerInterface.h" #include "XcbLayerInterface.h"
#include "VisualLayer.h" #include "VisualLayer.h"
#include "Color.h" #include "Color.h"
#include "RectangleElement.h"
#include <string.h> #include <string.h>
xcb_gcontext_t XcbTextInterface::GetFontGC(xcb_connection_t *connection, xcb_gcontext_t XcbTextInterface::GetFontGC(xcb_connection_t *connection,
xcb_screen_t *screen, xcb_window_t window, const char* font_name, xcb_screen_t *screen, xcb_window_t window, const char* font_name,
const TextElement* textElement) const TextNode* textElement)
{ {
xcb_font_t font = xcb_generate_id(connection); xcb_font_t font = xcb_generate_id(connection);
xcb_open_font(connection, font, strlen(font_name), font_name); xcb_open_font(connection, font, strlen(font_name), font_name);
@ -16,7 +16,7 @@ xcb_gcontext_t XcbTextInterface::GetFontGC(xcb_connection_t *connection,
/* create graphics context */ /* create graphics context */
xcb_gcontext_t gc = xcb_generate_id(connection); xcb_gcontext_t gc = xcb_generate_id(connection);
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT; uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
auto fillColor = XcbLayerInterface::GetColor(textElement->GetFillColor()); auto fillColor = XcbLayerInterface::getColor(&textElement->getFillColor());
uint32_t value_list[3] = {screen->black_pixel, fillColor, font }; uint32_t value_list[3] = {screen->black_pixel, fillColor, font };
xcb_create_gc(connection, gc, window, mask, value_list); xcb_create_gc(connection, gc, window, mask, value_list);
@ -28,15 +28,15 @@ xcb_gcontext_t XcbTextInterface::GetFontGC(xcb_connection_t *connection,
void XcbTextInterface::AddTextElement(xcb_connection_t* connection, void XcbTextInterface::AddTextElement(xcb_connection_t* connection,
xcb_screen_t* screen, xcb_window_t window, xcb_screen_t* screen, xcb_window_t window,
const TextElement* textElement) const TextNode* textElement)
{ {
/* get graphics context */ /* get graphics context */
auto gc = XcbTextInterface::GetFontGC(connection, screen, window, auto gc = XcbTextInterface::GetFontGC(connection, screen, window,
textElement->GetFontLabel().c_str(), textElement); textElement->getFontLabel().c_str(), textElement);
/* draw the text */ /* draw the text */
const auto content = textElement->GetContent(); const auto content = textElement->getContent();
Pixel loc = textElement->GetLocation(); Pixel loc = textElement->getLocation();
xcb_image_text_8(connection, content.length(), window, gc, xcb_image_text_8(connection, content.length(), window, gc,
loc.GetX(), loc.GetY(), content.c_str()); loc.GetX(), loc.GetY(), content.c_str());

View file

@ -1,17 +1,16 @@
#pragma once #pragma once
#include "TextElement.h" #include "TextNode.h"
#include <xcb/xcb.h> #include <xcb/xcb.h>
class XcbTextInterface class XcbTextInterface
{ {
public: public:
static xcb_gcontext_t GetFontGC(xcb_connection_t* connection, static xcb_gcontext_t GetFontGC(xcb_connection_t* connection, xcb_screen_t*screen, xcb_window_t window,
xcb_screen_t*screen, xcb_window_t window, const char*font_name, const char* font_name, const TextNode* textElement);
const TextElement* textElement);
static void AddTextElement(xcb_connection_t* connection, static void AddTextElement(xcb_connection_t* connection,
xcb_screen_t* screen, xcb_window_t window, xcb_screen_t* screen, xcb_window_t window, const TextNode* textElement);
const TextElement* textElement);
}; };

View file

@ -7,6 +7,7 @@
#include "Rasterizer.h" #include "Rasterizer.h"
#include "LineSegment.h" #include "LineSegment.h"
#include "Point.h" #include "Point.h"
#include "TriMesh.h"
int main() int main()
{ {