mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
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:
@@ -41,12 +41,7 @@
|
|||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
RivTernarySaturationOverlayItem::RivTernarySaturationOverlayItem(cvf::Font* font)
|
RivTernarySaturationOverlayItem::RivTernarySaturationOverlayItem(cvf::Font* font)
|
||||||
: m_textColor(cvf::Color3::BLACK)
|
: TitledOverlayFrame(font, 120, 150)
|
||||||
, 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)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,35 +53,14 @@ RivTernarySaturationOverlayItem::~RivTernarySaturationOverlayItem()
|
|||||||
// Empty destructor to avoid errors with undefined types when cvf::ref's destructor gets called
|
// Empty destructor to avoid errors with undefined types when cvf::ref's destructor gets called
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RivTernarySaturationOverlayItem::setAxisLabelsColor(const cvf::Color3f& color)
|
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);
|
renderGeneric(oglContext, position, size, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -104,7 +77,6 @@ void RivTernarySaturationOverlayItem::renderSoftware(cvf::OpenGLContext* oglCont
|
|||||||
renderGeneric(oglContext, position, size, true);
|
renderGeneric(oglContext, position, size, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
/// Set up camera/viewport and render
|
/// Set up camera/viewport and render
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -127,14 +99,14 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
|
|||||||
camera.applyOpenGL();
|
camera.applyOpenGL();
|
||||||
camera.viewport()->applyOpenGL(oglContext, cvf::Viewport::CLEAR_DEPTH);
|
camera.viewport()->applyOpenGL(oglContext, cvf::Viewport::CLEAR_DEPTH);
|
||||||
|
|
||||||
if ( m_isBackgroundEnabled )
|
if ( this->backgroundEnabled() )
|
||||||
{
|
{
|
||||||
if ( software )
|
if ( software )
|
||||||
{
|
{
|
||||||
caf::InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext,
|
caf::InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext,
|
||||||
cvf::Vec2f(size),
|
cvf::Vec2f(size),
|
||||||
m_backgroundColor,
|
this->backgroundColor(),
|
||||||
m_backgroundFrameColor);
|
this->backgroundFrameColor());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -143,22 +115,22 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
|
|||||||
caf::InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext,
|
caf::InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext,
|
||||||
matrixState,
|
matrixState,
|
||||||
cvf::Vec2f(size),
|
cvf::Vec2f(size),
|
||||||
m_backgroundColor,
|
this->backgroundColor(),
|
||||||
m_backgroundFrameColor);
|
this->backgroundFrameColor());
|
||||||
}
|
}
|
||||||
border = 3.0f;
|
border = 3.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
cvf::TextDrawer textDrawer(m_font.p());
|
cvf::TextDrawer textDrawer(this->font());
|
||||||
textDrawer.setTextColor(m_textColor);
|
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);
|
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);
|
cvf::Vec2f pos(border, textPosY);
|
||||||
textDrawer.addText(m_titleStrings[it], pos);
|
textDrawer.addText(this->titleStrings()[it], pos);
|
||||||
|
|
||||||
textPosY -= lineHeightInPixels;
|
textPosY -= lineHeightInPixels;
|
||||||
}
|
}
|
||||||
@@ -169,10 +141,10 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
|
|||||||
textPosY -= border;
|
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));
|
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;
|
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>( (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));
|
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));
|
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;
|
float soilRangePos = static_cast<float>(size.x()) - soilRangeTextWidth - border;
|
||||||
|
|
||||||
textDrawer.addText(m_soilRange, cvf::Vec2f(soilRangePos, (float)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 colB(cvf::Color3::GREEN);
|
||||||
cvf::Color3ub colC(cvf::Color3::RED);
|
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 a(float(border), lowerBoundY, 0);
|
||||||
cvf::Vec3f b(static_cast<float>(m_size.x() - border), lowerBoundY, 0);
|
cvf::Vec3f b(static_cast<float>(this->sizeHint().x() - border), lowerBoundY, 0);
|
||||||
cvf::Vec3f c(static_cast<float>(m_size.x() / 2), upperBoundY, 0);
|
cvf::Vec3f c(static_cast<float>(this->sizeHint().x() / 2), upperBoundY, 0);
|
||||||
|
|
||||||
|
|
||||||
// Draw filled rectangle elements
|
// Draw filled rectangle elements
|
||||||
@@ -272,44 +244,3 @@ void RivTernarySaturationOverlayItem::setRangeText(const cvf::String& soilRange,
|
|||||||
m_sgasRange = sgasRange;
|
m_sgasRange = sgasRange;
|
||||||
m_swatRange = swatRange;
|
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
|
#pragma once
|
||||||
|
|
||||||
#include "cvfOverlayItem.h"
|
#include "cafTitledOverlayFrame.h"
|
||||||
#include "cvfMatrix4.h"
|
#include "cvfMatrix4.h"
|
||||||
#include "cvfColor3.h"
|
#include "cvfColor3.h"
|
||||||
#include "cvfColor4.h"
|
#include "cvfColor4.h"
|
||||||
@@ -36,7 +36,7 @@ class Font;
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class RivTernarySaturationOverlayItem : public cvf::OverlayItem
|
class RivTernarySaturationOverlayItem : public caf::TitledOverlayFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit RivTernarySaturationOverlayItem(cvf::Font* font);
|
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 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 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:
|
private:
|
||||||
cvf::Vec2ui sizeHint() override;
|
|
||||||
void render(cvf::OpenGLContext* oglContext,
|
void render(cvf::OpenGLContext* oglContext,
|
||||||
const cvf::Vec2i& position,
|
const cvf::Vec2i& position,
|
||||||
const cvf::Vec2ui& size) override;
|
const cvf::Vec2ui& size) override;
|
||||||
@@ -68,19 +61,8 @@ private:
|
|||||||
void renderAxisImmediateMode(float upperY, float lowerBoundY, float border, cvf::OpenGLContext* oglContext);
|
void renderAxisImmediateMode(float upperY, float lowerBoundY, float border, cvf::OpenGLContext* oglContext);
|
||||||
|
|
||||||
private:
|
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_soilRange;
|
||||||
cvf::String m_sgasRange;
|
cvf::String m_sgasRange;
|
||||||
cvf::String m_swatRange;
|
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;
|
RimGeoMechView * geoView = nullptr;
|
||||||
m_intersection->firstAncestorOrThisOfType(geoView);
|
m_intersection->firstAncestorOrThisOfType(geoView);
|
||||||
|
|
||||||
cvf::OverlayItem* legend = nullptr;
|
caf::TitledOverlayFrame* legend = nullptr;
|
||||||
|
|
||||||
if (eclView)
|
if (eclView)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "RimStimPlanColors.h"
|
#include "RimStimPlanColors.h"
|
||||||
#include "RimViewLinker.h"
|
#include "RimViewLinker.h"
|
||||||
|
|
||||||
|
#include "cafTitledOverlayFrame.h"
|
||||||
#include "cafCategoryLegend.h"
|
#include "cafCategoryLegend.h"
|
||||||
#include "cafCategoryMapper.h"
|
#include "cafCategoryMapper.h"
|
||||||
#include "cafOverlayScalarMapperLegend.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)
|
if (m_currentScalarMapper == m_categoryMapper)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ namespace cvf
|
|||||||
|
|
||||||
namespace caf
|
namespace caf
|
||||||
{
|
{
|
||||||
|
class TitledOverlayFrame;
|
||||||
class CategoryLegend;
|
class CategoryLegend;
|
||||||
class CategoryMapper;
|
class CategoryMapper;
|
||||||
class OverlayScalarMapperLegend;
|
class OverlayScalarMapperLegend;
|
||||||
@@ -119,7 +120,7 @@ public:
|
|||||||
void setUiValuesFromLegendConfig(const RimLegendConfig* otherLegendConfig);
|
void setUiValuesFromLegendConfig(const RimLegendConfig* otherLegendConfig);
|
||||||
|
|
||||||
cvf::ScalarMapper* scalarMapper() { return m_currentScalarMapper.p(); }
|
cvf::ScalarMapper* scalarMapper() { return m_currentScalarMapper.p(); }
|
||||||
cvf::OverlayItem* legend();
|
caf::TitledOverlayFrame* legend();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "RiaApplication.h"
|
#include "RiaApplication.h"
|
||||||
#include "RiaBaseDefs.h"
|
#include "RiaBaseDefs.h"
|
||||||
#include "RiaColorTools.h"
|
#include "RiaColorTools.h"
|
||||||
|
#include "RiaPreferences.h"
|
||||||
#include "RiaRegressionTestRunner.h"
|
#include "RiaRegressionTestRunner.h"
|
||||||
|
|
||||||
#include "RimCase.h"
|
#include "RimCase.h"
|
||||||
@@ -40,6 +41,7 @@
|
|||||||
#include "RiuSimpleHistogramWidget.h"
|
#include "RiuSimpleHistogramWidget.h"
|
||||||
#include "RiuViewerCommands.h"
|
#include "RiuViewerCommands.h"
|
||||||
|
|
||||||
|
#include "cafTitledOverlayFrame.h"
|
||||||
#include "cafCategoryLegend.h"
|
#include "cafCategoryLegend.h"
|
||||||
#include "cafOverlayScalarMapperLegend.h"
|
#include "cafOverlayScalarMapperLegend.h"
|
||||||
#include "cafCeetronPlusNavigation.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::Rendering* firstRendering = m_mainRendering.p();
|
||||||
|
CVF_ASSERT(preferences);
|
||||||
CVF_ASSERT(firstRendering);
|
CVF_ASSERT(firstRendering);
|
||||||
|
|
||||||
if (legend)
|
if (legend)
|
||||||
@@ -544,7 +550,7 @@ void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend)
|
|||||||
updateLegendTextAndTickMarkColor(legend);
|
updateLegendTextAndTickMarkColor(legend);
|
||||||
|
|
||||||
firstRendering->addOverlayItem(legend);
|
firstRendering->addOverlayItem(legend);
|
||||||
|
legend->enableBackground(preferences->showLegendBackground());
|
||||||
m_visibleLegends.push_back(legend);
|
m_visibleLegends.push_back(legend);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,7 +558,7 @@ void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend)
|
|||||||
const size_t categoryThreshold = 13;
|
const size_t categoryThreshold = 13;
|
||||||
|
|
||||||
std::vector<caf::CategoryLegend*> categoryLegends;
|
std::vector<caf::CategoryLegend*> categoryLegends;
|
||||||
std::vector<cvf::OverlayItem*> overlayItems;
|
std::vector<caf::TitledOverlayFrame*> overlayItems;
|
||||||
for (auto legend : m_visibleLegends)
|
for (auto legend : m_visibleLegends)
|
||||||
{
|
{
|
||||||
legend->setLayout(cvf::OverlayItem::VERTICAL, cvf::OverlayItem::BOTTOM_LEFT);
|
legend->setLayout(cvf::OverlayItem::VERTICAL, cvf::OverlayItem::BOTTOM_LEFT);
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ class QCDEStyle;
|
|||||||
class QLabel;
|
class QLabel;
|
||||||
class QProgressBar;
|
class QProgressBar;
|
||||||
|
|
||||||
|
namespace caf
|
||||||
|
{
|
||||||
|
class TitledOverlayFrame;
|
||||||
|
}
|
||||||
|
|
||||||
namespace cvf
|
namespace cvf
|
||||||
{
|
{
|
||||||
class Color3f;
|
class Color3f;
|
||||||
@@ -91,7 +96,7 @@ public:
|
|||||||
void showAnimationProgress(bool enable);
|
void showAnimationProgress(bool enable);
|
||||||
|
|
||||||
void removeAllColorLegends();
|
void removeAllColorLegends();
|
||||||
void addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend);
|
void addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend);
|
||||||
|
|
||||||
void enableNavigationRotation(bool disable);
|
void enableNavigationRotation(bool disable);
|
||||||
void updateNavigationPolicy();
|
void updateNavigationPolicy();
|
||||||
@@ -150,7 +155,7 @@ private:
|
|||||||
|
|
||||||
cvf::ref<cvf::OverlayAxisCross> m_axisCross;
|
cvf::ref<cvf::OverlayAxisCross> m_axisCross;
|
||||||
bool m_showAxisCross;
|
bool m_showAxisCross;
|
||||||
cvf::Collection<cvf::OverlayItem> m_visibleLegends;
|
cvf::Collection<caf::TitledOverlayFrame> m_visibleLegends;
|
||||||
cvf::Collection<cvf::OverlayItem> allOverlayItems();
|
cvf::Collection<cvf::OverlayItem> allOverlayItems();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ add_library( ${PROJECT_NAME}
|
|||||||
cafBoxManipulatorPartManager.h
|
cafBoxManipulatorPartManager.h
|
||||||
cafBoxManipulatorGeometryGenerator.cpp
|
cafBoxManipulatorGeometryGenerator.cpp
|
||||||
cafBoxManipulatorGeometryGenerator.h
|
cafBoxManipulatorGeometryGenerator.h
|
||||||
|
cafTitledOverlayFrame.cpp
|
||||||
|
cafTitledOverlayFrame.h
|
||||||
cafCategoryLegend.cpp
|
cafCategoryLegend.cpp
|
||||||
cafCategoryLegend.h
|
cafCategoryLegend.h
|
||||||
cafOverlayScalarMapperLegend.h
|
cafOverlayScalarMapperLegend.h
|
||||||
|
|||||||
@@ -39,15 +39,8 @@ namespace caf {
|
|||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
CategoryLegend::CategoryLegend(Font* font, const CategoryMapper* categoryMapper)
|
CategoryLegend::CategoryLegend(Font* font, const CategoryMapper* categoryMapper)
|
||||||
: m_sizeHint(200, 200),
|
: TitledOverlayFrame(font, 200, 200)
|
||||||
m_textColor(Color3::BLACK),
|
, m_categoryMapper(categoryMapper)
|
||||||
m_lineColor(Color3::BLACK),
|
|
||||||
m_backgroundColor(1.0f, 1.0f, 1.0f, 0.8f),
|
|
||||||
m_backgroundFrameColor(0.0f, 0.0f, 0.0f, 0.5f),
|
|
||||||
m_isBackgroundEnabled(true),
|
|
||||||
m_lineWidth(1),
|
|
||||||
m_font(font),
|
|
||||||
m_categoryMapper(categoryMapper)
|
|
||||||
{
|
{
|
||||||
CVF_ASSERT(font);
|
CVF_ASSERT(font);
|
||||||
CVF_ASSERT(!font->isEmpty());
|
CVF_ASSERT(!font->isEmpty());
|
||||||
@@ -61,48 +54,6 @@ CategoryLegend::~CategoryLegend()
|
|||||||
// Empty destructor to avoid errors with undefined types when cvf::ref's destructor gets called
|
// Empty destructor to avoid errors with undefined types when cvf::ref's destructor gets called
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
cvf::Vec2ui CategoryLegend::sizeHint()
|
|
||||||
{
|
|
||||||
return m_sizeHint;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void CategoryLegend::setSizeHint(const Vec2ui& size)
|
|
||||||
{
|
|
||||||
m_sizeHint = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
/// Set color of the text
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void CategoryLegend::setTextColor(const Color3f& color)
|
|
||||||
{
|
|
||||||
m_textColor = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
/// Set the title (text that will be rendered above the legend)
|
|
||||||
///
|
|
||||||
/// The legend supports multi-line titles. Separate each line with a '\n' character
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void CategoryLegend::setTitle(const String& title)
|
|
||||||
{
|
|
||||||
// Title
|
|
||||||
if (title.isEmpty())
|
|
||||||
{
|
|
||||||
m_titleStrings.clear();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_titleStrings = title.split("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -184,7 +135,7 @@ void CategoryLegend::renderGeneric(OpenGLContext* oglContext,
|
|||||||
|
|
||||||
// Set up text drawer
|
// Set up text drawer
|
||||||
float maxLegendRightPos = 0;
|
float maxLegendRightPos = 0;
|
||||||
TextDrawer textDrawer(m_font.p());
|
TextDrawer textDrawer(this->font());
|
||||||
setupTextDrawer(&textDrawer, &layout, &maxLegendRightPos);
|
setupTextDrawer(&textDrawer, &layout, &maxLegendRightPos);
|
||||||
|
|
||||||
Vec2f backgroundSize(CVF_MIN(maxLegendRightPos + 3.0f, (float)size.x()), (float)size.y());
|
Vec2f backgroundSize(CVF_MIN(maxLegendRightPos + 3.0f, (float)size.x()), (float)size.y());
|
||||||
@@ -192,21 +143,21 @@ void CategoryLegend::renderGeneric(OpenGLContext* oglContext,
|
|||||||
// Do the actual rendering
|
// Do the actual rendering
|
||||||
if (software)
|
if (software)
|
||||||
{
|
{
|
||||||
if (m_isBackgroundEnabled) InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext,
|
if (this->backgroundEnabled()) InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext,
|
||||||
backgroundSize,
|
backgroundSize,
|
||||||
m_backgroundColor,
|
this->backgroundColor(),
|
||||||
m_backgroundFrameColor);
|
this->backgroundFrameColor());
|
||||||
renderLegendImmediateMode(oglContext, &layout);
|
renderLegendImmediateMode(oglContext, &layout);
|
||||||
textDrawer.renderSoftware(oglContext, camera);
|
textDrawer.renderSoftware(oglContext, camera);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const MatrixState matrixState(camera);
|
const MatrixState matrixState(camera);
|
||||||
if (m_isBackgroundEnabled) InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext,
|
if (this->backgroundEnabled()) InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext,
|
||||||
matrixState,
|
matrixState,
|
||||||
backgroundSize,
|
backgroundSize,
|
||||||
m_backgroundColor,
|
this->backgroundColor(),
|
||||||
m_backgroundFrameColor);
|
this->backgroundFrameColor());
|
||||||
renderLegendUsingShaders(oglContext, &layout, matrixState);
|
renderLegendUsingShaders(oglContext, &layout, matrixState);
|
||||||
textDrawer.render(oglContext, camera);
|
textDrawer.render(oglContext, camera);
|
||||||
}
|
}
|
||||||
@@ -231,7 +182,7 @@ void CategoryLegend::setupTextDrawer(TextDrawer* textDrawer,
|
|||||||
float legendRight = 0.0f;
|
float legendRight = 0.0f;
|
||||||
|
|
||||||
textDrawer->setVerticalAlignment(TextDrawer::CENTER);
|
textDrawer->setVerticalAlignment(TextDrawer::CENTER);
|
||||||
textDrawer->setTextColor(m_textColor);
|
textDrawer->setTextColor(this->textColor());
|
||||||
|
|
||||||
m_visibleCategoryLabels.clear();
|
m_visibleCategoryLabels.clear();
|
||||||
|
|
||||||
@@ -274,7 +225,7 @@ void CategoryLegend::setupTextDrawer(TextDrawer* textDrawer,
|
|||||||
Vec2f pos(textX, textY);
|
Vec2f pos(textX, textY);
|
||||||
textDrawer->addText(displayText, pos);
|
textDrawer->addText(displayText, pos);
|
||||||
|
|
||||||
float neededRightPos = pos.x() + m_font->textExtent(displayText).x();
|
float neededRightPos = pos.x() + this->font()->textExtent(displayText).x();
|
||||||
legendRight = legendRight >= neededRightPos ? legendRight :neededRightPos;
|
legendRight = legendRight >= neededRightPos ? legendRight :neededRightPos;
|
||||||
|
|
||||||
lastVisibleTextY = textY;
|
lastVisibleTextY = textY;
|
||||||
@@ -282,12 +233,12 @@ void CategoryLegend::setupTextDrawer(TextDrawer* textDrawer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
float titleY = static_cast<float>(layout->size.y()) - layout->margins.y() - layout->charHeight / 2.0f;
|
float titleY = static_cast<float>(layout->size.y()) - layout->margins.y() - layout->charHeight / 2.0f;
|
||||||
for (size_t it = 0; it < m_titleStrings.size(); it++)
|
for (size_t it = 0; it < this->titleStrings().size(); it++)
|
||||||
{
|
{
|
||||||
Vec2f pos(layout->margins.x(), titleY);
|
Vec2f pos(layout->margins.x(), titleY);
|
||||||
textDrawer->addText(m_titleStrings[it], pos);
|
textDrawer->addText(this->titleStrings()[it], pos);
|
||||||
|
|
||||||
float neededRightPos = pos.x() + m_font->textExtent(m_titleStrings[it]).x();
|
float neededRightPos = pos.x() + this->font()->textExtent(this->titleStrings()[it]).x();
|
||||||
legendRight = legendRight >= neededRightPos ? legendRight :neededRightPos;
|
legendRight = legendRight >= neededRightPos ? legendRight :neededRightPos;
|
||||||
|
|
||||||
titleY -= layout->lineSpacing;
|
titleY -= layout->lineSpacing;
|
||||||
@@ -311,7 +262,7 @@ void CategoryLegend::renderLegendUsingShaders(OpenGLContext* oglContext,
|
|||||||
|
|
||||||
RenderStateDepth depth(false);
|
RenderStateDepth depth(false);
|
||||||
depth.applyOpenGL(oglContext);
|
depth.applyOpenGL(oglContext);
|
||||||
RenderStateLine line(static_cast<float>(m_lineWidth));
|
RenderStateLine line(static_cast<float>(this->lineWidth()));
|
||||||
line.applyOpenGL(oglContext);
|
line.applyOpenGL(oglContext);
|
||||||
|
|
||||||
// All vertices. Initialized here to set Z to zero once and for all.
|
// All vertices. Initialized here to set Z to zero once and for all.
|
||||||
@@ -393,7 +344,7 @@ void CategoryLegend::renderLegendUsingShaders(OpenGLContext* oglContext,
|
|||||||
v2[1] = v3[1] = layout->legendRect.max().y() - 0.5f;
|
v2[1] = v3[1] = layout->legendRect.max().y() - 0.5f;
|
||||||
static const ushort frameConnects[] = { 0, 1, 1, 3, 3, 2, 2, 0 };
|
static const ushort frameConnects[] = { 0, 1, 1, 3, 3, 2, 2, 0 };
|
||||||
|
|
||||||
UniformFloat uniformColor("u_color", Color4f(m_lineColor));
|
UniformFloat uniformColor("u_color", Color4f(this->lineColor()));
|
||||||
shaderProgram->applyUniform(oglContext, uniformColor);
|
shaderProgram->applyUniform(oglContext, uniformColor);
|
||||||
|
|
||||||
#ifdef CVF_OPENGL_ES
|
#ifdef CVF_OPENGL_ES
|
||||||
@@ -497,7 +448,7 @@ void CategoryLegend::renderLegendImmediateMode(OpenGLContext* oglContext, Overla
|
|||||||
v0[1] = v1[1] = layout->legendRect.min().y() - 0.5f;
|
v0[1] = v1[1] = layout->legendRect.min().y() - 0.5f;
|
||||||
v2[1] = v3[1] = layout->legendRect.max().y() - 0.5f;
|
v2[1] = v3[1] = layout->legendRect.max().y() - 0.5f;
|
||||||
|
|
||||||
glColor3fv(m_textColor.ptr());
|
glColor3fv(this->textColor().ptr());
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glVertex3fv(v0);
|
glVertex3fv(v0);
|
||||||
glVertex3fv(v1);
|
glVertex3fv(v1);
|
||||||
@@ -528,13 +479,13 @@ void CategoryLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout)
|
|||||||
{
|
{
|
||||||
CVF_TIGHT_ASSERT(layout);
|
CVF_TIGHT_ASSERT(layout);
|
||||||
|
|
||||||
ref<Glyph> glyph = m_font->getGlyph(L'A');
|
ref<Glyph> glyph = this->font()->getGlyph(L'A');
|
||||||
layout->charHeight = static_cast<float>(glyph->height());
|
layout->charHeight = static_cast<float>(glyph->height());
|
||||||
layout->lineSpacing = layout->charHeight*1.5f;
|
layout->lineSpacing = layout->charHeight*1.5f;
|
||||||
layout->margins = Vec2f(4.0f, 4.0f);
|
layout->margins = Vec2f(4.0f, 4.0f);
|
||||||
|
|
||||||
float legendWidth = 25.0f;
|
float legendWidth = 25.0f;
|
||||||
float legendHeight = static_cast<float>(layout->size.y()) - 2 * layout->margins.y() - static_cast<float>(m_titleStrings.size())*layout->lineSpacing - layout->lineSpacing;
|
float legendHeight = static_cast<float>(layout->size.y()) - 2 * layout->margins.y() - static_cast<float>(this->titleStrings().size())*layout->lineSpacing - layout->lineSpacing;
|
||||||
layout->legendRect = Rectf(layout->margins.x(), layout->margins.y() + layout->charHeight / 2.0f, legendWidth, legendHeight);
|
layout->legendRect = Rectf(layout->margins.x(), layout->margins.y() + layout->charHeight / 2.0f, legendWidth, legendHeight);
|
||||||
|
|
||||||
if (layout->legendRect.width() < 1 || layout->legendRect.height() < 1)
|
if (layout->legendRect.width() < 1 || layout->legendRect.height() < 1)
|
||||||
@@ -547,46 +498,6 @@ void CategoryLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout)
|
|||||||
layout->tickX = layout->x1 + 5;
|
layout->tickX = layout->x1 + 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void CategoryLegend::setLineColor(const Color3f& lineColor)
|
|
||||||
{
|
|
||||||
m_lineColor = lineColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void CategoryLegend::setLineWidth(int lineWidth)
|
|
||||||
{
|
|
||||||
m_lineWidth = lineWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void CategoryLegend::setBackgroundColor(const Color4f& backgroundColor)
|
|
||||||
{
|
|
||||||
m_backgroundColor = backgroundColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void CategoryLegend::setBackgroundFrameColor(const Color4f& backgroundFrameColor)
|
|
||||||
{
|
|
||||||
m_backgroundFrameColor = backgroundFrameColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void CategoryLegend::enableBackground(bool enable)
|
|
||||||
{
|
|
||||||
m_isBackgroundEnabled = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "cafTitledOverlayFrame.h"
|
||||||
#include "cvfBase.h"
|
#include "cvfBase.h"
|
||||||
#include "cvfArray.h"
|
#include "cvfArray.h"
|
||||||
#include "cvfCamera.h"
|
#include "cvfCamera.h"
|
||||||
@@ -23,27 +24,15 @@ class CategoryMapper;
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class CategoryLegend : public cvf::OverlayItem
|
class CategoryLegend : public caf::TitledOverlayFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CategoryLegend(cvf::Font* font, const CategoryMapper* categoryMapper);
|
CategoryLegend(cvf::Font* font, const CategoryMapper* categoryMapper);
|
||||||
virtual ~CategoryLegend();
|
virtual ~CategoryLegend();
|
||||||
|
|
||||||
void setSizeHint(const cvf::Vec2ui& size);
|
|
||||||
|
|
||||||
void setTextColor(const cvf::Color3f& color);
|
|
||||||
void setLineColor(const cvf::Color3f& lineColor);
|
|
||||||
void setLineWidth(int lineWidth);
|
|
||||||
void setTitle(const cvf::String& title);
|
|
||||||
|
|
||||||
void enableBackground(bool enable);
|
|
||||||
void setBackgroundColor(const cvf::Color4f& backgroundColor);
|
|
||||||
void setBackgroundFrameColor(const cvf::Color4f& backgroundFrameColor);
|
|
||||||
|
|
||||||
size_t categoryCount() const;
|
size_t categoryCount() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
cvf::Vec2ui sizeHint() override;
|
|
||||||
void render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size) override;
|
void render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size) override;
|
||||||
void renderSoftware(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size) override;
|
void renderSoftware(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size) override;
|
||||||
bool pick(int oglXCoord, int oglYCoord, const cvf::Vec2i& position, const cvf::Vec2ui& size) override;
|
bool pick(int oglXCoord, int oglYCoord, const cvf::Vec2i& position, const cvf::Vec2ui& size) override;
|
||||||
@@ -93,18 +82,6 @@ protected:
|
|||||||
protected:
|
protected:
|
||||||
std::vector<bool> m_visibleCategoryLabels; // Skip labels ending up on top of previous visible label
|
std::vector<bool> m_visibleCategoryLabels; // Skip labels ending up on top of previous visible label
|
||||||
|
|
||||||
cvf::Vec2ui m_sizeHint; // Pixel size of the color legend area
|
|
||||||
|
|
||||||
cvf::Color3f m_textColor;
|
|
||||||
cvf::Color3f m_lineColor;
|
|
||||||
int m_lineWidth;
|
|
||||||
std::vector<cvf::String> m_titleStrings;
|
|
||||||
cvf::ref<cvf::Font> m_font;
|
|
||||||
|
|
||||||
bool m_isBackgroundEnabled;
|
|
||||||
cvf::Color4f m_backgroundColor;
|
|
||||||
cvf::Color4f m_backgroundFrameColor;
|
|
||||||
|
|
||||||
cvf::cref<CategoryMapper> m_categoryMapper;
|
cvf::cref<CategoryMapper> m_categoryMapper;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -83,16 +83,9 @@ using namespace cvf;
|
|||||||
/// Constructor
|
/// Constructor
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
OverlayScalarMapperLegend::OverlayScalarMapperLegend(Font* font)
|
OverlayScalarMapperLegend::OverlayScalarMapperLegend(Font* font)
|
||||||
: m_sizeHint(200, 200),
|
: TitledOverlayFrame(font, 200, 200)
|
||||||
m_textColor(Color3::BLACK),
|
, m_tickNumberPrecision(4)
|
||||||
m_lineColor(Color3::BLACK),
|
, m_numberFormat(AUTO)
|
||||||
m_backgroundColor(1.0f, 1.0f, 1.0f, 0.8f),
|
|
||||||
m_backgroundFrameColor(0.0f, 0.0f, 0.0f, 0.5f),
|
|
||||||
m_isBackgroundEnabled(true),
|
|
||||||
m_lineWidth(1),
|
|
||||||
m_font(font),
|
|
||||||
m_tickNumberPrecision(4),
|
|
||||||
m_numberFormat(AUTO)
|
|
||||||
{
|
{
|
||||||
CVF_ASSERT(font);
|
CVF_ASSERT(font);
|
||||||
CVF_ASSERT(!font->isEmpty());
|
CVF_ASSERT(!font->isEmpty());
|
||||||
@@ -112,16 +105,6 @@ OverlayScalarMapperLegend::~OverlayScalarMapperLegend()
|
|||||||
// Empty destructor to avoid errors with undefined types when cvf::ref's destructor gets called
|
// Empty destructor to avoid errors with undefined types when cvf::ref's destructor gets called
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
cvf::Vec2ui OverlayScalarMapperLegend::sizeHint()
|
|
||||||
{
|
|
||||||
return m_sizeHint;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -138,43 +121,6 @@ void OverlayScalarMapperLegend::setScalarMapper(const ScalarMapper* scalarMapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void OverlayScalarMapperLegend::setSizeHint(const Vec2ui& size)
|
|
||||||
{
|
|
||||||
m_sizeHint = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
/// Set color of the text
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void OverlayScalarMapperLegend::setTextColor(const Color3f& color)
|
|
||||||
{
|
|
||||||
m_textColor = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
/// Set the title (text that will be rendered above the legend)
|
|
||||||
///
|
|
||||||
/// The legend supports multi-line titles. Separate each line with a '\n' character
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void OverlayScalarMapperLegend::setTitle(const String& title)
|
|
||||||
{
|
|
||||||
// Title
|
|
||||||
if (title.isEmpty())
|
|
||||||
{
|
|
||||||
m_titleStrings.clear();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_titleStrings = title.split("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
/// Hardware rendering using shader programs
|
/// Hardware rendering using shader programs
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -243,7 +189,7 @@ void OverlayScalarMapperLegend::renderGeneric(OpenGLContext* oglContext, const V
|
|||||||
|
|
||||||
// Set up text drawer
|
// Set up text drawer
|
||||||
float maxLegendRightPos = 0;
|
float maxLegendRightPos = 0;
|
||||||
TextDrawer textDrawer(m_font.p());
|
TextDrawer textDrawer(this->font());
|
||||||
setupTextDrawer(&textDrawer, &layout, &maxLegendRightPos);
|
setupTextDrawer(&textDrawer, &layout, &maxLegendRightPos);
|
||||||
|
|
||||||
Vec2f backgroundSize(CVF_MIN(maxLegendRightPos + 3.0f, (float)size.x()), (float)size.y());
|
Vec2f backgroundSize(CVF_MIN(maxLegendRightPos + 3.0f, (float)size.x()), (float)size.y());
|
||||||
@@ -251,14 +197,14 @@ void OverlayScalarMapperLegend::renderGeneric(OpenGLContext* oglContext, const V
|
|||||||
// Do the actual rendering
|
// Do the actual rendering
|
||||||
if (software)
|
if (software)
|
||||||
{
|
{
|
||||||
if (m_isBackgroundEnabled) InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext, backgroundSize, m_backgroundColor, m_backgroundFrameColor);
|
if (this->backgroundEnabled()) InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext, backgroundSize, this->backgroundColor(), this->backgroundFrameColor());
|
||||||
renderLegendImmediateMode(oglContext, &layout);
|
renderLegendImmediateMode(oglContext, &layout);
|
||||||
textDrawer.renderSoftware(oglContext, camera);
|
textDrawer.renderSoftware(oglContext, camera);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const MatrixState matrixState(camera);
|
const MatrixState matrixState(camera);
|
||||||
if (m_isBackgroundEnabled) InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext, matrixState, backgroundSize, m_backgroundColor, m_backgroundFrameColor);
|
if (this->backgroundEnabled()) InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext, matrixState, backgroundSize, this->backgroundColor(), this->backgroundFrameColor());
|
||||||
renderLegendUsingShaders(oglContext, &layout, matrixState);
|
renderLegendUsingShaders(oglContext, &layout, matrixState);
|
||||||
textDrawer.render(oglContext, camera);
|
textDrawer.render(oglContext, camera);
|
||||||
}
|
}
|
||||||
@@ -277,7 +223,7 @@ void OverlayScalarMapperLegend::setupTextDrawer(TextDrawer* textDrawer, const Ov
|
|||||||
float legendRight = 0.0f;
|
float legendRight = 0.0f;
|
||||||
|
|
||||||
textDrawer->setVerticalAlignment(TextDrawer::CENTER);
|
textDrawer->setVerticalAlignment(TextDrawer::CENTER);
|
||||||
textDrawer->setTextColor(m_textColor);
|
textDrawer->setTextColor(this->textColor());
|
||||||
|
|
||||||
m_visibleTickLabels.clear();
|
m_visibleTickLabels.clear();
|
||||||
|
|
||||||
@@ -330,7 +276,7 @@ void OverlayScalarMapperLegend::setupTextDrawer(TextDrawer* textDrawer, const Ov
|
|||||||
Vec2f pos(textX, textY);
|
Vec2f pos(textX, textY);
|
||||||
textDrawer->addText(valueString, pos);
|
textDrawer->addText(valueString, pos);
|
||||||
|
|
||||||
float neededRightPos = pos.x() + m_font->textExtent(valueString).x();
|
float neededRightPos = pos.x() + this->font()->textExtent(valueString).x();
|
||||||
legendRight = legendRight >= neededRightPos ? legendRight :neededRightPos;
|
legendRight = legendRight >= neededRightPos ? legendRight :neededRightPos;
|
||||||
|
|
||||||
lastVisibleTextY = textY;
|
lastVisibleTextY = textY;
|
||||||
@@ -338,12 +284,12 @@ void OverlayScalarMapperLegend::setupTextDrawer(TextDrawer* textDrawer, const Ov
|
|||||||
}
|
}
|
||||||
|
|
||||||
float titleY = static_cast<float>(layout->size.y()) - layout->margins.y() - layout->charHeight/2.0f;
|
float titleY = static_cast<float>(layout->size.y()) - layout->margins.y() - layout->charHeight/2.0f;
|
||||||
for (it = 0; it < m_titleStrings.size(); it++)
|
for (it = 0; it < this->titleStrings().size(); it++)
|
||||||
{
|
{
|
||||||
Vec2f pos(layout->margins.x(), titleY);
|
Vec2f pos(layout->margins.x(), titleY);
|
||||||
textDrawer->addText(m_titleStrings[it], pos);
|
textDrawer->addText(this->titleStrings()[it], pos);
|
||||||
|
|
||||||
float neededRightPos = pos.x() + m_font->textExtent(m_titleStrings[it]).x();
|
float neededRightPos = pos.x() + this->font()->textExtent(this->titleStrings()[it]).x();
|
||||||
legendRight = legendRight >= neededRightPos ? legendRight :neededRightPos;
|
legendRight = legendRight >= neededRightPos ? legendRight :neededRightPos;
|
||||||
|
|
||||||
|
|
||||||
@@ -367,7 +313,7 @@ void OverlayScalarMapperLegend::renderLegendUsingShaders(OpenGLContext* oglConte
|
|||||||
|
|
||||||
RenderStateDepth depth(false);
|
RenderStateDepth depth(false);
|
||||||
depth.applyOpenGL(oglContext);
|
depth.applyOpenGL(oglContext);
|
||||||
RenderStateLine line(static_cast<float>(m_lineWidth));
|
RenderStateLine line(static_cast<float>(this->lineWidth()));
|
||||||
line.applyOpenGL(oglContext);
|
line.applyOpenGL(oglContext);
|
||||||
|
|
||||||
// All vertices. Initialized here to set Z to zero once and for all.
|
// All vertices. Initialized here to set Z to zero once and for all.
|
||||||
@@ -449,7 +395,7 @@ void OverlayScalarMapperLegend::renderLegendUsingShaders(OpenGLContext* oglConte
|
|||||||
v2[1] = v3[1] = layout->legendRect.max().y()-0.5f;
|
v2[1] = v3[1] = layout->legendRect.max().y()-0.5f;
|
||||||
static const ushort frameConnects[] = { 0, 1, 1, 3, 3, 2, 2, 0};
|
static const ushort frameConnects[] = { 0, 1, 1, 3, 3, 2, 2, 0};
|
||||||
|
|
||||||
UniformFloat uniformColor("u_color", Color4f(m_lineColor));
|
UniformFloat uniformColor("u_color", Color4f(this->lineColor()));
|
||||||
shaderProgram->applyUniform(oglContext, uniformColor);
|
shaderProgram->applyUniform(oglContext, uniformColor);
|
||||||
|
|
||||||
#ifdef CVF_OPENGL_ES
|
#ifdef CVF_OPENGL_ES
|
||||||
@@ -482,7 +428,7 @@ void OverlayScalarMapperLegend::renderLegendUsingShaders(OpenGLContext* oglConte
|
|||||||
// Dynamic coordinates for tickmarks-lines
|
// Dynamic coordinates for tickmarks-lines
|
||||||
v0[1] = v1[1] = v2[1] = v3[1] = v4[1] = y0;
|
v0[1] = v1[1] = v2[1] = v3[1] = v4[1] = y0;
|
||||||
|
|
||||||
UniformFloat uniformColor("u_color", Color4f(m_lineColor));
|
UniformFloat uniformColor("u_color", Color4f(this->lineColor()));
|
||||||
shaderProgram->applyUniform(oglContext, uniformColor);
|
shaderProgram->applyUniform(oglContext, uniformColor);
|
||||||
const ushort * linesConnects;
|
const ushort * linesConnects;
|
||||||
|
|
||||||
@@ -597,7 +543,7 @@ void OverlayScalarMapperLegend::renderLegendImmediateMode(OpenGLContext* oglCont
|
|||||||
v0[1] = v1[1] = layout->legendRect.min().y()-0.5f;
|
v0[1] = v1[1] = layout->legendRect.min().y()-0.5f;
|
||||||
v2[1] = v3[1] = layout->legendRect.max().y()-0.5f;
|
v2[1] = v3[1] = layout->legendRect.max().y()-0.5f;
|
||||||
|
|
||||||
glColor3fv(m_textColor.ptr());
|
glColor3fv(this->textColor().ptr());
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glVertex3fv(v0);
|
glVertex3fv(v0);
|
||||||
glVertex3fv(v1);
|
glVertex3fv(v1);
|
||||||
@@ -631,7 +577,7 @@ void OverlayScalarMapperLegend::renderLegendImmediateMode(OpenGLContext* oglCont
|
|||||||
// Dynamic coordinates for tickmarks-lines
|
// Dynamic coordinates for tickmarks-lines
|
||||||
v0[1] = v1[1] = v2[1] = v3[1] = v4[1] = y0;
|
v0[1] = v1[1] = v2[1] = v3[1] = v4[1] = y0;
|
||||||
|
|
||||||
glColor3fv(m_textColor.ptr());
|
glColor3fv(this->textColor().ptr());
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
if ( m_visibleTickLabels[ic])
|
if ( m_visibleTickLabels[ic])
|
||||||
{
|
{
|
||||||
@@ -664,13 +610,13 @@ void OverlayScalarMapperLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout)
|
|||||||
{
|
{
|
||||||
CVF_TIGHT_ASSERT(layout);
|
CVF_TIGHT_ASSERT(layout);
|
||||||
|
|
||||||
ref<Glyph> glyph = m_font->getGlyph(L'A');
|
ref<Glyph> glyph = this->font()->getGlyph(L'A');
|
||||||
layout->charHeight = static_cast<float>(glyph->height());
|
layout->charHeight = static_cast<float>(glyph->height());
|
||||||
layout->lineSpacing = layout->charHeight*1.5f;
|
layout->lineSpacing = layout->charHeight*1.5f;
|
||||||
layout->margins = Vec2f(4.0f, 4.0f);
|
layout->margins = Vec2f(4.0f, 4.0f);
|
||||||
|
|
||||||
float legendWidth = 25.0f;
|
float legendWidth = 25.0f;
|
||||||
float legendHeight = static_cast<float>(layout->size.y()) - 2*layout->margins.y() - static_cast<float>(m_titleStrings.size())*layout->lineSpacing - layout->lineSpacing;
|
float legendHeight = static_cast<float>(layout->size.y()) - 2*layout->margins.y() - static_cast<float>(this->titleStrings().size())*layout->lineSpacing - layout->lineSpacing;
|
||||||
layout->legendRect = Rectf(layout->margins.x(), layout->margins.y() + layout->charHeight/2.0f, legendWidth, legendHeight);
|
layout->legendRect = Rectf(layout->margins.x(), layout->margins.y() + layout->charHeight/2.0f, legendWidth, legendHeight);
|
||||||
|
|
||||||
if (layout->legendRect.width() < 1 || layout->legendRect.height() < 1)
|
if (layout->legendRect.width() < 1 || layout->legendRect.height() < 1)
|
||||||
@@ -704,46 +650,6 @@ void OverlayScalarMapperLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void OverlayScalarMapperLegend::setLineColor(const Color3f& lineColor)
|
|
||||||
{
|
|
||||||
m_lineColor = lineColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void OverlayScalarMapperLegend::setBackgroundColor(const Color4f& backgroundColor)
|
|
||||||
{
|
|
||||||
m_backgroundColor = backgroundColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void OverlayScalarMapperLegend::setBackgroundFrameColor(const Color4f& backgroundFrameColor)
|
|
||||||
{
|
|
||||||
m_backgroundFrameColor = backgroundFrameColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void OverlayScalarMapperLegend::enableBackground(bool enable)
|
|
||||||
{
|
|
||||||
m_isBackgroundEnabled = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void OverlayScalarMapperLegend::setLineWidth(int lineWidth)
|
|
||||||
{
|
|
||||||
m_lineWidth = lineWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "cafTitledOverlayFrame.h"
|
||||||
#include "cvfOverlayItem.h"
|
#include "cvfOverlayItem.h"
|
||||||
#include "cvfArray.h"
|
#include "cvfArray.h"
|
||||||
#include "cvfCamera.h"
|
#include "cvfCamera.h"
|
||||||
@@ -59,7 +60,7 @@ namespace caf {
|
|||||||
// Overlay color legend
|
// Overlay color legend
|
||||||
//
|
//
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class OverlayScalarMapperLegend : public cvf::OverlayItem
|
class OverlayScalarMapperLegend : public caf::TitledOverlayFrame
|
||||||
{
|
{
|
||||||
using Font = cvf::Font;
|
using Font = cvf::Font;
|
||||||
using ScalarMapper = cvf::ScalarMapper;
|
using ScalarMapper = cvf::ScalarMapper;
|
||||||
@@ -81,25 +82,11 @@ public:
|
|||||||
|
|
||||||
void setScalarMapper(const ScalarMapper* scalarMapper);
|
void setScalarMapper(const ScalarMapper* scalarMapper);
|
||||||
|
|
||||||
void setSizeHint(const Vec2ui& size);
|
|
||||||
|
|
||||||
void setTextColor(const Color3f& color);
|
|
||||||
void setLineColor(const Color3f& lineColor);
|
|
||||||
|
|
||||||
void setLineWidth(int lineWidth);
|
|
||||||
|
|
||||||
void setTickPrecision(int precision);
|
void setTickPrecision(int precision);
|
||||||
enum NumberFormat { AUTO, SCIENTIFIC, FIXED};
|
enum NumberFormat { AUTO, SCIENTIFIC, FIXED};
|
||||||
void setTickFormat(NumberFormat format);
|
void setTickFormat(NumberFormat format);
|
||||||
|
|
||||||
void enableBackground(bool enable);
|
|
||||||
void setBackgroundColor(const Color4f& backgroundColor);
|
|
||||||
void setBackgroundFrameColor(const Color4f& backgroundFrameColor);
|
|
||||||
|
|
||||||
void setTitle(const String& title);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Vec2ui sizeHint() override;
|
|
||||||
void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) override;
|
void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) override;
|
||||||
void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) override;
|
void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) override;
|
||||||
bool pick(int oglXCoord, int oglYCoord, const Vec2i& position, const Vec2ui& size) override;
|
bool pick(int oglXCoord, int oglYCoord, const Vec2i& position, const Vec2ui& size) override;
|
||||||
@@ -147,19 +134,6 @@ protected:
|
|||||||
int m_tickNumberPrecision;
|
int m_tickNumberPrecision;
|
||||||
NumberFormat m_numberFormat;
|
NumberFormat m_numberFormat;
|
||||||
|
|
||||||
Vec2ui m_sizeHint; // Pixel size of the color legend area
|
|
||||||
|
|
||||||
Color3f m_textColor;
|
|
||||||
Color3f m_lineColor;
|
|
||||||
bool m_isBackgroundEnabled;
|
|
||||||
Color4f m_backgroundColor;
|
|
||||||
Color4f m_backgroundFrameColor;
|
|
||||||
|
|
||||||
int m_lineWidth;
|
|
||||||
|
|
||||||
std::vector<String> m_titleStrings;
|
|
||||||
cvf::ref<Font> m_font;
|
|
||||||
|
|
||||||
cvf::cref<ScalarMapper> m_scalarMapper;
|
cvf::cref<ScalarMapper> m_scalarMapper;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
167
Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.cpp
Normal file
167
Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.cpp
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
#include "cafTitledOverlayFrame.h"
|
||||||
|
#include "cafCategoryMapper.h"
|
||||||
|
#include "cvfFont.h"
|
||||||
|
|
||||||
|
using namespace cvf;
|
||||||
|
|
||||||
|
namespace caf {
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
TitledOverlayFrame::TitledOverlayFrame(Font* font, unsigned int width, unsigned int height)
|
||||||
|
: m_font(font)
|
||||||
|
, m_sizeHint(width, height)
|
||||||
|
, m_textColor(Color3::BLACK)
|
||||||
|
, m_lineColor(Color3::BLACK)
|
||||||
|
, m_lineWidth(1)
|
||||||
|
, m_isBackgroundEnabled(true)
|
||||||
|
, m_backgroundColor(1.0f, 1.0f, 1.0f, 0.8f)
|
||||||
|
, m_backgroundFrameColor(0.0f, 0.0f, 0.0f, 0.5f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TitledOverlayFrame::~TitledOverlayFrame()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void TitledOverlayFrame::setSizeHint(const Vec2ui& size)
|
||||||
|
{
|
||||||
|
m_sizeHint = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Set color of the text
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void TitledOverlayFrame::setTextColor(const Color3f& color)
|
||||||
|
{
|
||||||
|
m_textColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void TitledOverlayFrame::setLineColor(const Color3f& lineColor)
|
||||||
|
{
|
||||||
|
m_lineColor = lineColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void TitledOverlayFrame::setLineWidth(int lineWidth)
|
||||||
|
{
|
||||||
|
m_lineWidth = lineWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Set the title (text that will be rendered above the legend)
|
||||||
|
///
|
||||||
|
/// The legend supports multi-line titles. Separate each line with a '\n' character
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void TitledOverlayFrame::setTitle(const String& title)
|
||||||
|
{
|
||||||
|
// Title
|
||||||
|
if (title.isEmpty())
|
||||||
|
{
|
||||||
|
m_titleStrings.clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_titleStrings = title.split("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void TitledOverlayFrame::enableBackground(bool enable)
|
||||||
|
{
|
||||||
|
m_isBackgroundEnabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void TitledOverlayFrame::setBackgroundColor(const Color4f& backgroundColor)
|
||||||
|
{
|
||||||
|
m_backgroundColor = backgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void TitledOverlayFrame::setBackgroundFrameColor(const Color4f& backgroundFrameColor)
|
||||||
|
{
|
||||||
|
m_backgroundFrameColor = backgroundFrameColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
cvf::Vec2ui TitledOverlayFrame::sizeHint()
|
||||||
|
{
|
||||||
|
return m_sizeHint;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
cvf::Color3f TitledOverlayFrame::textColor() const
|
||||||
|
{
|
||||||
|
return m_textColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
cvf::Color3f TitledOverlayFrame::lineColor() const
|
||||||
|
{
|
||||||
|
return m_lineColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
int TitledOverlayFrame::lineWidth() const
|
||||||
|
{
|
||||||
|
return m_lineWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool TitledOverlayFrame::backgroundEnabled() const
|
||||||
|
{
|
||||||
|
return m_isBackgroundEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
cvf::Color4f TitledOverlayFrame::backgroundColor() const
|
||||||
|
{
|
||||||
|
return m_backgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
cvf::Color4f TitledOverlayFrame::backgroundFrameColor() const
|
||||||
|
{
|
||||||
|
return m_backgroundFrameColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<cvf::String>& TitledOverlayFrame::titleStrings()
|
||||||
|
{
|
||||||
|
return m_titleStrings;
|
||||||
|
}
|
||||||
|
|
||||||
|
cvf::Font* TitledOverlayFrame::font()
|
||||||
|
{
|
||||||
|
return m_font.p();
|
||||||
|
}
|
||||||
|
}
|
||||||
62
Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.h
Normal file
62
Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.h
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "cvfBase.h"
|
||||||
|
#include "cvfColor3.h"
|
||||||
|
#include "cvfColor4.h"
|
||||||
|
#include "cvfOverlayItem.h"
|
||||||
|
#include "cvfString.h"
|
||||||
|
|
||||||
|
namespace cvf
|
||||||
|
{
|
||||||
|
class Font;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace caf {
|
||||||
|
//==================================================================================================
|
||||||
|
// Base class for ApplicationFwk Legends.
|
||||||
|
// Abstract because the pure virtual render methods from cvf::OverlayItem are not implemented.
|
||||||
|
//==================================================================================================
|
||||||
|
class TitledOverlayFrame : public cvf::OverlayItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TitledOverlayFrame(cvf::Font* font, unsigned int width = 100, unsigned int height = 200);
|
||||||
|
virtual ~TitledOverlayFrame();
|
||||||
|
|
||||||
|
virtual void setSizeHint(const cvf::Vec2ui& size);
|
||||||
|
|
||||||
|
void setTextColor(const cvf::Color3f& color);
|
||||||
|
void setLineColor(const cvf::Color3f& lineColor);
|
||||||
|
void setLineWidth(int lineWidth);
|
||||||
|
|
||||||
|
void setTitle(const cvf::String& title);
|
||||||
|
|
||||||
|
void enableBackground(bool enable);
|
||||||
|
void setBackgroundColor(const cvf::Color4f& backgroundColor);
|
||||||
|
void setBackgroundFrameColor(const cvf::Color4f& backgroundFrameColor);
|
||||||
|
|
||||||
|
virtual cvf::Vec2ui sizeHint() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
cvf::Color3f textColor() const;
|
||||||
|
cvf::Color3f lineColor() const;
|
||||||
|
int lineWidth() const;
|
||||||
|
|
||||||
|
bool backgroundEnabled() const;
|
||||||
|
cvf::Color4f backgroundColor() const;
|
||||||
|
cvf::Color4f backgroundFrameColor() const;
|
||||||
|
std::vector<cvf::String>& titleStrings();
|
||||||
|
cvf::Font* font();
|
||||||
|
|
||||||
|
private:
|
||||||
|
cvf::Vec2ui m_sizeHint; // The desired pixel size of the color legend area
|
||||||
|
cvf::Color3f m_textColor;
|
||||||
|
cvf::Color3f m_lineColor;
|
||||||
|
int m_lineWidth;
|
||||||
|
|
||||||
|
bool m_isBackgroundEnabled;
|
||||||
|
cvf::Color4f m_backgroundColor;
|
||||||
|
cvf::Color4f m_backgroundFrameColor;
|
||||||
|
|
||||||
|
std::vector<cvf::String> m_titleStrings;
|
||||||
|
cvf::ref<cvf::Font> m_font;
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user