mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#51 Add background to ternary legend
This commit is contained in:
parent
7a9e53bdb1
commit
b4935a0534
@ -33,6 +33,7 @@
|
||||
#include "cvfRenderState_FF.h"
|
||||
#include "cvfRenderStateDepth.h"
|
||||
#include "cvfRenderStatePolygonOffset.h"
|
||||
#include "cafInternalLegendRenderTools.h"
|
||||
|
||||
|
||||
|
||||
@ -40,13 +41,15 @@
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RivTernarySaturationOverlayItem::RivTernarySaturationOverlayItem(cvf::Font* font)
|
||||
: m_textColor(cvf::Color3::BLACK),
|
||||
m_font(font),
|
||||
m_size(100, 140)
|
||||
: 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -89,7 +92,7 @@ void RivTernarySaturationOverlayItem::setSize(const cvf::Vec2ui& size)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, false);
|
||||
renderGeneric(oglContext, position, size, false);
|
||||
}
|
||||
|
||||
|
||||
@ -98,20 +101,25 @@ void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, con
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivTernarySaturationOverlayItem::renderSoftware(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, true);
|
||||
renderGeneric(oglContext, position, size, true);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set up camera/viewport and render
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size, bool software)
|
||||
void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglContext,
|
||||
const cvf::Vec2i& position,
|
||||
const cvf::Vec2ui& size,
|
||||
bool software)
|
||||
{
|
||||
if (size.x() <= 0 || size.y() <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float border = 0.0f;
|
||||
|
||||
cvf::Camera camera;
|
||||
camera.setViewport(position.x(), position.y(), size.x(), size.y());
|
||||
camera.setProjectionAsPixelExact2D();
|
||||
@ -119,24 +127,46 @@ void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, con
|
||||
camera.applyOpenGL();
|
||||
camera.viewport()->applyOpenGL(oglContext, cvf::Viewport::CLEAR_DEPTH);
|
||||
|
||||
if ( m_isBackgroundEnabled )
|
||||
{
|
||||
if ( software )
|
||||
{
|
||||
caf::InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext,
|
||||
cvf::Vec2f(size),
|
||||
m_backgroundColor,
|
||||
m_backgroundFrameColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
const cvf::MatrixState matrixState(camera);
|
||||
|
||||
caf::InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext,
|
||||
matrixState,
|
||||
cvf::Vec2f(size),
|
||||
m_backgroundColor,
|
||||
m_backgroundFrameColor);
|
||||
}
|
||||
border = 3.0f;
|
||||
}
|
||||
|
||||
cvf::TextDrawer textDrawer(m_font.p());
|
||||
textDrawer.setTextColor(m_textColor);
|
||||
|
||||
float lineHeightInPixels = 10;
|
||||
float lineHeightInPixels = (float)(m_font->textExtent("SWAT").y() + 2);
|
||||
|
||||
float textPosY = static_cast<float>(size.y() - 10);
|
||||
float textPosY = static_cast<float>(size.y() - lineHeightInPixels);
|
||||
for (size_t it = 0; it < m_titleStrings.size(); it++)
|
||||
{
|
||||
cvf::Vec2f pos(5, textPosY);
|
||||
cvf::Vec2f pos(border, textPosY);
|
||||
textDrawer.addText(m_titleStrings[it], pos);
|
||||
|
||||
textPosY -= lineHeightInPixels;
|
||||
}
|
||||
|
||||
cvf::Vec2f pos(5, textPosY);
|
||||
cvf::Vec2f pos(border, textPosY);
|
||||
textDrawer.addText("TERNARY", pos);
|
||||
textPosY -= lineHeightInPixels;
|
||||
textPosY -= 2;
|
||||
textPosY -= border;
|
||||
|
||||
{
|
||||
cvf::uint sgasTextWidth = m_font->textExtent("SGAS").x();
|
||||
@ -147,23 +177,23 @@ void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, con
|
||||
textDrawer.addText(m_sgasRange, cvf::Vec2f(static_cast<float>( (size.x() / 2) - sgasRangeTextWidth / 2 ), textPosY));
|
||||
}
|
||||
|
||||
textDrawer.addText("SWAT", cvf::Vec2f(0.0, 10.0));
|
||||
textDrawer.addText(m_swatRange, cvf::Vec2f(0.0, 0.0));
|
||||
textDrawer.addText("SWAT", cvf::Vec2f((float)border, (float)(lineHeightInPixels + border)));
|
||||
textDrawer.addText(m_swatRange, cvf::Vec2f((float)border, (float)border));
|
||||
|
||||
{
|
||||
cvf::uint soilTextWidth = m_font->textExtent("SOIL").x();
|
||||
textDrawer.addText("SOIL", cvf::Vec2f(static_cast<float>(size.x() - soilTextWidth), 10.0));
|
||||
textDrawer.addText("SOIL", cvf::Vec2f(static_cast<float>(size.x() - soilTextWidth - border), lineHeightInPixels + border));
|
||||
|
||||
cvf::uint soilRangeTextWidth = m_font->textExtent(m_soilRange).x();
|
||||
float soilRangePos = static_cast<float>(size.x()) - soilRangeTextWidth;
|
||||
float soilRangePos = static_cast<float>(size.x()) - soilRangeTextWidth - border;
|
||||
|
||||
textDrawer.addText(m_soilRange, cvf::Vec2f(soilRangePos, 0.0));
|
||||
textDrawer.addText(m_soilRange, cvf::Vec2f(soilRangePos, (float)border));
|
||||
}
|
||||
|
||||
textDrawer.renderSoftware(oglContext, camera);
|
||||
|
||||
textPosY -= 3;
|
||||
renderAxisImmediateMode(textPosY, oglContext);
|
||||
renderAxisImmediateMode(textPosY, 2*lineHeightInPixels + border, border, oglContext);
|
||||
|
||||
CVF_CHECK_OGL(oglContext);
|
||||
}
|
||||
@ -173,7 +203,7 @@ void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, con
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Draw the axis using immediate mode OpenGL
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivTernarySaturationOverlayItem::renderAxisImmediateMode(float upperBoundY, cvf::OpenGLContext* oglContext)
|
||||
void RivTernarySaturationOverlayItem::renderAxisImmediateMode(float upperBoundY, float lowerBoundY, float border, cvf::OpenGLContext* oglContext)
|
||||
{
|
||||
#ifdef CVF_OPENGL_ES
|
||||
CVF_UNUSED(layout);
|
||||
@ -190,11 +220,10 @@ void RivTernarySaturationOverlayItem::renderAxisImmediateMode(float upperBoundY,
|
||||
cvf::Color3ub colB(cvf::Color3::GREEN);
|
||||
cvf::Color3ub colC(cvf::Color3::RED);
|
||||
|
||||
float lowerBoundY = 20;
|
||||
//float upperBoundY = static_cast<float>(m_size.y() - 20);
|
||||
|
||||
cvf::Vec3f a(0, lowerBoundY, 0);
|
||||
cvf::Vec3f b(static_cast<float>(m_size.x()), lowerBoundY, 0);
|
||||
cvf::Vec3f a(float(border), lowerBoundY, 0);
|
||||
cvf::Vec3f b(static_cast<float>(m_size.x() - border), lowerBoundY, 0);
|
||||
cvf::Vec3f c(static_cast<float>(m_size.x() / 2), upperBoundY, 0);
|
||||
|
||||
|
||||
@ -260,4 +289,27 @@ void RivTernarySaturationOverlayItem::setTitle(const cvf::String& title)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "cvfOverlayItem.h"
|
||||
#include "cvfMatrix4.h"
|
||||
#include "cvfColor3.h"
|
||||
#include "cvfColor4.h"
|
||||
#include "cvfString.h"
|
||||
|
||||
namespace cvf {
|
||||
@ -43,24 +44,37 @@ public:
|
||||
|
||||
void setRangeText(const cvf::String& soilRange, const cvf::String& sgasRange, const cvf::String& swatRange);
|
||||
|
||||
virtual cvf::Vec2ui sizeHint();
|
||||
|
||||
virtual void render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size);
|
||||
virtual void renderSoftware(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size);
|
||||
|
||||
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:
|
||||
void render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size, bool software);
|
||||
void renderAxisImmediateMode(float upperY, cvf::OpenGLContext* oglContext);
|
||||
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;
|
||||
|
||||
void renderGeneric(cvf::OpenGLContext* oglContext,
|
||||
const cvf::Vec2i& position,
|
||||
const cvf::Vec2ui& size,
|
||||
bool software);
|
||||
void renderAxisImmediateMode(float upperY, float lowerBoundY, float border, cvf::OpenGLContext* oglContext);
|
||||
|
||||
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_sgasRange;
|
||||
cvf::String m_swatRange;
|
||||
|
Loading…
Reference in New Issue
Block a user