mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/sequence] create a class grpah controller
Change-Id: Iaf9e9c03bd4b9946cddaefb14af5e014075ee109
This commit is contained in:
@@ -3,6 +3,7 @@ app_objs += $(addprefix apps/sequence/,\
|
||||
graph/banner_view.o\
|
||||
graph/curve_parameter_controller.o\
|
||||
graph/curve_view_range.o\
|
||||
graph/graph_controller.o\
|
||||
graph/graph_view.o\
|
||||
list/list_controller.o\
|
||||
list/list_parameter_controller.o\
|
||||
|
||||
@@ -14,7 +14,7 @@ App::App(Container * container, Context * context) :
|
||||
m_listStackViewController(StackViewController(&m_tabViewController, &m_listHeader)),
|
||||
m_graphController(&m_graphAlternateEmptyViewController, &m_sequenceStore, &m_graphHeader),
|
||||
m_graphAlternateEmptyViewController(AlternateEmptyViewController(&m_graphHeader, &m_graphController, &m_graphController)),
|
||||
m_graphHeader(HeaderViewController(nullptr, &m_graphAlternateEmptyViewController, &m_graphController)),
|
||||
m_graphHeader(HeaderViewController(&m_graphStackViewController, &m_graphAlternateEmptyViewController, &m_graphController)),
|
||||
m_graphStackViewController(StackViewController(&m_tabViewController, &m_graphHeader)),
|
||||
m_valuesController(&m_valuesAlternateEmptyViewController, &m_sequenceStore, &m_valuesHeader),
|
||||
m_valuesAlternateEmptyViewController(AlternateEmptyViewController(&m_valuesHeader, &m_valuesController, &m_valuesController)),
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <poincare.h>
|
||||
#include "local_context.h"
|
||||
#include "sequence_store.h"
|
||||
#include "graph/graph_controller.h"
|
||||
#include "list/list_controller.h"
|
||||
#include "values/values_controller.h"
|
||||
#include "../shared/text_field_delegate_app.h"
|
||||
@@ -23,7 +24,7 @@ private:
|
||||
ListController m_listController;
|
||||
HeaderViewController m_listHeader;
|
||||
StackViewController m_listStackViewController;
|
||||
ValuesController m_graphController;
|
||||
GraphController m_graphController;
|
||||
AlternateEmptyViewController m_graphAlternateEmptyViewController;
|
||||
HeaderViewController m_graphHeader;
|
||||
StackViewController m_graphStackViewController;
|
||||
|
||||
73
apps/sequence/graph/graph_controller.cpp
Normal file
73
apps/sequence/graph/graph_controller.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "graph_controller.h"
|
||||
|
||||
using namespace Shared;
|
||||
|
||||
namespace Sequence {
|
||||
|
||||
GraphController::GraphController(Responder * parentResponder, SequenceStore * sequenceStore, HeaderViewController * header) :
|
||||
FunctionGraphController(parentResponder, header, &m_graphRange, &m_view),
|
||||
m_bannerView(BannerView()),
|
||||
m_view(GraphView(sequenceStore, &m_graphRange, &m_cursor, &m_bannerView, &m_cursorView)),
|
||||
m_graphRange(CurveViewRange(&m_cursor, this)),
|
||||
m_curveParameterController(CurveParameterController(&m_graphRange, &m_cursor)),
|
||||
m_sequenceStore(sequenceStore)
|
||||
{
|
||||
}
|
||||
|
||||
const char * GraphController::emptyMessage() {
|
||||
if (m_sequenceStore->numberOfDefinedFunctions() == 0) {
|
||||
return "Aucune suite";
|
||||
}
|
||||
return "Aucune suite activee";
|
||||
}
|
||||
|
||||
BannerView * GraphController::bannerView() {
|
||||
return &m_bannerView;
|
||||
}
|
||||
|
||||
bool GraphController::moveCursorHorizontally(int direction) {
|
||||
float xCursorPosition = roundf(m_cursor.x());
|
||||
if (direction < 0 && xCursorPosition <= 0) {
|
||||
return false;
|
||||
}
|
||||
float x = direction > 0 ? xCursorPosition + 1.0f :
|
||||
xCursorPosition - 1.0f;
|
||||
Sequence * s = m_sequenceStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
|
||||
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
|
||||
float y = s->evaluateAtAbscissa(x, myApp->localContext());
|
||||
m_cursor.moveTo(x, y);
|
||||
m_graphRange.panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
|
||||
return true;
|
||||
}
|
||||
|
||||
void GraphController::initCursorParameters() {
|
||||
float x = roundf((interactiveCurveViewRange()->xMin()+interactiveCurveViewRange()->xMax())/2.0f);
|
||||
m_indexFunctionSelectedByCursor = 0;
|
||||
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
|
||||
int functionIndex = 0;
|
||||
float y = 0;
|
||||
do {
|
||||
Sequence * firstFunction = m_sequenceStore->activeFunctionAtIndex(functionIndex++);
|
||||
y = firstFunction->evaluateAtAbscissa(x, myApp->localContext());
|
||||
} while (isnan(y) && functionIndex < m_sequenceStore->numberOfActiveFunctions());
|
||||
m_cursor.moveTo(x, y);
|
||||
m_graphRange.panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
|
||||
}
|
||||
|
||||
CurveViewRange * GraphController::interactiveCurveViewRange() {
|
||||
return &m_graphRange;
|
||||
}
|
||||
|
||||
SequenceStore * GraphController::functionStore() const {
|
||||
return m_sequenceStore;
|
||||
}
|
||||
|
||||
GraphView * GraphController::functionGraphView() {
|
||||
return &m_view;
|
||||
}
|
||||
|
||||
CurveParameterController * GraphController::curveParameterController() {
|
||||
return &m_curveParameterController;
|
||||
}
|
||||
|
||||
}
|
||||
35
apps/sequence/graph/graph_controller.h
Normal file
35
apps/sequence/graph/graph_controller.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef SEQUENCE_GRAPH_CONTROLLER_H
|
||||
#define SEQUENCE_GRAPH_CONTROLLER_H
|
||||
|
||||
#include "graph_view.h"
|
||||
#include "banner_view.h"
|
||||
#include "curve_parameter_controller.h"
|
||||
#include "curve_view_range.h"
|
||||
#include "../../shared/function_graph_controller.h"
|
||||
#include "../sequence_store.h"
|
||||
|
||||
namespace Sequence {
|
||||
|
||||
class GraphController : public Shared::FunctionGraphController {
|
||||
public:
|
||||
GraphController(Responder * parentResponder, SequenceStore * sequenceStore, HeaderViewController * header);
|
||||
const char * emptyMessage() override;
|
||||
private:
|
||||
BannerView * bannerView() override;
|
||||
bool moveCursorHorizontally(int direction) override;
|
||||
void initCursorParameters() override;
|
||||
CurveViewRange * interactiveCurveViewRange() override;
|
||||
SequenceStore * functionStore() const override;
|
||||
GraphView * functionGraphView() override;
|
||||
CurveParameterController * curveParameterController() override;
|
||||
BannerView m_bannerView;
|
||||
GraphView m_view;
|
||||
CurveViewRange m_graphRange;
|
||||
CurveParameterController m_curveParameterController;
|
||||
SequenceStore * m_sequenceStore;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user