Numworks Epsilon  1.4.1
Graphing Calculator Operating System
function_graph_view.cpp
Go to the documentation of this file.
1 #include "function_graph_view.h"
2 #include <assert.h>
3 #include <cmath>
4 #include <float.h>
5 using namespace Poincare;
6 
7 namespace Shared {
8 
9 FunctionGraphView::FunctionGraphView(InteractiveCurveViewRange * graphRange,
10  CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) :
11  CurveView(graphRange, cursor, bannerView, cursorView),
12  m_selectedFunction(nullptr),
13  m_highlightedStart(NAN),
14  m_highlightedEnd(NAN),
15  m_shouldColorHighlighted(false),
16  m_xLabels{},
17  m_yLabels{},
18  m_context(nullptr)
19 {
20 }
21 
22 void FunctionGraphView::drawRect(KDContext * ctx, KDRect rect) const {
23  ctx->fillRect(rect, KDColorWhite);
24  drawGrid(ctx, rect);
25  drawAxes(ctx, rect, Axis::Horizontal);
26  drawAxes(ctx, rect, Axis::Vertical);
27  drawLabels(ctx, rect, Axis::Horizontal, true);
28  drawLabels(ctx, rect, Axis::Vertical, true);
29 }
30 
32  m_context = context;
33 }
34 
36  return m_context;
37 }
38 
40  if (m_selectedFunction != function) {
41  m_selectedFunction = function;
43  }
44 }
45 
47  if (m_highlightedStart != start || m_highlightedEnd != end) {
48  float dirtyStart = start > m_highlightedStart ? m_highlightedStart : start;
49  float dirtyEnd = start > m_highlightedStart ? start : m_highlightedStart;
50  reloadBetweenBounds(dirtyStart, dirtyEnd);
51  dirtyStart = end > m_highlightedEnd ? m_highlightedEnd : end;
52  dirtyEnd = end > m_highlightedEnd ? end : m_highlightedEnd;
53  reloadBetweenBounds(dirtyStart, dirtyEnd);
54  if (std::isnan(start) || std::isnan(end)) {
56  }
59  }
61  m_highlightedEnd = end;
62  }
63 }
64 
65 void FunctionGraphView::setAreaHighlightColor(bool highlightColor) {
66  if (m_shouldColorHighlighted != highlightColor) {
68  m_shouldColorHighlighted = highlightColor;
69  }
70 }
71 
72 char * FunctionGraphView::label(Axis axis, int index) const {
73  return (axis == Axis::Horizontal ? (char *)m_xLabels[index] : (char *)m_yLabels[index]);
74 }
75 
77  if (start == end) {
78  return;
79  }
80  float pixelLowerBound = floatToPixel(Axis::Horizontal, start)-2.0;
81  float pixelUpperBound = floatToPixel(Axis::Horizontal, end)+4.0;
82  /* We exclude the banner frame from the dirty zone to avoid unnecessary
83  * redrawing */
84  KDRect dirtyZone(KDRect(pixelLowerBound, 0, pixelUpperBound-pixelLowerBound,
85  bounds().height()-m_bannerView->bounds().height()));
86  markRectAsDirty(dirtyZone);
87 }
88 
89 
90 }
Poincare::Context * context() const
void reloadBetweenBounds(float start, float end)
#define NAN
Definition: math.h:30
View * m_bannerView
Definition: curve_view.h:56
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
void drawGrid(KDContext *ctx, KDRect rect) const
Definition: curve_view.cpp:277
void drawAxes(KDContext *ctx, KDRect rect, Axis axis) const
Definition: curve_view.cpp:282
constexpr KDColor KDColorWhite
Definition: color.h:42
void drawLabels(KDContext *ctx, KDRect rect, Axis axis, bool shiftOrigin) const
Definition: curve_view.cpp:146
void setAreaHighlight(float start, float end)
#define false
Definition: stdbool.h:9
void drawRect(KDContext *ctx, KDRect rect) const override
#define isnan(x)
Definition: math.h:43
void start()
Definition: rt0.cpp:31
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
float floatToPixel(Axis axis, float f) const
Definition: curve_view.cpp:115
Definition: view.h:23
void setContext(Poincare::Context *context)
void selectFunction(Function *function)
virtual void setAreaHighlightColor(bool highlightColor)
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157