Skip to content

Commit

Permalink
Added draw circle methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lexus2k committed Sep 13, 2020
1 parent 969022b commit 5fca7cf
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/canvas/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,43 @@ 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)
{
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))
{
return;
}
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);
while (y >= x)
{
x++;
if (d > 0)
{
y--;
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);
}
}

template <uint8_t BPP>
uint8_t NanoCanvasOps<BPP>::printChar(uint8_t c)
{
Expand Down
8 changes: 8 additions & 0 deletions src/canvas/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ class NanoCanvasOps
*/
void fillRect(const NanoRect &rect);

/**
* Draws circle
* @param x horizontal position of circle center in pixels
* @param y vertical position of circle center in pixels
* @param r circle radius in pixels
*/
void drawCircle(lcdint_t x, lcdint_t y, lcdint_t r) __attribute__ ((noinline));

/**
* @brief Draws monochrome bitmap in color buffer using color, specified via setColor() method
* Draws monochrome bitmap in color buffer using color, specified via setColor() method
Expand Down
8 changes: 8 additions & 0 deletions src/v2/lcd/base/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,14 @@ class NanoDisplayOps: public O
*/
void fillRect(const NanoRect &rect);

/**
* Draws circle
* @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
*/
void drawCircle(lcdint_t xc, lcdint_t yc, lcdint_t r);

/**
* Draws 1-bit canvas on lcd display
*
Expand Down
30 changes: 30 additions & 0 deletions src/v2/lcd/base/ssd1306_common.inl
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,36 @@ void NanoDisplayOps<O,I>::fillRect(const NanoRect &rect)
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)
{
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);
while (y >= x)
{
x++;
if (d > 0)
{
y--;
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);
}
}

template <class O, class I>
void NanoDisplayOps<O,I>::printFixedPgm(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style)
{
Expand Down

0 comments on commit 5fca7cf

Please sign in to comment.