Files
Upsilon/apps/shared/function_graph_view.cpp
Émilie Feral 7ea0dbeb56 [apps] Shared: Move part of the implementation of TermSumController to
shared (Integral Graph Controller) and improve bound edition in
TermSumController.
2018-01-30 18:19:27 +01:00

94 lines
2.5 KiB
C++

#include "function_graph_view.h"
#include <assert.h>
#include <cmath>
#include <float.h>
using namespace Poincare;
namespace Shared {
FunctionGraphView::FunctionGraphView(InteractiveCurveViewRange * graphRange,
CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) :
CurveView(graphRange, cursor, bannerView, cursorView),
m_selectedFunction(nullptr),
m_verticalCursor(false),
m_highlightedStart(NAN),
m_highlightedEnd(NAN),
m_shouldColorHighlighted(false),
m_xLabels{},
m_yLabels{},
m_context(nullptr)
{
}
void FunctionGraphView::reload() {
CurveView::reload();
if (!std::isnan(m_highlightedStart)) {
float pixelLowerBound = floatToPixel(Axis::Horizontal, m_highlightedStart)-2.0;
float pixelUpperBound = floatToPixel(Axis::Horizontal, m_highlightedEnd)+4.0;
/* We exclude the banner frame from the dirty zone to avoid unnecessary
* redrawing */
KDRect dirtyZone(KDRect(pixelLowerBound, 0, pixelUpperBound-pixelLowerBound,
bounds().height()-m_bannerView->bounds().height()));
markRectAsDirty(dirtyZone);
}
}
void FunctionGraphView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(rect, KDColorWhite);
drawGrid(ctx, rect);
drawAxes(ctx, rect, Axis::Horizontal);
drawAxes(ctx, rect, Axis::Vertical);
drawLabels(ctx, rect, Axis::Horizontal, true);
drawLabels(ctx, rect, Axis::Vertical, true);
}
void FunctionGraphView::setContext(Context * context) {
m_context = context;
}
Context * FunctionGraphView::context() const {
return m_context;
}
void FunctionGraphView::selectFunction(Function * function) {
if (m_selectedFunction != function) {
reload();
m_selectedFunction = function;
reload();
}
}
void FunctionGraphView::setVerticalCursor(bool verticalCursor) {
m_verticalCursor = verticalCursor;
}
void FunctionGraphView::setAreaHighlight(float start, float end) {
if (m_highlightedStart != start || m_highlightedEnd != end) {
reload();
m_highlightedStart = start;
m_highlightedEnd = end;
reload();
}
}
void FunctionGraphView::setAreaHighlightColor(bool highlightColor) {
if (m_shouldColorHighlighted != highlightColor) {
reload();
m_shouldColorHighlighted = highlightColor;
reload();
}
}
KDSize FunctionGraphView::cursorSize() {
if (m_verticalCursor) {
return KDSize(1, 0);
}
return CurveView::cursorSize();
}
char * FunctionGraphView::label(Axis axis, int index) const {
return (axis == Axis::Horizontal ? (char *)m_xLabels[index] : (char *)m_yLabels[index]);
}
}