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

Markus Mohrhard markus.mohrhard at googlemail.com
Thu Feb 6 07:15:34 PST 2014


 chart2/source/controller/main/ChartController_Window.cxx |   12 ++
 chart2/source/view/main/DummyXShape.cxx                  |   82 ++++++++-------
 chart2/source/view/main/OpenGLRender.cxx                 |   62 ++++++++---
 chart2/source/view/main/OpenGLRender.hxx                 |   10 -
 4 files changed, 109 insertions(+), 57 deletions(-)

New commits:
commit 61e28e86ed30fb37df96c7fd0807b5aaeacf5eea
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Feb 5 14:15:33 2014 +0100

    add a way to dump chart content to console
    
    CTRL + F12 will dump the chart with the XShapeDumper
    
    Change-Id: I1f40ddf7f51c2038be7af8fc56f626393f11da90

diff --git a/chart2/source/controller/main/ChartController_Window.cxx b/chart2/source/controller/main/ChartController_Window.cxx
index 896273b..439c13c 100644
--- a/chart2/source/controller/main/ChartController_Window.cxx
+++ b/chart2/source/controller/main/ChartController_Window.cxx
@@ -1302,6 +1302,7 @@ bool ChartController::execute_KeyInput( const KeyEvent& rKEvt )
     KeyCode aKeyCode( rKEvt.GetKeyCode());
     sal_uInt16 nCode = aKeyCode.GetCode();
     bool bAlternate = aKeyCode.IsMod2();
+    bool bCtrl = aKeyCode.IsMod1();
 
     if( m_apAccelExecute.get() )
         bReturn = m_apAccelExecute->execute( aKeyCode );
@@ -1501,6 +1502,17 @@ bool ChartController::execute_KeyInput( const KeyEvent& rKEvt )
         }
     }
 
+    // dumping the shape
+    if( !bReturn && bCtrl && nCode == KEY_F12)
+    {
+        uno::Reference< qa::XDumper > xChartModel( getModel(), uno::UNO_QUERY );
+        if(xChartModel.is())
+        {
+            OUString aDump = xChartModel->dump();
+            SAL_WARN("chart2", aDump);
+        }
+    }
+
     // text edit
     if( ! bReturn &&
         nCode == KEY_F2 )
commit a12ce634d83625886ee6930d6db2999c6864262d
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Feb 5 11:54:50 2014 +0100

    improve color handling and alpha channel handling
    
    Change-Id: Ic58c763318eab538ff84e408029aaabda635443e

diff --git a/chart2/source/view/main/DummyXShape.cxx b/chart2/source/view/main/DummyXShape.cxx
index 4cb2c7a..da83f73 100644
--- a/chart2/source/view/main/DummyXShape.cxx
+++ b/chart2/source/view/main/DummyXShape.cxx
@@ -361,17 +361,18 @@ void DummyPieSegment2D::render()
     pChart->m_GLRender.GeneratePieSegment2D(mfUnitCircleInnerRadius, mfUnitCircleOuterRadius,
             mfUnitCircleStartAngleDegree, mfUnitCircleWidthAngleDegree);
 
-    std::map<OUString, uno::Any>::const_iterator itr = maProperties.find(UNO_NAME_FILLCOLOR);
+    sal_uInt8 nAlpha = 255;
+    std::map<OUString, uno::Any>::const_iterator itr = maProperties.find(UNO_NAME_FILL_TRANSPARENCE);
     if(itr != maProperties.end())
     {
-        sal_Int32 nColor = itr->second.get<sal_Int32>();
-        pChart->m_GLRender.SetColor(nColor);
+        nAlpha = 255 - itr->second.get<sal_Int32>();
     }
-    itr = maProperties.find(UNO_NAME_FILL_TRANSPARENCE);
+
+    itr = maProperties.find(UNO_NAME_FILLCOLOR);
     if(itr != maProperties.end())
     {
-        sal_Int32 transparency = itr->second.get<sal_Int32>();
-        pChart->m_GLRender.SetTransparency(255-(transparency&(0xFF)));
+        sal_Int32 nColor = itr->second.get<sal_Int32>();
+        pChart->m_GLRender.SetColor(nColor, nAlpha);
     }
 
     float nSize = std::max<float>(maUnitCircleToScene.Line1.Column1, maUnitCircleToScene.Line2.Column2);
@@ -424,7 +425,7 @@ void DummyArea2D::render()
     if(itr != maProperties.end())
     {
         sal_Int32 nColor = itr->second.get<sal_Int32>();
-        pChart->m_GLRender.SetColor(nColor);
+        pChart->m_GLRender.SetColor(nColor, 255);
     }
 
     pChart->m_GLRender.RenderArea2DShape();
