From 85abdbcafb3abfd7591698df40fef6c4dec8d56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 9 Jan 2018 11:52:29 +0100 Subject: [PATCH] [apps] Shared: Break function_graph_controller into 2 classes: function_banner_delegate and function_graph_controller --- apps/regression/graph_controller.cpp | 4 --- apps/regression/graph_controller.h | 1 - apps/shared/Makefile | 1 + apps/shared/function_banner_delegate.cpp | 36 +++++++++++++++++++ apps/shared/function_banner_delegate.h | 20 +++++++++++ apps/shared/function_graph_controller.cpp | 27 +------------- apps/shared/function_graph_controller.h | 7 ++-- .../interactive_curve_view_controller.h | 2 -- 8 files changed, 61 insertions(+), 37 deletions(-) create mode 100644 apps/shared/function_banner_delegate.cpp create mode 100644 apps/shared/function_banner_delegate.h diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp index 70bb504b0..1599cd686 100644 --- a/apps/regression/graph_controller.cpp +++ b/apps/regression/graph_controller.cpp @@ -41,10 +41,6 @@ void GraphController::selectRegressionCurve() { *m_selectedDotIndex = -1; } -BannerView * GraphController::bannerView() { - return &m_bannerView; -} - CurveView * GraphController::curveView() { return &m_view; } diff --git a/apps/regression/graph_controller.h b/apps/regression/graph_controller.h index 5181f7382..8cf4a6bc6 100644 --- a/apps/regression/graph_controller.h +++ b/apps/regression/graph_controller.h @@ -27,7 +27,6 @@ private: constexpr static float k_cursorLeftMarginRatio = 0.04f; // (cursorWidth/2)/graphViewWidth constexpr static int k_maxLegendLength = 16; constexpr static int k_maxNumberOfCharacters = 50; - BannerView * bannerView() override; Shared::CurveView * curveView() override; Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override; bool handleEnter() override; diff --git a/apps/shared/Makefile b/apps/shared/Makefile index 080529995..3fabe4a8f 100644 --- a/apps/shared/Makefile +++ b/apps/shared/Makefile @@ -10,6 +10,7 @@ app_objs += $(addprefix apps/shared/,\ float_parameter_controller.o\ function.o\ function_app.o\ + function_banner_delegate.o\ function_curve_parameter_controller.o\ function_go_to_parameter_controller.o\ function_graph_view.o\ diff --git a/apps/shared/function_banner_delegate.cpp b/apps/shared/function_banner_delegate.cpp new file mode 100644 index 000000000..45060630c --- /dev/null +++ b/apps/shared/function_banner_delegate.cpp @@ -0,0 +1,36 @@ +#include "function_banner_delegate.h" +#include "../constant.h" + +using namespace Poincare; + +namespace Shared { + +void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Function * function, char symbol) { + char buffer[k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)]; + const char * space = " "; + int spaceLength = strlen(space); + const char * legend = "0="; + int legendLength = strlen(legend); + int numberOfChar = 0; + strlcpy(buffer, legend, legendLength+1); + numberOfChar += legendLength; + buffer[0] = symbol; + numberOfChar += Complex::convertFloatToText(cursor->x(), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); + strlcpy(buffer+numberOfChar, space, spaceLength+1); + buffer[k_maxLegendLength] = 0; + bannerView()->setLegendAtIndex(buffer, 0); + + numberOfChar = 0; + legend = "0(x)="; + legendLength = strlen(legend); + numberOfChar += legendLength; + strlcpy(buffer, legend, legendLength+1); + buffer[2] = symbol; + buffer[0] = function->name()[0]; + numberOfChar += Complex::convertFloatToText(cursor->y(), buffer+legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); + strlcpy(buffer+numberOfChar, space, spaceLength+1); + buffer[k_maxLegendLength] = 0; + bannerView()->setLegendAtIndex(buffer, 1); +} + +} diff --git a/apps/shared/function_banner_delegate.h b/apps/shared/function_banner_delegate.h new file mode 100644 index 000000000..7811f9074 --- /dev/null +++ b/apps/shared/function_banner_delegate.h @@ -0,0 +1,20 @@ +#ifndef SHARED_FUNCTION_BANNER_DELEGATE_H +#define SHARED_FUNCTION_BANNER_DELEGATE_H + +#include "function_store.h" +#include "banner_view.h" +#include "curve_view_cursor.h" + +namespace Shared { + +class FunctionBannerDelegate { +protected: + constexpr static int k_maxLegendLength = 14; + constexpr static int k_maxNumberOfCharacters = 50; + void reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Function * function, char symbol); + virtual BannerView * bannerView() = 0; +}; + +} + +#endif diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index 04fd053af..1f743c86f 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -49,36 +49,11 @@ bool FunctionGraphController::handleEnter() { } void FunctionGraphController::reloadBannerView() { - char buffer[k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)]; - const char * space = " "; - int spaceLength = strlen(space); - const char * legend = "0="; - int legendLength = strlen(legend); - int numberOfChar = 0; - strlcpy(buffer, legend, legendLength+1); - numberOfChar += legendLength; - buffer[0] = functionStore()->symbol(); - numberOfChar += Complex::convertFloatToText(m_cursor->x(), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); - strlcpy(buffer+numberOfChar, space, spaceLength+1); - buffer[k_maxLegendLength] = 0; - bannerView()->setLegendAtIndex(buffer, 0); - - numberOfChar = 0; - legend = "0(x)="; - legendLength = strlen(legend); - numberOfChar += legendLength; - strlcpy(buffer, legend, legendLength+1); - buffer[2] = functionStore()->symbol(); if (functionStore()->numberOfActiveFunctions() == 0) { return; } - assert(m_indexFunctionSelectedByCursor < functionStore()->numberOfActiveFunctions()); Function * f = functionStore()->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); - buffer[0] = f->name()[0]; - numberOfChar += Complex::convertFloatToText(m_cursor->y(), buffer+legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); - strlcpy(buffer+numberOfChar, space, spaceLength+1); - buffer[k_maxLegendLength] = 0; - bannerView()->setLegendAtIndex(buffer, 1); + reloadBannerViewForCursorOnFunction(m_cursor, f, functionStore()->symbol()); } InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange(InteractiveCurveViewRange * interactiveCurveViewRange) { diff --git a/apps/shared/function_graph_controller.h b/apps/shared/function_graph_controller.h index e0f2f97f5..fb9888bee 100644 --- a/apps/shared/function_graph_controller.h +++ b/apps/shared/function_graph_controller.h @@ -3,6 +3,7 @@ #include #include "initialisation_parameter_controller.h" +#include "function_banner_delegate.h" #include "interactive_curve_view_controller.h" #include "function_store.h" #include "function_graph_view.h" @@ -10,7 +11,7 @@ namespace Shared { -class FunctionGraphController : public InteractiveCurveViewController, public InteractiveCurveViewRangeDelegate { +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); bool isEmpty() const override; @@ -21,8 +22,6 @@ protected: constexpr static float k_cursorRightMarginRatio = 0.04f; // (cursorWidth/2)/graphViewWidth constexpr static float k_cursorBottomMarginRatio = 0.15f; // (cursorHeight/2+bannerHeigh)/graphViewHeight constexpr static float k_cursorLeftMarginRatio = 0.04f; // (cursorWidth/2)/graphViewWidth - constexpr static int k_maxLegendLength = 14; - constexpr static int k_maxNumberOfCharacters = 50; void reloadBannerView() override; bool handleEnter() override; int m_indexFunctionSelectedByCursor; @@ -41,8 +40,8 @@ private: uint32_t modelVersion() override; uint32_t rangeVersion() override; bool isCursorVisible() override; - virtual FunctionStore * functionStore() const = 0; virtual FunctionGraphView * functionGraphView() = 0; + virtual FunctionStore * functionStore() const = 0; virtual FunctionCurveParameterController * curveParameterController() = 0; InitialisationParameterController m_initialisationParameterController; Poincare::Expression::AngleUnit * m_angleUnitVersion; diff --git a/apps/shared/interactive_curve_view_controller.h b/apps/shared/interactive_curve_view_controller.h index 2cd5301a2..6ea425278 100644 --- a/apps/shared/interactive_curve_view_controller.h +++ b/apps/shared/interactive_curve_view_controller.h @@ -4,7 +4,6 @@ #include "simple_interactive_curve_view_controller.h" #include "cursor_view.h" #include "ok_view.h" -#include "banner_view.h" #include "range_parameter_controller.h" #include "zoom_parameter_controller.h" @@ -31,7 +30,6 @@ public: void didEnterResponderChain(Responder * previousFirstResponder) override; void willExitResponderChain(Responder * nextFirstResponder) override; protected: - virtual BannerView * bannerView() = 0; virtual bool handleEnter() = 0; Responder * tabController() const; virtual StackViewController * stackController() const;