Numworks Epsilon  1.4.1
Graphing Calculator Operating System
calculation_graph_controller.cpp
Go to the documentation of this file.
2 #include "../app.h"
3 
4 using namespace Shared;
5 using namespace Poincare;
6 
7 namespace Graph {
8 
9 CalculationGraphController::CalculationGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, I18n::Message defaultMessage) :
10  ViewController(parentResponder),
11  m_graphView(graphView),
12  m_bannerView(bannerView),
13  m_graphRange(curveViewRange),
14  m_cursor(cursor),
15  m_function(nullptr),
16  m_defaultBannerView(KDText::FontSize::Small, defaultMessage, 0.5f, 0.5f, KDColorBlack, Palette::GreyMiddle),
17  m_isActive(false)
18 {
19 }
20 
22  return m_graphView;
23 }
24 
26  assert(m_function != nullptr);
28  if (std::isnan(pointOfInterest.abscissa)) {
29  m_isActive = false;
30  m_graphView->setCursorView(nullptr);
32  } else {
33  m_isActive = true;
34  m_cursor->moveTo(pointOfInterest.abscissa, pointOfInterest.value);
35  m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, SimpleInteractiveCurveViewController::k_cursorRightMarginRatio, k_cursorBottomMarginRatio, SimpleInteractiveCurveViewController::k_cursorLeftMarginRatio);
37  }
38  m_graphView->setOkView(nullptr);
40 }
41 
43  if (event == Ion::Events::EXE || event == Ion::Events::OK) {
44  StackViewController * stack = static_cast<StackViewController *>(parentResponder());
45  stack->pop();
46  return true;
47  }
48  if (m_isActive && (event == Ion::Events::Right || event == Ion::Events::Left)) {
49  int direction = event == Ion::Events::Right ? 1 : -1;
50  if (moveCursor(direction)) {
53  return true;
54  }
55  }
56  return false;
57 }
58 
60  m_graphView->selectFunction(function);
61  m_function = function;
62 }
63 
67 }
68 
71  if (std::isnan(newPointOfInterest.abscissa)) {
72  return false;
73  }
74  m_cursor->moveTo(newPointOfInterest.abscissa, newPointOfInterest.value);
75  m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, SimpleInteractiveCurveViewController::k_cursorRightMarginRatio, k_cursorBottomMarginRatio, SimpleInteractiveCurveViewController::k_cursorLeftMarginRatio);
76  return true;
77 }
78 
81  double step = m_graphRange->xGridUnit()/10.0;
82  step = direction < 0 ? -step : step;
83  double max = direction > 0 ? m_graphRange->xMax() : m_graphRange->xMin();
84  return computeNewPointOfInterest(start, step, max, myApp->localContext());
85 }
86 
87 }
void setFunction(CartesianFunction *function)
#define assert(e)
Definition: assert.h:9
constexpr Event EXE
Definition: events.h:114
Responder * parentResponder() const
Definition: responder.cpp:12
void setBannerView(View *bannerView)
Definition: curve_view.cpp:71
void reload() override
Definition: graph_view.cpp:16
void setOkView(View *okView)
Definition: curve_view.cpp:77
Definition: text.h:8
Definition: app.cpp:9
virtual Poincare::Context * localContext()
void setNumberOfSubviews(int numberOfSubviews)
Definition: banner_view.cpp:17
void reloadBannerViewForCursorOnFunction(CurveViewCursor *cursor, Function *function, char symbol)
bool handleEvent(Ion::Events::Event event) override
constexpr KDColor KDColorBlack
Definition: color.h:41
#define false
Definition: stdbool.h:9
void moveTo(double x, double y)
#define isnan(x)
Definition: math.h:43
constexpr Event Left
Definition: events.h:61
void start()
Definition: rt0.cpp:31
void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation)
void setCursorView(View *cursorView)
Definition: curve_view.cpp:64
Definition: view.h:23
constexpr Event Right
Definition: events.h:64
CartesianFunction::Point computeNewPointOfInteresetFromAbscissa(double start, int direction)
void selectFunction(Function *function)
App * app()
Definition: responder.cpp:77
constexpr Event OK
Definition: events.h:65
Shared::InteractiveCurveViewRange * m_graphRange
virtual CartesianFunction::Point computeNewPointOfInterest(double start, double step, double max, Poincare::Context *context)=0
Definition: palette.h:6