[apps/sequence][apps/regression][apps/graph] Move ranges and cursor in

snapshot

Change-Id: I3e5a163ae4b3a6860969ef12d939513cffed7710
This commit is contained in:
Émilie Feral
2017-05-18 09:47:44 +02:00
parent 197e296474
commit 6b2ae04a13
19 changed files with 132 additions and 74 deletions

View File

@@ -20,6 +20,13 @@ const Image * App::Descriptor::icon() {
return ImageStore::GraphIcon;
}
App::Snapshot::Snapshot() :
m_functionStore(),
m_graphRange(&m_cursor),
m_cursor()
{
}
App * App::Snapshot::unpack(Container * container) {
return new App(container, this);
}
@@ -37,6 +44,14 @@ CartesianFunctionStore * App::Snapshot::functionStore() {
return &m_functionStore;
}
InteractiveCurveViewRange * App::Snapshot::graphRange() {
return &m_graphRange;
}
CurveViewCursor * App::Snapshot::cursor() {
return &m_cursor;
}
void App::Snapshot::tidy() {
m_functionStore.tidy();
}
@@ -48,7 +63,7 @@ App::App(Container * container, Snapshot * snapshot) :
m_listFooter(&m_listHeader, &m_listController, &m_listController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey),
m_listHeader(&m_listStackViewController, &m_listFooter, &m_listController),
m_listStackViewController(&m_tabViewController, &m_listHeader),
m_graphController(&m_graphAlternateEmptyViewController, snapshot->functionStore(), &m_graphHeader),
m_graphController(&m_graphAlternateEmptyViewController, snapshot->functionStore(), snapshot->graphRange(), snapshot->cursor(), &m_graphHeader),
m_graphAlternateEmptyViewController(&m_graphHeader, &m_graphController, &m_graphController),
m_graphHeader(&m_graphStackViewController, &m_graphAlternateEmptyViewController, &m_graphController),
m_graphStackViewController(&m_tabViewController, &m_graphHeader),

View File

