diff options
author | Franklin Wei <frankhwei536@gmail.com> | 2015-04-08 14:15:20 -0400 |
---|---|---|
committer | Gerrit Rockbox <gerrit@rockbox.org> | 2016-12-18 18:35:52 +0100 |
commit | 90f1370bbf7c3a6a21cfb41b637758178da9d553 (patch) | |
tree | 1028cd6ed98bcc7d6558e6d202c8b81502fb4138 | |
parent | c6996ab7312a5d113b3b9221324d2d203462c025 (diff) | |
download | rockbox-90f1370bbf7c3a6a21cfb41b637758178da9d553.tar.gz rockbox-90f1370bbf7c3a6a21cfb41b637758178da9d553.zip |
Add circle drawing/filling to xlcd
Change-Id: I5d28ade42145d9d82babcf62c0db7948927cafec
-rw-r--r-- | apps/plugins/lib/xlcd.h | 5 | ||||
-rw-r--r-- | apps/plugins/lib/xlcd_draw.c | 100 |
2 files changed, 105 insertions, 0 deletions
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 @@ | |||
31 | void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3); | 31 | void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3); |
32 | void xlcd_filltriangle_screen(struct screen* display, | 32 | void xlcd_filltriangle_screen(struct screen* display, |
33 | int x1, int y1, int x2, int y2, int x3, int y3); | 33 | int x1, int y1, int x2, int y2, int x3, int y3); |
34 | void xlcd_fillcircle(int cx, int cy, int radius); | ||
35 | void xlcd_fillcircle_screen(struct screen* display, int cx, int cy, int radius); | ||
36 | void xlcd_drawcircle(int cx, int cy, int radius); | ||
37 | void xlcd_drawcircle_screen(struct screen* display, int cx, int cy, int radius); | ||
38 | |||
34 | #if LCD_DEPTH >= 8 | 39 | #if LCD_DEPTH >= 8 |
35 | void xlcd_gray_bitmap_part(const unsigned char *src, int src_x, int src_y, | 40 | void xlcd_gray_bitmap_part(const unsigned char *src, int src_x, int src_y, |
36 | int stride, int x, int y, int width, int height); | 41 | 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, | |||
170 | xlcd_filltriangle_vertical(display, x1, y1, x2, y2, x3, y3); | 170 | xlcd_filltriangle_vertical(display, x1, y1, x2, y2, x3, y3); |
171 | } | 171 | } |
172 | 172 | ||
173 | static void xlcd_fillcircle_horizontal(struct screen* display, | ||
174 | int cx, int cy, int radius) | ||
175 | { | ||
176 | int d = 3 - (radius * 2); | ||
177 | int x = 0; | ||
178 | int y = radius; | ||
179 | while(x <= y) | ||
180 | { | ||
181 | display->hline(cx - x, cx + x, cy + y); | ||
182 | display->hline(cx - x, cx + x, cy - y); | ||
183 | display->hline(cx - y, cx + y, cy + x); | ||
184 | display->hline(cx - y, cx + y, cy - x); | ||
185 | if(d < 0) | ||
186 | { | ||
187 | d += (x * 4) + 6; | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | d += ((x - y) * 4) + 10; | ||
192 | --y; | ||
193 | } | ||
194 | ++x; | ||
195 | } | ||
196 | } | ||
197 | |||
198 | static void xlcd_fillcircle_vertical(struct screen* display, | ||
199 | int cx, int cy, int radius) | ||
200 | { | ||
201 | int d = 3 - (radius * 2); | ||
202 | int x = 0; | ||
203 | int y = radius; | ||
204 | while(x <= y) | ||
205 | { | ||
206 | display->vline(cx + x, cy + y, cy - y); | ||
207 | display->vline(cx - x, cy + y, cy - y); | ||
208 | display->vline(cy + x, cx + y, cx - y); | ||
209 | display->vline(cy - x, cx + y, cx - y); | ||
210 | if(d < 0) | ||
211 | { | ||
212 | d += (x * 4) + 6; | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | d += ((x - y) * 4) + 10; | ||
217 | --y; | ||
218 | } | ||
219 | ++x; | ||
220 | } | ||
221 | } | ||
222 | |||
223 | void xlcd_fillcircle_screen(struct screen* display, | ||
224 | int cx, int cy, int radius) | ||
225 | { | ||
226 | if(display->pixel_format == HORIZONTAL_PACKING || display->depth >= 8) | ||
227 | xlcd_fillcircle_horizontal(display, cx, cy, radius); | ||
228 | else | ||
229 | xlcd_fillcircle_vertical(display, cx, cy, radius); | ||
230 | } | ||
231 | |||
232 | void xlcd_fillcircle(int cx, int cy, int radius) | ||
233 | { | ||
234 | xlcd_fillcircle_screen(rb->screens[SCREEN_MAIN], cx, cy, radius); | ||
235 | } | ||
236 | |||
237 | void xlcd_drawcircle_screen(struct screen* display, | ||
238 | int cx, int cy, int radius) | ||
239 | { | ||
240 | int d = 3 - (radius * 2); | ||
241 | int x = 0; | ||
242 | int y = radius; | ||
243 | while(x <= y) | ||
244 | { | ||
245 | display->drawpixel(cx + x, cy + y); | ||
246 | display->drawpixel(cx - x, cy + y); | ||
247 | display->drawpixel(cx + x, cy - y); | ||
248 | display->drawpixel(cx - x, cy - y); | ||
249 | display->drawpixel(cx + y, cy + x); | ||
250 | display->drawpixel(cx - y, cy + x); | ||
251 | display->drawpixel(cx + y, cy - x); | ||
252 | display->drawpixel(cx - y, cy - x); | ||
253 | if(d < 0) | ||
254 | { | ||
255 | d += (x * 4) + 6; | ||
256 | } | ||
257 | else | ||
258 | { | ||
259 | d += ((x - y) * 4) + 10; | ||
260 | --y; | ||
261 | } | ||
262 | ++x; | ||
263 | } | ||
264 | } | ||
265 | |||
266 | void xlcd_drawcircle(int cx, int cy, int radius) | ||
267 | { | ||
268 | /* default is main screen */ | ||
269 | xlcd_drawcircle_screen(rb->screens[SCREEN_MAIN], cx, cy, radius); | ||
270 | } | ||
271 | |||
272 | |||
173 | #if LCD_DEPTH >= 8 && LCD_DEPTH <= 16 | 273 | #if LCD_DEPTH >= 8 && LCD_DEPTH <= 16 |
174 | 274 | ||
175 | #ifdef HAVE_LCD_COLOR | 275 | #ifdef HAVE_LCD_COLOR |