Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 77 additions & 3 deletions Adafruit_GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r,
@param x0 Center-point x coordinate
@param y0 Center-point y coordinate
@param r Radius of circle
@param cornername Mask bit #1 or bit #2 to indicate which quarters of
@param cornername Mask bit #1, #2, #4, and #8 to indicate which quarters of
the circle we're doing
@param color 16-bit 5-6-5 Color to draw with
*/
Expand Down Expand Up @@ -574,11 +574,12 @@ void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r,

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

/**************************************************************************/
/*!
@brief Quarter-circle drawer with fill.
@param useLegacy uses the half-circle implementation if desired
@param x0 Center-point x coordinate
@param y0 Center-point y coordinate
@param r Radius of circle
@param corners Mask bit #1, #2, #4, and #8 to indicate which quarters of
the circle we're doing
@param delta Offset from center-point. Elongates the horizontal face if desired.
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void Adafruit_GFX::fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, int16_t r,
uint8_t corners, int16_t delta,
uint16_t color) {

int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
int16_t px = x;
int16_t py = y;

if(useLegacy){
fillCircleHelper(x0, y0, r, corners, delta, color);
return;
}

if (corners & (0x2 | 0x1))
writeFastVLine(x0, y0 - r, r + 1, color);
if (corners & (0x8 | 0x4))
writeFastVLine(x0, y0, r + 1, color);

delta++; // Avoid some +1's in the loop

while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
// These checks avoid double-drawing certain lines, important
// for the SSD1306 library which has an INVERT drawing mode.
if (x < (y + 1)) {
if (corners & 0x4)
writeFastVLine(x0 + x, y0, y + delta, color);
if (corners & 0x2)
writeFastVLine(x0 + x, y0 - y, y + delta, color);
if (corners & 0x8)
writeFastVLine(x0 - x, y0, y + delta, color);
if (corners & 0x1)
writeFastVLine(x0 - x, y0 - y, y + delta, color);
}
if (y != py) {
if (corners & 0x4)
writeFastVLine(x0 + py, y0, px + delta, color);
if (corners & 0x2)
writeFastVLine(x0 + py, y0 - px, px + delta, color);
if (corners & 0x8)
writeFastVLine(x0 - py, y0, px + delta, color);
if (corners & 0x1)
writeFastVLine(x0 - py, y0 - px, px + delta, color);
py = y;
}
px = x;
}
}

/**************************************************************************/
/*!
@brief Draw a rectangle with no fill color
Expand Down
2 changes: 2 additions & 0 deletions Adafruit_GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Adafruit_GFX : public Print {
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
int16_t delta, uint16_t color);
void fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, int16_t r,
uint8_t corners, int16_t delta, uint16_t color);
void drawEllipse(int16_t x0, int16_t y0, int16_t rw, int16_t rh,
uint16_t color);
void fillEllipse(int16_t x0, int16_t y0, int16_t rw, int16_t rh,
Expand Down
Loading