[apps] Shared: Break function_graph_controller into 2 classes: function_banner_delegate and function_graph_controller

This commit is contained in:
Émilie Feral
2018-01-09 11:52:29 +01:00
committed by EmilieNumworks
parent 3a1d652a07
commit 85abdbcafb
8 changed files with 61 additions and 37 deletions

View File

@@ -41,10 +41,6 @@ void GraphController::selectRegressionCurve() {
*m_selectedDotIndex = -1;
}
BannerView * GraphController::bannerView() {
return &m_bannerView;
}
CurveView * GraphController::curveView() {
return &m_view;
}

View File

@@ -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;

View File

@@ -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\

View File

@@ -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<float>::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<float>::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);
}
}

View File

@@ -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

View File

@@ -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<float>::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<float>::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) {

View File

@@ -3,6 +3,7 @@
#include <escher.h>
#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;

View File

@@ -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;