Numworks Epsilon  1.4.1
Graphing Calculator Operating System
graph_view.cpp
Go to the documentation of this file.
1 #include "graph_view.h"
2 #include <float.h>
3 
4 using namespace Shared;
5 
6 namespace Graph {
7 
8 GraphView::GraphView(CartesianFunctionStore * functionStore, InteractiveCurveViewRange * graphRange,
9  CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) :
10  FunctionGraphView(graphRange, cursor, bannerView, cursorView),
11  m_functionStore(functionStore),
12  m_tangent(false)
13 {
14 }
15 
17  if (m_tangent) {
18  KDRect dirtyZone(KDRect(0, 0, bounds().width(), bounds().height()-m_bannerView->bounds().height()));
19  markRectAsDirty(dirtyZone);
20  }
21  return FunctionGraphView::reload();
22 }
23 
24 void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
25  FunctionGraphView::drawRect(ctx, rect);
26  for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) {
27  CartesianFunction * f = m_functionStore->activeFunctionAtIndex(i);
28 
29  /* Draw function (color the area under curve of the selected function) */
30  if (f == m_selectedFunction) {
31  drawCurve(ctx, rect, [](float t, void * model, void * context) {
34  return f->evaluateAtAbscissa(t, c);
35  }, f, context(), f->color(), true, m_highlightedStart, m_highlightedEnd);
36  } else {
37  drawCurve(ctx, rect, [](float t, void * model, void * context) {
40  return f->evaluateAtAbscissa(t, c);
41  }, f, context(), f->color());
42  }
43 
44  /* Draw tangent */
45  if (m_tangent && f == m_selectedFunction) {
46  float tangentParameter[2];
47  tangentParameter[0] = f->approximateDerivative(m_curveViewCursor->x(), context());
48  tangentParameter[1] = -tangentParameter[0]*m_curveViewCursor->x()+f->evaluateAtAbscissa(m_curveViewCursor->x(), context());
49  drawCurve(ctx, rect, [](float t, void * model, void * context) {
50  float * tangent = (float *)model;
51  return tangent[0]*t+tangent[1];
52  }, tangentParameter, nullptr, Palette::GreyVeryDark);
53  }
54  }
55 }
56 
57 }
Poincare::Context * context() const
void drawRect(KDContext *ctx, KDRect rect) const override
Definition: graph_view.cpp:24
View * m_bannerView
Definition: curve_view.h:56
const SettingsMessageTree model
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
void reload() override
Definition: graph_view.cpp:16
KDColor color() const
Definition: function.h:21
void drawCurve(KDContext *ctx, KDRect rect, EvaluateModelWithParameter evaluation, void *model, void *context, KDColor color, bool colorUnderCurve=false, float colorLowerBound=0.0f, float colorUpperBound=0.0f, bool continuously=false) const
Definition: curve_view.cpp:339
Definition: app.cpp:9
CurveViewCursor * m_curveViewCursor
Definition: curve_view.h:57
c(generic_all_nodes)
double approximateDerivative(double x, Poincare::Context *context) const
#define false
Definition: stdbool.h:9
Definition: rect.h:26
virtual float evaluateAtAbscissa(float x, Poincare::Context *context) const
Definition: function.h:30
static constexpr KDColor GreyVeryDark
Definition: palette.h:16
Definition: view.h:23
CartesianFunction * activeFunctionAtIndex(int i) override
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157