--- a/src/glRenderer.cpp Thu Jan 04 19:40:52 2018 +0200 +++ b/src/glRenderer.cpp Thu Jan 04 19:44:26 2018 +0200 @@ -52,50 +52,50 @@ {{ 0, -1, 0 }, Z, Y, false, true, true }, // right }; -ConfigOption (QColor BackgroundColor = "#FFFFFF") -ConfigOption (QColor MainColor = "#A0A0A0") -ConfigOption (float MainColorAlpha = 1.0) -ConfigOption (int LineThickness = 2) -ConfigOption (bool BfcRedGreenView = false) -ConfigOption (int Camera = 6) -ConfigOption (bool BlackEdges = false) -ConfigOption (bool DrawAxes = false) -ConfigOption (bool DrawWireframe = false) -ConfigOption (bool UseLogoStuds = false) -ConfigOption (bool AntiAliasedLines = true) -ConfigOption (bool RandomColors = false) -ConfigOption (bool HighlightObjectBelowCursor = true) -ConfigOption (bool DrawSurfaces = true) -ConfigOption (bool DrawEdgeLines = true) -ConfigOption (bool DrawConditionalLines = true) +ConfigOption(QColor BackgroundColor = "#FFFFFF") +ConfigOption(QColor MainColor = "#A0A0A0") +ConfigOption(float MainColorAlpha = 1.0) +ConfigOption(int LineThickness = 2) +ConfigOption(bool BfcRedGreenView = false) +ConfigOption(int Camera = 6) +ConfigOption(bool BlackEdges = false) +ConfigOption(bool DrawAxes = false) +ConfigOption(bool DrawWireframe = false) +ConfigOption(bool UseLogoStuds = false) +ConfigOption(bool AntiAliasedLines = true) +ConfigOption(bool RandomColors = false) +ConfigOption(bool HighlightObjectBelowCursor = true) +ConfigOption(bool DrawSurfaces = true) +ConfigOption(bool DrawEdgeLines = true) +ConfigOption(bool DrawConditionalLines = true) // ============================================================================= // -GLRenderer::GLRenderer (QWidget* parent) : - QGLWidget (parent), - HierarchyElement (parent), - m_document (nullptr), - m_initialized (false) +GLRenderer::GLRenderer(QWidget* parent) : + QGLWidget(parent), + HierarchyElement(parent), + m_document(nullptr), + m_initialized(false) { m_isPicking = false; m_camera = (ECamera) config.camera(); m_drawToolTip = false; - m_currentEditMode = AbstractEditMode::createByType (this, EditModeType::Select); + m_currentEditMode = AbstractEditMode::createByType(this, EditModeType::Select); m_panning = false; - m_compiler = new GLCompiler (this); + m_compiler = new GLCompiler(this); m_objectAtCursor = nullptr; - setDrawOnly (false); - m_messageLog = new MessageManager (this); - m_messageLog->setRenderer (this); + setDrawOnly(false); + m_messageLog = new MessageManager(this); + m_messageLog->setRenderer(this); m_width = m_height = -1; m_position3D = Origin; - m_toolTipTimer = new QTimer (this); - m_toolTipTimer->setSingleShot (true); + m_toolTipTimer = new QTimer(this); + m_toolTipTimer->setSingleShot(true); m_isCameraMoving = false; - m_thinBorderPen = QPen (QColor (0, 0, 0, 208), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); - m_thinBorderPen.setWidth (1); - setAcceptDrops (true); - connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); + m_thinBorderPen = QPen(QColor(0, 0, 0, 208), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + m_thinBorderPen.setWidth(1); + setAcceptDrops(true); + connect(m_toolTipTimer, SIGNAL(timeout()), this, SLOT(slot_toolTipTimer())); // Init camera icons for (ECamera cam = EFirstCamera; cam < ENumCameras; ++cam) @@ -108,7 +108,7 @@ }; CameraIcon* info = &m_cameraIcons[cam]; - info->image = new QPixmap (GetIcon (cameraIconNames[cam])); + info->image = new QPixmap(GetIcon(cameraIconNames[cam])); info->cam = cam; } @@ -119,20 +119,20 @@ // GLRenderer::~GLRenderer() { - for (int i = 0; i < countof (currentDocumentData().overlays); ++i) + for (int i = 0; i < countof(currentDocumentData().overlays); ++i) delete currentDocumentData().overlays[i].img; for (CameraIcon& info : m_cameraIcons) delete info.image; if (messageLog()) - messageLog()->setRenderer (nullptr); + messageLog()->setRenderer(nullptr); - m_compiler->setRenderer (nullptr); + m_compiler->setRenderer(nullptr); delete m_compiler; delete m_currentEditMode; - glDeleteBuffers (1, &m_axesVbo); - glDeleteBuffers (1, &m_axesColorVbo); + glDeleteBuffers(1, &m_axesVbo); + glDeleteBuffers(1, &m_axesColorVbo); } // ============================================================================= @@ -146,12 +146,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.cam != 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.sourceRect = QRect(0, 0, 16, 16); + info.targetRect = QRect(x1, y1, 16, 16); + info.selRect = QRect( info.targetRect.x(), info.targetRect.y(), info.targetRect.width() + 1, @@ -166,25 +166,25 @@ // void GLRenderer::initGLData() { - glEnable (GL_BLEND); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable (GL_POLYGON_OFFSET_FILL); - glPolygonOffset (1.0f, 1.0f); - glEnable (GL_DEPTH_TEST); - glShadeModel (GL_SMOOTH); - glEnable (GL_MULTISAMPLE); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(1.0f, 1.0f); + glEnable(GL_DEPTH_TEST); + glShadeModel(GL_SMOOTH); + glEnable(GL_MULTISAMPLE); if (config.antiAliasedLines()) { - glEnable (GL_LINE_SMOOTH); - glEnable (GL_POLYGON_SMOOTH); - glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); - glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); + glEnable(GL_LINE_SMOOTH); + glEnable(GL_POLYGON_SMOOTH); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); } else { - glDisable (GL_LINE_SMOOTH); - glDisable (GL_POLYGON_SMOOTH); + glDisable(GL_LINE_SMOOTH); + glDisable(GL_POLYGON_SMOOTH); } } @@ -193,7 +193,7 @@ return m_isDrawOnly; } -void GLRenderer::setDrawOnly (bool value) +void GLRenderer::setDrawOnly(bool value) { m_isDrawOnly = value; } @@ -235,9 +235,9 @@ // void GLRenderer::resetAngles() { - rotation (X) = 30.0f; - rotation (Y) = 325.f; - panning (X) = panning (Y) = rotation (Z) = 0.0f; + rotation(X) = 30.0f; + rotation(Y) = 325.f; + panning(X) = panning(Y) = rotation(Z) = 0.0f; needZoomToFit(); } @@ -249,11 +249,11 @@ for (int i = 0; i < 7; ++i) { - setCamera ((ECamera) i); + setCamera((ECamera) i); resetAngles(); } - setCamera (oldcam); + setCamera(oldcam); } // ============================================================================= @@ -264,11 +264,11 @@ initializeOpenGLFunctions(); #endif setBackground(); - glLineWidth (config.lineThickness()); - glLineStipple (1, 0x6666); - setAutoFillBackground (false); - setMouseTracking (true); - setFocusPolicy (Qt::WheelFocus); + glLineWidth(config.lineThickness()); + glLineStipple(1, 0x6666); + setAutoFillBackground(false); + setMouseTracking(true); + setFocusPolicy(Qt::WheelFocus); compiler()->initialize(); initializeAxes(); m_initialized = true; @@ -287,20 +287,20 @@ static const AxisInfo axisinfo[3] = { - { QColor (192, 96, 96), Vertex (10000, 0, 0) }, // X - { QColor (48, 192, 48), Vertex (0, 10000, 0) }, // Y - { QColor (48, 112, 192), Vertex (0, 0, 10000) }, // Z + { QColor(192, 96, 96), Vertex(10000, 0, 0) }, // X + { QColor(48, 192, 48), Vertex(0, 10000, 0) }, // Y + { QColor(48, 112, 192), Vertex(0, 0, 10000) }, // Z }; float axisdata[18]; float colordata[18]; - memset (axisdata, 0, sizeof axisdata); + memset(axisdata, 0, sizeof axisdata); for (int i = 0; i < 3; ++i) { const AxisInfo& data = axisinfo[i]; - for_axes (ax) + for_axes(ax) { axisdata[(i * 6) + ax] = data.extrema[ax]; axisdata[(i * 6) + 3 + ax] = -data.extrema[ax]; @@ -312,13 +312,13 @@ colordata[offset + 2] = colordata[offset + 5] = data.color.blue(); } - glGenBuffers (1, &m_axesVbo); - glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo); - glBufferData (GL_ARRAY_BUFFER, sizeof axisdata, axisdata, GL_STATIC_DRAW); - glGenBuffers (1, &m_axesColorVbo); - glBindBuffer (GL_ARRAY_BUFFER, m_axesColorVbo); - glBufferData (GL_ARRAY_BUFFER, sizeof colordata, colordata, GL_STATIC_DRAW); - glBindBuffer (GL_ARRAY_BUFFER, 0); + glGenBuffers(1, &m_axesVbo); + glBindBuffer(GL_ARRAY_BUFFER, m_axesVbo); + glBufferData(GL_ARRAY_BUFFER, sizeof axisdata, axisdata, GL_STATIC_DRAW); + glGenBuffers(1, &m_axesColorVbo); + glBindBuffer(GL_ARRAY_BUFFER, m_axesColorVbo); + glBufferData(GL_ARRAY_BUFFER, sizeof colordata, colordata, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); } // ============================================================================= @@ -327,7 +327,7 @@ { if (isPicking()) { - glClearColor (0.0f, 0.0f, 0.0f, 1.0f); + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); return; } @@ -336,10 +336,10 @@ if (not color.isValid()) return; - color.setAlpha (255); - m_useDarkBackground = luma (color) < 80; + color.setAlpha(255); + m_useDarkBackground = luma(color) < 80; m_backgroundColor = color; - qglClearColor (color); + qglClearColor(color); } // ============================================================================= @@ -358,25 +358,25 @@ { if (m_initialized) { - compiler()->compileDocument (currentDocument()); + compiler()->compileDocument(currentDocument()); refresh(); } } // ============================================================================= // -void GLRenderer::resizeGL (int w, int h) +void GLRenderer::resizeGL(int w, int h) { m_width = w; m_height = h; calcCameraIcons(); - glViewport (0, 0, w, h); - glMatrixMode (GL_PROJECTION); + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective (45.0f, (double) w / (double) h, 1.0f, 40000.0f); - glMatrixMode (GL_MODELVIEW); + gluPerspective(45.0f,(double) w /(double) h, 1.0f, 40000.0f); + glMatrixMode(GL_MODELVIEW); } // ============================================================================= @@ -393,23 +393,23 @@ } if (config.drawWireframe() and not isPicking()) - glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glEnable (GL_DEPTH_TEST); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_DEPTH_TEST); if (camera() != EFreeCamera) { - glMatrixMode (GL_PROJECTION); + glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - glOrtho (-m_virtualWidth, m_virtualWidth, -m_virtualHeight, m_virtualHeight, -200.0f, 200.0f); - glTranslatef (panning (X), panning (Y), 0.0f); + glOrtho(-m_virtualWidth, m_virtualWidth, -m_virtualHeight, m_virtualHeight, -200.0f, 200.0f); + glTranslatef(panning(X), panning(Y), 0.0f); if (camera() != EFrontCamera and camera() != EBackCamera) { - glRotatef (90.0f, g_FixedCameras[camera()].glrotate[0], + glRotatef(90.0f, g_FixedCameras[camera()].glrotate[0], g_FixedCameras[camera()].glrotate[1], g_FixedCameras[camera()].glrotate[2]); } @@ -417,45 +417,45 @@ // Back camera needs to be handled differently if (camera() == EBackCamera) { - glRotatef (180.0f, 1.0f, 0.0f, 0.0f); - glRotatef (180.0f, 0.0f, 0.0f, 1.0f); + glRotatef(180.0f, 1.0f, 0.0f, 0.0f); + glRotatef(180.0f, 0.0f, 0.0f, 1.0f); } } else { - glMatrixMode (GL_MODELVIEW); + glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - glTranslatef (0.0f, 0.0f, -2.0f); - glTranslatef (panning (X), panning (Y), -zoom()); - glRotatef (rotation (X), 1.0f, 0.0f, 0.0f); - glRotatef (rotation (Y), 0.0f, 1.0f, 0.0f); - glRotatef (rotation (Z), 0.0f, 0.0f, 1.0f); + glTranslatef(0.0f, 0.0f, -2.0f); + glTranslatef(panning(X), panning(Y), -zoom()); + glRotatef(rotation(X), 1.0f, 0.0f, 0.0f); + glRotatef(rotation(Y), 0.0f, 1.0f, 0.0f); + glRotatef(rotation(Z), 0.0f, 0.0f, 1.0f); } - glEnableClientState (GL_VERTEX_ARRAY); - glEnableClientState (GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); if (isPicking()) { - drawVbos (TrianglesVbo, PickColorsVboComplement, GL_TRIANGLES); - drawVbos (QuadsVbo, PickColorsVboComplement, GL_QUADS); - drawVbos (LinesVbo, PickColorsVboComplement, GL_LINES); - drawVbos (ConditionalLinesVbo, PickColorsVboComplement, GL_LINES); + drawVbos(TrianglesVbo, PickColorsVboComplement, GL_TRIANGLES); + drawVbos(QuadsVbo, PickColorsVboComplement, GL_QUADS); + drawVbos(LinesVbo, PickColorsVboComplement, GL_LINES); + drawVbos(ConditionalLinesVbo, PickColorsVboComplement, GL_LINES); } else { if (config.bfcRedGreenView()) { - glEnable (GL_CULL_FACE); - glCullFace (GL_BACK); - drawVbos (TrianglesVbo, BfcFrontColorsVboComplement, GL_TRIANGLES); - drawVbos (QuadsVbo, BfcFrontColorsVboComplement, GL_QUADS); - glCullFace (GL_FRONT); - drawVbos (TrianglesVbo, BfcBackColorsVboComplement, GL_TRIANGLES); - drawVbos (QuadsVbo, BfcBackColorsVboComplement, GL_QUADS); - glDisable (GL_CULL_FACE); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + drawVbos(TrianglesVbo, BfcFrontColorsVboComplement, GL_TRIANGLES); + drawVbos(QuadsVbo, BfcFrontColorsVboComplement, GL_QUADS); + glCullFace(GL_FRONT); + drawVbos(TrianglesVbo, BfcBackColorsVboComplement, GL_TRIANGLES); + drawVbos(QuadsVbo, BfcBackColorsVboComplement, GL_QUADS); + glDisable(GL_CULL_FACE); } else { @@ -466,65 +466,65 @@ else colors = NormalColorsVboComplement; - drawVbos (TrianglesVbo, colors, GL_TRIANGLES); - drawVbos (QuadsVbo, colors, GL_QUADS); + drawVbos(TrianglesVbo, colors, GL_TRIANGLES); + drawVbos(QuadsVbo, colors, GL_QUADS); } - drawVbos (LinesVbo, NormalColorsVboComplement, GL_LINES); - glEnable (GL_LINE_STIPPLE); - drawVbos (ConditionalLinesVbo, NormalColorsVboComplement, GL_LINES); - glDisable (GL_LINE_STIPPLE); + drawVbos(LinesVbo, NormalColorsVboComplement, GL_LINES); + glEnable(GL_LINE_STIPPLE); + drawVbos(ConditionalLinesVbo, NormalColorsVboComplement, GL_LINES); + glDisable(GL_LINE_STIPPLE); if (config.drawAxes()) { - glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo); - glVertexPointer (3, GL_FLOAT, 0, NULL); - glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo); - glColorPointer (3, GL_FLOAT, 0, NULL); - glDrawArrays (GL_LINES, 0, 6); + glBindBuffer(GL_ARRAY_BUFFER, m_axesVbo); + glVertexPointer(3, GL_FLOAT, 0, NULL); + glBindBuffer(GL_ARRAY_BUFFER, m_axesVbo); + glColorPointer(3, GL_FLOAT, 0, NULL); + glDrawArrays(GL_LINES, 0, 6); CHECK_GL_ERROR(); } } glPopMatrix(); - glBindBuffer (GL_ARRAY_BUFFER, 0); - glDisableClientState (GL_VERTEX_ARRAY); - glDisableClientState (GL_COLOR_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); CHECK_GL_ERROR(); - glDisable (GL_CULL_FACE); - glMatrixMode (GL_MODELVIEW); - glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + glDisable(GL_CULL_FACE); + glMatrixMode(GL_MODELVIEW); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } // ============================================================================= // -void GLRenderer::drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type) +void GLRenderer::drawVbos(SurfaceVboType surface, ComplementVboType colors, GLenum type) { // Filter this through some configuration options - if ((isOneOf (surface, QuadsVbo, TrianglesVbo) and config.drawSurfaces() == false) - or (surface == LinesVbo and config.drawEdgeLines() == false) - or (surface == ConditionalLinesVbo and config.drawConditionalLines() == false)) + if ((isOneOf(surface, QuadsVbo, TrianglesVbo) and config.drawSurfaces() == false) + or(surface == LinesVbo and config.drawEdgeLines() == false) + or(surface == ConditionalLinesVbo and config.drawConditionalLines() == false)) { return; } - int surfacenum = m_compiler->vboNumber (surface, SurfacesVboComplement); - int colornum = m_compiler->vboNumber (surface, colors); - m_compiler->prepareVBO (surfacenum); - m_compiler->prepareVBO (colornum); - GLuint surfacevbo = m_compiler->vbo (surfacenum); - GLuint colorvbo = m_compiler->vbo (colornum); - GLsizei count = m_compiler->vboSize (surfacenum) / 3; + int surfacenum = m_compiler->vboNumber(surface, SurfacesVboComplement); + int colornum = m_compiler->vboNumber(surface, colors); + m_compiler->prepareVBO(surfacenum); + m_compiler->prepareVBO(colornum); + GLuint surfacevbo = m_compiler->vbo(surfacenum); + GLuint colorvbo = m_compiler->vbo(colornum); + GLsizei count = m_compiler->vboSize(surfacenum) / 3; if (count > 0) { - glBindBuffer (GL_ARRAY_BUFFER, surfacevbo); - glVertexPointer (3, GL_FLOAT, 0, nullptr); + glBindBuffer(GL_ARRAY_BUFFER, surfacevbo); + glVertexPointer(3, GL_FLOAT, 0, nullptr); CHECK_GL_ERROR(); - glBindBuffer (GL_ARRAY_BUFFER, colorvbo); - glColorPointer (4, GL_FLOAT, 0, nullptr); + glBindBuffer(GL_ARRAY_BUFFER, colorvbo); + glColorPointer(4, GL_FLOAT, 0, nullptr); CHECK_GL_ERROR(); - glDrawArrays (type, 0, count); + glDrawArrays(type, 0, count); CHECK_GL_ERROR(); } } @@ -534,7 +534,7 @@ // This converts a 2D point on the screen to a 3D point in the model. If 'snap' // is true, the 3D point will snap to the current grid. // -Vertex GLRenderer::convert2dTo3d (const QPoint& pos2d, bool snap) const +Vertex GLRenderer::convert2dTo3d(const QPoint& pos2d, bool snap) const { if (camera() == EFreeCamera) return Origin; @@ -547,25 +547,25 @@ negYFac = cam->negatedY ? -1 : 1; // Calculate cx and cy - these are the LDraw unit coords the cursor is at. - double cx = (-m_virtualWidth + ((2 * pos2d.x() * m_virtualWidth) / m_width) - panning (X)); - double cy = (m_virtualHeight - ((2 * pos2d.y() * m_virtualHeight) / m_height) - panning (Y)); + double cx = (-m_virtualWidth +((2 * pos2d.x() * m_virtualWidth) / m_width) - panning(X)); + double cy = (m_virtualHeight -((2 * pos2d.y() * m_virtualHeight) / m_height) - panning(Y)); if (snap) { - cx = Grid::Snap (cx, Grid::Coordinate); - cy = Grid::Snap (cy, Grid::Coordinate); + cx = Grid::Snap(cx, Grid::Coordinate); + cy = Grid::Snap(cy, Grid::Coordinate); } cx *= negXFac; cy *= negYFac; - RoundToDecimals (cx, 4); - RoundToDecimals (cy, 4); + RoundToDecimals(cx, 4); + RoundToDecimals(cy, 4); // Create the vertex from the coordinates - pos3d.setCoordinate (axisX, cx); - pos3d.setCoordinate (axisY, cy); - pos3d.setCoordinate ((Axis) (3 - axisX - axisY), getDepthValue()); + pos3d.setCoordinate(axisX, cx); + pos3d.setCoordinate(axisY, cy); + pos3d.setCoordinate((Axis)(3 - axisX - axisY), getDepthValue()); return pos3d; } @@ -574,10 +574,10 @@ // Inverse operation for the above - convert a 3D position to a 2D screen position. Don't ask me how this code manages // to work, I don't even know. // -QPoint GLRenderer::convert3dTo2d (const Vertex& pos3d) +QPoint GLRenderer::convert3dTo2d(const Vertex& pos3d) { if (camera() == EFreeCamera) - return QPoint (0, 0); + return QPoint(0, 0); const LDFixedCamera* cam = &g_FixedCameras[camera()]; const Axis axisX = cam->localX; @@ -590,31 +590,31 @@ const double z = pos3d.z(); Vertex transformed; - glGetFloatv (GL_MODELVIEW_MATRIX, matrix); - transformed.setX ((matrix[0] * x) + (matrix[1] * y) + (matrix[2] * z) + matrix[3]); - transformed.setY ((matrix[4] * x) + (matrix[5] * y) + (matrix[6] * z) + matrix[7]); - transformed.setZ ((matrix[8] * x) + (matrix[9] * y) + (matrix[10] * z) + matrix[11]); - double rx = (((transformed[axisX] * negXFac) + m_virtualWidth + panning (X)) * m_width) / (2 * m_virtualWidth); - double ry = (((transformed[axisY] * negYFac) - m_virtualHeight + panning (Y)) * m_height) / (2 * m_virtualHeight); - return QPoint (rx, -ry); + glGetFloatv(GL_MODELVIEW_MATRIX, matrix); + transformed.setX((matrix[0] * x) +(matrix[1] * y) +(matrix[2] * z) + matrix[3]); + transformed.setY((matrix[4] * x) +(matrix[5] * y) +(matrix[6] * z) + matrix[7]); + transformed.setZ((matrix[8] * x) +(matrix[9] * y) +(matrix[10] * z) + matrix[11]); + double rx = (((transformed[axisX] * negXFac) + m_virtualWidth + panning(X)) * m_width) /(2 * m_virtualWidth); + double ry = (((transformed[axisY] * negYFac) - m_virtualHeight + panning(Y)) * m_height) /(2 * m_virtualHeight); + return QPoint(rx, -ry); } QPen GLRenderer::textPen() const { - return QPen (m_useDarkBackground ? Qt::white : Qt::black); + return QPen(m_useDarkBackground ? Qt::white : Qt::black); } QPen GLRenderer::linePen() const { - QPen linepen (m_thinBorderPen); - linepen.setWidth (2); - linepen.setColor (luma (m_backgroundColor) < 40 ? Qt::white : Qt::black); + QPen linepen(m_thinBorderPen); + linepen.setWidth(2); + linepen.setColor(luma(m_backgroundColor) < 40 ? Qt::white : Qt::black); return linepen; } // ============================================================================= // -void GLRenderer::paintEvent (QPaintEvent*) +void GLRenderer::paintEvent(QPaintEvent*) { doMakeCurrent(); m_virtualWidth = zoom(); @@ -622,9 +622,9 @@ initGLData(); drawGLScene(); - QPainter paint (this); - QFontMetrics metrics = QFontMetrics (QFont()); - paint.setRenderHint (QPainter::HighQualityAntialiasing); + QPainter paint(this); + QFontMetrics metrics = QFontMetrics(QFont()); + paint.setRenderHint(QPainter::HighQualityAntialiasing); // If we wish to only draw the brick, stop here if (isDrawOnly()) @@ -633,11 +633,11 @@ #ifndef RELEASE if (not isPicking()) { - QString text = format ("Rotation: (%1°, %2°, %3°)\nPanning: (%4, %5), Zoom: %6", + QString text = format("Rotation:(%1°, %2°, %3°)\nPanning:(%4, %5), Zoom: %6", rotation(X), rotation(Y), rotation(Z), panning(X), panning(Y), zoom()); - QRect textSize = metrics.boundingRect (0, 0, m_width, m_height, Qt::AlignCenter, text); - paint.setPen (textPen()); - paint.drawText ((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(), + QRect textSize = metrics.boundingRect(0, 0, m_width, m_height, Qt::AlignCenter, text); + paint.setPen(textPen()); + paint.drawText((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(), textSize.height(), Qt::AlignCenter, text); } #endif @@ -649,31 +649,31 @@ if (overlay.img) { - QPoint v0 = convert3dTo2d (currentDocumentData().overlays[camera()].v0); - QPoint v1 = convert3dTo2d (currentDocumentData().overlays[camera()].v1); - QRect targetRect (v0.x(), v0.y(), qAbs (v1.x() - v0.x()), qAbs (v1.y() - v0.y())); - QRect sourceRect (0, 0, overlay.img->width(), overlay.img->height()); - paint.drawImage (targetRect, *overlay.img, sourceRect); + QPoint v0 = convert3dTo2d(currentDocumentData().overlays[camera()].v0); + QPoint v1 = convert3dTo2d(currentDocumentData().overlays[camera()].v1); + QRect targetRect(v0.x(), v0.y(), qAbs(v1.x() - v0.x()), qAbs(v1.y() - v0.y())); + QRect sourceRect(0, 0, overlay.img->width(), overlay.img->height()); + paint.drawImage(targetRect, *overlay.img, sourceRect); } // Paint the coordinates onto the screen. - QString text = format (tr ("X: %1, Y: %2, Z: %3"), m_position3D[X], m_position3D[Y], m_position3D[Z]); - QFontMetrics metrics = QFontMetrics (font()); - QRect textSize = metrics.boundingRect (0, 0, m_width, m_height, Qt::AlignCenter, text); - paint.setPen (textPen()); - paint.drawText (m_width - textSize.width(), m_height - 16, textSize.width(), + QString text = format(tr("X: %1, Y: %2, Z: %3"), m_position3D[X], m_position3D[Y], m_position3D[Z]); + QFontMetrics metrics = QFontMetrics(font()); + QRect textSize = metrics.boundingRect(0, 0, m_width, m_height, Qt::AlignCenter, text); + paint.setPen(textPen()); + paint.drawText(m_width - textSize.width(), m_height - 16, textSize.width(), textSize.height(), Qt::AlignCenter, text); } if (not isPicking()) { // Draw edit mode HUD - m_currentEditMode->render (paint); + m_currentEditMode->render(paint); // Draw a background for the selected camera - paint.setPen (m_thinBorderPen); - paint.setBrush (QBrush (QColor (0, 128, 160, 128))); - paint.drawRect (m_cameraIcons[camera()].selRect); + paint.setPen(m_thinBorderPen); + paint.setBrush(QBrush(QColor(0, 128, 160, 128))); + paint.drawRect(m_cameraIcons[camera()].selRect); // Draw the camera icons for (CameraIcon& info : m_cameraIcons) @@ -682,23 +682,23 @@ if (&info == &m_cameraIcons[EFreeCamera] and not m_currentEditMode->allowFreeCamera()) continue; - paint.drawPixmap (info.targetRect, *info.image, info.sourceRect); + paint.drawPixmap(info.targetRect, *info.image, info.sourceRect); } // Draw a label for the current camera in the bottom left corner { const int margin = 4; - paint.setPen (textPen()); - paint.drawText (QPoint (margin, height() - (margin + metrics.descent())), currentCameraName()); + paint.setPen(textPen()); + paint.drawText(QPoint(margin, height() -(margin + metrics.descent())), currentCameraName()); } // Tool tips if (m_drawToolTip) { - if (not m_cameraIcons[m_toolTipCamera].targetRect.contains (m_mousePosition)) + if (not m_cameraIcons[m_toolTipCamera].targetRect.contains(m_mousePosition)) m_drawToolTip = false; else - QToolTip::showText (m_globalpos, currentCameraName()); + QToolTip::showText(m_globalpos, currentCameraName()); } } @@ -711,9 +711,9 @@ for (const MessageManager::Line& line : messageLog()->getLines()) { - penColor.setAlphaF (line.alpha); - paint.setPen (penColor); - paint.drawText (QPoint (margin, y + margin + metrics.ascent()), line.text); + penColor.setAlphaF(line.alpha); + paint.setPen(penColor); + paint.drawText(QPoint(margin, y + margin + metrics.ascent()), line.text); y += metrics.height(); } } @@ -721,30 +721,30 @@ // ============================================================================= // -void GLRenderer::drawBlip (QPainter& painter, QPointF pos, QColor color) const +void GLRenderer::drawBlip(QPainter& painter, QPointF pos, QColor color) const { QPen pen = m_thinBorderPen; const int blipsize = 8; - pen.setWidth (1); - painter.setPen (pen); - painter.setBrush (color); - painter.drawEllipse (pos.x() - blipsize / 2, pos.y() - blipsize / 2, blipsize, blipsize); + pen.setWidth(1); + painter.setPen(pen); + painter.setBrush(color); + painter.drawEllipse(pos.x() - blipsize / 2, pos.y() - blipsize / 2, blipsize, blipsize); } -void GLRenderer::drawBlipCoordinates (QPainter& painter, const Vertex& pos3d) +void GLRenderer::drawBlipCoordinates(QPainter& painter, const Vertex& pos3d) { - drawBlipCoordinates (painter, pos3d, convert3dTo2d (pos3d)); + drawBlipCoordinates(painter, pos3d, convert3dTo2d(pos3d)); } -void GLRenderer::drawBlipCoordinates (QPainter& painter, const Vertex& pos3d, QPointF pos) +void GLRenderer::drawBlipCoordinates(QPainter& painter, const Vertex& pos3d, QPointF pos) { - painter.setPen (textPen()); - painter.drawText (pos.x(), pos.y() - 8, pos3d.toString (true)); + painter.setPen(textPen()); + painter.drawText(pos.x(), pos.y() - 8, pos3d.toString(true)); } // ============================================================================= // -void GLRenderer::clampAngle (double& angle) const +void GLRenderer::clampAngle(double& angle) const { while (angle < 0) angle += 360.0; @@ -755,9 +755,9 @@ // ============================================================================= // -void GLRenderer::mouseReleaseEvent (QMouseEvent* ev) +void GLRenderer::mouseReleaseEvent(QMouseEvent* ev) { - bool wasLeft = (m_lastButtons & Qt::LeftButton) and not (ev->buttons() & Qt::LeftButton); + bool wasLeft = (m_lastButtons & Qt::LeftButton) and not(ev->buttons() & Qt::LeftButton); Qt::MouseButtons releasedbuttons = m_lastButtons & ~ev->buttons(); m_panning = false; @@ -768,9 +768,9 @@ { for (CameraIcon & info : m_cameraIcons) { - if (info.targetRect.contains (ev->pos())) + if (info.targetRect.contains(ev->pos())) { - setCamera (info.cam); + setCamera(info.cam); goto end; } } @@ -785,7 +785,7 @@ data.keymods = m_currentKeyboardModifiers; data.releasedButtons = releasedbuttons; - if (m_currentEditMode->mouseReleased (data)) + if (m_currentEditMode->mouseReleased(data)) goto end; } @@ -796,50 +796,50 @@ // ============================================================================= // -void GLRenderer::mousePressEvent (QMouseEvent* ev) +void GLRenderer::mousePressEvent(QMouseEvent* ev) { m_totalMouseMove = 0; m_lastButtons = ev->buttons(); - if (m_currentEditMode->mousePressed (ev)) + if (m_currentEditMode->mousePressed(ev)) ev->accept(); } // ============================================================================= // -void GLRenderer::mouseMoveEvent (QMouseEvent* ev) +void GLRenderer::mouseMoveEvent(QMouseEvent* ev) { int dx = ev->x() - m_mousePosition.x(); int dy = ev->y() - m_mousePosition.y(); - m_totalMouseMove += qAbs (dx) + qAbs (dy); + m_totalMouseMove += qAbs(dx) + qAbs(dy); m_isCameraMoving = false; - if (not m_currentEditMode->mouseMoved (ev)) + if (not m_currentEditMode->mouseMoved(ev)) { const bool left = ev->buttons() & Qt::LeftButton, mid = ev->buttons() & Qt::MidButton, shift = ev->modifiers() & Qt::ShiftModifier; - if (mid or (left and shift)) + if (mid or(left and shift)) { - panning (X) += 0.03f * dx * (zoom() / 7.5f); - panning (Y) -= 0.03f * dy * (zoom() / 7.5f); + panning(X) += 0.03f * dx *(zoom() / 7.5f); + panning(Y) -= 0.03f * dy *(zoom() / 7.5f); m_panning = true; m_isCameraMoving = true; } else if (left and camera() == EFreeCamera) { - rotation (X) = rotation (X) + dy; - rotation (Y) = rotation (Y) + dx; - clampAngle (rotation (X)); - clampAngle (rotation (Y)); + rotation(X) = rotation(X) + dy; + rotation(Y) = rotation(Y) + dx; + clampAngle(rotation(X)); + clampAngle(rotation(Y)); m_isCameraMoving = true; } } // Start the tool tip timer if (not m_drawToolTip) - m_toolTipTimer->start (500); + m_toolTipTimer->start(500); // Update 2d position m_mousePosition = ev->pos(); @@ -852,7 +852,7 @@ #endif // Calculate 3d position of the cursor - m_position3D = (camera() != EFreeCamera) ? convert2dTo3d (m_mousePosition, true) : Origin; + m_position3D = (camera() != EFreeCamera) ? convert2dTo3d(m_mousePosition, true) : Origin; highlightCursorObject(); update(); @@ -861,28 +861,28 @@ // ============================================================================= // -void GLRenderer::keyPressEvent (QKeyEvent* ev) +void GLRenderer::keyPressEvent(QKeyEvent* ev) { m_currentKeyboardModifiers = ev->modifiers(); } // ============================================================================= // -void GLRenderer::keyReleaseEvent (QKeyEvent* ev) +void GLRenderer::keyReleaseEvent(QKeyEvent* ev) { m_currentKeyboardModifiers = ev->modifiers(); - m_currentEditMode->keyReleased (ev); + m_currentEditMode->keyReleased(ev); update(); } // ============================================================================= // -void GLRenderer::wheelEvent (QWheelEvent* ev) +void GLRenderer::wheelEvent(QWheelEvent* ev) { doMakeCurrent(); - zoomNotch (ev->delta() > 0); - zoom() = qBound (0.01, zoom(), 10000.0); + zoomNotch(ev->delta() > 0); + zoom() = qBound(0.01, zoom(), 10000.0); m_isCameraMoving = true; update(); ev->accept(); @@ -890,7 +890,7 @@ // ============================================================================= // -void GLRenderer::leaveEvent (QEvent* ev) +void GLRenderer::leaveEvent(QEvent* ev) { (void) ev; m_drawToolTip = false; @@ -900,34 +900,34 @@ // ============================================================================= // -void GLRenderer::contextMenuEvent (QContextMenuEvent* ev) +void GLRenderer::contextMenuEvent(QContextMenuEvent* ev) { - m_window->spawnContextMenu (ev->globalPos()); + m_window->spawnContextMenu(ev->globalPos()); } // ============================================================================= // -void GLRenderer::setCamera (const ECamera cam) +void GLRenderer::setCamera(const ECamera cam) { // The edit mode may forbid the free camera. if (cam == EFreeCamera and not m_currentEditMode->allowFreeCamera()) return; m_camera = cam; - config.setCamera ((int) cam); + config.setCamera((int) cam); m_window->updateEditModeActions(); } // ============================================================================= // -void GLRenderer::pick (int mouseX, int mouseY, bool additive) +void GLRenderer::pick(int mouseX, int mouseY, bool additive) { - pick (QRect (mouseX, mouseY, mouseX + 1, mouseY + 1), additive); + pick(QRect(mouseX, mouseY, mouseX + 1, mouseY + 1), additive); } // ============================================================================= // -void GLRenderer::pick (QRect const& range, bool additive) +void GLRenderer::pick(QRect const& range, bool additive) { doMakeCurrent(); @@ -938,11 +938,11 @@ currentDocument()->clearSelection(); for (LDObject* obj : oldSelection) - compileObject (obj); + compileObject(obj); } // Paint the picking scene - setPicking (true); + setPicking(true); drawGLScene(); int x0 = range.left(); @@ -951,10 +951,10 @@ int y1 = y0 + range.height(); // Clamp the values to ensure they're within bounds - x0 = qMax (0, x0); - y0 = qMax (0, y0); - x1 = qMin (x1, m_width); - y1 = qMin (y1, m_height); + x0 = qMax(0, x0); + y0 = qMax(0, y0); + x1 = qMin(x1, m_width); + y1 = qMin(y1, m_height); const int areawidth = (x1 - x0); const int areaheight = (y1 - y0); const qint32 numpixels = areawidth * areaheight; @@ -964,7 +964,7 @@ uchar* pixelptr = &pixeldata[0]; // Read pixels from the color buffer. - glReadPixels (x0, m_height - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata); + glReadPixels(x0, m_height - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata); LDObject* removedObj = nullptr; QList<qint32> indices; @@ -983,11 +983,11 @@ indices << idx; } - removeDuplicates (indices); + removeDuplicates(indices); for (qint32 idx : indices) { - LDObject* obj = LDObject::fromID (idx); + LDObject* obj = LDObject::fromID(idx); if (obj == nullptr) continue; @@ -1014,44 +1014,44 @@ // Recompile the objects now to update their color for (LDObject* obj : selectedObjects()) - compileObject (obj); + compileObject(obj); if (removedObj) - compileObject (removedObj); + compileObject(removedObj); - setPicking (false); + setPicking(false); repaint(); } // // Simpler version of GLRenderer::pick which simply picks whatever object on the screen // -LDObject* GLRenderer::pickOneObject (int mouseX, int mouseY) +LDObject* GLRenderer::pickOneObject(int mouseX, int mouseY) { uchar pixel[4]; doMakeCurrent(); - setPicking (true); + setPicking(true); drawGLScene(); - glReadPixels (mouseX, m_height - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); - LDObject* obj = LDObject::fromID ((pixel[0] * 0x10000) + (pixel[1] * 0x100) + pixel[2]); - setPicking (false); + glReadPixels(mouseX, m_height - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); + LDObject* obj = LDObject::fromID((pixel[0] * 0x10000) +(pixel[1] * 0x100) + pixel[2]); + setPicking(false); repaint(); return obj; } // ============================================================================= // -void GLRenderer::setEditMode (EditModeType a) +void GLRenderer::setEditMode(EditModeType a) { if (m_currentEditMode and m_currentEditMode->type() == a) return; delete m_currentEditMode; - m_currentEditMode = AbstractEditMode::createByType (this, a); + m_currentEditMode = AbstractEditMode::createByType(this, a); // If we cannot use the free camera, use the top one instead. if (camera() == EFreeCamera and not m_currentEditMode->allowFreeCamera()) - setCamera (ETopCamera); + setCamera(ETopCamera); m_window->updateEditModeActions(); update(); @@ -1066,7 +1066,7 @@ // ============================================================================= // -void GLRenderer::setDocument (LDDocument* document) +void GLRenderer::setDocument(LDDocument* document) { m_document = document; @@ -1086,30 +1086,30 @@ // ============================================================================= // -void GLRenderer::setPicking (bool value) +void GLRenderer::setPicking(bool value) { m_isPicking = value; setBackground(); if (isPicking()) { - glDisable (GL_DITHER); + glDisable(GL_DITHER); // Use particularly thick lines while picking ease up selecting lines. - glLineWidth (qMax<double> (config.lineThickness(), 6.5)); + glLineWidth(qMax<double>(config.lineThickness(), 6.5)); } else { - glEnable (GL_DITHER); + glEnable(GL_DITHER); // Restore line thickness - glLineWidth (config.lineThickness()); + glLineWidth(config.lineThickness()); } } // ============================================================================= // -void GLRenderer::getRelativeAxes (Axis& relX, Axis& relY) const +void GLRenderer::getRelativeAxes(Axis& relX, Axis& relY) const { const LDFixedCamera* cam = &g_FixedCameras[camera()]; relX = cam->localX; @@ -1121,22 +1121,22 @@ Axis GLRenderer::getRelativeZ() const { const LDFixedCamera* cam = &g_FixedCameras[camera()]; - return (Axis) (3 - cam->localX - cam->localY); + return (Axis)(3 - cam->localX - cam->localY); } // ============================================================================= // -void GLRenderer::compileObject (LDObject* obj) +void GLRenderer::compileObject(LDObject* obj) { - compiler()->stageForCompilation (obj); + compiler()->stageForCompilation(obj); } // ============================================================================= // -void GLRenderer::forgetObject (LDObject* obj) +void GLRenderer::forgetObject(LDObject* obj) { - compiler()->dropObjectInfo (obj); - compiler()->unstage (obj); + compiler()->dropObjectInfo(obj); + compiler()->unstage(obj); if (m_objectAtCursor == obj) m_objectAtCursor = nullptr; @@ -1147,11 +1147,11 @@ QByteArray GLRenderer::capturePixels() { QByteArray result; - result.resize (4 * width() * height()); + result.resize(4 * width() * height()); m_takingScreenCapture = true; update(); // Smile! m_takingScreenCapture = false; - glReadPixels (0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, reinterpret_cast<uchar*> (result.data())); + glReadPixels(0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, reinterpret_cast<uchar*>(result.data())); return result; } @@ -1164,7 +1164,7 @@ // a tooltip. for (CameraIcon & icon : m_cameraIcons) { - if (icon.targetRect.contains (m_mousePosition)) + if (icon.targetRect.contains(m_mousePosition)) { m_toolTipCamera = icon.cam; m_drawToolTip = true; @@ -1176,7 +1176,7 @@ // ============================================================================= // -Axis GLRenderer::getCameraAxis (bool y, ECamera camid) +Axis GLRenderer::getCameraAxis(bool y, ECamera camid) { if (camid == (ECamera) -1) camid = camera(); @@ -1187,14 +1187,14 @@ // ============================================================================= // -bool GLRenderer::setupOverlay (ECamera cam, QString file, int x, int y, int w, int h) +bool GLRenderer::setupOverlay(ECamera cam, QString file, int x, int y, int w, int h) { - QImage* img = new QImage (QImage (file).convertToFormat (QImage::Format_ARGB32)); - LDGLOverlay& info = getOverlay (cam); + QImage* img = new QImage(QImage(file).convertToFormat(QImage::Format_ARGB32)); + LDGLOverlay& info = getOverlay(cam); if (img->isNull()) { - Critical (tr ("Failed to load overlay image!")); + Critical(tr("Failed to load overlay image!")); currentDocumentData().overlays[cam].invalid = true; delete img; return false; @@ -1215,23 +1215,23 @@ else if (info.lh == 0) info.lh = (info.lw * img->height()) / img->width(); - const Axis x2d = getCameraAxis (false, cam), - y2d = getCameraAxis (true, cam); + const Axis x2d = getCameraAxis(false, cam), + y2d = getCameraAxis(true, cam); const double negXFac = g_FixedCameras[cam].negatedX ? -1 : 1, negYFac = g_FixedCameras[cam].negatedY ? -1 : 1; info.v0 = info.v1 = Origin; - info.v0.setCoordinate (x2d, -(info.ox * info.lw * negXFac) / img->width()); - info.v0.setCoordinate (y2d, (info.oy * info.lh * negYFac) / img->height()); - info.v1.setCoordinate (x2d, info.v0[x2d] + info.lw); - info.v1.setCoordinate (y2d, info.v0[y2d] + info.lh); + info.v0.setCoordinate(x2d, -(info.ox * info.lw * negXFac) / img->width()); + info.v0.setCoordinate(y2d,(info.oy * info.lh * negYFac) / img->height()); + info.v1.setCoordinate(x2d, info.v0[x2d] + info.lw); + info.v1.setCoordinate(y2d, info.v0[y2d] + info.lh); // Set alpha of all pixels to 0.5 for (long i = 0; i < img->width(); ++i) for (long j = 0; j < img->height(); ++j) { - uint32 pixel = img->pixel (i, j); - img->setPixel (i, j, 0x80000000 | (pixel & 0x00FFFFFF)); + uint32 pixel = img->pixel(i, j); + img->setPixel(i, j, 0x80000000 |(pixel & 0x00FFFFFF)); } updateOverlayObjects(); @@ -1254,7 +1254,7 @@ // ============================================================================= // -void GLRenderer::setDepthValue (double depth) +void GLRenderer::setDepthValue(double depth) { if (camera() < EFreeCamera) currentDocumentData().depthValues[camera()] = depth; @@ -1272,17 +1272,17 @@ // ============================================================================= // -QString GLRenderer::cameraName (ECamera camera) const +QString GLRenderer::cameraName(ECamera camera) const { - switch (camera) + switch(camera) { - case ETopCamera: return tr ("Top Camera"); - case EFrontCamera: return tr ("Front Camera"); - case ELeftCamera: return tr ("Left Camera"); - case EBottomCamera: return tr ("Bottom Camera"); - case EBackCamera: return tr ("Back Camera"); - case ERightCamera: return tr ("Right Camera"); - case EFreeCamera: return tr ("Free Camera"); + case ETopCamera: return tr("Top Camera"); + case EFrontCamera: return tr("Front Camera"); + case ELeftCamera: return tr("Left Camera"); + case EBottomCamera: return tr("Bottom Camera"); + case EBackCamera: return tr("Back Camera"); + case ERightCamera: return tr("Right Camera"); + case EFreeCamera: return tr("Free Camera"); default: break; } @@ -1291,19 +1291,19 @@ QString GLRenderer::currentCameraName() const { - return cameraName (camera()); + return cameraName(camera()); } // ============================================================================= // -LDGLOverlay& GLRenderer::getOverlay (int newcam) +LDGLOverlay& GLRenderer::getOverlay(int newcam) { return currentDocumentData().overlays[newcam]; } // ============================================================================= // -void GLRenderer::zoomNotch (bool inward) +void GLRenderer::zoomNotch(bool inward) { zoom() *= inward ? 0.833f : 1.2f; } @@ -1325,7 +1325,7 @@ // Use the pick list while drawing the scene, this way we can tell whether borders // are background or not. - setPicking (true); + setPicking(true); while (--runaway) { @@ -1336,17 +1336,17 @@ break; } - zoomNotch (inward); - QVector<unsigned char> capture (4 * m_width * m_height); + zoomNotch(inward); + QVector<unsigned char> capture(4 * m_width * m_height); drawGLScene(); - glReadPixels (0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, capture.data()); - QImage image (capture.constData(), m_width, m_height, QImage::Format_ARGB32); + glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, capture.data()); + QImage image(capture.constData(), m_width, m_height, QImage::Format_ARGB32); bool filled = false; // Check the top and bottom rows for (int i = 0; i < image.width(); ++i) { - if (image.pixel (i, 0) != black or image.pixel (i, m_height - 1) != black) + if (image.pixel(i, 0) != black or image.pixel(i, m_height - 1) != black) { filled = true; break; @@ -1358,7 +1358,7 @@ { for (int i = 0; i < image.height(); ++i) { - if (image.pixel (0, i) != black or image.pixel (m_width - 1, i) != black) + if (image.pixel(0, i) != black or image.pixel(m_width - 1, i) != black) { filled = true; break; @@ -1380,7 +1380,7 @@ // last run had ideal zoom - zoom a bit back and we should reach it. if (filled and not lastfilled) { - zoomNotch (false); + zoomNotch(false); break; } @@ -1395,7 +1395,7 @@ lastfilled = filled; } - setPicking (false); + setPicking(false); } // ============================================================================= @@ -1407,19 +1407,19 @@ // ============================================================================= // -void GLRenderer::mouseDoubleClickEvent (QMouseEvent* ev) +void GLRenderer::mouseDoubleClickEvent(QMouseEvent* ev) { - if (m_currentEditMode->mouseDoubleClicked (ev)) + if (m_currentEditMode->mouseDoubleClicked(ev)) ev->accept(); } // ============================================================================= // -LDOverlay* GLRenderer::findOverlayObject (ECamera cam) +LDOverlay* GLRenderer::findOverlayObject(ECamera cam) { for (LDObject* obj : document()->objects()) { - LDOverlay* overlay = dynamic_cast<LDOverlay*> (obj); + LDOverlay* overlay = dynamic_cast<LDOverlay*>(obj); if (overlay and overlay->camera() == cam) return overlay; @@ -1440,7 +1440,7 @@ continue; LDGLOverlay& meta = currentDocumentData().overlays[cam]; - LDOverlay* ovlobj = findOverlayObject (cam); + LDOverlay* ovlobj = findOverlayObject(cam); if (ovlobj == nullptr and meta.img) { @@ -1451,7 +1451,7 @@ (meta.img == nullptr or meta.fname != ovlobj->fileName()) and not meta.invalid) { - setupOverlay (cam, ovlobj->fileName(), ovlobj->x(), + setupOverlay(cam, ovlobj->fileName(), ovlobj->x(), ovlobj->y(), ovlobj->width(), ovlobj->height()); } } @@ -1467,7 +1467,7 @@ continue; LDGLOverlay& meta = currentDocumentData().overlays[cam]; - LDOverlay* ovlobj = findOverlayObject (cam); + LDOverlay* ovlobj = findOverlayObject(cam); if (meta.img == nullptr and ovlobj) { @@ -1491,14 +1491,14 @@ // this into the header, which is everything up to the first scemantic // object. If we find another overlay object, place this object after // the last one found. Otherwise, place it before the first schemantic - // object and put an empty object after it (though don't do this if + // object and put an empty object after it(though don't do this if // there was no schemantic elements at all) int i, lastOverlay = -1; bool found = false; for (i = 0; i < document()->getObjectCount(); ++i) { - LDObject* obj = document()->getObject (i); + LDObject* obj = document()->getObject(i); if (obj->isScemantic()) { @@ -1511,24 +1511,24 @@ } if (lastOverlay != -1) - document()->insertObj (lastOverlay + 1, ovlobj); + document()->insertObj(lastOverlay + 1, ovlobj); else { - document()->insertObj (i, ovlobj); + document()->insertObj(i, ovlobj); if (found) - document()->insertObj (i + 1, LDSpawn<LDEmpty>()); + document()->insertObj(i + 1, LDSpawn<LDEmpty>()); } } if (meta.img and ovlobj) { - ovlobj->setCamera (cam); - ovlobj->setFileName (meta.fname); - ovlobj->setX (meta.ox); - ovlobj->setY (meta.oy); - ovlobj->setWidth (meta.lw); - ovlobj->setHeight (meta.lh); + ovlobj->setCamera(cam); + ovlobj->setFileName(meta.fname); + ovlobj->setX(meta.ox); + ovlobj->setY(meta.oy); + ovlobj->setWidth(meta.lw); + ovlobj->setHeight(meta.lh); } } @@ -1553,50 +1553,50 @@ } else { - setPicking (true); + setPicking(true); drawGLScene(); - setPicking (false); + setPicking(false); unsigned char pixel[4]; - glReadPixels (m_mousePosition.x(), m_height - m_mousePosition.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel[0]); + glReadPixels(m_mousePosition.x(), m_height - m_mousePosition.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel[0]); newIndex = pixel[0] * 0x10000 | pixel[1] * 0x100 | pixel[2]; } if (newIndex != (oldObject ? oldObject->id() : 0)) { if (newIndex != 0) - newObject = LDObject::fromID (newIndex); + newObject = LDObject::fromID(newIndex); m_objectAtCursor = newObject; if (oldObject) - compileObject (oldObject); + compileObject(oldObject); if (newObject) - compileObject (newObject); + compileObject(newObject); } update(); } -void GLRenderer::dragEnterEvent (QDragEnterEvent* ev) +void GLRenderer::dragEnterEvent(QDragEnterEvent* ev) { if (m_window and ev->source() == m_window->getPrimitivesTree() and m_window->getPrimitivesTree()->currentItem()) ev->acceptProposedAction(); } -void GLRenderer::dropEvent (QDropEvent* ev) +void GLRenderer::dropEvent(QDropEvent* ev) { if (m_window and ev->source() == m_window->getPrimitivesTree()) { - PrimitiveTreeItem* item = static_cast<PrimitiveTreeItem*> (m_window->getPrimitivesTree()->currentItem()); + PrimitiveTreeItem* item = static_cast<PrimitiveTreeItem*>(m_window->getPrimitivesTree()->currentItem()); QString primitiveName = item->primitive()->name; LDSubfileReference* ref = LDSpawn<LDSubfileReference>(); - ref->setColor (MainColor); - ref->setFileInfo (m_documents->getDocumentByName (primitiveName)); - ref->setPosition (Origin); - ref->setTransform (IdentityMatrix); - currentDocument()->insertObj (m_window->suggestInsertPoint(), ref); + ref->setColor(MainColor); + ref->setFileInfo(m_documents->getDocumentByName(primitiveName)); + ref->setPosition(Origin); + ref->setTransform(IdentityMatrix); + currentDocument()->insertObj(m_window->suggestInsertPoint(), ref); ref->select(); m_window->buildObjectList(); m_window->renderer()->refresh(); @@ -1609,7 +1609,7 @@ return m_position3D; } -const LDFixedCamera& GLRenderer::getFixedCamera (ECamera cam) const +const LDFixedCamera& GLRenderer::getFixedCamera(ECamera cam) const { return g_FixedCameras[cam]; } @@ -1655,7 +1655,7 @@ return *document()->glData(); } -double& GLRenderer::rotation (Axis ax) +double& GLRenderer::rotation(Axis ax) { return (ax == X) ? currentDocumentData().rotationX : @@ -1663,13 +1663,13 @@ currentDocumentData().rotationZ; } -double& GLRenderer::panning (Axis ax) +double& GLRenderer::panning(Axis ax) { return (ax == X) ? currentDocumentData().panX[camera()] : currentDocumentData().panY[camera()]; } -double GLRenderer::panning (Axis ax) const +double GLRenderer::panning(Axis ax) const { return (ax == X) ? currentDocumentData().panX[camera()] : currentDocumentData().panY[camera()];