summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2014-04-01 10:04:51 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2014-04-01 10:27:13 +0300
commite076fa05488bb9f58393f0e636c97d07b6fb446d (patch)
treeeefb7b1aed40640d7eb1f673c2fd63b2f7181027 /src
parentfe3c9ec0a9fb734e83eb70bc725c303a9d36cd6d (diff)
Axis label dragging support, part 1
Task-number: QTRD-2367 + Added label selection support to surface & scatter + Added Y-label selection support to bars Change-Id: I3153f1e38019604be763492feba66c3af084de14 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/datavisualization/engine/bars3drenderer.cpp113
-rw-r--r--src/datavisualization/engine/scatter3drenderer.cpp219
-rw-r--r--src/datavisualization/engine/scatter3drenderer_p.h2
-rw-r--r--src/datavisualization/engine/surface3drenderer.cpp151
-rw-r--r--src/datavisualization/engine/surface3drenderer_p.h2
-rw-r--r--src/datavisualization/global/datavisualizationglobal_p.h1
6 files changed, 307 insertions, 181 deletions
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp
index 6d54b190..15aa526f 100644
--- a/src/datavisualization/engine/bars3drenderer.cpp
+++ b/src/datavisualization/engine/bars3drenderer.cpp
@@ -1655,6 +1655,7 @@ void Bars3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCamer
GLfloat rowScaleFactor, GLfloat columnScaleFactor,
bool barSelectionFound, BarRenderItem *selectedBar) {
ShaderHelper *shader = 0;
+ GLfloat alphaForValueSelection = labelValueAlpha / 255.0f;
GLfloat alphaForRowSelection = labelRowAlpha / 255.0f;
GLfloat alphaForColumnSelection = labelColumnAlpha / 255.0f;
if (drawSelection) {
@@ -1672,59 +1673,63 @@ void Bars3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCamer
glEnable(GL_POLYGON_OFFSET_FILL);
// Y Labels
- if (!drawSelection) {
- int labelNbr = 0;
- int labelCount = m_axisCacheY.labelCount();
- GLfloat labelMarginXTrans = labelMargin;
- GLfloat labelMarginZTrans = labelMargin;
- GLfloat labelXTrans = rowScaleFactor;
- GLfloat labelZTrans = columnScaleFactor;
- QVector3D backLabelRotation(0.0f, -90.0f, 0.0f);
- QVector3D sideLabelRotation(0.0f, 0.0f, 0.0f);
- Qt::AlignmentFlag backAlignment = Qt::AlignLeft;
- Qt::AlignmentFlag sideAlignment = Qt::AlignLeft;
- if (!m_xFlipped) {
- labelXTrans = -labelXTrans;
- labelMarginXTrans = -labelMargin;
- backLabelRotation.setY(90.0f);
- sideAlignment = Qt::AlignRight;
- }
- if (m_zFlipped) {
- labelZTrans = -labelZTrans;
- labelMarginZTrans = -labelMargin;
- backAlignment = Qt::AlignRight;
- sideLabelRotation.setY(180.f);
- }
- QVector3D backLabelTrans = QVector3D(labelXTrans, 0.0f,
- labelZTrans + labelMarginZTrans);
- QVector3D sideLabelTrans = QVector3D(-labelXTrans - labelMarginXTrans,
- 0.0f, -labelZTrans);
-
- for (int i = 0; i < labelCount; i++) {
- if (m_axisCacheY.labelItems().size() > labelNbr) {
- backLabelTrans.setY(m_axisCacheY.labelPosition(i));
- sideLabelTrans.setY(backLabelTrans.y());
-
- glPolygonOffset(GLfloat(i) / -10.0f, 1.0f);
-
- const LabelItem &axisLabelItem = *m_axisCacheY.labelItems().at(labelNbr);
-
- // Back wall
- m_dummyBarRenderItem.setTranslation(backLabelTrans);
- m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
- zeroVector, backLabelRotation, 0, m_cachedSelectionMode,
- shader, m_labelObj, activeCamera,
- true, true, Drawer::LabelMid, backAlignment);
-
- // Side wall
- m_dummyBarRenderItem.setTranslation(sideLabelTrans);
- m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
- zeroVector, sideLabelRotation, 0, m_cachedSelectionMode,
- shader, m_labelObj, activeCamera,
- true, true, Drawer::LabelMid, sideAlignment);
+ int labelNbr = 0;
+ int labelCount = m_axisCacheY.labelCount();
+ GLfloat labelMarginXTrans = labelMargin;
+ GLfloat labelMarginZTrans = labelMargin;
+ GLfloat labelXTrans = rowScaleFactor;
+ GLfloat labelZTrans = columnScaleFactor;
+ QVector3D backLabelRotation(0.0f, -90.0f, 0.0f);
+ QVector3D sideLabelRotation(0.0f, 0.0f, 0.0f);
+ Qt::AlignmentFlag backAlignment = Qt::AlignLeft;
+ Qt::AlignmentFlag sideAlignment = Qt::AlignLeft;
+ if (!m_xFlipped) {
+ labelXTrans = -labelXTrans;
+ labelMarginXTrans = -labelMargin;
+ backLabelRotation.setY(90.0f);
+ sideAlignment = Qt::AlignRight;
+ }
+ if (m_zFlipped) {
+ labelZTrans = -labelZTrans;
+ labelMarginZTrans = -labelMargin;
+ backAlignment = Qt::AlignRight;
+ sideLabelRotation.setY(180.f);
+ }
+ QVector3D backLabelTrans = QVector3D(labelXTrans, 0.0f,
+ labelZTrans + labelMarginZTrans);
+ QVector3D sideLabelTrans = QVector3D(-labelXTrans - labelMarginXTrans,
+ 0.0f, -labelZTrans);
+
+ for (int i = 0; i < labelCount; i++) {
+ if (m_axisCacheY.labelItems().size() > labelNbr) {
+ backLabelTrans.setY(m_axisCacheY.labelPosition(i));
+ sideLabelTrans.setY(backLabelTrans.y());
+
+ glPolygonOffset(GLfloat(i) / -10.0f, 1.0f);
+
+ const LabelItem &axisLabelItem = *m_axisCacheY.labelItems().at(labelNbr);
+
+ if (drawSelection) {
+ QVector4D labelColor = QVector4D(0.0f, 0.0f, i / 255.0f,
+ alphaForValueSelection);
+ shader->setUniformValue(shader->color(), labelColor);
}
- labelNbr++;
+
+ // Back wall
+ m_dummyBarRenderItem.setTranslation(backLabelTrans);
+ m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
+ zeroVector, backLabelRotation, 0, m_cachedSelectionMode,
+ shader, m_labelObj, activeCamera,
+ true, true, Drawer::LabelMid, backAlignment);
+
+ // Side wall
+ m_dummyBarRenderItem.setTranslation(sideLabelTrans);
+ m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
+ zeroVector, sideLabelRotation, 0, m_cachedSelectionMode,
+ shader, m_labelObj, activeCamera,
+ true, true, Drawer::LabelMid, sideAlignment);
}
+ labelNbr++;
}
// Z labels
@@ -2169,11 +2174,17 @@ QPoint Bars3DRenderer::selectionColorToArrayPosition(const QVector4D &selectionC
// Use column from previous selection in case we have row + column mode
GLint previousCol = qMax(0, m_selectedBarPos.y()); // Use 0 if previous is invalid
position = QPoint(int(selectionColor.x() + int(m_axisCacheZ.min())), previousCol);
+ // TODO: Pass label clicked info to input handler (implement in part 2)
} else if (selectionColor.w() == labelColumnAlpha) {
// Column selection
// Use row from previous selection in case we have row + column mode
GLint previousRow = qMax(0, m_selectedBarPos.x()); // Use 0 if previous is invalid
position = QPoint(previousRow, int(selectionColor.y()) + int(m_axisCacheX.min()));
+ // TODO: Pass label clicked info to input handler (implement in part 2)
+ } else if (selectionColor.w() == labelValueAlpha) {
+ // Value selection
+ position = Bars3DController::invalidSelectionPosition();
+ // TODO: Pass label clicked info to input handler (implement in part 2)
}
return position;
}
diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp
index 9a2522d4..a6633183 100644
--- a/src/datavisualization/engine/scatter3drenderer.cpp
+++ b/src/datavisualization/engine/scatter3drenderer.cpp
@@ -547,6 +547,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
dotNo++;
}
}
+
+ drawLabels(true, activeCamera, viewMatrix, projectionMatrix);
+
glEnable(GL_DITHER);
// Read color under cursor
@@ -1234,12 +1237,97 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
}
}
- // Draw axis labels
- m_labelShader->bind();
+ drawLabels(false, activeCamera, viewMatrix, projectionMatrix);
+
+ // Handle selection clearing and selection label drawing
+ if (!dotSelectionFound) {
+ // We have no ownership, don't delete. Just NULL the pointer.
+ m_selectedItem = NULL;
+ } else {
+ glDisable(GL_DEPTH_TEST);
+ // Draw the selection label
+ LabelItem &labelItem = selectionLabelItem();
+ if (m_selectedItem != selectedItem || m_updateLabels
+ || !labelItem.textureId() || m_selectionLabelDirty) {
+ QString labelText = selectionLabel();
+ if (labelText.isNull() || m_selectionLabelDirty) {
+ static const QString xTitleTag(QStringLiteral("@xTitle"));
+ static const QString yTitleTag(QStringLiteral("@yTitle"));
+ static const QString zTitleTag(QStringLiteral("@zTitle"));
+ static const QString xLabelTag(QStringLiteral("@xLabel"));
+ static const QString yLabelTag(QStringLiteral("@yLabel"));
+ static const QString zLabelTag(QStringLiteral("@zLabel"));
+ static const QString seriesNameTag(QStringLiteral("@seriesName"));
+
+ labelText = m_visibleSeriesList[m_selectedItemSeriesIndex].itemLabelFormat();
+
+ labelText.replace(xTitleTag, m_axisCacheX.title());
+ labelText.replace(yTitleTag, m_axisCacheY.title());
+ labelText.replace(zTitleTag, m_axisCacheZ.title());
+
+ if (labelText.contains(xLabelTag)) {
+ QString valueLabelText = m_axisCacheX.formatter()->stringForValue(
+ qreal(selectedItem->position().x()), m_axisCacheX.labelFormat());
+ labelText.replace(xLabelTag, valueLabelText);
+ }
+ if (labelText.contains(yLabelTag)) {
+ QString valueLabelText = m_axisCacheY.formatter()->stringForValue(
+ qreal(selectedItem->position().y()), m_axisCacheY.labelFormat());
+ labelText.replace(yLabelTag, valueLabelText);
+ }
+ if (labelText.contains(zLabelTag)) {
+ QString valueLabelText = m_axisCacheZ.formatter()->stringForValue(
+ qreal(selectedItem->position().z()), m_axisCacheZ.labelFormat());
+ labelText.replace(zLabelTag, valueLabelText);
+ }
+ labelText.replace(seriesNameTag,
+ m_visibleSeriesList[m_selectedItemSeriesIndex].name());
+
+ setSelectionLabel(labelText);
+ m_selectionLabelDirty = false;
+ }
+ m_drawer->generateLabelItem(labelItem, labelText);
+ m_selectedItem = selectedItem;
+ }
+
+ m_drawer->drawLabel(*selectedItem, labelItem, viewMatrix, projectionMatrix,
+ zeroVector, zeroVector, selectedItemSize, m_cachedSelectionMode,
+ m_labelShader, m_labelObj, activeCamera, true, false,
+ Drawer::LabelOver);
+
+ // Reset label update flag; they should have been updated when we get here
+ m_updateLabels = false;
+ glEnable(GL_DEPTH_TEST);
+ }
+
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_BLEND);
+
+ // Release shader
+ glUseProgram(0);
+
+ m_selectionDirty = false;
+}
+
+void Scatter3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCamera,
+ const QMatrix4x4 &viewMatrix,
+ const QMatrix4x4 &projectionMatrix) {
+ ShaderHelper *shader = 0;
+ GLfloat alphaForValueSelection = labelValueAlpha / 255.0f;
+ GLfloat alphaForRowSelection = labelRowAlpha / 255.0f;
+ GLfloat alphaForColumnSelection = labelColumnAlpha / 255.0f;
+ if (drawSelection) {
+ shader = m_selectionShader;
+ // m_selectionShader is already bound
+ } else {
+ shader = m_labelShader;
+ shader->bind();
+
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_POLYGON_OFFSET_FILL);
// Z Labels
@@ -1282,6 +1370,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
m_dummyRenderItem.setTranslation(labelTrans);
const LabelItem &axisLabelItem = *m_axisCacheZ.labelItems().at(labelNbr);
+ if (drawSelection) {
+ QVector4D labelColor = QVector4D(label / 255.0f, 0.0f, 0.0f,
+ alphaForRowSelection);
+ shader->setUniformValue(shader->color(), labelColor);
+ }
+
m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
zeroVector, labelRotateVector, 0, m_cachedSelectionMode,
m_labelShader, m_labelObj, activeCamera, true, true,
@@ -1330,6 +1424,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
m_dummyRenderItem.setTranslation(labelTrans);
const LabelItem &axisLabelItem = *m_axisCacheX.labelItems().at(labelNbr);
+ if (drawSelection) {
+ QVector4D labelColor = QVector4D(0.0f, label / 255.0f, 0.0f,
+ alphaForColumnSelection);
+ shader->setUniformValue(shader->color(), labelColor);
+ }
+
m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
zeroVector, labelRotateVector, 0, m_cachedSelectionMode,
m_labelShader, m_labelObj, activeCamera, true, true,
@@ -1396,6 +1496,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
glPolygonOffset(GLfloat(label) / -10.0f, 1.0f);
+ if (drawSelection) {
+ QVector4D labelColor = QVector4D(0.0f, 0.0f, label / 255.0f,
+ alphaForValueSelection);
+ shader->setUniformValue(shader->color(), labelColor);
+ }
+
// Back wall
labelTransBack.setY(labelYTrans);
m_dummyRenderItem.setTranslation(labelTransBack);
@@ -1416,75 +1522,6 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
}
}
glDisable(GL_POLYGON_OFFSET_FILL);
-
- // Handle selection clearing and selection label drawing
- if (!dotSelectionFound) {
- // We have no ownership, don't delete. Just NULL the pointer.
- m_selectedItem = NULL;
- } else {
- glDisable(GL_DEPTH_TEST);
- // Draw the selection label
- LabelItem &labelItem = selectionLabelItem();
- if (m_selectedItem != selectedItem || m_updateLabels
- || !labelItem.textureId() || m_selectionLabelDirty) {
- QString labelText = selectionLabel();
- if (labelText.isNull() || m_selectionLabelDirty) {
- static const QString xTitleTag(QStringLiteral("@xTitle"));
- static const QString yTitleTag(QStringLiteral("@yTitle"));
- static const QString zTitleTag(QStringLiteral("@zTitle"));
- static const QString xLabelTag(QStringLiteral("@xLabel"));
- static const QString yLabelTag(QStringLiteral("@yLabel"));
- static const QString zLabelTag(QStringLiteral("@zLabel"));
- static const QString seriesNameTag(QStringLiteral("@seriesName"));
-
- labelText = m_visibleSeriesList[m_selectedItemSeriesIndex].itemLabelFormat();
-
- labelText.replace(xTitleTag, m_axisCacheX.title());
- labelText.replace(yTitleTag, m_axisCacheY.title());
- labelText.replace(zTitleTag, m_axisCacheZ.title());
-
- if (labelText.contains(xLabelTag)) {
- QString valueLabelText = m_axisCacheX.formatter()->stringForValue(
- qreal(selectedItem->position().x()), m_axisCacheX.labelFormat());
- labelText.replace(xLabelTag, valueLabelText);
- }
- if (labelText.contains(yLabelTag)) {
- QString valueLabelText = m_axisCacheY.formatter()->stringForValue(
- qreal(selectedItem->position().y()), m_axisCacheY.labelFormat());
- labelText.replace(yLabelTag, valueLabelText);
- }
- if (labelText.contains(zLabelTag)) {
- QString valueLabelText = m_axisCacheZ.formatter()->stringForValue(
- qreal(selectedItem->position().z()), m_axisCacheZ.labelFormat());
- labelText.replace(zLabelTag, valueLabelText);
- }
- labelText.replace(seriesNameTag,
- m_visibleSeriesList[m_selectedItemSeriesIndex].name());
-
- setSelectionLabel(labelText);
- m_selectionLabelDirty = false;
- }
- m_drawer->generateLabelItem(labelItem, labelText);
- m_selectedItem = selectedItem;
- }
-
- m_drawer->drawLabel(*selectedItem, labelItem, viewMatrix, projectionMatrix,
- zeroVector, zeroVector, selectedItemSize, m_cachedSelectionMode,
- m_labelShader, m_labelObj, activeCamera, true, false,
- Drawer::LabelOver);
-
- // Reset label update flag; they should have been updated when we get here
- m_updateLabels = false;
- glEnable(GL_DEPTH_TEST);
- }
-
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_BLEND);
-
- // Release shader
- glUseProgram(0);
-
- m_selectionDirty = false;
}
void Scatter3DRenderer::updateSelectedItem(int index, const QScatter3DSeries *series)
@@ -1735,16 +1772,30 @@ void Scatter3DRenderer::selectionColorToSeriesAndIndex(const QVector4D &color,
QAbstract3DSeries *&series)
{
if (color != selectionSkipColor) {
- index = int(color.x())
- + (int(color.y()) << 8)
- + (int(color.z()) << 16);
- // Find the series and adjust the index accordingly
- for (int i = 0; i < m_renderingArrays.size(); i++) {
- if (index < m_renderingArrays.at(i).size()) {
- series = m_visibleSeriesList.at(i).series();
- return; // Valid found and already set to return parameters, so we can return
- } else {
- index -= m_renderingArrays.at(i).size();
+ if (color.w() == labelRowAlpha) {
+ // Row selection
+ index = Scatter3DController::invalidSelectionIndex();
+ // TODO: Pass label clicked info to input handler (implement in part 2)
+ } else if (color.w() == labelColumnAlpha) {
+ // Column selection
+ index = Scatter3DController::invalidSelectionIndex();
+ // TODO: Pass label clicked info to input handler (implement in part 2)
+ } else if (color.w() == labelValueAlpha) {
+ // Value selection
+ index = Scatter3DController::invalidSelectionIndex();
+ // TODO: Pass label clicked info to input handler (implement in part 2)
+ } else {
+ index = int(color.x())
+ + (int(color.y()) << 8)
+ + (int(color.z()) << 16);
+ // Find the series and adjust the index accordingly
+ for (int i = 0; i < m_renderingArrays.size(); i++) {
+ if (index < m_renderingArrays.at(i).size()) {
+ series = m_visibleSeriesList.at(i).series();
+ return; // Valid found and already set to return parameters, so we can return
+ } else {
+ index -= m_renderingArrays.at(i).size();
+ }
}
}
}
diff --git a/src/datavisualization/engine/scatter3drenderer_p.h b/src/datavisualization/engine/scatter3drenderer_p.h
index 62a8de73..8b4d0759 100644
--- a/src/datavisualization/engine/scatter3drenderer_p.h
+++ b/src/datavisualization/engine/scatter3drenderer_p.h
@@ -121,6 +121,8 @@ private:
virtual void fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh mesh);
void drawScene(GLuint defaultFboHandle);
+ void drawLabels(bool drawSelection, const Q3DCamera *activeCamera,
+ const QMatrix4x4 &viewMatrix, const QMatrix4x4 &projectionMatrix);
void loadBackgroundMesh();
void loadLabelMesh();
diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp
index 0f9a3f10..fc31cd40 100644
--- a/src/datavisualization/engine/surface3drenderer.cpp
+++ b/src/datavisualization/engine/surface3drenderer.cpp
@@ -42,11 +42,12 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
const GLfloat aspectRatio = 2.0f; // Forced ratio of x and z to y. Dynamic will make it look odd.
const GLfloat backgroundMargin = 1.1f; // Margin for background (1.10 make it 10% larger to avoid
- // selection ball being drawn inside background)
+ // selection ball being drawn inside background)
const GLfloat labelMargin = 0.05f;
const GLfloat gridLineWidth = 0.005f;
const GLfloat sliceZScale = 0.1f;
const GLfloat sliceUnits = 2.5f;
+const uint alphaMultiplier = 16777216;
Surface3DRenderer::Surface3DRenderer(Surface3DController *controller)
: Abstract3DRenderer(controller),
@@ -1201,6 +1202,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
cache->selectionTexture());
}
}
+ drawLabels(true, activeCamera, viewMatrix, projectionMatrix);
glEnable(GL_DITHER);
@@ -1212,7 +1214,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
// Put the RGBA value back to uint
#if !defined(QT_OPENGL_ES_2)
- uint selectionId = pixel[0] + pixel[1] * 256 + pixel[2] * 65536 + pixel[3] * 16777216;
+ uint selectionId = pixel[0] + pixel[1] * 256 + pixel[2] * 65536 + pixel[3] * alphaMultiplier;
#else
uint selectionId = pixel[0] + pixel[1] * 256 + pixel[2] * 65536;
#endif
@@ -1729,11 +1731,61 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
}
}
- // Draw axis labels
- m_labelShader->bind();
+ drawLabels(false, activeCamera, viewMatrix, projectionMatrix);
+
+ // Release shader
+ glUseProgram(0);
+
+ // Selection handling
+ if (m_selectionDirty || m_selectionLabelDirty) {
+ QPoint visiblePoint = Surface3DController::invalidSelectionPosition();
+ if (m_selectedSeries) {
+ SurfaceSeriesRenderCache *cache =
+ m_renderCacheList.value(const_cast<QSurface3DSeries *>(m_selectedSeries));
+ if (cache && m_selectedPoint != Surface3DController::invalidSelectionPosition()) {
+ const QRect &sampleSpace = cache->sampleSpace();
+ int x = m_selectedPoint.x() - sampleSpace.y();
+ int y = m_selectedPoint.y() - sampleSpace.x();
+ if (x >= 0 && y >= 0 && x < sampleSpace.height() && y < sampleSpace.width()
+ && cache->dataArray().size()) {
+ visiblePoint = QPoint(x, y);
+ }
+ }
+ }
+
+ if (m_cachedSelectionMode == QAbstract3DGraph::SelectionNone
+ || visiblePoint == Surface3DController::invalidSelectionPosition()) {
+ m_selectionActive = false;
+ } else {
+ if (m_cachedIsSlicingActivated)
+ updateSliceDataModel(visiblePoint);
+ if (m_cachedSelectionMode.testFlag(QAbstract3DGraph::SelectionItem))
+ surfacePointSelected(visiblePoint);
+ m_selectionActive = true;
+ }
+
+ m_selectionDirty = false;
+ }
+}
+
+void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCamera,
+ const QMatrix4x4 &viewMatrix,
+ const QMatrix4x4 &projectionMatrix) {
+ ShaderHelper *shader = 0;
+ GLfloat alphaForValueSelection = labelValueAlpha / 255.0f;
+ GLfloat alphaForRowSelection = labelRowAlpha / 255.0f;
+ GLfloat alphaForColumnSelection = labelColumnAlpha / 255.0f;
+ if (drawSelection) {
+ shader = m_surfaceGridShader;
+ } else {
+ shader = m_labelShader;
+
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ shader->bind();
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_POLYGON_OFFSET_FILL);
// Z Labels
@@ -1771,9 +1823,15 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
m_dummyRenderItem.setTranslation(labelTrans);
const LabelItem &axisLabelItem = *m_axisCacheZ.labelItems().at(labelNbr);
+ if (drawSelection) {
+ QVector4D labelColor = QVector4D(label / 255.0f, 0.0f, 0.0f,
+ alphaForRowSelection);
+ shader->setUniformValue(shader->color(), labelColor);
+ }
+
m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
positionZComp, rotation, 0, m_cachedSelectionMode,
- m_labelShader, m_labelObj, activeCamera,
+ shader, m_labelObj, activeCamera,
true, true, Drawer::LabelMid, alignment);
}
labelNbr++;
@@ -1814,9 +1872,15 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
m_dummyRenderItem.setTranslation(labelTrans);
const LabelItem &axisLabelItem = *m_axisCacheX.labelItems().at(labelNbr);
+ if (drawSelection) {
+ QVector4D labelColor = QVector4D(0.0f, label / 255.0f, 0.0f,
+ alphaForColumnSelection);
+ shader->setUniformValue(shader->color(), labelColor);
+ }
+
m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
positionZComp, rotation, 0, m_cachedSelectionMode,
- m_labelShader, m_labelObj, activeCamera,
+ shader, m_labelObj, activeCamera,
true, true, Drawer::LabelMid, alignment);
}
labelNbr++;
@@ -1871,12 +1935,18 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
glPolygonOffset(GLfloat(label) / -10.0f, 1.0f);
+ if (drawSelection) {
+ QVector4D labelColor = QVector4D(0.0f, 0.0f, label / 255.0f,
+ alphaForValueSelection);
+ shader->setUniformValue(shader->color(), labelColor);
+ }
+
// Back wall
labelTransBack.setY(labelYTrans);
m_dummyRenderItem.setTranslation(labelTransBack);
m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
positionZComp, labelRotateVectorBack, 0, m_cachedSelectionMode,
- m_labelShader, m_labelObj, activeCamera,
+ shader, m_labelObj, activeCamera,
true, true, Drawer::LabelMid, alignmentBack);
// Side wall
@@ -1884,7 +1954,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
m_dummyRenderItem.setTranslation(labelTransSide);
m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
positionZComp, labelRotateVectorSide, 0, m_cachedSelectionMode,
- m_labelShader, m_labelObj, activeCamera,
+ shader, m_labelObj, activeCamera,
true, true, Drawer::LabelMid, alignmentSide);
}
labelNbr++;
@@ -1892,41 +1962,9 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
}
glDisable(GL_POLYGON_OFFSET_FILL);
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_BLEND);
-
- // Release shader
- glUseProgram(0);
-
- // Selection handling
- if (m_selectionDirty || m_selectionLabelDirty) {
- QPoint visiblePoint = Surface3DController::invalidSelectionPosition();
- if (m_selectedSeries) {
- SurfaceSeriesRenderCache *cache =
- m_renderCacheList.value(const_cast<QSurface3DSeries *>(m_selectedSeries));
- if (cache && m_selectedPoint != Surface3DController::invalidSelectionPosition()) {
- const QRect &sampleSpace = cache->sampleSpace();
- int x = m_selectedPoint.x() - sampleSpace.y();
- int y = m_selectedPoint.y() - sampleSpace.x();
- if (x >= 0 && y >= 0 && x < sampleSpace.height() && y < sampleSpace.width()
- && cache->dataArray().size()) {
- visiblePoint = QPoint(x, y);
- }
- }
- }
-
- if (m_cachedSelectionMode == QAbstract3DGraph::SelectionNone
- || visiblePoint == Surface3DController::invalidSelectionPosition()) {
- m_selectionActive = false;
- } else {
- if (m_cachedIsSlicingActivated)
- updateSliceDataModel(visiblePoint);
- if (m_cachedSelectionMode.testFlag(QAbstract3DGraph::SelectionItem))
- surfacePointSelected(visiblePoint);
- m_selectionActive = true;
- }
-
- m_selectionDirty = false;
+ if (!drawSelection) {
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_BLEND);
}
}
@@ -2202,6 +2240,27 @@ void Surface3DRenderer::updateSelectionPoint(SurfaceSeriesRenderCache *cache, co
// Maps selection Id to surface point in data array
QPoint Surface3DRenderer::selectionIdToSurfacePoint(uint id)
{
+#if 0 // TODO: Implement fully in part 2
+ // Check for label selection
+ if (id / alphaMultiplier == labelRowAlpha) {
+ int row = id - (labelRowAlpha * alphaMultiplier);
+ qDebug() << "row label" << row;
+ // TODO: Pass label clicked info to input handler
+ return Surface3DController::invalidSelectionPosition();
+ } else if (id / alphaMultiplier == labelColumnAlpha) {
+ int column = (id - (labelColumnAlpha * alphaMultiplier)) / 256;
+ qDebug() << "column label" << column;
+ // TODO: Pass label clicked info to input handler
+ return Surface3DController::invalidSelectionPosition();
+ } else if (id / alphaMultiplier == labelValueAlpha) {
+ int value = (id - (labelValueAlpha * alphaMultiplier)) / 65536;
+ qDebug() << "value label" << value;
+ // TODO: Pass label clicked info to input handler
+ return Surface3DController::invalidSelectionPosition();
+ }
+#endif
+
+ // Not a label selection
SurfaceSeriesRenderCache *selectedCache = 0;
foreach (SurfaceSeriesRenderCache *cache, m_renderCacheList) {
if (cache->isWithinIdRange(id)) {
@@ -2373,7 +2432,7 @@ void Surface3DRenderer::initShaders(const QString &vertexShader, const QString &
m_surfaceSliceSmoothShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertex"),
QStringLiteral(":/shaders/fragmentSurface"));
m_surfaceSliceFlatShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexSurfaceFlat"),
- QStringLiteral(":/shaders/fragmentSurfaceFlat"));
+ QStringLiteral(":/shaders/fragmentSurfaceFlat"));
#else
m_surfaceSmoothShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertex"),
QStringLiteral(":/shaders/fragmentSurfaceES2"));
diff --git a/src/datavisualization/engine/surface3drenderer_p.h b/src/datavisualization/engine/surface3drenderer_p.h
index 9fd5d0d9..7a3b279f 100644
--- a/src/datavisualization/engine/surface3drenderer_p.h
+++ b/src/datavisualization/engine/surface3drenderer_p.h
@@ -144,6 +144,8 @@ private:
void loadBackgroundMesh();
void loadLabelMesh();
void drawScene(GLuint defaultFboHandle);
+ void drawLabels(bool drawSelection, const Q3DCamera *activeCamera,
+ const QMatrix4x4 &viewMatrix, const QMatrix4x4 &projectionMatrix);
void calculateSceneScalingFactors();
void initBackgroundShaders(const QString &vertexShader, const QString &fragmentShader);
void initLabelShaders(const QString &vertexShader, const QString &fragmentShader);
diff --git a/src/datavisualization/global/datavisualizationglobal_p.h b/src/datavisualization/global/datavisualizationglobal_p.h
index ff658be3..f0a4f469 100644
--- a/src/datavisualization/global/datavisualizationglobal_p.h
+++ b/src/datavisualization/global/datavisualizationglobal_p.h
@@ -60,6 +60,7 @@ static const QQuaternion identityQuaternion;
static const QVector4D selectionSkipColor = QVector4D(255.0f, 255.0f, 255.0f, 255.0f);
static const QVector4D invalidColorVector = QVector4D(-1.0f, -1.0f, -1.0f, -1.0f);
static const GLfloat itemAlpha = 0.0f;
+static const GLfloat labelValueAlpha = 253.0f;
static const GLfloat labelRowAlpha = 254.0f;
static const GLfloat labelColumnAlpha = 255.0f;
static const GLfloat gradientTextureHeight = 1024.0f;