diff --git a/apps/graph/app.cpp b/apps/graph/app.cpp index 581877d5f..1bd39a231 100644 --- a/apps/graph/app.cpp +++ b/apps/graph/app.cpp @@ -61,7 +61,7 @@ App::App(Container * container, Snapshot * snapshot) : m_listFooter(&m_listHeader, &m_listController, &m_listController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey), m_listHeader(&m_listStackViewController, &m_listFooter, &m_listController), m_listStackViewController(&m_tabViewController, &m_listHeader), - m_graphController(&m_graphAlternateEmptyViewController, snapshot->functionStore(), snapshot->graphRange(), snapshot->cursor(), snapshot->modelVersion(), snapshot->rangeVersion(), snapshot->angleUnitVersion(), &m_graphHeader), + m_graphController(&m_graphAlternateEmptyViewController, snapshot->functionStore(), snapshot->graphRange(), snapshot->cursor(), snapshot->indexFunctionSelectedByCursor(), snapshot->modelVersion(), snapshot->rangeVersion(), snapshot->angleUnitVersion(), &m_graphHeader), m_graphAlternateEmptyViewController(&m_graphHeader, &m_graphController, &m_graphController), m_graphHeader(&m_graphStackViewController, &m_graphAlternateEmptyViewController, &m_graphController), m_graphStackViewController(&m_tabViewController, &m_graphHeader), diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 7013a8f5b..0a5056f53 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -6,8 +6,8 @@ using namespace Poincare; namespace Graph { -GraphController::GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion, Expression::AngleUnit * angleUnitVersion, ButtonRowController * header) : - FunctionGraphController(parentResponder, header, curveViewRange, &m_view, cursor, modelVersion, rangeVersion, angleUnitVersion), +GraphController::GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Expression::AngleUnit * angleUnitVersion, ButtonRowController * header) : + FunctionGraphController(parentResponder, header, curveViewRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion), m_bannerView(), m_view(functionStore, curveViewRange, m_cursor, &m_bannerView, &m_cursorView), m_graphRange(curveViewRange), @@ -48,20 +48,20 @@ void GraphController::reloadBannerView() { if (m_functionStore->numberOfActiveFunctions() == 0 || !m_displayDerivativeInBanner) { return; } - CartesianFunction * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); + CartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, f, myApp); } bool GraphController::moveCursorHorizontally(int direction) { - CartesianFunction * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); + CartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, f, myApp, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); } void GraphController::initCursorParameters() { double x = (interactiveCurveViewRange()->xMin()+interactiveCurveViewRange()->xMax())/2.0f; - m_indexFunctionSelectedByCursor = 0; + selectFunctionWithCursor(0); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); int functionIndex = 0; double y = 0; diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index eef097772..33b1a6ec0 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -14,7 +14,7 @@ namespace Graph { class GraphController : public Shared::FunctionGraphController, public GraphControllerHelper { public: - GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Expression::AngleUnit * angleUnitVersion, ButtonRowController * header); + GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Expression::AngleUnit * angleUnitVersion, ButtonRowController * header); I18n::Message emptyMessage() override; void viewWillAppear() override; bool displayDerivativeInBanner() const; diff --git a/apps/sequence/app.cpp b/apps/sequence/app.cpp index de681f165..a875a05d0 100644 --- a/apps/sequence/app.cpp +++ b/apps/sequence/app.cpp @@ -63,7 +63,7 @@ App::App(Container * container, Snapshot * snapshot) : m_listFooter(&m_listHeader, &m_listController, &m_listController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey), m_listHeader(nullptr, &m_listFooter, &m_listController), m_listStackViewController(&m_tabViewController, &m_listHeader), - m_graphController(&m_graphAlternateEmptyViewController, snapshot->sequenceStore(), snapshot->graphRange(), snapshot->cursor(), snapshot->modelVersion(), snapshot->rangeVersion(), snapshot->angleUnitVersion(), &m_graphHeader), + m_graphController(&m_graphAlternateEmptyViewController, snapshot->sequenceStore(), snapshot->graphRange(), snapshot->cursor(), snapshot->indexFunctionSelectedByCursor(), snapshot->modelVersion(), snapshot->rangeVersion(), snapshot->angleUnitVersion(), &m_graphHeader), m_graphAlternateEmptyViewController(&m_graphHeader, &m_graphController, &m_graphController), m_graphHeader(&m_graphStackViewController, &m_graphAlternateEmptyViewController, &m_graphController), m_graphStackViewController(&m_tabViewController, &m_graphHeader), diff --git a/apps/sequence/graph/graph_controller.cpp b/apps/sequence/graph/graph_controller.cpp index 48d9aec2b..f720cc60e 100644 --- a/apps/sequence/graph/graph_controller.cpp +++ b/apps/sequence/graph/graph_controller.cpp @@ -6,8 +6,8 @@ using namespace Poincare; namespace Sequence { -GraphController::GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion, Expression::AngleUnit * angleUnitVersion, ButtonRowController * header) : - FunctionGraphController(parentResponder, header, graphRange, &m_view, cursor, modelVersion, rangeVersion, angleUnitVersion), +GraphController::GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Expression::AngleUnit * angleUnitVersion, ButtonRowController * header) : + FunctionGraphController(parentResponder, header, graphRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion), m_bannerView(), m_view(sequenceStore, graphRange, m_cursor, &m_bannerView, &m_cursorView), m_graphRange(graphRange), @@ -34,7 +34,7 @@ BannerView * GraphController::bannerView() { } bool GraphController::handleEnter() { - m_termSumController.setFunction(m_sequenceStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor)); + m_termSumController.setFunction(m_sequenceStore->activeFunctionAtIndex(indexFunctionSelectedByCursor())); return FunctionGraphController::handleEnter(); } @@ -53,7 +53,7 @@ bool GraphController::moveCursorHorizontally(int direction) { if (x < 0.0) { return false; } - Sequence * s = m_sequenceStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); + Sequence * s = m_sequenceStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); double y = s->evaluateAtAbscissa(x, myApp->localContext()); m_cursor->moveTo(x, y); @@ -63,7 +63,7 @@ bool GraphController::moveCursorHorizontally(int direction) { void GraphController::initCursorParameters() { double x = std::round((interactiveCurveViewRange()->xMin()+interactiveCurveViewRange()->xMax())/2.0); - m_indexFunctionSelectedByCursor = 0; + selectFunctionWithCursor(0); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); int functionIndex = 0; double y = 0; diff --git a/apps/sequence/graph/graph_controller.h b/apps/sequence/graph/graph_controller.h index 84af201d1..a5e70a587 100644 --- a/apps/sequence/graph/graph_controller.h +++ b/apps/sequence/graph/graph_controller.h @@ -13,7 +13,7 @@ namespace Sequence { class GraphController : public Shared::FunctionGraphController { public: - GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, Shared::CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Expression::AngleUnit * angleUnitVersion, ButtonRowController * header); + GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Expression::AngleUnit * angleUnitVersion, ButtonRowController * header); I18n::Message emptyMessage() override; TermSumController * termSumController(); private: diff --git a/apps/shared/function_app.cpp b/apps/shared/function_app.cpp index 4e01d51d4..982e8e854 100644 --- a/apps/shared/function_app.cpp +++ b/apps/shared/function_app.cpp @@ -8,6 +8,7 @@ namespace Shared { FunctionApp::Snapshot::Snapshot() : m_cursor(), m_interval(), + m_indexFunctionSelectedByCursor(0), m_modelVersion(0), m_rangeVersion(0), m_angleUnitVersion(Expression::AngleUnit::Radian) @@ -37,10 +38,15 @@ Interval * FunctionApp::Snapshot::interval() { return &m_interval; } +int * FunctionApp::Snapshot::indexFunctionSelectedByCursor() { + return &m_indexFunctionSelectedByCursor; +} + void FunctionApp::Snapshot::reset() { m_interval.setStart(0); m_interval.setEnd(10); m_interval.setStep(1); + m_indexFunctionSelectedByCursor = 0; m_modelVersion = 0; m_rangeVersion = 0; setActiveTab(0); diff --git a/apps/shared/function_app.h b/apps/shared/function_app.h index 0c73d582f..1f2cc52b3 100644 --- a/apps/shared/function_app.h +++ b/apps/shared/function_app.h @@ -20,11 +20,13 @@ public: uint32_t * rangeVersion(); Poincare::Expression::AngleUnit * angleUnitVersion(); Interval * interval(); + int * indexFunctionSelectedByCursor(); void reset() override; protected: CurveViewCursor m_cursor; Interval m_interval; private: + int m_indexFunctionSelectedByCursor; uint32_t m_modelVersion; uint32_t m_rangeVersion; Poincare::Expression::AngleUnit m_angleUnitVersion; diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index 1e6206af3..2718886a3 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -8,11 +8,11 @@ using namespace Poincare; namespace Shared { -FunctionGraphController::FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion, Expression::AngleUnit * angleUnitVersion) : +FunctionGraphController::FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Expression::AngleUnit * angleUnitVersion) : InteractiveCurveViewController(parentResponder, header, interactiveRange, curveView, cursor, modelVersion, rangeVersion), - m_indexFunctionSelectedByCursor(0), m_initialisationParameterController(this, interactiveRange), - m_angleUnitVersion(angleUnitVersion) + m_angleUnitVersion(angleUnitVersion), + m_indexFunctionSelectedByCursor(indexFunctionSelectedByCursor) { } @@ -45,18 +45,22 @@ void FunctionGraphController::viewWillAppear() { } bool FunctionGraphController::handleEnter() { - Function * f = functionStore()->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); + Function * f = functionStore()->activeFunctionAtIndex(indexFunctionSelectedByCursor()); curveParameterController()->setFunction(f); StackViewController * stack = stackController(); stack->push(curveParameterController()); return true; } +void FunctionGraphController::selectFunctionWithCursor(int functionIndex) { + *m_indexFunctionSelectedByCursor = functionIndex; +} + void FunctionGraphController::reloadBannerView() { if (functionStore()->numberOfActiveFunctions() == 0) { return; } - Function * f = functionStore()->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); + Function * f = functionStore()->activeFunctionAtIndex(indexFunctionSelectedByCursor()); reloadBannerViewForCursorOnFunction(m_cursor, f, functionStore()->symbol()); } @@ -99,11 +103,11 @@ float FunctionGraphController::addMargin(float x, float range, bool isMin) { void FunctionGraphController::initRangeParameters() { interactiveCurveViewRange()->setDefault(); initCursorParameters(); - m_indexFunctionSelectedByCursor = 0; + selectFunctionWithCursor(0); } bool FunctionGraphController::moveCursorVertically(int direction) { - Function * actualFunction = functionStore()->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); + Function * actualFunction = functionStore()->activeFunctionAtIndex(indexFunctionSelectedByCursor()); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); double y = actualFunction->evaluateAtAbscissa(m_cursor->x(), myApp->localContext()); Function * nextFunction = actualFunction; @@ -113,7 +117,7 @@ bool FunctionGraphController::moveCursorVertically(int direction) { double newY = f->evaluateAtAbscissa(m_cursor->x(), myApp->localContext()); bool isNextFunction = direction > 0 ? (newY > y && newY < nextY) : (newY < y && newY > nextY); if (isNextFunction) { - m_indexFunctionSelectedByCursor = i; + selectFunctionWithCursor(i); nextY = newY; nextFunction = f; } diff --git a/apps/shared/function_graph_controller.h b/apps/shared/function_graph_controller.h index 60c80b2ce..981c27ebd 100644 --- a/apps/shared/function_graph_controller.h +++ b/apps/shared/function_graph_controller.h @@ -13,7 +13,7 @@ namespace Shared { class FunctionGraphController : public InteractiveCurveViewController, public InteractiveCurveViewRangeDelegate, public FunctionBannerDelegate { public: - FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Expression::AngleUnit * angleUnitVersion); + FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Expression::AngleUnit * angleUnitVersion); bool isEmpty() const override; ViewController * initialisationParameterController() override; void viewWillAppear() override; @@ -22,7 +22,10 @@ protected: constexpr static float k_cursorBottomMarginRatio = 0.15f; // (cursorHeight/2+bannerHeigh)/graphViewHeight void reloadBannerView() override; bool handleEnter() override; - int m_indexFunctionSelectedByCursor; + int indexFunctionSelectedByCursor() const { + return *m_indexFunctionSelectedByCursor; + } + virtual void selectFunctionWithCursor(int functionIndex); private: /* When y auto is ticked, we use a display margin to be ensure that the user * can move the cursor along the curve without panning the window */ @@ -43,6 +46,7 @@ private: virtual FunctionCurveParameterController * curveParameterController() = 0; InitialisationParameterController m_initialisationParameterController; Poincare::Expression::AngleUnit * m_angleUnitVersion; + int * m_indexFunctionSelectedByCursor; }; }