mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
Set background and frame color from the view plus update frame margins.
This commit is contained in:
parent
507229f84b
commit
63ffade452
@ -17,6 +17,8 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaColorTools.h"
|
||||
#include "cvfMath.h"
|
||||
#include <algorithm>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@ -31,6 +33,33 @@ bool RiaColorTools::isBrightnessAboveThreshold(cvf::Color3f backgroundColor)
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RiaColorTools::computeOffsetColor(cvf::Color3f color, float offsetFactor)
|
||||
{
|
||||
float gridR = 0.0;
|
||||
float gridG = 0.0;
|
||||
float gridB = 0.0;
|
||||
|
||||
if (isBrightnessAboveThreshold(color))
|
||||
{
|
||||
gridR = color.r() - (color.r() * offsetFactor);
|
||||
gridG = color.g() - (color.g() * offsetFactor);
|
||||
gridB = color.b() - (color.b() * offsetFactor);
|
||||
}
|
||||
else
|
||||
{
|
||||
gridR = color.r() + (1.0f - color.r()) * offsetFactor;
|
||||
gridG = color.g() + (1.0f - color.g()) * offsetFactor;
|
||||
gridB = color.b() + (1.0f - color.b()) * offsetFactor;
|
||||
}
|
||||
|
||||
return cvf::Color3f(cvf::Math::clamp(gridR, 0.0f, 1.0f),
|
||||
cvf::Math::clamp(gridG, 0.0f, 1.0f),
|
||||
cvf::Math::clamp(gridB, 0.0f, 1.0f));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -30,7 +30,8 @@ class RiaColorTools
|
||||
{
|
||||
public:
|
||||
static bool isBrightnessAboveThreshold(cvf::Color3f backgroundColor);
|
||||
|
||||
|
||||
static cvf::Color3f computeOffsetColor(cvf::Color3f color, float offsetFactor);
|
||||
static cvf::Color3f darkContrastColor();
|
||||
static cvf::Color3f brightContrastColor();
|
||||
static cvf::Color3f constrastColor(cvf::Color3f backgroundColor);
|
||||
|
@ -734,30 +734,8 @@ cvf::Vec3f RivGridBoxGenerator::cornerDirection(FaceType face1, FaceType face2)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivGridBoxGenerator::updateFromBackgroundColor(const cvf::Color3f& backgroundColor)
|
||||
{
|
||||
double adjustmentFactor = 0.3;
|
||||
|
||||
float gridR = 0.0;
|
||||
float gridG = 0.0;
|
||||
float gridB = 0.0;
|
||||
|
||||
if (RiaColorTools::isBrightnessAboveThreshold(backgroundColor))
|
||||
{
|
||||
gridR = backgroundColor.r() - (backgroundColor.r() * adjustmentFactor);
|
||||
gridG = backgroundColor.g() - (backgroundColor.g() * adjustmentFactor);
|
||||
gridB = backgroundColor.b() - (backgroundColor.b() * adjustmentFactor);
|
||||
|
||||
m_gridLegendColor = RiaColorTools::darkContrastColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
gridR = backgroundColor.r() + (1.0 - backgroundColor.r()) * adjustmentFactor;
|
||||
gridG = backgroundColor.g() + (1.0 - backgroundColor.g()) * adjustmentFactor;
|
||||
gridB = backgroundColor.b() + (1.0 - backgroundColor.b()) * adjustmentFactor;
|
||||
|
||||
m_gridLegendColor = RiaColorTools::brightContrastColor();
|
||||
}
|
||||
|
||||
m_gridColor.set(gridR, gridG, gridB);
|
||||
m_gridColor = RiaColorTools::computeOffsetColor(backgroundColor, 0.3f);
|
||||
m_gridLegendColor = RiaColorTools::constrastColor(backgroundColor);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -118,7 +118,7 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
|
||||
this->backgroundColor(),
|
||||
this->backgroundFrameColor());
|
||||
}
|
||||
border = 3.0f;
|
||||
border = 8.0f;
|
||||
}
|
||||
|
||||
cvf::TextDrawer textDrawer(this->font());
|
||||
@ -126,7 +126,7 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
|
||||
|
||||
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 - border);
|
||||
for (size_t it = 0; it < this->titleStrings().size(); it++)
|
||||
{
|
||||
cvf::Vec2f pos(border, textPosY);
|
||||
|
@ -603,7 +603,7 @@ void Rim2dIntersectionView::updateLegends()
|
||||
|
||||
if ( legend )
|
||||
{
|
||||
m_viewer->addColorLegendToBottomLeftCorner(legend);
|
||||
m_viewer->addColorLegendToBottomLeftCorner(legend, this->backgroundColor());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -583,12 +583,7 @@ void Rim3dView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const
|
||||
}
|
||||
else if (changedField == &m_backgroundColor)
|
||||
{
|
||||
if (m_viewer != nullptr)
|
||||
{
|
||||
m_viewer->mainCamera()->viewport()->setClearColor(cvf::Color4f(backgroundColor()));
|
||||
}
|
||||
updateGridBoxData();
|
||||
updateAnnotationItems();
|
||||
this->applyBackgroundColor();
|
||||
}
|
||||
else if (changedField == &maximumFrameRate)
|
||||
{
|
||||
@ -730,6 +725,19 @@ void Rim3dView::createHighlightAndGridBoxDisplayModel()
|
||||
m_viewer->showGridBox(m_showGridBox());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Rim3dView::applyBackgroundColor()
|
||||
{
|
||||
if (m_viewer != nullptr)
|
||||
{
|
||||
m_viewer->mainCamera()->viewport()->setClearColor(cvf::Color4f(backgroundColor()));
|
||||
}
|
||||
updateGridBoxData();
|
||||
updateAnnotationItems();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -155,6 +155,10 @@ protected:
|
||||
|
||||
void createHighlightAndGridBoxDisplayModel();
|
||||
|
||||
// Implementation of RiuViewerToViewInterface
|
||||
virtual cvf::Color3f backgroundColor() const override { return m_backgroundColor(); }
|
||||
virtual void applyBackgroundColor();
|
||||
|
||||
// Abstract methods to implement in subclasses
|
||||
|
||||
virtual void axisLabels(cvf::String* xLabel, cvf::String* yLabel, cvf::String* zLabel) = 0;
|
||||
@ -206,7 +210,6 @@ private:
|
||||
|
||||
// Implementation of RiuViewerToViewInterface
|
||||
|
||||
virtual cvf::Color3f backgroundColor() const override { return m_backgroundColor();}
|
||||
virtual void setCameraPosition(const cvf::Mat4d& cameraPosition) override { m_cameraPosition = cameraPosition; }
|
||||
virtual void setCameraPointOfInterest(const cvf::Vec3d& cameraPointOfInterest) override { m_cameraPointOfInterest = cameraPointOfInterest;}
|
||||
virtual QString timeStepName(int frameIdx) const override;
|
||||
|
@ -1085,7 +1085,7 @@ void RimEclipseView::updateLegends()
|
||||
}
|
||||
}
|
||||
|
||||
m_viewer->addColorLegendToBottomLeftCorner(this->cellEdgeResult()->legendConfig()->legend());
|
||||
m_viewer->addColorLegendToBottomLeftCorner(this->cellEdgeResult()->legendConfig()->legend(), this->backgroundColor());
|
||||
this->cellEdgeResult()->legendConfig()->setTitle(QString("Edge Results: \n") + this->cellEdgeResult()->resultVariableUiShortName());
|
||||
}
|
||||
else
|
||||
@ -1101,7 +1101,7 @@ void RimEclipseView::updateLegends()
|
||||
|
||||
if (fractureColors()->isChecked() && stimPlanLegend->legend())
|
||||
{
|
||||
m_viewer->addColorLegendToBottomLeftCorner(stimPlanLegend->legend());
|
||||
m_viewer->addColorLegendToBottomLeftCorner(stimPlanLegend->legend(), this->backgroundColor());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1111,7 +1111,7 @@ void RimEclipseView::updateLegends()
|
||||
|
||||
RimLegendConfig* virtLegend = m_virtualPerforationResult->legendConfig();
|
||||
|
||||
m_viewer->addColorLegendToBottomLeftCorner(virtLegend->legend());
|
||||
m_viewer->addColorLegendToBottomLeftCorner(virtLegend->legend(), this->backgroundColor());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1126,7 +1126,7 @@ void RimEclipseView::updateMinMaxValuesAndAddLegendToView(QString legendLabel,
|
||||
|
||||
if (resultColors->hasResult())
|
||||
{
|
||||
m_viewer->addColorLegendToBottomLeftCorner(resultColors->legendConfig()->legend());
|
||||
m_viewer->addColorLegendToBottomLeftCorner(resultColors->legendConfig()->legend(), this->backgroundColor());
|
||||
resultColors->legendConfig()->setTitle(legendLabel + resultColors->resultVariableUiShortName());
|
||||
}
|
||||
|
||||
@ -1136,7 +1136,7 @@ void RimEclipseView::updateMinMaxValuesAndAddLegendToView(QString legendLabel,
|
||||
if (resultColors->ternaryLegendConfig->legend())
|
||||
{
|
||||
resultColors->ternaryLegendConfig->setTitle(legendLabel);
|
||||
m_viewer->addColorLegendToBottomLeftCorner(resultColors->ternaryLegendConfig->legend());
|
||||
m_viewer->addColorLegendToBottomLeftCorner(resultColors->ternaryLegendConfig->legend(), this->backgroundColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1594,9 +1594,14 @@ void RimEclipseView::resetLegendsInViewer()
|
||||
|
||||
m_viewer->removeAllColorLegends();
|
||||
|
||||
if (cellResultNormalLegendConfig) m_viewer->addColorLegendToBottomLeftCorner(cellResultNormalLegendConfig->legend());
|
||||
if (cellResultNormalLegendConfig)
|
||||
{
|
||||
m_viewer->addColorLegendToBottomLeftCorner(cellResultNormalLegendConfig->legend(),
|
||||
this->backgroundColor());
|
||||
}
|
||||
|
||||
m_viewer->addColorLegendToBottomLeftCorner(this->cellEdgeResult()->legendConfig()->legend());
|
||||
m_viewer->addColorLegendToBottomLeftCorner(this->cellEdgeResult()->legendConfig()->legend(),
|
||||
this->backgroundColor());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -1732,6 +1737,15 @@ bool RimEclipseView::showActiveCellsOnly()
|
||||
return !m_showInactiveCells;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimEclipseView::applyBackgroundColor()
|
||||
{
|
||||
Rim3dView::applyBackgroundColor();
|
||||
this->updateLegends();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -147,6 +147,7 @@ protected:
|
||||
|
||||
virtual void createPartCollectionFromSelection(cvf::Collection<cvf::Part>* parts) override;
|
||||
virtual bool showActiveCellsOnly() override;
|
||||
virtual void applyBackgroundColor() override;
|
||||
|
||||
private:
|
||||
void createDisplayModel() override;
|
||||
|
@ -364,7 +364,8 @@ void RimGeoMechView::resetLegendsInViewer()
|
||||
this->cellResult()->legendConfig->recreateLegend();
|
||||
|
||||
m_viewer->removeAllColorLegends();
|
||||
m_viewer->addColorLegendToBottomLeftCorner(this->cellResult()->legendConfig->legend());
|
||||
m_viewer->addColorLegendToBottomLeftCorner(this->cellResult()->legendConfig->legend(),
|
||||
this->backgroundColor());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -380,14 +381,16 @@ void RimGeoMechView::updateLegends()
|
||||
|
||||
if (cellResult()->hasResult())
|
||||
{
|
||||
m_viewer->addColorLegendToBottomLeftCorner(cellResult()->legendConfig->legend());
|
||||
m_viewer->addColorLegendToBottomLeftCorner(cellResult()->legendConfig->legend(),
|
||||
this->backgroundColor());
|
||||
}
|
||||
|
||||
updateTensorLegendTextAndRanges(m_tensorResults->arrowColorLegendConfig(), m_currentTimeStep());
|
||||
|
||||
if (tensorResults()->vectorColors() == RimTensorResults::RESULT_COLORS && tensorResults()->showTensors())
|
||||
{
|
||||
m_viewer->addColorLegendToBottomLeftCorner(m_tensorResults->arrowColorLegendConfig->legend());
|
||||
m_viewer->addColorLegendToBottomLeftCorner(m_tensorResults->arrowColorLegendConfig->legend(),
|
||||
this->backgroundColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -536,7 +536,7 @@ void RiuViewer::removeAllColorLegends()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuViewer::addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend)
|
||||
void RiuViewer::addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend, const cvf::Color3f& backgroundColor)
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
CVF_ASSERT(app);
|
||||
@ -551,6 +551,8 @@ void RiuViewer::addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend
|
||||
|
||||
firstRendering->addOverlayItem(legend);
|
||||
legend->enableBackground(preferences->showLegendBackground());
|
||||
legend->setBackgroundColor(cvf::Color4f(backgroundColor, 0.8f));
|
||||
legend->setBackgroundFrameColor(cvf::Color4f(RiaColorTools::computeOffsetColor(backgroundColor, 0.3f), 0.9f));
|
||||
m_visibleLegends.push_back(legend);
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ public:
|
||||
void showAnimationProgress(bool enable);
|
||||
|
||||
void removeAllColorLegends();
|
||||
void addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend);
|
||||
void addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend, const cvf::Color3f& backgroundColor);
|
||||
|
||||
void enableNavigationRotation(bool disable);
|
||||
void updateNavigationPolicy();
|
||||
|
@ -138,7 +138,7 @@ void CategoryLegend::renderGeneric(OpenGLContext* oglContext,
|
||||
TextDrawer textDrawer(this->font());
|
||||
setupTextDrawer(&textDrawer, &layout, &maxLegendRightPos);
|
||||
|
||||
Vec2f backgroundSize(CVF_MIN(maxLegendRightPos + 3.0f, (float)size.x()), (float)size.y());
|
||||
Vec2f backgroundSize(CVF_MIN(maxLegendRightPos + layout.margins.x(), (float)size.x()), (float)size.y());
|
||||
|
||||
// Do the actual rendering
|
||||
if (software)
|
||||
@ -482,7 +482,7 @@ void CategoryLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout)
|
||||
ref<Glyph> glyph = this->font()->getGlyph(L'A');
|
||||
layout->charHeight = static_cast<float>(glyph->height());
|
||||
layout->lineSpacing = layout->charHeight*1.5f;
|
||||
layout->margins = Vec2f(4.0f, 4.0f);
|
||||
layout->margins = Vec2f(8.0f, 8.0f);
|
||||
|
||||
float legendWidth = 25.0f;
|
||||
float legendHeight = static_cast<float>(layout->size.y()) - 2 * layout->margins.y() - static_cast<float>(this->titleStrings().size())*layout->lineSpacing - layout->lineSpacing;
|
||||
|
@ -192,7 +192,7 @@ void OverlayScalarMapperLegend::renderGeneric(OpenGLContext* oglContext, const V
|
||||
TextDrawer textDrawer(this->font());
|
||||
setupTextDrawer(&textDrawer, &layout, &maxLegendRightPos);
|
||||
|
||||
Vec2f backgroundSize(CVF_MIN(maxLegendRightPos + 3.0f, (float)size.x()), (float)size.y());
|
||||
Vec2f backgroundSize(CVF_MIN(maxLegendRightPos + layout.margins.x(), (float)size.x()), (float)size.y());
|
||||
|
||||
// Do the actual rendering
|
||||
if (software)
|
||||
@ -613,7 +613,7 @@ void OverlayScalarMapperLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout)
|
||||
ref<Glyph> glyph = this->font()->getGlyph(L'A');
|
||||
layout->charHeight = static_cast<float>(glyph->height());
|
||||
layout->lineSpacing = layout->charHeight*1.5f;
|
||||
layout->margins = Vec2f(4.0f, 4.0f);
|
||||
layout->margins = Vec2f(8.0f, 8.0f);
|
||||
|
||||
float legendWidth = 25.0f;
|
||||
float legendHeight = static_cast<float>(layout->size.y()) - 2*layout->margins.y() - static_cast<float>(this->titleStrings().size())*layout->lineSpacing - layout->lineSpacing;
|
||||
|
Loading…
Reference in New Issue
Block a user