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

Markus Mohrhard markus.mohrhard at collabora.co.uk
Sat May 24 14:50:15 PDT 2014


 chart2/source/view/charttypes/GL3DBarChart.cxx |   15 +++++++--
 chart2/source/view/inc/GL3DBarChart.hxx        |    4 +-
 include/vcl/openglwin.hxx                      |    6 +++
 vcl/source/window/openglwin.cxx                |   40 ++++++++++++++++++-------
 4 files changed, 49 insertions(+), 16 deletions(-)

New commits:
commit fa97a8b91becb44c2bd56d91a603b76a16c34304
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sat May 24 23:28:06 2014 +0200

    some work on mouse scrolling and improved mouse dragging
    
    Change-Id: I3265e26530183b2fc4fd7f67319f3dc124353c2e

diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 33d6510..c95458b 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -229,7 +229,8 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
 
     maCameraPosition = glm::vec3(-30, -30, 200);
     mpCamera->setPosition(maCameraPosition);
-    mpCamera->setDirection(glm::vec3(nMaxPointCount*(nBarSizeX+ nBarDistanceX), nSeriesIndex*(nBarSizeY+nBarDistanceY), 0));
+    maCameraDirection = glm::vec3(0, 0, 0);
+    mpCamera->setDirection(maCameraDirection);
 }
 
 void GL3DBarChart::render()
@@ -289,9 +290,17 @@ void GL3DBarChart::clickedAt(const Point& rPos)
         mpCamera->zoom(nId);
 }
 
-void GL3DBarChart::mouseDragMove(const Point& /*rPos*/, sal_uInt16 /*nButtons*/)
+void GL3DBarChart::mouseDragMove(const Point& rStartPos, const Point& rEndPos, sal_uInt16 nButtons)
 {
-//    fprintf(stderr, "drag move %ld %ld (0x%x)\n", rPos.X(), rPos.Y(), nButtons);
+    SAL_WARN("chart2.opengl", "Dragging: " << rStartPos << " to : " << rEndPos << " Buttons: " << nButtons);
+}
+
+void GL3DBarChart::scroll(long nDelta)
+{
+    glm::vec3 maDir = glm::normalize(maCameraPosition - maCameraDirection);
+    maCameraPosition += (float((nDelta/10)) * maDir);
+    mpCamera->setPosition(maCameraPosition);
+    render();
 }
 
 void GL3DBarChart::contextDestroyed()
diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index c85cff8..7997174 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -50,7 +50,8 @@ public:
     virtual void update() SAL_OVERRIDE;
 
     virtual void clickedAt(const Point& rPos) SAL_OVERRIDE;
-    virtual void mouseDragMove(const Point& rPos, sal_uInt16 nButtons) SAL_OVERRIDE;
+    virtual void mouseDragMove(const Point& rStartPos, const Point& rEndPos, sal_uInt16 nButtons) SAL_OVERRIDE;
+    virtual void scroll(long nDelta) SAL_OVERRIDE;
     virtual void contextDestroyed() SAL_OVERRIDE;
 
 private:
@@ -66,6 +67,7 @@ private:
     boost::scoped_ptr<opengl3D::TextCache> mpTextCache;
 
     glm::vec3 maCameraPosition;
+    glm::vec3 maCameraDirection;
 };
 
 }
diff --git a/include/vcl/openglwin.hxx b/include/vcl/openglwin.hxx
index f69d0b3..d2e86cc 100644
--- a/include/vcl/openglwin.hxx
+++ b/include/vcl/openglwin.hxx
@@ -25,7 +25,8 @@ public:
     virtual ~IRenderer() {}
     virtual void update() = 0;
     virtual void clickedAt(const Point& rPos) = 0;
-    virtual void mouseDragMove(const Point& rPos, sal_uInt16 nButtons) = 0;
+    virtual void mouseDragMove(const Point& rPosBegin, const Point& rPosEnd, sal_uInt16 nButtons) = 0;
+    virtual void scroll(long nDelta) = 0;
 
     virtual void contextDestroyed() = 0;
 };
@@ -45,10 +46,13 @@ public:
     virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
+    virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
 
 private:
     boost::scoped_ptr<OpenGLWindowImpl> mpImpl;
     IRenderer* mpRenderer;
+
+    Point maStartPoint;
 };
 
 #endif
diff --git a/vcl/source/window/openglwin.cxx b/vcl/source/window/openglwin.cxx
index 9fd3935..455e455 100644
--- a/vcl/source/window/openglwin.cxx
+++ b/vcl/source/window/openglwin.cxx
@@ -57,24 +57,42 @@ void OpenGLWindow::Paint(const Rectangle&)
 
 void OpenGLWindow::MouseButtonDown( const MouseEvent& rMEvt )
 {
-    Point aPoint = rMEvt.GetPosPixel();
+    maStartPoint = rMEvt.GetPosPixel();
+}
 
-    Color aColor = GetPixel(aPoint);
-    SAL_WARN("vcl.opengl", aColor.GetColor());
-    if(mpRenderer)
-        mpRenderer->clickedAt(aPoint);
+void OpenGLWindow::MouseButtonUp( const MouseEvent& rMEvt )
+{
+    Point aPoint = rMEvt.GetPosPixel();
+    if(aPoint == maStartPoint)
+    {
+        Color aColor = GetPixel(aPoint);
+        SAL_WARN("vcl.opengl", aColor.GetColor());
+        if(mpRenderer)
+            mpRenderer->clickedAt(aPoint);
+    }
+    else
+    {
+        mpRenderer->mouseDragMove(maStartPoint, aPoint,
+                                  rMEvt.GetButtons());
+    }
 }
 
-void OpenGLWindow::MouseButtonUp( const MouseEvent& /* rMEvt */ )
+void OpenGLWindow::Command( const CommandEvent& rCEvt )
 {
-    // in case we need to track button state ourselves.
+    if(rCEvt.GetCommand() == COMMAND_WHEEL)
+    {
+        const CommandWheelData* pData = rCEvt.GetWheelData();
+        if(pData->GetMode() == COMMAND_WHEEL_SCROLL)
+        {
+            long nDelta = pData->GetDelta();
+            if(mpRenderer)
+                mpRenderer->scroll(nDelta);
+        }
+    }
 }
 
-void OpenGLWindow::MouseMove( const MouseEvent& rMEvt )
+void OpenGLWindow::MouseMove( const MouseEvent& /*rMEvt*/ )
 {
-    if(rMEvt.GetButtons())
-        mpRenderer->mouseDragMove(rMEvt.GetPosPixel(),
-                                  rMEvt.GetButtons());
 }
 
 void OpenGLWindow::setRenderer(IRenderer* pRenderer)


More information about the Libreoffice-commits mailing list