Skip to content

Commit

Permalink
Add ARC to Circle #107
Browse files Browse the repository at this point in the history
  • Loading branch information
lexus2k committed Aug 8, 2023
1 parent e7ef92d commit 79394c1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
26 changes: 13 additions & 13 deletions src/canvas/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ template <uint8_t BPP> void NanoCanvasOps<BPP>::fillRect(const NanoRect &rect)
fillRect(rect.p1.x, rect.p1.y, rect.p2.x, rect.p2.y);
}

template <uint8_t BPP> void NanoCanvasOps<BPP>::drawCircle(lcdint_t xc, lcdint_t yc, lcdint_t r)
template <uint8_t BPP> void NanoCanvasOps<BPP>::drawCircle(lcdint_t xc, lcdint_t yc, lcdint_t r, uint8_t options)
{
if ( (xc + r < offset.x) || (yc + r < offset.y) || (xc - r >= (lcdint_t)m_w + offset.x) ||
(yc - r >= (lcdint_t)m_h - offset.y) )
Expand All @@ -117,10 +117,10 @@ template <uint8_t BPP> void NanoCanvasOps<BPP>::drawCircle(lcdint_t xc, lcdint_t
lcdint_t x = 0;
lcdint_t y = r;

putPixel(xc, yc + r);
putPixel(xc, yc - r);
putPixel(xc + r, yc);
putPixel(xc - r, yc);
if (options & (2+4)) putPixel(xc, yc + r);
if (options & (1+8)) putPixel(xc, yc - r);
if (options & (1+2)) putPixel(xc + r, yc);
if (options & (4+8)) putPixel(xc - r, yc);
while ( y >= x )
{
x++;
Expand All @@ -131,14 +131,14 @@ template <uint8_t BPP> void NanoCanvasOps<BPP>::drawCircle(lcdint_t xc, lcdint_t
}
d += 4 * x + 6;

putPixel(xc + x, yc + y);
putPixel(xc - x, yc + y);
putPixel(xc + x, yc - y);
putPixel(xc - x, yc - y);
putPixel(xc + y, yc + x);
putPixel(xc - y, yc + x);
putPixel(xc + y, yc - x);
putPixel(xc - y, yc - x);
if (options & (2)) putPixel(xc + x, yc + y);
if (options & (4)) putPixel(xc - x, yc + y);
if (options & (1)) putPixel(xc + x, yc - y);
if (options & (8)) putPixel(xc - x, yc - y);
if (options & (2)) putPixel(xc + y, yc + x);
if (options & (4)) putPixel(xc - y, yc + x);
if (options & (1)) putPixel(xc + y, yc - x);
if (options & (8)) putPixel(xc - y, yc - x);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/canvas/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ template <uint8_t BPP> class NanoCanvasOps
* @param x horizontal position of circle center in pixels
* @param y vertical position of circle center in pixels
* @param r circle radius in pixels
* @param options - lower bits correspond to 4 setions, where 1 means to draw, 0 - no
*/
void drawCircle(lcdint_t x, lcdint_t y, lcdint_t r) __attribute__((noinline));
void drawCircle(lcdint_t x, lcdint_t y, lcdint_t r, uint8_t options = 0x0F) __attribute__((noinline));

/**
* @brief Draws monochrome bitmap in color buffer using color, specified via setColor() method
Expand Down
3 changes: 2 additions & 1 deletion src/v2/lcd/base/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -1040,8 +1040,9 @@ template <class O, class I> class NanoDisplayOps: public O
* @param xc horizontal position of circle center in pixels
* @param yc vertical position of circle center in pixels
* @param r radius of circle in pixels
* @param options draw specific sections: each bit corresponds to 90 degree section
*/
void drawCircle(lcdint_t xc, lcdint_t yc, lcdint_t r);
void drawCircle(lcdint_t xc, lcdint_t yc, lcdint_t r, uint8_t options = 0x0F);

/**
* Draws 1-bit canvas on lcd display
Expand Down
26 changes: 13 additions & 13 deletions src/v2/lcd/base/ssd1306_common.inl
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,15 @@ template <class O, class I> void NanoDisplayOps<O, I>::fillRect(const NanoRect &
this->fillRect(rect.p1.x, rect.p1.y, rect.p2.x, rect.p2.y);
}

template <class O, class I> void NanoDisplayOps<O, I>::drawCircle(lcdint_t xc, lcdint_t yc, lcdint_t r)
template <class O, class I> void NanoDisplayOps<O, I>::drawCircle(lcdint_t xc, lcdint_t yc, lcdint_t r, uint8_t options)
{
lcdint_t d = 3 - 2 * r;
lcdint_t x = 0;
lcdint_t y = r;
putPixel(xc, yc + r);
putPixel(xc, yc - r);
putPixel(xc + r, yc);
putPixel(xc - r, yc);
if (options & (2 + 4)) putPixel(xc, yc + r);
if (options & (1 + 8)) putPixel(xc, yc - r);
if (options & (1 + 2)) putPixel(xc + r, yc);
if (options & (4 + 8)) putPixel(xc - r, yc);
while ( y >= x )
{
x++;
Expand All @@ -609,14 +609,14 @@ template <class O, class I> void NanoDisplayOps<O, I>::drawCircle(lcdint_t xc, l
d += -4 * y + 4;
}
d += 4 * x + 6;
putPixel(xc + x, yc + y);
putPixel(xc - x, yc + y);
putPixel(xc + x, yc - y);
putPixel(xc - x, yc - y);
putPixel(xc + y, yc + x);
putPixel(xc - y, yc + x);
putPixel(xc + y, yc - x);
putPixel(xc - y, yc - x);
if (options & (2)) putPixel(xc + x, yc + y);
if (options & (4)) putPixel(xc - x, yc + y);
if (options & (1)) putPixel(xc + x, yc - y);
if (options & (8)) putPixel(xc - x, yc - y);
if (options & (2)) putPixel(xc + y, yc + x);
if (options & (4)) putPixel(xc - y, yc + x);
if (options & (1)) putPixel(xc + y, yc - x);
if (options & (8)) putPixel(xc - y, yc - x);
}
}

Expand Down

0 comments on commit 79394c1

Please sign in to comment.