diff --git a/apps/graph/Makefile b/apps/graph/Makefile index fd5a258a0..fab363194 100644 --- a/apps/graph/Makefile +++ b/apps/graph/Makefile @@ -12,6 +12,7 @@ app_objs += $(addprefix apps/graph/,\ graph/graph_controller.o\ graph/graph_controller_helper.o\ graph/graph_view.o\ + graph/integral_graph_controller.o\ graph/tangent_graph_controller.o\ list/list_controller.o\ values/derivative_parameter_controller.o\ diff --git a/apps/graph/graph/calculation_parameter_controller.cpp b/apps/graph/graph/calculation_parameter_controller.cpp index 3485d9b3f..e65c9b4fe 100644 --- a/apps/graph/graph/calculation_parameter_controller.cpp +++ b/apps/graph/graph/calculation_parameter_controller.cpp @@ -12,7 +12,8 @@ CalculationParameterController::CalculationParameterController(Responder * paren m_selectableTableView(this, this, 0, 1, Metric::CommonTopMargin, Metric::CommonRightMargin, Metric::CommonBottomMargin, Metric::CommonLeftMargin, this), m_function(nullptr), - m_tangentGraphController(nullptr, graphView, bannerView, range, cursor) + m_tangentGraphController(nullptr, graphView, bannerView, range, cursor), + m_integralGraphController(nullptr, graphView, range, cursor) { } @@ -31,19 +32,33 @@ void CalculationParameterController::didBecomeFirstResponder() { bool CalculationParameterController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::OK || event == Ion::Events::EXE) { + ViewController * controller = nullptr; switch(selectedRow()) { case 4: - { m_tangentGraphController.setFunction(m_function); - StackViewController * stack = (StackViewController *)parentResponder(); - stack->pop(); - stack->pop(); - stack->push(&m_tangentGraphController); - return true; - } + controller = &m_tangentGraphController; + break; + case 5: + m_integralGraphController.setFunction(m_function); + controller = &m_integralGraphController; + break; default: return false; } + // This is temporary (until the end of development of calculation menu) + if (controller == nullptr) { + return false; + } + StackViewController * stack = static_cast(parentResponder()); + stack->pop(); + stack->pop(); + stack->push(controller); + return true; + } + if (event == Ion::Events::Left) { + StackViewController * stack = static_cast(parentResponder()); + stack->pop(); + return true; } return false; } diff --git a/apps/graph/graph/calculation_parameter_controller.h b/apps/graph/graph/calculation_parameter_controller.h index 0ef3b9657..89fd9f0b5 100644 --- a/apps/graph/graph/calculation_parameter_controller.h +++ b/apps/graph/graph/calculation_parameter_controller.h @@ -4,6 +4,7 @@ #include #include "../cartesian_function.h" #include "tangent_graph_controller.h" +#include "integral_graph_controller.h" #include "graph_view.h" #include "banner_view.h" #include "../../i18n.h" @@ -29,6 +30,7 @@ private: SelectableTableView m_selectableTableView; CartesianFunction * m_function; TangentGraphController m_tangentGraphController; + IntegralGraphController m_integralGraphController; }; } diff --git a/apps/graph/graph/integral_graph_controller.cpp b/apps/graph/graph/integral_graph_controller.cpp new file mode 100644 index 000000000..e6c61f05c --- /dev/null +++ b/apps/graph/graph/integral_graph_controller.cpp @@ -0,0 +1,38 @@ +#include "integral_graph_controller.h" +#include "../../shared/text_field_delegate.h" +#include "../app.h" + +#include +#include +#include + +using namespace Shared; +using namespace Poincare; + +namespace Graph { + +IntegralGraphController::IntegralGraphController(Responder * parentResponder, GraphView * graphView, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor) : + SumGraphController(parentResponder, graphView, graphRange, cursor, Ion::Charset::Integral) +{ +} + +const char * IntegralGraphController::title() { + return I18n::translate(I18n::Message::Integral); +} + +I18n::Message IntegralGraphController::legendMessageAtStep(Step step) { + switch(step) { + case Step::FirstParameter: + return I18n::Message::SelectLowerBound; + case Step::SecondParameter: + return I18n::Message::SelectUpperBound; + default: + return I18n::Message::Default; + } +} + +double IntegralGraphController::cursorNextStep(double x, int direction) { + return (direction > 0 ? x + m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit : x - m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit); +} + +} diff --git a/apps/graph/graph/integral_graph_controller.h b/apps/graph/graph/integral_graph_controller.h new file mode 100644 index 000000000..d6a654402 --- /dev/null +++ b/apps/graph/graph/integral_graph_controller.h @@ -0,0 +1,21 @@ +#ifndef GRAPH_INTEGRAL_GRAPH_CONTROLLER_H +#define GRAPH_INTEGRAL_GRAPH_CONTROLLER_H + +#include +#include "graph_view.h" +#include "../../shared/sum_graph_controller.h" + +namespace Graph { + +class IntegralGraphController : public Shared::SumGraphController { +public: + IntegralGraphController(Responder * parentResponder, GraphView * graphView, Shared::InteractiveCurveViewRange * graphRange, Shared::CurveViewCursor * cursor); + const char * title() override; +private: + I18n::Message legendMessageAtStep(Step step) override; + double cursorNextStep(double position, int direction) override; +}; + +} + +#endif diff --git a/apps/shared/sum_graph_controller.cpp b/apps/shared/sum_graph_controller.cpp index f9e75a4ac..a9d2826ad 100644 --- a/apps/shared/sum_graph_controller.cpp +++ b/apps/shared/sum_graph_controller.cpp @@ -19,9 +19,9 @@ SumGraphController::SumGraphController(Responder * parentResponder, FunctionGrap m_startSum(NAN), m_endSum(NAN), m_function(nullptr), + m_graphRange(range), m_graphView(graphView), m_legendView(this, sumSymbol), - m_graphRange(range), m_cursorView() { } diff --git a/apps/shared/sum_graph_controller.h b/apps/shared/sum_graph_controller.h index 699e458f7..93bf4bda1 100644 --- a/apps/shared/sum_graph_controller.h +++ b/apps/shared/sum_graph_controller.h @@ -33,6 +33,7 @@ protected: double m_startSum; double m_endSum; Function * m_function; + InteractiveCurveViewRange * m_graphRange; private: constexpr static float k_cursorTopMarginRatio = 0.07f; // (cursorHeight/2)/graphViewHeight constexpr static float k_cursorRightMarginRatio = 0.04f; // (cursorWidth/2)/graphViewWidth @@ -79,7 +80,6 @@ private: }; FunctionGraphView * m_graphView; LegendView m_legendView; - InteractiveCurveViewRange * m_graphRange; VerticalCursorView m_cursorView; };