From 402f381d107d984dac07c199869c40b957e3b163 Mon Sep 17 00:00:00 2001 From: James Grogan Date: Sun, 13 Nov 2022 17:02:09 +0000 Subject: [PATCH] Cleaning for mesh addition. --- apps/console-main.cpp | 4 +- apps/sample-gui/MediaTool.cpp | 4 +- .../audio_editor/AudioEditorView.cpp | 2 +- .../image_editor/ImageEditorView.cpp | 2 +- .../sample-gui/text_editor/TextEditorView.cpp | 14 ++--- apps/sample-gui/web_client/WebClientView.cpp | 2 +- src/client/GuiApplication.cpp | 2 +- src/client/StatusBar.cpp | 2 +- src/client/TabbedPanelWidget.cpp | 2 +- src/client/TopBar.cpp | 2 +- src/console/MainApplication.cpp | 36 ++++++----- src/console/MainApplication.h | 22 +++---- src/core/Color.h | 13 ++++ src/geometry/DiscretePoint.h | 2 +- src/geometry/Point.cpp | 7 +++ src/geometry/Point.h | 2 +- src/graphics/DrawingContext.cpp | 19 ++++-- src/graphics/DrawingContext.h | 14 +++-- src/graphics/DrawingManager.cpp | 3 +- src/graphics/DrawingManager.h | 4 +- src/graphics/Rasterizer.cpp | 4 +- src/graphics/opengl/OpenGlInterface.cpp | 4 +- src/graphics/opengl/OpenGlInterface.h | 5 +- src/mesh/CMakeLists.txt | 3 + src/mesh/Edge.cpp | 15 ++++- src/mesh/Edge.h | 8 ++- src/mesh/MeshBuilder.cpp | 35 +++++++++++ src/mesh/MeshBuilder.h | 14 +++++ src/mesh/MeshPrimitives.h | 34 ++++++++-- src/mesh/Node.cpp | 27 ++++++++ src/mesh/Node.h | 20 +++--- src/mesh/TriFace.cpp | 15 ++++- src/mesh/TriFace.h | 7 ++- src/mesh/TriMesh.cpp | 17 +++-- src/mesh/TriMesh.h | 5 +- src/ui_elements/widgets/Button.cpp | 19 +++--- src/ui_elements/widgets/Button.h | 2 +- src/ui_elements/widgets/Label.cpp | 13 ++-- src/ui_elements/widgets/Label.h | 7 ++- src/ui_elements/widgets/TextBox.cpp | 26 ++++---- src/ui_elements/widgets/TextBox.h | 16 +++-- src/ui_elements/widgets/Widget.cpp | 25 +++----- src/ui_elements/widgets/Widget.h | 10 +-- src/visual_elements/AbstractVisualNode.h | 36 +++++++++++ src/visual_elements/CMakeLists.txt | 8 +-- src/visual_elements/GeometryElement.cpp | 39 ------------ src/visual_elements/GeometryElement.h | 37 ----------- src/visual_elements/GeometryNode.cpp | 41 ++++++++++++ src/visual_elements/GeometryNode.h | 36 +++++++++++ src/visual_elements/RectangleElement.cpp | 36 ----------- src/visual_elements/RectangleElement.h | 28 --------- src/visual_elements/RectangleNode.cpp | 29 +++++++++ src/visual_elements/RectangleNode.h | 25 ++++++++ src/visual_elements/TextElement.cpp | 62 ------------------- src/visual_elements/TextElement.h | 37 ----------- src/visual_elements/TextNode.cpp | 57 +++++++++++++++++ src/visual_elements/TextNode.h | 38 ++++++++++++ src/visual_elements/VisualLayer.cpp | 16 ++--- src/visual_elements/VisualLayer.h | 23 +++---- .../wayland/WaylandEglWindowInterface.cpp | 2 +- .../x11/XcbGlWindowInterface.cpp | 2 +- .../ui_interfaces/x11/XcbInterface.cpp | 2 +- .../ui_interfaces/x11/XcbLayerInterface.cpp | 34 +++++----- .../ui_interfaces/x11/XcbLayerInterface.h | 8 +-- .../ui_interfaces/x11/XcbTextInterface.cpp | 14 ++--- .../ui_interfaces/x11/XcbTextInterface.h | 11 ++-- test/graphics/TestRasterizer.cpp | 1 + 67 files changed, 655 insertions(+), 456 deletions(-) create mode 100644 src/visual_elements/AbstractVisualNode.h delete mode 100644 src/visual_elements/GeometryElement.cpp delete mode 100644 src/visual_elements/GeometryElement.h create mode 100644 src/visual_elements/GeometryNode.cpp create mode 100644 src/visual_elements/GeometryNode.h delete mode 100644 src/visual_elements/RectangleElement.cpp delete mode 100644 src/visual_elements/RectangleElement.h create mode 100644 src/visual_elements/RectangleNode.cpp create mode 100644 src/visual_elements/RectangleNode.h delete mode 100644 src/visual_elements/TextElement.cpp delete mode 100644 src/visual_elements/TextElement.h create mode 100644 src/visual_elements/TextNode.cpp create mode 100644 src/visual_elements/TextNode.h diff --git a/apps/console-main.cpp b/apps/console-main.cpp index d8239db..1978611 100644 --- a/apps/console-main.cpp +++ b/apps/console-main.cpp @@ -11,8 +11,6 @@ int main(int argc, char *argv[]) auto main_app = MainApplication::Create(); main_app->initialize(std::move(command_line_args)); - main_app->Run(); - - main_app->ShutDown(); + main_app->run(); return 0; } diff --git a/apps/sample-gui/MediaTool.cpp b/apps/sample-gui/MediaTool.cpp index 6de1603..20ef3a6 100644 --- a/apps/sample-gui/MediaTool.cpp +++ b/apps/sample-gui/MediaTool.cpp @@ -56,10 +56,10 @@ void MediaTool::initializeViews() auto button = Button::Create(); button->setLabel("Click!"); button->setBounds(100, 200); - button->setBackgroundColor(Color::Create(0, 0, 255, 0)); + button->setBackgroundColor(Color(0, 0, 255, 0)); 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(); horizontal_spacer->addWidgetWithScale(std::move(button), 1); diff --git a/apps/sample-gui/audio_editor/AudioEditorView.cpp b/apps/sample-gui/audio_editor/AudioEditorView.cpp index 94e9fdf..a0bb338 100644 --- a/apps/sample-gui/audio_editor/AudioEditorView.cpp +++ b/apps/sample-gui/audio_editor/AudioEditorView.cpp @@ -7,7 +7,7 @@ AudioEditorView::AudioEditorView() { auto label = Label::Create(); label->setLabel("Audio Editor"); - label->setBackgroundColor(Color::Create(200, 189, 160)); + label->setBackgroundColor(Color(200, 189, 160)); label->setMargin(1); addWidget(std::move(label)); } diff --git a/apps/sample-gui/image_editor/ImageEditorView.cpp b/apps/sample-gui/image_editor/ImageEditorView.cpp index 41f2f91..ff05aa9 100644 --- a/apps/sample-gui/image_editor/ImageEditorView.cpp +++ b/apps/sample-gui/image_editor/ImageEditorView.cpp @@ -7,7 +7,7 @@ ImageEditorView::ImageEditorView() { auto label = Label::Create(); label->setLabel("Image Editor"); - label->setBackgroundColor(Color::Create(200, 189, 160)); + label->setBackgroundColor(Color(200, 189, 160)); label->setMargin(1); addWidget(std::move(label)); } diff --git a/apps/sample-gui/text_editor/TextEditorView.cpp b/apps/sample-gui/text_editor/TextEditorView.cpp index 4df5614..6a6e972 100644 --- a/apps/sample-gui/text_editor/TextEditorView.cpp +++ b/apps/sample-gui/text_editor/TextEditorView.cpp @@ -19,7 +19,7 @@ void TextEditorView::Initialize() { auto label = Label::Create(); label->setLabel("Text Editor"); - label->setBackgroundColor(Color::Create(181, 189, 200)); + label->setBackgroundColor(Color(181, 189, 200)); label->setMargin(1); auto textBox = TextBox::Create(); @@ -27,12 +27,12 @@ void TextEditorView::Initialize() auto saveButton = Button::Create(); saveButton->setLabel("Save"); - saveButton->setBackgroundColor(Color::Create(200, 200, 200)); + saveButton->setBackgroundColor(Color(200, 200, 200)); saveButton->setMargin(2); auto onSave = [this](Widget* self){ if(this && mController && mTextBox) { - mController->SetContent(mTextBox->GetContent()); + mController->SetContent(mTextBox->getContent()); mController->OnSave(); }; }; @@ -40,26 +40,26 @@ void TextEditorView::Initialize() auto clearButton = Button::Create(); clearButton->setLabel("Clear"); - clearButton->setBackgroundColor(Color::Create(200, 200, 200)); + clearButton->setBackgroundColor(Color(200, 200, 200)); clearButton->setMargin(2); auto onClear = [this](Widget* self){ if(this && mController && mTextBox) { mController->OnClear(); - mTextBox->SetContent(""); + mTextBox->setContent(""); }; }; clearButton->setOnClickFunction(onClear); auto loadButton = Button::Create(); loadButton->setLabel("Load"); - loadButton->setBackgroundColor(Color::Create(200, 200, 200)); + loadButton->setBackgroundColor(Color(200, 200, 200)); loadButton->setMargin(2); auto onLoad = [this](Widget* self){ if(this && mController && mTextBox) { mController->OnLoad(); - mTextBox->SetContent(mController->GetContent()); + mTextBox->setContent(mController->GetContent()); }; }; loadButton->setOnClickFunction(onLoad); diff --git a/apps/sample-gui/web_client/WebClientView.cpp b/apps/sample-gui/web_client/WebClientView.cpp index 0cd152b..752389c 100644 --- a/apps/sample-gui/web_client/WebClientView.cpp +++ b/apps/sample-gui/web_client/WebClientView.cpp @@ -7,7 +7,7 @@ WebClientView::WebClientView() { auto label = Label::Create(); label->setLabel("Web Client"); - label->setBackgroundColor(Color::Create(200, 189, 160)); + label->setBackgroundColor(Color(200, 189, 160)); label->setMargin(1); addWidget(std::move(label)); } diff --git a/src/client/GuiApplication.cpp b/src/client/GuiApplication.cpp index 772ec4d..5fe4025 100644 --- a/src/client/GuiApplication.cpp +++ b/src/client/GuiApplication.cpp @@ -49,5 +49,5 @@ void GuiApplication::run() MLOG_INFO("Window Interface Shut Down"); - mMainApplication->ShutDown(); + mMainApplication->shutDown(); } diff --git a/src/client/StatusBar.cpp b/src/client/StatusBar.cpp index bf98098..eb3c625 100644 --- a/src/client/StatusBar.cpp +++ b/src/client/StatusBar.cpp @@ -4,7 +4,7 @@ StatusBar::StatusBar() { - setBackgroundColor(Color::Create(200, 200, 200)); + setBackgroundColor(Color(200, 200, 200)); } std::unique_ptr StatusBar::Create() diff --git a/src/client/TabbedPanelWidget.cpp b/src/client/TabbedPanelWidget.cpp index a6851cd..a3d8a32 100644 --- a/src/client/TabbedPanelWidget.cpp +++ b/src/client/TabbedPanelWidget.cpp @@ -35,7 +35,7 @@ void TabbedPanelWidget::AddPanel(WidgetUPtr panel, const std::string& label) { auto button = Button::Create(); button->setLabel(label); - button->setBackgroundColor(Color::Create(156, 156, 156)); + button->setBackgroundColor(Color(156, 156, 156)); button->setMargin({1, 0, 0, 1}); auto rawPanel = panel.get(); auto onClick = [this, rawPanel](Widget*){ diff --git a/src/client/TopBar.cpp b/src/client/TopBar.cpp index be83727..ea5c081 100644 --- a/src/client/TopBar.cpp +++ b/src/client/TopBar.cpp @@ -4,7 +4,7 @@ TopBar::TopBar() { - setBackgroundColor(Color::Create(50, 50, 50)); + setBackgroundColor(Color(50, 50, 50)); } std::unique_ptr TopBar::Create() diff --git a/src/console/MainApplication.cpp b/src/console/MainApplication.cpp index ca2aa18..7b60a42 100644 --- a/src/console/MainApplication.cpp +++ b/src/console/MainApplication.cpp @@ -9,8 +9,9 @@ #include "Rasterizer.h" #include "Grid.h" #include "Image.h" +#include "TriMesh.h" -#include "TextElement.h" +#include "TextNode.h" #include "DiscretePoint.h" @@ -23,6 +24,12 @@ MainApplication::MainApplication() } +std::unique_ptr MainApplication::Create() +{ + return std::make_unique(); +} + + MainApplication::~MainApplication() { @@ -53,7 +60,7 @@ void MainApplication::initialize(CommandLineArgsUPtr commandLineArgs, std::uniqu MLOG_INFO("Created Audio Manager"); } -void MainApplication::Run() +void MainApplication::run() { std::string program_type; if(mCommandLineArgs->getNumberOfArgs() > 1) @@ -78,22 +85,22 @@ void MainApplication::Run() if(program_type == "-server") { - RunServer(); + runServer(); } else if(program_type == "-audio") { - PlayAudio(); + playAudio(); } else if(program_type == "-convert") { - ConvertDocument(input_path, output_path); + convertDocument(input_path, output_path); } else if(program_type == "-draw") { auto drawing_manager = DrawingManager::Create(); 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->RenderToFile("test.png"); } @@ -101,21 +108,23 @@ void MainApplication::Run() { MLOG_ERROR("Unknown program type: " + program_type); } + + shutDown(); } -void MainApplication::RunServer() +void MainApplication::runServer() { mNetworkManager->RunHttpServer(); } -void MainApplication::PlayAudio() +void MainApplication::playAudio() { //MidiReader reader; //reader.Read("/home/james/sample.mid"); 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 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); } -CommandLineArgs* MainApplication::GetCommandLineArgs() const +CommandLineArgs* MainApplication::getCommandLineArgs() const { return mCommandLineArgs.get(); } -void MainApplication::ShutDown() +void MainApplication::shutDown() { mDatabaseManager->OnShutDown(); mNetworkManager->ShutDown(); MLOG_INFO("Shut down"); FileLogger::GetInstance().Close(); } - -std::unique_ptr MainApplication::Create() -{ - return std::make_unique(); -} diff --git a/src/console/MainApplication.h b/src/console/MainApplication.h index 9045f0b..1142960 100644 --- a/src/console/MainApplication.h +++ b/src/console/MainApplication.h @@ -17,22 +17,22 @@ public: ~MainApplication(); - void initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr applicationContext=nullptr); - - void Run(); - - void ShutDown(); - - CommandLineArgs* GetCommandLineArgs() const; - static std::unique_ptr Create(); + void initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr applicationContext=nullptr); + + void run(); + + void shutDown(); + + CommandLineArgs* getCommandLineArgs() const; + 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; DatabaseManagerPtr mDatabaseManager; diff --git a/src/core/Color.h b/src/core/Color.h index 4141138..567ba95 100644 --- a/src/core/Color.h +++ b/src/core/Color.h @@ -15,6 +15,19 @@ public: unsigned GetB() 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: unsigned mR{0}; unsigned mG{0}; diff --git a/src/geometry/DiscretePoint.h b/src/geometry/DiscretePoint.h index 2735fb0..997c5bf 100644 --- a/src/geometry/DiscretePoint.h +++ b/src/geometry/DiscretePoint.h @@ -9,7 +9,7 @@ class DiscretePoint public: - DiscretePoint(unsigned x, unsigned y); + DiscretePoint(unsigned x = 0, unsigned y = 0); ~DiscretePoint(); diff --git a/src/geometry/Point.cpp b/src/geometry/Point.cpp index fc8e9db..fbff86a 100644 --- a/src/geometry/Point.cpp +++ b/src/geometry/Point.cpp @@ -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() { }; diff --git a/src/geometry/Point.h b/src/geometry/Point.h index a75a0e2..7e47005 100644 --- a/src/geometry/Point.h +++ b/src/geometry/Point.h @@ -9,7 +9,7 @@ public: Point(double x, double y); - //Point(const Point& reference, double offSetX, double offSetY); + Point(const Point& reference, double offSetX, double offSetY); ~Point(); diff --git a/src/graphics/DrawingContext.cpp b/src/graphics/DrawingContext.cpp index 8bc60e3..20fcf69 100644 --- a/src/graphics/DrawingContext.cpp +++ b/src/graphics/DrawingContext.cpp @@ -3,32 +3,41 @@ #include "INativeDrawingContext.h" #include "AbstractGeometricItem.h" +#include "MeshBuilder.h" + +#include "TriMesh.h" + std::unique_ptr DrawingContext::Create() { return std::make_unique(); } -void DrawingContext::SetNativeContext(std::unique_ptr context) +void DrawingContext::setNativeContext(std::unique_ptr context) { mNativeDrawingContext = std::move(context); } -INativeDrawingContext* DrawingContext::GetNativeContext() +INativeDrawingContext* DrawingContext::getNativeContext() { return mNativeDrawingContext.get(); } -void DrawingContext::AddDrawable(AbstractGeometricItemPtr item) +void DrawingContext::addDrawable(AbstractGeometricItemPtr item) { mItems.push_back(std::move(item)); } -unsigned DrawingContext::GetNumItems() const +unsigned DrawingContext::getNumItems() const { return mItems.size(); } -AbstractGeometricItem* DrawingContext::GetDrawable(unsigned idx) const +AbstractGeometricItem* DrawingContext::getDrawable(unsigned idx) const { return mItems[idx].get(); } + +void DrawingContext::updateMesh() +{ + +} diff --git a/src/graphics/DrawingContext.h b/src/graphics/DrawingContext.h index 545e517..342463b 100644 --- a/src/graphics/DrawingContext.h +++ b/src/graphics/DrawingContext.h @@ -7,6 +7,8 @@ class INativeDrawingContext; class AbstractGeometricItem; using AbstractGeometricItemPtr = std::unique_ptr; +class TriMesh; + class DrawingContext { public: @@ -14,18 +16,20 @@ public: static std::unique_ptr Create(); - void SetNativeContext(std::unique_ptr context); + void setNativeContext(std::unique_ptr 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: + void updateMesh(); + std::unique_ptr mMesh; std::vector > mItems; std::unique_ptr mNativeDrawingContext; }; diff --git a/src/graphics/DrawingManager.cpp b/src/graphics/DrawingManager.cpp index 65d55db..07b6c7f 100644 --- a/src/graphics/DrawingManager.cpp +++ b/src/graphics/DrawingManager.cpp @@ -7,6 +7,7 @@ #include "Grid.h" #include "Image.h" +#include "TriMesh.h" DrawingManager::DrawingManager() : mRasterizer(std::make_unique()) @@ -30,7 +31,7 @@ void DrawingManager::InitializeContext() mDrawingContext = DrawingContext::Create(); } -void DrawingManager::AddText(TextElement* text) +void DrawingManager::AddText(TextNode* text) { if (!mDrawingContext) { diff --git a/src/graphics/DrawingManager.h b/src/graphics/DrawingManager.h index 66eb27e..01d2523 100644 --- a/src/graphics/DrawingManager.h +++ b/src/graphics/DrawingManager.h @@ -5,7 +5,7 @@ #include "INativeDrawingContext.h" #include "INativeDrawingSurface.h" -class TextElement; +class TextNode; class DrawingSurface; using DrawingSurfacePtr = std::unique_ptr; @@ -21,7 +21,7 @@ public: static std::unique_ptr Create(); void InitalizeSurface(unsigned width, unsigned height); void InitializeContext(); - void AddText(TextElement* text); + void AddText(TextNode* text); void RenderToFile(const std::string& path); private: diff --git a/src/graphics/Rasterizer.cpp b/src/graphics/Rasterizer.cpp index c5b1b5e..2736551 100644 --- a/src/graphics/Rasterizer.cpp +++ b/src/graphics/Rasterizer.cpp @@ -16,9 +16,9 @@ void Rasterizer::Paint(DrawingSurface* surface, DrawingContext* context) const auto height = surface->GetHeight(); 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()); diff --git a/src/graphics/opengl/OpenGlInterface.cpp b/src/graphics/opengl/OpenGlInterface.cpp index 7cf5781..267ccdd 100644 --- a/src/graphics/opengl/OpenGlInterface.cpp +++ b/src/graphics/opengl/OpenGlInterface.cpp @@ -5,7 +5,7 @@ #include -void OpenGlInterface::draw() +void OpenGlInterface::draw(TriMesh* mesh) { glClearColor(0.4, 0.4, 0.4, 0.4); glClear(GL_COLOR_BUFFER_BIT); @@ -13,6 +13,8 @@ void OpenGlInterface::draw() glColor3f(1.0, 1.0, 1.0); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + + glBegin(GL_TRIANGLES); glVertex3f(-0.7, 0.7, 0); glVertex3f(0.7, 0.7, 0); diff --git a/src/graphics/opengl/OpenGlInterface.h b/src/graphics/opengl/OpenGlInterface.h index 40264d3..744b171 100644 --- a/src/graphics/opengl/OpenGlInterface.h +++ b/src/graphics/opengl/OpenGlInterface.h @@ -1,10 +1,11 @@ #pragma once +class TriMesh; + class OpenGlInterface { public: - - static void draw(); + static void draw(TriMesh* mesh); }; diff --git a/src/mesh/CMakeLists.txt b/src/mesh/CMakeLists.txt index 12a894d..e29d1d2 100644 --- a/src/mesh/CMakeLists.txt +++ b/src/mesh/CMakeLists.txt @@ -2,6 +2,7 @@ list(APPEND mesh_LIB_INCLUDES AbstractMesh.cpp Edge.cpp Face.cpp + TriFace.cpp Node.cpp QuadMesh.cpp TriMesh.cpp @@ -13,5 +14,7 @@ list(APPEND mesh_LIB_INCLUDES add_library(mesh SHARED ${mesh_LIB_INCLUDES}) 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_property(TARGET mesh PROPERTY FOLDER src) diff --git a/src/mesh/Edge.cpp b/src/mesh/Edge.cpp index a4290b5..5ef8101 100644 --- a/src/mesh/Edge.cpp +++ b/src/mesh/Edge.cpp @@ -2,8 +2,19 @@ #include "Node.h" -Edge::Edge(Node* node0, Node* node1) +Edge::Edge(Node* node0, Node* node1, unsigned id) : mNode0(node0), - mNode1(node1) + mNode1(node1), + mId(id) { } + +std::unique_ptr Edge::Create(Node* node0, Node* node1, unsigned id) +{ + return std::make_unique(node0, node1, id); +} + +Edge::~Edge() +{ + +} diff --git a/src/mesh/Edge.h b/src/mesh/Edge.h index 8bfaba2..d9899fb 100644 --- a/src/mesh/Edge.h +++ b/src/mesh/Edge.h @@ -2,12 +2,18 @@ class Node; +#include + class Edge { public: - Edge(Node* node0, Node* node1); + Edge(Node* node0, Node* node1, unsigned id = 0); + ~Edge(); + + static std::unique_ptr Create(Node* node0, Node* node1, unsigned id = 0); private: + unsigned mId{0}; Node* mNode0{nullptr}; Node* mNode1{nullptr}; }; diff --git a/src/mesh/MeshBuilder.cpp b/src/mesh/MeshBuilder.cpp index e69de29..1159431 100644 --- a/src/mesh/MeshBuilder.cpp +++ b/src/mesh/MeshBuilder.cpp @@ -0,0 +1,35 @@ +#include "MeshBuilder.h" + +#include "Node.h" +#include "Edge.h" +#include "TriFace.h" + +std::unique_ptr MeshBuilder::buildTriMesh(const VecPoints& locations, const EdgeIds& edgeIds, const FaceIds& faceIds) +{ + auto mesh = std::make_unique(); + + VecNodes nodes(locations.size()); + for (std::size_t idx=0; idxpopulate(nodes, edges, faces); + return mesh; +} diff --git a/src/mesh/MeshBuilder.h b/src/mesh/MeshBuilder.h index e69de29..596ab56 100644 --- a/src/mesh/MeshBuilder.h +++ b/src/mesh/MeshBuilder.h @@ -0,0 +1,14 @@ +#pragma once + +#include "TriMesh.h" +#include "Point.h" + +using EdgeIds = std::vector >; +using FaceIds = std::vector >; +using VecPoints = std::vector; + +class MeshBuilder +{ +public: + static std::unique_ptr buildTriMesh(const VecPoints& locations, const EdgeIds& edgeIds, const FaceIds& faceIds); +}; diff --git a/src/mesh/MeshPrimitives.h b/src/mesh/MeshPrimitives.h index 4a73c3e..71d50b3 100644 --- a/src/mesh/MeshPrimitives.h +++ b/src/mesh/MeshPrimitives.h @@ -7,20 +7,46 @@ #include "Edge.h" #include "Face.h" +#include "MeshBuilder.h" +#include "AbstractGeometricItem.h" + +#include + class MeshPrimitives { public: - std::unique_ptr build(const Rectangle& rectangle) + static std::unique_ptr build(AbstractGeometricItem* item) { - auto mesh = std::make_unique(); + } + static std::unique_ptr build(const Rectangle& rectangle) + { const auto bottom_left = rectangle.getBottomLeft(); const auto width = rectangle.GetWidth(); const auto height = rectangle.GetHeight(); - //VecNodes nodes = {Node(bottom_left), } - return mesh; + VecPoints locations = { + 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); } }; diff --git a/src/mesh/Node.cpp b/src/mesh/Node.cpp index 1e5b784..0526f58 100644 --- a/src/mesh/Node.cpp +++ b/src/mesh/Node.cpp @@ -1,3 +1,30 @@ #include "Node.h" +std::unique_ptr Node::Create(const Point& p, unsigned index) +{ + return std::make_unique(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; +} + diff --git a/src/mesh/Node.h b/src/mesh/Node.h index 1f606a1..6cf673a 100644 --- a/src/mesh/Node.h +++ b/src/mesh/Node.h @@ -4,22 +4,16 @@ class Node { - Node(const Point& p, unsigned index = 0) - : mPoint(p), - mIndex(index) - { +public: + Node(const Point& p, unsigned index = 0); - } + static std::unique_ptr Create(const Point& p, unsigned index = 0); - unsigned getIndex() const - { - return mIndex; - } + ~Node(); - void updateIndex(unsigned index) - { - mIndex = index; - } + unsigned getIndex() const; + + void updateIndex(unsigned index); private: unsigned mIndex{0}; diff --git a/src/mesh/TriFace.cpp b/src/mesh/TriFace.cpp index 524ed05..d84c0d2 100644 --- a/src/mesh/TriFace.cpp +++ b/src/mesh/TriFace.cpp @@ -1,9 +1,20 @@ #include "TriFace.h" -TriFace::TriFace(Edge* edge0, Edge* edge1, Edge* edge2) +TriFace::TriFace(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id) : mEdge0(edge0), mEdge1(edge1), - mEdge2(edge2) + mEdge2(edge2), + mId(id) +{ + +} + +std::unique_ptr TriFace::Create(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id) +{ + return std::make_unique(edge0, edge1, edge2, id); +} + +TriFace::~TriFace() { } diff --git a/src/mesh/TriFace.h b/src/mesh/TriFace.h index b5fa184..529c93d 100644 --- a/src/mesh/TriFace.h +++ b/src/mesh/TriFace.h @@ -1,13 +1,18 @@ #pragma once +#include + class Edge; class TriFace { public: - TriFace(Edge* edge0, Edge* edge1, Edge* edge2); + TriFace(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id=0); + ~TriFace(); + static std::unique_ptr Create(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id=0); private: + unsigned mId{0}; Edge* mEdge0{nullptr}; Edge* mEdge1{nullptr}; Edge* mEdge2{nullptr}; diff --git a/src/mesh/TriMesh.cpp b/src/mesh/TriMesh.cpp index c6817cf..6919105 100644 --- a/src/mesh/TriMesh.cpp +++ b/src/mesh/TriMesh.cpp @@ -1,8 +1,17 @@ #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); } diff --git a/src/mesh/TriMesh.h b/src/mesh/TriMesh.h index 5d19d1a..80b0a29 100644 --- a/src/mesh/TriMesh.h +++ b/src/mesh/TriMesh.h @@ -17,9 +17,12 @@ using VecFaces = std::vector; class TriMesh { +public: TriMesh() = default; - void populate(const VecNodes& nodes, const VecEdges& edges, const VecFaces& faces); + ~TriMesh(); + + void populate(VecNodes& nodes, VecEdges& edges, VecFaces& faces); private: VecNodes mNodes; diff --git a/src/ui_elements/widgets/Button.cpp b/src/ui_elements/widgets/Button.cpp index ac21a5a..929613a 100644 --- a/src/ui_elements/widgets/Button.cpp +++ b/src/ui_elements/widgets/Button.cpp @@ -1,7 +1,7 @@ #include "Button.h" -#include "TextElement.h" -#include "GeometryElement.h" +#include "TextNode.h" +#include "GeometryNode.h" #include "VisualLayer.h" #include "MouseEvent.h" @@ -11,9 +11,10 @@ Button::Button() : Widget(), mLabel(), mCachedColor(255, 255, 255), + mClickedColor(Color(180, 180, 180)), mClickFunc() { - mClickedColor = Color::Create(180, 180, 180); + } std::unique_ptr