(#51) Use contrast color for overlay item text and grid colors

This commit is contained in:
Magne Sjaastad 2015-11-23 13:31:01 +01:00
parent 469ffdf920
commit ca9b1cf683
4 changed files with 75 additions and 24 deletions

View File

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

View File

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

View File

@ -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 <QCDEStyle>
#include <QLabel>
@ -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<cvf::OverlayScalarMapperLegend*>(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;
}

View File

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