From 53b90034da516ecd2a35e093c0bc77a6281e2968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 10 Jan 2018 15:11:53 +0100 Subject: [PATCH] [apps] Graph: In graphview, replace the type by a boolean to decide wether to draw tangent --- apps/graph/graph/graph_controller.cpp | 2 +- apps/graph/graph/graph_controller.h | 1 - apps/graph/graph/graph_view.cpp | 6 +++--- apps/graph/graph/graph_view.h | 11 +++-------- apps/graph/graph/tangent_graph_controller.cpp | 2 +- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index b67a33bdb..f85439481 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -26,7 +26,7 @@ I18n::Message GraphController::emptyMessage() { } void GraphController::viewWillAppear() { - m_view.setType(GraphView::Type::Default); + m_view.drawTangent(false); FunctionGraphController::viewWillAppear(); } diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index 45b6e7de0..eef097772 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -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; diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index 346a009f7..092d65b42 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -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()); diff --git a/apps/graph/graph/graph_view.h b/apps/graph/graph/graph_view.h index 84a30e526..9d586eeff 100644 --- a/apps/graph/graph/graph_view.h +++ b/apps/graph/graph/graph_view.h @@ -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; }; } diff --git a/apps/graph/graph/tangent_graph_controller.cpp b/apps/graph/graph/tangent_graph_controller.cpp index a518b234f..6fac9385d 100644 --- a/apps/graph/graph/tangent_graph_controller.cpp +++ b/apps/graph/graph/tangent_graph_controller.cpp @@ -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();