src/ui/canvas.h

Tue, 20 Jul 2021 01:22:01 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 20 Jul 2021 01:22:01 +0300
changeset 106
128efb9d148b
parent 105
6ca6e8c647d4
child 107
02f142b399b1
permissions
-rw-r--r--

work on draw preview

47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #pragma once
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include "gl/partrenderer.h"
61
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 57
diff changeset
3 #include "gl/gridprogram.h"
70
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents: 67
diff changeset
4 #include "gl/axesprogram.h"
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 class Canvas : public PartRenderer
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 {
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 Q_OBJECT
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 public:
104
cd4df75924b7 Add connections
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
10 struct MouseClickInfo;
105
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
11 enum PreviewLayerName : std::int8_t
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
12 {
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
13 DrawToolPreview
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
14 };
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
15 struct PreviewLayer
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
16 {
106
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 105
diff changeset
17 QVector<geom::NPolygon> polygons;
105
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
18 QColor color{64, 255, 128};
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
19 };
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
20 static constexpr int NUM_PREVIEW_LAYERS = 1;
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
21
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 Canvas(
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 Model* model,
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 DocumentManager* documents,
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 const ldraw::ColorTable& colorTable,
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 QWidget* parent = nullptr);
105
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
27 const PreviewLayer& getPreviewLayer(PreviewLayerName name) const;
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
28 PreviewLayer& modifyPreviewLayer(PreviewLayerName name);
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
29 public slots:
73
97df974b5ed5 ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
30 void handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds);
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 protected:
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 void mouseMoveEvent(QMouseEvent* event) override;
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
33 void mousePressEvent(QMouseEvent* event) override;
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
34 void mouseReleaseEvent(QMouseEvent* event) override;
61
4585d8d7a7ec moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 57
diff changeset
35 void initializeGL() override;
57
5c0005f63319 use glm::unProject to implement screenToModelCoordinates
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
36 void paintGL() override;
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 signals:
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 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
39 void selectionChanged(const QSet<ldraw::id_t>& newSelection);
104
cd4df75924b7 Add connections
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
40 void mouseClick(const MouseClickInfo& info);
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
41 private:
64
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 61
diff changeset
42 void updateGridMatrix();
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;
57
5c0005f63319 use glm::unProject to implement screenToModelCoordinates
Teemu Piippo <teemu@hecknology.net>
parents: 51
diff changeset
47 std::optional<glm::vec3> worldPosition;
64
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 61
diff changeset
48 glm::mat4 gridMatrix;
f99d52b1646b grid snapping now also works with transformed grids
Teemu Piippo <teemu@hecknology.net>
parents: 61
diff changeset
49 geom::Plane gridPlane;
51
1a9eac27698d selection works now
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
50 int totalMouseMove = 0;
73
97df974b5ed5 ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents: 70
diff changeset
51 QSet<ldraw::id_t> selection;
105
6ca6e8c647d4 added preview layer code and fixed build warnings
Teemu Piippo <teemu@hecknology.net>
parents: 104
diff changeset
52 PreviewLayer previewLayers[NUM_PREVIEW_LAYERS];
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 };
104
cd4df75924b7 Add connections
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
54
cd4df75924b7 Add connections
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
55 struct Canvas::MouseClickInfo
cd4df75924b7 Add connections
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
56 {
106
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 105
diff changeset
57 std::optional<glm::vec3> worldPosition;
128efb9d148b work on draw preview
Teemu Piippo <teemu@hecknology.net>
parents: 105
diff changeset
58 Canvas* invoker;
104
cd4df75924b7 Add connections
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
59 };

mercurial