Cleaning for mesh addition.
This commit is contained in:
parent
8e0ce22b57
commit
402f381d10
67 changed files with 655 additions and 456 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -49,5 +49,5 @@ void GuiApplication::run()
|
|||
|
||||
MLOG_INFO("Window Interface Shut Down");
|
||||
|
||||
mMainApplication->ShutDown();
|
||||
mMainApplication->shutDown();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
StatusBar::StatusBar()
|
||||
{
|
||||
setBackgroundColor(Color::Create(200, 200, 200));
|
||||
setBackgroundColor(Color(200, 200, 200));
|
||||
}
|
||||
|
||||
std::unique_ptr<StatusBar> StatusBar::Create()
|
||||
|
|
|
@ -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*){
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
TopBar::TopBar()
|
||||
{
|
||||
setBackgroundColor(Color::Create(50, 50, 50));
|
||||
setBackgroundColor(Color(50, 50, 50));
|
||||
}
|
||||
|
||||
std::unique_ptr<TopBar> TopBar::Create()
|
||||
|
|
|
@ -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> MainApplication::Create()
|
||||
{
|
||||
return std::make_unique<MainApplication>();
|
||||
}
|
||||
|
||||
|
||||
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> MainApplication::Create()
|
||||
{
|
||||
return std::make_unique<MainApplication>();
|
||||
}
|
||||
|
|
|
@ -17,22 +17,22 @@ public:
|
|||
|
||||
~MainApplication();
|
||||
|
||||
void initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr<IApplicationContext> applicationContext=nullptr);
|
||||
|
||||
void Run();
|
||||
|
||||
void ShutDown();
|
||||
|
||||
CommandLineArgs* GetCommandLineArgs() const;
|
||||
|
||||
static std::unique_ptr<MainApplication> Create();
|
||||
|
||||
void initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr<IApplicationContext> 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;
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -9,7 +9,7 @@ class DiscretePoint
|
|||
|
||||
public:
|
||||
|
||||
DiscretePoint(unsigned x, unsigned y);
|
||||
DiscretePoint(unsigned x = 0, unsigned y = 0);
|
||||
|
||||
~DiscretePoint();
|
||||
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -3,32 +3,41 @@
|
|||
#include "INativeDrawingContext.h"
|
||||
#include "AbstractGeometricItem.h"
|
||||
|
||||
#include "MeshBuilder.h"
|
||||
|
||||
#include "TriMesh.h"
|
||||
|
||||
std::unique_ptr<DrawingContext> DrawingContext::Create()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ class INativeDrawingContext;
|
|||
class AbstractGeometricItem;
|
||||
using AbstractGeometricItemPtr = std::unique_ptr<AbstractGeometricItem>;
|
||||
|
||||
class TriMesh;
|
||||
|
||||
class DrawingContext
|
||||
{
|
||||
public:
|
||||
|
@ -14,18 +16,20 @@ public:
|
|||
|
||||
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:
|
||||
void updateMesh();
|
||||
|
||||
std::unique_ptr<TriMesh> mMesh;
|
||||
std::vector<std::unique_ptr<AbstractGeometricItem> > mItems;
|
||||
std::unique_ptr<INativeDrawingContext> mNativeDrawingContext;
|
||||
};
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "Grid.h"
|
||||
#include "Image.h"
|
||||
#include "TriMesh.h"
|
||||
|
||||
DrawingManager::DrawingManager()
|
||||
: mRasterizer(std::make_unique<Rasterizer>())
|
||||
|
@ -30,7 +31,7 @@ void DrawingManager::InitializeContext()
|
|||
mDrawingContext = DrawingContext::Create();
|
||||
}
|
||||
|
||||
void DrawingManager::AddText(TextElement* text)
|
||||
void DrawingManager::AddText(TextNode* text)
|
||||
{
|
||||
if (!mDrawingContext)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "INativeDrawingContext.h"
|
||||
#include "INativeDrawingSurface.h"
|
||||
|
||||
class TextElement;
|
||||
class TextNode;
|
||||
|
||||
class DrawingSurface;
|
||||
using DrawingSurfacePtr = std::unique_ptr<DrawingSurface>;
|
||||
|
@ -21,7 +21,7 @@ public:
|
|||
static std::unique_ptr<DrawingManager> Create();
|
||||
void InitalizeSurface(unsigned width, unsigned height);
|
||||
void InitializeContext();
|
||||
void AddText(TextElement* text);
|
||||
void AddText(TextNode* text);
|
||||
void RenderToFile(const std::string& path);
|
||||
|
||||
private:
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <GL/gl.h>
|
||||
|
||||
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);
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
class TriMesh;
|
||||
|
||||
class OpenGlInterface
|
||||
{
|
||||
public:
|
||||
|
||||
static void draw();
|
||||
static void draw(TriMesh* mesh);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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> Edge::Create(Node* node0, Node* node1, unsigned id)
|
||||
{
|
||||
return std::make_unique<Edge>(node0, node1, id);
|
||||
}
|
||||
|
||||
Edge::~Edge()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -2,12 +2,18 @@
|
|||
|
||||
class Node;
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Edge
|
||||
{
|
||||
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:
|
||||
unsigned mId{0};
|
||||
Node* mNode0{nullptr};
|
||||
Node* mNode1{nullptr};
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
};
|
|
@ -7,20 +7,46 @@
|
|||
#include "Edge.h"
|
||||
#include "Face.h"
|
||||
|
||||
#include "MeshBuilder.h"
|
||||
#include "AbstractGeometricItem.h"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
class MeshPrimitives
|
||||
{
|
||||
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 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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,3 +1,30 @@
|
|||
#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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<Node> 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};
|
||||
|
|
|
@ -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> TriFace::Create(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id)
|
||||
{
|
||||
return std::make_unique<TriFace>(edge0, edge1, edge2, id);
|
||||
}
|
||||
|
||||
TriFace::~TriFace()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
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<TriFace> Create(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id=0);
|
||||
private:
|
||||
unsigned mId{0};
|
||||
Edge* mEdge0{nullptr};
|
||||
Edge* mEdge1{nullptr};
|
||||
Edge* mEdge2{nullptr};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -17,9 +17,12 @@ using VecFaces = std::vector<TriFacePtr>;
|
|||
|
||||
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;
|
||||
|
|
|
@ -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<Button> Button::Create()
|
||||
|
@ -39,8 +40,8 @@ void Button::onMyMouseEvent(const MouseEvent* event)
|
|||
{
|
||||
if(event->GetAction() == MouseEvent::Action::Pressed)
|
||||
{
|
||||
mCachedColor = *mBackgroundColor;
|
||||
setBackgroundColor(Color::Create(*mClickedColor));
|
||||
mCachedColor = mBackgroundColor;
|
||||
setBackgroundColor(mClickedColor);
|
||||
if(mClickFunc)
|
||||
{
|
||||
mClickFunc(this);
|
||||
|
@ -48,7 +49,7 @@ void Button::onMyMouseEvent(const MouseEvent* event)
|
|||
}
|
||||
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;
|
||||
auto middle = DiscretePoint(mLocation.GetX() + mSize.mWidth/2 - fontOffset, mLocation.GetY() + mSize.mHeight/2 + 4);
|
||||
auto textLayer = VisualLayer::Create();
|
||||
auto textElement = TextElement::Create(mLabel, middle);
|
||||
textElement->SetFillColor(Color::Create(*mBackgroundColor));
|
||||
textLayer->SetText(std::move(textElement));
|
||||
auto textElement = TextNode::Create(mLabel, middle);
|
||||
textElement->setFillColor(mBackgroundColor);
|
||||
textLayer->setText(std::move(textElement));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
}
|
||||
mDirty = false;
|
||||
|
|
|
@ -31,7 +31,7 @@ private:
|
|||
std::string mLabel;
|
||||
clickFunc mClickFunc;
|
||||
Color mCachedColor;
|
||||
ColorUPtr mClickedColor;
|
||||
Color mClickedColor;
|
||||
};
|
||||
|
||||
using ButtonUPtr = std::unique_ptr<Button>;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "Label.h"
|
||||
|
||||
#include "TextElement.h"
|
||||
#include "GeometryElement.h"
|
||||
#include "TextNode.h"
|
||||
#include "GeometryNode.h"
|
||||
#include "VisualLayer.h"
|
||||
|
||||
Label::Label()
|
||||
|
@ -44,12 +44,11 @@ void Label::onPaintEvent(const PaintEvent* event)
|
|||
if(!mLabel.empty())
|
||||
{
|
||||
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 textElement = TextElement::Create(mLabel, middle);
|
||||
textElement->SetFillColor(Color::Create(*mBackgroundColor));
|
||||
textLayer->SetText(std::move(textElement));
|
||||
auto textElement = TextNode::Create(mLabel, middle);
|
||||
textElement->setFillColor(mBackgroundColor);
|
||||
textLayer->setText(std::move(textElement));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
}
|
||||
addMyLayers();
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
|
||||
class Label : public Widget
|
||||
{
|
||||
private:
|
||||
|
||||
std::string mLabel;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -19,6 +16,10 @@ public:
|
|||
void setLabel(const std::string& text);
|
||||
|
||||
void onPaintEvent(const PaintEvent* event) override;
|
||||
|
||||
private:
|
||||
std::string mLabel;
|
||||
|
||||
};
|
||||
|
||||
using LabelUPtr = std::unique_ptr<Label>;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "TextBox.h"
|
||||
|
||||
#include "TextElement.h"
|
||||
#include "TextNode.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "GeometryElement.h"
|
||||
#include "GeometryNode.h"
|
||||
#include "KeyboardEvent.h"
|
||||
|
||||
#include <sstream>
|
||||
|
@ -12,7 +12,7 @@ TextBox::TextBox()
|
|||
mContent(),
|
||||
mCaps(false)
|
||||
{
|
||||
mBackgroundColor = Color::Create(250, 250, 250);
|
||||
mBackgroundColor = Color(250, 250, 250);
|
||||
mPadding = {10, 0, 10, 0};
|
||||
}
|
||||
|
||||
|
@ -21,17 +21,17 @@ std::unique_ptr<TextBox> TextBox::Create()
|
|||
return std::make_unique<TextBox>();
|
||||
}
|
||||
|
||||
void TextBox::SetContent(const std::string& text)
|
||||
void TextBox::setContent(const std::string& text)
|
||||
{
|
||||
mContent = text;
|
||||
}
|
||||
|
||||
std::string TextBox::GetContent() const
|
||||
std::string TextBox::getContent() const
|
||||
{
|
||||
return mContent;
|
||||
}
|
||||
|
||||
void TextBox::AppendContent(const std::string& text)
|
||||
void TextBox::appendContent(const std::string& text)
|
||||
{
|
||||
mContent += text;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event)
|
|||
const auto keyString = event->GetKeyString();
|
||||
if (keyString == "KEY_RETURN")
|
||||
{
|
||||
AppendContent("\n");
|
||||
appendContent("\n");
|
||||
}
|
||||
else if (keyString == "KEY_BACK")
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event)
|
|||
}
|
||||
else if (keyString == "KEY_SPACE")
|
||||
{
|
||||
AppendContent(" ");
|
||||
appendContent(" ");
|
||||
}
|
||||
else if (keyString == "KEY_CAPS")
|
||||
{
|
||||
|
@ -62,11 +62,11 @@ bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event)
|
|||
if (mCaps && !keyString.empty())
|
||||
{
|
||||
const char c = std::toupper(keyString[0]);
|
||||
AppendContent(std::string(&c));
|
||||
appendContent(std::string(&c));
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendContent(keyString);
|
||||
appendContent(keyString);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -92,9 +92,9 @@ void TextBox::onPaintEvent(const PaintEvent* event)
|
|||
auto loc = DiscretePoint(mLocation.GetX() + mPadding.mLeft,
|
||||
mLocation.GetY() + mPadding.mTop + unsigned(offset));
|
||||
auto textLayer = VisualLayer::Create();
|
||||
auto textElement = TextElement::Create(line, loc);
|
||||
textElement->SetFillColor(Color::Create(*mBackgroundColor));
|
||||
textLayer->SetText(std::move(textElement));
|
||||
auto textElement = TextNode::Create(line, loc);
|
||||
textElement->setFillColor(mBackgroundColor);
|
||||
textLayer->setText(std::move(textElement));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
offset += 20;
|
||||
}
|
||||
|
|
|
@ -6,26 +6,24 @@
|
|||
|
||||
class TextBox : public Widget
|
||||
{
|
||||
private:
|
||||
|
||||
std::string mContent;
|
||||
bool mCaps;
|
||||
|
||||
public:
|
||||
|
||||
TextBox();
|
||||
|
||||
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;
|
||||
|
||||
bool onMyKeyboardEvent(const KeyboardEvent* event) override;
|
||||
|
||||
private:
|
||||
std::string mContent;
|
||||
bool mCaps;
|
||||
};
|
||||
|
||||
using TextBoxUPtr = std::unique_ptr<TextBox>;
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
#include "Widget.h"
|
||||
|
||||
#include "RectangleElement.h"
|
||||
#include "RectangleNode.h"
|
||||
#include "MouseEvent.h"
|
||||
#include "KeyboardEvent.h"
|
||||
#include "PaintEvent.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "TextElement.h"
|
||||
#include "TextNode.h"
|
||||
#include "Color.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
|
||||
Widget::Widget()
|
||||
: mLocation(DiscretePoint(0, 0)),
|
||||
|
@ -21,8 +20,8 @@ Widget::Widget()
|
|||
mLayers(),
|
||||
mChildren(),
|
||||
mBorderThickness(0),
|
||||
mBackgroundColor(Color::Create(255, 255, 255)),
|
||||
mBorderColor(Color::Create(0, 0, 0)),
|
||||
mBackgroundColor(Color(255, 255, 255)),
|
||||
mBorderColor(Color(0, 0, 0)),
|
||||
mVisible(true)
|
||||
{
|
||||
|
||||
|
@ -48,7 +47,7 @@ Widget::BoundedSize Widget::getSize() const
|
|||
return mSize;
|
||||
}
|
||||
|
||||
DiscretePoint Widget::getLocation() const
|
||||
const DiscretePoint& Widget::getLocation() const
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
@ -105,7 +104,7 @@ void Widget::setBounds(unsigned width, unsigned height)
|
|||
mSize.mHeight = height;
|
||||
}
|
||||
|
||||
void Widget::setBackgroundColor(ColorUPtr color)
|
||||
void Widget::setBackgroundColor(const Color& color)
|
||||
{
|
||||
if (mBackgroundColor != color)
|
||||
{
|
||||
|
@ -273,16 +272,10 @@ void Widget::addBackground(const PaintEvent* event)
|
|||
unsigned locY = mLocation.GetY() + mMargin.mTop;
|
||||
unsigned deltaX = mSize.mWidth - mMargin.mLeft - mMargin.mRight;
|
||||
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;
|
||||
std::cout << "Has dimensions : " << deltaX << " | " << deltaY << std::endl;
|
||||
|
||||
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 shape = RectangleNode::Create(DiscretePoint(locX, locY), deltaX, deltaY);
|
||||
shape->setFillColor(mBackgroundColor);
|
||||
auto shapeLayer = VisualLayer::Create();
|
||||
shapeLayer->SetShape(std::move(shape));
|
||||
shapeLayer->setShape(std::move(shape));
|
||||
mMyLayers.push_back(std::move(shapeLayer));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "DiscretePoint.h"
|
||||
#include "Color.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
@ -10,7 +11,6 @@ class KeyboardEvent;
|
|||
class PaintEvent;
|
||||
|
||||
class VisualLayer;
|
||||
class Color;
|
||||
|
||||
class Widget
|
||||
{
|
||||
|
@ -73,7 +73,7 @@ public:
|
|||
|
||||
std::vector<VisualLayer*> getLayers() const;
|
||||
|
||||
DiscretePoint getLocation() const;
|
||||
const DiscretePoint& getLocation() const;
|
||||
|
||||
virtual void onPaintEvent(const PaintEvent* event);
|
||||
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
|
||||
bool contains(const DiscretePoint& loc) const;
|
||||
|
||||
void setBackgroundColor(std::unique_ptr<Color> color);
|
||||
void setBackgroundColor(const Color& color);
|
||||
|
||||
void setBounds(unsigned width, unsigned height);
|
||||
|
||||
|
@ -123,8 +123,8 @@ protected:
|
|||
std::vector<VisualLayer*> mLayers;
|
||||
std::vector<std::unique_ptr<Widget> > mChildren;
|
||||
unsigned mBorderThickness{0};
|
||||
std::unique_ptr<Color> mBackgroundColor;
|
||||
std::unique_ptr<Color> mBorderColor;
|
||||
Color mBackgroundColor;
|
||||
Color mBorderColor;
|
||||
bool mVisible{false};
|
||||
bool mDirty{true};
|
||||
};
|
||||
|
|
36
src/visual_elements/AbstractVisualNode.h
Normal file
36
src/visual_elements/AbstractVisualNode.h
Normal 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;
|
||||
};
|
|
@ -1,7 +1,7 @@
|
|||
list(APPEND visual_elements_LIB_INCLUDES
|
||||
GeometryElement.cpp
|
||||
RectangleElement.cpp
|
||||
TextElement.cpp
|
||||
GeometryNode.cpp
|
||||
RectangleNode.cpp
|
||||
TextNode.cpp
|
||||
VisualLayer.cpp
|
||||
)
|
||||
|
||||
|
@ -12,7 +12,7 @@ target_include_directories(visual_elements PUBLIC
|
|||
"${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)
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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>;
|
41
src/visual_elements/GeometryNode.cpp
Normal file
41
src/visual_elements/GeometryNode.cpp
Normal 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;
|
||||
}
|
36
src/visual_elements/GeometryNode.h
Normal file
36
src/visual_elements/GeometryNode.h
Normal 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>;
|
|
@ -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;
|
||||
}
|
|
@ -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>;
|
||||
|
||||
|
29
src/visual_elements/RectangleNode.cpp
Normal file
29
src/visual_elements/RectangleNode.cpp
Normal 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;
|
||||
}
|
25
src/visual_elements/RectangleNode.h
Normal file
25
src/visual_elements/RectangleNode.h
Normal 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>;
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
|
@ -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>;
|
57
src/visual_elements/TextNode.cpp
Normal file
57
src/visual_elements/TextNode.cpp
Normal 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;
|
||||
}
|
38
src/visual_elements/TextNode.h
Normal file
38
src/visual_elements/TextNode.h
Normal 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>;
|
|
@ -1,7 +1,7 @@
|
|||
#include "VisualLayer.h"
|
||||
|
||||
#include "GeometryElement.h"
|
||||
#include "TextElement.h"
|
||||
#include "GeometryNode.h"
|
||||
#include "TextNode.h"
|
||||
|
||||
VisualLayer::VisualLayer()
|
||||
: mShape(),
|
||||
|
@ -15,32 +15,32 @@ std::unique_ptr<VisualLayer> VisualLayer::Create()
|
|||
return std::make_unique<VisualLayer>();
|
||||
}
|
||||
|
||||
bool VisualLayer::HasShape() const
|
||||
bool VisualLayer::hasShape() const
|
||||
{
|
||||
return bool(mShape);
|
||||
}
|
||||
|
||||
bool VisualLayer::HasText() const
|
||||
bool VisualLayer::hasText() const
|
||||
{
|
||||
return bool(mText);
|
||||
}
|
||||
|
||||
GeometryElement* VisualLayer::GetShape() const
|
||||
GeometryNode* VisualLayer::getShape() const
|
||||
{
|
||||
return mShape.get();
|
||||
}
|
||||
|
||||
TextElement* VisualLayer::GetText() const
|
||||
TextNode* VisualLayer::getText() const
|
||||
{
|
||||
return mText.get();
|
||||
}
|
||||
|
||||
void VisualLayer::SetShape(GeometryElementUPtr shape)
|
||||
void VisualLayer::setShape(GeometryNodePtr shape)
|
||||
{
|
||||
mShape = std::move(shape);
|
||||
}
|
||||
|
||||
void VisualLayer::SetText(TextElementUPtr text)
|
||||
void VisualLayer::setText(std::unique_ptr<TextNode> text)
|
||||
{
|
||||
mText = std::move(text);
|
||||
}
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
class GeometryElement;
|
||||
class TextElement;
|
||||
class GeometryNode;
|
||||
class TextNode;
|
||||
|
||||
class VisualLayer
|
||||
{
|
||||
std::unique_ptr<GeometryElement> mShape;
|
||||
std::unique_ptr<TextElement> mText;
|
||||
|
||||
public:
|
||||
|
||||
VisualLayer();
|
||||
|
||||
static std::unique_ptr<VisualLayer> Create();
|
||||
|
||||
GeometryElement* GetShape() const;
|
||||
TextElement* GetText() const;
|
||||
bool HasShape() const;
|
||||
bool HasText() const;
|
||||
void SetShape(std::unique_ptr<GeometryElement> shape);
|
||||
void SetText(std::unique_ptr<TextElement> text);
|
||||
GeometryNode* getShape() const;
|
||||
TextNode* getText() const;
|
||||
bool hasShape() const;
|
||||
bool hasText() const;
|
||||
void setShape(std::unique_ptr<GeometryNode> shape);
|
||||
void setText(std::unique_ptr<TextNode> text);
|
||||
|
||||
private:
|
||||
std::unique_ptr<GeometryNode> mShape;
|
||||
std::unique_ptr<TextNode> mText;
|
||||
};
|
||||
using VisualLayerUPtr = std::unique_ptr<VisualLayer>;
|
||||
|
|
|
@ -71,7 +71,7 @@ void WaylandEglWindowInterface::draw()
|
|||
MLOG_ERROR("Made current failed");
|
||||
}
|
||||
|
||||
OpenGlInterface::draw();
|
||||
OpenGlInterface::draw(nullptr);
|
||||
|
||||
if (!eglSwapBuffers(mEglInterface->getDisplay(), mEglSurface))
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ XcbGlWindowInterface::~XcbGlWindowInterface()
|
|||
|
||||
void XcbGlWindowInterface::draw()
|
||||
{
|
||||
OpenGlInterface::draw();
|
||||
OpenGlInterface::draw(nullptr);
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ void XcbInterface::createGraphicsContext()
|
|||
auto gc = xcb_generate_id(mConnection);
|
||||
xcb_drawable_t window = xcb_screen->GetNativeScreen()->root;
|
||||
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_screen->SetGraphicsContext(gc);
|
||||
}
|
||||
|
|
|
@ -1,47 +1,47 @@
|
|||
#include "XcbLayerInterface.h"
|
||||
|
||||
#include "XcbTextInterface.h"
|
||||
#include "RectangleElement.h"
|
||||
#include "RectangleNode.h"
|
||||
#include "VisualLayer.h"
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
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 values[2] = {XcbLayerInterface::GetColor(color), 0};
|
||||
uint32_t values[2] = {XcbLayerInterface::getColor(color), 0};
|
||||
|
||||
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();
|
||||
if(shape->GetType() == GeometryElement::Type::Rectangle)
|
||||
auto shape = layer->getShape();
|
||||
if(shape->getType() == GeometryNode::Type::Rectangle)
|
||||
{
|
||||
const auto rectangle = dynamic_cast<RectangleElement*>(shape);
|
||||
const auto loc = rectangle->GetLocation();
|
||||
const auto width = static_cast<uint16_t>(rectangle->GetWidth());
|
||||
const auto height = static_cast<uint16_t>(rectangle->GetHeight());
|
||||
const auto rectangle = dynamic_cast<RectangleNode*>(shape);
|
||||
const auto loc = rectangle->getLocation();
|
||||
const auto width = static_cast<uint16_t>(rectangle->getWidth());
|
||||
const auto height = static_cast<uint16_t>(rectangle->getHeight());
|
||||
xcb_rectangle_t rectangles[] = { { static_cast<int16_t>(loc.GetX()),
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ class VisualLayer;
|
|||
class XcbLayerInterface
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#include "XcbTextInterface.h"
|
||||
|
||||
#include "XcbLayerInterface.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "Color.h"
|
||||
#include "RectangleElement.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
xcb_gcontext_t XcbTextInterface::GetFontGC(xcb_connection_t *connection,
|
||||
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_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 */
|
||||
xcb_gcontext_t gc = xcb_generate_id(connection);
|
||||
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 };
|
||||
|
||||
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,
|
||||
xcb_screen_t* screen, xcb_window_t window,
|
||||
const TextElement* textElement)
|
||||
const TextNode* textElement)
|
||||
{
|
||||
/* get graphics context */
|
||||
auto gc = XcbTextInterface::GetFontGC(connection, screen, window,
|
||||
textElement->GetFontLabel().c_str(), textElement);
|
||||
textElement->getFontLabel().c_str(), textElement);
|
||||
|
||||
/* draw the text */
|
||||
const auto content = textElement->GetContent();
|
||||
Pixel loc = textElement->GetLocation();
|
||||
const auto content = textElement->getContent();
|
||||
Pixel loc = textElement->getLocation();
|
||||
xcb_image_text_8(connection, content.length(), window, gc,
|
||||
loc.GetX(), loc.GetY(), content.c_str());
|
||||
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
#pragma once
|
||||
#include "TextElement.h"
|
||||
#include "TextNode.h"
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
class XcbTextInterface
|
||||
{
|
||||
|
||||
public:
|
||||
static xcb_gcontext_t GetFontGC(xcb_connection_t* connection,
|
||||
xcb_screen_t*screen, xcb_window_t window, const char*font_name,
|
||||
const TextElement* textElement);
|
||||
static xcb_gcontext_t GetFontGC(xcb_connection_t* connection, xcb_screen_t*screen, xcb_window_t window,
|
||||
const char* font_name, const TextNode* textElement);
|
||||
|
||||
static void AddTextElement(xcb_connection_t* connection,
|
||||
xcb_screen_t* screen, xcb_window_t window,
|
||||
const TextElement* textElement);
|
||||
xcb_screen_t* screen, xcb_window_t window, const TextNode* textElement);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "Rasterizer.h"
|
||||
#include "LineSegment.h"
|
||||
#include "Point.h"
|
||||
#include "TriMesh.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue