From 11787aee4e574c9850a3257c022d76c5cfc484c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 30 Dec 2016 12:21:20 +0100 Subject: [PATCH] [apps] Add a method drawDot in curve view Change-Id: Ic6b421ebe094aeeaa110a009d9251f0464941db1 --- apps/curve_view.cpp | 13 ++++++++++++- apps/curve_view.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/curve_view.cpp b/apps/curve_view.cpp index 0dc9932df..d547e8df0 100644 --- a/apps/curve_view.cpp +++ b/apps/curve_view.cpp @@ -147,6 +147,18 @@ void CurveView::drawSegment(KDContext * ctx, KDRect rect, Axis axis, float coord } } +void CurveView::drawDot(KDContext * ctx, KDRect rect, float x, float y, KDColor color, KDSize size) const { + KDCoordinate px = roundf(floatToPixel(Axis::Horizontal, x)); + KDCoordinate py = roundf(floatToPixel(Axis::Vertical, y)); + if ((px - size.width() < rect.left() - k_externRectMargin || px + size.width() > rect.right() + k_externRectMargin) && + (py - size.height() < rect.top() - k_externRectMargin || py + size.height() > rect.bottom() + k_externRectMargin)) { + return; + } + KDRect dotRect = KDRect(px - size.width()/2, py-size.height()/2, size.width(), size.height()); + ctx->fillRect(dotRect, color); +} + + void CurveView::drawAxes(KDContext * ctx, KDRect rect, Axis axis) const { drawLine(ctx, rect, axis, 0.0f, k_axisColor, 2); } @@ -183,7 +195,6 @@ const uint8_t stampMask[stampSize+1][stampSize+1] = { constexpr static int k_maxNumberOfIterations = 10; constexpr static int k_resolution = 320.0f; -constexpr static int k_externRectMargin = 1; void CurveView::drawCurve(KDContext * ctx, KDRect rect, Model * curve, KDColor color, bool colorUnderCurve, float colorLowerBound, float colorUpperBound, bool continuously) const { float xMin = min(Axis::Horizontal); diff --git a/apps/curve_view.h b/apps/curve_view.h index 552cf3b27..9ecb67420 100644 --- a/apps/curve_view.h +++ b/apps/curve_view.h @@ -36,6 +36,7 @@ protected: void drawSegment(KDContext * ctx, KDRect rect, Axis axis, float coordinate, float lowerBound, float upperBound, KDColor color, KDCoordinate thickness = 1) const; + void drawDot(KDContext * ctx, KDRect rect, float x, float y, KDColor color, KDSize size) const; void drawAxes(KDContext * ctx, KDRect rect, Axis axis) const; void drawCurve(KDContext * ctx, KDRect rect, Model * curve, KDColor color, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f, bool continuously = false) const; void drawHistogram(KDContext * ctx, KDRect rect, Model * model, float firstBarAbscissa, float barWidth, @@ -43,6 +44,7 @@ protected: void computeLabels(Axis axis); void drawLabels(KDContext * ctx, KDRect rect, Axis axis, bool shiftOrigin) const; private: + constexpr static int k_externRectMargin = 1; int numberOfLabels(Axis axis) const; virtual float evaluateModelWithParameter(Model * curve, float t) const; /* Recursively join two dots (dichotomy). The method stops when the