59 // The main renderer object, draws the brick on the screen, manages the camera |
62 // The main renderer object, draws the brick on the screen, manages the camera |
60 // and selection picking. The instance of GLRenderer is accessible as |
63 // and selection picking. The instance of GLRenderer is accessible as |
61 // g_win->R() |
64 // g_win->R() |
62 // ============================================================================= |
65 // ============================================================================= |
63 class GLRenderer : public QGLWidget |
66 class GLRenderer : public QGLWidget |
64 { Q_OBJECT |
67 { typedefs: |
65 |
68 enum EFixedCamera |
66 PROPERTY (public, bool, DrawOnly, BOOL_OPS, STOCK_WRITE) |
69 { ETopCamera, |
67 PROPERTY (public, MessageManager*, MessageLog, NO_OPS, STOCK_WRITE) |
70 EFrontCamera, |
68 PROPERTY (private, bool, Picking, BOOL_OPS, STOCK_WRITE) |
71 ELeftCamera, |
69 PROPERTY (public, LDFile*, File, NO_OPS, CUSTOM_WRITE) |
72 EBottomCamera, |
70 PROPERTY (public, EditMode, EditMode, NO_OPS, CUSTOM_WRITE) |
73 EBackCamera, |
71 |
74 ERightCamera, |
72 public: |
75 EFreeCamera |
73 enum Camera { Top, Front, Left, Bottom, Back, Right, Free }; |
76 }; |
74 enum ListType { NormalList, PickList, BFCFrontList, BFCBackList }; |
77 |
75 |
78 enum ListType |
|
79 { NormalList, |
|
80 PickList, |
|
81 BFCFrontList, |
|
82 BFCBackList |
|
83 }; |
|
84 |
|
85 // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets |
|
86 // initialized before program gets to main() and constructs a QApplication |
|
87 // and Qt doesn't like that. |
|
88 struct CameraIcon |
|
89 { QPixmap* img; |
|
90 QRect srcRect, |
|
91 destRect, |
|
92 selRect; |
|
93 EFixedCamera cam; |
|
94 }; |
|
95 |
|
96 properties: |
|
97 Q_OBJECT |
|
98 PROPERTY (public, bool, DrawOnly, BOOL_OPS, STOCK_WRITE) |
|
99 PROPERTY (public, MessageManager*, MessageLog, NO_OPS, STOCK_WRITE) |
|
100 PROPERTY (private, bool, Picking, BOOL_OPS, STOCK_WRITE) |
|
101 PROPERTY (public, LDFile*, File, NO_OPS, CUSTOM_WRITE) |
|
102 PROPERTY (public, EditMode, EditMode, NO_OPS, CUSTOM_WRITE) |
|
103 |
|
104 public methods: |
76 GLRenderer (QWidget* parent = null); |
105 GLRenderer (QWidget* parent = null); |
77 ~GLRenderer(); |
106 ~GLRenderer(); |
78 |
107 |
79 inline Camera camera() const |
108 inline EFixedCamera camera() const |
80 { return m_camera; |
109 { return m_camera; |
81 } |
110 } |
82 |
111 |
83 void clearOverlay(); |
112 void clearOverlay(); |
84 void compileObject (LDObject* obj); |
113 void compileObject (LDObject* obj); |
85 void compileAllObjects(); |
114 void compileAllObjects(); |
86 void drawGLScene(); |
115 void drawGLScene(); |
87 void endDraw (bool accept); |
116 void endDraw (bool accept); |
88 Axis getCameraAxis (bool y, Camera camid = (Camera) - 1); |
117 Axis getCameraAxis (bool y, EFixedCamera camid = (EFixedCamera) - 1); |
89 const char* getCameraName() const; |
118 const char* getCameraName() const; |
90 double getDepthValue() const; |
119 double getDepthValue() const; |
91 QColor getMainColor(); |
120 QColor getMainColor(); |
92 LDGLOverlay& getOverlay (int newcam); |
121 LDGLOverlay& getOverlay (int newcam); |
93 uchar* getScreencap (int& w, int& h); |
122 uchar* getScreencap (int& w, int& h); |
96 void initOverlaysFromObjects(); |
125 void initOverlaysFromObjects(); |
97 void refresh(); |
126 void refresh(); |
98 void resetAngles(); |
127 void resetAngles(); |
99 void resetAllAngles(); |
128 void resetAllAngles(); |
100 void setBackground(); |
129 void setBackground(); |
101 void setCamera (const Camera cam); |
130 void setCamera (const EFixedCamera cam); |
102 void setDepthValue (double depth); |
131 void setDepthValue (double depth); |
103 bool setupOverlay (GLRenderer::Camera cam, str file, int x, int y, int w, int h); |
132 bool setupOverlay (EFixedCamera cam, str file, int x, int y, int w, int h); |
104 void updateOverlayObjects(); |
133 void updateOverlayObjects(); |
105 void zoomNotch (bool inward); |
134 void zoomNotch (bool inward); |
106 void zoomToFit(); |
135 void zoomToFit(); |
107 void zoomAllToFit(); |
136 void zoomAllToFit(); |
108 |
137 |
109 static void deleteLists (LDObject* obj); |
138 static void deleteLists (LDObject* obj); |
110 |
139 |
111 protected: |
140 protected methods: |
112 void contextMenuEvent (QContextMenuEvent* ev); |
141 void contextMenuEvent (QContextMenuEvent* ev); |
113 void initializeGL(); |
142 void initializeGL(); |
114 void keyPressEvent (QKeyEvent* ev); |
143 void keyPressEvent (QKeyEvent* ev); |
115 void keyReleaseEvent (QKeyEvent* ev); |
144 void keyReleaseEvent (QKeyEvent* ev); |
116 void leaveEvent (QEvent* ev); |
145 void leaveEvent (QEvent* ev); |
121 void paintEvent (QPaintEvent* ev); |
150 void paintEvent (QPaintEvent* ev); |
122 void resizeGL (int w, int h); |
151 void resizeGL (int w, int h); |
123 void wheelEvent (QWheelEvent* ev); |
152 void wheelEvent (QWheelEvent* ev); |
124 |
153 |
125 private: |
154 private: |
126 // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets |
|
127 // initialized before program gets to main() and constructs a QApplication |
|
128 // and Qt doesn't like that. |
|
129 struct CameraIcon |
|
130 { QPixmap* img; |
|
131 QRect srcRect, destRect, selRect; |
|
132 Camera cam; |
|
133 }; |
|
134 |
|
135 CameraIcon m_cameraIcons[7]; |
155 CameraIcon m_cameraIcons[7]; |
136 QTimer* m_toolTipTimer; |
156 QTimer* m_toolTipTimer; |
137 Qt::MouseButtons m_lastButtons; |
157 Qt::MouseButtons m_lastButtons; |
138 Qt::KeyboardModifiers m_keymods; |
158 Qt::KeyboardModifiers m_keymods; |
139 vertex m_hoverpos; |
159 vertex m_hoverpos; |
169 double m_depthValues[6]; |
189 double m_depthValues[6]; |
170 LDGLOverlay m_overlays[6]; |
190 LDGLOverlay m_overlays[6]; |
171 QList<vertex> m_knownVerts; |
191 QList<vertex> m_knownVerts; |
172 |
192 |
173 void addDrawnVertex (vertex m_hoverpos); |
193 void addDrawnVertex (vertex m_hoverpos); |
174 LDOverlay* findOverlayObject (Camera cam); |
194 LDOverlay* findOverlayObject (EFixedCamera cam); |
175 void updateRectVerts(); |
195 void updateRectVerts(); |
176 void getRelativeAxes (Axis& relX, Axis& relY) const; |
196 void getRelativeAxes (Axis& relX, Axis& relY) const; |
177 matrix getCircleDrawMatrix (double scale); |
197 matrix getCircleDrawMatrix (double scale); |
178 void drawBlip (QPainter& paint, QPoint pos) const; |
198 void drawBlip (QPainter& paint, QPoint pos) const; |
179 |
199 |