#831 Category legend use full height to be able to show as many category names as possible

This commit is contained in:
Magne Sjaastad 2016-09-12 11:11:25 +02:00
parent 25d5a500f0
commit 7306950d9d
2 changed files with 68 additions and 0 deletions

View File

@ -498,6 +498,50 @@ void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend)
m_visibleLegends.push_back(legend);
}
std::vector<caf::CategoryLegend*> categoryLegends;
std::vector<cvf::OverlayItem*> overlayItems;
for (auto legend : m_visibleLegends)
{
caf::CategoryLegend* catLegend = dynamic_cast<caf::CategoryLegend*>(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<int>(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<caf::CategoryLegend*>(m_visibleLegends.at(i));
if (categoryLegend)
{
hasCategoryLegend = true;
}
}
if (hasCategoryLegend)
{
m_rimView->updateCurrentTimeStepAndRedraw();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -95,6 +95,7 @@ public slots:
protected:
virtual void optimizeClippingPlanes();
virtual void resizeGL(int width, int height);
private:
void updateTextAndTickMarkColorForOverlayItems();