From 2dee8f2b1f22f2312ca3de56a87bde6618ce65af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 27 Sep 2019 17:37:11 +0200 Subject: [PATCH] [apps/regression] Fix cursor redrawing when changing cursor type Scenario: double x[numberOfPoints] = {0.0, 0.975, 1.97, 2.945, 3.971, 4.887, 5.924, 6.964, 7.979, 8.974, 9.998}; double y[numberOfPoints] = {-23.784, -23.322, -28.322, -18.422, -4.813206, 7.146241, 16.631, 16.632, 9.209189, -6.050863, -19.659}; Quadratic regression, navigate on the points then go on the regressioncurve -> there is a drawing glitch --- apps/regression/graph_controller.cpp | 19 +++++++++++++++---- apps/regression/graph_controller.h | 1 + apps/shared/round_cursor_view.h | 3 +++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp index 173254d6c..ffee0eed2 100644 --- a/apps/regression/graph_controller.cpp +++ b/apps/regression/graph_controller.cpp @@ -82,16 +82,16 @@ void GraphController::viewWillAppear() { /* Since *m_selectedDotIndex is altered by initCursorParameters(), * the following must absolutely come at the end. */ if (*m_selectedDotIndex >= 0) { - m_view.setCursorView(static_cast(&m_crossCursorView)); + setRoundCrossCursorView(false); } else { - m_view.setCursorView(static_cast(&m_roundCursorView)); + setRoundCrossCursorView(true); m_roundCursorView.setColor(Palette::DataColor[*m_selectedSeriesIndex]); } } void GraphController::selectRegressionCurve() { *m_selectedDotIndex = -1; - m_view.setCursorView(&m_roundCursorView); + setRoundCrossCursorView(true); m_roundCursorView.setColor(Palette::DataColor[*m_selectedSeriesIndex]); } @@ -334,7 +334,7 @@ bool GraphController::moveCursorVertically(int direction) { if (validDot) { // Select the dot - m_view.setCursorView(&m_crossCursorView); + setRoundCrossCursorView(false); *m_selectedSeriesIndex = closestDotSeries; *m_selectedDotIndex = dotSelected; if (dotSelected == m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex)) { @@ -404,4 +404,15 @@ InteractiveCurveViewRangeDelegate::Range GraphController::computeYRange(Interact return range; } +void GraphController::setRoundCrossCursorView(bool round) { + CursorView * nextCursorView = round ? static_cast(&m_roundCursorView) : static_cast(&m_crossCursorView); + if (m_view.cursorView() == nextCursorView) { + return; + } +#ifdef GRAPH_CURSOR_SPEEDUP + m_roundCursorView.resetMemoization(); +#endif + m_view.setCursorView(nextCursorView); +} + } diff --git a/apps/regression/graph_controller.h b/apps/regression/graph_controller.h index 310648af1..ad6c10529 100644 --- a/apps/regression/graph_controller.h +++ b/apps/regression/graph_controller.h @@ -55,6 +55,7 @@ private: // InteractiveCurveViewRangeDelegate Shared::InteractiveCurveViewRangeDelegate::Range computeYRange(Shared::InteractiveCurveViewRange * interactiveCurveViewRange) override; + void setRoundCrossCursorView(bool round); Shared::CursorView m_crossCursorView; Shared::RoundCursorView m_roundCursorView; BannerView m_bannerView; diff --git a/apps/shared/round_cursor_view.h b/apps/shared/round_cursor_view.h index 8e2fa5ef6..b84d7e07b 100644 --- a/apps/shared/round_cursor_view.h +++ b/apps/shared/round_cursor_view.h @@ -14,6 +14,9 @@ public: KDSize minimalSizeForOptimalDisplay() const override; void setColor(KDColor color); void setCursorFrame(KDRect frame) override; +#ifdef GRAPH_CURSOR_SPEEDUP + void resetMemoization() const { m_underneathPixelBufferLoaded = false; } +#endif private: #ifdef GRAPH_CURSOR_SPEEDUP bool eraseCursorIfPossible();