From ba67ef4a2e49e08d3b9be35d1eef75618f3f9d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 20 Dec 2016 11:31:53 +0100 Subject: [PATCH] [apps/graph/graph] Add a banner view in the graph view Change-Id: Iafa0dcfc730911264d5b045c14bde54f432f53a2 --- .../graph/curve_parameter_controller.cpp | 9 ++----- apps/graph/graph/curve_parameter_controller.h | 2 -- apps/graph/graph/graph_view.cpp | 26 ++++++++++++++++--- apps/graph/graph/graph_view.h | 6 +++++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/apps/graph/graph/curve_parameter_controller.cpp b/apps/graph/graph/curve_parameter_controller.cpp index 54fb977b8..49bd845e0 100644 --- a/apps/graph/graph/curve_parameter_controller.cpp +++ b/apps/graph/graph/curve_parameter_controller.cpp @@ -6,7 +6,6 @@ namespace Graph { CurveParameterController::CurveParameterController(GraphView * graphView) : ViewController(nullptr), m_graphView(graphView), - m_displayDerivative(false), m_function(nullptr), m_calculationCell(ChevronMenuListCell((char*)"Calculer")), m_goToCell(ChevronMenuListCell((char*)"Aller a")), @@ -33,7 +32,7 @@ void CurveParameterController::didBecomeFirstResponder() { void CurveParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) { if (cell == &m_derivativeCell) { SwitchView * switchView = (SwitchView *)m_derivativeCell.accessoryView(); - switchView->setState(m_displayDerivative); + switchView->setState(m_graphView->bannerView()->displayDerivative()); } } @@ -50,7 +49,7 @@ bool CurveParameterController::handleEvent(Ion::Events::Event event) { return true; } case 2: - m_displayDerivative = !m_displayDerivative; + m_graphView->bannerView()->setDisplayDerivative(!m_graphView->bannerView()->displayDerivative()); m_selectableTableView.reloadData(); return true; default: @@ -79,10 +78,6 @@ KDCoordinate CurveParameterController::cellHeight() { return 35; } -bool CurveParameterController::displayDerivative() const { - return m_displayDerivative; -} - void CurveParameterController::setFunction(Function * function) { m_function = function; } diff --git a/apps/graph/graph/curve_parameter_controller.h b/apps/graph/graph/curve_parameter_controller.h index fd2e49f11..e89608968 100644 --- a/apps/graph/graph/curve_parameter_controller.h +++ b/apps/graph/graph/curve_parameter_controller.h @@ -20,11 +20,9 @@ public: TableViewCell * reusableCell(int index) override; int reusableCellCount() override; void willDisplayCellForIndex(TableViewCell * cell, int index) override; - bool displayDerivative() const; void setFunction(Function * function); private: GraphView * m_graphView; - bool m_displayDerivative; Function * m_function; constexpr static int k_totalNumberOfCells = 3; ChevronMenuListCell m_calculationCell; diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index 409927a45..c04d9ccd5 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -19,17 +19,25 @@ GraphView::GraphView(FunctionStore * functionStore, GraphWindow * graphWindow) : { } +BannerView * GraphView::bannerView() { + return &m_bannerView; +} + int GraphView::numberOfSubviews() const { - return 1; + return 2; }; View * GraphView::subviewAtIndex(int index) { - assert(index == 0); - return &m_cursorView; + assert(index >= 0 && index < 2); + if (index == 0) { + return &m_cursorView; + } + return &m_bannerView; } void GraphView::setContext(Context * context) { m_context = context; + m_bannerView.setContext(context); } Context * GraphView::context() const { @@ -74,6 +82,7 @@ void GraphView::goToAbscissaOnFunction(float abscissa, Function * function) { float ordinate = function->evaluateAtAbscissa(abscissa, m_context); m_graphWindow->centerAxisAround(GraphWindow::Axis::Y, ordinate); m_yCursorPosition = floatToPixel(Axis::Vertical, ordinate); + updateBannerView(function); reload(); } @@ -89,6 +98,7 @@ void GraphView::initCursorPosition() { float fCenter = firstFunction->evaluateAtAbscissa(center, m_context); m_xCursorPosition = (bounds().width()-1.0f)/2.0f; m_yCursorPosition = floatToPixel(Axis::Vertical, fCenter); + updateBannerView(firstFunction); } void GraphView::moveCursorHorizontally(KDCoordinate xOffset) { @@ -102,6 +112,7 @@ void GraphView::moveCursorHorizontally(KDCoordinate xOffset) { bool windowHasMoved = m_graphWindow->panToMakePointVisible(x, y, xMargin, yMargin); m_xCursorPosition = floatToPixel(Axis::Horizontal, x); m_yCursorPosition = floatToPixel(Axis::Vertical, y); + updateBannerView(f); if (windowHasMoved) { reload(); } else { @@ -134,6 +145,7 @@ Function * GraphView::moveCursorVertically(int direction) { markRectAsDirty(KDRect(KDPoint(roundf(m_xCursorPosition) - k_cursorSize/2, roundf(m_yCursorPosition)- k_cursorSize/2), k_cursorSize, k_cursorSize)); m_xCursorPosition = floatToPixel(Axis::Horizontal, x); m_yCursorPosition = floatToPixel(Axis::Vertical, nextY); + updateBannerView(nextFunction); if (windowHasMoved) { reload(); } else { @@ -144,10 +156,13 @@ Function * GraphView::moveCursorVertically(int direction) { void GraphView::layoutSubviews() { KDRect cursorFrame(roundf(m_xCursorPosition) - k_cursorSize/2, roundf(m_yCursorPosition) - k_cursorSize/2, k_cursorSize, k_cursorSize); + KDRect bannerFrame(KDRect(0, bounds().height()- k_bannerHeight, bounds().width(), k_bannerHeight)); if (!m_visibleCursor) { cursorFrame = KDRectZero; + bannerFrame = KDRectZero; } m_cursorView.setFrame(cursorFrame); + m_bannerView.setFrame(bannerFrame); } void GraphView::drawRect(KDContext * ctx, KDRect rect) const { @@ -199,4 +214,9 @@ float GraphView::evaluateCurveAtAbscissa(void * curve, float abscissa) const { return f->evaluateAtAbscissa(abscissa, m_context); } +void GraphView::updateBannerView(Function * function) { + m_bannerView.setAbscissa(xCursorPosition()); + m_bannerView.setFunction(function); +} + } diff --git a/apps/graph/graph/graph_view.h b/apps/graph/graph/graph_view.h index 7bcfb4b29..11acba314 100644 --- a/apps/graph/graph/graph_view.h +++ b/apps/graph/graph/graph_view.h @@ -2,6 +2,7 @@ #define GRAPH_GRAPH_VIEW_H #include +#include "banner_view.h" #include "cursor_view.h" #include "graph_window.h" #include "../../curve_view.h" @@ -14,6 +15,7 @@ namespace Graph { class GraphView : public CurveView { public: GraphView(FunctionStore * functionStore, GraphWindow * graphWindow); + BannerView * bannerView(); void drawRect(KDContext * ctx, KDRect rect) const override; float xPixelCursorPosition(); @@ -32,6 +34,7 @@ private: constexpr static KDColor k_gridColor = KDColor::RGB24(0xEEEEEE); constexpr static KDCoordinate k_cursorSize = 9; constexpr static float k_cursorMarginToBorder = 6.0f; + constexpr static KDCoordinate k_bannerHeight = 30; int numberOfSubviews() const override; View * subviewAtIndex(int index) override; @@ -44,6 +47,9 @@ private: float evaluateCurveAtAbscissa(void * expression, float abscissa) const override; void drawGrid(KDContext * ctx, KDRect rect) const; void drawGridLines(KDContext * ctx, KDRect rect, Axis axis, float step, KDColor color) const; + void updateBannerView(Function * function); + + BannerView m_bannerView; CursorView m_cursorView; float m_xCursorPosition;