9 { |
10 { |
10 Q_OBJECT |
11 Q_OBJECT |
11 public: |
12 public: |
12 struct MouseClickInfo; |
13 struct MouseClickInfo; |
13 struct MouseMoveInfo; |
14 struct MouseMoveInfo; |
14 enum PreviewLayerName : std::int8_t |
15 using OverpaintCallback = std::function<void(Canvas*, QPainter*)>; |
15 { |
|
16 DrawToolPreview |
|
17 }; |
|
18 struct PreviewLayer |
|
19 { |
|
20 struct Point |
|
21 { |
|
22 glm::vec3 location; |
|
23 QBrush brush = {}; |
|
24 QPen pen = {}; |
|
25 }; |
|
26 struct Polygon |
|
27 { |
|
28 geom::NPolygon geometry; |
|
29 QBrush brush = {}; |
|
30 QPen pen = {}; |
|
31 }; |
|
32 QVector<Point> points; |
|
33 QVector<Polygon> polygons; |
|
34 }; |
|
35 static constexpr int NUM_PREVIEW_LAYERS = 1; |
|
36 |
|
37 Canvas( |
16 Canvas( |
38 Model* model, |
17 Model* model, |
39 DocumentManager* documents, |
18 DocumentManager* documents, |
40 const ldraw::ColorTable& colorTable, |
19 const ldraw::ColorTable& colorTable, |
41 QWidget* parent = nullptr); |
20 QWidget* parent = nullptr); |
42 const PreviewLayer& getPreviewLayer(PreviewLayerName name) const; |
|
43 PreviewLayer& modifyPreviewLayer(PreviewLayerName name); |
|
44 void clearSelection(); |
21 void clearSelection(); |
45 void addToSelection(ldraw::id_t id); |
22 void addToSelection(ldraw::id_t id); |
|
23 void setOverpaintCallback(OverpaintCallback fn); |
|
24 void drawWorldPoint(QPainter* painter, const glm::vec3& worldPoint) const; |
|
25 void drawWorldPolygon(QPainter* painter, const std::vector<glm::vec3>& points); |
46 public slots: |
26 public slots: |
47 void handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds); |
27 void handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds); |
48 protected: |
28 protected: |
49 void mouseMoveEvent(QMouseEvent* event) override; |
29 void mouseMoveEvent(QMouseEvent* event) override; |
50 void mousePressEvent(QMouseEvent* event) override; |
30 void mousePressEvent(QMouseEvent* event) override; |
65 std::optional<glm::vec3> worldPosition; |
45 std::optional<glm::vec3> worldPosition; |
66 glm::mat4 gridMatrix; |
46 glm::mat4 gridMatrix; |
67 geom::Plane gridPlane; |
47 geom::Plane gridPlane; |
68 int totalMouseMove = 0; |
48 int totalMouseMove = 0; |
69 QSet<ldraw::id_t> selection; |
49 QSet<ldraw::id_t> selection; |
70 PreviewLayer previewLayers[NUM_PREVIEW_LAYERS]; |
50 OverpaintCallback overpaintCallback = nullptr; |
71 }; |
51 }; |
72 |
52 |
73 struct Canvas::MouseClickInfo |
53 struct Canvas::MouseClickInfo |
74 { |
54 { |
75 std::optional<glm::vec3> worldPosition; |
55 std::optional<glm::vec3> worldPosition; |