mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-21 06:40:37 +01:00
[apps/graph/graph] CalculationGraphController inherits from SimpleInteractiveCurveViewController
This commit is contained in:
committed by
Émilie Feral
parent
ce712eac53
commit
fe977bdc07
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user