Chybejici vypln kruhu

This commit is contained in:
Pavel Brychta 2021-07-08 12:58:56 +02:00
parent 894973a9e7
commit eded1d270a

View File

@ -1080,3 +1080,54 @@ void OLEDDisplay::drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int1
drawCircleQuads(x+w-r-1, y+h-r-1, r, 8);
drawCircleQuads(x+r , y+h-r-1, r, 4);
}
/**************************************************************************/
/*!
@brief Quarter-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 delta Offset from center-point, used for round-rects
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void OLEDDisplay::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
uint8_t corners, int16_t delta) {
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;
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 & 1)
drawVerticalLine(x0 + x, y0 - y, 2 * y + delta);
if (corners & 2)
drawVerticalLine(x0 - x, y0 - y, 2 * y + delta);
}
if (y != py) {
if (corners & 1)
drawVerticalLine(x0 + py, y0 - px, 2 * px + delta);
if (corners & 2)
drawVerticalLine(x0 - py, y0 - px, 2 * px + delta);
py = y;
}
px = x;
}
}