From 507229f84b321b7e58d26fd15c8fa344ed59dac0 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Thu, 5 Apr 2018 15:25:33 +0200 Subject: [PATCH] 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 --- .../RivTernarySaturationOverlayItem.cpp | 107 ++--------- .../RivTernarySaturationOverlayItem.h | 22 +-- .../Rim2dIntersectionView.cpp | 2 +- .../ProjectDataModel/RimLegendConfig.cpp | 3 +- .../ProjectDataModel/RimLegendConfig.h | 3 +- ApplicationCode/UserInterface/RiuViewer.cpp | 12 +- ApplicationCode/UserInterface/RiuViewer.h | 9 +- Fwk/AppFwk/cafVizExtensions/CMakeLists.txt | 2 + .../cafVizExtensions/cafCategoryLegend.cpp | 127 ++----------- .../cafVizExtensions/cafCategoryLegend.h | 29 +-- .../cafOverlayScalarMapperLegend.cpp | 130 ++------------ .../cafOverlayScalarMapperLegend.h | 30 +--- .../cafTitledOverlayFrame.cpp | 167 ++++++++++++++++++ .../cafVizExtensions/cafTitledOverlayFrame.h | 62 +++++++ 14 files changed, 315 insertions(+), 390 deletions(-) create mode 100644 Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.cpp create mode 100644 Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.h diff --git a/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.cpp b/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.cpp index 34fea69b1f..1168eaa619 100644 --- a/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.cpp +++ b/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.cpp @@ -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(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( (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( (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(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(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(m_size.y() - 20); + //float upperBoundY = static_cast(this->sizeHint().y() - 20); cvf::Vec3f a(float(border), lowerBoundY, 0); - cvf::Vec3f b(static_cast(m_size.x() - border), lowerBoundY, 0); - cvf::Vec3f c(static_cast(m_size.x() / 2), upperBoundY, 0); + cvf::Vec3f b(static_cast(this->sizeHint().x() - border), lowerBoundY, 0); + cvf::Vec3f c(static_cast(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; -} - diff --git a/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.h b/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.h index 138f328c82..ff3fffd0b3 100644 --- a/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.h +++ b/ApplicationCode/ModelVisualization/RivTernarySaturationOverlayItem.h @@ -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 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 m_titleStrings; }; diff --git a/ApplicationCode/ProjectDataModel/Rim2dIntersectionView.cpp b/ApplicationCode/ProjectDataModel/Rim2dIntersectionView.cpp index afffe6ead0..cea81d063c 100644 --- a/ApplicationCode/ProjectDataModel/Rim2dIntersectionView.cpp +++ b/ApplicationCode/ProjectDataModel/Rim2dIntersectionView.cpp @@ -573,7 +573,7 @@ void Rim2dIntersectionView::updateLegends() RimGeoMechView * geoView = nullptr; m_intersection->firstAncestorOrThisOfType(geoView); - cvf::OverlayItem* legend = nullptr; + caf::TitledOverlayFrame* legend = nullptr; if (eclView) { diff --git a/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp b/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp index ffaa8b9333..3b8fc83bce 100644 --- a/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp +++ b/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp @@ -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) { diff --git a/ApplicationCode/ProjectDataModel/RimLegendConfig.h b/ApplicationCode/ProjectDataModel/RimLegendConfig.h index d0772c3e6b..fb591bbc5c 100644 --- a/ApplicationCode/ProjectDataModel/RimLegendConfig.h +++ b/ApplicationCode/ProjectDataModel/RimLegendConfig.h @@ -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); diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index ac9fe87deb..cd79a7e394 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -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 categoryLegends; - std::vector overlayItems; + std::vector overlayItems; for (auto legend : m_visibleLegends) { legend->setLayout(cvf::OverlayItem::VERTICAL, cvf::OverlayItem::BOTTOM_LEFT); diff --git a/ApplicationCode/UserInterface/RiuViewer.h b/ApplicationCode/UserInterface/RiuViewer.h index ebee202195..8c3266d80e 100644 --- a/ApplicationCode/UserInterface/RiuViewer.h +++ b/ApplicationCode/UserInterface/RiuViewer.h @@ -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 m_axisCross; bool m_showAxisCross; - cvf::Collection m_visibleLegends; + cvf::Collection m_visibleLegends; cvf::Collection allOverlayItems(); diff --git a/Fwk/AppFwk/cafVizExtensions/CMakeLists.txt b/Fwk/AppFwk/cafVizExtensions/CMakeLists.txt index 4acaab9e6a..136ab8146f 100644 --- a/Fwk/AppFwk/cafVizExtensions/CMakeLists.txt +++ b/Fwk/AppFwk/cafVizExtensions/CMakeLists.txt @@ -12,6 +12,8 @@ add_library( ${PROJECT_NAME} cafBoxManipulatorPartManager.h cafBoxManipulatorGeometryGenerator.cpp cafBoxManipulatorGeometryGenerator.h + cafTitledOverlayFrame.cpp + cafTitledOverlayFrame.h cafCategoryLegend.cpp cafCategoryLegend.h cafOverlayScalarMapperLegend.h diff --git a/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.cpp b/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.cpp index c69b5f936a..640fc7b528 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.cpp +++ b/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.cpp @@ -39,15 +39,8 @@ namespace caf { /// //-------------------------------------------------------------------------------------------------- CategoryLegend::CategoryLegend(Font* font, const CategoryMapper* categoryMapper) - : m_sizeHint(200, 200), - m_textColor(Color3::BLACK), - 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) + : TitledOverlayFrame(font, 200, 200) + , m_categoryMapper(categoryMapper) { CVF_ASSERT(font); 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 } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -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 float maxLegendRightPos = 0; - TextDrawer textDrawer(m_font.p()); + TextDrawer textDrawer(this->font()); setupTextDrawer(&textDrawer, &layout, &maxLegendRightPos); 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 if (software) { - if (m_isBackgroundEnabled) InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext, + if (this->backgroundEnabled()) InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext, backgroundSize, - m_backgroundColor, - m_backgroundFrameColor); + this->backgroundColor(), + this->backgroundFrameColor()); renderLegendImmediateMode(oglContext, &layout); textDrawer.renderSoftware(oglContext, camera); } else { const MatrixState matrixState(camera); - if (m_isBackgroundEnabled) InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext, + if (this->backgroundEnabled()) InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext, matrixState, backgroundSize, - m_backgroundColor, - m_backgroundFrameColor); + this->backgroundColor(), + this->backgroundFrameColor()); renderLegendUsingShaders(oglContext, &layout, matrixState); textDrawer.render(oglContext, camera); } @@ -231,7 +182,7 @@ void CategoryLegend::setupTextDrawer(TextDrawer* textDrawer, float legendRight = 0.0f; textDrawer->setVerticalAlignment(TextDrawer::CENTER); - textDrawer->setTextColor(m_textColor); + textDrawer->setTextColor(this->textColor()); m_visibleCategoryLabels.clear(); @@ -274,7 +225,7 @@ void CategoryLegend::setupTextDrawer(TextDrawer* textDrawer, Vec2f pos(textX, textY); 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; lastVisibleTextY = textY; @@ -282,12 +233,12 @@ void CategoryLegend::setupTextDrawer(TextDrawer* textDrawer, } float titleY = static_cast(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); - 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; titleY -= layout->lineSpacing; @@ -311,7 +262,7 @@ void CategoryLegend::renderLegendUsingShaders(OpenGLContext* oglContext, RenderStateDepth depth(false); depth.applyOpenGL(oglContext); - RenderStateLine line(static_cast(m_lineWidth)); + RenderStateLine line(static_cast(this->lineWidth())); line.applyOpenGL(oglContext); // 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; 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); #ifdef CVF_OPENGL_ES @@ -497,7 +448,7 @@ void CategoryLegend::renderLegendImmediateMode(OpenGLContext* oglContext, Overla v0[1] = v1[1] = layout->legendRect.min().y() - 0.5f; v2[1] = v3[1] = layout->legendRect.max().y() - 0.5f; - glColor3fv(m_textColor.ptr()); + glColor3fv(this->textColor().ptr()); glBegin(GL_LINES); glVertex3fv(v0); glVertex3fv(v1); @@ -528,13 +479,13 @@ void CategoryLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout) { CVF_TIGHT_ASSERT(layout); - ref glyph = m_font->getGlyph(L'A'); + ref glyph = this->font()->getGlyph(L'A'); layout->charHeight = static_cast(glyph->height()); layout->lineSpacing = layout->charHeight*1.5f; layout->margins = Vec2f(4.0f, 4.0f); float legendWidth = 25.0f; - float legendHeight = static_cast(layout->size.y()) - 2 * layout->margins.y() - static_cast(m_titleStrings.size())*layout->lineSpacing - layout->lineSpacing; + float legendHeight = static_cast(layout->size.y()) - 2 * layout->margins.y() - static_cast(this->titleStrings().size())*layout->lineSpacing - layout->lineSpacing; layout->legendRect = Rectf(layout->margins.x(), layout->margins.y() + layout->charHeight / 2.0f, legendWidth, legendHeight); if (layout->legendRect.width() < 1 || layout->legendRect.height() < 1) @@ -547,46 +498,6 @@ void CategoryLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout) 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; -} - diff --git a/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.h b/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.h index 450a6e3a8d..0e5e6cdf29 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.h +++ b/Fwk/AppFwk/cafVizExtensions/cafCategoryLegend.h @@ -1,6 +1,7 @@ #pragma once +#include "cafTitledOverlayFrame.h" #include "cvfBase.h" #include "cvfArray.h" #include "cvfCamera.h" @@ -23,27 +24,15 @@ class CategoryMapper; // // //================================================================================================== -class CategoryLegend : public cvf::OverlayItem +class CategoryLegend : public caf::TitledOverlayFrame { public: CategoryLegend(cvf::Font* font, const CategoryMapper* categoryMapper); 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; protected: - cvf::Vec2ui sizeHint() 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; bool pick(int oglXCoord, int oglYCoord, const cvf::Vec2i& position, const cvf::Vec2ui& size) override; @@ -92,19 +81,7 @@ protected: protected: std::vector 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 m_titleStrings; - cvf::ref m_font; - - bool m_isBackgroundEnabled; - cvf::Color4f m_backgroundColor; - cvf::Color4f m_backgroundFrameColor; - + cvf::cref m_categoryMapper; }; diff --git a/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.cpp b/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.cpp index 4c2c4601ba..0cdccdd3ca 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.cpp +++ b/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.cpp @@ -83,16 +83,9 @@ using namespace cvf; /// Constructor //-------------------------------------------------------------------------------------------------- OverlayScalarMapperLegend::OverlayScalarMapperLegend(Font* font) -: m_sizeHint(200, 200), - m_textColor(Color3::BLACK), - 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_tickNumberPrecision(4), - m_numberFormat(AUTO) +: TitledOverlayFrame(font, 200, 200) + , m_tickNumberPrecision(4) + , m_numberFormat(AUTO) { CVF_ASSERT(font); 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 } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -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 //-------------------------------------------------------------------------------------------------- @@ -243,7 +189,7 @@ void OverlayScalarMapperLegend::renderGeneric(OpenGLContext* oglContext, const V // Set up text drawer float maxLegendRightPos = 0; - TextDrawer textDrawer(m_font.p()); + TextDrawer textDrawer(this->font()); setupTextDrawer(&textDrawer, &layout, &maxLegendRightPos); 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 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); textDrawer.renderSoftware(oglContext, camera); } else { 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); textDrawer.render(oglContext, camera); } @@ -277,7 +223,7 @@ void OverlayScalarMapperLegend::setupTextDrawer(TextDrawer* textDrawer, const Ov float legendRight = 0.0f; textDrawer->setVerticalAlignment(TextDrawer::CENTER); - textDrawer->setTextColor(m_textColor); + textDrawer->setTextColor(this->textColor()); m_visibleTickLabels.clear(); @@ -330,7 +276,7 @@ void OverlayScalarMapperLegend::setupTextDrawer(TextDrawer* textDrawer, const Ov Vec2f pos(textX, textY); 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; lastVisibleTextY = textY; @@ -338,12 +284,12 @@ void OverlayScalarMapperLegend::setupTextDrawer(TextDrawer* textDrawer, const Ov } float titleY = static_cast(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); - 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; @@ -367,7 +313,7 @@ void OverlayScalarMapperLegend::renderLegendUsingShaders(OpenGLContext* oglConte RenderStateDepth depth(false); depth.applyOpenGL(oglContext); - RenderStateLine line(static_cast(m_lineWidth)); + RenderStateLine line(static_cast(this->lineWidth())); line.applyOpenGL(oglContext); // 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; 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); #ifdef CVF_OPENGL_ES @@ -482,7 +428,7 @@ void OverlayScalarMapperLegend::renderLegendUsingShaders(OpenGLContext* oglConte // Dynamic coordinates for tickmarks-lines 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); const ushort * linesConnects; @@ -597,7 +543,7 @@ void OverlayScalarMapperLegend::renderLegendImmediateMode(OpenGLContext* oglCont v0[1] = v1[1] = layout->legendRect.min().y()-0.5f; v2[1] = v3[1] = layout->legendRect.max().y()-0.5f; - glColor3fv(m_textColor.ptr()); + glColor3fv(this->textColor().ptr()); glBegin(GL_LINES); glVertex3fv(v0); glVertex3fv(v1); @@ -631,7 +577,7 @@ void OverlayScalarMapperLegend::renderLegendImmediateMode(OpenGLContext* oglCont // Dynamic coordinates for tickmarks-lines v0[1] = v1[1] = v2[1] = v3[1] = v4[1] = y0; - glColor3fv(m_textColor.ptr()); + glColor3fv(this->textColor().ptr()); glBegin(GL_LINES); if ( m_visibleTickLabels[ic]) { @@ -664,13 +610,13 @@ void OverlayScalarMapperLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout) { CVF_TIGHT_ASSERT(layout); - ref glyph = m_font->getGlyph(L'A'); + ref glyph = this->font()->getGlyph(L'A'); layout->charHeight = static_cast(glyph->height()); layout->lineSpacing = layout->charHeight*1.5f; layout->margins = Vec2f(4.0f, 4.0f); float legendWidth = 25.0f; - float legendHeight = static_cast(layout->size.y()) - 2*layout->margins.y() - static_cast(m_titleStrings.size())*layout->lineSpacing - layout->lineSpacing; + float legendHeight = static_cast(layout->size.y()) - 2*layout->margins.y() - static_cast(this->titleStrings().size())*layout->lineSpacing - layout->lineSpacing; layout->legendRect = Rectf(layout->margins.x(), layout->margins.y() + layout->charHeight/2.0f, legendWidth, legendHeight); 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; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.h b/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.h index 1890f41244..11a2f2c7cc 100644 --- a/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.h +++ b/Fwk/AppFwk/cafVizExtensions/cafOverlayScalarMapperLegend.h @@ -37,6 +37,7 @@ #pragma once +#include "cafTitledOverlayFrame.h" #include "cvfOverlayItem.h" #include "cvfArray.h" #include "cvfCamera.h" @@ -59,7 +60,7 @@ namespace caf { // Overlay color legend // //================================================================================================== -class OverlayScalarMapperLegend : public cvf::OverlayItem +class OverlayScalarMapperLegend : public caf::TitledOverlayFrame { using Font = cvf::Font; using ScalarMapper = cvf::ScalarMapper; @@ -81,25 +82,11 @@ public: 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); enum NumberFormat { AUTO, SCIENTIFIC, FIXED}; void setTickFormat(NumberFormat format); - void enableBackground(bool enable); - void setBackgroundColor(const Color4f& backgroundColor); - void setBackgroundFrameColor(const Color4f& backgroundFrameColor); - - void setTitle(const String& title); - protected: - Vec2ui sizeHint() override; void render(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; @@ -147,19 +134,6 @@ protected: int m_tickNumberPrecision; 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 m_titleStrings; - cvf::ref m_font; - cvf::cref m_scalarMapper; }; diff --git a/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.cpp b/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.cpp new file mode 100644 index 0000000000..4660733875 --- /dev/null +++ b/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.cpp @@ -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& TitledOverlayFrame::titleStrings() + { + return m_titleStrings; + } + + cvf::Font* TitledOverlayFrame::font() + { + return m_font.p(); + } +} \ No newline at end of file diff --git a/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.h b/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.h new file mode 100644 index 0000000000..384aff7c8e --- /dev/null +++ b/Fwk/AppFwk/cafVizExtensions/cafTitledOverlayFrame.h @@ -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& 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 m_titleStrings; + cvf::ref m_font; + }; +}