src/ui/canvas.h

Fri, 04 Mar 2022 23:00:06 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 04 Mar 2022 23:00:06 +0200
changeset 154
47cb50cfa9ad
parent 130
f2d78b30f2a9
child 164
8305e2f968fb
permissions
-rw-r--r--

add missing files

47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
94c92c923713 work on editing tools
Teemu Piippo <teemu@hecknology.net>
parents: 107
diff changeset
3 #include <QBrush>
94c92c923713 work on editing tools
Teemu Piippo <teemu@hecknology.net>
parents: 107
diff changeset
4 #include <QPen>
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents: 67
diff changeset
7 #include "gl/axesprogram.h"
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 112
diff changeset
8 #include "gl/vertexprogram.h"
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 class Canvas : public PartRenderer
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 {
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 Q_OBJECT
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 Canvas(
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 Model* model,
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 DocumentManager* documents,
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 const ldraw::ColorTable& colorTable,
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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;
40a1cf2f38f5 replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents: 108
diff changeset
24 void drawWorldPolygon(QPainter* painter, const std::vector<glm::vec3>& points);
110
Teemu Piippo <teemu@hecknology.net>
parents: 109
diff changeset
25 const std::optional<glm::vec3>& getWorldPosition() const;
130
f2d78b30f2a9 Add missing changes to canvas.h
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
26 void adjustGridToView();
112
5760cbb32bc0 use QT_NO_KEYWORDS
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
27 public Q_SLOTS:
73
97df974b5ed5 ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
28 void handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds);
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 112
diff changeset
29 void rebuildVertices(Document *document);
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 protected:
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 void mouseMoveEvent(QMouseEvent* event) override;
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
32 void mousePressEvent(QMouseEvent* event) override;
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
33 void mouseReleaseEvent(QMouseEvent* event) override;
61
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 57
diff changeset
34 void initializeGL() override;
57
5c0005f63319 use glm::unProject to implement screenToModelCoordinates
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
35 void paintGL() override;
112
5760cbb32bc0 use QT_NO_KEYWORDS
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
36 Q_SIGNALS:
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 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
38 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
39 void mouseClick(Canvas* canvas, QMouseEvent* event);
000781318c36 added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents: 118
diff changeset
40 void mouseMove(Canvas* canvas, QMouseEvent* event);
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
41 private:
130
f2d78b30f2a9 Add missing changes to canvas.h
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
42 void setGridMatrix(const glm::mat4 &newMatrix);
67
612213a168da grid autorotation
Teemu Piippo <teemu@hecknology.net>
parents: 66
diff changeset
43 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
44 bool isGridPerpendicularToScreen(float threshold) const;
61
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 57
diff changeset
45 std::optional<GridProgram> gridProgram;
70
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents: 67
diff changeset
46 std::optional<AxesProgram> axesProgram;
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 112
diff changeset
47 std::optional<VertexProgram> vertexProgram;
57
5c0005f63319 use glm::unProject to implement screenToModelCoordinates
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
48 std::optional<glm::vec3> worldPosition;
64
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 61
diff changeset
49 glm::mat4 gridMatrix;
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 61
diff changeset
50 geom::Plane gridPlane;
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
51 int totalMouseMove = 0;
73
97df974b5ed5 ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
52 QSet<ldraw::id_t> selection;
109
40a1cf2f38f5 replaced preview layers in favor of overpainting callback
Teemu Piippo <teemu@hecknology.net>
parents: 108
diff changeset
53 OverpaintCallback overpaintCallback = nullptr;
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 };

mercurial