[apps/graph/graph] CalculationGraphController inherits from SimpleInteractiveCurveViewController

This commit is contained in:
Ruben Dashyan
2019-03-12 15:00:16 +01:00
committed by Émilie Feral
parent ce712eac53
commit fe977bdc07
3 changed files with 36 additions and 43 deletions

View File

@@ -7,21 +7,16 @@ using namespace Poincare;
namespace Graph {
CalculationGraphController::CalculationGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, I18n::Message defaultMessage) :
ViewController(parentResponder),
SimpleInteractiveCurveViewController(parentResponder, cursor),
m_graphView(graphView),
m_bannerView(bannerView),
m_graphRange(curveViewRange),
m_cursor(cursor),
m_record(),
m_defaultBannerView(KDFont::SmallFont, defaultMessage, 0.5f, 0.5f, KDColorBlack, Palette::GreyMiddle),
m_isActive(false)
{
}
View * CalculationGraphController::view() {
return m_graphView;
}
void CalculationGraphController::viewWillAppear() {
assert(!m_record.isNull());
Expression::Coordinate2D pointOfInterest = computeNewPointOfInteresetFromAbscissa(m_graphRange->xMin(), 1);
@@ -32,30 +27,13 @@ void CalculationGraphController::viewWillAppear() {
} else {
m_isActive = true;
m_cursor->moveTo(pointOfInterest.abscissa, pointOfInterest.value);
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, SimpleInteractiveCurveViewController::k_cursorRightMarginRatio, k_cursorBottomMarginRatio, SimpleInteractiveCurveViewController::k_cursorLeftMarginRatio);
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
reloadBannerView();
}
m_graphView->setOkView(nullptr);
m_graphView->reload();
}
bool CalculationGraphController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::EXE || event == Ion::Events::OK) {
StackViewController * stack = static_cast<StackViewController *>(parentResponder());
stack->pop();
return true;
}
if (m_isActive && (event == Ion::Events::Right || event == Ion::Events::Left)) {
int direction = event == Ion::Events::Right ? 1 : -1;
if (moveCursor(direction)) {
reloadBannerView();
m_graphView->reload();
return true;
}
}
return false;
}
void CalculationGraphController::setRecord(Ion::Storage::Record record) {
m_graphView->selectRecord(record);
m_record = record;
@@ -66,16 +44,6 @@ void CalculationGraphController::reloadBannerView() {
reloadBannerViewForCursorOnFunction(m_cursor, m_record, functionStore(), CartesianFunction::Symbol());
}
bool CalculationGraphController::moveCursor(int direction) {
Expression::Coordinate2D newPointOfInterest = computeNewPointOfInteresetFromAbscissa(m_cursor->x(), direction);
if (std::isnan(newPointOfInterest.abscissa)) {
return false;
}
m_cursor->moveTo(newPointOfInterest.abscissa, newPointOfInterest.value);
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, SimpleInteractiveCurveViewController::k_cursorRightMarginRatio, k_cursorBottomMarginRatio, SimpleInteractiveCurveViewController::k_cursorLeftMarginRatio);
return true;
}
Expression::Coordinate2D CalculationGraphController::computeNewPointOfInteresetFromAbscissa(double start, int direction) {
App * myApp = static_cast<App *>(app());
double step = m_graphRange->xGridUnit()/10.0;
@@ -89,4 +57,27 @@ CartesianFunctionStore * CalculationGraphController::functionStore() const {
return a->functionStore();
}
bool CalculationGraphController::handleLeftRightEvent(Ion::Events::Event event) {
if (!m_isActive) {
return false;
}
return SimpleInteractiveCurveViewController::handleLeftRightEvent(event);
}
bool CalculationGraphController::handleEnter() {
StackViewController * stack = static_cast<StackViewController *>(parentResponder());
stack->pop();
return true;
}
bool CalculationGraphController::moveCursorHorizontally(int direction) {
Expression::Coordinate2D newPointOfInterest = computeNewPointOfInteresetFromAbscissa(m_cursor->x(), direction);
if (std::isnan(newPointOfInterest.abscissa)) {
return false;
}
m_cursor->moveTo(newPointOfInterest.abscissa, newPointOfInterest.value);
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
return true;
}
}

View File

@@ -3,8 +3,7 @@
#include "graph_view.h"
#include "banner_view.h"
#include "../../shared/curve_view_cursor.h"
#include "../../shared/interactive_curve_view_range.h"
#include "../../shared/simple_interactive_curve_view_controller.h"
#include "../../shared/function_banner_delegate.h"
#include "../cartesian_function_store.h"
@@ -12,29 +11,32 @@ namespace Graph {
class App;
class CalculationGraphController : public ViewController, public Shared::FunctionBannerDelegate {
class CalculationGraphController : public Shared::SimpleInteractiveCurveViewController, public Shared::FunctionBannerDelegate {
public:
CalculationGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, I18n::Message defaultMessage);
View * view() override;
void viewWillAppear() override;
bool handleEvent(Ion::Events::Event event) override;
void setRecord(Ion::Storage::Record record);
protected:
constexpr static float k_cursorTopMarginRatio = 0.07f; // (cursorHeight/2)/graphViewHeight
constexpr static float k_cursorBottomMarginRatio = 0.15f; // (cursorHeight/2+bannerHeigh)/graphViewHeight
BannerView * bannerView() override { return m_bannerView; }
virtual void reloadBannerView();
bool moveCursor(int direction);
void reloadBannerView() override;
Poincare::Expression::Coordinate2D computeNewPointOfInteresetFromAbscissa(double start, int direction);
CartesianFunctionStore * functionStore() const;
virtual Poincare::Expression::Coordinate2D computeNewPointOfInterest(double start, double step, double max, Poincare::Context * context) = 0;
GraphView * m_graphView;
BannerView * m_bannerView;
Shared::InteractiveCurveViewRange * m_graphRange;
Shared::CurveViewCursor * m_cursor;
Ion::Storage::Record m_record;
MessageTextView m_defaultBannerView;
bool m_isActive;
private:
bool handleZoom(Ion::Events::Event event) override { return false; }
bool handleLeftRightEvent(Ion::Events::Event event) override;
bool handleEnter() override;
bool moveCursorHorizontally(int direction) override;
Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override { return m_graphRange; }
Shared::CurveView * curveView() override { return m_graphView; }
};
}

View File

@@ -16,10 +16,10 @@ public:
SimpleInteractiveCurveViewController(Responder * parentResponder, CurveViewCursor * cursor);
View * view() override;
bool handleEvent(Ion::Events::Event event) override;
protected:
constexpr static float k_cursorRightMarginRatio = 0.04f; // (cursorWidth/2)/graphViewWidth
constexpr static float k_cursorLeftMarginRatio = 0.04f; // (cursorWidth/2)/graphViewWidth
constexpr static float k_numberOfCursorStepsInGradUnit = 5.0f;
protected:
virtual bool handleZoom(Ion::Events::Event event);
virtual bool handleLeftRightEvent(Ion::Events::Event event);
virtual void reloadBannerView() = 0;