Tue, 27 Jul 2021 12:44:54 +0300
refactor
47 | 1 | #pragma once |
109
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
2 | #include <QPainter> |
108 | 3 | #include <QBrush> |
4 | #include <QPen> | |
47 | 5 | #include "gl/partrenderer.h" |
61
4585d8d7a7ec
moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
57
diff
changeset
|
6 | #include "gl/gridprogram.h" |
70 | 7 | #include "gl/axesprogram.h" |
47 | 8 | |
9 | class Canvas : public PartRenderer | |
10 | { | |
11 | Q_OBJECT | |
12 | public: | |
109
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
13 | using OverpaintCallback = std::function<void(Canvas*, QPainter*)>; |
47 | 14 | Canvas( |
15 | Model* model, | |
16 | DocumentManager* documents, | |
17 | const ldraw::ColorTable& colorTable, | |
18 | QWidget* parent = nullptr); | |
107
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
106
diff
changeset
|
19 | void clearSelection(); |
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
106
diff
changeset
|
20 | void addToSelection(ldraw::id_t id); |
109
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
21 | void setOverpaintCallback(OverpaintCallback fn); |
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
22 | void drawWorldPoint(QPainter* painter, const glm::vec3& worldPoint) const; |
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
23 | void drawWorldPolygon(QPainter* painter, const std::vector<glm::vec3>& points); |
110 | 24 | const std::optional<glm::vec3>& getWorldPosition() const; |
112 | 25 | public Q_SLOTS: |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
26 | void handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds); |
47 | 27 | protected: |
28 | void mouseMoveEvent(QMouseEvent* event) override; | |
51 | 29 | void mousePressEvent(QMouseEvent* event) override; |
30 | void mouseReleaseEvent(QMouseEvent* event) override; | |
61
4585d8d7a7ec
moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
57
diff
changeset
|
31 | void initializeGL() override; |
57
5c0005f63319
use glm::unProject to implement screenToModelCoordinates
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
32 | void paintGL() override; |
112 | 33 | Q_SIGNALS: |
47 | 34 | void newStatusText(const QString& newStatusText); |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
35 | void selectionChanged(const QSet<ldraw::id_t>& newSelection); |
111
1f42c03fafca
Draw tool actually adds objects now
Teemu Piippo <teemu@hecknology.net>
parents:
110
diff
changeset
|
36 | void mouseClick(Canvas* canvas); |
1f42c03fafca
Draw tool actually adds objects now
Teemu Piippo <teemu@hecknology.net>
parents:
110
diff
changeset
|
37 | void mouseMove(Canvas* canvas); |
51 | 38 | private: |
64
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
61
diff
changeset
|
39 | void updateGridMatrix(); |
67 | 40 | glm::vec3 cameraVector() const; |
66
77c819262b7a
added a method to find out if the view is perpendicular to grid
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
41 | bool isGridPerpendicularToScreen(float threshold) const; |
61
4585d8d7a7ec
moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
57
diff
changeset
|
42 | std::optional<GridProgram> gridProgram; |
70 | 43 | std::optional<AxesProgram> axesProgram; |
57
5c0005f63319
use glm::unProject to implement screenToModelCoordinates
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
44 | std::optional<glm::vec3> worldPosition; |
64
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
61
diff
changeset
|
45 | glm::mat4 gridMatrix; |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
61
diff
changeset
|
46 | geom::Plane gridPlane; |
51 | 47 | int totalMouseMove = 0; |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
48 | QSet<ldraw::id_t> selection; |
109
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
49 | OverpaintCallback overpaintCallback = nullptr; |
47 | 50 | }; |