From 190568ea846ef843d5056448cd3d57901138a318 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Wed, 14 Oct 2020 09:46:21 +0200 Subject: [PATCH] [interactive_curve_view_controller] Fix Cursor Restore the permanence of the cursor between accesses to the graph window. The cursor used to be reset when the models had been modified. As there is no longer a system in place to track these modifications, we manually check if there is a curve beneath the cursor before reseting it. Change-Id: I6f71fc17744b5bf1ee552c82126bb4a08b823629 --- apps/regression/graph_controller.cpp | 15 +++++++++++++++ apps/regression/graph_controller.h | 1 + apps/shared/function_graph_controller.cpp | 10 ++++++++++ apps/shared/function_graph_controller.h | 1 + apps/shared/interactive_curve_view_controller.cpp | 6 +++++- apps/shared/interactive_curve_view_controller.h | 1 + 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp index aad2a78e5..6ccc4f1f4 100644 --- a/apps/regression/graph_controller.cpp +++ b/apps/regression/graph_controller.cpp @@ -259,6 +259,21 @@ void GraphController::initCursorParameters() { *m_selectedDotIndex = m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex); } +bool GraphController::isCursorHanging() { + if (m_store->seriesIsEmpty(*m_selectedSeriesIndex)) { + return true; + } + Coordinate2D xy; + if (*m_selectedDotIndex == -1) { + xy = xyValues(*m_selectedSeriesIndex, m_cursor->t(), globalContext()); + } else if (*m_selectedDotIndex == m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex)) { + xy = Coordinate2D(m_store->meanOfColumn(*m_selectedSeriesIndex, 0), m_store->meanOfColumn(*m_selectedSeriesIndex, 1)); + } else { + xy = Coordinate2D(m_store->get(*m_selectedSeriesIndex, 0, *m_selectedDotIndex), m_store->get(*m_selectedSeriesIndex, 1, *m_selectedDotIndex)); + } + return xy.x1() != m_cursor->x() || xy.x2() != m_cursor->y(); +} + bool GraphController::moveCursorVertically(int direction) { Poincare::Context * context = globalContext(); double x = m_cursor->x(); diff --git a/apps/regression/graph_controller.h b/apps/regression/graph_controller.h index 4adf50f9c..622ac76bc 100644 --- a/apps/regression/graph_controller.h +++ b/apps/regression/graph_controller.h @@ -40,6 +40,7 @@ private: // InteractiveCurveViewController void initCursorParameters() override; + bool isCursorHanging() override; uint32_t rangeVersion() override; int selectedCurveIndex() const override { return *m_selectedSeriesIndex; } bool closestCurveIndexIsSuitable(int newIndex, int currentIndex) const override; diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index bb50d07d5..267b45d73 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -116,6 +116,16 @@ bool FunctionGraphController::moveCursorVertically(int direction) { return true; } +bool FunctionGraphController::isCursorHanging() { + Poincare::Context * context = textFieldDelegateApp()->localContext(); + if (indexFunctionSelectedByCursor() >= functionStore()->numberOfActiveFunctions()) { + return true; + } + ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor())); + Coordinate2D xy = f->evaluateXYAtParameter(m_cursor->t(), context); + return xy.x1() != m_cursor->x() || xy.x2() != m_cursor->y(); +} + CurveView * FunctionGraphController::curveView() { return functionGraphView(); } diff --git a/apps/shared/function_graph_controller.h b/apps/shared/function_graph_controller.h index 6c3469a25..0516b0c87 100644 --- a/apps/shared/function_graph_controller.h +++ b/apps/shared/function_graph_controller.h @@ -37,6 +37,7 @@ protected: Poincare::Coordinate2D xyValues(int curveIndex, double t, Poincare::Context * context) const override; int numberOfCurves() const override; void initCursorParameters() override; + bool isCursorHanging() override; CurveView * curveView() override; void yRangeForCursorFirstMove(Shared::InteractiveCurveViewRange * range) const; diff --git a/apps/shared/interactive_curve_view_controller.cpp b/apps/shared/interactive_curve_view_controller.cpp index d091aea8d..e97a3d9dc 100644 --- a/apps/shared/interactive_curve_view_controller.cpp +++ b/apps/shared/interactive_curve_view_controller.cpp @@ -156,7 +156,11 @@ void InteractiveCurveViewController::viewWillAppear() { /* Warning: init cursor parameter before reloading banner view. Indeed, * reloading banner view needs an updated cursor to load the right data. */ - initCursorParameters(); + uint32_t newRangeVersion = rangeVersion(); + if ((*m_rangeVersion != newRangeVersion && !isCursorVisible()) || isCursorHanging()) { + initCursorParameters(); + } + *m_rangeVersion = newRangeVersion; curveView()->setOkView(&m_okView); if (!curveView()->isMainViewSelected()) { diff --git a/apps/shared/interactive_curve_view_controller.h b/apps/shared/interactive_curve_view_controller.h index 62a6b2438..8a7c43cf3 100644 --- a/apps/shared/interactive_curve_view_controller.h +++ b/apps/shared/interactive_curve_view_controller.h @@ -40,6 +40,7 @@ protected: virtual bool moveCursorVertically(int direction) = 0; virtual uint32_t rangeVersion() = 0; bool isCursorVisible(); + virtual bool isCursorHanging() = 0; // Closest vertical curve helper int closestCurveIndexVertically(bool goingUp, int currentSelectedCurve, Poincare::Context * context) const;