Tue, 07 Jun 2022 21:35:29 +0300
Move editing modes tool bar, tool options widget stack and model list view into the main window
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" |
118 | 8 | #include "gl/vertexprogram.h" |
47 | 9 | |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
10 | enum EditingMode |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
11 | { |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
12 | SelectMode, |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
13 | DrawMode |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
14 | }; |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
15 | |
203
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
201
diff
changeset
|
16 | Q_DECLARE_METATYPE(EditingMode); |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
201
diff
changeset
|
17 | |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
18 | struct DrawState |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
19 | { |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
20 | std::vector<glm::vec3> polygon; |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
21 | std::vector<glm::vec3> previewPolygon; |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
22 | glm::vec3 previewPoint; |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
23 | bool isconcave = false; |
197
0e729e681a2c
move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents:
191
diff
changeset
|
24 | EditingMode mode = SelectMode; |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
25 | }; |
47 | 26 | class Canvas : public PartRenderer |
27 | { | |
28 | Q_OBJECT | |
29 | public: | |
109
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
30 | using OverpaintCallback = std::function<void(Canvas*, QPainter*)>; |
47 | 31 | Canvas( |
32 | Model* model, | |
200 | 33 | EditorTabWidget* document, |
47 | 34 | DocumentManager* documents, |
35 | const ldraw::ColorTable& colorTable, | |
36 | QWidget* parent = nullptr); | |
109
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
37 | void setOverpaintCallback(OverpaintCallback fn); |
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
38 | void drawWorldPoint(QPainter* painter, const glm::vec3& worldPoint) const; |
164
8305e2f968fb
Render draw tool preview as a line when we only have 2 points
Teemu Piippo <teemu@hecknology.net>
parents:
130
diff
changeset
|
39 | void drawWorldPolyline(QPainter* painter, const std::vector<glm::vec3>& points); |
109
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
40 | void drawWorldPolygon(QPainter* painter, const std::vector<glm::vec3>& points); |
168
24590af32ad6
Draw tool now renders the winding of the new polygon
Teemu Piippo <teemu@hecknology.net>
parents:
166
diff
changeset
|
41 | Winding worldPolygonWinding(const std::vector<glm::vec3>& points) const; |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
42 | const std::optional<glm::vec3>& getWorldPosition() const; |
200 | 43 | const QSet<ModelId> selectedObjects() const; |
187 | 44 | const glm::mat4& getGridMatrix() const; |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
45 | void closeShape(); |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
46 | glm::vec3 cameraVector() const; |
197
0e729e681a2c
move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents:
191
diff
changeset
|
47 | std::optional<glm::vec3> worldPosition; |
0e729e681a2c
move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents:
191
diff
changeset
|
48 | DrawState* drawState = nullptr; |
112 | 49 | public Q_SLOTS: |
200 | 50 | void handleSelectionChange(const QSet<ModelId>& selectedIds, const QSet<ModelId>& deselectedIds); |
51 | void rebuildVertices(EditorTabWidget *document); | |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
52 | void setGridMatrix(const glm::mat4 &newMatrix); |
47 | 53 | protected: |
54 | void mouseMoveEvent(QMouseEvent* event) override; | |
51 | 55 | void mousePressEvent(QMouseEvent* event) override; |
56 | void mouseReleaseEvent(QMouseEvent* event) override; | |
61
4585d8d7a7ec
moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
57
diff
changeset
|
57 | void initializeGL() override; |
57
5c0005f63319
use glm::unProject to implement screenToModelCoordinates
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
58 | void paintGL() override; |
112 | 59 | Q_SIGNALS: |
47 | 60 | void newStatusText(const QString& newStatusText); |
197
0e729e681a2c
move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents:
191
diff
changeset
|
61 | void mouseClick(QMouseEvent* event); |
0e729e681a2c
move drawState to Document
Teemu Piippo <teemu@hecknology.net>
parents:
191
diff
changeset
|
62 | void mouseMove(QMouseEvent* event); |
51 | 63 | private: |
66
77c819262b7a
added a method to find out if the view is perpendicular to grid
Teemu Piippo <teemu@hecknology.net>
parents:
64
diff
changeset
|
64 | bool isGridPerpendicularToScreen(float threshold) const; |
168
24590af32ad6
Draw tool now renders the winding of the new polygon
Teemu Piippo <teemu@hecknology.net>
parents:
166
diff
changeset
|
65 | QVector<QPointF> convertWorldPointsToScreenPoints(const std::vector<glm::vec3>& worldPoints) const; |
165
f6eab2bd46c2
fixed the grid not being black on startup if settings has bright background color
Teemu Piippo <teemu@hecknology.net>
parents:
164
diff
changeset
|
66 | Q_SLOT void updateCanvasRenderPreferences(); |
170
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
67 | void renderAxesLabels(QPainter& painter); |
61
4585d8d7a7ec
moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
57
diff
changeset
|
68 | std::optional<GridProgram> gridProgram; |
70 | 69 | std::optional<AxesProgram> axesProgram; |
118 | 70 | std::optional<VertexProgram> vertexProgram; |
64
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
61
diff
changeset
|
71 | glm::mat4 gridMatrix; |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
72 | Plane gridPlane; |
51 | 73 | int totalMouseMove = 0; |
166
8857351912d0
Fix rendering of cursor coordinates on bright background
Teemu Piippo <teemu@hecknology.net>
parents:
165
diff
changeset
|
74 | bool isDark = true; |
200 | 75 | QSet<ModelId> selection; |
109
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
76 | OverpaintCallback overpaintCallback = nullptr; |
200 | 77 | EditorTabWidget* document; |
47 | 78 | }; |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
79 | |
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
188
diff
changeset
|
80 | void adjustGridToView(Canvas* canvas); |