@@ -21,13 +21,18 @@ public:
};
class Snapshot : public ::App::Snapshot {
public:
Snapshot();
App * unpack(Container * container) override;
void reset() override;
Descriptor * descriptor() override;
CartesianFunctionStore * functionStore();
Shared::InteractiveCurveViewRange * graphRange();
Shared::CurveViewCursor * cursor();
private:
void tidy() override;
CartesianFunctionStore m_functionStore;
Shared::InteractiveCurveViewRange m_graphRange;
Shared::CurveViewCursor m_cursor;
};
InputViewController * inputViewController() override;
/* This local context can parse x. However, it always stores NAN

View File

@@ -5,14 +5,15 @@ using namespace Poincare;
namespace Graph {
GraphController::GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, ButtonRowController * header) :
FunctionGraphController(parentResponder, header, &m_graphRange, &m_view),
GraphController::GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, ButtonRowController * header) :
FunctionGraphController(parentResponder, header, curveViewRange, &m_view, cursor),
m_bannerView(),
m_view(functionStore, &m_graphRange, &m_cursor, &m_bannerView, &m_cursorView),
m_graphRange(&m_cursor, this),
m_curveParameterController(&m_graphRange, &m_bannerView, &m_cursor),
m_view(functionStore, curveViewRange, m_cursor, &m_bannerView, &m_cursorView),
m_graphRange(curveViewRange),
m_curveParameterController(curveViewRange, &m_bannerView, m_cursor),
m_functionStore(functionStore)
{
m_graphRange->setDelegate(this);
}
I18n::Message GraphController::emptyMessage() {
@@ -42,20 +43,20 @@ void GraphController::reloadBannerView() {
buffer[0] = f->name()[0];
buffer[1] = '\'';
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
float y = f->approximateDerivative(m_cursor.x(), myApp->localContext());
float y = f->approximateDerivative(m_cursor->x(), myApp->localContext());
Complex::convertFloatToText(y, buffer + legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
m_bannerView.setLegendAtIndex(buffer, 2);
}
bool GraphController::moveCursorHorizontally(int direction) {
float xCursorPosition = m_cursor.x();
float x = direction > 0 ? xCursorPosition + m_graphRange.xGridUnit()/k_numberOfCursorStepsInGradUnit :
xCursorPosition - m_graphRange.xGridUnit()/k_numberOfCursorStepsInGradUnit;
float xCursorPosition = m_cursor->x();
float x = direction > 0 ? xCursorPosition + m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit :
xCursorPosition - m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit;
CartesianFunction * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
float y = f->evaluateAtAbscissa(x, myApp->localContext());
m_cursor.moveTo(x, y);
m_graphRange.panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
m_cursor->moveTo(x, y);
m_graphRange->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
return true;
}
@@ -69,12 +70,12 @@ void GraphController::initCursorParameters() {
CartesianFunction * firstFunction = functionStore()->activeFunctionAtIndex(functionIndex++);
y = firstFunction->evaluateAtAbscissa(x, myApp->localContext());
} while (isnan(y) && functionIndex < functionStore()->numberOfActiveFunctions());
m_cursor.moveTo(x, y);
m_cursor->moveTo(x, y);
interactiveCurveViewRange()->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
}
InteractiveCurveViewRange * GraphController::interactiveCurveViewRange() {
return &m_graphRange;
return m_graphRange;
}
CartesianFunctionStore * GraphController::functionStore() const {

View File

@@ -5,13 +5,15 @@
#include "banner_view.h"
#include "curve_parameter_controller.h"
#include "../../shared/function_graph_controller.h"
#include "../../shared/curve_view_cursor.h"
#include "../../shared/interactive_curve_view_range.h"
#include "../cartesian_function_store.h"
namespace Graph {
class GraphController : public Shared::FunctionGraphController {
public:
GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, ButtonRowController * header);
GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, ButtonRowController * header);
I18n::Message emptyMessage() override;
private:
BannerView * bannerView() override;
@@ -24,7 +26,7 @@ private:
CurveParameterController * curveParameterController() override;
BannerView m_bannerView;
GraphView m_view;
Shared::InteractiveCurveViewRange m_graphRange;
Shared::InteractiveCurveViewRange * m_graphRange;
CurveParameterController m_curveParameterController;
CartesianFunctionStore * m_functionStore;
};

View File

@@ -35,12 +35,16 @@ Store * App::Snapshot::store() {
return &m_store;
}
CurveViewCursor * App::Snapshot::cursor() {
return &m_cursor;
}
App::App(Container * container, Snapshot * snapshot) :
TextFieldDelegateApp(container, snapshot, &m_tabViewController),
m_calculationController(&m_calculationAlternateEmptyViewController, &m_calculationHeader, snapshot->store()),
m_calculationAlternateEmptyViewController(&m_calculationHeader, &m_calculationController, &m_calculationController),
m_calculationHeader(&m_tabViewController, &m_calculationAlternateEmptyViewController, &m_calculationController),
m_graphController(&m_graphAlternateEmptyViewController, &m_graphHeader, snapshot->store()),
m_graphController(&m_graphAlternateEmptyViewController, &m_graphHeader, snapshot->store(), snapshot->cursor()),
m_graphAlternateEmptyViewController(&m_graphHeader, &m_graphController, &m_graphController),
m_graphHeader(&m_graphStackViewController, &m_graphAlternateEmptyViewController, &m_graphController),
m_graphStackViewController(&m_tabViewController, &m_graphHeader),

View File

@@ -24,9 +24,11 @@ public:
void reset() override;
Descriptor * descriptor() override;
Store * store();
Shared::CurveViewCursor * cursor();
private:
Store m_store;
};
Shared::CurveViewCursor m_cursor;
};
private:
App(Container * container, Snapshot * snapshot);
CalculationController m_calculationController;

View File

@@ -6,16 +6,16 @@ using namespace Shared;
namespace Regression {
GraphController::GraphController(Responder * parentResponder, ButtonRowController * header, Store * store) :
InteractiveCurveViewController(parentResponder, header, store, &m_view),
GraphController::GraphController(Responder * parentResponder, ButtonRowController * header, Store * store, CurveViewCursor * cursor) :
InteractiveCurveViewController(parentResponder, header, store, &m_view, cursor),
m_bannerView(),
m_view(store, &m_cursor, &m_bannerView, &m_cursorView),
m_view(store, m_cursor, &m_bannerView, &m_cursorView),
m_store(store),
m_initialisationParameterController(this, m_store),
m_predictionParameterController(this, m_store, &m_cursor),
m_predictionParameterController(this, m_store, m_cursor),
m_selectedDotIndex(-1)
{
m_store->setCursor(&m_cursor);
m_store->setCursor(m_cursor);
}
ViewController * GraphController::initialisationParameterController() {
@@ -84,7 +84,7 @@ void GraphController::reloadBannerView() {
numberOfChar = 0;
legend = " x=";
float x = m_cursor.x();
float x = m_cursor->x();
// Display a specific legend if the mean dot is selected
if (m_selectedDotIndex == m_store->numberOfPairs()) {
constexpr static char legX[] = {Ion::Charset::XBar, ' ', '=', ' ', 0};
@@ -103,7 +103,7 @@ void GraphController::reloadBannerView() {
numberOfChar = 0;
legend = " y=";
float y = m_cursor.y();
float y = m_cursor->y();
if (m_selectedDotIndex == m_store->numberOfPairs()) {
constexpr static char legY[] = {Ion::Charset::YBar, ' ', '=', ' ', 0};
legend = legY;
@@ -127,7 +127,7 @@ void GraphController::initRangeParameters() {
void GraphController::initCursorParameters() {
float x = (m_store->xMin() + m_store->xMax())/2.0f;
float y = m_store->yValueForXValue(x);
m_cursor.moveTo(x, y);
m_cursor->moveTo(x, y);
m_store->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
m_selectedDotIndex = -1;
}
@@ -137,49 +137,49 @@ bool GraphController::moveCursorHorizontally(int direction) {
int dotSelected = m_store->nextDot(direction, m_selectedDotIndex);
if (dotSelected >= 0 && dotSelected < m_store->numberOfPairs()) {
m_selectedDotIndex = dotSelected;
m_cursor.moveTo(m_store->get(0, m_selectedDotIndex), m_store->get(1, m_selectedDotIndex));
m_store->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
m_cursor->moveTo(m_store->get(0, m_selectedDotIndex), m_store->get(1, m_selectedDotIndex));
m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
return true;
}
if (dotSelected == m_store->numberOfPairs()) {
m_selectedDotIndex = dotSelected;
m_cursor.moveTo(m_store->meanOfColumn(0), m_store->meanOfColumn(1));
m_store->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
m_cursor->moveTo(m_store->meanOfColumn(0), m_store->meanOfColumn(1));
m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
return true;
}
return false;
}
float x = direction > 0 ? m_cursor.x() + m_store->xGridUnit()/k_numberOfCursorStepsInGradUnit :
m_cursor.x() - m_store->xGridUnit()/k_numberOfCursorStepsInGradUnit;
float x = direction > 0 ? m_cursor->x() + m_store->xGridUnit()/k_numberOfCursorStepsInGradUnit :
m_cursor->x() - m_store->xGridUnit()/k_numberOfCursorStepsInGradUnit;
float y = m_store->yValueForXValue(x);
m_cursor.moveTo(x, y);
m_cursor->moveTo(x, y);
m_store->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
return true;
}
bool GraphController::moveCursorVertically(int direction) {
float yRegressionCurve = m_store->yValueForXValue(m_cursor.x());
float yRegressionCurve = m_store->yValueForXValue(m_cursor->x());
if (m_selectedDotIndex >= 0) {
if ((yRegressionCurve - m_cursor.y() > 0) == (direction > 0)) {
if ((yRegressionCurve - m_cursor->y() > 0) == (direction > 0)) {
m_selectedDotIndex = -1;
m_cursor.moveTo(m_cursor.x(), yRegressionCurve);
m_store->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
m_cursor->moveTo(m_cursor->x(), yRegressionCurve);
m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
return true;
} else {
return false;
}
} else {
int dotSelected = m_store->closestVerticalDot(direction, m_cursor.x());
int dotSelected = m_store->closestVerticalDot(direction, m_cursor->x());
if (dotSelected >= 0 && dotSelected < m_store->numberOfPairs()) {
m_selectedDotIndex = dotSelected;
m_cursor.moveTo(m_store->get(0, m_selectedDotIndex), m_store->get(1, m_selectedDotIndex));
m_store->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
m_cursor->moveTo(m_store->get(0, m_selectedDotIndex), m_store->get(1, m_selectedDotIndex));
m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
return true;
}
if (dotSelected == m_store->numberOfPairs()) {
m_selectedDotIndex = dotSelected;
m_cursor.moveTo(m_store->meanOfColumn(0), m_store->meanOfColumn(1));
m_store->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
m_cursor->moveTo(m_store->meanOfColumn(0), m_store->meanOfColumn(1));
m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
return true;
}
return false;

View File

@@ -8,13 +8,14 @@
#include "initialisation_parameter_controller.h"
#include "prediction_parameter_controller.h"
#include "../shared/interactive_curve_view_controller.h"
#include "../shared/curve_view_cursor.h"
namespace Regression {
class GraphController : public Shared::InteractiveCurveViewController {
public:
GraphController(Responder * parentResponder, ButtonRowController * header, Store * store);
GraphController(Responder * parentResponder, ButtonRowController * header, Store * store, Shared::CurveViewCursor * cursor);
ViewController * initialisationParameterController() override;
bool isEmpty() const override;
I18n::Message emptyMessage() override;

View File

@@ -18,6 +18,13 @@ const Image * App::Descriptor::icon() {
return ImageStore::SequenceIcon;
}
App::Snapshot::Snapshot() :
m_sequenceStore(),
m_graphRange(&m_cursor),
m_cursor()
{
}
App * App::Snapshot::unpack(Container * container) {
return new App(container, this);
}
@@ -35,6 +42,14 @@ SequenceStore * App::Snapshot::sequenceStore() {
return &m_sequenceStore;
}
CurveViewRange * App::Snapshot::graphRange() {
return &m_graphRange;
}
Shared::CurveViewCursor * App::Snapshot::cursor() {
return &m_cursor;
}
void App::Snapshot::tidy() {
m_sequenceStore.tidy();
}
@@ -46,7 +61,7 @@ App::App(Container * container, Snapshot * snapshot) :
m_listFooter(&m_listHeader, &m_listController, &m_listController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey),
m_listHeader(nullptr, &m_listFooter, &m_listController),
m_listStackViewController(&m_tabViewController, &m_listHeader),
m_graphController(&m_graphAlternateEmptyViewController, snapshot->sequenceStore(), &m_graphHeader),
m_graphController(&m_graphAlternateEmptyViewController, snapshot->sequenceStore(), snapshot->graphRange(), snapshot->cursor(), &m_graphHeader),
m_graphAlternateEmptyViewController(&m_graphHeader, &m_graphController, &m_graphController),
m_graphHeader(&m_graphStackViewController, &m_graphAlternateEmptyViewController, &m_graphController),
m_graphStackViewController(&m_tabViewController, &m_graphHeader),

View File

@@ -6,6 +6,7 @@
#include "local_context.h"
#include "sequence_store.h"
#include "graph/graph_controller.h"
#include "graph/curve_view_range.h"
#include "list/list_controller.h"
#include "values/values_controller.h"
#include "../shared/function_app.h"
@@ -22,13 +23,18 @@ public:
};
class Snapshot : public ::App::Snapshot {
public:
Snapshot();
App * unpack(Container * container) override;
void reset() override;
Descriptor * descriptor() override;
SequenceStore * sequenceStore();
CurveViewRange * graphRange();
Shared::CurveViewCursor * cursor();
private:
void tidy() override;
SequenceStore m_sequenceStore;
CurveViewRange m_graphRange;
Shared::CurveViewCursor m_cursor;
};
InputViewController * inputViewController() override;
Poincare::Context * localContext() override;

View File

@@ -7,7 +7,7 @@ namespace Sequence {
class CurveViewRange : public Shared::InteractiveCurveViewRange {
public:
CurveViewRange(Shared::CurveViewCursor * cursor, Shared::InteractiveCurveViewRangeDelegate * delegate);
CurveViewRange(Shared::CurveViewCursor * cursor, Shared::InteractiveCurveViewRangeDelegate * delegate = nullptr);
void roundAbscissa() override;
void normalize() override;
void setTrigonometric() override;

View File

@@ -4,15 +4,16 @@ using namespace Shared;
namespace Sequence {
GraphController::GraphController(Responder * parentResponder, SequenceStore * sequenceStore, ButtonRowController * header) :
FunctionGraphController(parentResponder, header, &m_graphRange, &m_view),
GraphController::GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, ButtonRowController * header) :
FunctionGraphController(parentResponder, header, graphRange, &m_view, cursor),
m_bannerView(),
m_view(sequenceStore, &m_graphRange, &m_cursor, &m_bannerView, &m_cursorView),
m_graphRange(&m_cursor, this),
m_curveParameterController(this, &m_graphRange, &m_cursor),
m_termSumController(this, &m_view, &m_graphRange, &m_cursor),
m_view(sequenceStore, graphRange, m_cursor, &m_bannerView, &m_cursorView),
m_graphRange(graphRange),
m_curveParameterController(this, graphRange, m_cursor),
m_termSumController(this, &m_view, graphRange, m_cursor),
m_sequenceStore(sequenceStore)
{
m_graphRange->setDelegate(this);
}
void GraphController::viewWillAppear() {
@@ -44,7 +45,7 @@ bool GraphController::handleEnter() {
}
bool GraphController::moveCursorHorizontally(int direction) {
float xCursorPosition = roundf(m_cursor.x());
float xCursorPosition = roundf(m_cursor->x());
if (direction < 0 && xCursorPosition <= 0) {
return false;
}
@@ -61,8 +62,8 @@ bool GraphController::moveCursorHorizontally(int direction) {
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);
m_cursor->moveTo(x, y);
m_graphRange->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
return true;
}
@@ -76,12 +77,12 @@ void GraphController::initCursorParameters() {
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);
m_cursor->moveTo(x, y);
m_graphRange->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
}
CurveViewRange * GraphController::interactiveCurveViewRange() {
return &m_graphRange;
return m_graphRange;
}
SequenceStore * GraphController::functionStore() const {

View File

@@ -13,7 +13,7 @@ namespace Sequence {
class GraphController : public Shared::FunctionGraphController {
public:
GraphController(Responder * parentResponder, SequenceStore * sequenceStore, ButtonRowController * header);
GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, Shared::CurveViewCursor * cursor, ButtonRowController * header);
void viewWillAppear() override;
I18n::Message emptyMessage() override;
TermSumController * termSumController();
@@ -28,7 +28,7 @@ private:
CurveParameterController * curveParameterController() override;
BannerView m_bannerView;
GraphView m_view;
CurveViewRange m_graphRange;
CurveViewRange * m_graphRange;
CurveParameterController m_curveParameterController;
TermSumController m_termSumController;
SequenceStore * m_sequenceStore;

View File

@@ -8,8 +8,8 @@ using namespace Poincare;
namespace Shared {
FunctionGraphController::FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView) :
InteractiveCurveViewController(parentResponder, header, interactiveRange, curveView),
FunctionGraphController::FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor) :
InteractiveCurveViewController(parentResponder, header, interactiveRange, curveView, cursor),
m_indexFunctionSelectedByCursor(0),
m_initialisationParameterController(InitialisationParameterController(this, interactiveRange))
{
@@ -116,7 +116,7 @@ void FunctionGraphController::reloadBannerView() {
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
buffer[0] = functionStore()->symbol();
numberOfChar += Complex::convertFloatToText(m_cursor.x(), buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
numberOfChar += Complex::convertFloatToText(m_cursor->x(), buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
legend = " ";
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);
@@ -133,7 +133,7 @@ void FunctionGraphController::reloadBannerView() {
}
Function * f = functionStore()->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
buffer[0] = f->name()[0];
numberOfChar += Complex::convertFloatToText(m_cursor.y(), buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
numberOfChar += Complex::convertFloatToText(m_cursor->y(), buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
legend = " ";
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);
@@ -149,12 +149,12 @@ void FunctionGraphController::initRangeParameters() {
bool FunctionGraphController::moveCursorVertically(int direction) {
Function * actualFunction = functionStore()->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
float y = actualFunction->evaluateAtAbscissa(m_cursor.x(), myApp->localContext());
float y = actualFunction->evaluateAtAbscissa(m_cursor->x(), myApp->localContext());
Function * nextFunction = actualFunction;
float nextY = direction > 0 ? FLT_MAX : -FLT_MAX;
for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) {
Function * f = functionStore()->activeFunctionAtIndex(i);
float newY = f->evaluateAtAbscissa(m_cursor.x(), myApp->localContext());
float newY = f->evaluateAtAbscissa(m_cursor->x(), myApp->localContext());
bool isNextFunction = direction > 0 ? (newY > y && newY < nextY) : (newY < y && newY > nextY);
if (isNextFunction) {
m_indexFunctionSelectedByCursor = i;
@@ -165,8 +165,8 @@ bool FunctionGraphController::moveCursorVertically(int direction) {
if (nextFunction == actualFunction) {
return false;
}
m_cursor.moveTo(m_cursor.x(), nextY);
interactiveCurveViewRange()->panToMakePointVisible(m_cursor.x(), m_cursor.y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
m_cursor->moveTo(m_cursor->x(), nextY);
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
return true;
}

View File

@@ -12,7 +12,7 @@ namespace Shared {
class FunctionGraphController : public InteractiveCurveViewController, public InteractiveCurveViewRangeDelegate {
public:
FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView);
FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor);
bool isEmpty() const override;
ViewController * initialisationParameterController() override;
void viewWillAppear() override;

View File

@@ -7,10 +7,10 @@ using namespace Poincare;
namespace Shared {
InteractiveCurveViewController::InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView) :
InteractiveCurveViewController::InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor) :
ViewController(parentResponder),
ButtonRowDelegate(header, nullptr),
m_cursor(),
m_cursor(cursor),
m_cursorView(CursorView()),
m_modelVersion(0),
m_rangeVersion(0),
@@ -181,7 +181,7 @@ StackViewController * InteractiveCurveViewController::stackController() const{
void InteractiveCurveViewController::centerCursorVertically() {
if (!interactiveCurveViewRange()->yAuto()) {
interactiveCurveViewRange()->centerAxisAround(CurveViewRange::Axis::Y, m_cursor.y());
interactiveCurveViewRange()->centerAxisAround(CurveViewRange::Axis::Y, m_cursor->y());
}
}
}

View File

@@ -3,6 +3,7 @@
#include <escher.h>
#include "interactive_curve_view_range.h"
#include "curve_view_cursor.h"
#include "curve_view.h"
#include "cursor_view.h"
#include "ok_view.h"
@@ -14,7 +15,7 @@ namespace Shared {
class InteractiveCurveViewController : public ViewController, public ButtonRowDelegate, public AlternateEmptyViewDelegate {
public:
InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView);
InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor);
View * view() override;
const char * title() override;
bool handleEvent(Ion::Events::Event event) override;
@@ -51,7 +52,7 @@ protected:
virtual uint32_t rangeVersion() = 0;
virtual InteractiveCurveViewRange * interactiveCurveViewRange() = 0;
virtual CurveView * curveView() = 0;
CurveViewCursor m_cursor;
CurveViewCursor * m_cursor;
CursorView m_cursorView;
OkView m_okView;
private:

View File

@@ -17,6 +17,10 @@ InteractiveCurveViewRange::InteractiveCurveViewRange(CurveViewCursor * cursor, I
{
}
void InteractiveCurveViewRange::setDelegate(InteractiveCurveViewRangeDelegate * delegate) {
m_delegate = delegate;
}
void InteractiveCurveViewRange::setCursor(CurveViewCursor * cursor) {
m_cursor = cursor;
}

View File

@@ -10,7 +10,8 @@ namespace Shared {
class InteractiveCurveViewRange : public MemoizedCurveViewRange {
public:
InteractiveCurveViewRange(CurveViewCursor * cursor, InteractiveCurveViewRangeDelegate * delegate);
InteractiveCurveViewRange(CurveViewCursor * cursor, InteractiveCurveViewRangeDelegate * delegate = nullptr);
void setDelegate(InteractiveCurveViewRangeDelegate * delegate);
void setCursor(CurveViewCursor * cursor);
uint32_t rangeChecksum() override;