@@ -445,7 +446,7 @@ void DummySymbol2D::render()
 {
     DummyChart* pChart = getRootShape();
 
-    pChart->m_GLRender.SetColor(mnFillColor);
+    pChart->m_GLRender.SetColor(mnFillColor, 255);
 
     pChart->m_GLRender.RenderSymbol2DShape(maPosition.X, maPosition.Y, maSize.Width, maSize.Height, mnStandardSymbol);
 }
@@ -465,10 +466,11 @@ void DummyCircle::render()
     if(itr != maProperties.end())
     {
         sal_Int32 nColor = itr->second.get<sal_Int32>();
-        pChart->m_GLRender.SetColor(nColor);
+        pChart->m_GLRender.SetColor(nColor, 255);
     }
     else
         SAL_WARN("chart2.opengl", "missing color");
+
     pChart->m_GLRender.Bubble2DShapePoint(maPosition.X, maPosition.Y,
                                           maSize.Width, maSize.Height);
     pChart->m_GLRender.RenderBubble2FBO(GL_TRUE);
@@ -530,19 +532,41 @@ void DummyLine2D::render()
     SAL_WARN("chart2.opengl", "rendering line 2D");
     debugProperties(maProperties);
     DummyChart* pChart = getRootShape();
-    std::map< OUString, uno::Any >::const_iterator itr = maProperties.find(UNO_NAME_LINECOLOR);
+
+    //add style and transparency
+    std::map< OUString, uno::Any >::const_iterator itr = maProperties.find(UNO_NAME_LINESTYLE);
+    if (itr != maProperties.end())
+    {
+        uno::Any cow = itr->second;
+        drawing::LineStyle nStyle = cow.get<drawing::LineStyle>();
+        if (drawing::LineStyle_NONE == nStyle)
+        {
+            // nothing to render
+            return;
+        }
+    }
+
+    sal_uInt8 nAlpha = 255;
+    itr = maProperties.find("LineTransparence");
+    if(itr != maProperties.end())
+    {
+        uno::Any al = itr->second;
+        nAlpha = 255 - al.get<sal_Int32>();
+    }
+
+    itr = maProperties.find(UNO_NAME_LINECOLOR);
     if(itr != maProperties.end())
     {
         //set line color
         uno::Any co =  itr->second;
         sal_Int32 nColorValue = co.get<sal_Int32>();
-        SAL_WARN("chart2.opengl", "*colorvalue = " << nColorValue);
+        SAL_INFO("chart2.opengl", "line colorvalue = " << nColorValue);
         sal_uInt8 R = (nColorValue & 0x00FF0000) >> 16;
         sal_uInt8 G = (nColorValue & 0x0000FF00) >> 8;
         sal_uInt8 B = (nColorValue & 0x000000FF);
-        pChart->m_GLRender.SetLine2DColor(R, G, B);
+        pChart->m_GLRender.SetLine2DColor(R, G, B, nAlpha);
 
-        SAL_WARN("chart2.opengl", "*colorvalue = " << nColorValue << ", R = " << (int)R << ", G = " << (int)G << ", B = " << (int)B);
+        SAL_INFO("chart2.opengl", "line colorvalue = " << nColorValue << ", R = " << (int)R << ", G = " << (int)G << ", B = " << (int)B);
     }
     else
         SAL_WARN("chart2.opengl", "no line color set");
@@ -560,22 +584,6 @@ void DummyLine2D::render()
     else
         SAL_WARN("chart2.opengl", "no line width set");
 
-    //add style and transparency
-    itr =  maProperties.find(UNO_NAME_LINESTYLE);
-    if (itr != maProperties.end())
-    {
-        uno::Any cow = itr->second;
-        drawing::LineStyle nStyle = cow.get<drawing::LineStyle>();
-        if (drawing::LineStyle_NONE == nStyle)
-        {
-            pChart->m_GLRender.SetTransparency(0);
-        }
-        else
-        {
-            pChart->m_GLRender.SetTransparency(255);
-        }
-    }
-
     sal_Int32 pointsscount = maPoints.getLength();
     for(sal_Int32 i = 0; i < pointsscount; i++)
     {
@@ -636,7 +644,15 @@ void DummyRectangle::render()
     {
         uno::Any co =  itr->second;
         sal_Int32 nColorValue = co.get<sal_Int32>();
-        pChart->m_GLRender.SetBackGroundColor(nColorValue, nColorValue);
+
+        itr = maProperties.find("FillTransparence");
+        sal_uInt8 nAlpha = 255;
+        if(itr != maProperties.end())
+        {
+            uno::Any al = itr->second;
+            nAlpha = al.get<sal_Int32>();
+        }
+        pChart->m_GLRender.SetBackGroundColor(nColorValue, nColorValue, nAlpha);
     }
 
     bool bBorder = true;
diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 9097c78..9de0571 100755
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -835,9 +835,9 @@ int OpenGLRender::CreateBMPHeader(sal_uInt8 *bmpHeader, int xsize, int ysize)
 }
 #endif
 
