src/glRenderer.h

changeset 1217
314e12e23c3a
parent 1008
74cb432812d3
child 1222
34def2630300
equal deleted inserted replaced
1216:12f9ea615cbc 1217:314e12e23c3a
76 LDGLOverlay overlays[6]; 76 LDGLOverlay overlays[6];
77 bool init; 77 bool init;
78 bool needZoomToFit; 78 bool needZoomToFit;
79 79
80 LDGLData() : 80 LDGLData() :
81 rotationX (0.0), 81 rotationX(0.0),
82 rotationY (0.0), 82 rotationY(0.0),
83 rotationZ (0.0), 83 rotationZ(0.0),
84 init (false), 84 init(false),
85 needZoomToFit (true) 85 needZoomToFit(true)
86 { 86 {
87 for (int i = 0; i < 7; ++i) 87 for (int i = 0; i < 7; ++i)
88 { 88 {
89 if (i < 6) 89 if (i < 6)
90 { 90 {
112 112
113 ENumCameras, 113 ENumCameras,
114 EFirstCamera = ETopCamera 114 EFirstCamera = ETopCamera
115 }; 115 };
116 116
117 MAKE_ITERABLE_ENUM (ECamera) 117 MAKE_ITERABLE_ENUM(ECamera)
118 118
119 // 119 //
120 // CameraIcon::image is a heap-allocated QPixmap because otherwise it gets 120 // CameraIcon::image is a heap-allocated QPixmap because otherwise it gets
121 // initialized before program gets to main() and constructs a QApplication 121 // initialized before program gets to main() and constructs a QApplication
122 // and Qt doesn't like that. 122 // and Qt doesn't like that.
134 class GLRenderer : public QGLWidget, protected QOpenGLFunctions, public HierarchyElement 134 class GLRenderer : public QGLWidget, protected QOpenGLFunctions, public HierarchyElement
135 { 135 {
136 Q_OBJECT 136 Q_OBJECT
137 137
138 public: 138 public:
139 GLRenderer (QWidget* parent = nullptr); 139 GLRenderer(QWidget* parent = nullptr);
140 ~GLRenderer(); 140 ~GLRenderer();
141 141
142 ECamera camera() const; 142 ECamera camera() const;
143 QString cameraName (ECamera camera) const; 143 QString cameraName(ECamera camera) const;
144 QByteArray capturePixels(); 144 QByteArray capturePixels();
145 void clearOverlay(); 145 void clearOverlay();
146 void compileObject (LDObject* obj); 146 void compileObject(LDObject* obj);
147 GLCompiler* compiler() const; 147 GLCompiler* compiler() const;
148 Vertex convert2dTo3d (const QPoint& pos2d, bool snap) const; 148 Vertex convert2dTo3d(const QPoint& pos2d, bool snap) const;
149 QPoint convert3dTo2d (const Vertex& pos3d); 149 QPoint convert3dTo2d(const Vertex& pos3d);
150 QString currentCameraName() const; 150 QString currentCameraName() const;
151 EditModeType currentEditModeType() const; 151 EditModeType currentEditModeType() const;
152 int depthNegateFactor() const; 152 int depthNegateFactor() const;
153 LDDocument* document() const; 153 LDDocument* document() const;
154 void drawBlip (QPainter& painter, QPointF pos, QColor color = QColor (64, 192, 0)) const; 154 void drawBlip(QPainter& painter, QPointF pos, QColor color = QColor(64, 192, 0)) const;
155 void drawBlipCoordinates (QPainter& painter, const Vertex& pos3d); 155 void drawBlipCoordinates(QPainter& painter, const Vertex& pos3d);
156 void drawBlipCoordinates (QPainter& painter, const Vertex& pos3d, QPointF pos); 156 void drawBlipCoordinates(QPainter& painter, const Vertex& pos3d, QPointF pos);
157 void drawGLScene(); 157 void drawGLScene();
158 void forgetObject (LDObject* obj); 158 void forgetObject(LDObject* obj);
159 Axis getCameraAxis (bool y, ECamera camid = (ECamera) -1); 159 Axis getCameraAxis(bool y, ECamera camid = (ECamera) -1);
160 double getDepthValue() const; 160 double getDepthValue() const;
161 const LDFixedCamera& getFixedCamera (ECamera cam) const; 161 const LDFixedCamera& getFixedCamera(ECamera cam) const;
162 LDGLOverlay& getOverlay (int newcam); 162 LDGLOverlay& getOverlay(int newcam);
163 void getRelativeAxes (Axis& relX, Axis& relY) const; 163 void getRelativeAxes(Axis& relX, Axis& relY) const;
164 Axis getRelativeZ() const; 164 Axis getRelativeZ() const;
165 void hardRefresh(); 165 void hardRefresh();
166 void highlightCursorObject(); 166 void highlightCursorObject();
167 void initGLData(); 167 void initGLData();
168 void initOverlaysFromObjects(); 168 void initOverlaysFromObjects();
174 bool mouseHasMoved() const; 174 bool mouseHasMoved() const;
175 QPoint const& mousePosition() const; 175 QPoint const& mousePosition() const;
176 QPointF const& mousePositionF() const; 176 QPointF const& mousePositionF() const;
177 void needZoomToFit(); 177 void needZoomToFit();
178 LDObject* objectAtCursor() const; 178 LDObject* objectAtCursor() const;
179 void pick (int mouseX, int mouseY, bool additive); 179 void pick(int mouseX, int mouseY, bool additive);
180 void pick (QRect const& range, bool additive); 180 void pick(QRect const& range, bool additive);
181 LDObject* pickOneObject (int mouseX, int mouseY); 181 LDObject* pickOneObject(int mouseX, int mouseY);
182 Vertex const& position3D() const; 182 Vertex const& position3D() const;
183 void refresh(); 183 void refresh();
184 void resetAllAngles(); 184 void resetAllAngles();
185 void resetAngles(); 185 void resetAngles();
186 void setBackground(); 186 void setBackground();
187 void setCamera (const ECamera cam); 187 void setCamera(const ECamera cam);
188 void setDepthValue (double depth); 188 void setDepthValue(double depth);
189 void setDocument (LDDocument* document); 189 void setDocument(LDDocument* document);
190 void setDrawOnly (bool value); 190 void setDrawOnly(bool value);
191 void setEditMode (EditModeType type); 191 void setEditMode(EditModeType type);
192 void setPicking (bool a); 192 void setPicking(bool a);
193 bool setupOverlay (ECamera cam, QString file, int x, int y, int w, int h); 193 bool setupOverlay(ECamera cam, QString file, int x, int y, int w, int h);
194 QPen textPen() const; 194 QPen textPen() const;
195 void updateOverlayObjects(); 195 void updateOverlayObjects();
196 void zoomNotch (bool inward); 196 void zoomNotch(bool inward);
197 197
198 protected: 198 protected:
199 void contextMenuEvent (QContextMenuEvent* ev); 199 void contextMenuEvent(QContextMenuEvent* ev);
200 void dragEnterEvent (QDragEnterEvent* ev); 200 void dragEnterEvent(QDragEnterEvent* ev);
201 void dropEvent (QDropEvent* ev); 201 void dropEvent(QDropEvent* ev);
202 void initializeGL(); 202 void initializeGL();
203 void keyPressEvent (QKeyEvent* ev); 203 void keyPressEvent(QKeyEvent* ev);
204 void keyReleaseEvent (QKeyEvent* ev); 204 void keyReleaseEvent(QKeyEvent* ev);
205 void leaveEvent (QEvent* ev); 205 void leaveEvent(QEvent* ev);
206 void mouseDoubleClickEvent (QMouseEvent* ev); 206 void mouseDoubleClickEvent(QMouseEvent* ev);
207 void mousePressEvent (QMouseEvent* ev); 207 void mousePressEvent(QMouseEvent* ev);
208 void mouseMoveEvent (QMouseEvent* ev); 208 void mouseMoveEvent(QMouseEvent* ev);
209 void mouseReleaseEvent (QMouseEvent* ev); 209 void mouseReleaseEvent(QMouseEvent* ev);
210 void paintEvent (QPaintEvent* ev); 210 void paintEvent(QPaintEvent* ev);
211 void resizeGL (int w, int h); 211 void resizeGL(int w, int h);
212 void wheelEvent (QWheelEvent* ev); 212 void wheelEvent(QWheelEvent* ev);
213 213
214 private: 214 private:
215 MessageManager* m_messageLog; 215 MessageManager* m_messageLog;
216 LDDocument* m_document; 216 LDDocument* m_document;
217 GLCompiler* m_compiler; 217 GLCompiler* m_compiler;
246 AbstractEditMode* m_currentEditMode; 246 AbstractEditMode* m_currentEditMode;
247 GLuint m_axesVbo; 247 GLuint m_axesVbo;
248 GLuint m_axesColorVbo; 248 GLuint m_axesColorVbo;
249 249
250 void calcCameraIcons(); 250 void calcCameraIcons();
251 void clampAngle (double& angle) const; 251 void clampAngle(double& angle) const;
252 LDGLData& currentDocumentData() const; 252 LDGLData& currentDocumentData() const;
253 void drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type); 253 void drawVbos(SurfaceVboType surface, ComplementVboType colors, GLenum type);
254 void doMakeCurrent(); 254 void doMakeCurrent();
255 LDOverlay* findOverlayObject (ECamera cam); 255 LDOverlay* findOverlayObject(ECamera cam);
256 double& panning (Axis ax); 256 double& panning(Axis ax);
257 double panning (Axis ax) const; 257 double panning(Axis ax) const;
258 double& rotation (Axis ax); 258 double& rotation(Axis ax);
259 double& zoom(); 259 double& zoom();
260 void zoomToFit(); 260 void zoomToFit();
261 void zoomAllToFit(); 261 void zoomAllToFit();
262 262
263 template<typename... Args> 263 template<typename... Args>
264 QString format (QString fmtstr, Args... args) 264 QString format(QString fmtstr, Args... args)
265 { 265 {
266 return ::format (fmtstr, args...); 266 return ::format(fmtstr, args...);
267 } 267 }
268 268
269 private slots: 269 private slots:
270 void slot_toolTipTimer(); 270 void slot_toolTipTimer();
271 void initializeAxes(); 271 void initializeAxes();

mercurial