From 4842d230bd6f0fc22c8409c808df71b88492b0c6 Mon Sep 17 00:00:00 2001 From: 3djc Date: Sat, 17 Oct 2020 09:38:24 +0200 Subject: [PATCH 1/7] Add drawLine function --- .../thirdparty/libopenui/src/bitmapbuffer.cpp | 53 +++++++++++++++++++ .../thirdparty/libopenui/src/bitmapbuffer.h | 2 + .../libopenui/src/libopenui_helpers.h | 6 +++ 3 files changed, 61 insertions(+) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index 197c77208..7dceba807 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -126,6 +126,57 @@ void BitmapBuffer::drawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat } } +void BitmapBuffer::drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att) +{ + // Offsets + x1 += this->offsetX; + y1 += this->offsetY; + x2 += this->offsetX; + y2 += this->offsetY; + + pixel_t color = lcdColorTable[COLOR_IDX(att)]; + + int dx = x2 - x1; /* the horizontal distance of the line */ + int dy = y2 - y1; /* the vertical distance of the line */ + int dxabs = abs(dx); + int dyabs = abs(dy); + int sdx = sgn(dx); + int sdy = sgn(dy); + int x = dyabs >> 1; + int y = dxabs >> 1; + int px = x1; + int py = y1; + + if (dxabs >= dyabs) { + /* the line is more horizontal than vertical */ + for (int i = 0; i <= dxabs; i++) { + if ((1 << (px % 8)) & pat) { + drawPixel(px, py, color); + } + y += dyabs; + if (y >= dxabs) { + y -= dxabs; + py += sdy; + } + px += sdx; + } + } else { + /* the line is more vertical than horizontal */ + for (int i = 0; i <= dyabs; i++) { + if ((1 << (py % 8)) & pat) { + drawPixel(px, py, color); + } + x += dxabs; + if (x >= dyabs) { + x -= dyabs; + px += sdx; + } + py += sdy; + } + } +} + + void BitmapBuffer::drawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness, uint8_t pat, LcdFlags att) { for (int i=0; idrawSolidFilledRect(x, y, thickness, h, att); diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h index adfd435f4..e0243e56d 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h @@ -327,6 +327,8 @@ class BitmapBuffer: public BitmapBufferBase void drawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat = SOLID, LcdFlags flags = 0); + void drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att); + inline void drawSolidHorizontalLine(coord_t x, coord_t y, coord_t w, LcdFlags flags) { drawSolidFilledRect(x, y, w, 1, flags); diff --git a/radio/src/thirdparty/libopenui/src/libopenui_helpers.h b/radio/src/thirdparty/libopenui/src/libopenui_helpers.h index 640f05046..508dd1548 100644 --- a/radio/src/thirdparty/libopenui/src/libopenui_helpers.h +++ b/radio/src/thirdparty/libopenui/src/libopenui_helpers.h @@ -53,6 +53,12 @@ inline int divRoundClosest(const int n, const int d) return ((n < 0) ^ (d < 0)) ? ((n - d/2)/d) : ((n + d/2)/d); } +template +inline T sgn(T a) +{ + return a > 0 ? 1 : (a < 0 ? -1 : 0); +} + // TODO duplicated code inline std::string TEXT_AT_INDEX(const char * val, uint8_t idx) { From b13c383a4ded17d60610974e4d7233572191eab9 Mon Sep 17 00:00:00 2001 From: 3djc Date: Sat, 17 Oct 2020 09:39:54 +0200 Subject: [PATCH 2/7] Cosmetics --- radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index 7dceba807..09a0af32b 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -678,8 +678,6 @@ coord_t BitmapBuffer::drawNumber(coord_t x, coord_t y, int32_t val, LcdFlags fla return drawText(x, y, s, flags); } - - void drawSolidRect(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness, LcdFlags att) { dc->drawSolidFilledRect(x, y, thickness, h, att); From 2c0e4df2eb1467b1f73704c64c607508800737cd Mon Sep 17 00:00:00 2001 From: 3djc Date: Sat, 17 Oct 2020 10:13:39 +0200 Subject: [PATCH 3/7] Cosmetics --- radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index 09a0af32b..dd86e51c8 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -126,13 +126,12 @@ void BitmapBuffer::drawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat } } -void BitmapBuffer::drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att) -{ +void BitmapBuffer::drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att) { // Offsets - x1 += this->offsetX; - y1 += this->offsetY; - x2 += this->offsetX; - y2 += this->offsetY; + x1 += offsetX; + y1 += offsetY; + x2 += offsetX; + y2 += offsetY; pixel_t color = lcdColorTable[COLOR_IDX(att)]; From 7f1ec0206630fdd45ba375c1325978e94289481b Mon Sep 17 00:00:00 2001 From: 3djc Date: Sat, 17 Oct 2020 10:23:54 +0200 Subject: [PATCH 4/7] Cosmetics --- .../thirdparty/libopenui/src/bitmapbuffer.cpp | 88 ++++++++++--------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index dd86e51c8..f66cc0ee9 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -126,53 +126,55 @@ void BitmapBuffer::drawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat } } -void BitmapBuffer::drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att) { - // Offsets - x1 += offsetX; - y1 += offsetY; - x2 += offsetX; - y2 += offsetY; +void BitmapBuffer::drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att) +{ + // Offsets + x1 += offsetX; + y1 += offsetY; + x2 += offsetX; + y2 += offsetY; - pixel_t color = lcdColorTable[COLOR_IDX(att)]; + pixel_t color = lcdColorTable[COLOR_IDX(att)]; - int dx = x2 - x1; /* the horizontal distance of the line */ - int dy = y2 - y1; /* the vertical distance of the line */ - int dxabs = abs(dx); - int dyabs = abs(dy); - int sdx = sgn(dx); - int sdy = sgn(dy); - int x = dyabs >> 1; - int y = dxabs >> 1; - int px = x1; - int py = y1; + int dx = x2 - x1; /* the horizontal distance of the line */ + int dy = y2 - y1; /* the vertical distance of the line */ + int dxabs = abs(dx); + int dyabs = abs(dy); + int sdx = sgn(dx); + int sdy = sgn(dy); + int x = dyabs >> 1; + int y = dxabs >> 1; + int px = x1; + int py = y1; - if (dxabs >= dyabs) { - /* the line is more horizontal than vertical */ - for (int i = 0; i <= dxabs; i++) { - if ((1 << (px % 8)) & pat) { - drawPixel(px, py, color); - } - y += dyabs; - if (y >= dxabs) { - y -= dxabs; - py += sdy; - } - px += sdx; - } - } else { - /* the line is more vertical than horizontal */ - for (int i = 0; i <= dyabs; i++) { - if ((1 << (py % 8)) & pat) { - drawPixel(px, py, color); - } - x += dxabs; - if (x >= dyabs) { - x -= dyabs; - px += sdx; - } - py += sdy; - } + if (dxabs >= dyabs) { + /* the line is more horizontal than vertical */ + for (int i = 0; i <= dxabs; i++) { + if ((1 << (px % 8)) & pat) { + drawPixel(px, py, color); + } + y += dyabs; + if (y >= dxabs) { + y -= dxabs; + py += sdy; + } + px += sdx; } + } + else { + /* the line is more vertical than horizontal */ + for (int i = 0; i <= dyabs; i++) { + if ((1 << (py % 8)) & pat) { + drawPixel(px, py, color); + } + x += dxabs; + if (x >= dyabs) { + x -= dyabs; + px += sdx; + } + py += sdy; + } + } } From 53afe96cb5fee93d66ab0245626ea855b475c747 Mon Sep 17 00:00:00 2001 From: 3djc Date: Sat, 17 Oct 2020 10:24:27 +0200 Subject: [PATCH 5/7] Add clion codestyle --- .../libopenui/.idea/codeStyles/Project.xml | 32 +++++++++++++++++++ .../.idea/codeStyles/codeStyleConfig.xml | 5 +++ 2 files changed, 37 insertions(+) create mode 100644 radio/src/thirdparty/libopenui/.idea/codeStyles/Project.xml create mode 100644 radio/src/thirdparty/libopenui/.idea/codeStyles/codeStyleConfig.xml diff --git a/radio/src/thirdparty/libopenui/.idea/codeStyles/Project.xml b/radio/src/thirdparty/libopenui/.idea/codeStyles/Project.xml new file mode 100644 index 000000000..efad3ce27 --- /dev/null +++ b/radio/src/thirdparty/libopenui/.idea/codeStyles/Project.xml @@ -0,0 +1,32 @@ + + + + \ No newline at end of file diff --git a/radio/src/thirdparty/libopenui/.idea/codeStyles/codeStyleConfig.xml b/radio/src/thirdparty/libopenui/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 000000000..79ee123c2 --- /dev/null +++ b/radio/src/thirdparty/libopenui/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file From cda1c440ab4d473cb35ebab549b42ba3928ef04e Mon Sep 17 00:00:00 2001 From: 3djc Date: Sat, 17 Oct 2020 10:26:57 +0200 Subject: [PATCH 6/7] cosmetics --- radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index f66cc0ee9..3f53642a2 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -126,7 +126,7 @@ void BitmapBuffer::drawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat } } -void BitmapBuffer::drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att) +void BitmapBuffer::drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags flags) { // Offsets x1 += offsetX; @@ -134,7 +134,7 @@ void BitmapBuffer::drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint x2 += offsetX; y2 += offsetY; - pixel_t color = lcdColorTable[COLOR_IDX(att)]; + pixel_t color = lcdColorTable[COLOR_IDX(flags)]; int dx = x2 - x1; /* the horizontal distance of the line */ int dy = y2 - y1; /* the vertical distance of the line */ From de8f4f37f2312ef021013646ab2dbc0a378a8cf0 Mon Sep 17 00:00:00 2001 From: 3djc Date: Sat, 17 Oct 2020 10:27:47 +0200 Subject: [PATCH 7/7] cosmetics --- radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index 3f53642a2..dcd492a21 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -177,7 +177,6 @@ void BitmapBuffer::drawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint } } - void BitmapBuffer::drawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness, uint8_t pat, LcdFlags att) { for (int i=0; i