-void OpenGLRender::SetLine2DColor(sal_uInt8 r, sal_uInt8 g, sal_uInt8 b)
+void OpenGLRender::SetLine2DColor(sal_uInt8 r, sal_uInt8 g, sal_uInt8 b, sal_uInt8 nAlpha)
 {
-    m_2DColor = glm::vec4((float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, m_fAlpha);
+    m_2DColor = glm::vec4((float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, nAlpha/255.f);
 }
 
 void OpenGLRender::SetLine2DWidth(int width)
@@ -1046,12 +1046,12 @@ bool OpenGLRender::WGLisExtensionSupported(const char *extension)
 }
 #endif
 
-void OpenGLRender::SetColor(sal_uInt32 color)
+void OpenGLRender::SetColor(sal_uInt32 color, sal_uInt8 nAlpha)
 {
     sal_uInt8 r = (color & 0x00FF0000) >> 16;
     sal_uInt8 g = (color & 0x0000FF00) >> 8;
     sal_uInt8 b = (color & 0x000000FF);
-    m_2DColor = glm::vec4((float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, m_fAlpha);
+    m_2DColor = glm::vec4((float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, nAlpha/ 255.f);
 }
 
 int OpenGLRender::CreateMultiSampleFrameBufObj()
@@ -1169,12 +1169,6 @@ int OpenGLRender::RenderBubble2FBO(int)
     return 0;
 }
 
-void OpenGLRender::SetTransparency(sal_uInt32 transparency)
-{
-    m_fAlpha = (float)transparency / 255.0;
-    m_2DColor = glm::vec4(m_2DColor.r, m_2DColor.g, m_2DColor.b, m_fAlpha);
-}
-
 int OpenGLRender::RectangleShapePoint(float x, float y, float directionX, float directionY)
 {
     //check whether to create the circle data
@@ -1269,7 +1263,7 @@ int OpenGLRender::RenderRectangleShape(bool bBorder, bool bFill)
                 m_fZStep += Z_STEP;
                 glUniformMatrix4fv(m_BackgroundMatrixID, 1, GL_FALSE, &m_MVP[0][0]);
             }
-            SetBackGroundColor(COL_BLACK, COL_BLACK);
+            SetBackGroundColor(COL_BLACK, COL_BLACK, 255);
 
             glBindBuffer(GL_ARRAY_BUFFER, m_ColorBuffer);
             glBufferData(GL_ARRAY_BUFFER, sizeof(m_BackgroundColor), m_BackgroundColor, GL_STATIC_DRAW);
@@ -1571,7 +1565,7 @@ int OpenGLRender::RenderArea2DShape()
     return 0;
 }
 
-void OpenGLRender::SetBackGroundColor(sal_uInt32 color1, sal_uInt32 color2)
+void OpenGLRender::SetBackGroundColor(sal_uInt32 color1, sal_uInt32 color2, sal_uInt8 nAlpha)
 {
     sal_uInt8 r = (color1 & 0x00FF0000) >> 16;
     sal_uInt8 g = (color1 & 0x0000FF00) >> 8;
@@ -1580,12 +1574,12 @@ void OpenGLRender::SetBackGroundColor(sal_uInt32 color1, sal_uInt32 color2)
     m_BackgroundColor[0] = (float)r / 255.0f;
     m_BackgroundColor[1] = (float)g / 255.0f;
     m_BackgroundColor[2] = (float)b / 255.0f;
-    m_BackgroundColor[3] = m_fAlpha;
+    m_BackgroundColor[3] = nAlpha / 255.0f;
 
     m_BackgroundColor[4] = (float)r / 255.0f;
     m_BackgroundColor[5] = (float)g / 255.0f;
     m_BackgroundColor[6] = (float)b / 255.0f;
-    m_BackgroundColor[7] = m_fAlpha;
+    m_BackgroundColor[7] = nAlpha / 255.0f;
 
     r = (color2 & 0x00FF0000) >> 16;
     g = (color2 & 0x0000FF00) >> 8;
@@ -1594,12 +1588,12 @@ void OpenGLRender::SetBackGroundColor(sal_uInt32 color1, sal_uInt32 color2)
     m_BackgroundColor[8] = (float)r / 255.0f;
     m_BackgroundColor[9] = (float)g / 255.0f;
     m_BackgroundColor[10] = (float)b / 255.0f;
-    m_BackgroundColor[11] = 1.0;
+    m_BackgroundColor[11] = nAlpha / 255.0f;
 
     m_BackgroundColor[12] = (float)r / 255.0f;
     m_BackgroundColor[13] = (float)g / 255.0f;
     m_BackgroundColor[14] = (float)b / 255.0f;
-    m_BackgroundColor[15] = 1.0;
+    m_BackgroundColor[15] = nAlpha / 255.0f;
     SAL_INFO("chart2.opengl", "color1 = " << color1 << ", color2 = " << color2);
 
 }
diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx
index b5aeba3..8ba5c76 100755
--- a/chart2/source/view/main/OpenGLRender.hxx
+++ b/chart2/source/view/main/OpenGLRender.hxx
@@ -141,7 +141,7 @@ public:
 #endif
     int RenderLine2FBO(int wholeFlag);
     int SetLine2DShapePoint(float x, float y, int listLength);
-    void SetLine2DColor(sal_uInt8 r, sal_uInt8 g, sal_uInt8 b);
+    void SetLine2DColor(sal_uInt8 r, sal_uInt8 g, sal_uInt8 b, sal_uInt8 nAlpha);
     void SetLine2DWidth(int width);
     BitmapEx GetAsBitmap();
 #if defined( _WIN32 )
@@ -149,15 +149,13 @@ public:
     bool GetMSAASupport();
     int GetMSAAFormat();
 #endif
-    void SetColor(sal_uInt32 color);
+    void SetColor(sal_uInt32 color, sal_uInt8 nAlpha);
     int Bubble2DShapePoint(float x, float y, float directionX, float directionY);
     int RenderBubble2FBO(int wholeFlag);
 
     void prepareToRender();
     void renderToBitmap();
 
-
-    void SetTransparency(sal_uInt32 transparency);
     int RenderRectangleShape(bool bBorder, bool bFill);
     int RectangleShapePoint(float x, float y, float directionX, float directionY);
 
@@ -178,7 +176,7 @@ public:
     void renderDebug();
 #endif
 
-    void SetBackGroundColor(sal_uInt32 color1, sal_uInt32 color2);
+    void SetBackGroundColor(sal_uInt32 color1, sal_uInt32 color2, sal_uInt8 nAlpha);
 
 private:
     GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName);
