Fixed background color setting for legends and refactored Legend class hierarchy

* Added a new cafTitledOverlayFrame as a base-class for all ResInsight legend classes
  * Inherits cvf::OverlayItem
This commit is contained in:
Gaute Lindkvist
2018-04-09 13:14:19 +02:00
parent 7a09b9a146
commit 507229f84b
14 changed files with 315 additions and 390 deletions
@@ -41,12 +41,7 @@
///
//--------------------------------------------------------------------------------------------------
RivTernarySaturationOverlayItem::RivTernarySaturationOverlayItem(cvf::Font* font)
: m_textColor(cvf::Color3::BLACK)
, m_font(font)
, m_size(120, 150)
, m_backgroundColor(1.0f, 1.0f, 1.0f, 0.8f)
, m_backgroundFrameColor(0.0f, 0.0f, 0.0f, 0.5f)
, m_isBackgroundEnabled(true)
: TitledOverlayFrame(font, 120, 150)
{
}
@@ -58,35 +53,14 @@ RivTernarySaturationOverlayItem::~RivTernarySaturationOverlayItem()
// Empty destructor to avoid errors with undefined types when cvf::ref's destructor gets called
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::setAxisLabelsColor(const cvf::Color3f& color)
{
m_textColor = color;
this->setTextColor(color);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec2ui RivTernarySaturationOverlayItem::sizeHint()
{
return m_size;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::setSize(const cvf::Vec2ui& size)
{
m_size = size;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -95,7 +69,6 @@ void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, con
renderGeneric(oglContext, position, size, false);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -104,7 +77,6 @@ void RivTernarySaturationOverlayItem::renderSoftware(cvf::OpenGLContext* oglCont
renderGeneric(oglContext, position, size, true);
}
//--------------------------------------------------------------------------------------------------
/// Set up camera/viewport and render
//--------------------------------------------------------------------------------------------------
@@ -127,14 +99,14 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
camera.applyOpenGL();
camera.viewport()->applyOpenGL(oglContext, cvf::Viewport::CLEAR_DEPTH);
if ( m_isBackgroundEnabled )
if ( this->backgroundEnabled() )
{
if ( software )
{
caf::InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext,
cvf::Vec2f(size),
m_backgroundColor,
m_backgroundFrameColor);
this->backgroundColor(),
this->backgroundFrameColor());
}
else
{
@@ -143,22 +115,22 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
caf::InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext,
matrixState,
cvf::Vec2f(size),
m_backgroundColor,
m_backgroundFrameColor);
this->backgroundColor(),
this->backgroundFrameColor());
}
border = 3.0f;
}
cvf::TextDrawer textDrawer(m_font.p());
textDrawer.setTextColor(m_textColor);
cvf::TextDrawer textDrawer(this->font());
textDrawer.setTextColor(this->textColor());
float lineHeightInPixels = (float)(m_font->textExtent("SWAT").y() + 2);
float lineHeightInPixels = (float)(this->font()->textExtent("SWAT").y() + 2);
float textPosY = static_cast<float>(size.y() - lineHeightInPixels);
for (size_t it = 0; it < m_titleStrings.size(); it++)
for (size_t it = 0; it < this->titleStrings().size(); it++)
{
cvf::Vec2f pos(border, textPosY);
textDrawer.addText(m_titleStrings[it], pos);
textDrawer.addText(this->titleStrings()[it], pos);
textPosY -= lineHeightInPixels;
}
@@ -169,10 +141,10 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
textPosY -= border;
{
cvf::uint sgasTextWidth = m_font->textExtent("SGAS").x();
cvf::uint sgasTextWidth = this->font()->textExtent("SGAS").x();
textDrawer.addText("SGAS", cvf::Vec2f(static_cast<float>( (size.x() / 2) - sgasTextWidth / 2 ), textPosY));
cvf::uint sgasRangeTextWidth = m_font->textExtent(m_sgasRange).x();
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));
}
@@ -181,10 +153,10 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
textDrawer.addText(m_swatRange, cvf::Vec2f((float)border, (float)border));
{
cvf::uint soilTextWidth = m_font->textExtent("SOIL").x();
cvf::uint soilTextWidth = this->font()->textExtent("SOIL").x();
textDrawer.addText("SOIL", cvf::Vec2f(static_cast<float>(size.x() - soilTextWidth - border), lineHeightInPixels + border));
cvf::uint soilRangeTextWidth = m_font->textExtent(m_soilRange).x();
cvf::uint soilRangeTextWidth = this->font()->textExtent(m_soilRange).x();
float soilRangePos = static_cast<float>(size.x()) - soilRangeTextWidth - border;
textDrawer.addText(m_soilRange, cvf::Vec2f(soilRangePos, (float)border));
@@ -220,11 +192,11 @@ void RivTernarySaturationOverlayItem::renderAxisImmediateMode(float upperBoundY,
cvf::Color3ub colB(cvf::Color3::GREEN);
cvf::Color3ub colC(cvf::Color3::RED);
//float upperBoundY = static_cast<float>(m_size.y() - 20);
//float upperBoundY = static_cast<float>(this->sizeHint().y() - 20);
cvf::Vec3f a(float(border), lowerBoundY, 0);
cvf::Vec3f b(static_cast<float>(m_size.x() - border), lowerBoundY, 0);
cvf::Vec3f c(static_cast<float>(m_size.x() / 2), upperBoundY, 0);
cvf::Vec3f b(static_cast<float>(this->sizeHint().x() - border), lowerBoundY, 0);
cvf::Vec3f c(static_cast<float>(this->sizeHint().x() / 2), upperBoundY, 0);
// Draw filled rectangle elements
@@ -272,44 +244,3 @@ void RivTernarySaturationOverlayItem::setRangeText(const cvf::String& soilRange,
m_sgasRange = sgasRange;
m_swatRange = swatRange;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::setTitle(const cvf::String& title)
{
// Title
if (title.isEmpty())
{
m_titleStrings.clear();
}
else
{
m_titleStrings = title.split("\n");
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::enableBackground(bool enable)
{
m_isBackgroundEnabled = enable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::setBackgroundColor(const cvf::Color4f& backgroundColor)
{
m_backgroundColor = backgroundColor;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::setBackgroundFrameColor(const cvf::Color4f& backgroundFrameColor)
{
m_backgroundFrameColor = backgroundFrameColor;
}
@@ -19,7 +19,7 @@
#pragma once
#include "cvfOverlayItem.h"
#include "cafTitledOverlayFrame.h"
#include "cvfMatrix4.h"
#include "cvfColor3.h"
#include "cvfColor4.h"
@@ -36,7 +36,7 @@ class Font;
//
//
//==================================================================================================
class RivTernarySaturationOverlayItem : public cvf::OverlayItem
class RivTernarySaturationOverlayItem : public caf::TitledOverlayFrame
{
public:
explicit RivTernarySaturationOverlayItem(cvf::Font* font);
@@ -44,16 +44,9 @@ public:
void setRangeText(const cvf::String& soilRange, const cvf::String& sgasRange, const cvf::String& swatRange);
void setSize(const cvf::Vec2ui& size);
void setAxisLabelsColor(const cvf::Color3f& color);
void setTitle(const cvf::String& title);
void enableBackground(bool enable);
void setBackgroundColor(const cvf::Color4f& backgroundColor);
void setBackgroundFrameColor(const cvf::Color4f& backgroundFrameColor);
private:
cvf::Vec2ui sizeHint() override;
void render(cvf::OpenGLContext* oglContext,
const cvf::Vec2i& position,
const cvf::Vec2ui& size) override;
@@ -68,19 +61,8 @@ private:
void renderAxisImmediateMode(float upperY, float lowerBoundY, float border, cvf::OpenGLContext* oglContext);
private:
cvf::Color3f m_textColor; // Text color
cvf::ref<cvf::Font> m_font;
bool m_isBackgroundEnabled;
cvf::Color4f m_backgroundColor;
cvf::Color4f m_backgroundFrameColor;
cvf::String m_soilRange;
cvf::String m_sgasRange;
cvf::String m_swatRange;
cvf::Vec2ui m_size; // Pixel size of draw area
std::vector<cvf::String> m_titleStrings;
};
@@ -573,7 +573,7 @@ void Rim2dIntersectionView::updateLegends()
RimGeoMechView * geoView = nullptr;
m_intersection->firstAncestorOrThisOfType(geoView);
cvf::OverlayItem* legend = nullptr;
caf::TitledOverlayFrame* legend = nullptr;
if (eclView)
{
@@ -32,6 +32,7 @@
#include "RimStimPlanColors.h"
#include "RimViewLinker.h"
#include "cafTitledOverlayFrame.h"
#include "cafCategoryLegend.h"
#include "cafCategoryMapper.h"
#include "cafOverlayScalarMapperLegend.h"
@@ -675,7 +676,7 @@ void RimLegendConfig::setTitle(const QString& title)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::OverlayItem* RimLegendConfig::legend()
caf::TitledOverlayFrame* RimLegendConfig::legend()
{
if (m_currentScalarMapper == m_categoryMapper)
{
@@ -41,6 +41,7 @@ namespace cvf
namespace caf
{
class TitledOverlayFrame;
class CategoryLegend;
class CategoryMapper;
class OverlayScalarMapperLegend;
@@ -119,7 +120,7 @@ public:
void setUiValuesFromLegendConfig(const RimLegendConfig* otherLegendConfig);
cvf::ScalarMapper* scalarMapper() { return m_currentScalarMapper.p(); }
cvf::OverlayItem* legend();
caf::TitledOverlayFrame* legend();
protected:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
+9 -3
View File
@@ -23,6 +23,7 @@
#include "RiaApplication.h"
#include "RiaBaseDefs.h"
#include "RiaColorTools.h"
#include "RiaPreferences.h"
#include "RiaRegressionTestRunner.h"
#include "RimCase.h"
@@ -40,6 +41,7 @@
#include "RiuSimpleHistogramWidget.h"
#include "RiuViewerCommands.h"
#include "cafTitledOverlayFrame.h"
#include "cafCategoryLegend.h"
#include "cafOverlayScalarMapperLegend.h"
#include "cafCeetronPlusNavigation.h"
@@ -534,9 +536,13 @@ void RiuViewer::removeAllColorLegends()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend)
void RiuViewer::addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend)
{
RiaApplication* app = RiaApplication::instance();
CVF_ASSERT(app);
RiaPreferences* preferences = app->preferences();
cvf::Rendering* firstRendering = m_mainRendering.p();
CVF_ASSERT(preferences);
CVF_ASSERT(firstRendering);
if (legend)
@@ -544,7 +550,7 @@ void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend)
updateLegendTextAndTickMarkColor(legend);
firstRendering->addOverlayItem(legend);
legend->enableBackground(preferences->showLegendBackground());
m_visibleLegends.push_back(legend);
}
@@ -552,7 +558,7 @@ void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend)
const size_t categoryThreshold = 13;
std::vector<caf::CategoryLegend*> categoryLegends;
std::vector<cvf::OverlayItem*> overlayItems;
std::vector<caf::TitledOverlayFrame*> overlayItems;
for (auto legend : m_visibleLegends)
{
legend->setLayout(cvf::OverlayItem::VERTICAL, cvf::OverlayItem::BOTTOM_LEFT);
+7 -2
View File
@@ -42,6 +42,11 @@ class QCDEStyle;
class QLabel;
class QProgressBar;
namespace caf
{
class TitledOverlayFrame;
}
namespace cvf
{
class Color3f;
@@ -91,7 +96,7 @@ public:
void showAnimationProgress(bool enable);
void removeAllColorLegends();
void addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend);
void addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend);
void enableNavigationRotation(bool disable);
void updateNavigationPolicy();
@@ -150,7 +155,7 @@ private:
cvf::ref<cvf::OverlayAxisCross> m_axisCross;
bool m_showAxisCross;
cvf::Collection<cvf::OverlayItem> m_visibleLegends;
cvf::Collection<caf::TitledOverlayFrame> m_visibleLegends;
cvf::Collection<cvf::OverlayItem> allOverlayItems();