#2478 Add top edge axis (intersection View) and repositioned info box and legends to follow.

This commit is contained in:
Jacob Støren 2018-03-07 12:47:48 +01:00
parent 0083ecdf6a
commit df0a356a0a
3 changed files with 66 additions and 49 deletions

View File

@ -65,6 +65,7 @@ RivWindowEdgeAxesOverlayItem::RivWindowEdgeAxesOverlayItem(Font* font)
: m_windowSize(600, 600), : m_windowSize(600, 600),
m_textColor(Color3::BLACK), m_textColor(Color3::BLACK),
m_lineColor(Color3::BLACK), m_lineColor(Color3::BLACK),
m_frameColor(Color3::WHITE),
m_lineWidth(1), m_lineWidth(1),
m_font(font), m_font(font),
m_isSwitchingYAxisValueSign(true) m_isSwitchingYAxisValueSign(true)
@ -278,7 +279,9 @@ void RivWindowEdgeAxesOverlayItem::addTextToTextDrawer(TextDrawer* textDrawer)
// Bottom X - axis text // Bottom X - axis text
{ {
const float textY = m_pixelSpacing + m_textSize.y()*0.5f; const float textYTop = m_windowSize.y() - m_pixelSpacing - m_textSize.y()*0.5f;
const float textYBott = m_pixelSpacing + m_textSize.y()*0.5f;
size_t numTicks = m_domainCoordsXValues.size(); size_t numTicks = m_domainCoordsXValues.size();
size_t i; size_t i;
for ( i = 0; i < numTicks; i++ ) for ( i = 0; i < numTicks; i++ )
@ -291,14 +294,17 @@ void RivWindowEdgeAxesOverlayItem::addTextToTextDrawer(TextDrawer* textDrawer)
valueString = String::number(tickValue); valueString = String::number(tickValue);
auto labelSize = m_font->textExtent(valueString); auto labelSize = m_font->textExtent(valueString);
Vec2f pos(textX - labelSize.x()*0.5f, textY); Vec2f pos(textX - labelSize.x()*0.5f, textYBott);
textDrawer->addText(valueString, pos);
pos[1] = textYTop;
textDrawer->addText(valueString, pos); textDrawer->addText(valueString, pos);
} }
} }
// Right Y - axis texts // Right Y - axis texts
{ {
const float textX = m_windowSize.x() - m_pixelSpacing - m_textSize.x(); const float textXRight = m_windowSize.x() - m_pixelSpacing - m_textSize.x();
const float textXLeft = m_frameBorderWidth - m_tickLineLength - m_pixelSpacing;
size_t numTicks = m_domainCoordsYValues.size(); size_t numTicks = m_domainCoordsYValues.size();
size_t i; size_t i;
@ -312,29 +318,10 @@ void RivWindowEdgeAxesOverlayItem::addTextToTextDrawer(TextDrawer* textDrawer)
valueString = String::number(tickValue); valueString = String::number(tickValue);
auto labelSize = m_font->textExtent(valueString); auto labelSize = m_font->textExtent(valueString);
Vec2f pos(textX, textY); Vec2f pos(textXRight, textY);
textDrawer->addText(valueString, pos);
}
}
// Left Y - axis texts
{
const float textX = m_frameBorderWidth - m_tickLineLength - m_pixelSpacing;
size_t numTicks = m_domainCoordsYValues.size();
size_t i;
for ( i = 0; i < numTicks; i++ )
{
float textY = static_cast<float>(m_windowTickYValues[i]);
double tickValue = m_isSwitchingYAxisValueSign ? -m_domainCoordsYValues[i]: m_domainCoordsYValues[i];
String valueString;
valueString = String::number(tickValue);
auto labelSize = m_font->textExtent(valueString);
Vec2f pos(textX - labelSize.x(), textY);
textDrawer->addText(valueString, pos); textDrawer->addText(valueString, pos);
Vec2f posl(textXLeft - labelSize.x(), textY);
textDrawer->addText(valueString, posl);
} }
} }
} }
@ -347,15 +334,22 @@ std::array<Vec3f, 8> RivWindowEdgeAxesOverlayItem::frameVertexArray()
float windowWidth = static_cast<float>(m_windowSize.x()); float windowWidth = static_cast<float>(m_windowSize.x());
float windowHeight = static_cast<float>(m_windowSize.y()); float windowHeight = static_cast<float>(m_windowSize.y());
// 3 2
// 7 6
//
// 4 5
// 0 1
std::array<Vec3f, 8> vertexArray ={ std::array<Vec3f, 8> vertexArray ={
Vec3f(0.0f , 0.0f , 0.0f), Vec3f(0.0f , 0.0f , 0.0f),
Vec3f(windowWidth , 0.0f , 0.0f), Vec3f(windowWidth , 0.0f , 0.0f),
Vec3f(windowWidth , windowHeight , 0.0f), Vec3f(windowWidth , windowHeight , 0.0f),
Vec3f(0.0f , windowHeight , 0.0f), Vec3f(0.0f , windowHeight , 0.0f),
Vec3f(m_frameBorderWidth , m_frameBorderHeight, 0.0f),
Vec3f(windowWidth - m_frameBorderWidth, m_frameBorderHeight, 0.0f), Vec3f(m_frameBorderWidth , m_frameBorderHeight , 0.0f),
Vec3f(windowWidth - m_frameBorderWidth, windowHeight , 0.0f), Vec3f(windowWidth - m_frameBorderWidth, m_frameBorderHeight , 0.0f),
Vec3f(m_frameBorderWidth , windowHeight , 0.0f), Vec3f(windowWidth - m_frameBorderWidth, windowHeight - m_frameBorderHeight, 0.0f),
Vec3f(m_frameBorderWidth , windowHeight - m_frameBorderHeight, 0.0f),
}; };
return vertexArray; return vertexArray;
@ -380,7 +374,7 @@ void RivWindowEdgeAxesOverlayItem::renderSoftwareFrameAndTickLines(OpenGLContext
std::array<Vec3f, 8> vertexArray = frameVertexArray(); std::array<Vec3f, 8> vertexArray = frameVertexArray();
glColor4fv(Vec4f(1.0f,1.0f,1.0f,0.5f).ptr()); glColor4fv(m_frameColor.ptr());
glBegin(GL_TRIANGLE_FAN); glBegin(GL_TRIANGLE_FAN);
glVertex3fv(vertexArray[0].ptr()); glVertex3fv(vertexArray[0].ptr());
glVertex3fv(vertexArray[1].ptr()); glVertex3fv(vertexArray[1].ptr());
@ -399,6 +393,12 @@ void RivWindowEdgeAxesOverlayItem::renderSoftwareFrameAndTickLines(OpenGLContext
glVertex3fv(vertexArray[4].ptr()); glVertex3fv(vertexArray[4].ptr());
glVertex3fv(vertexArray[7].ptr()); glVertex3fv(vertexArray[7].ptr());
glEnd(); glEnd();
glBegin(GL_TRIANGLE_FAN);
glVertex3fv(vertexArray[2].ptr());
glVertex3fv(vertexArray[3].ptr());
glVertex3fv(vertexArray[7].ptr());
glVertex3fv(vertexArray[6].ptr());
glEnd();
// Render Line around // Render Line around
@ -413,6 +413,8 @@ void RivWindowEdgeAxesOverlayItem::renderSoftwareFrameAndTickLines(OpenGLContext
glVertex3fv(vertexArray[5].ptr()); glVertex3fv(vertexArray[5].ptr());
glVertex3fv(vertexArray[5].ptr()); glVertex3fv(vertexArray[5].ptr());
glVertex3fv(vertexArray[6].ptr()); glVertex3fv(vertexArray[6].ptr());
glVertex3fv(vertexArray[6].ptr());
glVertex3fv(vertexArray[7].ptr());
// X - axis Tick lines // X - axis Tick lines
for (double txpos : m_windowTickXValues) for (double txpos : m_windowTickXValues)
@ -427,6 +429,14 @@ void RivWindowEdgeAxesOverlayItem::renderSoftwareFrameAndTickLines(OpenGLContext
glVertex3fv(p1.ptr()); glVertex3fv(p1.ptr());
glVertex3fv(p2.ptr()); glVertex3fv(p2.ptr());
p1[0] = (float)txpos;
p1[1] = m_windowSize.y() - m_frameBorderHeight;
p2[0] = (float)txpos;
p2[1] = m_windowSize.y() - m_frameBorderHeight + m_tickLineLength;
glVertex3fv(p1.ptr());
glVertex3fv(p2.ptr());
} }
// Left Y - axis Tick lines // Left Y - axis Tick lines
@ -503,16 +513,17 @@ void RivWindowEdgeAxesOverlayItem::renderShaderFrameAndTickLines(OpenGLContext*
// Draw frame background // Draw frame background
UniformFloat backgroundColorUniform("u_color", Color4f(1.0f, 1.0f, 1.0f, 0.5f)); UniformFloat backgroundColorUniform("u_color", m_frameColor);
shaderProgram->applyUniform(oglContext, backgroundColorUniform); shaderProgram->applyUniform(oglContext, backgroundColorUniform);
// Triangle indices for the frame background // Triangle indices for the frame background
static const ushort backgroundTriangleIndices[] = { 0, 1, 5, 0, 5, 4, static const ushort backgroundTriangleIndices[] = { 0, 1, 5, 0, 5, 4,
1, 2, 6, 1, 6, 5, 1, 2, 6, 1, 6, 5,
3, 0, 4, 3, 4, 7 }; 3, 0, 4, 3, 4, 7,
2, 3, 6, 3, 7, 6 };
glDrawRangeElements(GL_TRIANGLES, 0, 7, 18, GL_UNSIGNED_SHORT, backgroundTriangleIndices); glDrawRangeElements(GL_TRIANGLES, 0, 7, 24, GL_UNSIGNED_SHORT, backgroundTriangleIndices);
// Draw frame border lines // Draw frame border lines
@ -522,9 +533,10 @@ void RivWindowEdgeAxesOverlayItem::renderShaderFrameAndTickLines(OpenGLContext*
static const ushort frameLineIndices[] = { 7, 4, static const ushort frameLineIndices[] = { 7, 4,
4, 5, 4, 5,
5, 6 }; 5, 6,
6, 7 };
glDrawRangeElements(GL_LINES, 0, 7, 6, GL_UNSIGNED_SHORT, frameLineIndices); glDrawRangeElements(GL_LINES, 0, 7, 8, GL_UNSIGNED_SHORT, frameLineIndices);
// Render tickmarks // Render tickmarks
@ -540,6 +552,13 @@ void RivWindowEdgeAxesOverlayItem::renderShaderFrameAndTickLines(OpenGLContext*
vertexArray[1][1] = m_frameBorderHeight - m_tickLineLength; vertexArray[1][1] = m_frameBorderHeight - m_tickLineLength;
glDrawRangeElements(GL_LINES, 0, 1, 2, GL_UNSIGNED_SHORT, tickLineIndices); glDrawRangeElements(GL_LINES, 0, 1, 2, GL_UNSIGNED_SHORT, tickLineIndices);
vertexArray[0][0] = (float)txpos;
vertexArray[0][1] = m_windowSize.y() - m_frameBorderHeight;
vertexArray[1][0] = (float)txpos;
vertexArray[1][1] = m_windowSize.y() - m_frameBorderHeight + m_tickLineLength;
glDrawRangeElements(GL_LINES, 0, 1, 2, GL_UNSIGNED_SHORT, tickLineIndices);
} }
// Left Y - axis Tick lines // Left Y - axis Tick lines

View File

@ -72,6 +72,7 @@ class RivWindowEdgeAxesOverlayItem : public cvf::OverlayItem
using OpenGLContext = cvf::OpenGLContext; using OpenGLContext = cvf::OpenGLContext;
using Vec2i = cvf::Vec2i; using Vec2i = cvf::Vec2i;
using Color3f = cvf::Color3f; using Color3f = cvf::Color3f;
using Color4f = cvf::Color4f;
using String = cvf::String; using String = cvf::String;
using Vec2f = cvf::Vec2f; using Vec2f = cvf::Vec2f;
using Vec3f = cvf::Vec3f; using Vec3f = cvf::Vec3f;
@ -91,6 +92,7 @@ public:
const Color3f& textColor() const; const Color3f& textColor() const;
void setLineColor(const Color3f& lineColor); void setLineColor(const Color3f& lineColor);
const Color3f& lineColor() const; const Color3f& lineColor() const;
void setFrameColor(const Color4f& frameColor);
int frameBorderWidth() { return static_cast<int>( m_frameBorderWidth); } int frameBorderWidth() { return static_cast<int>( m_frameBorderWidth); }
int frameBorderHeight() { return static_cast<int>( m_frameBorderHeight); } int frameBorderHeight() { return static_cast<int>( m_frameBorderHeight); }
@ -116,6 +118,7 @@ private:
Vec2ui m_textSize; Vec2ui m_textSize;
Color3f m_textColor; Color3f m_textColor;
Color3f m_lineColor; Color3f m_lineColor;
Color4f m_frameColor;
int m_lineWidth; int m_lineWidth;
cvf::ref<Font> m_font; cvf::ref<Font> m_font;

View File

@ -347,22 +347,17 @@ void RiuViewer::setEnableMask(unsigned int mask)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuViewer::paintOverlayItems(QPainter* painter) void RiuViewer::paintOverlayItems(QPainter* painter)
{ {
// No support for overlay items using SW rendering yet.
//if (!isShadersSupported())
//{
// return;
//}
int columnWidth = 200; int columnWidth = 200;
int edgeAxisFrameBorderWidth = m_showWindowEdgeAxes ? m_windowEdgeAxisOverlay->frameBorderWidth(): 0; int edgeAxisFrameBorderWidth = m_showWindowEdgeAxes ? m_windowEdgeAxisOverlay->frameBorderWidth(): 0;
int edgeAxisFrameBorderHeight = m_showWindowEdgeAxes ? m_windowEdgeAxisOverlay->frameBorderHeight(): 0; int edgeAxisFrameBorderHeight = m_showWindowEdgeAxes ? m_windowEdgeAxisOverlay->frameBorderHeight(): 0;
int margin = 5; int margin = 5;
int yPos = margin; int yPos = margin + edgeAxisFrameBorderHeight;
bool showAnimBar = false; bool showAnimBar = false;
if (isAnimationActive() && frameCount() > 1) showAnimBar = true; if (isAnimationActive() && frameCount() > 1) showAnimBar = true;
//if (showAnimBar) columnWidth = CVF_MAX(columnWidth, m_animationProgress->width());
if (m_showInfoText) columnWidth = CVF_MAX(columnWidth, m_infoLabel->sizeHint().width()); if (m_showInfoText) columnWidth = CVF_MAX(columnWidth, m_infoLabel->sizeHint().width());
int columnPos = this->width() - columnWidth - margin - edgeAxisFrameBorderWidth; int columnPos = this->width() - columnWidth - margin - edgeAxisFrameBorderWidth;
@ -598,7 +593,7 @@ void RiuViewer::addColorLegendToBottomLeftCorner(cvf::OverlayItem* legend)
for (auto catLegend : categoryLegends) for (auto catLegend : categoryLegends)
{ {
catLegend->setLayoutFixedPosition(cvf::Vec2i(xPos, yPos)); catLegend->setLayoutFixedPosition(cvf::Vec2i(xPos, yPos));
catLegend->setSizeHint(cvf::Vec2ui(categoryWidth, height - 2*border - axisCrossHeight - edgeAxisBorderHeight)); catLegend->setSizeHint(cvf::Vec2ui(categoryWidth, height - 2*border - axisCrossHeight - 2*edgeAxisBorderHeight));
xPos += categoryWidth + border; xPos += categoryWidth + border;
} }