[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
This commit is contained in:
Gabriel Ozouf
2020-10-14 09:46:21 +02:00
committed by Émilie Feral
parent 16707aa518
commit 190568ea84
6 changed files with 33 additions and 1 deletions

View File

@@ -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<double> xy;
if (*m_selectedDotIndex == -1) {
xy = xyValues(*m_selectedSeriesIndex, m_cursor->t(), globalContext());
} else if (*m_selectedDotIndex == m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex)) {
xy = Coordinate2D<double>(m_store->meanOfColumn(*m_selectedSeriesIndex, 0), m_store->meanOfColumn(*m_selectedSeriesIndex, 1));
} else {
xy = Coordinate2D<double>(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();

View File

@@ -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;

View File

@@ -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<Function> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()));
Coordinate2D<double> xy = f->evaluateXYAtParameter(m_cursor->t(), context);
return xy.x1() != m_cursor->x() || xy.x2() != m_cursor->y();
}
CurveView * FunctionGraphController::curveView() {
return functionGraphView();
}

View File

@@ -37,6 +37,7 @@ protected:
Poincare::Coordinate2D<double> 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;

View File

@@ -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()) {

View File

@@ -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;