Make sure Ternary legends also expand and renamed width method.

This commit is contained in:
Gaute Lindkvist 2018-04-06 14:35:00 +02:00
parent 38aa447dcd
commit e93f79790e
6 changed files with 26 additions and 23 deletions

View File

@ -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<float>(size.y() - lineHeightInPixels - border);
float textPosY = static_cast<float>(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<float>( (size.x() / 2) - sgasTextWidth / 2 ), textPosY));
textDrawer.addText("SGAS", cvf::Vec2f(static_cast<float>( (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<float>( (size.x() / 2) - sgasRangeTextWidth / 2 ), textPosY));
textDrawer.addText(m_sgasRange, cvf::Vec2f(static_cast<float>( (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<float>(size.x() - soilTextWidth - border), lineHeightInPixels + border));
textDrawer.addText("SOIL", cvf::Vec2f(static_cast<float>(sizeMatched.x() - soilTextWidth - border), lineHeightInPixels + border));
cvf::uint soilRangeTextWidth = this->font()->textExtent(m_soilRange).x();
float soilRangePos = static_cast<float>(size.x()) - soilRangeTextWidth - border;
float soilRangePos = static_cast<float>(sizeMatched.x()) - soilRangeTextWidth - border;
textDrawer.addText(m_soilRange, cvf::Vec2f(soilRangePos, (float)border));
}

View File

@ -623,7 +623,7 @@ void RiuViewer::addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend
for (auto legend : m_visibleLegends)
{
legend->setWidth(requiredLegendWidth);
legend->setMatchedWidth(requiredLegendWidth);
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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;
}
//--------------------------------------------------------------------------------------------------

View File

@ -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;