From 28dddb42af18ace8599615b33e14b5dd23bdeff2 Mon Sep 17 00:00:00 2001 From: Joachim LF Date: Wed, 30 Dec 2020 11:23:47 +0100 Subject: [PATCH] Changed color_cell to a circle --- apps/shared/color_cell.cpp | 6 ++++-- apps/shared/color_cell.h | 1 + kandinsky/Makefile | 1 + kandinsky/include/kandinsky/context.h | 6 ++++++ kandinsky/src/context_circle.cpp | 31 +++++++++++++++++++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 kandinsky/src/context_circle.cpp diff --git a/apps/shared/color_cell.cpp b/apps/shared/color_cell.cpp index 261e5cb6b..5d7d421af 100644 --- a/apps/shared/color_cell.cpp +++ b/apps/shared/color_cell.cpp @@ -1,4 +1,5 @@ #include "color_cell.h" +#include namespace Shared { @@ -42,11 +43,12 @@ MessageTableCellWithColor::ColorView::ColorView() : {} void MessageTableCellWithColor::ColorView::drawRect(KDContext * ctx, KDRect rect) const { - ctx->fillRect(bounds(), Palette::DataColor[m_index]); + KDPoint center(bounds().x() + k_radius, bounds().y() + (Metric::ParameterCellHeight)/2 - k_radius + 5); + ctx->fillCircle(center, k_radius, Palette::DataColor[m_index]); } KDSize MessageTableCellWithColor::ColorView::minimalSizeForOptimalDisplay() const { - return KDSize(10, 10); + return KDSize(k_radius*2, k_radius*2); } } diff --git a/apps/shared/color_cell.h b/apps/shared/color_cell.h index a614ae5c9..0ec890608 100644 --- a/apps/shared/color_cell.h +++ b/apps/shared/color_cell.h @@ -24,6 +24,7 @@ private: constexpr static KDCoordinate k_chevronWidth = 8; private: int m_index; + constexpr static int k_radius = 9; }; ColorView m_accessoryView; constexpr static I18n::Message k_textForIndex[] = { diff --git a/kandinsky/Makefile b/kandinsky/Makefile index 1e1ad24ff..376197384 100644 --- a/kandinsky/Makefile +++ b/kandinsky/Makefile @@ -2,6 +2,7 @@ SFLAGS += -Ikandinsky/include kandinsky_src += $(addprefix kandinsky/src/,\ color.cpp \ + context_circle.cpp \ context_line.cpp \ context_pixel.cpp \ context_rect.cpp \ diff --git a/kandinsky/include/kandinsky/context.h b/kandinsky/include/kandinsky/context.h index fbcc6bf4f..2ddd3f315 100644 --- a/kandinsky/include/kandinsky/context.h +++ b/kandinsky/include/kandinsky/context.h @@ -28,6 +28,10 @@ public: void fillRectWithPixels(KDRect rect, const KDColor * pixels, KDColor * workingBuffer); void blendRectWithMask(KDRect rect, KDColor color, const uint8_t * mask, KDColor * workingBuffer); void strokeRect(KDRect rect, KDColor color); + + // Circle + void fillCircle(KDPoint center, KDCoordinate radius, KDColor c); + protected: KDContext(KDPoint origin, KDRect clippingRect) : m_origin(origin), @@ -39,6 +43,8 @@ protected: private: KDRect absoluteFillRect(KDRect rect); KDPoint pushOrPullString(const char * text, KDPoint p, const KDFont * font, KDColor textColor, KDColor backgroundColor, int maxByteLength, bool push, int * result = nullptr); + void horizontalLine(KDPoint begin, KDCoordinate length, KDColor c); + void verticalLine(KDPoint begin, KDCoordinate length, KDColor c); KDPoint m_origin; KDRect m_clippingRect; }; diff --git a/kandinsky/src/context_circle.cpp b/kandinsky/src/context_circle.cpp new file mode 100644 index 000000000..ca5556b9d --- /dev/null +++ b/kandinsky/src/context_circle.cpp @@ -0,0 +1,31 @@ +#include +#include + +void KDContext::fillCircle(KDPoint center, KDCoordinate radius, KDColor c) { // FIXME The circle doesn't look like a circle + KDPoint p(0, radius); + KDCoordinate m(5 - 4*radius); + while(p.x()<=p.y()) { + horizontalLine(KDPoint(center.x()-p.x(), p.y()+center.y()), 2*p.x(),c); + horizontalLine(KDPoint(center.x()-p.x(), center.y()-p.y()),2*p.x(),c); + verticalLine(KDPoint(center.x()-p.x(),center.y()-p.y()),2*p.y(),c); + verticalLine(KDPoint(center.x()+p.x(),center.y()-p.y()),2*p.y(),c); + if (m>0) { + p = KDPoint(p.x(), p.y()-1); + m-=8*p.x()+4; + } + p = KDPoint(p.x()+1,p.y()); + m+=8*p.x()+4; + } +} + +void KDContext::horizontalLine(KDPoint begin, KDCoordinate length, KDColor c) { + for(KDCoordinate i = 0; i < length; i++){ + setPixel(KDPoint(begin.x() + i, begin.y()), c); + } +} + +void KDContext::verticalLine(KDPoint begin, KDCoordinate length, KDColor c) { + for(KDCoordinate i = 0; i < length; i++){ + setPixel(KDPoint(begin.x(), begin.y() + i), c); + } +}