Fri, 11 Mar 2022 20:19:26 +0200
add grid actions
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 | |
10 | class Canvas : public PartRenderer | |
11 | { | |
12 | Q_OBJECT | |
13 | public: | |
109
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
14 | using OverpaintCallback = std::function<void(Canvas*, QPainter*)>; |
47 | 15 | Canvas( |
16 | Model* model, | |
17 | DocumentManager* documents, | |
18 | const ldraw::ColorTable& colorTable, | |
19 | QWidget* parent = nullptr); | |
107
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
106
diff
changeset
|
20 | void clearSelection(); |
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
106
diff
changeset
|
21 | 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
|
22 | void setOverpaintCallback(OverpaintCallback fn); |
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
23 | 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
|
24 | 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
|
25 | 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
|
26 | Winding worldPolygonWinding(const std::vector<glm::vec3>& points) const; |
110 | 27 | const std::optional<glm::vec3>& getWorldPosition() const; |
130
f2d78b30f2a9
Add missing changes to canvas.h
Teemu Piippo <teemu@hecknology.net>
parents:
128
diff
changeset
|
28 | void adjustGridToView(); |
169
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
168
diff
changeset
|
29 | const QSet<ldraw::id_t> selectedObjects() const; |
112 | 30 | public Q_SLOTS: |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
31 | void handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds); |
118 | 32 | void rebuildVertices(Document *document); |
47 | 33 | protected: |
34 | void mouseMoveEvent(QMouseEvent* event) override; | |
51 | 35 | void mousePressEvent(QMouseEvent* event) override; |
36 | void mouseReleaseEvent(QMouseEvent* event) override; | |
61
4585d8d7a7ec
moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
57
diff
changeset
|
37 | void initializeGL() override; |
57
5c0005f63319
use glm::unProject to implement screenToModelCoordinates
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
38 | void paintGL() override; |
112 | 39 | Q_SIGNALS: |
47 | 40 | 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
|
41 | void selectionChanged(const QSet<ldraw::id_t>& newSelection); |
121
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
118
diff
changeset
|
42 | void mouseClick(Canvas* canvas, QMouseEvent* event); |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
118
diff
changeset
|
43 | void mouseMove(Canvas* canvas, QMouseEvent* event); |
51 | 44 | private: |
130
f2d78b30f2a9
Add missing changes to canvas.h
Teemu Piippo <teemu@hecknology.net>
parents:
128
diff
changeset
|
45 | void setGridMatrix(const glm::mat4 &newMatrix); |
67 | 46 | 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
|
47 | 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
|
48 | 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
|
49 | Q_SLOT void updateCanvasRenderPreferences(); |
170
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
50 | void renderAxesLabels(QPainter& painter); |
61
4585d8d7a7ec
moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
57
diff
changeset
|
51 | std::optional<GridProgram> gridProgram; |
70 | 52 | std::optional<AxesProgram> axesProgram; |
118 | 53 | std::optional<VertexProgram> vertexProgram; |
57
5c0005f63319
use glm::unProject to implement screenToModelCoordinates
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
54 | std::optional<glm::vec3> worldPosition; |
64
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
61
diff
changeset
|
55 | glm::mat4 gridMatrix; |
f99d52b1646b
grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents:
61
diff
changeset
|
56 | geom::Plane gridPlane; |
51 | 57 | int totalMouseMove = 0; |
166
8857351912d0
Fix rendering of cursor coordinates on bright background
Teemu Piippo <teemu@hecknology.net>
parents:
165
diff
changeset
|
58 | bool isDark = true; |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
70
diff
changeset
|
59 | QSet<ldraw::id_t> selection; |
109
40a1cf2f38f5
replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents:
108
diff
changeset
|
60 | OverpaintCallback overpaintCallback = nullptr; |
47 | 61 | }; |