diff options
author | weigao <weigao@multicorewareinc.com> | 2014-08-08 18:35:25 +0800 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-08-13 06:21:33 +0200 |
commit | 05ecb52d2bc95dcaceb47df8f09b5bfbe924f9b7 (patch) | |
tree | ae6c3655dbe3ca8283a9593a86609972a9e088cd /chart2 | |
parent | 692878e3bb83c0fc104c5cca946c25ccf2d84ab2 (diff) |
add position control to screen text
Change-Id: I6bf340acb3aa50f2ce534b10d5be32c4615b0688
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/view/charttypes/GL3DBarChart.cxx | 12 | ||||
-rw-r--r-- | chart2/source/view/inc/3DChartObjects.hxx | 3 | ||||
-rw-r--r-- | chart2/source/view/inc/GL3DRenderer.hxx | 4 | ||||
-rw-r--r-- | chart2/source/view/main/3DChartObjects.cxx | 5 | ||||
-rw-r--r-- | chart2/source/view/main/GL3DRenderer.cxx | 43 |
5 files changed, 49 insertions, 18 deletions
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index 3a3989635222..b325ac86bfe1 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -25,6 +25,8 @@ #endif #define BENCH_MARK_MODE false +#define CLICK_EVENT_ID 1 +#define SHAPE_START_ID 10 using namespace com::sun::star; @@ -489,7 +491,7 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer // Each series of data flows from left to right, and multiple series are // stacked vertically along y axis. - sal_uInt32 nId = 1; + sal_uInt32 nId = SHAPE_START_ID; float nXEnd = 0.0; float nYPos = 0.0; @@ -805,11 +807,13 @@ void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons) return; const BarInformation& rBarInfo = itr->second; - + glm::vec3 textPos = glm::vec3(rBarInfo.maPos.x + BAR_SIZE_X / 2.0f, + rBarInfo.maPos.y + BAR_SIZE_Y / 2.0f, + rBarInfo.maPos.z); maShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, - OUString("Value: ") + OUString::number(rBarInfo.mnVal), 0)); + OUString("Value: ") + OUString::number(rBarInfo.mnVal), CLICK_EVENT_ID)); opengl3D::ScreenText* pScreenText = static_cast<opengl3D::ScreenText*>(&maShapes.back()); - pScreenText->setPosition(glm::vec2(-0.9f, 0.9f), glm::vec2(-0.6f, 0.8f)); + pScreenText->setPosition(glm::vec2(-0.9f, 0.9f), glm::vec2(-0.6f, 0.8f), textPos); pScreenText->render(); glm::vec3 maTargetPosition = rBarInfo.maPos; diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index 54b04fdcbb0f..9c8bb503c1ca 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -111,12 +111,13 @@ public: ScreenText(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId); virtual void render() SAL_OVERRIDE; - void setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight); + void setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight, glm::vec3 r3DPos = glm::vec3(0.0, 0.0, 0.0)); private: TextCacheItem maText; glm::vec2 maTopLeft; glm::vec2 maBottomRight; + glm::vec3 ma3DPos; }; class Rectangle : public Renderable3DObject diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index f4b4b6762167..94a5f88ca4ee 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -138,8 +138,10 @@ struct PackedVertex{ struct TextInfo { glm::vec4 id; + sal_uInt32 uniqueId; GLuint texture; float vertex[12]; + glm::vec3 pos; }; struct TextureArrayInfo @@ -197,7 +199,7 @@ public: sal_uInt32 nUniqueId); void CreateScreenTextTexture(const boost::shared_array<sal_uInt8> &bitmapBuf, ::Size maSizePixels, const glm::vec2& vTopLeft, - const glm::vec2& vBottomRight, sal_uInt32 nUniqueId); + const glm::vec2& vBottomRight, glm::vec3 vPos, sal_uInt32 nUniqueId); void ProcessUnrenderedShape(bool bNewScene); void SetPickingMode(bool bPickingMode); diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index 9786c00c1e61..a045b48d0a12 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -134,16 +134,17 @@ ScreenText::ScreenText(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const { } -void ScreenText::setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight) +void ScreenText::setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight, glm::vec3 r3DPos) { maTopLeft = rTopLeft; maBottomRight = rBottomRight; + ma3DPos = r3DPos; } void ScreenText::render() { mpRenderer->CreateScreenTextTexture(maText.maPixels, maText.maSize, - maTopLeft, maBottomRight, + maTopLeft, maBottomRight, ma3DPos, mnUniqueId); } diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index 48d7da7bc49e..295a8a70bdb5 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -1666,13 +1666,14 @@ void OpenGL3DRenderer::RenderExtrude3DObject() void OpenGL3DRenderer::CreateScreenTextTexture( const boost::shared_array<sal_uInt8> &bitmapBuf, ::Size maSizePixels, const glm::vec2& vTopLeft, - const glm::vec2& vBottomRight, sal_uInt32 nUniqueId) + const glm::vec2& vBottomRight, glm::vec3 vPos, sal_uInt32 nUniqueId) { long bmpWidth = maSizePixels.Width(); long bmpHeight = maSizePixels.Height(); TextInfo aTextInfo; aTextInfo.id = getColorAsVector(nUniqueId); + aTextInfo.uniqueId = nUniqueId; aTextInfo.vertex[0] = vBottomRight.x; aTextInfo.vertex[1] = vBottomRight.y; aTextInfo.vertex[2] = 0; @@ -1688,6 +1689,7 @@ void OpenGL3DRenderer::CreateScreenTextTexture( aTextInfo.vertex[9] = vTopLeft.x; aTextInfo.vertex[10] = vBottomRight.y; aTextInfo.vertex[11] = 0; + aTextInfo.pos = vPos; CHECK_GL_ERROR(); glGenTextures(1, &aTextInfo.texture); @@ -1868,17 +1870,38 @@ void OpenGL3DRenderer::ReleaseScreenTextShapes() void OpenGL3DRenderer::RenderScreenTextShape() { + glUseProgram(maResources.m_ScreenTextProID); CHECK_GL_ERROR(); for (size_t i = 0; i < m_ScreenTextInfoList.size(); i++) { TextInfo &textInfo = m_ScreenTextInfoList[i]; + //calc the postition and check whether it can be displayed + float xTrans = 0.0f; + float yTrans = 0.0f; + if (textInfo.uniqueId) + { + glm::vec3 worldPos = glm::vec3(m_ScrollMoveMatrix * m_GlobalScaleMatrix * glm::vec4(textInfo.pos, 1)); + if (worldPos.x < m_fMinCoordX) + continue; + glm::vec4 pos = m_3DProjection * m_3DView * glm::vec4(worldPos, 1); + xTrans = pos.x / pos.w; + yTrans = pos.y / pos.w; + for (int j = 0; j < 12; j++) + { + if (j % 3 == 0) + { + textInfo.vertex[j] += xTrans; + } + if (j % 3 == 1) + { + textInfo.vertex[j] += yTrans; + } + } + } glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer); CHECK_GL_ERROR(); glBufferData(GL_ARRAY_BUFFER, sizeof(textInfo.vertex), textInfo.vertex, GL_STATIC_DRAW); CHECK_GL_ERROR(); - glUseProgram(maResources.m_ScreenTextProID); - - CHECK_GL_ERROR(); // 1rst attribute buffer : vertices glEnableVertexAttribArray(maResources.m_ScreenTextVertexID); @@ -1912,13 +1935,13 @@ void OpenGL3DRenderer::RenderScreenTextShape() //TODO: moggi: get rid fo GL_QUADS glDrawArrays(GL_QUADS, 0, 4); CHECK_GL_ERROR(); - glDisableVertexAttribArray(maResources.m_ScreenTextTexCoordID); - CHECK_GL_ERROR(); - glDisableVertexAttribArray(maResources.m_ScreenTextVertexID); - CHECK_GL_ERROR(); - glBindTexture(GL_TEXTURE_2D, 0); - glUseProgram(0); } + glDisableVertexAttribArray(maResources.m_ScreenTextTexCoordID); + CHECK_GL_ERROR(); + glDisableVertexAttribArray(maResources.m_ScreenTextVertexID); + CHECK_GL_ERROR(); + glBindTexture(GL_TEXTURE_2D, 0); + glUseProgram(0); CHECK_GL_ERROR(); } void OpenGL3DRenderer::ReleaseTextShapesBatch() |