49 // ============================================================================= |
49 // ============================================================================= |
50 // GLRenderer |
50 // GLRenderer |
51 // |
51 // |
52 // The main renderer object, draws the brick on the screen, manages the camera |
52 // The main renderer object, draws the brick on the screen, manages the camera |
53 // and selection picking. The instance of GLRenderer is accessible as |
53 // and selection picking. The instance of GLRenderer is accessible as |
54 // g_win->R () |
54 // g_win->R() |
55 // ============================================================================= |
55 // ============================================================================= |
56 class GLRenderer : public QGLWidget { |
56 class GLRenderer : public QGLWidget { |
57 Q_OBJECT |
57 Q_OBJECT |
58 |
58 |
59 PROPERTY( bool, drawOnly, setDrawOnly ) |
59 PROPERTY (bool, drawOnly, setDrawOnly) |
60 PROPERTY( double, zoom, setZoom ) |
60 PROPERTY (double, zoom, setZoom) |
61 PROPERTY( MessageManager*, msglog, setMessageLog ) |
61 PROPERTY (MessageManager*, msglog, setMessageLog) |
62 READ_PROPERTY (bool, picking, setPicking) |
62 READ_PROPERTY (bool, picking, setPicking) |
63 DECLARE_PROPERTY (LDFile*, file, setFile) |
63 DECLARE_PROPERTY (LDFile*, file, setFile) |
64 DECLARE_PROPERTY (EditMode, editMode, setEditMode) |
64 DECLARE_PROPERTY (EditMode, editMode, setEditMode) |
65 |
65 |
66 public: |
66 public: |
67 enum Camera { Top, Front, Left, Bottom, Back, Right, Free }; |
67 enum Camera { Top, Front, Left, Bottom, Back, Right, Free }; |
68 enum ListType { NormalList, PickList, BFCFrontList, BFCBackList }; |
68 enum ListType { NormalList, PickList, BFCFrontList, BFCBackList }; |
69 |
69 |
70 GLRenderer (QWidget* parent = null); |
70 GLRenderer (QWidget* parent = null); |
71 ~GLRenderer (); |
71 ~GLRenderer(); |
72 |
72 |
73 Camera camera () const { return m_camera; } |
73 Camera camera() const { return m_camera; } |
74 Axis cameraAxis ( bool y, Camera camid = (Camera) -1 ); |
74 Axis cameraAxis (bool y, Camera camid = (Camera) -1); |
75 const char* cameraName () const; |
75 const char* cameraName() const; |
76 void clearOverlay (); |
76 void clearOverlay(); |
77 void compileObject (LDObject* obj); |
77 void compileObject (LDObject* obj); |
78 void compileAllObjects (); |
78 void compileAllObjects(); |
79 double depthValue () const; |
79 double depthValue() const; |
80 void drawGLScene (); |
80 void drawGLScene(); |
81 void endDraw (bool accept); |
81 void endDraw (bool accept); |
82 QColor getMainColor (); |
82 QColor getMainColor(); |
83 overlayMeta& getOverlay (int newcam); |
83 overlayMeta& getOverlay (int newcam); |
84 void hardRefresh (); |
84 void hardRefresh(); |
85 void initGLData (); |
85 void initGLData(); |
86 void overlaysFromObjects (); |
86 void overlaysFromObjects(); |
87 void refresh (); |
87 void refresh(); |
88 void resetAngles (); |
88 void resetAngles(); |
89 uchar* screencap (ushort& w, ushort& h); |
89 uchar* screencap (ushort& w, ushort& h); |
90 void setBackground (); |
90 void setBackground(); |
91 void setCamera (const Camera cam); |
91 void setCamera (const Camera cam); |
92 void setDepthValue (double depth); |
92 void setDepthValue (double depth); |
93 bool setupOverlay ( GLRenderer::Camera cam, str file, int x, int y, int w, int h ); |
93 bool setupOverlay (GLRenderer::Camera cam, str file, int x, int y, int w, int h); |
94 void updateOverlayObjects(); |
94 void updateOverlayObjects(); |
95 void zoomNotch (bool inward); |
95 void zoomNotch (bool inward); |
96 void zoomToFit (); |
96 void zoomToFit(); |
97 |
97 |
98 static void deleteLists (LDObject* obj); |
98 static void deleteLists (LDObject* obj); |
99 |
99 |
100 protected: |
100 protected: |
101 void contextMenuEvent (QContextMenuEvent* ev); |
101 void contextMenuEvent (QContextMenuEvent* ev); |
102 void initializeGL (); |
102 void initializeGL(); |
103 void keyPressEvent (QKeyEvent* ev); |
103 void keyPressEvent (QKeyEvent* ev); |
104 void keyReleaseEvent (QKeyEvent* ev); |
104 void keyReleaseEvent (QKeyEvent* ev); |
105 void leaveEvent (QEvent* ev); |
105 void leaveEvent (QEvent* ev); |
106 void mouseDoubleClickEvent (QMouseEvent* ev); |
106 void mouseDoubleClickEvent (QMouseEvent* ev); |
107 void mousePressEvent (QMouseEvent* ev); |
107 void mousePressEvent (QMouseEvent* ev); |
108 void mouseMoveEvent (QMouseEvent* ev); |
108 void mouseMoveEvent (QMouseEvent* ev); |
109 void mouseReleaseEvent (QMouseEvent* ev); |
109 void mouseReleaseEvent (QMouseEvent* ev); |
110 void paintEvent (QPaintEvent* ev); |
110 void paintEvent (QPaintEvent* ev); |
111 void resizeGL (int w, int h); |
111 void resizeGL (int w, int h); |
112 void wheelEvent (QWheelEvent* ev); |
112 void wheelEvent (QWheelEvent* ev); |
113 |
113 |
114 private: |
114 private: |
115 // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets |
115 // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets |
116 // initialized before program gets to main() and constructs a QApplication |
116 // initialized before program gets to main() and constructs a QApplication |
117 // and Qt doesn't like that. |
117 // and Qt doesn't like that. |
140 double m_depthValues[6]; |
140 double m_depthValues[6]; |
141 overlayMeta m_overlays[6]; |
141 overlayMeta m_overlays[6]; |
142 List<vertex> m_knownVerts; |
142 List<vertex> m_knownVerts; |
143 bool m_panning; |
143 bool m_panning; |
144 |
144 |
145 void addDrawnVertex (vertex m_hoverpos); |
145 void addDrawnVertex (vertex m_hoverpos); |
146 void calcCameraIcons (); // Compute geometry for camera icons |
146 void calcCameraIcons(); // Compute geometry for camera icons |
147 void clampAngle (double& angle) const; // Clamps an angle to [0, 360] |
147 void clampAngle (double& angle) const; // Clamps an angle to [0, 360] |
148 void compileList (LDObject* obj, const ListType list); // Compile one of the lists of an object |
148 void compileList (LDObject* obj, const ListType list); // Compile one of the lists of an object |
149 void compileSubObject (LDObject* obj, const GLenum gltype); // Sub-routine for object compiling |
149 void compileSubObject (LDObject* obj, const GLenum gltype); // Sub-routine for object compiling |
150 void compileVertex (const vertex& vrt); // Compile a single vertex to a list |
150 void compileVertex (const vertex& vrt); // Compile a single vertex to a list |
151 vertex coordconv2_3 (const QPoint& pos2d, bool snap) const; // Convert a 2D point to a 3D point |
151 vertex coordconv2_3 (const QPoint& pos2d, bool snap) const; // Convert a 2D point to a 3D point |
152 QPoint coordconv3_2 (const vertex& pos3d) const; // Convert a 3D point to a 2D point |
152 QPoint coordconv3_2 (const vertex& pos3d) const; // Convert a 3D point to a 2D point |
153 LDOverlayObject* findOverlayObject ( Camera cam ); |
153 LDOverlayObject* findOverlayObject (Camera cam); |
154 void updateRectVerts (); |
154 void updateRectVerts(); |
155 void pick (uint mouseX, uint mouseY); // Perform object selection |
155 void pick (uint mouseX, uint mouseY); // Perform object selection |
156 void setObjectColor (LDObject* obj, const ListType list); // Set the color to an object list |
156 void setObjectColor (LDObject* obj, const ListType list); // Set the color to an object list |
157 |
157 |
158 private slots: |
158 private slots: |
159 void slot_toolTipTimer (); |
159 void slot_toolTipTimer(); |
160 }; |
160 }; |
161 |
161 |
162 // Alias for short namespaces |
162 // Alias for short namespaces |
163 typedef GLRenderer GL; |
163 typedef GLRenderer GL; |
164 |
164 |