src/gldraw.h

changeset 493
16766ac1bbd9
parent 492
e964085e6913
child 497
c51941e590b6
equal deleted inserted replaced
492:e964085e6913 493:16766ac1bbd9
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 CircleMode,
39 }; 39 };
40 40
41 // Meta for overlays 41 // Meta for overlays
42 struct overlayMeta { 42 struct overlayMeta
43 vertex v0, v1; 43 { vertex v0, v1;
44 ushort ox, oy; 44 ushort ox, oy;
45 double lw, lh; 45 double lw, lh;
46 str fname; 46 str fname;
47 QImage* img; 47 QImage* img;
48 }; 48 };
49 49
50 // ============================================================================= 50 // =============================================================================
51 // GLRenderer 51 // GLRenderer
52 // 52 //
53 // The main renderer object, draws the brick on the screen, manages the camera 53 // The main renderer object, draws the brick on the screen, manages the camera
54 // and selection picking. The instance of GLRenderer is accessible as 54 // and selection picking. The instance of GLRenderer is accessible as
55 // g_win->R() 55 // g_win->R()
56 // ============================================================================= 56 // =============================================================================
57 class GLRenderer : public QGLWidget { 57 class GLRenderer : public QGLWidget
58 Q_OBJECT 58 { Q_OBJECT
59 59
60 PROPERTY (bool, drawOnly, setDrawOnly) 60 PROPERTY (bool, drawOnly, setDrawOnly)
61 PROPERTY (double, zoom, setZoom) 61 PROPERTY (double, zoom, setZoom)
62 PROPERTY (MessageManager*, msglog, setMessageLog) 62 PROPERTY (MessageManager*, msglog, setMessageLog)
63 READ_PROPERTY (bool, picking, setPicking) 63 READ_PROPERTY (bool, picking, setPicking)
64 DECLARE_PROPERTY (LDFile*, file, setFile) 64 DECLARE_PROPERTY (LDFile*, file, setFile)
65 DECLARE_PROPERTY (EditMode, editMode, setEditMode) 65 DECLARE_PROPERTY (EditMode, editMode, setEditMode)
66
67 public:
68 enum Camera { Top, Front, Left, Bottom, Back, Right, Free };
69 enum ListType { NormalList, PickList, BFCFrontList, BFCBackList };
70
71 GLRenderer (QWidget* parent = null);
72 ~GLRenderer();
73
74 Camera camera() const { return m_camera; }
75 Axis cameraAxis (bool y, Camera camid = (Camera) -1);
76 const char* cameraName() const;
77 void clearOverlay();
78 void compileObject (LDObject* obj);
79 void compileAllObjects();
80 double depthValue() const;
81 void drawGLScene();
82 void endDraw (bool accept);
83 QColor getMainColor();
84 overlayMeta& getOverlay (int newcam);
85 void hardRefresh();
86 void initGLData();
87 void overlaysFromObjects();
88 void refresh();
89 void resetAngles();
90 uchar* screencap (ushort& w, ushort& h);
91 void setBackground();
92 void setCamera (const Camera cam);
93 void setDepthValue (double depth);
94 bool setupOverlay (GLRenderer::Camera cam, str file, int x, int y, int w, int h);
95 void updateOverlayObjects();
96 void zoomNotch (bool inward);
97 void zoomToFit();
98
99 static void deleteLists (LDObject* obj);
100 66
101 protected: 67 public:
102 void contextMenuEvent (QContextMenuEvent* ev); 68 enum Camera { Top, Front, Left, Bottom, Back, Right, Free };
103 void initializeGL(); 69 enum ListType { NormalList, PickList, BFCFrontList, BFCBackList };
104 void keyPressEvent (QKeyEvent* ev);
105 void keyReleaseEvent (QKeyEvent* ev);
106 void leaveEvent (QEvent* ev);
107 void mouseDoubleClickEvent (QMouseEvent* ev);
108 void mousePressEvent (QMouseEvent* ev);
109 void mouseMoveEvent (QMouseEvent* ev);
110 void mouseReleaseEvent (QMouseEvent* ev);
111 void paintEvent (QPaintEvent* ev);
112 void resizeGL (int w, int h);
113 void wheelEvent (QWheelEvent* ev);
114 70
115 private: 71 GLRenderer (QWidget* parent = null);
116 // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets 72 ~GLRenderer();
117 // initialized before program gets to main() and constructs a QApplication
118 // and Qt doesn't like that.
119 struct CameraIcon {
120 QPixmap* img;
121 QRect srcRect, destRect, selRect;
122 Camera cam;
123 } m_cameraIcons[7];
124
125 QTimer* m_toolTipTimer;
126 Qt::MouseButtons m_lastButtons;
127 Qt::KeyboardModifiers m_keymods;
128 ulong m_totalmove;
129 vertex m_hoverpos;
130 double m_virtWidth, m_virtHeight, m_rotX, m_rotY, m_rotZ, m_panX, m_panY;
131 bool m_darkbg, m_rangepick, m_addpick, m_drawToolTip, m_screencap;
132 QPoint m_pos, m_globalpos, m_rangeStart;
133 QPen m_thickBorderPen, m_thinBorderPen;
134 Camera m_camera, m_toolTipCamera;
135 uint m_axeslist;
136 ushort m_width, m_height;
137 List<vertex> m_drawedVerts;
138 bool m_rectdraw;
139 vertex m_rectverts[4];
140 QColor m_bgcolor;
141 double m_depthValues[6];
142 overlayMeta m_overlays[6];
143 List<vertex> m_knownVerts;
144 bool m_panning;
145
146 void addDrawnVertex (vertex m_hoverpos);
147 void calcCameraIcons(); // Compute geometry for camera icons
148 void clampAngle (double& angle) const; // Clamps an angle to [0, 360]
149 void compileList (LDObject* obj, const ListType list); // Compile one of the lists of an object
150 void compileSubObject (LDObject* obj, const GLenum gltype); // Sub-routine for object compiling
151 void compileVertex (const vertex& vrt); // Compile a single vertex to a list
152 vertex coordconv2_3 (const QPoint& pos2d, bool snap) const; // Convert a 2D point to a 3D point
153 QPoint coordconv3_2 (const vertex& pos3d) const; // Convert a 3D point to a 2D point
154 LDOverlay* findOverlayObject (Camera cam);
155 void updateRectVerts();
156 void pick (uint mouseX, uint mouseY); // Perform object selection
157 void setObjectColor (LDObject* obj, const ListType list); // Set the color to an object list
158 QColor getTextPen() const; // Determine which color to draw text with
159 void getRelativeAxes (Axis& relX, Axis& relY) const;
160 73
161 void drawBlip (QPainter& paint, QPoint pos) const; 74 inline Camera camera() const
162 double circleDrawDist() const; 75 { return m_camera;
76 }
163 77
164 private slots: 78 Axis cameraAxis (bool y, Camera camid = (Camera) - 1);
165 void slot_toolTipTimer(); 79 const char* cameraName() const;
80 void clearOverlay();
81 void compileObject (LDObject* obj);
82 void compileAllObjects();
83 double depthValue() const;
84 void drawGLScene();
85 void endDraw (bool accept);
86 QColor getMainColor();
87 overlayMeta& getOverlay (int newcam);
88 void hardRefresh();
89 void initGLData();
90 void overlaysFromObjects();
91 void refresh();
92 void resetAngles();
93 uchar* screencap (ushort& w, ushort& h);
94 void setBackground();
95 void setCamera (const Camera cam);
96 void setDepthValue (double depth);
97 bool setupOverlay (GLRenderer::Camera cam, str file, int x, int y, int w, int h);
98 void updateOverlayObjects();
99 void zoomNotch (bool inward);
100 void zoomToFit();
101
102 static void deleteLists (LDObject* obj);
103
104 protected:
105 void contextMenuEvent (QContextMenuEvent* ev);
106 void initializeGL();
107 void keyPressEvent (QKeyEvent* ev);
108 void keyReleaseEvent (QKeyEvent* ev);
109 void leaveEvent (QEvent* ev);
110 void mouseDoubleClickEvent (QMouseEvent* ev);
111 void mousePressEvent (QMouseEvent* ev);
112 void mouseMoveEvent (QMouseEvent* ev);
113 void mouseReleaseEvent (QMouseEvent* ev);
114 void paintEvent (QPaintEvent* ev);
115 void resizeGL (int w, int h);
116 void wheelEvent (QWheelEvent* ev);
117
118 private:
119 // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets
120 // initialized before program gets to main() and constructs a QApplication
121 // and Qt doesn't like that.
122 struct CameraIcon
123 { QPixmap* img;
124 QRect srcRect, destRect, selRect;
125 Camera cam;
126 } m_cameraIcons[7];
127
128 QTimer* m_toolTipTimer;
129 Qt::MouseButtons m_lastButtons;
130 Qt::KeyboardModifiers m_keymods;
131 ulong m_totalmove;
132 vertex m_hoverpos;
133 double m_virtWidth, m_virtHeight, m_rotX, m_rotY, m_rotZ, m_panX, m_panY;
134 bool m_darkbg, m_rangepick, m_addpick, m_drawToolTip, m_screencap;
135 QPoint m_pos, m_globalpos, m_rangeStart;
136 QPen m_thickBorderPen, m_thinBorderPen;
137 Camera m_camera, m_toolTipCamera;
138 uint m_axeslist;
139 ushort m_width, m_height;
140 List<vertex> m_drawedVerts;
141 bool m_rectdraw;
142 vertex m_rectverts[4];
143 QColor m_bgcolor;
144 double m_depthValues[6];
145 overlayMeta m_overlays[6];
146 List<vertex> m_knownVerts;
147 bool m_panning;
148
149 void addDrawnVertex (vertex m_hoverpos);
150 void calcCameraIcons(); // Compute geometry for camera icons
151 void clampAngle (double& angle) const; // Clamps an angle to [0, 360]
152 void compileList (LDObject* obj, const ListType list); // Compile one of the lists of an object
153 void compileSubObject (LDObject* obj, const GLenum gltype); // Sub-routine for object compiling
154 void compileVertex (const vertex& vrt); // Compile a single vertex to a list
155 vertex coordconv2_3 (const QPoint& pos2d, bool snap) const; // Convert a 2D point to a 3D point
156 QPoint coordconv3_2 (const vertex& pos3d) const; // Convert a 3D point to a 2D point
157 LDOverlay* findOverlayObject (Camera cam);
158 void updateRectVerts();
159 void pick (uint mouseX, uint mouseY); // Perform object selection
160 void setObjectColor (LDObject* obj, const ListType list); // Set the color to an object list
161 QColor getTextPen() const; // Determine which color to draw text with
162 void getRelativeAxes (Axis& relX, Axis& relY) const;
163
164 void drawBlip (QPainter& paint, QPoint pos) const;
165 double circleDrawDist() const;
166
167 private slots:
168 void slot_toolTipTimer();
166 }; 169 };
167 170
168 // Alias for short namespaces 171 // Alias for short namespaces
169 typedef GLRenderer GL; 172 typedef GLRenderer GL;
170 173
171 static const GLRenderer::ListType g_glListTypes[] = { 174 static const GLRenderer::ListType g_glListTypes[] =
172 GL::NormalList, 175 { GL::NormalList,
173 GL::PickList, 176 GL::PickList,
174 GL::BFCFrontList, 177 GL::BFCFrontList,
175 GL::BFCBackList, 178 GL::BFCBackList,
176 }; 179 };
177 180

mercurial