diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 1d8bd706ba..3ccdae4027 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -498,6 +498,50 @@ void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend) m_visibleLegends.push_back(legend); } + + std::vector categoryLegends; + std::vector overlayItems; + for (auto legend : m_visibleLegends) + { + caf::CategoryLegend* catLegend = dynamic_cast(legend.p()); + if (catLegend) + { + categoryLegends.push_back(catLegend); + } + else + { + overlayItems.push_back(legend.p()); + } + } + + if (categoryLegends.size() > 0) + { + const int border = 3; + const int categoryWidth = 120; + + // This value is taken from OverlayAxisCross, as the axis cross is always shown in the lower left corner + const int axisCrossHeight = 120; + + int height = static_cast(m_mainCamera->viewport()->height()); + int xPos = border; + + int yPos = axisCrossHeight + 2*border; + + for (auto catLegend : categoryLegends) + { + catLegend->setLayoutFixedPosition(cvf::Vec2i(xPos, yPos)); + catLegend->setSizeHint(cvf::Vec2ui(categoryWidth, height - 2*border - axisCrossHeight)); + + xPos += categoryWidth + border; + } + + for (auto item : overlayItems) + { + item->setLayoutFixedPosition(cvf::Vec2i(xPos, yPos)); + + yPos += item->sizeHint().y() + border; + } + } } //-------------------------------------------------------------------------------------------------- @@ -577,6 +621,29 @@ void RiuViewer::optimizeClippingPlanes() caf::Viewer::optimizeClippingPlanes(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuViewer::resizeGL(int width, int height) +{ + caf::Viewer::resizeGL(width, height); + + bool hasCategoryLegend = false; + for (size_t i = 0; i < m_visibleLegends.size(); i++) + { + caf::CategoryLegend* categoryLegend = dynamic_cast(m_visibleLegends.at(i)); + if (categoryLegend) + { + hasCategoryLegend = true; + } + } + + if (hasCategoryLegend) + { + m_rimView->updateCurrentTimeStepAndRedraw(); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuViewer.h b/ApplicationCode/UserInterface/RiuViewer.h index 504e51f620..6a8937f4d5 100644 --- a/ApplicationCode/UserInterface/RiuViewer.h +++ b/ApplicationCode/UserInterface/RiuViewer.h @@ -95,6 +95,7 @@ public slots: protected: virtual void optimizeClippingPlanes(); + virtual void resizeGL(int width, int height); private: void updateTextAndTickMarkColorForOverlayItems();