diff --git a/apps/graph/app.cpp b/apps/graph/app.cpp index 3611dd320..734ba72e7 100644 --- a/apps/graph/app.cpp +++ b/apps/graph/app.cpp @@ -10,8 +10,8 @@ App::App(::Context * context) : m_evaluateContext(EvaluateContext(context)), m_listController(ListController(nullptr, &m_functionStore)), m_listStackViewController(StackViewController(&m_tabViewController, &m_listController)), - m_graphController(GraphController(nullptr, &m_functionStore, &m_evaluateContext)), - m_valuesController(nullptr, &m_functionStore, &m_evaluateContext), + m_graphController(GraphController(nullptr, &m_functionStore)), + m_valuesController(nullptr, &m_functionStore), m_valuesStackViewController(StackViewController(&m_tabViewController, &m_valuesController)), m_tabViewController(&m_inputViewController, &m_listStackViewController, &m_graphController, &m_valuesStackViewController), m_inputViewController(&m_modalViewController, &m_tabViewController, this) @@ -26,4 +26,8 @@ Context * App::globalContext() { return m_globalContext; } +Context * App::evaluateContext() { + return &m_evaluateContext; +} + } diff --git a/apps/graph/app.h b/apps/graph/app.h index a0b4b462e..3dda36a45 100644 --- a/apps/graph/app.h +++ b/apps/graph/app.h @@ -16,6 +16,7 @@ public: App(::Context * context); InputViewController * inputViewController(); Context * globalContext(); + Context * evaluateContext(); private: FunctionStore m_functionStore; Context * m_globalContext; diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 20f74d949..aca0000dd 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -1,17 +1,26 @@ #include "graph_controller.h" +#include "../app.h" #include namespace Graph { -GraphController::GraphController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext) : +GraphController::GraphController(Responder * parentResponder, FunctionStore * functionStore) : HeaderViewController(parentResponder, &m_view), - m_view(GraphView(functionStore, evaluateContext)), + m_view(GraphView(functionStore)), m_headerSelected(false), m_windowButton(Button(this, "Fenetre", Invocation([](void * context, void * sender) {}, this))), m_displayButton(this, "Affichage", Invocation([](void * context, void * sender) {}, this)) { } +View * GraphController::view() { + if (m_view.context() == nullptr) { + App * graphApp = (Graph::App *)app(); + m_view.setContext(graphApp->evaluateContext()); + } + return HeaderViewController::view(); +} + const char * GraphController::title() const { return "Graphique"; } diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index 5a86e2b16..ccfd74203 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -4,14 +4,13 @@ #include #include "graph_view.h" #include "../function_store.h" -#include "../evaluate_context.h" namespace Graph { class GraphController : public HeaderViewController { public: - GraphController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext); + GraphController(Responder * parentResponder, FunctionStore * functionStore); const char * title() const override; - + View * view() override; bool handleEvent(Ion::Events::Event event) override; void didBecomeFirstResponder() override; diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index 99d550ddc..5ee5ba5b8 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -9,7 +9,7 @@ constexpr KDColor kSecondaryGridColor = KDColor(0xEEEEEE); constexpr int kNumberOfMainGridLines = 5; constexpr int kNumberOfSecondaryGridLines = 4; -GraphView::GraphView(FunctionStore * functionStore, EvaluateContext * evaluateContext) : +GraphView::GraphView(FunctionStore * functionStore) : #if GRAPH_VIEW_IS_TILED TiledView(), #else @@ -22,7 +22,7 @@ GraphView::GraphView(FunctionStore * functionStore, EvaluateContext * evaluateCo m_yMin(-2.0f), m_yMax(2.0f), m_functionStore(functionStore), - m_evaluateContext(evaluateContext) + m_evaluateContext(nullptr) { } @@ -34,6 +34,14 @@ View * GraphView::subviewAtIndex(int index) { return &m_cursorView; } +void GraphView::setContext(Context * context) { + m_evaluateContext = (EvaluateContext *)context; +} + +Context * GraphView::context() const { + return m_evaluateContext; +} + void GraphView::moveCursorRight() { KDPoint offset = KDPoint(2,0); m_cursorPosition = m_cursorPosition.translatedBy(offset); diff --git a/apps/graph/graph/graph_view.h b/apps/graph/graph/graph_view.h index 33c4a36da..429ece581 100644 --- a/apps/graph/graph/graph_view.h +++ b/apps/graph/graph/graph_view.h @@ -18,7 +18,7 @@ class GraphView : public #endif { public: - GraphView(FunctionStore * functionStore, EvaluateContext * evaluateContext); + GraphView(FunctionStore * functionStore); #if GRAPH_VIEW_IS_TILED KDColor * tile() const override; @@ -30,6 +30,8 @@ public: // void drawRect(KDRect rect) const override; void moveCursorRight(); + void setContext(Context * evaluateContext); + Context * context() const; private: int numberOfSubviews() const override; View * subviewAtIndex(int index) override; diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index a6ff6779b..b90742ae2 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -47,11 +47,10 @@ ValuesController::ContentView::TableState ValuesController::ContentView::tableSt /* Value Controller */ -ValuesController::ValuesController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext) : +ValuesController::ValuesController(Responder * parentResponder, FunctionStore * functionStore) : HeaderViewController(parentResponder, &m_contentView), m_selectableTableView(SelectableTableView(this, this, k_topMargin, k_rightMargin, k_bottomMargin, k_leftMargin)), m_functionStore(functionStore), - m_evaluateContext(evaluateContext), m_parameterController(ValuesParameterController(this, &m_interval)), m_abscissaParameterController(AbscissaParameterController(this, &m_parameterController)), m_functionParameterController(FunctionParameterController(this)), @@ -384,10 +383,11 @@ void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, in } Function * function = functionAtColumn(i); float x = m_interval.element(j-1); + App * graphApp = (Graph::App *)app(); if (isDerivativeColumn(i)) { - Float(function->approximateDerivative(x, m_evaluateContext)).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaForDerivativeNumberInScientificMode); + Float(function->approximateDerivative(x, (EvaluateContext *)graphApp->evaluateContext())).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaForDerivativeNumberInScientificMode); } else { - Float(function->evaluateAtAbscissa(x, m_evaluateContext)).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode); + Float(function->evaluateAtAbscissa(x, (EvaluateContext *)graphApp->evaluateContext())).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode); } myValueCell->setText(buffer); } diff --git a/apps/graph/values/values_controller.h b/apps/graph/values/values_controller.h index 8e85a7990..79760e5a6 100644 --- a/apps/graph/values/values_controller.h +++ b/apps/graph/values/values_controller.h @@ -3,7 +3,6 @@ #include #include "../function_store.h" -#include "../evaluate_context.h" #include "../function_title_cell.h" #include "value_cell.h" #include "title_cell.h" @@ -17,7 +16,7 @@ namespace Graph { class ValuesController : public HeaderViewController, public TableViewDataSource { public: - ValuesController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext); + ValuesController(Responder * parentResponder, FunctionStore * functionStore); int activeRow(); int activeColumn(); @@ -88,7 +87,6 @@ private: FunctionTitleCell m_functionTitleCells[k_maxNumberOfFunctions]; ValueCell m_floatCells[k_maxNumberOfCells]; FunctionStore * m_functionStore; - EvaluateContext * m_evaluateContext; Interval m_interval; ValuesParameterController m_parameterController; AbscissaParameterController m_abscissaParameterController;