From df0a356a0a6b1ce1a4c779652e66494a9f391a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Wed, 7 Mar 2018 12:47:48 +0100 Subject: [PATCH] #2478 Add top edge axis (intersection View) and repositioned info box and legends to follow. --- .../RivWindowEdgeAxesOverlayItem.cpp | 99 +++++++++++-------- .../RivWindowEdgeAxesOverlayItem.h | 3 + ApplicationCode/UserInterface/RiuViewer.cpp | 13 +-- 3 files changed, 66 insertions(+), 49 deletions(-) diff --git a/ApplicationCode/ModelVisualization/WindowEdgeAxesOverlayItem/RivWindowEdgeAxesOverlayItem.cpp b/ApplicationCode/ModelVisualization/WindowEdgeAxesOverlayItem/RivWindowEdgeAxesOverlayItem.cpp index 88e2717939..666ccd0cf8 100644 --- a/ApplicationCode/ModelVisualization/WindowEdgeAxesOverlayItem/RivWindowEdgeAxesOverlayItem.cpp +++ b/ApplicationCode/ModelVisualization/WindowEdgeAxesOverlayItem/RivWindowEdgeAxesOverlayItem.cpp @@ -65,6 +65,7 @@ RivWindowEdgeAxesOverlayItem::RivWindowEdgeAxesOverlayItem(Font* font) : m_windowSize(600, 600), m_textColor(Color3::BLACK), m_lineColor(Color3::BLACK), + m_frameColor(Color3::WHITE), m_lineWidth(1), m_font(font), m_isSwitchingYAxisValueSign(true) @@ -278,7 +279,9 @@ void RivWindowEdgeAxesOverlayItem::addTextToTextDrawer(TextDrawer* textDrawer) // Bottom X - axis text { - const float textY = m_pixelSpacing + m_textSize.y()*0.5f; + const float textYTop = m_windowSize.y() - m_pixelSpacing - m_textSize.y()*0.5f; + const float textYBott = m_pixelSpacing + m_textSize.y()*0.5f; + size_t numTicks = m_domainCoordsXValues.size(); size_t i; for ( i = 0; i < numTicks; i++ ) @@ -291,14 +294,17 @@ void RivWindowEdgeAxesOverlayItem::addTextToTextDrawer(TextDrawer* textDrawer) valueString = String::number(tickValue); auto labelSize = m_font->textExtent(valueString); - Vec2f pos(textX - labelSize.x()*0.5f, textY); + Vec2f pos(textX - labelSize.x()*0.5f, textYBott); + textDrawer->addText(valueString, pos); + pos[1] = textYTop; textDrawer->addText(valueString, pos); } } - + // Right Y - axis texts { - const float textX = m_windowSize.x() - m_pixelSpacing - m_textSize.x(); + const float textXRight = m_windowSize.x() - m_pixelSpacing - m_textSize.x(); + const float textXLeft = m_frameBorderWidth - m_tickLineLength - m_pixelSpacing; size_t numTicks = m_domainCoordsYValues.size(); size_t i; @@ -312,29 +318,10 @@ void RivWindowEdgeAxesOverlayItem::addTextToTextDrawer(TextDrawer* textDrawer) valueString = String::number(tickValue); auto labelSize = m_font->textExtent(valueString); - Vec2f pos(textX, textY); - textDrawer->addText(valueString, pos); - } - } - - // Left Y - axis texts - { - const float textX = m_frameBorderWidth - m_tickLineLength - m_pixelSpacing; - - size_t numTicks = m_domainCoordsYValues.size(); - size_t i; - for ( i = 0; i < numTicks; i++ ) - { - float textY = static_cast(m_windowTickYValues[i]); - - double tickValue = m_isSwitchingYAxisValueSign ? -m_domainCoordsYValues[i]: m_domainCoordsYValues[i]; - String valueString; - - valueString = String::number(tickValue); - auto labelSize = m_font->textExtent(valueString); - - Vec2f pos(textX - labelSize.x(), textY); + Vec2f pos(textXRight, textY); textDrawer->addText(valueString, pos); + Vec2f posl(textXLeft - labelSize.x(), textY); + textDrawer->addText(valueString, posl); } } } @@ -347,15 +334,22 @@ std::array RivWindowEdgeAxesOverlayItem::frameVertexArray() float windowWidth = static_cast(m_windowSize.x()); float windowHeight = static_cast(m_windowSize.y()); + // 3 2 + // 7 6 + // + // 4 5 + // 0 1 + std::array vertexArray ={ - Vec3f(0.0f , 0.0f , 0.0f), - Vec3f(windowWidth , 0.0f , 0.0f), - Vec3f(windowWidth , windowHeight , 0.0f), - Vec3f(0.0f , windowHeight , 0.0f), - Vec3f(m_frameBorderWidth , m_frameBorderHeight, 0.0f), - Vec3f(windowWidth - m_frameBorderWidth, m_frameBorderHeight, 0.0f), - Vec3f(windowWidth - m_frameBorderWidth, windowHeight , 0.0f), - Vec3f(m_frameBorderWidth , windowHeight , 0.0f), + Vec3f(0.0f , 0.0f , 0.0f), + Vec3f(windowWidth , 0.0f , 0.0f), + Vec3f(windowWidth , windowHeight , 0.0f), + Vec3f(0.0f , windowHeight , 0.0f), + + Vec3f(m_frameBorderWidth , m_frameBorderHeight , 0.0f), + Vec3f(windowWidth - m_frameBorderWidth, m_frameBorderHeight , 0.0f), + Vec3f(windowWidth - m_frameBorderWidth, windowHeight - m_frameBorderHeight, 0.0f), + Vec3f(m_frameBorderWidth , windowHeight - m_frameBorderHeight, 0.0f), }; return vertexArray; @@ -380,7 +374,7 @@ void RivWindowEdgeAxesOverlayItem::renderSoftwareFrameAndTickLines(OpenGLContext std::array vertexArray = frameVertexArray(); - glColor4fv(Vec4f(1.0f,1.0f,1.0f,0.5f).ptr()); + glColor4fv(m_frameColor.ptr()); glBegin(GL_TRIANGLE_FAN); glVertex3fv(vertexArray[0].ptr()); glVertex3fv(vertexArray[1].ptr()); @@ -399,6 +393,12 @@ void RivWindowEdgeAxesOverlayItem::renderSoftwareFrameAndTickLines(OpenGLContext glVertex3fv(vertexArray[4].ptr()); glVertex3fv(vertexArray[7].ptr()); glEnd(); + glBegin(GL_TRIANGLE_FAN); + glVertex3fv(vertexArray[2].ptr()); + glVertex3fv(vertexArray[3].ptr()); + glVertex3fv(vertexArray[7].ptr()); + glVertex3fv(vertexArray[6].ptr()); + glEnd(); // Render Line around @@ -413,6 +413,8 @@ void RivWindowEdgeAxesOverlayItem::renderSoftwareFrameAndTickLines(OpenGLContext glVertex3fv(vertexArray[5].ptr()); glVertex3fv(vertexArray[5].ptr()); glVertex3fv(vertexArray[6].ptr()); + glVertex3fv(vertexArray[6].ptr()); + glVertex3fv(vertexArray[7].ptr()); // X - axis Tick lines for (double txpos : m_windowTickXValues) @@ -427,6 +429,14 @@ void RivWindowEdgeAxesOverlayItem::renderSoftwareFrameAndTickLines(OpenGLContext glVertex3fv(p1.ptr()); glVertex3fv(p2.ptr()); + + p1[0] = (float)txpos; + p1[1] = m_windowSize.y() - m_frameBorderHeight; + p2[0] = (float)txpos; + p2[1] = m_windowSize.y() - m_frameBorderHeight + m_tickLineLength; + + glVertex3fv(p1.ptr()); + glVertex3fv(p2.ptr()); } // Left Y - axis Tick lines @@ -503,16 +513,17 @@ void RivWindowEdgeAxesOverlayItem::renderShaderFrameAndTickLines(OpenGLContext* // Draw frame background - UniformFloat backgroundColorUniform("u_color", Color4f(1.0f, 1.0f, 1.0f, 0.5f)); + UniformFloat backgroundColorUniform("u_color", m_frameColor); shaderProgram->applyUniform(oglContext, backgroundColorUniform); // Triangle indices for the frame background static const ushort backgroundTriangleIndices[] = { 0, 1, 5, 0, 5, 4, 1, 2, 6, 1, 6, 5, - 3, 0, 4, 3, 4, 7 }; + 3, 0, 4, 3, 4, 7, + 2, 3, 6, 3, 7, 6 }; - glDrawRangeElements(GL_TRIANGLES, 0, 7, 18, GL_UNSIGNED_SHORT, backgroundTriangleIndices); + glDrawRangeElements(GL_TRIANGLES, 0, 7, 24, GL_UNSIGNED_SHORT, backgroundTriangleIndices); // Draw frame border lines @@ -522,9 +533,10 @@ void RivWindowEdgeAxesOverlayItem::renderShaderFrameAndTickLines(OpenGLContext* static const ushort frameLineIndices[] = { 7, 4, 4, 5, - 5, 6 }; + 5, 6, + 6, 7 }; - glDrawRangeElements(GL_LINES, 0, 7, 6, GL_UNSIGNED_SHORT, frameLineIndices); + glDrawRangeElements(GL_LINES, 0, 7, 8, GL_UNSIGNED_SHORT, frameLineIndices); // Render tickmarks @@ -540,6 +552,13 @@ void RivWindowEdgeAxesOverlayItem::renderShaderFrameAndTickLines(OpenGLContext* vertexArray[1][1] = m_frameBorderHeight - m_tickLineLength; glDrawRangeElements(GL_LINES, 0, 1, 2, GL_UNSIGNED_SHORT, tickLineIndices); + + vertexArray[0][0] = (float)txpos; + vertexArray[0][1] = m_windowSize.y() - m_frameBorderHeight; + vertexArray[1][0] = (float)txpos; + vertexArray[1][1] = m_windowSize.y() - m_frameBorderHeight + m_tickLineLength; + + glDrawRangeElements(GL_LINES, 0, 1, 2, GL_UNSIGNED_SHORT, tickLineIndices); } // Left Y - axis Tick lines diff --git a/ApplicationCode/ModelVisualization/WindowEdgeAxesOverlayItem/RivWindowEdgeAxesOverlayItem.h b/ApplicationCode/ModelVisualization/WindowEdgeAxesOverlayItem/RivWindowEdgeAxesOverlayItem.h index 229906929f..8aefe6a6b4 100644 --- a/ApplicationCode/ModelVisualization/WindowEdgeAxesOverlayItem/RivWindowEdgeAxesOverlayItem.h +++ b/ApplicationCode/ModelVisualization/WindowEdgeAxesOverlayItem/RivWindowEdgeAxesOverlayItem.h @@ -72,6 +72,7 @@ class RivWindowEdgeAxesOverlayItem : public cvf::OverlayItem using OpenGLContext = cvf::OpenGLContext; using Vec2i = cvf::Vec2i; using Color3f = cvf::Color3f; + using Color4f = cvf::Color4f; using String = cvf::String; using Vec2f = cvf::Vec2f; using Vec3f = cvf::Vec3f; @@ -91,6 +92,7 @@ public: const Color3f& textColor() const; void setLineColor(const Color3f& lineColor); const Color3f& lineColor() const; + void setFrameColor(const Color4f& frameColor); int frameBorderWidth() { return static_cast( m_frameBorderWidth); } int frameBorderHeight() { return static_cast( m_frameBorderHeight); } @@ -116,6 +118,7 @@ private: Vec2ui m_textSize; Color3f m_textColor; Color3f m_lineColor; + Color4f m_frameColor; int m_lineWidth; cvf::ref m_font; diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 41877fc8fe..62cb0232b3 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -347,22 +347,17 @@ void RiuViewer::setEnableMask(unsigned int mask) //-------------------------------------------------------------------------------------------------- void RiuViewer::paintOverlayItems(QPainter* painter) { - // No support for overlay items using SW rendering yet. - //if (!isShadersSupported()) - //{ - // return; - //} - int columnWidth = 200; + int edgeAxisFrameBorderWidth = m_showWindowEdgeAxes ? m_windowEdgeAxisOverlay->frameBorderWidth(): 0; int edgeAxisFrameBorderHeight = m_showWindowEdgeAxes ? m_windowEdgeAxisOverlay->frameBorderHeight(): 0; + int margin = 5; - int yPos = margin; + int yPos = margin + edgeAxisFrameBorderHeight; bool showAnimBar = false; if (isAnimationActive() && frameCount() > 1) showAnimBar = true; - //if (showAnimBar) columnWidth = CVF_MAX(columnWidth, m_animationProgress->width()); if (m_showInfoText) columnWidth = CVF_MAX(columnWidth, m_infoLabel->sizeHint().width()); int columnPos = this->width() - columnWidth - margin - edgeAxisFrameBorderWidth; @@ -598,7 +593,7 @@ void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend) for (auto catLegend : categoryLegends) { catLegend->setLayoutFixedPosition(cvf::Vec2i(xPos, yPos)); - catLegend->setSizeHint(cvf::Vec2ui(categoryWidth, height - 2*border - axisCrossHeight - edgeAxisBorderHeight)); + catLegend->setSizeHint(cvf::Vec2ui(categoryWidth, height - 2*border - axisCrossHeight - 2*edgeAxisBorderHeight)); xPos += categoryWidth + border; }