@@ -262,8 +260,6 @@ private:
 
     float m_fZStep;
 
-    float m_fAlpha;
-
     std::list <RectanglePointList> m_RectangleShapePointList;
     // add for text
     std::list <TextInfo> m_TextInfoList;
commit d76b50a0883451c6c92618f06ecbd7d5232d79d7
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Feb 5 10:24:34 2014 +0100

    small clean-up
    
    Change-Id: I2bc4ff6f559eec11bcd48298e1147dbed96ee558

diff --git a/chart2/source/view/main/DummyXShape.cxx b/chart2/source/view/main/DummyXShape.cxx
index 9e957d2..4cb2c7a 100644
--- a/chart2/source/view/main/DummyXShape.cxx
+++ b/chart2/source/view/main/DummyXShape.cxx
@@ -347,8 +347,10 @@ DummyPieSegment2D::DummyPieSegment2D(double fUnitCircleStartAngleDegree, double
     maUnitCircleToScene(rUnitCircleToScene)
 {
 }
+
 void DummyPieSegment2D::render()
 {
+    SAL_WARN("chart2.opengl", "render DummyPieSegment2D");
     DummyChart* pChart = getRootShape();
 
     while(mfUnitCircleWidthAngleDegree>360)
@@ -425,7 +427,6 @@ void DummyArea2D::render()
         pChart->m_GLRender.SetColor(nColor);
     }
 
-    //render the shape
     pChart->m_GLRender.RenderArea2DShape();
 }
 
@@ -470,8 +471,6 @@ void DummyCircle::render()
         SAL_WARN("chart2.opengl", "missing color");
     pChart->m_GLRender.Bubble2DShapePoint(maPosition.X, maPosition.Y,
                                           maSize.Width, maSize.Height);
-    SAL_WARN("chart2.opengl", "Bubble Position: " << maPosition.X << "," << maPosition.Y);
-    SAL_WARN("chart2.opengl", "Bubble Size: " << maSize.Width << "," << maSize.Height);
     pChart->m_GLRender.RenderBubble2FBO(GL_TRUE);
 }
 
