diff --git a/apps/graph/Makefile b/apps/graph/Makefile index f9e70f98e..8dedf6855 100644 --- a/apps/graph/Makefile +++ b/apps/graph/Makefile @@ -22,6 +22,7 @@ app_objs += $(addprefix apps/graph/,\ graph/storage_calculation_parameter_controller.o\ graph/storage_curve_parameter_controller.o\ graph/storage_graph_controller.o\ + graph/storage_graph_controller_helper.o\ graph/storage_graph_view.o\ graph/storage_intersection_graph_controller.o\ graph/storage_tangent_graph_controller.o\ diff --git a/apps/graph/graph/storage_graph_controller.cpp b/apps/graph/graph/storage_graph_controller.cpp index 29b2e7e67..7b5f81563 100644 --- a/apps/graph/graph/storage_graph_controller.cpp +++ b/apps/graph/graph/storage_graph_controller.cpp @@ -75,7 +75,7 @@ void StorageGraphController::reloadBannerView() { bool StorageGraphController::moveCursorHorizontally(int direction) { StorageCartesianFunction f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); - return true; //TODO privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, &f, myApp, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); + return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, &f, myApp, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); } InteractiveCurveViewRange * StorageGraphController::interactiveCurveViewRange() { diff --git a/apps/graph/graph/storage_graph_controller.h b/apps/graph/graph/storage_graph_controller.h index a21f10dd8..225f7c415 100644 --- a/apps/graph/graph/storage_graph_controller.h +++ b/apps/graph/graph/storage_graph_controller.h @@ -1,9 +1,9 @@ #ifndef GRAPH_STORAGE_GRAPH_CONTROLLER_H #define GRAPH_STORAGE_GRAPH_CONTROLLER_H -#include "graph_controller_helper.h" #include "banner_view.h" #include "storage_curve_parameter_controller.h" +#include "storage_graph_controller_helper.h" #include "storage_graph_view.h" #include "../../shared/storage_function_graph_controller.h" #include "../../shared/curve_view_cursor.h" @@ -13,7 +13,7 @@ namespace Graph { -class StorageGraphController : public Shared::StorageFunctionGraphController, public GraphControllerHelper { +class StorageGraphController : public Shared::StorageFunctionGraphController, public StorageGraphControllerHelper { public: StorageGraphController(Responder * parentResponder, StorageCartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header); I18n::Message emptyMessage() override; diff --git a/apps/graph/graph/storage_graph_controller_helper.cpp b/apps/graph/graph/storage_graph_controller_helper.cpp new file mode 100644 index 000000000..0a4dc93a8 --- /dev/null +++ b/apps/graph/graph/storage_graph_controller_helper.cpp @@ -0,0 +1,35 @@ +#include "storage_graph_controller_helper.h" +#include "../../constant.h" +#include "../../shared/poincare_helpers.h" + +using namespace Shared; +using namespace Poincare; + +namespace Graph { + +bool StorageGraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, StorageCartesianFunction * function, Shared::TextFieldDelegateApp * app, float cursorTopMarginRatio, float cursorRightMarginRatio, float cursorBottomMarginRatio, float cursorLeftMarginRatio) { + double xCursorPosition = cursor->x(); + double x = direction > 0 ? xCursorPosition + range->xGridUnit()/numberOfStepsInGradUnit : xCursorPosition - range->xGridUnit()/numberOfStepsInGradUnit; + double y = function->evaluateAtAbscissa(x, app->localContext()); + cursor->moveTo(x, y); + range->panToMakePointVisible(x, y, cursorTopMarginRatio, cursorRightMarginRatio, cursorBottomMarginRatio, cursorLeftMarginRatio); + return true; +} + +void StorageGraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, StorageCartesianFunction * function, TextFieldDelegateApp * app) { + char buffer[StorageFunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)]; + const char * space = " "; + int spaceLength = strlen(space); + const char * legend = "00(x)="; + int legendLength = strlen(legend); + int numberOfChar = strlcpy(buffer, legend, legendLength+1); + buffer[0] = function->name()[0]; + buffer[1] = '\''; + double y = function->approximateDerivative(cursor->x(), app->localContext()); + numberOfChar += PoincareHelpers::ConvertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits); + strlcpy(buffer+numberOfChar, space, spaceLength+1); + buffer[k_maxDigitLegendLength+6] = 0; + bannerView()->setLegendAtIndex(buffer, 2); +} + +} diff --git a/apps/graph/graph/storage_graph_controller_helper.h b/apps/graph/graph/storage_graph_controller_helper.h new file mode 100644 index 000000000..e7ce787e0 --- /dev/null +++ b/apps/graph/graph/storage_graph_controller_helper.h @@ -0,0 +1,21 @@ +#ifndef GRAPH_STORAGE_GRAPH_CONTROLLER_HELPER_H +#define GRAPH_STORAGE_GRAPH_CONTROLLER_HELPER_H + +#include "../../shared/storage_function_banner_delegate.h" +#include "../../shared/text_field_delegate_app.h" +#include "../../shared/interactive_curve_view_range.h" +#include "../storage_cartesian_function.h" + +namespace Graph { + +class StorageGraphControllerHelper { +protected: + constexpr static int k_maxDigitLegendLength = 10; + bool privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, StorageCartesianFunction * function, Shared::TextFieldDelegateApp * app, float cursorTopMarginRatio, float cursorRightMarginRatio, float cursorBottomMarginRatio, float cursorLeftMarginRatio); + void reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, StorageCartesianFunction * function, Shared::TextFieldDelegateApp * app); + virtual Shared::BannerView * bannerView() = 0; +}; + +} + +#endif