Tue, 20 Jul 2021 01:22:01 +0300
work on draw preview
#pragma once #include "gl/partrenderer.h" #include "gl/gridprogram.h" #include "gl/axesprogram.h" class Canvas : public PartRenderer { Q_OBJECT public: struct MouseClickInfo; enum PreviewLayerName : std::int8_t { DrawToolPreview }; struct PreviewLayer { QVector<geom::NPolygon> polygons; QColor color{64, 255, 128}; }; static constexpr int NUM_PREVIEW_LAYERS = 1; Canvas( Model* model, DocumentManager* documents, const ldraw::ColorTable& colorTable, QWidget* parent = nullptr); const PreviewLayer& getPreviewLayer(PreviewLayerName name) const; PreviewLayer& modifyPreviewLayer(PreviewLayerName name); public slots: void handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds); protected: void mouseMoveEvent(QMouseEvent* event) override; void mousePressEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; void initializeGL() override; void paintGL() override; signals: void newStatusText(const QString& newStatusText); void selectionChanged(const QSet<ldraw::id_t>& newSelection); void mouseClick(const MouseClickInfo& info); private: void updateGridMatrix(); glm::vec3 cameraVector() const; bool isGridPerpendicularToScreen(float threshold) const; std::optional<GridProgram> gridProgram; std::optional<AxesProgram> axesProgram; std::optional<glm::vec3> worldPosition; glm::mat4 gridMatrix; geom::Plane gridPlane; int totalMouseMove = 0; QSet<ldraw::id_t> selection; PreviewLayer previewLayers[NUM_PREVIEW_LAYERS]; }; struct Canvas::MouseClickInfo { std::optional<glm::vec3> worldPosition; Canvas* invoker; };