Sun, 08 May 2016 15:26:58 +0300
- Refactoring...
- Camera icons don't have to be heap allocated anymore
src/dialogs.cpp | file | annotate | diff | comparison | revisions | |
src/editmodes/abstractEditMode.cpp | file | annotate | diff | comparison | revisions | |
src/glRenderer.cpp | file | annotate | diff | comparison | revisions | |
src/glRenderer.h | file | annotate | diff | comparison | revisions | |
src/glShared.h | file | annotate | diff | comparison | revisions | |
src/ldObject.h | file | annotate | diff | comparison | revisions | |
src/macros.h | file | annotate | diff | comparison | revisions | |
src/mainwindow.cpp | file | annotate | diff | comparison | revisions | |
src/toolsets/viewtoolset.cpp | file | annotate | diff | comparison | revisions |
--- a/src/dialogs.cpp Sun May 08 13:25:12 2016 +0300 +++ b/src/dialogs.cpp Sun May 08 15:26:58 2016 +0300 @@ -60,7 +60,7 @@ { ui->right, ERightCamera } }; - ECamera cam = g_win->renderer()->camera(); + Camera cam = g_win->renderer()->camera(); if (cam == EFreeCamera) cam = ETopCamera;
--- a/src/editmodes/abstractEditMode.cpp Sun May 08 13:25:12 2016 +0300 +++ b/src/editmodes/abstractEditMode.cpp Sun May 08 15:26:58 2016 +0300 @@ -108,7 +108,7 @@ // Sort the vertices in order of distance to camera std::sort (vertices.begin(), vertices.end(), [&](const Vertex& a, const Vertex& b) -> bool { - if (renderer()->getFixedCamera (renderer()->camera()).negatedDepth) + if (renderer()->cameraInfo (renderer()->camera()).negatedDepth) return a[relZ] > b[relZ]; return a[relZ] < b[relZ];
--- a/src/glRenderer.cpp Sun May 08 13:25:12 2016 +0300 +++ b/src/glRenderer.cpp Sun May 08 15:26:58 2016 +0300 @@ -79,7 +79,7 @@ m_initialized (false) { m_isPicking = false; - m_camera = (ECamera) m_config->camera(); + m_camera = (Camera) m_config->camera(); m_drawToolTip = false; m_currentEditMode = AbstractEditMode::createByType (this, EditModeType::Select); m_panning = false; @@ -99,7 +99,7 @@ connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); // Init camera icons - for (ECamera cam = EFirstCamera; cam < ENumCameras; ++cam) + for (Camera cam = EFirstCamera; cam < ENumCameras; ++cam) { const char* cameraIconNames[ENumCameras] = { @@ -109,8 +109,8 @@ }; CameraIcon* info = &m_cameraIcons[cam]; - info->image = new QPixmap (GetIcon (cameraIconNames[cam])); - info->cam = cam; + info->image = GetIcon (cameraIconNames[cam]); + info->camera = cam; } calcCameraIcons(); @@ -141,12 +141,12 @@ for (CameraIcon& info : m_cameraIcons) { // MATH - int x1 = (m_width - (info.cam != EFreeCamera ? 48 : 16)) + ((i % 3) * 16) - 1; + int x1 = (m_width - (info.camera != EFreeCamera ? 48 : 16)) + ((i % 3) * 16) - 1; int y1 = ((i / 3) * 16) + 1; info.sourceRect = QRect (0, 0, 16, 16); info.targetRect = QRect (x1, y1, 16, 16); - info.selRect = QRect ( + info.hitRect = QRect ( info.targetRect.x(), info.targetRect.y(), info.targetRect.width() + 1, @@ -240,11 +240,11 @@ // void GLRenderer::resetAllAngles() { - ECamera oldcam = camera(); + Camera oldcam = camera(); for (int i = 0; i < 7; ++i) { - setCamera ((ECamera) i); + setCamera ((Camera) i); resetAngles(); } @@ -669,7 +669,7 @@ // Draw a background for the selected camera painter.setPen (m_thinBorderPen); painter.setBrush (QBrush (QColor (0, 128, 160, 128))); - painter.drawRect (m_cameraIcons[camera()].selRect); + painter.drawRect (m_cameraIcons[camera()].hitRect); // Draw the camera icons for (CameraIcon& info : m_cameraIcons) @@ -678,7 +678,7 @@ if (&info == &m_cameraIcons[EFreeCamera] and not m_currentEditMode->allowFreeCamera()) continue; - painter.drawPixmap (info.targetRect, *info.image, info.sourceRect); + painter.drawPixmap (info.targetRect, info.image, info.sourceRect); } // Draw a label for the current camera in the bottom left corner @@ -772,7 +772,7 @@ { if (info.targetRect.contains (ev->pos())) { - setCamera (info.cam); + setCamera (info.camera); goto end; } } @@ -907,7 +907,7 @@ // ============================================================================= // -void GLRenderer::setCamera (const ECamera camera) +void GLRenderer::setCamera (const Camera camera) { // The edit mode may forbid the free camera. if (m_currentEditMode->allowFreeCamera() or camera != EFreeCamera) @@ -1159,7 +1159,7 @@ { if (icon.targetRect.contains (m_mousePosition)) { - m_toolTipCamera = icon.cam; + m_toolTipCamera = icon.camera; m_drawToolTip = true; update(); break; @@ -1169,9 +1169,9 @@ // ============================================================================= // -Axis GLRenderer::getCameraAxis (bool y, ECamera camid) +Axis GLRenderer::getCameraAxis (bool y, Camera camid) { - if (camid == (ECamera) -1) + if (camid == (Camera) -1) camid = camera(); const LDFixedCamera* cam = &g_FixedCameras[camid]; @@ -1180,7 +1180,7 @@ // ============================================================================= // -bool GLRenderer::setupOverlay (ECamera camera, QString fileName, int x, int y, int w, int h) +bool GLRenderer::setupOverlay (Camera camera, QString fileName, int x, int y, int w, int h) { QImage* image = new QImage (QImage (fileName).convertToFormat (QImage::Format_ARGB32)); LDGLOverlay& info = getOverlay (camera); @@ -1265,7 +1265,7 @@ // ============================================================================= // -QString GLRenderer::cameraName (ECamera camera) const +QString GLRenderer::cameraName (Camera camera) const { switch (camera) { @@ -1408,7 +1408,7 @@ // ============================================================================= // -LDOverlay* GLRenderer::findOverlayObject (ECamera cam) +LDOverlay* GLRenderer::findOverlayObject (Camera cam) { for (LDObject* obj : document()->objects()) { @@ -1427,7 +1427,7 @@ // void GLRenderer::initOverlaysFromObjects() { - for (ECamera camera = EFirstCamera; camera < ENumCameras; ++camera) + for (Camera camera = EFirstCamera; camera < ENumCameras; ++camera) { if (camera == EFreeCamera) continue; @@ -1456,7 +1456,7 @@ // void GLRenderer::updateOverlayObjects() { - for (ECamera cam = EFirstCamera; cam < ENumCameras; ++cam) + for (Camera cam = EFirstCamera; cam < ENumCameras; ++cam) { if (cam == EFreeCamera) continue; @@ -1604,9 +1604,12 @@ return m_position3D; } -const LDFixedCamera& GLRenderer::getFixedCamera (ECamera cam) const +const LDFixedCamera& GLRenderer::cameraInfo (Camera camera) const { - return g_FixedCameras[cam]; + if (camera >= EFirstCamera and camera <= ELastFixedCamera) + return g_FixedCameras[camera]; + else + return g_FixedCameras[0]; } bool GLRenderer::mouseHasMoved() const @@ -1640,7 +1643,7 @@ return m_currentKeyboardModifiers; } -ECamera GLRenderer::camera() const +Camera GLRenderer::camera() const { return m_camera; } @@ -1688,16 +1691,3 @@ { delete image; } - - -// -// --------------------------------------------------------------------------------------------------------------------- -// - -CameraIcon::CameraIcon() : - image(nullptr) {} - -CameraIcon::~CameraIcon() -{ - delete image; -}
--- a/src/glRenderer.h Sun May 08 13:25:12 2016 +0300 +++ b/src/glRenderer.h Sun May 08 15:26:58 2016 +0300 @@ -103,7 +103,7 @@ } }; -enum ECamera +enum Camera { ETopCamera, EFrontCamera, @@ -114,27 +114,19 @@ EFreeCamera, ENumCameras, + ELastFixedCamera = ERightCamera, EFirstCamera = ETopCamera }; -MAKE_ITERABLE_ENUM (ECamera) - +MAKE_ITERABLE_ENUM(Camera, ETopCamera, EFreeCamera) -// CameraIcon::image 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. -// -// TODO: maybe this then shouldn't get allocated before the program gets to main(). struct CameraIcon { - CameraIcon(); - ~CameraIcon(); - - QPixmap* image; - QRect sourceRect; - QRect targetRect; - QRect selRect; - ECamera cam; + QPixmap image; + QRect sourceRect; + QRect targetRect; + QRect hitRect; + Camera camera; }; // The main renderer object, draws the brick on the screen, manages the camera and selection picking. @@ -146,8 +138,8 @@ GLRenderer (QWidget* parent = nullptr); ~GLRenderer(); - ECamera camera() const; - QString cameraName (ECamera camera) const; + Camera camera() const; + QString cameraName (Camera camera) const; QByteArray capturePixels(); void clearOverlay(); void compileObject (LDObject* obj); @@ -163,9 +155,9 @@ void drawBlipCoordinates (QPainter& painter, const Vertex& pos3d, QPointF pos); void drawGLScene(); void forgetObject (LDObject* obj); - Axis getCameraAxis (bool y, ECamera camid = (ECamera) -1); + Axis getCameraAxis (bool y, Camera camid = (Camera) -1); double getDepthValue() const; - const LDFixedCamera& getFixedCamera (ECamera cam) const; + const LDFixedCamera& cameraInfo (Camera camera) const; LDGLOverlay& getOverlay (int newcam); void getRelativeAxes (Axis& relX, Axis& relY) const; Axis getRelativeZ() const; @@ -192,13 +184,13 @@ void resetAllAngles(); void resetAngles(); void setBackground(); - void setCamera (const ECamera cam); + void setCamera (const Camera cam); void setDepthValue (double depth); void setDocument (LDDocument* document); void setDrawOnly (bool value); void setEditMode (EditModeType type); void setPicking (bool a); - bool setupOverlay (ECamera camera, QString fileName, int x, int y, int w, int h); + bool setupOverlay (Camera camera, QString fileName, int x, int y, int w, int h); QPen textPen() const; void updateOverlayObjects(); void zoomNotch (bool inward); @@ -244,8 +236,8 @@ QPoint m_globalpos; QPointF m_mousePositionF; QPen m_thinBorderPen; - ECamera m_camera; - ECamera m_toolTipCamera; + Camera m_camera; + Camera m_toolTipCamera; GLuint m_axeslist; int m_width; int m_height; @@ -259,7 +251,7 @@ void clampAngle (double& angle) const; LDGLData& currentDocumentData() const; void drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type); - LDOverlay* findOverlayObject (ECamera cam); + LDOverlay* findOverlayObject (Camera cam); double& panning (Axis ax); double panning (Axis ax) const; double& rotation (Axis ax);
--- a/src/glShared.h Sun May 08 13:25:12 2016 +0300 +++ b/src/glShared.h Sun May 08 15:26:58 2016 +0300 @@ -49,6 +49,8 @@ FirstSurfaceVbo = LinesVbo }; +MAKE_ITERABLE_ENUM (SurfaceVboType, LinesVbo, ConditionalLinesVbo) + enum ComplementVboType { SurfacesVboComplement, @@ -62,14 +64,13 @@ FirstVboComplement = SurfacesVboComplement }; +MAKE_ITERABLE_ENUM (ComplementVboType, SurfacesVboComplement, RandomColorsVboComplement) + enum { - NumVbos = NumSurfaceVbos * NumVboComplements + NumVbos = EnumLimits::SurfaceVboType::Count * EnumLimits::ComplementVboType::Count, }; -MAKE_ITERABLE_ENUM (SurfaceVboType) -MAKE_ITERABLE_ENUM (ComplementVboType) - #ifndef USE_QT5 // Placeholder QOpenGLFunctions for Qt 4.x support struct QOpenGLFunctions
--- a/src/ldObject.h Sun May 08 13:25:12 2016 +0300 +++ b/src/ldObject.h Sun May 08 15:26:58 2016 +0300 @@ -78,7 +78,7 @@ OBJ_FirstType = OBJ_SubfileReference }; -MAKE_ITERABLE_ENUM (LDObjectType) +MAKE_ITERABLE_ENUM (LDObjectType, OBJ_SubfileReference, OBJ_BezierCurve) // // LDObject
--- a/src/macros.h Sun May 08 13:25:12 2016 +0300 +++ b/src/macros.h Sun May 08 15:26:58 2016 +0300 @@ -43,7 +43,8 @@ #define dvalof(A) dprint ("value of '%1' = %2\n", #A, A) #define for_axes(AX) for (const Axis AX : std::initializer_list<const Axis> ({X, Y, Z})) -#define MAKE_ITERABLE_ENUM(T) \ +#define MAKE_ITERABLE_ENUM(T, FIRST, LAST) \ + namespace EnumLimits { namespace T { enum { First = FIRST, Last = LAST, Count = LAST - FIRST + 1 }; } } \ inline T operator++ (T& a) { a = (T) ((int) a + 1); return a; } \ inline T operator-- (T& a) { a = (T) ((int) a - 1); return a; } \ inline T operator++ (T& a, int) { T result = a; a = (T) ((int) a + 1); return result; } \
--- a/src/mainwindow.cpp Sun May 08 13:25:12 2016 +0300 +++ b/src/mainwindow.cpp Sun May 08 15:26:58 2016 +0300 @@ -450,7 +450,7 @@ case OBJ_Overlay: { LDOverlay* ovl = static_cast<LDOverlay*> (obj); - descr = format ("[%1] %2 (%3, %4), %5 x %6", renderer()->cameraName ((ECamera) ovl->camera()), + descr = format ("[%1] %2 (%3, %4), %5 x %6", renderer()->cameraName ((Camera) ovl->camera()), Basename (ovl->fileName()), ovl->x(), ovl->y(), ovl->width(), ovl->height()); break;
--- a/src/toolsets/viewtoolset.cpp Sun May 08 13:25:12 2016 +0300 +++ b/src/toolsets/viewtoolset.cpp Sun May 08 15:26:58 2016 +0300 @@ -162,7 +162,7 @@ if (not dlg.exec()) return; - m_window->renderer()->setupOverlay ((ECamera) dlg.camera(), dlg.fpath(), dlg.ofsx(), + m_window->renderer()->setupOverlay ((Camera) dlg.camera(), dlg.fpath(), dlg.ofsx(), dlg.ofsy(), dlg.lwidth(), dlg.lheight()); }