|
1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013 - 2017 Teemu Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #pragma once |
|
20 #include <QGLWidget> |
|
21 #include "main.h" |
|
22 #include "model.h" |
|
23 #include "glShared.h" |
|
24 #include "glcamera.h" |
|
25 |
|
26 class GLCompiler; |
|
27 class MessageManager; |
|
28 class QDialogButtonBox; |
|
29 class RadioGroup; |
|
30 class QDoubleSpinBox; |
|
31 class QSpinBox; |
|
32 class QLineEdit; |
|
33 class QTimer; |
|
34 class MagicWandMode; |
|
35 |
|
36 struct CameraInfo |
|
37 { |
|
38 CameraInfo(const CameraInfo&) = delete; |
|
39 |
|
40 int glrotate[3]; |
|
41 Axis localX; |
|
42 Axis localY; |
|
43 bool negatedX; |
|
44 bool negatedY; |
|
45 bool negatedDepth; // is greater depth value closer to camera? |
|
46 }; |
|
47 |
|
48 enum class Camera |
|
49 { |
|
50 Top, |
|
51 Front, |
|
52 Left, |
|
53 Bottom, |
|
54 Back, |
|
55 Right, |
|
56 Free, |
|
57 _End |
|
58 }; |
|
59 |
|
60 struct CameraIcon |
|
61 { |
|
62 QPixmap image; |
|
63 QRect sourceRect; |
|
64 QRect targetRect; |
|
65 QRect hitRect; |
|
66 Camera camera; |
|
67 }; |
|
68 |
|
69 MAKE_ITERABLE_ENUM(Camera) |
|
70 |
|
71 // The main renderer object, draws the brick on the screen, manages the camera and selection picking. |
|
72 class GLRenderer : public QGLWidget, protected QOpenGLFunctions, public HierarchyElement |
|
73 { |
|
74 Q_OBJECT |
|
75 |
|
76 public: |
|
77 GLRenderer(const Model* model, QWidget* parent = nullptr); |
|
78 ~GLRenderer(); |
|
79 |
|
80 QColor backgroundColor() const; |
|
81 Camera camera() const; |
|
82 QByteArray capturePixels(); |
|
83 GLCamera& currentCamera(); |
|
84 const GLCamera& currentCamera() const; |
|
85 void drawGLScene(); |
|
86 void forgetObject(LDObject* obj); |
|
87 void highlightCursorObject(); |
|
88 void initGLData(); |
|
89 bool isPicking() const; |
|
90 Qt::KeyboardModifiers keyboardModifiers() const; |
|
91 const Model* model() const; |
|
92 bool mouseHasMoved() const; |
|
93 QPoint const& mousePosition() const; |
|
94 QPointF const& mousePositionF() const; |
|
95 void needZoomToFit(); |
|
96 LDObject* objectAtCursor() const; |
|
97 QSet<LDObject*> pick(const QRect& range); |
|
98 LDObject* pick(int mouseX, int mouseY); |
|
99 void refresh(); |
|
100 void resetAllAngles(); |
|
101 void resetAngles(); |
|
102 void setBackground(); |
|
103 void setCamera(Camera cam); |
|
104 void setPicking(bool a); |
|
105 QPen textPen() const; |
|
106 |
|
107 static const QPen thinBorderPen; |
|
108 |
|
109 signals: |
|
110 void objectHighlightingChanged(LDObject* object); |
|
111 |
|
112 protected: |
|
113 void initializeGL(); |
|
114 void keyPressEvent(QKeyEvent* event); |
|
115 void keyReleaseEvent(QKeyEvent* event); |
|
116 void leaveEvent(QEvent* event); |
|
117 void mousePressEvent(QMouseEvent* event); |
|
118 void mouseMoveEvent(QMouseEvent* ev); |
|
119 void mouseReleaseEvent(QMouseEvent* ev); |
|
120 void paintEvent(QPaintEvent*); |
|
121 void resizeGL(int w, int h); |
|
122 void wheelEvent(QWheelEvent* ev); |
|
123 |
|
124 virtual void overpaint(QPainter& painter); |
|
125 virtual bool freeCameraAllowed() const; |
|
126 bool isDrawingSelectionScene() const; |
|
127 Qt::MouseButtons lastButtons() const; |
|
128 double panning (Axis ax) const; |
|
129 const QGenericMatrix<4, 4, GLfloat>& rotationMatrix() const; |
|
130 double zoom(); |
|
131 |
|
132 template<typename... Args> |
|
133 QString format (QString fmtstr, Args... args) |
|
134 { |
|
135 return ::format (fmtstr, args...); |
|
136 } |
|
137 |
|
138 private: |
|
139 const Model* const m_model; |
|
140 GLCompiler* m_compiler; |
|
141 LDObject* m_objectAtCursor = nullptr; |
|
142 CameraIcon m_cameraIcons[7]; |
|
143 QTimer* m_toolTipTimer; |
|
144 Qt::MouseButtons m_lastButtons; |
|
145 Qt::KeyboardModifiers m_currentKeyboardModifiers; |
|
146 QGenericMatrix<4, 4, GLfloat> m_rotationMatrix; |
|
147 GLCamera m_cameras[7]; |
|
148 bool m_useDarkBackground = false; |
|
149 bool m_takingScreenCapture = false; |
|
150 bool m_panning = false; |
|
151 bool m_initialized = false; |
|
152 bool m_isDrawingSelectionScene = false; |
|
153 bool m_isCameraMoving = false; |
|
154 bool m_needZoomToFit = true; |
|
155 QPoint m_mousePosition; |
|
156 QPoint m_globalpos; |
|
157 QPointF m_mousePositionF; |
|
158 Camera m_camera; |
|
159 GLuint m_axeslist; |
|
160 int m_totalMouseMove; |
|
161 QColor m_backgroundColor; |
|
162 GLuint m_axesVbo; |
|
163 GLuint m_axesColorVbo; |
|
164 |
|
165 void calcCameraIcons(); |
|
166 void drawVbos (VboClass surface, VboSubclass colors, GLenum type); |
|
167 void zoomToFit(); |
|
168 void zoomAllToFit(); |
|
169 |
|
170 private slots: |
|
171 void showCameraIconTooltip(); |
|
172 void initializeAxes(); |
|
173 void initializeLighting(); |
|
174 }; |