diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2007-06-18 13:37:57 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2007-06-18 13:37:57 +0000 |
commit | 46e186fa61acac1cdf02db597b0cac05de189cfa (patch) | |
tree | 5ab46c45aac79b727f8cc197f1c3f447489a503e /apps | |
parent | 06797c2c7fd2643343f3209e9f9c940565fe6f1b (diff) | |
download | rockbox-46e186fa61acac1cdf02db597b0cac05de189cfa.tar.gz rockbox-46e186fa61acac1cdf02db597b0cac05de189cfa.zip |
extend the text editor plugin to be able to modify the .colors file
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13665 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugin.c | 3 | ||||
-rw-r--r-- | apps/plugin.h | 5 | ||||
-rw-r--r-- | apps/plugins/text_editor.c | 87 | ||||
-rw-r--r-- | apps/plugins/viewers.config | 1 |
4 files changed, 95 insertions, 1 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index fda46ceb05..ca0b8a2ba6 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -498,6 +498,9 @@ static const struct plugin_api rockbox_api = { | |||
498 | threads, | 498 | threads, |
499 | create_numbered_filename, | 499 | create_numbered_filename, |
500 | set_bool_options, | 500 | set_bool_options, |
501 | #ifdef HAVE_LCD_COLOR | ||
502 | set_color, | ||
503 | #endif | ||
501 | }; | 504 | }; |
502 | 505 | ||
503 | int plugin_load(const char* plugin, void* parameter) | 506 | int plugin_load(const char* plugin, void* parameter) |
diff --git a/apps/plugin.h b/apps/plugin.h index cc5acb0270..29e7f5d318 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -79,6 +79,7 @@ | |||
79 | #include "rbunicode.h" | 79 | #include "rbunicode.h" |
80 | #include "list.h" | 80 | #include "list.h" |
81 | #include "tree.h" | 81 | #include "tree.h" |
82 | #include "color_picker.h" | ||
82 | 83 | ||
83 | #ifdef HAVE_REMOTE_LCD | 84 | #ifdef HAVE_REMOTE_LCD |
84 | #include "lcd-remote.h" | 85 | #include "lcd-remote.h" |
@@ -621,6 +622,10 @@ struct plugin_api { | |||
621 | const char* yes_str, int yes_voice, | 622 | const char* yes_str, int yes_voice, |
622 | const char* no_str, int no_voice, | 623 | const char* no_str, int no_voice, |
623 | void (*function)(bool)); | 624 | void (*function)(bool)); |
625 | #ifdef HAVE_LCD_COLOR | ||
626 | bool (*set_color)(struct screen *display, char *title, unsigned *color, | ||
627 | unsigned banned_color); | ||
628 | #endif | ||
624 | }; | 629 | }; |
625 | 630 | ||
626 | /* plugin header */ | 631 | /* plugin header */ |
diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c index 523cbad30c..943596905c 100644 --- a/apps/plugins/text_editor.c +++ b/apps/plugins/text_editor.c | |||
@@ -283,6 +283,39 @@ int do_item_menu(int cur_sel, char* copy_buffer) | |||
283 | menu_exit(m); | 283 | menu_exit(m); |
284 | return ret; | 284 | return ret; |
285 | } | 285 | } |
286 | |||
287 | #ifdef HAVE_LCD_COLOR | ||
288 | /* in misc.h but no need to polute the api */ | ||
289 | #define toupper(c) (((c >= 'a') && (c <= 'z'))?c+'A':c) | ||
290 | #define isxdigit(c) ((c>='a' && c<= 'f') || (c>='A' && c<= 'F') \ | ||
291 | || (c>='0' && c<= '9')) | ||
292 | #define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \ | ||
293 | (toupper(c)) - 'A' + 10) | ||
294 | int hex_to_rgb(const char* hex) | ||
295 | { int ok = 1; | ||
296 | int i; | ||
297 | int red, green, blue; | ||
298 | |||
299 | if (rb->strlen(hex) == 6) { | ||
300 | for (i=0; i < 6; i++ ) { | ||
301 | if (!isxdigit(hex[i])) { | ||
302 | ok=0; | ||
303 | break; | ||
304 | } | ||
305 | } | ||
306 | |||
307 | if (ok) { | ||
308 | red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]); | ||
309 | green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]); | ||
310 | blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]); | ||
311 | return LCD_RGBPACK(red,green,blue); | ||
312 | } | ||
313 | } | ||
314 | |||
315 | return 0; | ||
316 | } | ||
317 | #endif /* HAVE_LCD_COLOR */ | ||
318 | |||
286 | /* this is the plugin entry point */ | 319 | /* this is the plugin entry point */ |
287 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | 320 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
288 | { | 321 | { |
@@ -296,6 +329,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
296 | int cur_sel=0; | 329 | int cur_sel=0; |
297 | static char copy_buffer[MAX_LINE_LEN]; | 330 | static char copy_buffer[MAX_LINE_LEN]; |
298 | bool prev_show_statusbar; | 331 | bool prev_show_statusbar; |
332 | #ifdef HAVE_LCD_COLOR | ||
333 | bool edit_icons_file = false; | ||
334 | #endif | ||
299 | 335 | ||
300 | rb = api; | 336 | rb = api; |
301 | 337 | ||
@@ -308,6 +344,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
308 | #endif | 344 | #endif |
309 | if (parameter) | 345 | if (parameter) |
310 | { | 346 | { |
347 | #ifdef HAVE_LCD_COLOR | ||
348 | char *c = NULL; | ||
349 | #endif | ||
311 | rb->strcpy(filename,(char*)parameter); | 350 | rb->strcpy(filename,(char*)parameter); |
312 | if (!get_eol_string(filename)) | 351 | if (!get_eol_string(filename)) |
313 | { | 352 | { |
@@ -319,6 +358,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
319 | rb->splash(HZ*2,"Couldnt open file: %s",(char*)parameter); | 358 | rb->splash(HZ*2,"Couldnt open file: %s",(char*)parameter); |
320 | return PLUGIN_ERROR; | 359 | return PLUGIN_ERROR; |
321 | } | 360 | } |
361 | #ifdef HAVE_LCD_COLOR | ||
362 | c = rb->strchr(filename, '.'); | ||
363 | if (c && rb->strcmp(c, ".icons")) | ||
364 | edit_icons_file = true; | ||
365 | #endif | ||
322 | /* read in the file */ | 366 | /* read in the file */ |
323 | while (rb->read_line(fd,temp_line,MAX_LINE_LEN)) | 367 | while (rb->read_line(fd,temp_line,MAX_LINE_LEN)) |
324 | { | 368 | { |
@@ -353,9 +397,50 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
353 | { | 397 | { |
354 | case ACTION_STD_OK: | 398 | case ACTION_STD_OK: |
355 | { | 399 | { |
400 | bool edit_text = true; | ||
401 | #ifdef HAVE_LCD_COLOR | ||
402 | int color; | ||
403 | #endif | ||
356 | if (line_count) | 404 | if (line_count) |
357 | rb->strcpy(temp_line,&buffer[do_action(ACTION_GET,0,cur_sel)]); | 405 | rb->strcpy(temp_line,&buffer[do_action(ACTION_GET,0,cur_sel)]); |
358 | if (!rb->kbd_input(temp_line,MAX_LINE_LEN)) | 406 | #ifdef HAVE_LCD_COLOR |
407 | if (edit_icons_file) | ||
408 | { | ||
409 | char *name = temp_line, *value = NULL; | ||
410 | char extension[MAX_LINE_LEN]; | ||
411 | rb->settings_parseline(temp_line, &name, &value); | ||
412 | if (line_count) | ||
413 | { | ||
414 | MENUITEM_STRINGLIST(menu, "Edit What?", NULL, | ||
415 | "Extension", "Color",); | ||
416 | switch (rb->do_menu(&menu, NULL)) | ||
417 | { | ||
418 | case 0: | ||
419 | edit_text = true; | ||
420 | break; | ||
421 | case 1: | ||
422 | edit_text = false; | ||
423 | if (value) | ||
424 | color = hex_to_rgb(value); | ||
425 | else color = 0; | ||
426 | rb->strcpy(extension, name); | ||
427 | rb->set_color(rb->screens[SCREEN_MAIN], name, &color, -1); | ||
428 | rb->snprintf(temp_line, MAX_LINE_LEN, "%s: %02X%02X%02X", | ||
429 | extension, RGB_UNPACK_RED(color), | ||
430 | RGB_UNPACK_GREEN(color), | ||
431 | RGB_UNPACK_BLUE(color)); | ||
432 | if (line_count) | ||
433 | { | ||
434 | do_action(ACTION_UPDATE,temp_line,cur_sel); | ||
435 | } | ||
436 | else do_action(ACTION_INSERT,temp_line,cur_sel); | ||
437 | changed = true; | ||
438 | break; | ||
439 | } | ||
440 | } | ||
441 | } | ||
442 | #endif | ||
443 | if (edit_text &&!rb->kbd_input(temp_line,MAX_LINE_LEN)) | ||
359 | { | 444 | { |
360 | if (line_count) | 445 | if (line_count) |
361 | { | 446 | { |
diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config index 3dc5dd952c..2d091bf62b 100644 --- a/apps/plugins/viewers.config +++ b/apps/plugins/viewers.config | |||
@@ -32,3 +32,4 @@ sna,viewers/zxbox,12 | |||
32 | tzx,viewers/zxbox,12 | 32 | tzx,viewers/zxbox,12 |
33 | z80,viewers/zxbox,12 | 33 | z80,viewers/zxbox,12 |
34 | zzz,viewers/properties,- | 34 | zzz,viewers/properties,- |
35 | colors,rocks/text_editor,11 | ||