diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-05-08 16:03:10 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-05-08 16:04:09 -0400 |
commit | 74335267c235bb4eb8e015d271983dbc9f3ada24 (patch) | |
tree | ca4ae9cfec7e2145b2710f5bf24b8a4188702d28 /chart2 | |
parent | 9613d0d64c957e7716344926f8d238a5152453ad (diff) |
My best attempt at positioning text objects.
Change-Id: I390b6d09558b7f2dea46cfd4e5db5ed6f2162b5f
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/view/charttypes/GL3DBarChart.cxx | 54 | ||||
-rw-r--r-- | chart2/source/view/inc/3DChartObjects.hxx | 5 | ||||
-rw-r--r-- | chart2/source/view/main/3DChartObjects.cxx | 28 |
3 files changed, 79 insertions, 8 deletions
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index be82ca58027e..4bf460e233a1 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -41,6 +41,14 @@ GL3DBarChart::~GL3DBarChart() void GL3DBarChart::create3DShapes() { + // Each series of data flows from left to right, and multiple series are + // stacked vertically along y axis. + + // NOTE: These objects are created and positioned in a totally blind + // fashion since we don't even have a way to see them on screen. So, no + // guarantee they are positioned correctly. In fact, they are guaranteed + // to be positioned incorrectly. + const float nBarSizeX = 10; const float nBarSizeY = 10; const float nBarDistanceX = nBarSizeX / 2; @@ -48,10 +56,9 @@ void GL3DBarChart::create3DShapes() sal_uInt32 nId = 1; - uno::Sequence<OUString> aCats = mrCatProvider.getSimpleCategories(); - for (sal_Int32 i = 0; i < aCats.getLength(); ++i) - // Category name text object. - maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aCats[i], nId++)); + std::vector<opengl3D::Text*> aYAxisTexts; + + float nYPos = 0.0; maShapes.clear(); maShapes.push_back(new opengl3D::Camera(mpRenderer.get())); @@ -59,6 +66,8 @@ void GL3DBarChart::create3DShapes() for (boost::ptr_vector<VDataSeries>::const_iterator itr = maDataSeries.begin(), itrEnd = maDataSeries.end(); itr != itrEnd; ++itr) { + nYPos = nSeriesIndex * (nBarSizeY + nBarDistanceY); + const VDataSeries& rDataSeries = *itr; sal_Int32 nPointCount = rDataSeries.getTotalPointCount(); @@ -67,13 +76,21 @@ void GL3DBarChart::create3DShapes() DataSeriesHelper::getDataSeriesLabel( rDataSeries.getModel(), mxChartType->getRoleOfSequenceForSeriesLabel()); - maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aSeriesName, nId++)); + aYAxisTexts.push_back(new opengl3D::Text(mpRenderer.get(), aSeriesName, nId++)); + opengl3D::Text* p = aYAxisTexts.back(); + Size aTextSize = p->getSize(); + glm::vec3 aTopLeft, aTopRight, aBottomRight; + aTopLeft.x = aTextSize.getWidth() * -1.0; + aTopLeft.y = nYPos; + aTopRight.y = nYPos; + aBottomRight = aTopRight; + aBottomRight.y += aTextSize.getHeight(); + p->setPosition(aTopLeft, aTopRight, aBottomRight); for(sal_Int32 nIndex = 0; nIndex < nPointCount; ++nIndex) { float nVal = rDataSeries.getYValue(nIndex); float nXPos = nIndex * (nBarSizeX + nBarDistanceX); - float nYPos = nSeriesIndex * (nBarSizeY + nBarDistanceY); sal_Int32 nColor = COL_BLUE; @@ -86,6 +103,31 @@ void GL3DBarChart::create3DShapes() ++nSeriesIndex; } + + nYPos += nBarSizeY + nBarDistanceY; + + // Create category texts along X-axis at the bottom. + uno::Sequence<OUString> aCats = mrCatProvider.getSimpleCategories(); + for (sal_Int32 i = 0; i < aCats.getLength(); ++i) + { + float nXPos = i * (nBarSizeX + nBarDistanceX); + + maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aCats[i], nId++)); + opengl3D::Text* p = static_cast<opengl3D::Text*>(&maShapes.back()); + Size aTextSize = p->getSize(); + glm::vec3 aTopLeft; + aTopLeft.x = nXPos; + aTopLeft.y = nYPos; + glm::vec3 aTopRight = aTopLeft; + aTopRight.x += aTextSize.getWidth(); + glm::vec3 aBottomRight = aTopRight; + aBottomRight.y += aTextSize.getHeight(); + p->setPosition(aTopLeft, aTopRight, aBottomRight); + } + + // Transfer all Y-axis text objects to the shape collection. + std::copy(aYAxisTexts.begin(), aYAxisTexts.end(), std::back_inserter(maShapes)); + aYAxisTexts.clear(); } void GL3DBarChart::render() diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index ca56580b4eec..e93d656c1f2b 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -64,6 +64,11 @@ class Text : public Renderable3DObject public: Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId); virtual void render() SAL_OVERRIDE; + + Size getSize() const; + + void setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight); + private: BitmapEx maText; glm::vec3 maTopLeft; diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index daa5eca2331e..820e79d01b4b 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -8,6 +8,8 @@ */ #include "3DChartObjects.hxx" +#include <vcl/virdev.hxx> +#include <vcl/svapp.hxx> namespace chart { @@ -51,10 +53,20 @@ void Line::render() mpRenderer->EndAddShapePolygon3DObject(); } -Text::Text(OpenGL3DRenderer* pRenderer, const OUString& /*rStr*/, sal_uInt32 nId): +Text::Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId): Renderable3DObject(pRenderer, nId) { - // TODO : convert OUString to BitmapEx. + // Convert OUString to BitmapEx. + VirtualDevice aDevice(*Application::GetDefaultDevice(), 0, 0); + Font aFont = aDevice.GetFont(); + aFont.SetColor(COL_WHITE); + aDevice.SetFont(aFont); + aDevice.Erase(); + aDevice.SetOutputSizePixel(Size(20,12)); + aDevice.SetBackground(Wallpaper(COL_TRANSPARENT)); + aDevice.DrawText(Point(0,0), rStr); + + maText = BitmapEx(aDevice.GetBitmapEx(Point(0,0), Size(20,12))); } void Text::render() @@ -64,6 +76,18 @@ void Text::render() mpRenderer->CreateTextTexture(maText, maTopLeft, maTopRight, maBottomRight, bottomLeft); } +Size Text::getSize() const +{ + return maText.GetSizePixel(); +} + +void Text::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight) +{ + maTopLeft = rTopLeft; + maTopRight = rTopRight; + maBottomRight = rBottomRight; +} + Rectangle::Rectangle(OpenGL3DRenderer* pRenderer, sal_uInt32 nId): Renderable3DObject(pRenderer, nId) { |