From c19ecaeebead3fd3aac2bbd21d6e226a3fe1308a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 12 Jan 2017 17:53:01 +0100 Subject: [PATCH] [apps] In curve view, avoid to reload the whole view when reloading cursor Change-Id: Ie8c0e100159201cc6b11122eeb567c68092a7b06 --- apps/banner_view.cpp | 1 + apps/curve_view.cpp | 29 ++++++++++++++++++----------- apps/curve_view.h | 6 ++++-- apps/graph/graph/graph_view.cpp | 4 ++-- apps/graph/graph/graph_view.h | 2 +- apps/regression/graph_view.cpp | 2 +- apps/regression/graph_view.h | 2 +- apps/statistics/box_view.cpp | 2 +- apps/statistics/box_view.h | 2 +- apps/statistics/histogram_view.cpp | 4 ++-- apps/statistics/histogram_view.h | 2 +- 11 files changed, 33 insertions(+), 23 deletions(-) diff --git a/apps/banner_view.cpp b/apps/banner_view.cpp index f7c388422..e359c3837 100644 --- a/apps/banner_view.cpp +++ b/apps/banner_view.cpp @@ -20,6 +20,7 @@ int BannerView::numberOfSubviews() const { } void BannerView::layoutSubviews() { + markRectAsDirty(bounds()); /* We iterate on subviews, adding their width until we exceed the view bound. * The last subview that exceeds the bound is recorded as the first subview of * the next line. For the current line, we scan again the subviews and frame diff --git a/apps/curve_view.cpp b/apps/curve_view.cpp index 904d0098c..45f09d7a0 100644 --- a/apps/curve_view.cpp +++ b/apps/curve_view.cpp @@ -8,7 +8,7 @@ constexpr KDColor CurveView::k_axisColor; constexpr KDColor CurveView::k_gridColor; -CurveView::CurveView(CurveViewRange * curveViewRange, CurveViewCursor * curveViewCursor, View * bannerView, +CurveView::CurveView(CurveViewRange * curveViewRange, CurveViewCursor * curveViewCursor, BannerView * bannerView, View * cursorView, float topMarginFactor, float rightMarginFactor, float bottomMarginFactor, float leftMarginFactor) : View(), @@ -40,7 +40,10 @@ void CurveView::reloadSelection() { float pixelYSelection = roundf(floatToPixel(Axis::Vertical, m_curveViewCursor->y())); KDRect dirtyZone(KDRect(pixelXSelection - k_cursorSize/2, pixelYSelection - k_cursorSize/2, k_cursorSize, k_cursorSize)); markRectAsDirty(dirtyZone); - layoutSubviews(); + layoutCursor(); + if (m_bannerView != nullptr) { + m_bannerView->layoutSubviews(); + } } } @@ -392,15 +395,7 @@ void CurveView::stampAtLocation(KDContext * ctx, KDRect rect, float pxf, float p } void CurveView::layoutSubviews() { - if (m_curveViewCursor != nullptr && m_cursorView != nullptr) { - KDCoordinate xCursorPixelPosition = roundf(floatToPixel(Axis::Horizontal, m_curveViewCursor->x())); - KDCoordinate yCursorPixelPosition = roundf(floatToPixel(Axis::Vertical, m_curveViewCursor->y())); - KDRect cursorFrame(xCursorPixelPosition - k_cursorSize/2, yCursorPixelPosition - k_cursorSize/2, k_cursorSize, k_cursorSize); - if (!m_mainViewSelected) { - cursorFrame = KDRectZero; - } - m_cursorView->setFrame(cursorFrame); - } + layoutCursor(); if (m_bannerView != nullptr) { m_bannerView->setFrame(bounds()); KDCoordinate bannerHeight = m_bannerView->minimalSizeForOptimalDisplay().height(); @@ -412,6 +407,18 @@ void CurveView::layoutSubviews() { } } +void CurveView::layoutCursor() { + if (m_curveViewCursor != nullptr && m_cursorView != nullptr) { + KDCoordinate xCursorPixelPosition = roundf(floatToPixel(Axis::Horizontal, m_curveViewCursor->x())); + KDCoordinate yCursorPixelPosition = roundf(floatToPixel(Axis::Vertical, m_curveViewCursor->y())); + KDRect cursorFrame(xCursorPixelPosition - k_cursorSize/2, yCursorPixelPosition - k_cursorSize/2, k_cursorSize, k_cursorSize); + if (!m_mainViewSelected) { + cursorFrame = KDRectZero; + } + m_cursorView->setFrame(cursorFrame); + } +} + int CurveView::numberOfSubviews() const { return (m_bannerView != nullptr) + (m_cursorView != nullptr); }; diff --git a/apps/curve_view.h b/apps/curve_view.h index d859b9547..2705d6965 100644 --- a/apps/curve_view.h +++ b/apps/curve_view.h @@ -5,6 +5,7 @@ #include #include "curve_view_range.h" #include "curve_view_cursor.h" +#include "banner_view.h" #include class CurveView : public View { @@ -15,7 +16,7 @@ public: Vertical = 1 }; CurveView(CurveViewRange * curveViewRange = nullptr, CurveViewCursor * curveViewCursor = nullptr, - View * bannerView = nullptr, View * cursorView = nullptr, float topMarginFactor = 0.0f, + BannerView * bannerView = nullptr, View * cursorView = nullptr, float topMarginFactor = 0.0f, float rightMarginFactor = 0.0f, float bottomMarginFactor = 0.0f, float leftMarginFactor = 0.0f); // Reload methods void reload(); @@ -71,13 +72,14 @@ private: * anti alising. */ void stampAtLocation(KDContext * ctx, KDRect rect, float pxf, float pyf, KDColor color) const; void layoutSubviews() override; + void layoutCursor(); int numberOfSubviews() const override; View * subviewAtIndex(int index) override; /* m_curveViewRange has to be non null but the cursor model, the banner and * cursor views may be nullptr if not needed. */ CurveViewRange * m_curveViewRange; CurveViewCursor * m_curveViewCursor; - View * m_bannerView; + BannerView * m_bannerView; View * m_cursorView; bool m_mainViewSelected; float m_topMarginFactor; diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index 22aab8543..1d8be6374 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -5,8 +5,8 @@ namespace Graph { -GraphView::GraphView(FunctionStore * functionStore, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, View * bannerView, View * cursorView) : - CurveView(graphRange, cursor, bannerView, cursorView, 0.0f, 0.0f, 0.2f, 0.0f), +GraphView::GraphView(FunctionStore * functionStore, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, ::BannerView * bannerView, View * cursorView) : + CurveView(graphRange, cursor, bannerView, cursorView, 0.0f, 0.0f, 0.1f, 0.0f), m_functionStore(functionStore), m_context(nullptr) { diff --git a/apps/graph/graph/graph_view.h b/apps/graph/graph/graph_view.h index 4f2469ee3..5ada72f3c 100644 --- a/apps/graph/graph/graph_view.h +++ b/apps/graph/graph/graph_view.h @@ -11,7 +11,7 @@ namespace Graph { class GraphView : public CurveView { public: - GraphView(FunctionStore * functionStore, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, View * bannerView, View * cursorView); + GraphView(FunctionStore * functionStore, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, ::BannerView * bannerView, View * cursorView); void drawRect(KDContext * ctx, KDRect rect) const override; void setContext(Context * context); Context * context() const; diff --git a/apps/regression/graph_view.cpp b/apps/regression/graph_view.cpp index 310fe76d0..970708ae2 100644 --- a/apps/regression/graph_view.cpp +++ b/apps/regression/graph_view.cpp @@ -4,7 +4,7 @@ namespace Regression { -GraphView::GraphView(Store * store, CurveViewCursor * cursor, View * bannerView, View * cursorView) : +GraphView::GraphView(Store * store, CurveViewCursor * cursor, ::BannerView * bannerView, View * cursorView) : CurveView(store, cursor, bannerView, cursorView, 0.05f, 0.05f, 0.25f, 0.05f), m_store(store) { diff --git a/apps/regression/graph_view.h b/apps/regression/graph_view.h index 2df77cb6a..35a94b6da 100644 --- a/apps/regression/graph_view.h +++ b/apps/regression/graph_view.h @@ -10,7 +10,7 @@ namespace Regression { class GraphView : public CurveView { public: - GraphView(Store * store, CurveViewCursor * cursor, View * bannerView, View * cursorView); + GraphView(Store * store, CurveViewCursor * cursor, ::BannerView * bannerView, View * cursorView); void drawRect(KDContext * ctx, KDRect rect) const override; private: constexpr static KDCoordinate k_dotSize = 5; diff --git a/apps/statistics/box_view.cpp b/apps/statistics/box_view.cpp index f772df799..96ee62007 100644 --- a/apps/statistics/box_view.cpp +++ b/apps/statistics/box_view.cpp @@ -4,7 +4,7 @@ namespace Statistics { -BoxView::BoxView(Store * store, View * bannerView) : +BoxView::BoxView(Store * store, ::BannerView * bannerView) : CurveView(&m_boxRange, nullptr, bannerView, nullptr, 0.0f, 0.2f, 0.4f, 0.2f), m_store(store), m_boxRange(BoxRange(store)), diff --git a/apps/statistics/box_view.h b/apps/statistics/box_view.h index 398b66a7a..431aeb82f 100644 --- a/apps/statistics/box_view.h +++ b/apps/statistics/box_view.h @@ -19,7 +19,7 @@ public: ThirdQuartile = 3, Max = 4 }; - BoxView(Store * store, View * bannerView); + BoxView(Store * store, ::BannerView * bannerView); void reloadSelection() override; Quantile selectedQuantile(); bool selectQuantile(int selectedQuantile); diff --git a/apps/statistics/histogram_view.cpp b/apps/statistics/histogram_view.cpp index 966005d6c..f5b78cd6e 100644 --- a/apps/statistics/histogram_view.cpp +++ b/apps/statistics/histogram_view.cpp @@ -4,8 +4,8 @@ namespace Statistics { -HistogramView::HistogramView(Store * store, View * bannerView) : - CurveView(store, nullptr, bannerView, nullptr, 0.2f, 0.1f, 0.4f, 0.1f), +HistogramView::HistogramView(Store * store, ::BannerView * bannerView) : + CurveView(store, nullptr, bannerView, nullptr, 0.2f, 0.05f, 0.4f, 0.05f), m_store(store), m_highlightedBarStart(NAN), m_highlightedBarEnd(NAN) diff --git a/apps/statistics/histogram_view.h b/apps/statistics/histogram_view.h index 3c2676420..e6aedca20 100644 --- a/apps/statistics/histogram_view.h +++ b/apps/statistics/histogram_view.h @@ -10,7 +10,7 @@ namespace Statistics { class HistogramView : public CurveView { public: - HistogramView(Store * store, View * bannerView); + HistogramView(Store * store, ::BannerView * bannerView); void reloadSelection() override; void drawRect(KDContext * ctx, KDRect rect) const override; void setHighlight(float start, float end);