From eded1d270a7b75bd8644ce212879edbaee343a51 Mon Sep 17 00:00:00 2001 From: Pavel Brychta Date: Thu, 8 Jul 2021 12:58:56 +0200 Subject: [PATCH] Chybejici vypln kruhu --- src/OLEDDisplay.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/OLEDDisplay.cpp b/src/OLEDDisplay.cpp index 409c97a..5dd0398 100644 --- a/src/OLEDDisplay.cpp +++ b/src/OLEDDisplay.cpp @@ -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; + } +}