From 90f1370bbf7c3a6a21cfb41b637758178da9d553 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Wed, 8 Apr 2015 14:15:20 -0400 Subject: Add circle drawing/filling to xlcd Change-Id: I5d28ade42145d9d82babcf62c0db7948927cafec --- apps/plugins/lib/xlcd.h | 5 +++ apps/plugins/lib/xlcd_draw.c | 100 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) (limited to 'apps') diff --git a/apps/plugins/lib/xlcd.h b/apps/plugins/lib/xlcd.h index b6d0867e01..abd5cff62b 100644 --- a/apps/plugins/lib/xlcd.h +++ b/apps/plugins/lib/xlcd.h @@ -31,6 +31,11 @@ void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3); void xlcd_filltriangle_screen(struct screen* display, int x1, int y1, int x2, int y2, int x3, int y3); +void xlcd_fillcircle(int cx, int cy, int radius); +void xlcd_fillcircle_screen(struct screen* display, int cx, int cy, int radius); +void xlcd_drawcircle(int cx, int cy, int radius); +void xlcd_drawcircle_screen(struct screen* display, int cx, int cy, int radius); + #if LCD_DEPTH >= 8 void xlcd_gray_bitmap_part(const unsigned char *src, int src_x, int src_y, int stride, int x, int y, int width, int height); diff --git a/apps/plugins/lib/xlcd_draw.c b/apps/plugins/lib/xlcd_draw.c index 83ddf68e5c..311782c21f 100644 --- a/apps/plugins/lib/xlcd_draw.c +++ b/apps/plugins/lib/xlcd_draw.c @@ -170,6 +170,106 @@ void xlcd_filltriangle_screen(struct screen* display, xlcd_filltriangle_vertical(display, x1, y1, x2, y2, x3, y3); } +static void xlcd_fillcircle_horizontal(struct screen* display, + int cx, int cy, int radius) +{ + int d = 3 - (radius * 2); + int x = 0; + int y = radius; + while(x <= y) + { + display->hline(cx - x, cx + x, cy + y); + display->hline(cx - x, cx + x, cy - y); + display->hline(cx - y, cx + y, cy + x); + display->hline(cx - y, cx + y, cy - x); + if(d < 0) + { + d += (x * 4) + 6; + } + else + { + d += ((x - y) * 4) + 10; + --y; + } + ++x; + } +} + +static void xlcd_fillcircle_vertical(struct screen* display, + int cx, int cy, int radius) +{ + int d = 3 - (radius * 2); + int x = 0; + int y = radius; + while(x <= y) + { + display->vline(cx + x, cy + y, cy - y); + display->vline(cx - x, cy + y, cy - y); + display->vline(cy + x, cx + y, cx - y); + display->vline(cy - x, cx + y, cx - y); + if(d < 0) + { + d += (x * 4) + 6; + } + else + { + d += ((x - y) * 4) + 10; + --y; + } + ++x; + } +} + +void xlcd_fillcircle_screen(struct screen* display, + int cx, int cy, int radius) +{ + if(display->pixel_format == HORIZONTAL_PACKING || display->depth >= 8) + xlcd_fillcircle_horizontal(display, cx, cy, radius); + else + xlcd_fillcircle_vertical(display, cx, cy, radius); +} + +void xlcd_fillcircle(int cx, int cy, int radius) +{ + xlcd_fillcircle_screen(rb->screens[SCREEN_MAIN], cx, cy, radius); +} + +void xlcd_drawcircle_screen(struct screen* display, + int cx, int cy, int radius) +{ + int d = 3 - (radius * 2); + int x = 0; + int y = radius; + while(x <= y) + { + display->drawpixel(cx + x, cy + y); + display->drawpixel(cx - x, cy + y); + display->drawpixel(cx + x, cy - y); + display->drawpixel(cx - x, cy - y); + display->drawpixel(cx + y, cy + x); + display->drawpixel(cx - y, cy + x); + display->drawpixel(cx + y, cy - x); + display->drawpixel(cx - y, cy - x); + if(d < 0) + { + d += (x * 4) + 6; + } + else + { + d += ((x - y) * 4) + 10; + --y; + } + ++x; + } +} + +void xlcd_drawcircle(int cx, int cy, int radius) +{ + /* default is main screen */ + xlcd_drawcircle_screen(rb->screens[SCREEN_MAIN], cx, cy, radius); +} + + #if LCD_DEPTH >= 8 && LCD_DEPTH <= 16 #ifdef HAVE_LCD_COLOR -- cgit v1.2.3