[Libreoffice-commits] core.git: 2 commits - chart2/source

Kohei Yoshida kohei.yoshida at collabora.com
Thu May 8 13:04:15 PDT 2014


 chart2/source/view/charttypes/GL3DBarChart.cxx |   54 ++++++++++++++++++++++---
 chart2/source/view/inc/3DChartObjects.hxx      |    5 ++
 chart2/source/view/inc/GL3DBarChart.hxx        |    6 --
 chart2/source/view/main/3DChartObjects.cxx     |   28 ++++++++++++
 4 files changed, 80 insertions(+), 13 deletions(-)

New commits:
commit 74335267c235bb4eb8e015d271983dbc9f3ada24
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Thu May 8 16:03:10 2014 -0400

    My best attempt at positioning text objects.
    
    Change-Id: I390b6d09558b7f2dea46cfd4e5db5ed6f2162b5f

diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index be82ca5..4bf460e 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 ca56580..e93d656 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 daa5eca..820e79d 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)
 {
commit 9613d0d64c957e7716344926f8d238a5152453ad
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Thu May 8 13:25:27 2014 -0400

    TemporaryContext is no more.
    
    Change-Id: I9cf0f5db276c5837921c132d98032cf2331362fd

diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index 8237805..86115de 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -25,11 +25,7 @@ namespace opengl3D {
 class Renderable3DObject;
 class OpenGL3DRenderer;
 
-namespace temporary {
-
-class TemporaryContext;
-
-} }
+}
 
 class GL3DBarChart
 {


More information about the Libreoffice-commits mailing list