diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-05-24 23:28:06 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-05-24 23:45:01 +0200 |
commit | fa97a8b91becb44c2bd56d91a603b76a16c34304 (patch) | |
tree | c524d0c26eb4193e63b9dc0e927a58a41d7c665b | |
parent | 2d8941eea664031567f4d70f8347dc15befe8880 (diff) |
some work on mouse scrolling and improved mouse dragging
Change-Id: I3265e26530183b2fc4fd7f67319f3dc124353c2e
-rw-r--r-- | chart2/source/view/charttypes/GL3DBarChart.cxx | 15 | ||||
-rw-r--r-- | chart2/source/view/inc/GL3DBarChart.hxx | 4 | ||||
-rw-r--r-- | include/vcl/openglwin.hxx | 6 | ||||
-rw-r--r-- | vcl/source/window/openglwin.cxx | 40 |
4 files changed, 49 insertions, 16 deletions
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index 33d6510938ad..c95458b00ceb 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 c85cff887d37..79971746582f 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 f69d0b327388..d2e86cce90b1 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 9fd3935df210..455e455feaf9 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) |