src/gldraw.h

changeset 665
4355e72ffd47
parent 489
0b32138fedcc
parent 534
3ed2ebcbc84f
child 666
c595cfb4791c
equal deleted inserted replaced
664:e3a32a79a10a 665:4355e72ffd47
30 class QSpinBox; 30 class QSpinBox;
31 class QLineEdit; 31 class QLineEdit;
32 class LDFile; 32 class LDFile;
33 class QTimer; 33 class QTimer;
34 34
35 enum EditMode { 35 enum EditMode
36 Select, 36 { Select,
37 Draw 37 Draw,
38 CircleMode,
38 }; 39 };
39 40
40 // Meta for overlays 41 // Meta for overlays
41 struct overlayMeta { 42 struct LDGLOverlay
42 vertex v0, v1; 43 { vertex v0, v1;
43 ushort ox, oy; 44 int ox, oy;
44 double lw, lh; 45 double lw, lh;
45 str fname; 46 str fname;
46 QImage* img; 47 QImage* img;
47 }; 48 };
48 49
50 struct LDFixedCameraInfo
51 { const char glrotate[3];
52 const Axis axisX, axisY;
53 const bool negX, negY;
54 };
55
49 // ============================================================================= 56 // =============================================================================
50 // GLRenderer 57 // GLRenderer
51 // 58 //
52 // The main renderer object, draws the brick on the screen, manages the camera 59 // The main renderer object, draws the brick on the screen, manages the camera
53 // and selection picking. The instance of GLRenderer is accessible as 60 // and selection picking. The instance of GLRenderer is accessible as
54 // g_win->R() 61 // g_win->R()
55 // ============================================================================= 62 // =============================================================================
56 class GLRenderer : public QGLWidget { 63 class GLRenderer : public QGLWidget
57 Q_OBJECT 64 { Q_OBJECT
58 65
59 PROPERTY (bool, drawOnly, setDrawOnly) 66 PROPERTY (bool, drawOnly, setDrawOnly)
60 PROPERTY (double, zoom, setZoom)
61 PROPERTY (MessageManager*, msglog, setMessageLog) 67 PROPERTY (MessageManager*, msglog, setMessageLog)
62 READ_PROPERTY (bool, picking, setPicking) 68 READ_PROPERTY (bool, picking, setPicking)
63 DECLARE_PROPERTY (LDFile*, file, setFile) 69 DECLARE_PROPERTY (LDFile*, file, setFile)
64 DECLARE_PROPERTY (EditMode, editMode, setEditMode) 70 DECLARE_PROPERTY (EditMode, editMode, setEditMode)
65 71
66 public: 72 public:
67 enum Camera { Top, Front, Left, Bottom, Back, Right, Free }; 73 enum Camera { Top, Front, Left, Bottom, Back, Right, Free };
68 enum ListType { NormalList, PickList, BFCFrontList, BFCBackList }; 74 enum ListType { NormalList, PickList, BFCFrontList, BFCBackList };
69 75
70 enum VAOType { 76 GLRenderer (QWidget* parent = null);
71 MainArray, 77 ~GLRenderer();
72 EdgeArray, 78
73 CondEdgeArray, 79 inline Camera camera() const
74 BFCArray, 80 { return m_camera;
75 PickArray, 81 }
76 EdgePickArray, 82
77 NumArrays 83 Axis cameraAxis (bool y, Camera camid = (Camera) - 1);
78 }; 84 const char* cameraName() const;
79 85 void clearOverlay();
80 GLRenderer (QWidget* parent = null); 86 void compileObject (LDObject* obj);
81 ~GLRenderer(); 87 void compileAllObjects();
82 88 double depthValue() const;
83 Camera camera() const { return m_camera; } 89 void drawGLScene();
84 Axis cameraAxis (bool y, Camera camid = (Camera) -1); 90 void endDraw (bool accept);
85 const char* cameraName() const; 91 QColor getMainColor();
86 void clearOverlay(); 92 LDGLOverlay& getOverlay (int newcam);
87 void compileObject (LDObject* obj); 93 void hardRefresh();
88 void compileAllObjects(); 94 void initGLData();
89 double depthValue() const; 95 void overlaysFromObjects();
90 void drawGLScene(); 96 void refresh();
91 void endDraw (bool accept); 97 void resetAngles();
92 static QColor getMainColor(); 98 void resetAllAngles();
93 overlayMeta& getOverlay (int newcam); 99 uchar* screencap (int& w, int& h);
94 void hardRefresh(); 100 void setBackground();
95 void initGLData(); 101 void setCamera (const Camera cam);
96 void overlaysFromObjects(); 102 void setDepthValue (double depth);
97 void refresh(); 103 bool setupOverlay (GLRenderer::Camera cam, str file, int x, int y, int w, int h);
98 void resetAngles(); 104 void updateOverlayObjects();
99 uchar* screencap (ushort& w, ushort& h); 105 void zoomNotch (bool inward);
100 void setBackground(); 106 void zoomToFit();
101 void setCamera (const Camera cam); 107 void zoomAllToFit();
102 void setDepthValue (double depth); 108
103 bool setupOverlay (GLRenderer::Camera cam, str file, int x, int y, int w, int h); 109 static void deleteLists (LDObject* obj);
104 void updateOverlayObjects(); 110
105 void zoomNotch (bool inward); 111 protected:
106 void zoomToFit(); 112 void contextMenuEvent (QContextMenuEvent* ev);
107 113 void initializeGL();
108 static void deleteLists (LDObject* obj); 114 void keyPressEvent (QKeyEvent* ev);
109 115 void keyReleaseEvent (QKeyEvent* ev);
110 protected: 116 void leaveEvent (QEvent* ev);
111 void contextMenuEvent (QContextMenuEvent* ev); 117 void mouseDoubleClickEvent (QMouseEvent* ev);
112 void initializeGL(); 118 void mousePressEvent (QMouseEvent* ev);
113 void keyPressEvent (QKeyEvent* ev); 119 void mouseMoveEvent (QMouseEvent* ev);
114 void keyReleaseEvent (QKeyEvent* ev); 120 void mouseReleaseEvent (QMouseEvent* ev);
115 void leaveEvent (QEvent* ev); 121 void paintEvent (QPaintEvent* ev);
116 void mouseDoubleClickEvent (QMouseEvent* ev); 122 void resizeGL (int w, int h);
117 void mousePressEvent (QMouseEvent* ev); 123 void wheelEvent (QWheelEvent* ev);
118 void mouseMoveEvent (QMouseEvent* ev); 124
119 void mouseReleaseEvent (QMouseEvent* ev); 125 private:
120 void paintEvent (QPaintEvent* ev); 126 // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets
121 void resizeGL (int w, int h); 127 // initialized before program gets to main() and constructs a QApplication
122 void wheelEvent (QWheelEvent* ev); 128 // and Qt doesn't like that.
123 129 struct CameraIcon
124 private: 130 { QPixmap* img;
125 // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets 131 QRect srcRect, destRect, selRect;
126 // initialized before program gets to main() and constructs a QApplication 132 Camera cam;
127 // and Qt doesn't like that. 133 };
128 struct CameraIcon { 134
129 QPixmap* img; 135 CameraIcon m_cameraIcons[7];
130 QRect srcRect, destRect, selRect; 136 QTimer* m_toolTipTimer;
131 Camera cam; 137 Qt::MouseButtons m_lastButtons;
132 } m_cameraIcons[7]; 138 Qt::KeyboardModifiers m_keymods;
133 139 vertex m_hoverpos;
134 QTimer* m_toolTipTimer; 140 double m_virtWidth,
135 Qt::MouseButtons m_lastButtons; 141 m_virtHeight,
136 Qt::KeyboardModifiers m_keymods; 142 m_rotX[7],
137 ulong m_totalmove; 143 m_rotY[7],
138 vertex m_hoverpos; 144 m_rotZ[7],
139 double m_virtWidth, m_virtHeight, m_rotX, m_rotY, m_rotZ, m_panX, m_panY; 145 m_panX[7],
140 bool m_darkbg, m_rangepick, m_addpick, m_drawToolTip, m_screencap; 146 m_panY[7],
141 QPoint m_pos, m_globalpos, m_rangeStart; 147 m_zoom[7];
142 QPen m_thickBorderPen, m_thinBorderPen; 148 bool m_darkbg,
143 Camera m_camera, m_toolTipCamera; 149 m_rangepick,
144 GLuint m_axeslist; 150 m_addpick,
145 int m_width, m_height; 151 m_drawToolTip,
146 List<vertex> m_drawedVerts; 152 m_screencap,
147 bool m_rectdraw; 153 m_panning;
148 vertex m_rectverts[4]; 154 QPoint m_pos,
149 QColor m_bgcolor; 155 m_globalpos,
150 double m_depthValues[6]; 156 m_rangeStart;
151 overlayMeta m_overlays[6]; 157 QPen m_thickBorderPen,
152 List<vertex> m_knownVerts; 158 m_thinBorderPen;
153 bool m_panning; 159 Camera m_camera,
154 160 m_toolTipCamera;
155 void addDrawnVertex (vertex m_hoverpos); 161 GLuint m_axeslist;
156 void calcCameraIcons(); // Compute geometry for camera icons 162 int m_width,
157 void clampAngle (double& angle) const; // Clamps an angle to [0, 360] 163 m_height,
158 vertex coordconv2_3 (const QPoint& pos2d, bool snap) const; // Convert a 2D point to a 3D point 164 m_totalmove;
159 QPoint coordconv3_2 (const vertex& pos3d) const; // Convert a 3D point to a 2D point 165 QList<vertex> m_drawedVerts;
160 void drawVAOs (VAOType arrayType, GLenum type); // Draw a VAO array 166 bool m_rectdraw;
161 LDOverlay* findOverlayObject (Camera cam); 167 vertex m_rectverts[4];
162 void updateRectVerts(); 168 QColor m_bgcolor;
163 void pick (uint mouseX, uint mouseY); // Perform object selection 169 double m_depthValues[6];
164 QColor getTextPen() const; // Determine which color to draw text with 170 LDGLOverlay m_overlays[6];
165 171 QList<vertex> m_knownVerts;
166 private slots: 172
167 void slot_toolTipTimer(); 173 void addDrawnVertex (vertex m_hoverpos);
174 LDOverlay* findOverlayObject (Camera cam);
175 void updateRectVerts();
176 void getRelativeAxes (Axis& relX, Axis& relY) const;
177 matrix getCircleDrawMatrix (double scale);
178 void drawBlip (QPainter& paint, QPoint pos) const;
179
180 // Compute geometry for camera icons
181 void calcCameraIcons();
182
183 // How large is the circle we're drawing right now?
184 double circleDrawDist (int pos) const;
185
186 // Clamps an angle to [0, 360]
187 void clampAngle (double& angle) const;
188
189 // Compile one of the lists of an object
190 void compileList (LDObject* obj, const ListType list);
191
192 // Sub-routine for object compiling
193 void compileSubObject (LDObject* obj, const GLenum gltype);
194
195 // Compile a single vertex to a list
196 void compileVertex (const vertex& vrt);
197
198 // Convert a 2D point to a 3D point
199 vertex coordconv2_3 (const QPoint& pos2d, bool snap) const;
200
201 // Convert a 3D point to a 2D point
202 QPoint coordconv3_2 (const vertex& pos3d) const;
203
204 // Draw a VAO array
205 void drawVAOs (VAOType arrayType, GLenum type);
206
207 // Determine which color to draw text with
208 QColor getTextPen() const;
209
210 // Perform object selection
211 void pick (int mouseX, int mouseY);
212
213 // Set the color to an object list
214 void setObjectColor (LDObject* obj, const ListType list);
215
216 // Get a rotation value
217 inline double& rot (Axis ax)
218 { return
219 (ax == X) ? m_rotX[camera()] :
220 (ax == Y) ? m_rotY[camera()] :
221 m_rotZ[camera()];
222 }
223
224 // Get a panning value
225 inline double& pan (Axis ax)
226 { return (ax == X) ? m_panX[camera()] : m_panY[camera()];
227 }
228
229 // Same except const (can be used in const methods)
230 inline const double& pan (Axis ax) const
231 { return (ax == X) ? m_panX[camera()] : m_panY[camera()];
232 }
233
234 // Get the zoom value
235 inline double& zoom()
236 { return m_zoom[camera()];
237 }
238
239 private slots:
240 void slot_toolTipTimer();
168 }; 241 };
169 242
170 // Alias for short namespaces 243 // Alias for short namespaces
171 typedef GLRenderer GL; 244 typedef GLRenderer GL;
172 245
173 static const GLRenderer::ListType g_glListTypes[] = { 246 static const GLRenderer::ListType g_glListTypes[] =
174 GL::NormalList, 247 { GL::NormalList,
175 GL::PickList, 248 GL::PickList,
176 GL::BFCFrontList, 249 GL::BFCFrontList,
177 GL::BFCBackList, 250 GL::BFCBackList,
178 }; 251 };
179 252

mercurial