Sun, 12 Jan 2014 23:38:40 +0200
- GL-variables that should be document-specific are now properly document-specific (i.e. pan and zoom won't be shared across documents anymore)
src/document.cc | file | annotate | diff | comparison | revisions | |
src/document.h | file | annotate | diff | comparison | revisions | |
src/gldraw.cc | file | annotate | diff | comparison | revisions | |
src/gldraw.h | file | annotate | diff | comparison | revisions |
--- a/src/document.cc Sun Jan 12 23:12:55 2014 +0200 +++ b/src/document.cc Sun Jan 12 23:38:40 2014 +0200 @@ -120,7 +120,8 @@ // ============================================================================= // ----------------------------------------------------------------------------- -LDDocument::LDDocument() +LDDocument::LDDocument() : + m_gldata (new LDGLData) { setImplicit (true); setSavePosition (-1); @@ -148,6 +149,7 @@ obj->deleteSelf(); delete m_History; + delete m_gldata; // If we just closed the current file, we need to set the current // file as something else. @@ -1281,7 +1283,7 @@ // Sets the given file as the current one on display. At some point in time this // was an operation completely unheard of. ;) // -// FIXME: f can be temporarily null. This probably should not be the case. +// TODO: f can be temporarily null. This probably should not be the case. // ----------------------------------------------------------------------------- void LDDocument::setCurrent (LDDocument* f) { @@ -1299,7 +1301,6 @@ g_win->buildObjList(); g_win->updateTitle(); g_win->R()->setFile (f); - g_win->R()->resetAllAngles(); g_win->R()->repaint(); log ("Changed file to %1", f->getDisplayName()); }
--- a/src/document.h Sun Jan 12 23:12:55 2014 +0200 +++ b/src/document.h Sun Jan 12 23:38:40 2014 +0200 @@ -19,14 +19,15 @@ #ifndef LDFORGE_DOCUMENT_H #define LDFORGE_DOCUMENT_H +#include <QObject> #include "main.h" #include "ldtypes.h" #include "history.h" -#include <QObject> class History; class OpenProgressDialog; class LDDocumentPointer; +struct LDGLData; namespace LDPaths { @@ -133,16 +134,24 @@ protected: void addToSelection (LDObject* obj); void removeFromSelection (LDObject* obj); + + LDGLData* getGLData() + { + return m_gldata; + } + friend class LDObject; + friend class GLRenderer; private: LDObjectList m_sel; + LDGLData* m_gldata; // If set to true, next inline of this document discards the cache and // re-builds it. - bool m_needsCache; + bool m_needsCache; - static LDDocument* m_curdoc; + static LDDocument* m_curdoc; }; inline LDDocument* getCurrentDocument()
--- a/src/gldraw.cc Sun Jan 12 23:12:55 2014 +0200 +++ b/src/gldraw.cc Sun Jan 12 23:38:40 2014 +0200 @@ -146,12 +146,6 @@ info->cam = cam; } - for (int i = 0; i < 6; ++i) - { - m_overlays[i].img = null; - m_depthValues[i] = 0.0f; - } - calcCameraIcons(); } @@ -160,7 +154,7 @@ GLRenderer::~GLRenderer() { for (int i = 0; i < 6; ++i) - delete m_overlays[i].img; + delete currentDocumentData().overlays[i].img; for (CameraIcon& info : m_cameraIcons) delete info.img; @@ -605,12 +599,12 @@ if (m_camera != EFreeCamera && !isPicking()) { // Paint the overlay image if we have one - const LDGLOverlay& overlay = m_overlays[m_camera]; + const LDGLOverlay& overlay = currentDocumentData().overlays[m_camera]; if (overlay.img != null) { - QPoint v0 = coordconv3_2 (m_overlays[m_camera].v0), - v1 = coordconv3_2 (m_overlays[m_camera].v1); + QPoint v0 = coordconv3_2 (currentDocumentData().overlays[m_camera].v0), + v1 = coordconv3_2 (currentDocumentData().overlays[m_camera].v1); QRect targRect (v0.x(), v0.y(), abs (v1.x() - v0.x()), abs (v1.y() - v0.y())), srcRect (0, 0, overlay.img->width(), overlay.img->height()); @@ -1434,7 +1428,7 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- +// void GLRenderer::setEditMode (EditMode const& a) { m_EditMode = a; @@ -1477,16 +1471,26 @@ update(); } +// ============================================================================= +// void GLRenderer::setFile (LDDocument* const& a) { m_File = a; if (a != null) + { initOverlaysFromObjects(); + + if (currentDocumentData().init == false) + { + resetAllAngles(); + currentDocumentData().init = true; + } + } } // ============================================================================= -// ----------------------------------------------------------------------------- +// Matrix GLRenderer::getCircleDrawMatrix (double scale) { Matrix transform = g_circleDrawTransforms[camera() % 3]; @@ -1503,7 +1507,7 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- +// void GLRenderer::endDraw (bool accept) { (void) accept; @@ -1889,7 +1893,7 @@ if (camera() == EFreeCamera) return; - LDGLOverlay& info = m_overlays[camera()]; + LDGLOverlay& info = currentDocumentData().overlays[camera()]; delete info.img; info.img = null; @@ -1901,7 +1905,7 @@ void GLRenderer::setDepthValue (double depth) { assert (camera() < EFreeCamera); - m_depthValues[camera()] = depth; + currentDocumentData().depthValues[camera()] = depth; } // ============================================================================= @@ -1909,7 +1913,7 @@ double GLRenderer::getDepthValue() const { assert (camera() < EFreeCamera); - return m_depthValues[camera()]; + return currentDocumentData().depthValues[camera()]; } // ============================================================================= @@ -1923,7 +1927,7 @@ // ----------------------------------------------------------------------------- LDGLOverlay& GLRenderer::getOverlay (int newcam) { - return m_overlays[newcam]; + return currentDocumentData().overlays[newcam]; } // ============================================================================= @@ -2123,7 +2127,7 @@ if (cam == EFreeCamera) continue; - LDGLOverlay& meta = m_overlays[cam]; + LDGLOverlay& meta = currentDocumentData().overlays[cam]; LDOverlay* ovlobj = findOverlayObject (cam); if (!ovlobj && meta.img) @@ -2145,7 +2149,7 @@ if (cam == EFreeCamera) continue; - LDGLOverlay& meta = m_overlays[cam]; + LDGLOverlay& meta = currentDocumentData().overlays[cam]; LDOverlay* ovlobj = findOverlayObject (cam); if (!meta.img && ovlobj)
--- a/src/gldraw.h Sun Jan 12 23:12:55 2014 +0200 +++ b/src/gldraw.h Sun Jan 12 23:38:40 2014 +0200 @@ -22,6 +22,7 @@ #include <QGLWidget> #include "main.h" #include "ldtypes.h" +#include "document.h" class MessageManager; class QDialogButtonBox; @@ -29,7 +30,6 @@ class QDoubleSpinBox; class QSpinBox; class QLineEdit; -class LDDocument; class QTimer; enum EditMode @@ -42,30 +42,57 @@ // Meta for overlays struct LDGLOverlay { - Vertex v0, - v1; - int ox, - oy; - double lw, - lh; - QString fname; - QImage* img; + Vertex v0, + v1; + int ox, + oy; + double lw, + lh; + QString fname; + QImage* img; }; struct LDFixedCameraInfo { - const char glrotate[3]; - const Axis axisX, axisY; - const bool negX, negY; + const char glrotate[3]; + const Axis axisX, + axisY; + const bool negX, + negY; }; // ============================================================================= -// GLRenderer +// Document-specific data // +struct LDGLData +{ + double rotX, + rotY, + rotZ, + panX[7], + panY[7], + zoom[7]; + double depthValues[6]; + LDGLOverlay overlays[6]; + bool init; + + LDGLData() + { + for (int i = 0; i < 6; ++i) + { + overlays[i].img = null; + depthValues[i] = 0.0f; + } + + init = false; + } +}; + +// ============================================================================= // The main renderer object, draws the brick on the screen, manages the camera // and selection picking. The instance of GLRenderer is accessible as // g_win->R() -// ============================================================================= +// class GLRenderer : public QGLWidget { typedefs: @@ -166,13 +193,7 @@ Qt::KeyboardModifiers m_keymods; Vertex m_hoverpos; double m_virtWidth, - m_virtHeight, - m_rotX[7], - m_rotY[7], - m_rotZ[7], - m_panX[7], - m_panY[7], - m_zoom[7]; + m_virtHeight; bool m_darkbg, m_rangepick, m_addpick, @@ -194,8 +215,6 @@ bool m_rectdraw; Vertex m_rectverts[4]; QColor m_bgcolor; - double m_depthValues[6]; - LDGLOverlay m_overlays[6]; QList<Vertex> m_knownVerts; void addDrawnVertex (Vertex m_hoverpos); @@ -235,31 +254,38 @@ // Set the color to an object list void setObjectColor (LDObject* obj, const ListType list); + LDGLData& currentDocumentData() const + { + return *getFile()->getGLData(); + } + // Get a rotation value inline double& rot (Axis ax) { return - (ax == X) ? m_rotX[camera()] : - (ax == Y) ? m_rotY[camera()] : - m_rotZ[camera()]; + (ax == X) ? currentDocumentData().rotX : + (ax == Y) ? currentDocumentData().rotY : + currentDocumentData().rotZ; } // Get a panning value inline double& pan (Axis ax) { - return (ax == X) ? m_panX[camera()] : m_panY[camera()]; + return (ax == X) ? currentDocumentData().panX[camera()] : + currentDocumentData().panY[camera()]; } // Same except const (can be used in const methods) inline const double& pan (Axis ax) const { - return (ax == X) ? m_panX[camera()] : m_panY[camera()]; + return (ax == X) ? currentDocumentData().panX[camera()] : + currentDocumentData().panY[camera()]; } // Get the zoom value inline double& zoom() { - return m_zoom[camera()]; + return currentDocumentData().zoom[camera()]; } private slots: