aboutsummaryrefslogtreecommitdiffstats
path: root/src/gdisp.c
diff options
context:
space:
mode:
authorTectu <joel@unormal.org>2012-08-28 16:24:00 +0200
committerTectu <joel@unormal.org>2012-08-28 16:24:00 +0200
commit2c7cbc1dd733d6835da7b49019e512d6eb06f8fa (patch)
tree7a34d5222facef31d1cceb0e20cde5a651705b5c /src/gdisp.c
parent8fd1de6ef5a806ccc6e23ba1ba18dfc06b6fbbde (diff)
downloaduGFX-2c7cbc1dd733d6835da7b49019e512d6eb06f8fa.tar.gz
uGFX-2c7cbc1dd733d6835da7b49019e512d6eb06f8fa.tar.bz2
uGFX-2c7cbc1dd733d6835da7b49019e512d6eb06f8fa.zip
implemented gdispDrawArc() by noether
Diffstat (limited to 'src/gdisp.c')
-rw-r--r--src/gdisp.c99
1 files changed, 91 insertions, 8 deletions
diff --git a/src/gdisp.c b/src/gdisp.c
index f5da45b9..2b8989e6 100644
--- a/src/gdisp.c
+++ b/src/gdisp.c
@@ -659,6 +659,84 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
}
}
+void _draw_arc(int x, int y, int start, int end, int radius, color_t color) {
+ if (start >= 0 && start <= 180)
+ {
+ float x_maxI = x + radius*cos(start*M_PI/180);
+ float x_minI;
+
+ if (end > 180)
+ x_minI = x - radius;
+ else
+ x_minI = x + radius*cos(end*M_PI/180);
+
+ int a = 0;
+ int b = radius;
+ int P = 1 - radius;
+
+ do
+ {
+ if(x-a <= x_maxI && x-a >= x_minI)
+ gdispDrawPixel(x-a, y+b, color);
+ if(x+a <= x_maxI && x+a >= x_minI)
+ gdispDrawPixel(x+a, y+b, color);
+ if(x-b <= x_maxI && x-b >= x_minI)
+ gdispDrawPixel(x-b, y+a, color);
+ if(x+b <= x_maxI && x+b >= x_minI)
+ gdispDrawPixel(x+b, y+a, color);
+
+ if (P < 0)
+ {
+ P = P + 3 + 2*a;
+ a = a + 1;
+ }else
+ {
+ P = P + 5 + 2*(a - b);
+ a = a + 1;
+ b = b - 1;
+ }
+ }while(a <= b);
+ }
+
+ if (end > 180 && end <= 360)
+ {
+ float x_maxII = x+radius*cos(end*M_PI/180);
+ float x_minII;
+
+ if(start <= 180)
+ x_minII = x - radius;
+ else
+ x_minII = x+radius*cos(start*M_PI/180);
+
+ int a = 0;
+ int b = radius;
+ int P = 1 - radius;
+
+ do{
+ if(x-a <= x_maxII && x-a >= x_minII)
+ gdispDrawPixel(x-a, y-b, color);
+ if(x+a <= x_maxII && x+a >= x_minII)
+ gdispDrawPixel(x+a, y-b, color);
+ if(x-b <= x_maxII && x-b >= x_minII)
+ gdispDrawPixel(x-b, y-a, color);
+ if(x+b <= x_maxII && x+b >= x_minII)
+ gdispDrawPixel(x+b, y-a, color);
+
+ if (P < 0)
+ {
+ P = P + 3 + 2*a;
+ a = a + 1;
+ }
+ else
+ {
+ P = P + 5 + 2*(a - b);
+ a = a + 1;
+ b = b - 1;
+ }
+ }while (a <= b);
+ }
+}
+
/*
* @brief Draw an arc.
* @pre The GDISP must be in powerOn or powerSleep mode.
@@ -672,13 +750,12 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
* @api
*/
void gdispDrawArc(coord_t x, coord_t y, coord_t radius, uint16_t start, uint16_t end, color_t color) {
- uint16_t i;
- float step = 0.01;
-
- for(i = 0; i <= (int)((abs(end-start)) / step); i++) {
- gdispDrawPixel( ((float)x + (float)radius * cosf((float)start * M_PI / 180.0f) + (float)i * step * M_PI / 180.0f),
- ((float)y + (float)radius * sinf((float)start * M_PI / 180.0f) + (float)i * step * M_PI / 180.0f), color);
- }
+ if (end < start) {
+ _draw_arc(x, y, start, 360, radius, color);
+ _draw_arc(x, y, 0, end, radius, color);
+ }
+ else
+ _draw_arc(x, y, start, end, radius, color);
}
/*
@@ -694,7 +771,13 @@ void gdispDrawArc(coord_t x, coord_t y, coord_t radius, uint16_t start, uint16_t
* @api
*/
void gdispFillArc(coord_t x, coord_t y, coord_t radius, uint16_t start, uint16_t end, color_t color) {
-
+ /* ToDo */
+ (void)x;
+ (void)y;
+ (void)radius;
+ (void)start;
+ (void)end;
+ (void)color;
}
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)