Tue, 14 Feb 2017 08:08:17 +0200
Moved camera names to GLCamera, other adjustments
--- a/src/editmodes/abstractEditMode.cpp Tue Feb 14 07:57:27 2017 +0200 +++ b/src/editmodes/abstractEditMode.cpp Tue Feb 14 08:08:17 2017 +0200 @@ -124,7 +124,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()->cameraInfo(renderer()->camera()).negatedDepth) + if (renderer()->currentCamera().isAxisNegated(Z)) return a[depthAxis] > b[depthAxis]; else return a[depthAxis] < b[depthAxis];
--- a/src/glRenderer.cpp Tue Feb 14 07:57:27 2017 +0200 +++ b/src/glRenderer.cpp Tue Feb 14 08:08:17 2017 +0200 @@ -35,17 +35,6 @@ #include "documentmanager.h" #include "grid.h" -const CameraInfo g_cameraInfo[EnumLimits<Camera>::Count] = -{ - {{ 1, 0, 0 }, X, Z, false, false, false }, // top - {{ 0, 0, 0 }, X, Y, false, true, false }, // front - {{ 0, 1, 0 }, Z, Y, true, true, false }, // left - {{ -1, 0, 0 }, X, Z, false, true, true }, // bottom - {{ 0, 0, 0 }, X, Y, true, true, true }, // back - {{ 0, -1, 0 }, Z, Y, false, true, true }, // right - {{ 1, 0, 0 }, X, Z, false, false, false }, // free (defensive dummy data) -}; - const QPen GLRenderer::thinBorderPen {QColor {0, 0, 0, 208}, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin}; // ============================================================================= @@ -55,13 +44,13 @@ HierarchyElement {parent}, m_model {model}, m_cameras { - {1, 0, 0, X, Z, false, false, false}, // top - {0, 0, 0, X, Y, false, true, false}, // front - {0, 1, 0, Z, Y, true, true, false}, // left - {-1, 0, 0, X, Z, false, true, true}, // bottom - {0, 0, 0, X, Y, true, true, true}, // back - {0, -1, 0, Z, Y, false, true, true}, // right - {GLCamera::FreeCamera}, // free + {"Top camera", {1, 0, 0, X, Z, false, false, false}}, // top + {"Front camera", {0, 0, 0, X, Y, false, true, false}}, // front + {"Left camera", {0, 1, 0, Z, Y, true, true, false}}, // left + {"Bottom camera", {-1, 0, 0, X, Z, false, true, true}}, // bottom + {"Back camera", {0, 0, 0, X, Y, true, true, true}}, // back + {"Right camera", {0, -1, 0, Z, Y, false, true, true}}, // right + {"Free camera", GLCamera::FreeCamera}, // free } { m_camera = (Camera) m_config->camera(); @@ -571,7 +560,7 @@ if (not m_cameraIcons[static_cast<int>(m_toolTipCamera)].targetRect.contains (m_mousePosition)) m_drawToolTip = false; else - QToolTip::showText(m_globalpos, currentCameraName()); + QToolTip::showText(m_globalpos, m_cameras[static_cast<int>(m_toolTipCamera)].name()); } // Draw a label for the current camera in the bottom left corner @@ -579,7 +568,7 @@ QFontMetrics metrics {QFont {}}; int margin = 4; painter.setPen(textPen()); - painter.drawText(QPoint {margin, height() - margin - metrics.descent()}, currentCameraName()); + painter.drawText(QPoint {margin, height() - margin - metrics.descent()}, currentCamera().name()); } } @@ -851,30 +840,6 @@ // ============================================================================= // -QString GLRenderer::cameraName (Camera camera) const -{ - switch (camera) - { - case Camera::Top: return tr ("Top Camera"); - case Camera::Front: return tr ("Front Camera"); - case Camera::Left: return tr ("Left Camera"); - case Camera::Bottom: return tr ("Bottom Camera"); - case Camera::Back: return tr ("Back Camera"); - case Camera::Right: return tr ("Right Camera"); - case Camera::Free: return tr ("Free Camera"); - default: break; - } - - return ""; -} - -QString GLRenderer::currentCameraName() const -{ - return cameraName (camera()); -} - -// ============================================================================= -// void GLRenderer::zoomToFit() { currentCamera().setZoom(30.0f); @@ -1009,14 +974,6 @@ update(); } -const CameraInfo& GLRenderer::cameraInfo (Camera camera) const -{ - if (valueInEnum<Camera>(camera)) - return g_cameraInfo[static_cast<int>(camera)]; - else - return g_cameraInfo[0]; -} - bool GLRenderer::mouseHasMoved() const { return m_totalMouseMove >= 10;
--- a/src/glRenderer.h Tue Feb 14 07:57:27 2017 +0200 +++ b/src/glRenderer.h Tue Feb 14 08:08:17 2017 +0200 @@ -79,13 +79,10 @@ QColor backgroundColor() const; Camera camera() const; - const CameraInfo& cameraInfo(Camera camera) const; - QString cameraName(Camera camera) const; QByteArray capturePixels(); GLCompiler* compiler() const; GLCamera& currentCamera(); const GLCamera& currentCamera() const; - QString currentCameraName() const; void drawGLScene(); void forgetObject(LDObject* obj); void highlightCursorObject();
--- a/src/glcamera.cpp Tue Feb 14 07:57:27 2017 +0200 +++ b/src/glcamera.cpp Tue Feb 14 08:08:17 2017 +0200 @@ -23,18 +23,20 @@ /* * Constructs a fixed camera from parameters. */ -GLCamera::GLCamera(int glRotateX, int glRotateY, int glRotateZ, Axis localX, Axis localY, bool negatedX, bool negatedY, bool negatedDepth) : - m_glrotate {glRotateX, glRotateY, glRotateZ}, - m_localX {localX}, - m_localY {localY}, - m_negatedX {negatedX}, - m_negatedY {negatedY}, - m_negatedDepth {negatedDepth} {} +GLCamera::GLCamera(QString name, FixedCameraParameters&& bag) : + m_name {name}, + m_glrotate {bag.glRotateX, bag.glRotateY, bag.glRotateZ}, + m_localX {bag.localX}, + m_localY {bag.localY}, + m_negatedX {bag.negatedX}, + m_negatedY {bag.negatedY}, + m_negatedDepth {bag.negatedZ} {} /* * Constructs a free camera. */ -GLCamera::GLCamera(FreeToken) : +GLCamera::GLCamera(QString name, FreeToken) : + m_name {name}, m_isFree {true} {} /* @@ -232,3 +234,11 @@ m_zoom = zoom; rendererResized(m_size.width(), m_size.height()); } + +/* + * Returns the name of the camera + */ +const QString& GLCamera::name() const +{ + return m_name; +}
--- a/src/glcamera.h Tue Feb 14 07:57:27 2017 +0200 +++ b/src/glcamera.h Tue Feb 14 08:08:17 2017 +0200 @@ -19,6 +19,18 @@ #pragma once #include "main.h" +struct FixedCameraParameters +{ + int glRotateX; + int glRotateY; + int glRotateZ; + Axis localX; + Axis localY; + bool negatedX; + bool negatedY; + bool negatedZ; +}; + /* * Models a 2D x/y co-ordinate system that maps to a fixed camera position. * Owns camera orientation information and provides 2Dāā3D translation. @@ -31,28 +43,30 @@ // This is used to construct the free camera enum FreeToken { FreeCamera }; - GLCamera(int glRotateX, int glRotateY, int glRotateZ, Axis localX, Axis localY, bool negatedX, bool negatedY, bool negatedDepth); - GLCamera(FreeToken); + GLCamera(QString name, FixedCameraParameters&& bag); + GLCamera(QString name, FreeToken); Axis axisX() const; Axis axisY() const; Axis axisZ() const; + Vertex convert2dTo3d(const QPoint& pos2d, Grid* grid = nullptr) const; + QPoint convert3dTo2d(const Vertex& pos3d) const; double depth() const; int glRotate(Axis axis) const; bool isAxisNegated(Axis axis) const; - Q_SLOT void rendererResized(int width, int height); - const QSizeF& virtualSize() const; - Vertex convert2dTo3d(const QPoint& pos2d, Grid* grid = nullptr) const; - QPoint convert3dTo2d(const Vertex& pos3d) const; + const QString& name() const; + void pan(int xMove, int yMove); double panningX() const; double panningY() const; - double zoom() const; + Q_SLOT void rendererResized(int width, int height); void setPanning(double x, double y); - void pan(int xMove, int yMove); + void setZoom(double zoom); + const QSizeF& virtualSize() const; + double zoom() const; void zoomNotch(bool inward); - void setZoom(double zoom); private: + QString m_name; double m_panningX = 0; double m_panningY = 0; double m_depth = 0;
--- a/src/toolsets/viewtoolset.cpp Tue Feb 14 07:57:27 2017 +0200 +++ b/src/toolsets/viewtoolset.cpp Tue Feb 14 08:08:17 2017 +0200 @@ -166,9 +166,9 @@ return; bool ok; - double depth = QInputDialog::getDouble (m_window, "Set Draw Depth", - format ("Depth value for %1:", m_window->renderer()->currentCameraName()), - m_window->renderer()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok); + double depth = QInputDialog::getDouble(m_window, "Set Draw Depth", + format("Depth value for %1:", m_window->renderer()->currentCamera().name()), + m_window->renderer()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok); if (ok) m_window->renderer()->setDepthValue (depth);