diff --git a/src/client/GuiApplication.cpp b/src/client/GuiApplication.cpp index 092e04d..f871ada 100644 --- a/src/client/GuiApplication.cpp +++ b/src/client/GuiApplication.cpp @@ -29,7 +29,7 @@ AbstractApp* GuiApplication::getMainApplication() const void GuiApplication::initializeViews() { - + mDesktopManager->getWindowManager()->getMainWindow()->setSize(800, 600); } void GuiApplication::setUiInterfaceBackend(UiInterfaceFactory::Backend backend) diff --git a/src/geometry/Point.cpp b/src/geometry/Point.cpp index fbff86a..b556ad2 100644 --- a/src/geometry/Point.cpp +++ b/src/geometry/Point.cpp @@ -6,9 +6,16 @@ Point::Point(double x, double y) { } +Point::Point(const DiscretePoint& point) + : mX(point.GetX()), + mY(point.GetY()) +{ + +} + Point::Point(const Point& reference, double offSetX, double offSetY) : mX(reference.getX() + offSetX), - mY(reference.getX() + offSetY) + mY(reference.getY() + offSetY) { } diff --git a/src/geometry/Point.h b/src/geometry/Point.h index 7e47005..740eb6c 100644 --- a/src/geometry/Point.h +++ b/src/geometry/Point.h @@ -1,5 +1,7 @@ #pragma once +#include "DiscretePoint.h" + #include #include @@ -9,6 +11,8 @@ public: Point(double x, double y); + Point(const DiscretePoint& point); + Point(const Point& reference, double offSetX, double offSetY); ~Point(); diff --git a/src/geometry/Rectangle.cpp b/src/geometry/Rectangle.cpp index 5ed0a19..25d20e1 100644 --- a/src/geometry/Rectangle.cpp +++ b/src/geometry/Rectangle.cpp @@ -7,6 +7,14 @@ Rectangle::Rectangle(const Point& bottomLeft, const Point& topRight) mWidth = mBottomLeft.getDeltaX(topRight); } +Rectangle::Rectangle(const Point& bottomLeft, double width, double height) + : mBottomLeft(bottomLeft), + mHeight(height), + mWidth(width) +{ + +} + Rectangle Rectangle::getBounds() const { return Rectangle(mBottomLeft, Point(mBottomLeft, mWidth, mHeight)); diff --git a/src/geometry/Rectangle.h b/src/geometry/Rectangle.h index d850f47..5e12fc7 100644 --- a/src/geometry/Rectangle.h +++ b/src/geometry/Rectangle.h @@ -11,6 +11,7 @@ class Rectangle : public AbstractGeometricItem public: Rectangle(const Point& bottomLeft, const Point& topRight); + Rectangle(const Point& bottomLeft, double width, double height); double getHeight() const; diff --git a/src/graphics/DrawingContext.cpp b/src/graphics/DrawingContext.cpp index 9004434..d3cf6d4 100644 --- a/src/graphics/DrawingContext.cpp +++ b/src/graphics/DrawingContext.cpp @@ -1,16 +1,13 @@ #include "DrawingContext.h" -#include "AbstractGeometricItem.h" #include "AbstractPainter.h" #include "OpenGlPainter.h" #include "RasterPainter.h" +#include "Grid.h" +#include "TriMesh.h" + #include "DrawingSurface.h" #include "Scene.h" -#include "Grid.h" - -#include "MeshBuilder.h" - -#include "TriMesh.h" DrawingContext::DrawingContext(DrawingSurface* surface, DrawingMode requestedDrawingMode) : mSurface(surface), @@ -32,11 +29,6 @@ std::unique_ptr DrawingContext::Create(DrawingSurface* surface, return std::make_unique(surface, requestedDrawingMode); } -void DrawingContext::updateMesh() -{ - -} - Scene* DrawingContext::getScene() const { return mScene.get(); @@ -49,5 +41,6 @@ DrawingSurface* DrawingContext::getSurface() const void DrawingContext::paint() { - + mScene->update(mDrawingMode == DrawingMode::RASTER ? mSurface->getImage() : nullptr); + mPainter->paint(this); } diff --git a/src/graphics/DrawingContext.h b/src/graphics/DrawingContext.h index ebcbe64..9c5fcf5 100644 --- a/src/graphics/DrawingContext.h +++ b/src/graphics/DrawingContext.h @@ -6,7 +6,6 @@ class Scene; class AbstractPainter; class DrawingSurface; -class TriMesh; enum class DrawingMode { @@ -28,12 +27,10 @@ public: void paint(); private: - void updateMesh(); - DrawingMode mDrawingMode; - std::unique_ptr mMesh; - std::unique_ptr mScene; + DrawingSurface* mSurface{nullptr}; + std::unique_ptr mScene; std::unique_ptr mPainter; }; diff --git a/src/graphics/opengl/OpenGlPainter.cpp b/src/graphics/opengl/OpenGlPainter.cpp index a6626cb..92c301f 100644 --- a/src/graphics/opengl/OpenGlPainter.cpp +++ b/src/graphics/opengl/OpenGlPainter.cpp @@ -1,6 +1,9 @@ #include "OpenGlPainter.h" #include "DrawingContext.h" +#include "DrawingSurface.h" +#include "Scene.h" +#include "TriMesh.h" #ifdef _WIN32 #include @@ -8,19 +11,47 @@ #include +#include + void OpenGlPainter::paint(DrawingContext* context) { + auto surface = context->getSurface(); + const auto width = double(surface->getWidth()); + const auto height = double(surface->getHeight()); + + const auto num_mesh = context->getScene()->getNumMeshes(); + glClearColor(0.4, 0.4, 0.4, 0.4); glClear(GL_COLOR_BUFFER_BIT); - 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); - glVertex3f(0, -1, 0); - glEnd(); + for (std::size_t idx=0; idxgetScene()->getMesh(idx); + const auto faces = mesh->getFaceVertices(); + + glColor3f(1.0, 0.0, 1.0); + + for (const auto& face : faces) + { + glBegin(GL_TRIANGLES); + double x0 = 2.0*face[0].getX() / width - 1.0; + double y0 = 2.0*face[0].getY() / height - 1.0; + + double x1 = 2.0*face[1].getX() / width - 1.0; + double y1 = 2.0*face[1].getY() / height - 1.0; + + double x2 = 2.0*face[2].getX() / width - 1.0; + double y2 = 2.0*face[2].getY() / height - 1.0; + + glVertex3f(x0, y0, 0); + glVertex3f(x1, y1, 0); + glVertex3f(x2, y2, 0); + + glEnd(); + } + } glFlush(); } diff --git a/src/mesh/AbstractMesh.h b/src/mesh/AbstractMesh.h index cb4ba9f..a27414e 100644 --- a/src/mesh/AbstractMesh.h +++ b/src/mesh/AbstractMesh.h @@ -1,8 +1,7 @@ #pragma once -class AbstractGeometricItem; - class AbstractMesh { - +public: + virtual ~AbstractMesh() = default; }; diff --git a/src/mesh/Edge.cpp b/src/mesh/Edge.cpp index 5ef8101..35d8dec 100644 --- a/src/mesh/Edge.cpp +++ b/src/mesh/Edge.cpp @@ -18,3 +18,13 @@ Edge::~Edge() { } + +unsigned Edge::getNode0Id() const +{ + return mNode0->getIndex(); +} + +unsigned Edge::getNode1Id() const +{ + return mNode1->getIndex(); +} diff --git a/src/mesh/Edge.h b/src/mesh/Edge.h index d9899fb..6e73af9 100644 --- a/src/mesh/Edge.h +++ b/src/mesh/Edge.h @@ -12,6 +12,10 @@ public: static std::unique_ptr Create(Node* node0, Node* node1, unsigned id = 0); + unsigned getNode0Id() const; + + unsigned getNode1Id() const; + private: unsigned mId{0}; Node* mNode0{nullptr}; diff --git a/src/mesh/MeshPrimitives.h b/src/mesh/MeshPrimitives.h index 71d50b3..7d683ff 100644 --- a/src/mesh/MeshPrimitives.h +++ b/src/mesh/MeshPrimitives.h @@ -16,16 +16,11 @@ class MeshPrimitives { public: - static std::unique_ptr build(AbstractGeometricItem* item) - { - - } - static std::unique_ptr build(const Rectangle& rectangle) { - const auto bottom_left = rectangle.getBottomLeft(); - const auto width = rectangle.GetWidth(); - const auto height = rectangle.GetHeight(); + const auto bottom_left = rectangle.getLocation(); + const auto width = rectangle.getWidth(); + const auto height = rectangle.getHeight(); VecPoints locations = { bottom_left, diff --git a/src/mesh/Node.h b/src/mesh/Node.h index 6cf673a..92abdba 100644 --- a/src/mesh/Node.h +++ b/src/mesh/Node.h @@ -15,6 +15,11 @@ public: void updateIndex(unsigned index); + const Point& getPoint() const + { + return mPoint; + } + private: unsigned mIndex{0}; Point mPoint; diff --git a/src/mesh/TriFace.cpp b/src/mesh/TriFace.cpp index d84c0d2..efe0b44 100644 --- a/src/mesh/TriFace.cpp +++ b/src/mesh/TriFace.cpp @@ -1,5 +1,7 @@ #include "TriFace.h" +#include "Edge.h" + TriFace::TriFace(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id) : mEdge0(edge0), mEdge1(edge1), @@ -18,3 +20,8 @@ TriFace::~TriFace() { } + +std::vector TriFace::getNodeIds() const +{ + return {mEdge0->getNode0Id(), mEdge0->getNode1Id(), mEdge1->getNode1Id()}; +} diff --git a/src/mesh/TriFace.h b/src/mesh/TriFace.h index 529c93d..43aa17d 100644 --- a/src/mesh/TriFace.h +++ b/src/mesh/TriFace.h @@ -1,6 +1,7 @@ #pragma once #include +#include class Edge; @@ -11,6 +12,8 @@ public: ~TriFace(); static std::unique_ptr Create(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id=0); + + std::vector getNodeIds() const; private: unsigned mId{0}; Edge* mEdge0{nullptr}; diff --git a/src/mesh/TriMesh.cpp b/src/mesh/TriMesh.cpp index 6919105..1046f22 100644 --- a/src/mesh/TriMesh.cpp +++ b/src/mesh/TriMesh.cpp @@ -15,3 +15,15 @@ void TriMesh::populate(VecNodes& nodes, VecEdges& edges, VecFaces& faces) mEdges = std::move(edges); mFaces = std::move(faces); } + +std::vector > TriMesh::getFaceVertices() const +{ + std::vector > verts(mFaces.size()); + + for(std::size_t idx=0; idxgetNodeIds(); + verts[idx] = {mNodes[nodeIds[0]]->getPoint(), mNodes[nodeIds[1]]->getPoint(), mNodes[nodeIds[2]]->getPoint()}; + } + return verts; +} diff --git a/src/mesh/TriMesh.h b/src/mesh/TriMesh.h index 80b0a29..989761f 100644 --- a/src/mesh/TriMesh.h +++ b/src/mesh/TriMesh.h @@ -1,5 +1,8 @@ #pragma once +#include "AbstractMesh.h" +#include "Point.h" + #include #include @@ -15,7 +18,7 @@ using VecNodes = std::vector; using VecEdges = std::vector; using VecFaces = std::vector; -class TriMesh +class TriMesh : public AbstractMesh { public: TriMesh() = default; @@ -24,6 +27,8 @@ public: void populate(VecNodes& nodes, VecEdges& edges, VecFaces& faces); + std::vector > getFaceVertices() const; + private: VecNodes mNodes; VecEdges mEdges; diff --git a/src/ui_elements/desktop_elements/Window.cpp b/src/ui_elements/desktop_elements/Window.cpp index 855d8c8..540f326 100644 --- a/src/ui_elements/desktop_elements/Window.cpp +++ b/src/ui_elements/desktop_elements/Window.cpp @@ -22,9 +22,9 @@ Window::Window() : DrawingSurface(), mWidget(Widget::Create()) { - mWidget->setBounds(mWidth, mHeight); mWidth = 800; mHeight = 600; + mWidget->setBounds(mWidth, mHeight); } Window::~Window() @@ -104,7 +104,7 @@ void Window::doPaint(mt::Screen* screen) { mPlatformWindow->beforePaint(screen); - mDrawingContext->getScene()->setLayers(mWidget->getLayers()); + mDrawingContext->getScene()->syncLayers(mWidget->getLayers()); mDrawingContext->paint(); diff --git a/src/ui_elements/widgets/Button.cpp b/src/ui_elements/widgets/Button.cpp index 929613a..458e7f1 100644 --- a/src/ui_elements/widgets/Button.cpp +++ b/src/ui_elements/widgets/Button.cpp @@ -74,10 +74,11 @@ 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 = TextNode::Create(mLabel, middle); - textElement->setFillColor(mBackgroundColor); - textLayer->setText(std::move(textElement)); + auto node = TextNode::Create(mLabel, middle); + node->setFillColor(mBackgroundColor); + textLayer->setTextNode(std::move(node)); mMyLayers.push_back(std::move(textLayer)); } mDirty = false; diff --git a/src/ui_elements/widgets/Label.cpp b/src/ui_elements/widgets/Label.cpp index b0ca4dc..524725d 100644 --- a/src/ui_elements/widgets/Label.cpp +++ b/src/ui_elements/widgets/Label.cpp @@ -48,7 +48,7 @@ void Label::onPaintEvent(const PaintEvent* event) auto textLayer = VisualLayer::Create(); auto textElement = TextNode::Create(mLabel, middle); textElement->setFillColor(mBackgroundColor); - textLayer->setText(std::move(textElement)); + textLayer->setTextNode(std::move(textElement)); mMyLayers.push_back(std::move(textLayer)); } addMyLayers(); diff --git a/src/ui_elements/widgets/TextBox.cpp b/src/ui_elements/widgets/TextBox.cpp index 35fd669..bce6163 100644 --- a/src/ui_elements/widgets/TextBox.cpp +++ b/src/ui_elements/widgets/TextBox.cpp @@ -94,7 +94,7 @@ void TextBox::onPaintEvent(const PaintEvent* event) auto textLayer = VisualLayer::Create(); auto textElement = TextNode::Create(line, loc); textElement->setFillColor(mBackgroundColor); - textLayer->setText(std::move(textElement)); + textLayer->setTextNode(std::move(textElement)); mMyLayers.push_back(std::move(textLayer)); offset += 20; } diff --git a/src/ui_elements/widgets/Widget.cpp b/src/ui_elements/widgets/Widget.cpp index 9f8b9d0..3daa840 100644 --- a/src/ui_elements/widgets/Widget.cpp +++ b/src/ui_elements/widgets/Widget.cpp @@ -10,6 +10,7 @@ #include #include +#include Widget::Widget() : mLocation(DiscretePoint(0, 0)), @@ -99,9 +100,9 @@ void Widget::setBounds(unsigned width, unsigned height) if (width != mSize.mWidth || height != mSize.mHeight) { mDirty = true; + mSize.mWidth = width; + mSize.mHeight = height; } - mSize.mWidth = width; - mSize.mHeight = height; } void Widget::setBackgroundColor(const Color& color) @@ -273,9 +274,9 @@ void Widget::addBackground(const PaintEvent* event) unsigned deltaX = mSize.mWidth - mMargin.mLeft - mMargin.mRight; unsigned deltaY = mSize.mHeight - mMargin.mTop - mMargin.mBottom; - auto shape = RectangleNode::Create(DiscretePoint(locX, locY), deltaX, deltaY); - shape->setFillColor(mBackgroundColor); - auto shapeLayer = VisualLayer::Create(); - shapeLayer->setShape(std::move(shape)); - mMyLayers.push_back(std::move(shapeLayer)); + auto node = RectangleNode::Create(DiscretePoint(locX, locY), deltaX, deltaY); + node->setFillColor(mBackgroundColor); + auto layer = VisualLayer::Create(); + layer->setShapeNode(std::move(node)); + mMyLayers.push_back(std::move(layer)); } diff --git a/src/visual_elements/AbstractVisualNode.h b/src/visual_elements/AbstractVisualNode.h index 98c7b3a..9aadedb 100644 --- a/src/visual_elements/AbstractVisualNode.h +++ b/src/visual_elements/AbstractVisualNode.h @@ -14,11 +14,18 @@ public: } + virtual ~AbstractVisualNode() = default; + AbstractMesh* getMesh() const { return mMesh.get(); } + virtual void updateMesh() + { + + } + Image* getImage() const { return mImage.get(); @@ -29,7 +36,7 @@ public: return mLocation; } -private: +protected: DiscretePoint mLocation; std::unique_ptr mMesh; std::unique_ptr > mImage; diff --git a/src/visual_elements/RectangleNode.cpp b/src/visual_elements/RectangleNode.cpp index 0efc62f..8a01240 100644 --- a/src/visual_elements/RectangleNode.cpp +++ b/src/visual_elements/RectangleNode.cpp @@ -1,5 +1,10 @@ #include "RectangleNode.h" +#include "Rectangle.h" +#include "MeshPrimitives.h" + +#include + RectangleNode::RectangleNode(const DiscretePoint& loc, unsigned width, unsigned height) : GeometryNode(loc), mWidth(width), @@ -27,3 +32,11 @@ unsigned RectangleNode::getHeight() const { return mHeight; } + +void RectangleNode::updateMesh() +{ + const auto rect = Rectangle(mLocation, mWidth, mHeight); + + auto mesh = MeshPrimitives::build(rect); + mMesh = std::move(mesh); +} diff --git a/src/visual_elements/RectangleNode.h b/src/visual_elements/RectangleNode.h index ccfa5ca..0cd30ff 100644 --- a/src/visual_elements/RectangleNode.h +++ b/src/visual_elements/RectangleNode.h @@ -15,6 +15,8 @@ public: unsigned getWidth() const; unsigned getHeight() const; + void updateMesh() override; + private: unsigned mWidth{1}; unsigned mHeight{1}; diff --git a/src/visual_elements/Scene.cpp b/src/visual_elements/Scene.cpp index e69de29..007f15c 100644 --- a/src/visual_elements/Scene.cpp +++ b/src/visual_elements/Scene.cpp @@ -0,0 +1,54 @@ +#include "Scene.h" + +#include "VisualLayer.h" +#include "GeometryNode.h" +#include "RectangleNode.h" + +#include "MeshBuilder.h" +#include "TriMesh.h" + +void Scene::syncLayers(const std::vector& layers) +{ + mLayers = layers; +} + +void Scene::update(Image* image) +{ + if (image) + { + // + } + else + { + mWorkingMeshs.clear(); + for(auto layer : mLayers) + { + if (layer->hasShapeNode()) + { + auto node = layer->getShapeNode(); + if (layer->getIsDirty()) + { + node->updateMesh(); + layer->setIsDirty(false); + } + + mWorkingMeshs.push_back(dynamic_cast(node->getMesh())); + } + } + } +} + +void Scene::processRectangleNode(RectangleNode* node) +{ + +} + +unsigned Scene::getNumMeshes() const +{ + return mWorkingMeshs.size(); +} + +TriMesh* Scene::getMesh(std::size_t idx) const +{ + return mWorkingMeshs[idx]; +} diff --git a/src/visual_elements/Scene.h b/src/visual_elements/Scene.h index 5e91124..fd9faee 100644 --- a/src/visual_elements/Scene.h +++ b/src/visual_elements/Scene.h @@ -1,23 +1,33 @@ #pragma once #include +#include class VisualLayer; +class TriMesh; + +class RectangleNode; + +template +class Image; class Scene { public: Scene() = default; - void setLayers(const std::vector& layers) - { - mLayers = layers; - } + void syncLayers(const std::vector& layers); + + void update(Image* image = nullptr); + + unsigned getNumMeshes() const; + + TriMesh* getMesh(std::size_t idx) const; - const std::vector& getLayers() const - { - return mLayers; - } private: + + void processRectangleNode(RectangleNode* node); + + std::vector mWorkingMeshs; std::vector mLayers; }; diff --git a/src/visual_elements/VisualLayer.cpp b/src/visual_elements/VisualLayer.cpp index 4613ed1..042ccfe 100644 --- a/src/visual_elements/VisualLayer.cpp +++ b/src/visual_elements/VisualLayer.cpp @@ -15,32 +15,32 @@ std::unique_ptr VisualLayer::Create() return std::make_unique(); } -bool VisualLayer::hasShape() const +bool VisualLayer::hasShapeNode() const { return bool(mShape); } -bool VisualLayer::hasText() const +bool VisualLayer::hasTextNode() const { return bool(mText); } -GeometryNode* VisualLayer::getShape() const +GeometryNode* VisualLayer::getShapeNode() const { return mShape.get(); } -TextNode* VisualLayer::getText() const +TextNode* VisualLayer::getTextNode() const { return mText.get(); } -void VisualLayer::setShape(GeometryNodePtr shape) +void VisualLayer::setShapeNode(GeometryNodePtr shape) { mShape = std::move(shape); } -void VisualLayer::setText(std::unique_ptr text) +void VisualLayer::setTextNode(std::unique_ptr text) { mText = std::move(text); } diff --git a/src/visual_elements/VisualLayer.h b/src/visual_elements/VisualLayer.h index 9c888e9..f87e18f 100644 --- a/src/visual_elements/VisualLayer.h +++ b/src/visual_elements/VisualLayer.h @@ -12,14 +12,25 @@ public: static std::unique_ptr Create(); - GeometryNode* getShape() const; - TextNode* getText() const; - bool hasShape() const; - bool hasText() const; - void setShape(std::unique_ptr shape); - void setText(std::unique_ptr text); + GeometryNode* getShapeNode() const; + TextNode* getTextNode() const; + bool hasShapeNode() const; + bool hasTextNode() const; + void setShapeNode(std::unique_ptr shape); + void setTextNode(std::unique_ptr text); + + bool getIsDirty() const + { + return mIsDirty; + } + + void setIsDirty(bool isDirty) + { + mIsDirty = isDirty; + } private: + bool mIsDirty{true}; std::unique_ptr mShape; std::unique_ptr mText; }; diff --git a/src/windows/ui_interfaces/x11/XcbLayerInterface.cpp b/src/windows/ui_interfaces/x11/XcbLayerInterface.cpp index 1bc1e62..8261ff2 100644 --- a/src/windows/ui_interfaces/x11/XcbLayerInterface.cpp +++ b/src/windows/ui_interfaces/x11/XcbLayerInterface.cpp @@ -26,6 +26,7 @@ void XcbLayerInterface::modifyGcColor(xcb_connection_t* connection, xcb_gcontext void XcbLayerInterface::addLayer(xcb_connection_t* connection, xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc, VisualLayer* layer) { + /* if(layer->hasText()) { XcbTextInterface::AddTextElement(connection, screen, window, layer->getText()); @@ -45,5 +46,6 @@ void XcbLayerInterface::addLayer(xcb_connection_t* connection, xcb_screen_t* scr xcb_poly_fill_rectangle(connection, window, gc, 1, rectangles); } } + */ }