Sat, 07 Dec 2013 01:03:17 +0200
more stuff
src/dialogs.cpp | file | annotate | diff | comparison | revisions | |
src/file.h | file | annotate | diff | comparison | revisions | |
src/gldraw.cpp | file | annotate | diff | comparison | revisions | |
src/gldraw.h | file | annotate | diff | comparison | revisions | |
src/gui.cpp | file | annotate | diff | comparison | revisions | |
src/gui_actions.cpp | file | annotate | diff | comparison | revisions |
--- a/src/dialogs.cpp Sat Dec 07 00:01:20 2013 +0200 +++ b/src/dialogs.cpp Sat Dec 07 01:03:17 2013 +0200 @@ -55,18 +55,18 @@ ui->setupUi (this); m_cameraArgs = - { { ui->top, GL::Top }, - { ui->bottom, GL::Bottom }, - { ui->front, GL::Front }, - { ui->back, GL::Back }, - { ui->left, GL::Left }, - { ui->right, GL::Right } + { { ui->top, GL::ETopCamera }, + { ui->bottom, GL::EBottomCamera }, + { ui->front, GL::EFrontCamera }, + { ui->back, GL::EBackCamera }, + { ui->left, GL::ELeftCamera }, + { ui->right, GL::ERightCamera } }; - GL::Camera cam = g_win->R()->camera(); + GL::EFixedCamera cam = g_win->R()->camera(); - if (cam == GL::Free) - cam = GL::Top; + if (cam == GL::EFreeCamera) + cam = GL::ETopCamera; connect (ui->width, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged())); connect (ui->height, SIGNAL (valueChanged (double)), this, SLOT (slot_dimensionsChanged())); @@ -128,7 +128,7 @@ } int OverlayDialog::camera() const -{ return radioSwitch<int> (GL::Top, m_cameraArgs); +{ return radioSwitch<int> (GL::ETopCamera, m_cameraArgs); } void OverlayDialog::slot_fpath()
--- a/src/file.h Sat Dec 07 00:01:20 2013 +0200 +++ b/src/file.h Sat Dec 07 01:03:17 2013 +0200 @@ -52,16 +52,17 @@ // primitive generator uses this to give initial names to primitives. // ============================================================================= class LDFile : public QObject -{ Q_OBJECT - PROPERTY (private, QList<LDObject*>, Objects, NO_OPS, STOCK_WRITE) - PROPERTY (private, History*, History, NO_OPS, STOCK_WRITE) - PROPERTY (private, QList<LDObject*>, Vertices, NO_OPS, STOCK_WRITE) - PROPERTY (public, str, Name, STR_OPS, STOCK_WRITE) - PROPERTY (public, str, DefaultName, STR_OPS, STOCK_WRITE) - PROPERTY (public, bool, Implicit, BOOL_OPS, STOCK_WRITE) - PROPERTY (public, QList<LDObject*>, Cache, NO_OPS, STOCK_WRITE) - PROPERTY (public, long, SavePosition, NUM_OPS, STOCK_WRITE) - PROPERTY (public, QListWidgetItem*, ListItem, NO_OPS, STOCK_WRITE) +{ properties: + Q_OBJECT + PROPERTY (private, QList<LDObject*>, Objects, NO_OPS, STOCK_WRITE) + PROPERTY (private, History*, History, NO_OPS, STOCK_WRITE) + PROPERTY (private, QList<LDObject*>, Vertices, NO_OPS, STOCK_WRITE) + PROPERTY (public, str, Name, STR_OPS, STOCK_WRITE) + PROPERTY (public, str, DefaultName, STR_OPS, STOCK_WRITE) + PROPERTY (public, bool, Implicit, BOOL_OPS, STOCK_WRITE) + PROPERTY (public, QList<LDObject*>, Cache, NO_OPS, STOCK_WRITE) + PROPERTY (public, long, SavePosition, NUM_OPS, STOCK_WRITE) + PROPERTY (public, QListWidgetItem*, ListItem, NO_OPS, STOCK_WRITE) public: LDFile();
--- a/src/gldraw.cpp Sat Dec 07 00:01:20 2013 +0200 +++ b/src/gldraw.cpp Sat Dec 07 01:03:17 2013 +0200 @@ -59,7 +59,7 @@ cfg (Float, gl_maincolor_alpha, 1.0); cfg (Int, gl_linethickness, 2); cfg (Bool, gl_colorbfc, false); -cfg (Int, gl_camera, GLRenderer::Free); +cfg (Int, gl_camera, GLRenderer::EFreeCamera); cfg (Bool, gl_blackedges, false); cfg (Bool, gl_axes, false); cfg (Bool, gl_wireframe, false); @@ -77,14 +77,14 @@ QT_TRANSLATE_NOOP ("GLRenderer", "Free") }; -const GL::Camera g_Cameras[7] = -{ GL::Top, - GL::Front, - GL::Left, - GL::Bottom, - GL::Back, - GL::Right, - GL::Free +const GL::EFixedCamera g_Cameras[7] = +{ GL::ETopCamera, + GL::EFrontCamera, + GL::ELeftCamera, + GL::EBottomCamera, + GL::EBackCamera, + GL::ERightCamera, + GL::EFreeCamera }; const struct LDGLAxis @@ -103,9 +103,9 @@ // ----------------------------------------------------------------------------- GLRenderer::GLRenderer (QWidget* parent) : QGLWidget (parent) { m_Picking = m_rangepick = false; - m_camera = (GL::Camera) gl_camera.value; + m_camera = (GL::EFixedCamera) gl_camera.value; m_drawToolTip = false; - m_EditMode = Select; + m_EditMode = ESelectMode; m_rectdraw = false; m_panning = false; setFile (null); @@ -123,7 +123,7 @@ m_thinBorderPen.setWidth (1); // Init camera icons - for (const GL::Camera cam : g_Cameras) + for (const GL::EFixedCamera cam : g_Cameras) { str iconname = fmt ("camera-%1", tr (g_CameraNames[cam]).toLower()); CameraIcon* info = &m_cameraIcons[cam]; @@ -158,7 +158,7 @@ for (CameraIcon& info : m_cameraIcons) { // MATH - const long x1 = (m_width - (info.cam != Free ? 48 : 16)) + ((i % 3) * 16) - 1, + const long x1 = (m_width - (info.cam != EFreeCamera ? 48 : 16)) + ((i % 3) * 16) - 1, y1 = ((i / 3) * 16) + 1; info.srcRect = QRect (0, 0, 16, 16); @@ -209,10 +209,10 @@ // ============================================================================= // ----------------------------------------------------------------------------- void GLRenderer::resetAllAngles() -{ Camera oldcam = camera(); +{ EFixedCamera oldcam = camera(); for (int i = 0; i < 7; ++i) - { setCamera ((Camera) i); + { setCamera ((EFixedCamera) i); resetAngles(); } @@ -392,7 +392,7 @@ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable (GL_DEPTH_TEST); - if (m_camera != Free) + if (m_camera != EFreeCamera) { glMatrixMode (GL_PROJECTION); glPushMatrix(); @@ -400,14 +400,14 @@ glOrtho (-m_virtWidth, m_virtWidth, -m_virtHeight, m_virtHeight, -100.0f, 100.0f); glTranslatef (pan (X), pan (Y), 0.0f); - if (m_camera != Front && m_camera != Back) + if (m_camera != EFrontCamera && m_camera != EBackCamera) { glRotatef (90.0f, g_FixedCameras[camera()].glrotate[0], g_FixedCameras[camera()].glrotate[1], g_FixedCameras[camera()].glrotate[2]); } // Back camera needs to be handled differently - if (m_camera == GLRenderer::Back) + if (m_camera == GLRenderer::EBackCamera) { glRotatef (180.0f, 1.0f, 0.0f, 0.0f); glRotatef (180.0f, 0.0f, 0.0f, 1.0f); } @@ -465,7 +465,7 @@ // is true, the 3D point will snap to the current grid. // ----------------------------------------------------------------------------- vertex GLRenderer::coordconv2_3 (const QPoint& pos2d, bool snap) const -{ assert (camera() != Free); +{ assert (camera() != EFreeCamera); vertex pos3d; const LDFixedCameraInfo* cam = &g_FixedCameras[m_camera]; @@ -546,7 +546,7 @@ if (isDrawOnly()) return; - if (m_camera != Free && !isPicking()) + if (m_camera != EFreeCamera && !isPicking()) { // Paint the overlay image if we have one const LDGLOverlay& overlay = m_overlays[m_camera]; @@ -574,7 +574,7 @@ linepen.setColor (luma (m_bgcolor) < 40 ? Qt::white : Qt::black); // If we're drawing, draw the vertices onto the screen. - if (getEditMode() == Draw) + if (getEditMode() == EDrawMode) { int numverts = 4; if (!m_rectdraw) @@ -631,7 +631,7 @@ } } } - elif (getEditMode() == CircleMode) + elif (getEditMode() == ECircleMode) { // If we have not specified the center point of the circle yet, preview it on the screen. if (m_drawedVerts.isEmpty()) drawBlip (paint, coordconv3_2 (m_hoverpos)); @@ -726,7 +726,7 @@ // Draw the actual icons for (CameraIcon& info : m_cameraIcons) { // Don't draw the free camera icon when in draw mode - if (&info == &m_cameraIcons[GL::Free] && getEditMode() != Select) + if (&info == &m_cameraIcons[GL::EFreeCamera] && getEditMode() != ESelectMode) continue; paint.drawPixmap (info.destRect, *info.img, info.srcRect); @@ -935,7 +935,7 @@ // ----------------------------------------------------------------------------- void GLRenderer::addDrawnVertex (vertex pos) { // If we picked an already-existing vertex, stop drawing - if (getEditMode() != CircleMode) + if (getEditMode() != ECircleMode) { for (vertex& vert : m_drawedVerts) { if (vert == pos) { endDraw (true); @@ -969,7 +969,7 @@ } switch (getEditMode()) - { case Draw: + { case EDrawMode: { if (m_rectdraw) { if (m_drawedVerts.size() == 2) { endDraw (true); @@ -991,7 +991,7 @@ addDrawnVertex (m_hoverpos); } break; - case CircleMode: + case ECircleMode: { if (m_drawedVerts.size() == 3) { endDraw (true); return; @@ -1000,7 +1000,7 @@ addDrawnVertex (m_hoverpos); } break; - case Select: + case ESelectMode: { if (!isDrawOnly()) { if (m_totalmove < 10) m_rangepick = false; @@ -1017,7 +1017,7 @@ m_rangepick = false; } - if (wasMid && getEditMode() != Select && m_drawedVerts.size() < 4 && m_totalmove < 10) + if (wasMid && getEditMode() != ESelectMode && m_drawedVerts.size() < 4 && m_totalmove < 10) { // Find the closest vertex to our cursor double mindist = 1024.0f; vertex closest; @@ -1096,7 +1096,7 @@ { pan (X) += 0.03f * dx * (zoom() / 7.5f); pan (Y) -= 0.03f * dy * (zoom() / 7.5f); m_panning = true; - } elif (left && !m_rangepick && camera() == Free) + } elif (left && !m_rangepick && camera() == EFreeCamera) { rot (X) = rot (X) + dy; rot (Y) = rot (Y) + dx; @@ -1113,7 +1113,7 @@ m_globalpos = ev->globalPos(); // Calculate 3d position of the cursor - m_hoverpos = (camera() != Free) ? coordconv2_3 (m_pos, true) : g_origin; + m_hoverpos = (camera() != EFreeCamera) ? coordconv2_3 (m_pos, true) : g_origin; // Update rect vertices since m_hoverpos may have changed updateRectVerts(); @@ -1162,7 +1162,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -void GLRenderer::setCamera (const GL::Camera cam) +void GLRenderer::setCamera (const GLRenderer::EFixedCamera cam) { m_camera = cam; gl_camera = (int) cam; g_win->updateEditModeActions(); @@ -1294,16 +1294,16 @@ { m_EditMode = a; switch (a) - { case Select: + { case ESelectMode: { unsetCursor(); setContextMenuPolicy (Qt::DefaultContextMenu); } break; - case Draw: - case CircleMode: + case EDrawMode: + case ECircleMode: { // Cannot draw into the free camera - use top instead. - if (m_camera == Free) - setCamera (Top); + if (m_camera == EFreeCamera) + setCamera (ETopCamera); // Disable the context menu - we need the right mouse button // for removing vertices. @@ -1360,7 +1360,7 @@ QList<LDObject*> objs; switch (getEditMode()) - { case Draw: + { case EDrawMode: { if (m_rectdraw) { LDQuad* quad = new LDQuad; @@ -1407,7 +1407,7 @@ } } break; - case CircleMode: + case ECircleMode: { const int segs = lores, divs = lores; // TODO: make customizable double dist0 = getCircleDrawDist (0), dist1 = getCircleDrawDist (1); @@ -1499,7 +1499,7 @@ } } break; - case Select: + case ESelectMode: { // this shouldn't happen assert (false); return; @@ -1638,8 +1638,8 @@ // ============================================================================= // ----------------------------------------------------------------------------- -Axis GLRenderer::getCameraAxis (bool y, GL::Camera camid) -{ if (camid == (GL::Camera) - 1) +Axis GLRenderer::getCameraAxis (bool y, GLRenderer::EFixedCamera camid) +{ if (camid == (GL::EFixedCamera) - 1) camid = m_camera; const LDFixedCameraInfo* cam = &g_FixedCameras[camid]; @@ -1648,7 +1648,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -bool GLRenderer::setupOverlay (GL::Camera cam, str file, int x, int y, int w, int h) +bool GLRenderer::setupOverlay (EFixedCamera cam, str file, int x, int y, int w, int h) { QImage* img = new QImage (file); LDGLOverlay& info = getOverlay (cam); @@ -1697,7 +1697,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void GLRenderer::clearOverlay() -{ if (camera() == Free) +{ if (camera() == EFreeCamera) return; LDGLOverlay& info = m_overlays[camera()]; @@ -1710,14 +1710,14 @@ // ============================================================================= // ----------------------------------------------------------------------------- void GLRenderer::setDepthValue (double depth) -{ assert (camera() < Free); +{ assert (camera() < EFreeCamera); m_depthValues[camera()] = depth; } // ============================================================================= // ----------------------------------------------------------------------------- double GLRenderer::getDepthValue() const -{ assert (camera() < Free); +{ assert (camera() < EFreeCamera); return m_depthValues[camera()]; } @@ -1824,10 +1824,10 @@ // ============================================================================= // ----------------------------------------------------------------------------- void GLRenderer::zoomAllToFit() -{ Camera oldcam = camera(); +{ EFixedCamera oldcam = camera(); for (int i = 0; i < 7; ++i) - { setCamera ((Camera) i); + { setCamera ((EFixedCamera) i); zoomToFit(); } @@ -1870,7 +1870,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void GLRenderer::mouseDoubleClickEvent (QMouseEvent* ev) -{ if (!(ev->buttons() & Qt::LeftButton) || getEditMode() != Select) +{ if (!(ev->buttons() & Qt::LeftButton) || getEditMode() != ESelectMode) return; pick (ev->x(), ev->y()); @@ -1887,7 +1887,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -LDOverlay* GLRenderer::findOverlayObject (GLRenderer::Camera cam) +LDOverlay* GLRenderer::findOverlayObject (EFixedCamera cam) { LDOverlay* ovlobj = null; for (LDObject * obj : getFile()->getObjects()) @@ -1905,8 +1905,8 @@ // Read in overlays from the current file and update overlay info accordingly. // ----------------------------------------------------------------------------- void GLRenderer::initOverlaysFromObjects() -{ for (Camera cam : g_Cameras) - { if (cam == Free) +{ for (EFixedCamera cam : g_Cameras) + { if (cam == EFreeCamera) continue; LDGLOverlay& meta = m_overlays[cam]; @@ -1924,8 +1924,8 @@ // ============================================================================= // ----------------------------------------------------------------------------- void GLRenderer::updateOverlayObjects() -{ for (Camera cam : g_Cameras) - { if (cam == Free) +{ for (EFixedCamera cam : g_Cameras) + { if (cam == EFreeCamera) continue; LDGLOverlay& meta = m_overlays[cam];
--- a/src/gldraw.h Sat Dec 07 00:01:20 2013 +0200 +++ b/src/gldraw.h Sat Dec 07 01:03:17 2013 +0200 @@ -33,18 +33,21 @@ class QTimer; enum EditMode -{ Select, - Draw, - CircleMode, +{ ESelectMode, + EDrawMode, + ECircleMode, }; // Meta for overlays struct LDGLOverlay -{ vertex v0, v1; - int ox, oy; - double lw, lh; - str fname; - QImage* img; +{ vertex v0, + v1; + int ox, + oy; + double lw, + lh; + str fname; + QImage* img; }; struct LDFixedCameraInfo @@ -61,22 +64,48 @@ // g_win->R() // ============================================================================= class GLRenderer : public QGLWidget -{ Q_OBJECT +{ typedefs: + enum EFixedCamera + { ETopCamera, + EFrontCamera, + ELeftCamera, + EBottomCamera, + EBackCamera, + ERightCamera, + EFreeCamera + }; + + enum ListType + { NormalList, + PickList, + BFCFrontList, + BFCBackList + }; - PROPERTY (public, bool, DrawOnly, BOOL_OPS, STOCK_WRITE) - PROPERTY (public, MessageManager*, MessageLog, NO_OPS, STOCK_WRITE) - PROPERTY (private, bool, Picking, BOOL_OPS, STOCK_WRITE) - PROPERTY (public, LDFile*, File, NO_OPS, CUSTOM_WRITE) - PROPERTY (public, EditMode, EditMode, NO_OPS, CUSTOM_WRITE) + // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets + // initialized before program gets to main() and constructs a QApplication + // and Qt doesn't like that. + struct CameraIcon + { QPixmap* img; + QRect srcRect, + destRect, + selRect; + EFixedCamera cam; + }; - public: - enum Camera { Top, Front, Left, Bottom, Back, Right, Free }; - enum ListType { NormalList, PickList, BFCFrontList, BFCBackList }; + properties: + Q_OBJECT + PROPERTY (public, bool, DrawOnly, BOOL_OPS, STOCK_WRITE) + PROPERTY (public, MessageManager*, MessageLog, NO_OPS, STOCK_WRITE) + PROPERTY (private, bool, Picking, BOOL_OPS, STOCK_WRITE) + PROPERTY (public, LDFile*, File, NO_OPS, CUSTOM_WRITE) + PROPERTY (public, EditMode, EditMode, NO_OPS, CUSTOM_WRITE) + public methods: GLRenderer (QWidget* parent = null); ~GLRenderer(); - inline Camera camera() const + inline EFixedCamera camera() const { return m_camera; } @@ -85,7 +114,7 @@ void compileAllObjects(); void drawGLScene(); void endDraw (bool accept); - Axis getCameraAxis (bool y, Camera camid = (Camera) - 1); + Axis getCameraAxis (bool y, EFixedCamera camid = (EFixedCamera) - 1); const char* getCameraName() const; double getDepthValue() const; QColor getMainColor(); @@ -98,9 +127,9 @@ void resetAngles(); void resetAllAngles(); void setBackground(); - void setCamera (const Camera cam); + void setCamera (const EFixedCamera cam); void setDepthValue (double depth); - bool setupOverlay (GLRenderer::Camera cam, str file, int x, int y, int w, int h); + bool setupOverlay (EFixedCamera cam, str file, int x, int y, int w, int h); void updateOverlayObjects(); void zoomNotch (bool inward); void zoomToFit(); @@ -108,7 +137,7 @@ static void deleteLists (LDObject* obj); - protected: + protected methods: void contextMenuEvent (QContextMenuEvent* ev); void initializeGL(); void keyPressEvent (QKeyEvent* ev); @@ -123,15 +152,6 @@ void wheelEvent (QWheelEvent* ev); private: - // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets - // initialized before program gets to main() and constructs a QApplication - // and Qt doesn't like that. - struct CameraIcon - { QPixmap* img; - QRect srcRect, destRect, selRect; - Camera cam; - }; - CameraIcon m_cameraIcons[7]; QTimer* m_toolTipTimer; Qt::MouseButtons m_lastButtons; @@ -156,7 +176,7 @@ m_rangeStart; QPen m_thickBorderPen, m_thinBorderPen; - Camera m_camera, + EFixedCamera m_camera, m_toolTipCamera; GLuint m_axeslist; int m_width, @@ -171,7 +191,7 @@ QList<vertex> m_knownVerts; void addDrawnVertex (vertex m_hoverpos); - LDOverlay* findOverlayObject (Camera cam); + LDOverlay* findOverlayObject (EFixedCamera cam); void updateRectVerts(); void getRelativeAxes (Axis& relX, Axis& relY) const; matrix getCircleDrawMatrix (double scale); @@ -247,7 +267,7 @@ GL::BFCBackList, }; -extern const GL::Camera g_Cameras[7]; +extern const GL::EFixedCamera g_Cameras[7]; extern const char* g_CameraNames[7]; #endif // LDFORGE_GLDRAW_H
--- a/src/gui.cpp Sat Dec 07 00:01:20 2013 +0200 +++ b/src/gui.cpp Sat Dec 07 01:03:17 2013 +0200 @@ -597,7 +597,7 @@ contextMenu->addAction (ui->actionModeDraw); contextMenu->addAction (ui->actionModeCircle); - if (R()->camera() != GL::Free) + if (R()->camera() != GL::EFreeCamera) { contextMenu->addSeparator(); contextMenu->addAction (ui->actionSetDrawDepth); } @@ -633,9 +633,9 @@ // ----------------------------------------------------------------------------- void ForgeWindow::updateEditModeActions() { const EditMode mode = R()->getEditMode(); - ui->actionModeSelect->setChecked (mode == Select); - ui->actionModeDraw->setChecked (mode == Draw); - ui->actionModeCircle->setChecked (mode == CircleMode); + ui->actionModeSelect->setChecked (mode == ESelectMode); + ui->actionModeDraw->setChecked (mode == EDrawMode); + ui->actionModeCircle->setChecked (mode == ECircleMode); } // =============================================================================
--- a/src/gui_actions.cpp Sat Dec 07 00:01:20 2013 +0200 +++ b/src/gui_actions.cpp Sat Dec 07 01:03:17 2013 +0200 @@ -512,8 +512,8 @@ if (!dlg.exec()) return; - g_win->R()->setupOverlay ( (GL::Camera) dlg.camera(), dlg.fpath(), dlg.ofsx(), - dlg.ofsy(), dlg.lwidth(), dlg.lheight()); + g_win->R()->setupOverlay ((GL::EFixedCamera) dlg.camera(), dlg.fpath(), dlg.ofsx(), + dlg.ofsy(), dlg.lwidth(), dlg.lheight()); } // ============================================================================= @@ -525,25 +525,25 @@ // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (ModeSelect, CTRL (1)) -{ g_win->R()->setEditMode (Select); +{ g_win->R()->setEditMode (ESelectMode); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (ModeDraw, CTRL (2)) -{ g_win->R()->setEditMode (Draw); +{ g_win->R()->setEditMode (EDrawMode); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (ModeCircle, CTRL (3)) -{ g_win->R()->setEditMode (CircleMode); +{ g_win->R()->setEditMode (ECircleMode); } // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (SetDrawDepth, 0) -{ if (g_win->R()->camera() == GL::Free) +{ if (g_win->R()->camera() == GL::EFreeCamera) return; bool ok;