From d6093a2f186cd06a2a8b18555faff743d571ad81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 23 Feb 2017 17:54:05 +0100 Subject: [PATCH] [apps/sequence] Draw term sum in graph view Change-Id: Ib742dcf4949f87813b25779698b82cb454c7c1e5 --- apps/sequence/graph/graph_controller.cpp | 1 + apps/sequence/graph/graph_view.cpp | 44 ++++++++++++++++++++- apps/sequence/graph/graph_view.h | 8 ++++ apps/sequence/graph/term_sum_controller.cpp | 6 +++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/apps/sequence/graph/graph_controller.cpp b/apps/sequence/graph/graph_controller.cpp index 0b86a9602..a9a5c4641 100644 --- a/apps/sequence/graph/graph_controller.cpp +++ b/apps/sequence/graph/graph_controller.cpp @@ -19,6 +19,7 @@ void GraphController::viewWillAppear() { m_view.setVerticalCursor(false); m_view.setCursorView(&m_cursorView); m_view.setBannerView(&m_bannerView); + m_view.setHighlight(-1.0f, -1.0f); FunctionGraphController::viewWillAppear(); } diff --git a/apps/sequence/graph/graph_view.cpp b/apps/sequence/graph/graph_view.cpp index daaec69fc..352a9d1de 100644 --- a/apps/sequence/graph/graph_view.cpp +++ b/apps/sequence/graph/graph_view.cpp @@ -8,7 +8,11 @@ GraphView::GraphView(SequenceStore * sequenceStore, InteractiveCurveViewRange * CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) : FunctionGraphView(graphRange, cursor, bannerView, cursorView), m_sequenceStore(sequenceStore), - m_verticalCursor(false) + m_verticalCursor(false), + m_highlightedDotStart(-1), + m_highlightedDotEnd(-1), + m_highlightColor(false), + m_selectedSequence(nullptr) { } @@ -24,6 +28,14 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const { continue; } drawDot(ctx, rect, x, y, s->color()); + if (x >= m_highlightedDotStart && x <= m_highlightedDotEnd && s == m_selectedSequence) { + KDColor color = m_highlightColor ? s->color() : KDColorBlack; + if (y >= 0.0f) { + drawSegment(ctx, rect, Axis::Vertical, x, 0.0f, y, color, 1); + } else { + drawSegment(ctx, rect, Axis::Vertical, x, y, 0.0f, color, 1); + } + } } } } @@ -32,6 +44,36 @@ void GraphView::setVerticalCursor(bool verticalCursor) { m_verticalCursor = verticalCursor; } +void GraphView::reload() { + FunctionGraphView::reload(); + markRectAsDirty(bounds()); +} + +void GraphView::selectSequence(Sequence * sequence) { + if (m_selectedSequence != sequence) { + reload(); + m_selectedSequence = sequence; + reload(); + } +} + +void GraphView::setHighlight(int start, int end) { + if (m_highlightedDotStart != start || m_highlightedDotEnd != end) { + reload(); + m_highlightedDotStart = start; + m_highlightedDotEnd = end; + reload(); + } +} + +void GraphView::setHighlightColor(bool highlightColor) { + if (m_highlightColor != highlightColor) { + reload(); + m_highlightColor = highlightColor; + reload(); + } +} + float GraphView::evaluateModelWithParameter(Model * curve, float abscissa) const { Sequence * s = (Sequence *)curve; return s->evaluateAtAbscissa(abscissa, context()); diff --git a/apps/sequence/graph/graph_view.h b/apps/sequence/graph/graph_view.h index 34c0f70fa..93f741fef 100644 --- a/apps/sequence/graph/graph_view.h +++ b/apps/sequence/graph/graph_view.h @@ -12,11 +12,19 @@ public: Shared::CurveViewCursor * cursor, Shared::BannerView * bannerView, View * cursorView); void drawRect(KDContext * ctx, KDRect rect) const override; void setVerticalCursor(bool verticalCursor); + void reload() override; + void selectSequence(Sequence * sequence); + void setHighlight(int start, int end); + void setHighlightColor(bool highlightColor); private: float evaluateModelWithParameter(Model * expression, float abscissa) const override; KDSize cursorSize() override; SequenceStore * m_sequenceStore; bool m_verticalCursor; + int m_highlightedDotStart; + int m_highlightedDotEnd; + bool m_highlightColor; + Sequence * m_selectedSequence; }; } diff --git a/apps/sequence/graph/term_sum_controller.cpp b/apps/sequence/graph/term_sum_controller.cpp index 84720a1a4..3345d052e 100644 --- a/apps/sequence/graph/term_sum_controller.cpp +++ b/apps/sequence/graph/term_sum_controller.cpp @@ -39,6 +39,8 @@ void TermSumController::viewWillAppear() { m_contentView.graphView()->setCursorView(&m_cursorView); m_contentView.graphView()->setBannerView(nullptr); m_contentView.graphView()->selectMainView(true); + m_contentView.graphView()->setHighlightColor(false); + m_contentView.graphView()->setHighlight(-1.0f,-1.0f); m_contentView.graphView()->reload(); m_contentView.layoutSubviews(); @@ -101,6 +103,8 @@ bool TermSumController::handleEvent(Ion::Events::Event event) { TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); float sum = m_sequence->sumOfTermsBetweenAbscissa(m_startSum, m_endSum, myApp->localContext()); Complex::convertFloatToText(sum, buffer+2, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + m_contentView.graphView()->setHighlightColor(true); + m_contentView.graphView()->selectMainView(false); m_contentView.legendView()->setLegendText(buffer); } return false; @@ -121,6 +125,7 @@ bool TermSumController::moveCursorHorizontallyToPosition(int position) { m_contentView.legendView()->setSumSubscript(m_cursor->x()); } if (m_step == 1) { + m_contentView.graphView()->setHighlight(m_startSum, m_cursor->x()); m_contentView.legendView()->setSumSuperscript(m_startSum, m_cursor->x()); } m_graphRange->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); @@ -128,6 +133,7 @@ bool TermSumController::moveCursorHorizontallyToPosition(int position) { } void TermSumController::setSequence(Sequence * sequence) { + m_contentView.graphView()->selectSequence(sequence); m_sequence = sequence; }