From d6528d84a9d650015630defaf59041ea5e76e84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 9 Jun 2017 11:35:53 +0200 Subject: [PATCH] [apps/shared] Change zoom to ensure to keep the same cusor position Change-Id: Ie24fcdda2aad7da8872915511fcd2e71d19ff8a6 --- .../interactive_curve_view_controller.cpp | 8 ++------ apps/shared/interactive_curve_view_range.cpp | 20 +++++++++---------- apps/shared/interactive_curve_view_range.h | 2 +- apps/shared/zoom_parameter_controller.cpp | 8 ++++++-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/apps/shared/interactive_curve_view_controller.cpp b/apps/shared/interactive_curve_view_controller.cpp index 9c3b3b606..25181ade5 100644 --- a/apps/shared/interactive_curve_view_controller.cpp +++ b/apps/shared/interactive_curve_view_controller.cpp @@ -60,16 +60,12 @@ bool InteractiveCurveViewController::handleEvent(Ion::Events::Event event) { return false; } if (event == Ion::Events::Plus) { - interactiveCurveViewRange()->zoom(1.0f/3.0f); - initCursorParameters(); - reloadBannerView(); + interactiveCurveViewRange()->zoom(2.0f/3.0f, m_cursor->x(), m_cursor->y()); curveView()->reload(); return true; } if (event == Ion::Events::Minus) { - interactiveCurveViewRange()->zoom(3.0f/4.0f); - initCursorParameters(); - reloadBannerView(); + interactiveCurveViewRange()->zoom(3.0f/2.0f, m_cursor->x(), m_cursor->y()); curveView()->reload(); return true; } diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index 9eb8b9f6b..c0da85988 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -85,26 +85,26 @@ void InteractiveCurveViewRange::setYAuto(bool yAuto) { } } -void InteractiveCurveViewRange::zoom(float ratio) { +void InteractiveCurveViewRange::zoom(float ratio, float x, float y) { float xMin = m_xMin; float xMax = m_xMax; float yMin = m_yMin; float yMax = m_yMax; - if (2.0f*ratio*fabsf(xMax-xMin) < k_minFloat || 2.0f*ratio*fabsf(yMax-yMin) < k_minFloat) { + if (ratio*fabsf(xMax-xMin) < k_minFloat || ratio*fabsf(yMax-yMin) < k_minFloat) { return; } - float newXMin = clipped((xMax+xMin)/2.0f - ratio*fabsf(xMax-xMin), false); - float newXMax = clipped((xMax+xMin)/2.0f + ratio*fabsf(xMax-xMin), true); + float newXMin = clipped(x*(1.0f-ratio)+ratio*xMin, false); + float newXMax = clipped(x*(1.0f-ratio)+ratio*xMax, true); if (!isnan(newXMin) && !isnan(newXMax)) { - m_xMax = clipped((xMax+xMin)/2.0f + ratio*fabsf(xMax-xMin), true); - MemoizedCurveViewRange::setXMin(clipped((xMax+xMin)/2.0f - ratio*fabsf(xMax-xMin), false)); + m_xMax = newXMax; + MemoizedCurveViewRange::setXMin(newXMin); } m_yAuto = false; - float newYMin = clipped((yMax+yMin)/2.0f - ratio*fabsf(yMax-yMin), false); - float newYMax = clipped((yMax+yMin)/2.0f + ratio*fabsf(yMax-yMin), true); + float newYMin = clipped(y*(1.0f-ratio)+ratio*yMin, false); + float newYMax = clipped(y*(1.0f-ratio)+ratio*yMax, true); if (!isnan(newYMin) && !isnan(newYMax)) { - m_yMax = clipped((yMax+yMin)/2.0f + ratio*fabsf(yMax-yMin), true); - MemoizedCurveViewRange::setYMin(clipped((yMax+yMin)/2.0f - ratio*fabsf(yMax-yMin), false)); + m_yMax = newYMax; + MemoizedCurveViewRange::setYMin(newYMin); } } diff --git a/apps/shared/interactive_curve_view_range.h b/apps/shared/interactive_curve_view_range.h index 5aa57871e..afe7b6c21 100644 --- a/apps/shared/interactive_curve_view_range.h +++ b/apps/shared/interactive_curve_view_range.h @@ -24,7 +24,7 @@ public: void setYAuto(bool yAuto); // Window - void zoom(float ratio); + void zoom(float ratio, float x, float y); void panWithVector(float x, float y); virtual void roundAbscissa(); virtual void normalize(); diff --git a/apps/shared/zoom_parameter_controller.cpp b/apps/shared/zoom_parameter_controller.cpp index bb2f8bf63..761930834 100644 --- a/apps/shared/zoom_parameter_controller.cpp +++ b/apps/shared/zoom_parameter_controller.cpp @@ -21,12 +21,16 @@ View * ZoomParameterController::view() { bool ZoomParameterController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::Plus) { - m_interactiveRange->zoom(1.0f/3.0f); + float meanX = (m_interactiveRange->xMin()+m_interactiveRange->xMax())/2.0f; + float meanY = (m_interactiveRange->yMin()+m_interactiveRange->yMax())/2.0f; + m_interactiveRange->zoom(2.0f/3.0f, meanX, meanY); m_contentView.curveView()->reload(); return true; } if (event == Ion::Events::Minus) { - m_interactiveRange->zoom(3.0f/4.0f); + float meanX = (m_interactiveRange->xMin()+m_interactiveRange->xMax())/2.0f; + float meanY = (m_interactiveRange->yMin()+m_interactiveRange->yMax())/2.0f; + m_interactiveRange->zoom(3.0f/2.0f, meanX, meanY); m_contentView.curveView()->reload(); return true; }