src/gldraw.h

changeset 550
d97594e3fc54
parent 541
0e38beeb050a
child 553
2418d5955421
equal deleted inserted replaced
549:715d9a7f6598 550:d97594e3fc54
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 { ESelectMode,
37 Draw, 37 EDrawMode,
38 CircleMode, 38 ECircleMode,
39 }; 39 };
40 40
41 // Meta for overlays 41 // Meta for overlays
42 struct LDGLOverlay 42 struct LDGLOverlay
43 { vertex v0, v1; 43 { vertex v0,
44 int ox, oy; 44 v1;
45 double lw, lh; 45 int ox,
46 str fname; 46 oy;
47 QImage* img; 47 double lw,
48 lh;
49 str fname;
50 QImage* img;
48 }; 51 };
49 52
50 struct LDFixedCameraInfo 53 struct LDFixedCameraInfo
51 { const char glrotate[3]; 54 { const char glrotate[3];
52 const Axis axisX, axisY; 55 const Axis axisX, axisY;
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;
154 QPoint m_pos, 174 QPoint m_pos,
155 m_globalpos, 175 m_globalpos,
156 m_rangeStart; 176 m_rangeStart;
157 QPen m_thickBorderPen, 177 QPen m_thickBorderPen,
158 m_thinBorderPen; 178 m_thinBorderPen;
159 Camera m_camera, 179 EFixedCamera m_camera,
160 m_toolTipCamera; 180 m_toolTipCamera;
161 GLuint m_axeslist; 181 GLuint m_axeslist;
162 int m_width, 182 int m_width,
163 m_height, 183 m_height,
164 m_totalmove; 184 m_totalmove;
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
245 GL::PickList, 265 GL::PickList,
246 GL::BFCFrontList, 266 GL::BFCFrontList,
247 GL::BFCBackList, 267 GL::BFCBackList,
248 }; 268 };
249 269
250 extern const GL::Camera g_Cameras[7]; 270 extern const GL::EFixedCamera g_Cameras[7];
251 extern const char* g_CameraNames[7]; 271 extern const char* g_CameraNames[7];
252 272
253 #endif // LDFORGE_GLDRAW_H 273 #endif // LDFORGE_GLDRAW_H

mercurial