@@ -618,7 +617,6 @@ void DummyRectangle::render()
     std::map< OUString, uno::Any >::const_iterator itr = maProperties.find("Invisible");
     if(itr != maProperties.end())
     {
-        SAL_WARN("chart2.opengl", "invisble");
         return;
     }
 
commit 09ada722c867cba72cc9ae256b6dd54aed0d8aed
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue Feb 4 22:03:43 2014 +0100

    get z order correct in a few more places
    
    Change-Id: I88ff54193fe527fe4d498753557a27a99a856f05

diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 74eb078..9097c78 100755
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -611,6 +611,8 @@ int OpenGLRender::RenderTexture2FBO(GLuint TexID)
     glUseProgram(0);
     glDepthMask(GL_TRUE);
     CHECK_GL_ERROR();
+
+    m_fZStep += Z_STEP;
     return 0;
 }
 
@@ -657,6 +659,7 @@ int OpenGLRender::RenderTexture(GLuint TexID)
     glXSwapBuffers(glWin.dpy, glWin.win);
 #endif
     glFlush();
+    m_fZStep += Z_STEP;
     return 0;
 }
 
@@ -1162,6 +1165,7 @@ int OpenGLRender::RenderBubble2FBO(int)
         return -1;
     }
     CHECK_GL_ERROR();
+    m_fZStep += Z_STEP;
     return 0;
 }
 
commit ad491f201ad35c8ab3a687f40dfc4d0680c61cb7
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue Feb 4 22:01:37 2014 +0100

    make bar charts working
    
    Apparently the bar chart polygon points are clockwise and are therefore
    culled. Detect and change the front facing setting that case. Disabling
    culling does not work here.
    
    Change-Id: I5b243210d1febcbae2126f099455dd1330a5b7d6

diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 5e1f5dd..74eb078 100755
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -241,6 +241,7 @@ int OpenGLRender::InitOpenGL(GLWindow aWindow)
     glEnable(GL_TEXTURE_2D);
     glEnable(GL_CULL_FACE);
     glCullFace(GL_BACK);
+    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
     // Enable depth test
     glEnable(GL_DEPTH_TEST);
     // Accept fragment if it closer to the camera than the former one
@@ -1487,6 +1488,31 @@ int OpenGLRender::SetArea2DShapePoint(float x, float y, int listLength)
     return 0;
 }
 
+namespace {
+
+// only 2D
+bool checkCCW(const Area2DPointList& rPoints)
+{
+    if(rPoints.size() < 3)
+        return true;
+
+    GLfloat sum = 0;
+    for(size_t i = 1; i < rPoints.size()/3; i += 3)
+    {
+        GLfloat x1 = rPoints[(i-1)*3];
+        GLfloat x2 = rPoints[i*3];
+        GLfloat y1 = rPoints[(i-1)*3 + 1];
+        GLfloat y2 = rPoints[i*3 + 1];
+        GLfloat prod = (x2-x1)*(y2+y1);
+
+        sum += prod;
+    }
+
+    return (sum <= 0);
+}
+
+}
+
 int OpenGLRender::RenderArea2DShape()
 {
     CHECK_GL_ERROR();
@@ -1501,6 +1527,9 @@ int OpenGLRender::RenderArea2DShape()
     for (size_t i = 0; i < listNum; ++i)
     {
         Area2DPointList &pointList = m_Area2DShapePointList.front();
+        bool bIsCCW = checkCCW(pointList); // is it counter clockwise (CCW) or clockwise (CW)
+        if(!bIsCCW)
+            glFrontFace(GL_CW);
         //fill vertex buffer
         glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
         glBufferData(GL_ARRAY_BUFFER, pointList.size() * sizeof(float), &pointList[0], GL_STATIC_DRAW);
@@ -1522,9 +1551,12 @@ int OpenGLRender::RenderArea2DShape()
             0,                  // stride
             (void*)0            // array buffer offset
             );
+        // TODO: moggi: remove deprecated GL_POLYGON
         glDrawArrays(GL_POLYGON, 0, pointList.size() / 3); // 12*3 indices starting at 0 -> 12 triangles
         glDisableVertexAttribArray(m_2DVertexID);
         glUseProgram(0);
+        if(!bIsCCW)
+            glFrontFace(GL_CCW);
         m_Area2DShapePointList.pop_front();
     }
     glEnable(GL_MULTISAMPLE);


More information about the Libreoffice-commits mailing list