From ca9b1cf6833bde202b2cebf18c00ebc57adb43d6 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 23 Nov 2015 13:31:01 +0100 Subject: [PATCH] (#51) Use contrast color for overlay item text and grid colors --- .../GridBox/RivGridBoxGenerator.cpp | 2 +- .../GridBox/RivGridBoxGenerator.h | 2 +- ApplicationCode/UserInterface/RiuViewer.cpp | 87 ++++++++++++++----- ApplicationCode/UserInterface/RiuViewer.h | 8 ++ 4 files changed, 75 insertions(+), 24 deletions(-) diff --git a/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.cpp b/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.cpp index 89b27c10af..905f06be32 100644 --- a/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.cpp +++ b/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.cpp @@ -649,7 +649,7 @@ cvf::Vec3f RivGridBoxGenerator::cornerDirection(FaceType face1, FaceType face2) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RivGridBoxGenerator::updateFromBackgroundColor(const cvf::Color3f backgroundColor) +void RivGridBoxGenerator::updateFromBackgroundColor(const cvf::Color3f& backgroundColor) { double adjustmentFactor = 0.3; diff --git a/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.h b/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.h index a5268af07f..2cba4cf647 100644 --- a/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.h +++ b/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.h @@ -48,7 +48,7 @@ public: void setScaleZ(double scaleZ); void setDisplayModelOffset(cvf::Vec3d offset); void setGridBoxDomainCoordBoundingBox(const cvf::BoundingBox& boundingBox); - void updateFromBackgroundColor(const cvf::Color3f backgroundColor); + void updateFromBackgroundColor(const cvf::Color3f& backgroundColor); void createGridBoxParts(); diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 16d1a1baa5..4be74f84ea 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -42,12 +42,13 @@ #include "cvfCamera.h" #include "cvfFont.h" +#include "cvfOpenGLResourceManager.h" #include "cvfOverlayAxisCross.h" +#include "cvfOverlayScalarMapperLegend.h" #include "cvfRenderQueueSorter.h" #include "cvfRenderSequence.h" #include "cvfRendering.h" #include "cvfScene.h" -#include "cvfOpenGLResourceManager.h" #include #include @@ -459,6 +460,8 @@ void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend) if (legend) { + updateLegendTextAndTickMarkColor(legend); + legend->setLayout(cvf::OverlayItem::VERTICAL, cvf::OverlayItem::BOTTOM_LEFT); firstRendering->addOverlayItem(legend); @@ -567,6 +570,8 @@ void RiuViewer::updateGridBoxData() } m_gridBoxGenerator->createGridBoxParts(); + + updateTextAndTickMarkColorForOverlayItems(); } } @@ -584,25 +589,63 @@ cvf::Model* RiuViewer::gridBoxModel() const void RiuViewer::setAxisLabels(const cvf::String& xLabel, const cvf::String& yLabel, const cvf::String& zLabel) { m_axisCross->setAxisLabels(xLabel, yLabel, zLabel); - - // The axis cross is designed for short labels, longer labels causes clipping of text - // The commented out code adjust the size of the axis cross, and this makes the axis cross labels visible - // Side effect is also that the axis cross is zoomed (will be larger) - /* - size_t maxAxisLabelLength = xLabel.size(); - if (yLabel.size() > maxAxisLabelLength) maxAxisLabelLength = yLabel.size(); - if (zLabel.size() > maxAxisLabelLength) maxAxisLabelLength = zLabel.size(); - - if (maxAxisLabelLength > 4) - { - if (maxAxisLabelLength < 6) - { - m_axisCross->setSize(cvf::Vec2ui(140, 140)); - } - else if (maxAxisLabelLength < 8) - { - m_axisCross->setSize(cvf::Vec2ui(160, 160)); - } - } - */ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuViewer::updateLegendTextAndTickMarkColor(cvf::OverlayItem* legend) +{ + if (m_rimView.isNull()) return; + + cvf::Color3f contrastColor = computeContrastColor(); + + cvf::OverlayScalarMapperLegend* scalarMapperLegend = dynamic_cast(legend); + if (scalarMapperLegend) + { + scalarMapperLegend->setColor(contrastColor); + scalarMapperLegend->setLineColor(contrastColor); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuViewer::updateTextAndTickMarkColorForOverlayItems() +{ + for (size_t i = 0; i < m_visibleLegends.size(); i++) + { + updateLegendTextAndTickMarkColor(m_visibleLegends.at(i)); + } + + updateAxisCrossTextColor(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuViewer::updateAxisCrossTextColor() +{ + cvf::Color3f contrastColor = computeContrastColor(); + + m_axisCross->setAxisLabelsColor(contrastColor); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Color3f RiuViewer::computeContrastColor() const +{ + cvf::Color3f contrastColor = cvf::Color3f::WHITE; + + if (m_rimView.notNull()) + { + cvf::Color3f backgroundColor = m_rimView->backgroundColor; + if (backgroundColor.r() + backgroundColor.g() + backgroundColor.b() > 1.5f) + { + contrastColor = cvf::Color3f::BLACK; + } + } + + return contrastColor; } diff --git a/ApplicationCode/UserInterface/RiuViewer.h b/ApplicationCode/UserInterface/RiuViewer.h index 3a52f93e66..9adceb68e5 100644 --- a/ApplicationCode/UserInterface/RiuViewer.h +++ b/ApplicationCode/UserInterface/RiuViewer.h @@ -39,6 +39,7 @@ class QProgressBar; namespace cvf { + class Color3f; class Model; class OverlayItem; class Part; @@ -95,6 +96,13 @@ protected: virtual void optimizeClippingPlanes(); private: + void updateTextAndTickMarkColorForOverlayItems(); + void updateLegendTextAndTickMarkColor(cvf::OverlayItem* legend); + + cvf::Color3f computeContrastColor() const; + + void updateAxisCrossTextColor(); + void paintOverlayItems(QPainter* painter); void mouseReleaseEvent(QMouseEvent* event);