Skip to content

Commit 0cc05b4

Browse files
committed
create alternative fillCircleHelper
1 parent a969a70 commit 0cc05b4

2 files changed

Lines changed: 79 additions & 3 deletions

File tree

Adafruit_GFX.cpp

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r,
514514
@param x0 Center-point x coordinate
515515
@param y0 Center-point y coordinate
516516
@param r Radius of circle
517-
@param cornername Mask bit #1 or bit #2 to indicate which quarters of
517+
@param cornername Mask bit #1, #2, #4, and #8 to indicate which quarters of
518518
the circle we're doing
519519
@param color 16-bit 5-6-5 Color to draw with
520520
*/
@@ -574,11 +574,12 @@ void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r,
574574

575575
/**************************************************************************/
576576
/*!
577-
@brief Quarter-circle drawer with fill, used for circles and roundrects
577+
@brief Half-circle drawer with fill, used for circles and roundrects
578578
@param x0 Center-point x coordinate
579579
@param y0 Center-point y coordinate
580580
@param r Radius of circle
581-
@param corners Mask bits indicating which quarters we're doing
581+
@param corners Mask bits indicating which sides of the circle we are doing,
582+
left and/or right
582583
@param delta Offset from center-point, used for round-rects
583584
@param color 16-bit 5-6-5 Color to fill with
584585
*/
@@ -625,6 +626,79 @@ void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
625626
}
626627
}
627628

629+
/**************************************************************************/
630+
/*!
631+
@brief Quarter-circle drawer with fill.
632+
@param useLegacy uses the half-circle implementation if desired
633+
@param x0 Center-point x coordinate
634+
@param y0 Center-point y coordinate
635+
@param r Radius of circle
636+
@param corners Mask bit #1, #2, #4, and #8 to indicate which quarters of
637+
the circle we're doing
638+
@param delta Offset from center-point. Elongates the horizontal face if desired.
639+
@param color 16-bit 5-6-5 Color to fill with
640+
*/
641+
/**************************************************************************/
642+
void Adafruit_GFX::fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, int16_t r,
643+
uint8_t corners, int16_t delta,
644+
uint16_t color) {
645+
646+
int16_t f = 1 - r;
647+
int16_t ddF_x = 1;
648+
int16_t ddF_y = -2 * r;
649+
int16_t x = 0;
650+
int16_t y = r;
651+
int16_t px = x;
652+
int16_t py = y;
653+
654+
if(useLegacy){
655+
fillCircleHelper(x0, y0, r, corners, delta, color);
656+
return;
657+
}
658+
659+
if (corners & (0x2 | 0x1))
660+
writeFastVLine(x0, y0 - r, r + 1, color);
661+
if (corners & (0x8 | 0x4))
662+
writeFastVLine(x0, y0, r + 1, color);
663+
664+
delta++; // Avoid some +1's in the loop
665+
666+
while (x < y) {
667+
if (f >= 0) {
668+
y--;
669+
ddF_y += 2;
670+
f += ddF_y;
671+
}
672+
x++;
673+
ddF_x += 2;
674+
f += ddF_x;
675+
// These checks avoid double-drawing certain lines, important
676+
// for the SSD1306 library which has an INVERT drawing mode.
677+
if (x < (y + 1)) {
678+
if (corners & 0x4)
679+
writeFastVLine(x0 + x, y0, y + delta, color);
680+
if (corners & 0x2)
681+
writeFastVLine(x0 + x, y0 - y, y + delta, color);
682+
if (corners & 0x8)
683+
writeFastVLine(x0 - x, y0, y + delta, color);
684+
if (corners & 0x1)
685+
writeFastVLine(x0 - x, y0 - y, y + delta, color);
686+
}
687+
if (y != py) {
688+
if (corners & 0x4)
689+
writeFastVLine(x0 + py, y0, px + delta, color);
690+
if (corners & 0x2)
691+
writeFastVLine(x0 + py, y0 - px, px + delta, color);
692+
if (corners & 0x8)
693+
writeFastVLine(x0 - py, y0, px + delta, color);
694+
if (corners & 0x1)
695+
writeFastVLine(x0 - py, y0 - px, px + delta, color);
696+
py = y;
697+
}
698+
px = x;
699+
}
700+
}
701+
628702
/**************************************************************************/
629703
/*!
630704
@brief Draw a rectangle with no fill color

Adafruit_GFX.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class Adafruit_GFX : public Print {
7373
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
7474
void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
7575
int16_t delta, uint16_t color);
76+
void fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, int16_t r,
77+
uint8_t corners, int16_t delta, uint16_t color);
7678
void drawEllipse(int16_t x0, int16_t y0, int16_t rw, int16_t rh,
7779
uint16_t color);
7880
void fillEllipse(int16_t x0, int16_t y0, int16_t rw, int16_t rh,

0 commit comments

Comments
 (0)