diff --git a/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.cpp b/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.cpp index 78695e899e..6cf2ecec42 100644 --- a/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.cpp +++ b/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.cpp @@ -91,18 +91,21 @@ void RivTernarySaturationOverlayItem::renderSoftware(cvf::OpenGLContext* oglCont //-------------------------------------------------------------------------------------------------- void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, - const cvf::Vec2ui& size, + const cvf::Vec2ui& sizeHint, bool software) { - if (size.x() <= 0 || size.y() <= 0) + if (sizeHint.x() <= 0 || sizeHint.y() <= 0) { return; } float border = 0.0f; + cvf::Vec2ui sizeMatched = sizeHint; + sizeMatched.x() = this->matchedWidth(); // Match to other legends + cvf::Camera camera; - camera.setViewport(position.x(), position.y(), size.x(), size.y()); + camera.setViewport(position.x(), position.y(), sizeMatched.x(), sizeMatched.y()); camera.setProjectionAsPixelExact2D(); camera.setViewMatrix(cvf::Mat4d::IDENTITY); camera.applyOpenGL(); @@ -113,7 +116,7 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte if ( software ) { caf::InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext, - cvf::Vec2f(size), + cvf::Vec2f(sizeMatched), this->backgroundColor(), this->backgroundFrameColor()); } @@ -123,7 +126,7 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte caf::InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext, matrixState, - cvf::Vec2f(size), + cvf::Vec2f(sizeMatched), this->backgroundColor(), this->backgroundFrameColor()); } @@ -135,7 +138,7 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte float lineHeightInPixels = (float)(this->font()->textExtent("SWAT").y() + 2); - float textPosY = static_cast(size.y() - lineHeightInPixels - border); + float textPosY = static_cast(sizeMatched.y() - lineHeightInPixels - border); for (size_t it = 0; it < this->titleStrings().size(); it++) { cvf::Vec2f pos(border, textPosY); @@ -151,11 +154,11 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte { cvf::uint sgasTextWidth = this->font()->textExtent("SGAS").x(); - textDrawer.addText("SGAS", cvf::Vec2f(static_cast( (size.x() / 2) - sgasTextWidth / 2 ), textPosY)); + textDrawer.addText("SGAS", cvf::Vec2f(static_cast( (sizeMatched.x() / 2) - sgasTextWidth / 2 ), textPosY)); cvf::uint sgasRangeTextWidth = this->font()->textExtent(m_sgasRange).x(); textPosY -= lineHeightInPixels; - textDrawer.addText(m_sgasRange, cvf::Vec2f(static_cast( (size.x() / 2) - sgasRangeTextWidth / 2 ), textPosY)); + textDrawer.addText(m_sgasRange, cvf::Vec2f(static_cast( (sizeMatched.x() / 2) - sgasRangeTextWidth / 2 ), textPosY)); } textDrawer.addText("SWAT", cvf::Vec2f((float)border, (float)(lineHeightInPixels + border))); @@ -163,10 +166,10 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte { cvf::uint soilTextWidth = this->font()->textExtent("SOIL").x(); - textDrawer.addText("SOIL", cvf::Vec2f(static_cast(size.x() - soilTextWidth - border), lineHeightInPixels + border)); + textDrawer.addText("SOIL", cvf::Vec2f(static_cast(sizeMatched.x() - soilTextWidth - border), lineHeightInPixels + border)); cvf::uint soilRangeTextWidth = this->font()->textExtent(m_soilRange).x(); - float soilRangePos = static_cast(size.x()) - soilRangeTextWidth - border; + float soilRangePos = static_cast(sizeMatched.x()) - soilRangeTextWidth - border; textDrawer.addText(m_soilRange, cvf::Vec2f(soilRangePos, (float)border)); } diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 4bc5008681..bbb8b9a85e 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -623,7 +623,7 @@ void RiuViewer::addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend for (auto legend : m_visibleLegends) { - legend->setWidth(requiredLegendWidth); + legend->setMatchedWidth(requiredLegendWidth); } } diff --git a/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.cpp b/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.cpp index 58e9797481..9297c6061e 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.cpp +++ b/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.cpp @@ -131,7 +131,7 @@ void CategoryLegend::renderGeneric(OpenGLContext* oglContext, this->computeLayoutAndExtents(); - Vec2f backgroundSize(CVF_MIN((float) this->width(), (float)size.x()), (float)size.y()); + Vec2f backgroundSize(CVF_MIN((float) this->matchedWidth(), (float)size.x()), (float)size.y()); // Do the actual rendering if (software) diff --git a/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.cpp b/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.cpp index 0abf0c9b79..0753dfcf55 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.cpp +++ b/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.cpp @@ -188,7 +188,7 @@ void OverlayScalarMapperLegend::renderGeneric(OpenGLContext* oglContext, const V this->computeLayoutAndExtents(); - Vec2f backgroundSize(CVF_MIN((float)this->width(), (float)size.x()), (float)size.y()); + Vec2f backgroundSize(CVF_MIN((float)this->matchedWidth(), (float)size.x()), (float)size.y()); // Do the actual rendering if (software) diff --git a/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.cpp b/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.cpp index 10f35d6832..14ce1943bd 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.cpp +++ b/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.cpp @@ -37,20 +37,20 @@ namespace caf { } //-------------------------------------------------------------------------------------------------- - /// + /// Will also update the matched width since this should always be >= minimum width //-------------------------------------------------------------------------------------------------- void TitledOverlayFrame::setMinimumWidth(unsigned int width) { m_minimumWidth = width; - m_actualWidth = std::max(m_minimumWidth, m_actualWidth); + m_matchedWidth = std::max(m_minimumWidth, m_matchedWidth); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- - void TitledOverlayFrame::setWidth(unsigned int width) + void TitledOverlayFrame::setMatchedWidth(unsigned int width) { - m_actualWidth = width; + m_matchedWidth = width; } //-------------------------------------------------------------------------------------------------- @@ -138,9 +138,9 @@ namespace caf { //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- - unsigned int TitledOverlayFrame::width() + unsigned int TitledOverlayFrame::matchedWidth() { - return m_actualWidth; + return m_matchedWidth; } //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.h b/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.h index 8c211253f8..6ca71a7722 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.h +++ b/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.h @@ -23,7 +23,7 @@ namespace caf { virtual void setSizeHint(const cvf::Vec2ui& size); void setMinimumWidth(unsigned int width); - void setWidth(unsigned int width); + void setMatchedWidth(unsigned int width); void setTextColor(const cvf::Color3f& color); void setLineColor(const cvf::Color3f& lineColor); @@ -39,7 +39,7 @@ namespace caf { virtual cvf::Vec2ui sizeHint() override; unsigned int minimumWidth(); - unsigned int width(); + unsigned int matchedWidth(); protected: cvf::Color3f textColor() const; @@ -54,8 +54,8 @@ namespace caf { private: cvf::Vec2ui m_sizeHint; // The desired pixel size of the color legend area - unsigned int m_minimumWidth; - unsigned int m_actualWidth; + unsigned int m_minimumWidth; // Minimum width required to fit content + unsigned int m_matchedWidth; // Width matched to other legends (>= minimumWidth) cvf::Color3f m_textColor; cvf::Color3f m_lineColor;