2016-08-02 03:25:55 -05:00
|
|
|
|
|
|
|
#include "cafCategoryLegend.h"
|
|
|
|
#include "cafCategoryMapper.h"
|
|
|
|
|
|
|
|
#include "cvfBase.h"
|
|
|
|
#include "cvfBufferObjectManaged.h"
|
|
|
|
#include "cvfCamera.h"
|
|
|
|
#include "cvfFont.h"
|
|
|
|
#include "cvfGeometryBuilderDrawableGeo.h"
|
|
|
|
#include "cvfGeometryUtils.h"
|
|
|
|
#include "cvfGlyph.h"
|
|
|
|
#include "cvfMatrixState.h"
|
|
|
|
#include "cvfOpenGL.h"
|
|
|
|
#include "cvfOpenGLResourceManager.h"
|
|
|
|
#include "cvfRenderStateDepth.h"
|
|
|
|
#include "cvfRenderStateLine.h"
|
|
|
|
#include "cvfShaderProgram.h"
|
|
|
|
#include "cvfShaderProgramGenerator.h"
|
|
|
|
#include "cvfShaderSourceProvider.h"
|
|
|
|
#include "cvfShaderSourceRepository.h"
|
|
|
|
#include "cvfTextDrawer.h"
|
|
|
|
#include "cvfUniform.h"
|
|
|
|
#include "cvfViewport.h"
|
|
|
|
|
|
|
|
#ifndef CVF_OPENGL_ES
|
|
|
|
#include "cvfRenderState_FF.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "cvfScalarMapper.h"
|
2018-03-08 04:38:51 -06:00
|
|
|
#include "cafInternalLegendRenderTools.h"
|
2016-08-02 03:25:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
using namespace cvf;
|
|
|
|
|
|
|
|
namespace caf {
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
CategoryLegend::CategoryLegend(Font* font, const CategoryMapper* categoryMapper)
|
2018-04-05 08:25:33 -05:00
|
|
|
: TitledOverlayFrame(font, 200, 200)
|
|
|
|
, m_categoryMapper(categoryMapper)
|
2016-08-02 03:25:55 -05:00
|
|
|
{
|
|
|
|
CVF_ASSERT(font);
|
|
|
|
CVF_ASSERT(!font->isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
CategoryLegend::~CategoryLegend()
|
|
|
|
{
|
|
|
|
// Empty destructor to avoid errors with undefined types when cvf::ref's destructor gets called
|
|
|
|
}
|
|
|
|
|
2016-09-22 08:31:21 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
size_t CategoryLegend::categoryCount() const
|
|
|
|
{
|
|
|
|
if (m_categoryMapper.notNull())
|
|
|
|
{
|
|
|
|
return m_categoryMapper->categoryCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-02 03:25:55 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Hardware rendering using shader programs
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void CategoryLegend::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
|
|
|
{
|
2018-03-08 04:20:27 -06:00
|
|
|
renderGeneric(oglContext, position, size, false);
|
2016-08-02 03:25:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Software rendering using software
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void CategoryLegend::renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
|
|
|
{
|
2018-03-08 04:20:27 -06:00
|
|
|
renderGeneric(oglContext, position, size, true);
|
2016-08-02 03:25:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool CategoryLegend::pick(int oglXCoord, int oglYCoord, const Vec2i& position, const Vec2ui& size)
|
|
|
|
{
|
|
|
|
Recti oglRect(position, size.x(), size.y());
|
|
|
|
|
|
|
|
OverlayColorLegendLayoutInfo layoutInViewPortCoords(oglRect.min(), Vec2ui(oglRect.width(), oglRect.height()));
|
|
|
|
layoutInfo(&layoutInViewPortCoords);
|
|
|
|
|
|
|
|
Vec2i legendBarOrigin = oglRect.min();
|
|
|
|
legendBarOrigin.x() += static_cast<uint>(layoutInViewPortCoords.legendRect.min().x());
|
|
|
|
legendBarOrigin.y() += static_cast<uint>(layoutInViewPortCoords.legendRect.min().y());
|
|
|
|
|
|
|
|
Recti legendBarRect = Recti(legendBarOrigin, static_cast<uint>(layoutInViewPortCoords.legendRect.width()), static_cast<uint>(layoutInViewPortCoords.legendRect.height()));
|
|
|
|
|
|
|
|
if ((oglXCoord > legendBarRect.min().x()) && (oglXCoord < legendBarRect.max().x()) &&
|
|
|
|
(oglYCoord > legendBarRect.min().y()) && (oglYCoord < legendBarRect.max().y()))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Set up camera/viewport and render
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-08 04:38:51 -06:00
|
|
|
void CategoryLegend::renderGeneric(OpenGLContext* oglContext,
|
|
|
|
const Vec2i& position,
|
|
|
|
const Vec2ui& size,
|
|
|
|
bool software)
|
2016-08-02 03:25:55 -05:00
|
|
|
{
|
|
|
|
if (size.x() <= 0 || size.y() <= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Camera camera;
|
|
|
|
camera.setViewport(position.x(), position.y(), size.x(), size.y());
|
|
|
|
camera.setProjectionAsPixelExact2D();
|
|
|
|
camera.setViewMatrix(Mat4d::IDENTITY);
|
|
|
|
camera.applyOpenGL();
|
|
|
|
camera.viewport()->applyOpenGL(oglContext, Viewport::CLEAR_DEPTH);
|
|
|
|
|
|
|
|
// Get layout information
|
|
|
|
// Todo: Cache this between renderings. Update only when needed.
|
|
|
|
OverlayColorLegendLayoutInfo layout(position, size);
|
|
|
|
layoutInfo(&layout);
|
|
|
|
|
|
|
|
// Set up text drawer
|
2018-03-08 04:38:51 -06:00
|
|
|
float maxLegendRightPos = 0;
|
2018-04-05 08:25:33 -05:00
|
|
|
TextDrawer textDrawer(this->font());
|
2018-03-08 04:38:51 -06:00
|
|
|
setupTextDrawer(&textDrawer, &layout, &maxLegendRightPos);
|
|
|
|
|
2018-04-06 04:52:29 -05:00
|
|
|
Vec2f backgroundSize(CVF_MIN(maxLegendRightPos + layout.margins.x(), (float)size.x()), (float)size.y());
|
2016-08-02 03:25:55 -05:00
|
|
|
|
|
|
|
// Do the actual rendering
|
|
|
|
if (software)
|
|
|
|
{
|
2018-04-05 08:25:33 -05:00
|
|
|
if (this->backgroundEnabled()) InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext,
|
2018-03-08 04:38:51 -06:00
|
|
|
backgroundSize,
|
2018-04-05 08:25:33 -05:00
|
|
|
this->backgroundColor(),
|
|
|
|
this->backgroundFrameColor());
|
2016-08-02 03:25:55 -05:00
|
|
|
renderLegendImmediateMode(oglContext, &layout);
|
|
|
|
textDrawer.renderSoftware(oglContext, camera);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const MatrixState matrixState(camera);
|
2018-04-05 08:25:33 -05:00
|
|
|
if (this->backgroundEnabled()) InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext,
|
2018-03-08 04:38:51 -06:00
|
|
|
matrixState,
|
|
|
|
backgroundSize,
|
2018-04-05 08:25:33 -05:00
|
|
|
this->backgroundColor(),
|
|
|
|
this->backgroundFrameColor());
|
2018-03-08 04:20:27 -06:00
|
|
|
renderLegendUsingShaders(oglContext, &layout, matrixState);
|
2016-08-02 03:25:55 -05:00
|
|
|
textDrawer.render(oglContext, camera);
|
|
|
|
}
|
|
|
|
|
|
|
|
CVF_CHECK_OGL(oglContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-08 04:38:51 -06:00
|
|
|
void CategoryLegend::setupTextDrawer(TextDrawer* textDrawer,
|
|
|
|
OverlayColorLegendLayoutInfo* layout,
|
|
|
|
float* maxLegendRightPos)
|
2016-08-02 03:25:55 -05:00
|
|
|
{
|
|
|
|
if (m_categoryMapper.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CVF_ASSERT(layout);
|
|
|
|
|
2018-03-08 04:38:51 -06:00
|
|
|
float legendRight = 0.0f;
|
|
|
|
|
2016-08-02 03:25:55 -05:00
|
|
|
textDrawer->setVerticalAlignment(TextDrawer::CENTER);
|
2018-04-05 08:25:33 -05:00
|
|
|
textDrawer->setTextColor(this->textColor());
|
2016-08-02 03:25:55 -05:00
|
|
|
|
|
|
|
m_visibleCategoryLabels.clear();
|
|
|
|
|
|
|
|
const float textX = layout->tickX + 5;
|
|
|
|
|
|
|
|
const float overlapTolerance = 1.2f * layout->charHeight;
|
|
|
|
float lastVisibleTextY = 0.0;
|
|
|
|
|
|
|
|
CVF_ASSERT(m_categoryMapper.notNull());
|
2016-09-06 04:15:21 -05:00
|
|
|
size_t numLabels = m_categoryMapper->categoryCount();
|
2016-08-02 03:25:55 -05:00
|
|
|
|
|
|
|
float categoryHeight = static_cast<float>(layout->legendRect.height() / numLabels);
|
|
|
|
|
|
|
|
for (size_t it = 0; it < numLabels; it++)
|
|
|
|
{
|
|
|
|
float textY = static_cast<float>(layout->legendRect.min().y() + it * categoryHeight + categoryHeight / 2);
|
|
|
|
|
|
|
|
// Always draw first and last tick label. For all others, skip drawing if text ends up
|
|
|
|
// on top of the previous label.
|
|
|
|
if (it != 0 && it != (numLabels - 1))
|
|
|
|
{
|
|
|
|
if (cvf::Math::abs(textY - lastVisibleTextY) < overlapTolerance)
|
|
|
|
{
|
|
|
|
m_visibleCategoryLabels.push_back(false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Make sure it does not overlap the last tick as well
|
|
|
|
|
|
|
|
float lastTickY = static_cast<float>(layout->legendRect.max().y());
|
|
|
|
|
|
|
|
if (cvf::Math::abs(textY - lastTickY) < overlapTolerance)
|
|
|
|
{
|
|
|
|
m_visibleCategoryLabels.push_back(false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-06 04:15:21 -05:00
|
|
|
String displayText = m_categoryMapper->textForCategoryIndex(it);
|
2016-08-02 03:25:55 -05:00
|
|
|
|
|
|
|
Vec2f pos(textX, textY);
|
2016-09-06 04:15:21 -05:00
|
|
|
textDrawer->addText(displayText, pos);
|
2016-08-02 03:25:55 -05:00
|
|
|
|
2018-04-05 08:25:33 -05:00
|
|
|
float neededRightPos = pos.x() + this->font()->textExtent(displayText).x();
|
2018-03-08 04:38:51 -06:00
|
|
|
legendRight = legendRight >= neededRightPos ? legendRight :neededRightPos;
|
|
|
|
|
2016-08-02 03:25:55 -05:00
|
|
|
lastVisibleTextY = textY;
|
|
|
|
m_visibleCategoryLabels.push_back(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
float titleY = static_cast<float>(layout->size.y()) - layout->margins.y() - layout->charHeight / 2.0f;
|
2018-04-05 08:25:33 -05:00
|
|
|
for (size_t it = 0; it < this->titleStrings().size(); it++)
|
2016-08-02 03:25:55 -05:00
|
|
|
{
|
|
|
|
Vec2f pos(layout->margins.x(), titleY);
|
2018-04-05 08:25:33 -05:00
|
|
|
textDrawer->addText(this->titleStrings()[it], pos);
|
2016-08-02 03:25:55 -05:00
|
|
|
|
2018-04-05 08:25:33 -05:00
|
|
|
float neededRightPos = pos.x() + this->font()->textExtent(this->titleStrings()[it]).x();
|
2018-03-08 04:38:51 -06:00
|
|
|
legendRight = legendRight >= neededRightPos ? legendRight :neededRightPos;
|
|
|
|
|
2016-08-02 03:25:55 -05:00
|
|
|
titleY -= layout->lineSpacing;
|
|
|
|
}
|
2018-03-08 04:38:51 -06:00
|
|
|
|
|
|
|
*maxLegendRightPos = legendRight;
|
2016-08-02 03:25:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Draw the legend using shader programs
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-08 04:38:51 -06:00
|
|
|
void CategoryLegend::renderLegendUsingShaders(OpenGLContext* oglContext,
|
|
|
|
OverlayColorLegendLayoutInfo* layout,
|
|
|
|
const MatrixState& matrixState)
|
2016-08-02 03:25:55 -05:00
|
|
|
{
|
|
|
|
CVF_CALLSITE_OPENGL(oglContext);
|
|
|
|
|
|
|
|
CVF_TIGHT_ASSERT(layout);
|
|
|
|
CVF_TIGHT_ASSERT(layout->size.x() > 0);
|
|
|
|
CVF_TIGHT_ASSERT(layout->size.y() > 0);
|
|
|
|
|
|
|
|
RenderStateDepth depth(false);
|
|
|
|
depth.applyOpenGL(oglContext);
|
2018-04-05 08:25:33 -05:00
|
|
|
RenderStateLine line(static_cast<float>(this->lineWidth()));
|
2016-08-02 03:25:55 -05:00
|
|
|
line.applyOpenGL(oglContext);
|
|
|
|
|
|
|
|
// All vertices. Initialized here to set Z to zero once and for all.
|
|
|
|
static float vertexArray[] =
|
|
|
|
{
|
|
|
|
0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f
|
|
|
|
};
|
|
|
|
|
|
|
|
// Per vector convenience pointers
|
|
|
|
float* v0 = &vertexArray[0];
|
|
|
|
float* v1 = &vertexArray[3];
|
|
|
|
float* v2 = &vertexArray[6];
|
|
|
|
float* v3 = &vertexArray[9];
|
|
|
|
float* v4 = &vertexArray[12];
|
|
|
|
|
|
|
|
// Constant coordinates
|
|
|
|
v0[0] = v3[0] = layout->x0;
|
|
|
|
v1[0] = v4[0] = layout->x1;
|
|
|
|
|
|
|
|
// Connects
|
|
|
|
static const ushort trianglesConnects[] = { 0, 1, 4, 0, 4, 3 };
|
|
|
|
|
|
|
|
ref<ShaderProgram> shaderProgram = oglContext->resourceManager()->getLinkedUnlitColorShaderProgram(oglContext);
|
|
|
|
CVF_TIGHT_ASSERT(shaderProgram.notNull());
|
|
|
|
|
|
|
|
if (shaderProgram->useProgram(oglContext))
|
|
|
|
{
|
|
|
|
shaderProgram->clearUniformApplyTracking();
|
|
|
|
shaderProgram->applyFixedUniforms(oglContext, matrixState);
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
glEnableVertexAttribArray(ShaderProgram::VERTEX);
|
|
|
|
glVertexAttribPointer(ShaderProgram::VERTEX, 3, GL_FLOAT, GL_FALSE, 0, vertexArray);
|
|
|
|
|
|
|
|
// Render color bar as one colored quad per pixel
|
|
|
|
|
|
|
|
int legendHeightPixelCount = static_cast<int>(layout->legendRect.height());
|
|
|
|
if (m_categoryMapper.notNull())
|
|
|
|
{
|
|
|
|
int iPx;
|
|
|
|
for (iPx = 0; iPx < legendHeightPixelCount; iPx++)
|
|
|
|
{
|
|
|
|
const Color3ub& clr = m_categoryMapper->mapToColor(m_categoryMapper->domainValue((iPx + 0.5) / legendHeightPixelCount));
|
|
|
|
float y0 = static_cast<float>(layout->legendRect.min().y() + iPx);
|
|
|
|
float y1 = static_cast<float>(layout->legendRect.min().y() + iPx + 1);
|
|
|
|
|
|
|
|
// Dynamic coordinates for rectangle
|
|
|
|
v0[1] = v1[1] = y0;
|
|
|
|
v3[1] = v4[1] = y1;
|
|
|
|
|
|
|
|
// Draw filled rectangle elements
|
|
|
|
{
|
|
|
|
UniformFloat uniformColor("u_color", Color4f(Color3f(clr)));
|
|
|
|
shaderProgram->applyUniform(oglContext, uniformColor);
|
|
|
|
|
|
|
|
#ifdef CVF_OPENGL_ES
|
|
|
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, trianglesConnects);
|
|
|
|
#else
|
|
|
|
glDrawRangeElements(GL_TRIANGLES, 0, 4, 6, GL_UNSIGNED_SHORT, trianglesConnects);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render frame
|
|
|
|
|
|
|
|
// Dynamic coordinates for tickmarks-lines
|
|
|
|
bool isRenderingFrame = true;
|
|
|
|
if (isRenderingFrame)
|
|
|
|
{
|
|
|
|
v0[0] = v2[0] = layout->legendRect.min().x() - 0.5f;
|
|
|
|
v1[0] = v3[0] = layout->legendRect.max().x() - 0.5f;
|
|
|
|
v0[1] = v1[1] = layout->legendRect.min().y() - 0.5f;
|
|
|
|
v2[1] = v3[1] = layout->legendRect.max().y() - 0.5f;
|
|
|
|
static const ushort frameConnects[] = { 0, 1, 1, 3, 3, 2, 2, 0 };
|
|
|
|
|
2018-04-05 08:25:33 -05:00
|
|
|
UniformFloat uniformColor("u_color", Color4f(this->lineColor()));
|
2016-08-02 03:25:55 -05:00
|
|
|
shaderProgram->applyUniform(oglContext, uniformColor);
|
|
|
|
|
|
|
|
#ifdef CVF_OPENGL_ES
|
|
|
|
glDrawElements(GL_LINES, 8, GL_UNSIGNED_SHORT, frameConnects);
|
|
|
|
#else
|
|
|
|
glDrawRangeElements(GL_LINES, 0, 3, 8, GL_UNSIGNED_SHORT, frameConnects);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisableVertexAttribArray(ShaderProgram::VERTEX);
|
|
|
|
|
|
|
|
CVF_TIGHT_ASSERT(shaderProgram.notNull());
|
|
|
|
shaderProgram->useNoProgram(oglContext);
|
|
|
|
|
|
|
|
// Reset render states
|
|
|
|
RenderStateDepth resetDepth;
|
|
|
|
resetDepth.applyOpenGL(oglContext);
|
|
|
|
|
|
|
|
RenderStateLine resetLine;
|
|
|
|
resetLine.applyOpenGL(oglContext);
|
|
|
|
|
|
|
|
CVF_CHECK_OGL(oglContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Draw the legend using immediate mode OpenGL
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void CategoryLegend::renderLegendImmediateMode(OpenGLContext* oglContext, OverlayColorLegendLayoutInfo* layout)
|
|
|
|
{
|
|
|
|
#ifdef CVF_OPENGL_ES
|
|
|
|
CVF_UNUSED(layout);
|
|
|
|
CVF_FAIL_MSG("Not supported on OpenGL ES");
|
|
|
|
#else
|
|
|
|
CVF_TIGHT_ASSERT(layout);
|
|
|
|
CVF_TIGHT_ASSERT(layout->size.x() > 0);
|
|
|
|
CVF_TIGHT_ASSERT(layout->size.y() > 0);
|
|
|
|
|
|
|
|
RenderStateDepth depth(false);
|
|
|
|
depth.applyOpenGL(oglContext);
|
|
|
|
|
|
|
|
RenderStateLighting_FF lighting(false);
|
|
|
|
lighting.applyOpenGL(oglContext);
|
|
|
|
|
|
|
|
// All vertices. Initialized here to set Z to zero once and for all.
|
|
|
|
static float vertexArray[] =
|
|
|
|
{
|
|
|
|
0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Per vector convenience pointers
|
|
|
|
float* v0 = &vertexArray[0];
|
|
|
|
float* v1 = &vertexArray[3];
|
|
|
|
float* v2 = &vertexArray[6];
|
|
|
|
float* v3 = &vertexArray[9];
|
|
|
|
float* v4 = &vertexArray[12];
|
|
|
|
|
|
|
|
// Constant coordinates
|
|
|
|
v0[0] = v3[0] = layout->x0;
|
|
|
|
v1[0] = v4[0] = layout->x1;
|
|
|
|
|
|
|
|
// Render color bar as one colored quad per pixel
|
|
|
|
|
|
|
|
int legendHeightPixelCount = static_cast<int>(layout->legendRect.height());
|
|
|
|
if (m_categoryMapper.notNull())
|
|
|
|
{
|
|
|
|
int iPx;
|
|
|
|
for (iPx = 0; iPx < legendHeightPixelCount; iPx++)
|
|
|
|
{
|
|
|
|
const Color3ub& clr = m_categoryMapper->mapToColor(m_categoryMapper->domainValue((iPx + 0.5) / legendHeightPixelCount));
|
|
|
|
float y0 = static_cast<float>(layout->legendRect.min().y() + iPx);
|
|
|
|
float y1 = static_cast<float>(layout->legendRect.min().y() + iPx + 1);
|
|
|
|
|
|
|
|
// Dynamic coordinates for rectangle
|
|
|
|
v0[1] = v1[1] = y0;
|
|
|
|
v3[1] = v4[1] = y1;
|
|
|
|
|
|
|
|
// Draw filled rectangle elements
|
|
|
|
glColor3ubv(clr.ptr());
|
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
glVertex3fv(v0);
|
|
|
|
glVertex3fv(v1);
|
|
|
|
glVertex3fv(v4);
|
|
|
|
glVertex3fv(v3);
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render frame
|
|
|
|
|
|
|
|
// Dynamic coordinates for tickmarks-lines
|
|
|
|
bool isRenderingFrame = true;
|
|
|
|
if (isRenderingFrame)
|
|
|
|
{
|
|
|
|
v0[0] = v2[0] = layout->legendRect.min().x() - 0.5f;
|
|
|
|
v1[0] = v3[0] = layout->legendRect.max().x() - 0.5f;
|
|
|
|
v0[1] = v1[1] = layout->legendRect.min().y() - 0.5f;
|
|
|
|
v2[1] = v3[1] = layout->legendRect.max().y() - 0.5f;
|
|
|
|
|
2018-04-05 08:25:33 -05:00
|
|
|
glColor3fv(this->textColor().ptr());
|
2016-08-02 03:25:55 -05:00
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3fv(v0);
|
|
|
|
glVertex3fv(v1);
|
|
|
|
glVertex3fv(v1);
|
|
|
|
glVertex3fv(v3);
|
|
|
|
glVertex3fv(v3);
|
|
|
|
glVertex3fv(v2);
|
|
|
|
glVertex3fv(v2);
|
|
|
|
glVertex3fv(v0);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset render states
|
|
|
|
RenderStateLighting_FF resetLighting;
|
|
|
|
resetLighting.applyOpenGL(oglContext);
|
|
|
|
RenderStateDepth resetDepth;
|
|
|
|
resetDepth.applyOpenGL(oglContext);
|
|
|
|
|
|
|
|
CVF_CHECK_OGL(oglContext);
|
|
|
|
#endif // CVF_OPENGL_ES
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Get layout information
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void CategoryLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout)
|
|
|
|
{
|
|
|
|
CVF_TIGHT_ASSERT(layout);
|
|
|
|
|
2018-04-05 08:25:33 -05:00
|
|
|
ref<Glyph> glyph = this->font()->getGlyph(L'A');
|
2016-08-02 03:25:55 -05:00
|
|
|
layout->charHeight = static_cast<float>(glyph->height());
|
|
|
|
layout->lineSpacing = layout->charHeight*1.5f;
|
2018-04-06 04:52:29 -05:00
|
|
|
layout->margins = Vec2f(8.0f, 8.0f);
|
2016-08-02 03:25:55 -05:00
|
|
|
|
|
|
|
float legendWidth = 25.0f;
|
2018-04-05 08:25:33 -05:00
|
|
|
float legendHeight = static_cast<float>(layout->size.y()) - 2 * layout->margins.y() - static_cast<float>(this->titleStrings().size())*layout->lineSpacing - layout->lineSpacing;
|
2016-08-02 03:25:55 -05:00
|
|
|
layout->legendRect = Rectf(layout->margins.x(), layout->margins.y() + layout->charHeight / 2.0f, legendWidth, legendHeight);
|
|
|
|
|
|
|
|
if (layout->legendRect.width() < 1 || layout->legendRect.height() < 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
layout->x0 = layout->margins.x();
|
|
|
|
layout->x1 = layout->margins.x() + layout->legendRect.width();
|
|
|
|
layout->tickX = layout->x1 + 5;
|
|
|
|
}
|
|
|
|
|
2018-03-08 04:20:27 -06:00
|
|
|
|
2016-08-02 03:25:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace cvf
|
|
|
|
|