diff --git a/apps/graph/app.cpp b/apps/graph/app.cpp index 7e3337edb..618441969 100644 --- a/apps/graph/app.cpp +++ b/apps/graph/app.cpp @@ -20,6 +20,13 @@ const Image * App::Descriptor::icon() { return ImageStore::GraphIcon; } +App::Snapshot::Snapshot() : + m_functionStore(), + m_graphRange(&m_cursor), + m_cursor() +{ +} + App * App::Snapshot::unpack(Container * container) { return new App(container, this); } @@ -37,6 +44,14 @@ CartesianFunctionStore * App::Snapshot::functionStore() { return &m_functionStore; } +InteractiveCurveViewRange * App::Snapshot::graphRange() { + return &m_graphRange; +} + +CurveViewCursor * App::Snapshot::cursor() { + return &m_cursor; +} + void App::Snapshot::tidy() { m_functionStore.tidy(); } @@ -48,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(&m_listStackViewController, &m_listFooter, &m_listController), m_listStackViewController(&m_tabViewController, &m_listHeader), - m_graphController(&m_graphAlternateEmptyViewController, snapshot->functionStore(), &m_graphHeader), + m_graphController(&m_graphAlternateEmptyViewController, snapshot->functionStore(), snapshot->graphRange(), snapshot->cursor(), &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/app.h b/apps/graph/app.h index c3cd58129..335dbd0d8 100644 --- a/apps/graph/app.h +++ b/apps/graph/app.h @@ -21,13 +21,18 @@ public: }; class Snapshot : public ::App::Snapshot { public: + Snapshot(); App * unpack(Container * container) override; void reset() override; Descriptor * descriptor() override; CartesianFunctionStore * functionStore(); + Shared::InteractiveCurveViewRange * graphRange(); + Shared::CurveViewCursor * cursor(); private: void tidy() override; CartesianFunctionStore m_functionStore; + Shared::InteractiveCurveViewRange m_graphRange; + Shared::CurveViewCursor m_cursor; }; InputViewController * inputViewController() override; /* This local context can parse x. However, it always stores NAN diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 9ee69e78b..2a5796961 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -5,14 +5,15 @@ using namespace Poincare; namespace Graph { -GraphController::GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, ButtonRowController * header) : - FunctionGraphController(parentResponder, header, &m_graphRange, &m_view), +GraphController::GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, ButtonRowController * header) : + FunctionGraphController(parentResponder, header, curveViewRange, &m_view, cursor), m_bannerView(), - m_view(functionStore, &m_graphRange, &m_cursor, &m_bannerView, &m_cursorView), - m_graphRange(&m_cursor, this), - m_curveParameterController(&m_graphRange, &m_bannerView, &m_cursor), + m_view(functionStore, curveViewRange, m_cursor, &m_bannerView, &m_cursorView), + m_graphRange(curveViewRange), + m_curveParameterController(curveViewRange, &m_bannerView, m_cursor), m_functionStore(functionStore) { + m_graphRange->setDelegate(this); } I18n::Message GraphController::emptyMessage() { @@ -42,20 +43,20 @@ void GraphController::reloadBannerView() { buffer[0] = f->name()[0]; buffer[1] = '\''; TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); - float y = f->approximateDerivative(m_cursor.x(), myApp->localContext()); + float y = f->approximateDerivative(m_cursor->x(), myApp->localContext()); Complex::convertFloatToText(y, buffer + legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); m_bannerView.setLegendAtIndex(buffer, 2); } bool GraphController::moveCursorHorizontally(int direction) { - float xCursorPosition = m_cursor.x(); - float x = direction > 0 ? xCursorPosition + m_graphRange.xGridUnit()/k_numberOfCursorStepsInGradUnit : - xCursorPosition - m_graphRange.xGridUnit()/k_numberOfCursorStepsInGradUnit; + float xCursorPosition = m_cursor->x(); + float x = direction > 0 ? xCursorPosition + m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit : + xCursorPosition - m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit; CartesianFunction * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); float y = f->evaluateAtAbscissa(x, myApp->localContext()); - m_cursor.moveTo(x, y); - m_graphRange.panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); + m_cursor->moveTo(x, y); + m_graphRange->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); return true; } @@ -69,12 +70,12 @@ void GraphController::initCursorParameters() { CartesianFunction * firstFunction = functionStore()->activeFunctionAtIndex(functionIndex++); y = firstFunction->evaluateAtAbscissa(x, myApp->localContext()); } while (isnan(y) && functionIndex < functionStore()->numberOfActiveFunctions()); - m_cursor.moveTo(x, y); + m_cursor->moveTo(x, y); interactiveCurveViewRange()->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); } InteractiveCurveViewRange * GraphController::interactiveCurveViewRange() { - return &m_graphRange; + return m_graphRange; } CartesianFunctionStore * GraphController::functionStore() const { diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index 96dad41f2..f54ddd156 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -5,13 +5,15 @@ #include "banner_view.h" #include "curve_parameter_controller.h" #include "../../shared/function_graph_controller.h" +#include "../../shared/curve_view_cursor.h" +#include "../../shared/interactive_curve_view_range.h" #include "../cartesian_function_store.h" namespace Graph { class GraphController : public Shared::FunctionGraphController { public: - GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, ButtonRowController * header); + GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, ButtonRowController * header); I18n::Message emptyMessage() override; private: BannerView * bannerView() override; @@ -24,7 +26,7 @@ private: CurveParameterController * curveParameterController() override; BannerView m_bannerView; GraphView m_view; - Shared::InteractiveCurveViewRange m_graphRange; + Shared::InteractiveCurveViewRange * m_graphRange; CurveParameterController m_curveParameterController; CartesianFunctionStore * m_functionStore; }; diff --git a/apps/regression/app.cpp b/apps/regression/app.cpp index b656e60d5..03220f053 100644 --- a/apps/regression/app.cpp +++ b/apps/regression/app.cpp @@ -35,12 +35,16 @@ Store * App::Snapshot::store() { return &m_store; } +CurveViewCursor * App::Snapshot::cursor() { + return &m_cursor; +} + App::App(Container * container, Snapshot * snapshot) : TextFieldDelegateApp(container, snapshot, &m_tabViewController), m_calculationController(&m_calculationAlternateEmptyViewController, &m_calculationHeader, snapshot->store()), m_calculationAlternateEmptyViewController(&m_calculationHeader, &m_calculationController, &m_calculationController), m_calculationHeader(&m_tabViewController, &m_calculationAlternateEmptyViewController, &m_calculationController), - m_graphController(&m_graphAlternateEmptyViewController, &m_graphHeader, snapshot->store()), + m_graphController(&m_graphAlternateEmptyViewController, &m_graphHeader, snapshot->store(), snapshot->cursor()), 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/regression/app.h b/apps/regression/app.h index 611658dac..30b21654d 100644 --- a/apps/regression/app.h +++ b/apps/regression/app.h @@ -24,9 +24,11 @@ public: void reset() override; Descriptor * descriptor() override; Store * store(); + Shared::CurveViewCursor * cursor(); private: Store m_store; - }; + Shared::CurveViewCursor m_cursor; + }; private: App(Container * container, Snapshot * snapshot); CalculationController m_calculationController; diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp index a26649d60..a1fe8aca6 100644 --- a/apps/regression/graph_controller.cpp +++ b/apps/regression/graph_controller.cpp @@ -6,16 +6,16 @@ using namespace Shared; namespace Regression { -GraphController::GraphController(Responder * parentResponder, ButtonRowController * header, Store * store) : - InteractiveCurveViewController(parentResponder, header, store, &m_view), +GraphController::GraphController(Responder * parentResponder, ButtonRowController * header, Store * store, CurveViewCursor * cursor) : + InteractiveCurveViewController(parentResponder, header, store, &m_view, cursor), m_bannerView(), - m_view(store, &m_cursor, &m_bannerView, &m_cursorView), + m_view(store, m_cursor, &m_bannerView, &m_cursorView), m_store(store), m_initialisationParameterController(this, m_store), - m_predictionParameterController(this, m_store, &m_cursor), + m_predictionParameterController(this, m_store, m_cursor), m_selectedDotIndex(-1) { - m_store->setCursor(&m_cursor); + m_store->setCursor(m_cursor); } ViewController * GraphController::initialisationParameterController() { @@ -84,7 +84,7 @@ void GraphController::reloadBannerView() { numberOfChar = 0; legend = " x="; - float x = m_cursor.x(); + float x = m_cursor->x(); // Display a specific legend if the mean dot is selected if (m_selectedDotIndex == m_store->numberOfPairs()) { constexpr static char legX[] = {Ion::Charset::XBar, ' ', '=', ' ', 0}; @@ -103,7 +103,7 @@ void GraphController::reloadBannerView() { numberOfChar = 0; legend = " y="; - float y = m_cursor.y(); + float y = m_cursor->y(); if (m_selectedDotIndex == m_store->numberOfPairs()) { constexpr static char legY[] = {Ion::Charset::YBar, ' ', '=', ' ', 0}; legend = legY; @@ -127,7 +127,7 @@ void GraphController::initRangeParameters() { void GraphController::initCursorParameters() { float x = (m_store->xMin() + m_store->xMax())/2.0f; float y = m_store->yValueForXValue(x); - m_cursor.moveTo(x, y); + m_cursor->moveTo(x, y); m_store->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); m_selectedDotIndex = -1; } @@ -137,49 +137,49 @@ bool GraphController::moveCursorHorizontally(int direction) { int dotSelected = m_store->nextDot(direction, m_selectedDotIndex); if (dotSelected >= 0 && dotSelected < m_store->numberOfPairs()) { m_selectedDotIndex = dotSelected; - m_cursor.moveTo(m_store->get(0, m_selectedDotIndex), m_store->get(1, m_selectedDotIndex)); - m_store->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); + m_cursor->moveTo(m_store->get(0, m_selectedDotIndex), m_store->get(1, m_selectedDotIndex)); + m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); return true; } if (dotSelected == m_store->numberOfPairs()) { m_selectedDotIndex = dotSelected; - m_cursor.moveTo(m_store->meanOfColumn(0), m_store->meanOfColumn(1)); - m_store->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); + m_cursor->moveTo(m_store->meanOfColumn(0), m_store->meanOfColumn(1)); + m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); return true; } return false; } - float x = direction > 0 ? m_cursor.x() + m_store->xGridUnit()/k_numberOfCursorStepsInGradUnit : - m_cursor.x() - m_store->xGridUnit()/k_numberOfCursorStepsInGradUnit; + float x = direction > 0 ? m_cursor->x() + m_store->xGridUnit()/k_numberOfCursorStepsInGradUnit : + m_cursor->x() - m_store->xGridUnit()/k_numberOfCursorStepsInGradUnit; float y = m_store->yValueForXValue(x); - m_cursor.moveTo(x, y); + m_cursor->moveTo(x, y); m_store->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); return true; } bool GraphController::moveCursorVertically(int direction) { - float yRegressionCurve = m_store->yValueForXValue(m_cursor.x()); + float yRegressionCurve = m_store->yValueForXValue(m_cursor->x()); if (m_selectedDotIndex >= 0) { - if ((yRegressionCurve - m_cursor.y() > 0) == (direction > 0)) { + if ((yRegressionCurve - m_cursor->y() > 0) == (direction > 0)) { m_selectedDotIndex = -1; - m_cursor.moveTo(m_cursor.x(), yRegressionCurve); - m_store->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); + m_cursor->moveTo(m_cursor->x(), yRegressionCurve); + m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); return true; } else { return false; } } else { - int dotSelected = m_store->closestVerticalDot(direction, m_cursor.x()); + int dotSelected = m_store->closestVerticalDot(direction, m_cursor->x()); if (dotSelected >= 0 && dotSelected < m_store->numberOfPairs()) { m_selectedDotIndex = dotSelected; - m_cursor.moveTo(m_store->get(0, m_selectedDotIndex), m_store->get(1, m_selectedDotIndex)); - m_store->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); + m_cursor->moveTo(m_store->get(0, m_selectedDotIndex), m_store->get(1, m_selectedDotIndex)); + m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); return true; } if (dotSelected == m_store->numberOfPairs()) { m_selectedDotIndex = dotSelected; - m_cursor.moveTo(m_store->meanOfColumn(0), m_store->meanOfColumn(1)); - m_store->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); + m_cursor->moveTo(m_store->meanOfColumn(0), m_store->meanOfColumn(1)); + m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); return true; } return false; diff --git a/apps/regression/graph_controller.h b/apps/regression/graph_controller.h index 1ea214483..095a0001c 100644 --- a/apps/regression/graph_controller.h +++ b/apps/regression/graph_controller.h @@ -8,13 +8,14 @@ #include "initialisation_parameter_controller.h" #include "prediction_parameter_controller.h" #include "../shared/interactive_curve_view_controller.h" +#include "../shared/curve_view_cursor.h" namespace Regression { class GraphController : public Shared::InteractiveCurveViewController { public: - GraphController(Responder * parentResponder, ButtonRowController * header, Store * store); + GraphController(Responder * parentResponder, ButtonRowController * header, Store * store, Shared::CurveViewCursor * cursor); ViewController * initialisationParameterController() override; bool isEmpty() const override; I18n::Message emptyMessage() override; diff --git a/apps/sequence/app.cpp b/apps/sequence/app.cpp index 12d01680c..dcc9560ae 100644 --- a/apps/sequence/app.cpp +++ b/apps/sequence/app.cpp @@ -18,6 +18,13 @@ const Image * App::Descriptor::icon() { return ImageStore::SequenceIcon; } +App::Snapshot::Snapshot() : + m_sequenceStore(), + m_graphRange(&m_cursor), + m_cursor() +{ +} + App * App::Snapshot::unpack(Container * container) { return new App(container, this); } @@ -35,6 +42,14 @@ SequenceStore * App::Snapshot::sequenceStore() { return &m_sequenceStore; } +CurveViewRange * App::Snapshot::graphRange() { + return &m_graphRange; +} + +Shared::CurveViewCursor * App::Snapshot::cursor() { + return &m_cursor; +} + void App::Snapshot::tidy() { m_sequenceStore.tidy(); } @@ -46,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(nullptr, &m_listFooter, &m_listController), m_listStackViewController(&m_tabViewController, &m_listHeader), - m_graphController(&m_graphAlternateEmptyViewController, snapshot->sequenceStore(), &m_graphHeader), + m_graphController(&m_graphAlternateEmptyViewController, snapshot->sequenceStore(), snapshot->graphRange(), snapshot->cursor(), &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/app.h b/apps/sequence/app.h index b959fd82b..6614f9b7a 100644 --- a/apps/sequence/app.h +++ b/apps/sequence/app.h @@ -6,6 +6,7 @@ #include "local_context.h" #include "sequence_store.h" #include "graph/graph_controller.h" +#include "graph/curve_view_range.h" #include "list/list_controller.h" #include "values/values_controller.h" #include "../shared/function_app.h" @@ -22,13 +23,18 @@ public: }; class Snapshot : public ::App::Snapshot { public: + Snapshot(); App * unpack(Container * container) override; void reset() override; Descriptor * descriptor() override; SequenceStore * sequenceStore(); + CurveViewRange * graphRange(); + Shared::CurveViewCursor * cursor(); private: void tidy() override; SequenceStore m_sequenceStore; + CurveViewRange m_graphRange; + Shared::CurveViewCursor m_cursor; }; InputViewController * inputViewController() override; Poincare::Context * localContext() override; diff --git a/apps/sequence/graph/curve_view_range.h b/apps/sequence/graph/curve_view_range.h index 57c45203e..480a49fc6 100644 --- a/apps/sequence/graph/curve_view_range.h +++ b/apps/sequence/graph/curve_view_range.h @@ -7,7 +7,7 @@ namespace Sequence { class CurveViewRange : public Shared::InteractiveCurveViewRange { public: - CurveViewRange(Shared::CurveViewCursor * cursor, Shared::InteractiveCurveViewRangeDelegate * delegate); + CurveViewRange(Shared::CurveViewCursor * cursor, Shared::InteractiveCurveViewRangeDelegate * delegate = nullptr); void roundAbscissa() override; void normalize() override; void setTrigonometric() override; diff --git a/apps/sequence/graph/graph_controller.cpp b/apps/sequence/graph/graph_controller.cpp index cbdf37917..0145bf2ca 100644 --- a/apps/sequence/graph/graph_controller.cpp +++ b/apps/sequence/graph/graph_controller.cpp @@ -4,15 +4,16 @@ using namespace Shared; namespace Sequence { -GraphController::GraphController(Responder * parentResponder, SequenceStore * sequenceStore, ButtonRowController * header) : - FunctionGraphController(parentResponder, header, &m_graphRange, &m_view), +GraphController::GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, ButtonRowController * header) : + FunctionGraphController(parentResponder, header, graphRange, &m_view, cursor), m_bannerView(), - m_view(sequenceStore, &m_graphRange, &m_cursor, &m_bannerView, &m_cursorView), - m_graphRange(&m_cursor, this), - m_curveParameterController(this, &m_graphRange, &m_cursor), - m_termSumController(this, &m_view, &m_graphRange, &m_cursor), + m_view(sequenceStore, graphRange, m_cursor, &m_bannerView, &m_cursorView), + m_graphRange(graphRange), + m_curveParameterController(this, graphRange, m_cursor), + m_termSumController(this, &m_view, graphRange, m_cursor), m_sequenceStore(sequenceStore) { + m_graphRange->setDelegate(this); } void GraphController::viewWillAppear() { @@ -44,7 +45,7 @@ bool GraphController::handleEnter() { } bool GraphController::moveCursorHorizontally(int direction) { - float xCursorPosition = roundf(m_cursor.x()); + float xCursorPosition = roundf(m_cursor->x()); if (direction < 0 && xCursorPosition <= 0) { return false; } @@ -61,8 +62,8 @@ bool GraphController::moveCursorHorizontally(int direction) { Sequence * s = m_sequenceStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); float y = s->evaluateAtAbscissa(x, myApp->localContext()); - m_cursor.moveTo(x, y); - m_graphRange.panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); + m_cursor->moveTo(x, y); + m_graphRange->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); return true; } @@ -76,12 +77,12 @@ void GraphController::initCursorParameters() { Sequence * firstFunction = m_sequenceStore->activeFunctionAtIndex(functionIndex++); y = firstFunction->evaluateAtAbscissa(x, myApp->localContext()); } while (isnan(y) && functionIndex < m_sequenceStore->numberOfActiveFunctions()); - m_cursor.moveTo(x, y); - m_graphRange.panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); + m_cursor->moveTo(x, y); + m_graphRange->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); } CurveViewRange * GraphController::interactiveCurveViewRange() { - return &m_graphRange; + return m_graphRange; } SequenceStore * GraphController::functionStore() const { diff --git a/apps/sequence/graph/graph_controller.h b/apps/sequence/graph/graph_controller.h index dc30ff389..2fead3141 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, ButtonRowController * header); + GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, Shared::CurveViewCursor * cursor, ButtonRowController * header); void viewWillAppear() override; I18n::Message emptyMessage() override; TermSumController * termSumController(); @@ -28,7 +28,7 @@ private: CurveParameterController * curveParameterController() override; BannerView m_bannerView; GraphView m_view; - CurveViewRange m_graphRange; + CurveViewRange * m_graphRange; CurveParameterController m_curveParameterController; TermSumController m_termSumController; SequenceStore * m_sequenceStore; diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index b476802ff..edb701605 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -8,8 +8,8 @@ using namespace Poincare; namespace Shared { -FunctionGraphController::FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView) : - InteractiveCurveViewController(parentResponder, header, interactiveRange, curveView), +FunctionGraphController::FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor) : + InteractiveCurveViewController(parentResponder, header, interactiveRange, curveView, cursor), m_indexFunctionSelectedByCursor(0), m_initialisationParameterController(InitialisationParameterController(this, interactiveRange)) { @@ -116,7 +116,7 @@ void FunctionGraphController::reloadBannerView() { strlcpy(buffer, legend, legendLength+1); numberOfChar += legendLength; buffer[0] = functionStore()->symbol(); - numberOfChar += Complex::convertFloatToText(m_cursor.x(), buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + numberOfChar += Complex::convertFloatToText(m_cursor->x(), buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); legend = " "; legendLength = strlen(legend); strlcpy(buffer+numberOfChar, legend, legendLength+1); @@ -133,7 +133,7 @@ void FunctionGraphController::reloadBannerView() { } Function * f = functionStore()->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); buffer[0] = f->name()[0]; - numberOfChar += Complex::convertFloatToText(m_cursor.y(), buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + numberOfChar += Complex::convertFloatToText(m_cursor->y(), buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); legend = " "; legendLength = strlen(legend); strlcpy(buffer+numberOfChar, legend, legendLength+1); @@ -149,12 +149,12 @@ void FunctionGraphController::initRangeParameters() { bool FunctionGraphController::moveCursorVertically(int direction) { Function * actualFunction = functionStore()->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); - float y = actualFunction->evaluateAtAbscissa(m_cursor.x(), myApp->localContext()); + float y = actualFunction->evaluateAtAbscissa(m_cursor->x(), myApp->localContext()); Function * nextFunction = actualFunction; float nextY = direction > 0 ? FLT_MAX : -FLT_MAX; for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) { Function * f = functionStore()->activeFunctionAtIndex(i); - float newY = f->evaluateAtAbscissa(m_cursor.x(), myApp->localContext()); + float 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; @@ -165,8 +165,8 @@ bool FunctionGraphController::moveCursorVertically(int direction) { if (nextFunction == actualFunction) { return false; } - m_cursor.moveTo(m_cursor.x(), nextY); - interactiveCurveViewRange()->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); + m_cursor->moveTo(m_cursor->x(), nextY); + interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); return true; } diff --git a/apps/shared/function_graph_controller.h b/apps/shared/function_graph_controller.h index c22da9b49..0b53d094d 100644 --- a/apps/shared/function_graph_controller.h +++ b/apps/shared/function_graph_controller.h @@ -12,7 +12,7 @@ namespace Shared { class FunctionGraphController : public InteractiveCurveViewController, public InteractiveCurveViewRangeDelegate { public: - FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView); + FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor); bool isEmpty() const override; ViewController * initialisationParameterController() override; void viewWillAppear() override; diff --git a/apps/shared/interactive_curve_view_controller.cpp b/apps/shared/interactive_curve_view_controller.cpp index 6d6b03e78..f1d2d67f7 100644 --- a/apps/shared/interactive_curve_view_controller.cpp +++ b/apps/shared/interactive_curve_view_controller.cpp @@ -7,10 +7,10 @@ using namespace Poincare; namespace Shared { -InteractiveCurveViewController::InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView) : +InteractiveCurveViewController::InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor) : ViewController(parentResponder), ButtonRowDelegate(header, nullptr), - m_cursor(), + m_cursor(cursor), m_cursorView(CursorView()), m_modelVersion(0), m_rangeVersion(0), @@ -181,7 +181,7 @@ StackViewController * InteractiveCurveViewController::stackController() const{ void InteractiveCurveViewController::centerCursorVertically() { if (!interactiveCurveViewRange()->yAuto()) { - interactiveCurveViewRange()->centerAxisAround(CurveViewRange::Axis::Y, m_cursor.y()); + interactiveCurveViewRange()->centerAxisAround(CurveViewRange::Axis::Y, m_cursor->y()); } } } diff --git a/apps/shared/interactive_curve_view_controller.h b/apps/shared/interactive_curve_view_controller.h index d8c8aafad..d35c6db5b 100644 --- a/apps/shared/interactive_curve_view_controller.h +++ b/apps/shared/interactive_curve_view_controller.h @@ -3,6 +3,7 @@ #include #include "interactive_curve_view_range.h" +#include "curve_view_cursor.h" #include "curve_view.h" #include "cursor_view.h" #include "ok_view.h" @@ -14,7 +15,7 @@ namespace Shared { class InteractiveCurveViewController : public ViewController, public ButtonRowDelegate, public AlternateEmptyViewDelegate { public: - InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView); + InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor); View * view() override; const char * title() override; bool handleEvent(Ion::Events::Event event) override; @@ -51,7 +52,7 @@ protected: virtual uint32_t rangeVersion() = 0; virtual InteractiveCurveViewRange * interactiveCurveViewRange() = 0; virtual CurveView * curveView() = 0; - CurveViewCursor m_cursor; + CurveViewCursor * m_cursor; CursorView m_cursorView; OkView m_okView; private: diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index f6e53cd8d..169965a09 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -17,6 +17,10 @@ InteractiveCurveViewRange::InteractiveCurveViewRange(CurveViewCursor * cursor, I { } +void InteractiveCurveViewRange::setDelegate(InteractiveCurveViewRangeDelegate * delegate) { + m_delegate = delegate; +} + void InteractiveCurveViewRange::setCursor(CurveViewCursor * cursor) { m_cursor = cursor; } diff --git a/apps/shared/interactive_curve_view_range.h b/apps/shared/interactive_curve_view_range.h index 2f4671ce0..2f0ce8287 100644 --- a/apps/shared/interactive_curve_view_range.h +++ b/apps/shared/interactive_curve_view_range.h @@ -10,7 +10,8 @@ namespace Shared { class InteractiveCurveViewRange : public MemoizedCurveViewRange { public: - InteractiveCurveViewRange(CurveViewCursor * cursor, InteractiveCurveViewRangeDelegate * delegate); + InteractiveCurveViewRange(CurveViewCursor * cursor, InteractiveCurveViewRangeDelegate * delegate = nullptr); + void setDelegate(InteractiveCurveViewRangeDelegate * delegate); void setCursor(CurveViewCursor * cursor); uint32_t rangeChecksum() override;