[apps] Graph: In graphview, replace the type by a boolean to decide

wether to draw tangent
This commit is contained in:
Émilie Feral
2018-01-10 15:11:53 +01:00
committed by EmilieNumworks
parent cdfbc02499
commit 53b90034da
5 changed files with 8 additions and 14 deletions

View File

@@ -26,7 +26,7 @@ I18n::Message GraphController::emptyMessage() {
}
void GraphController::viewWillAppear() {
m_view.setType(GraphView::Type::Default);
m_view.drawTangent(false);
FunctionGraphController::viewWillAppear();
}

View File

@@ -20,7 +20,6 @@ public:
bool displayDerivativeInBanner() const;
void setDisplayDerivativeInBanner(bool displayDerivative);
private:
GraphView::Type type() const;
BannerView * bannerView() override;
void reloadBannerView() override;
bool moveCursorHorizontally(int direction) override;

View File

@@ -8,12 +8,12 @@ GraphView::GraphView(CartesianFunctionStore * functionStore, InteractiveCurveVie
CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) :
FunctionGraphView(graphRange, cursor, bannerView, cursorView),
m_functionStore(functionStore),
m_type(Type::Default)
m_tangent(false)
{
}
void GraphView::reload() {
if (m_type == Type::Tangent) {
if (m_tangent) {
KDRect dirtyZone(KDRect(0, 0, bounds().width(), bounds().height()-m_bannerView->bounds().height()));
markRectAsDirty(dirtyZone);
}
@@ -29,7 +29,7 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
Poincare::Context * c = (Poincare::Context *)context;
return f->evaluateAtAbscissa(t, c);
}, f, context(), f->color());
if (m_type == Type::Tangent && f == m_selectedFunction) {
if (m_tangent && f == m_selectedFunction) {
float tangentParameter[2];
tangentParameter[0] = f->approximateDerivative(m_curveViewCursor->x(), context());
tangentParameter[1] = -tangentParameter[0]*m_curveViewCursor->x()+f->evaluateAtAbscissa(m_curveViewCursor->x(), context());

View File

@@ -8,20 +8,15 @@ namespace Graph {
class GraphView : public Shared::FunctionGraphView {
public:
enum class Type {
Default,
Tangent,
Integral
};
GraphView(CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * graphRange,
Shared::CurveViewCursor * cursor, Shared::BannerView * bannerView, View * cursorView);
void reload() override;
void drawRect(KDContext * ctx, KDRect rect) const override;
Type type() const { return m_type; }
void setType(Type type) { m_type = type; }
void drawTangent(bool tangent) { m_tangent = tangent; }
private:
CartesianFunctionStore * m_functionStore;
Type m_type;
bool m_tangent;
};
}

View File

@@ -21,7 +21,7 @@ const char * TangentGraphController::title() {
void TangentGraphController::viewWillAppear() {
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
m_graphView->setType(GraphView::Type::Tangent);
m_graphView->drawTangent(true);
m_graphView->setOkView(nullptr);
m_graphView->selectMainView(true);
reloadBannerView();