mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[apps] Graph: redesign TangentGraphController implementation: use
different controller with common parent class
This commit is contained in:
committed by
EmilieNumworks
parent
7ce68d0a11
commit
5c64f76735
@@ -11,22 +11,13 @@ GraphController::GraphController(Responder * parentResponder, CartesianFunctionS
|
||||
m_bannerView(),
|
||||
m_view(functionStore, curveViewRange, m_cursor, &m_bannerView, &m_cursorView),
|
||||
m_graphRange(curveViewRange),
|
||||
m_curveParameterController(curveViewRange, &m_bannerView, m_cursor, this),
|
||||
m_curveParameterController(curveViewRange, &m_bannerView, m_cursor, &m_view, this),
|
||||
m_functionStore(functionStore),
|
||||
m_displayDerivativeInBanner(false)
|
||||
{
|
||||
m_graphRange->setDelegate(this);
|
||||
}
|
||||
|
||||
const char * GraphController::title() {
|
||||
switch(type()) {
|
||||
case GraphView::Type::Tangent:
|
||||
return I18n::translate(I18n::Message::Tangent);
|
||||
default:
|
||||
return I18n::translate(I18n::Message::GraphTab);
|
||||
}
|
||||
}
|
||||
|
||||
I18n::Message GraphController::emptyMessage() {
|
||||
if (m_functionStore->numberOfDefinedFunctions() == 0) {
|
||||
return I18n::Message::NoFunction;
|
||||
@@ -34,28 +25,9 @@ I18n::Message GraphController::emptyMessage() {
|
||||
return I18n::Message::NoActivatedFunction;
|
||||
}
|
||||
|
||||
bool GraphController::handleEvent(Ion::Events::Event event) {
|
||||
if (type() == GraphView::Type::Default || event == Ion::Events::Left || event == Ion::Events::Right || event == Ion::Events::Plus || event == Ion::Events::Minus) {
|
||||
return FunctionGraphController::handleEvent(event);
|
||||
}
|
||||
if (type() != GraphView::Type::Default && (event == Ion::Events::Back || event == Ion::Events::OK)) {
|
||||
StackViewController * stack = stackController();
|
||||
setType(GraphView::Type::Default);
|
||||
App * a = static_cast<App *>(app());
|
||||
stack->handleEvent(Ion::Events::Back);
|
||||
setParentResponder(a->graphControllerParent());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GraphController::setType(GraphView::Type t) {
|
||||
m_view.setType(t);
|
||||
if (type() != GraphView::Type::Default) {
|
||||
m_view.selectFunction(m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor));
|
||||
} else {
|
||||
m_view.selectFunction(nullptr);
|
||||
}
|
||||
void GraphController::viewWillAppear() {
|
||||
m_view.setType(GraphView::Type::Default);
|
||||
FunctionGraphController::viewWillAppear();
|
||||
}
|
||||
|
||||
bool GraphController::displayDerivativeInBanner() const {
|
||||
@@ -66,10 +38,6 @@ void GraphController::setDisplayDerivativeInBanner(bool displayDerivative) {
|
||||
m_displayDerivativeInBanner = displayDerivative;
|
||||
}
|
||||
|
||||
GraphView::Type GraphController::type() const {
|
||||
return m_view.type();
|
||||
}
|
||||
|
||||
BannerView * GraphController::bannerView() {
|
||||
return &m_bannerView;
|
||||
}
|
||||
@@ -77,33 +45,12 @@ BannerView * GraphController::bannerView() {
|
||||
void GraphController::reloadBannerView() {
|
||||
FunctionGraphController::reloadBannerView();
|
||||
m_bannerView.setNumberOfSubviews(2+m_displayDerivativeInBanner);
|
||||
if (type() == GraphView::Type::Tangent) {
|
||||
m_bannerView.setNumberOfSubviews(6);
|
||||
}
|
||||
if (m_functionStore->numberOfActiveFunctions() == 0) {
|
||||
if (m_functionStore->numberOfActiveFunctions() == 0 || !m_displayDerivativeInBanner) {
|
||||
return;
|
||||
}
|
||||
CartesianFunction * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
|
||||
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
|
||||
reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, f, myApp);
|
||||
|
||||
|
||||
char buffer[FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
||||
if (type() == GraphView::Type::Tangent) {
|
||||
const char * legend = "a=";
|
||||
int legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
double y = f->approximateDerivative(m_cursor->x(), myApp->localContext());
|
||||
Complex<double>::convertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
|
||||
m_bannerView.setLegendAtIndex(buffer, 4);
|
||||
|
||||
legend = "b=";
|
||||
legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
y = -y*m_cursor->x()+f->evaluateAtAbscissa(m_cursor->x(), myApp->localContext());
|
||||
Complex<double>::convertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
|
||||
m_bannerView.setLegendAtIndex(buffer, 5);
|
||||
}
|
||||
}
|
||||
|
||||
bool GraphController::moveCursorHorizontally(int direction) {
|
||||
@@ -142,11 +89,4 @@ CurveParameterController * GraphController::curveParameterController() {
|
||||
return &m_curveParameterController;
|
||||
}
|
||||
|
||||
StackViewController * GraphController::stackController() const{
|
||||
if (type() != GraphView::Type::Default) {
|
||||
return (StackViewController *)(parentResponder());
|
||||
}
|
||||
return FunctionGraphController::stackController();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user