[apps] In curve view, avoid to reload the whole view when reloading

cursor

Change-Id: Ie8c0e100159201cc6b11122eeb567c68092a7b06
This commit is contained in:
Émilie Feral
2017-01-12 17:53:01 +01:00
parent 5b5dea0243
commit c19ecaeebe
11 changed files with 33 additions and 23 deletions

View File

@@ -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

View File

@@ -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);
};

View File

@@ -5,6 +5,7 @@
#include <poincare.h>
#include "curve_view_range.h"
#include "curve_view_cursor.h"
#include "banner_view.h"
#include <math.h>
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;

View File

@@ -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)
{

View File

@@ -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;

View File

@@ -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)
{

View File

@@ -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;

View File

@@ -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)),

View File

@@ -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);

View File

@@ -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)

View File

@@ -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);