mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 10:37:38 -04:00
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
This commit is contained in:
parent
06797c2c7f
commit
46e186fa61
4 changed files with 95 additions and 1 deletions
|
@ -498,6 +498,9 @@ static const struct plugin_api rockbox_api = {
|
||||||
threads,
|
threads,
|
||||||
create_numbered_filename,
|
create_numbered_filename,
|
||||||
set_bool_options,
|
set_bool_options,
|
||||||
|
#ifdef HAVE_LCD_COLOR
|
||||||
|
set_color,
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
int plugin_load(const char* plugin, void* parameter)
|
int plugin_load(const char* plugin, void* parameter)
|
||||||
|
|
|
@ -79,6 +79,7 @@
|
||||||
#include "rbunicode.h"
|
#include "rbunicode.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
|
#include "color_picker.h"
|
||||||
|
|
||||||
#ifdef HAVE_REMOTE_LCD
|
#ifdef HAVE_REMOTE_LCD
|
||||||
#include "lcd-remote.h"
|
#include "lcd-remote.h"
|
||||||
|
@ -621,6 +622,10 @@ struct plugin_api {
|
||||||
const char* yes_str, int yes_voice,
|
const char* yes_str, int yes_voice,
|
||||||
const char* no_str, int no_voice,
|
const char* no_str, int no_voice,
|
||||||
void (*function)(bool));
|
void (*function)(bool));
|
||||||
|
#ifdef HAVE_LCD_COLOR
|
||||||
|
bool (*set_color)(struct screen *display, char *title, unsigned *color,
|
||||||
|
unsigned banned_color);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* plugin header */
|
/* plugin header */
|
||||||
|
|
|
@ -283,6 +283,39 @@ int do_item_menu(int cur_sel, char* copy_buffer)
|
||||||
menu_exit(m);
|
menu_exit(m);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LCD_COLOR
|
||||||
|
/* in misc.h but no need to polute the api */
|
||||||
|
#define toupper(c) (((c >= 'a') && (c <= 'z'))?c+'A':c)
|
||||||
|
#define isxdigit(c) ((c>='a' && c<= 'f') || (c>='A' && c<= 'F') \
|
||||||
|
|| (c>='0' && c<= '9'))
|
||||||
|
#define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \
|
||||||
|
(toupper(c)) - 'A' + 10)
|
||||||
|
int hex_to_rgb(const char* hex)
|
||||||
|
{ int ok = 1;
|
||||||
|
int i;
|
||||||
|
int red, green, blue;
|
||||||
|
|
||||||
|
if (rb->strlen(hex) == 6) {
|
||||||
|
for (i=0; i < 6; i++ ) {
|
||||||
|
if (!isxdigit(hex[i])) {
|
||||||
|
ok=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]);
|
||||||
|
green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]);
|
||||||
|
blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]);
|
||||||
|
return LCD_RGBPACK(red,green,blue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* HAVE_LCD_COLOR */
|
||||||
|
|
||||||
/* this is the plugin entry point */
|
/* this is the plugin entry point */
|
||||||
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
{
|
{
|
||||||
|
@ -296,6 +329,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
int cur_sel=0;
|
int cur_sel=0;
|
||||||
static char copy_buffer[MAX_LINE_LEN];
|
static char copy_buffer[MAX_LINE_LEN];
|
||||||
bool prev_show_statusbar;
|
bool prev_show_statusbar;
|
||||||
|
#ifdef HAVE_LCD_COLOR
|
||||||
|
bool edit_icons_file = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
rb = api;
|
rb = api;
|
||||||
|
|
||||||
|
@ -308,6 +344,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
#endif
|
#endif
|
||||||
if (parameter)
|
if (parameter)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_LCD_COLOR
|
||||||
|
char *c = NULL;
|
||||||
|
#endif
|
||||||
rb->strcpy(filename,(char*)parameter);
|
rb->strcpy(filename,(char*)parameter);
|
||||||
if (!get_eol_string(filename))
|
if (!get_eol_string(filename))
|
||||||
{
|
{
|
||||||
|
@ -319,6 +358,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
rb->splash(HZ*2,"Couldnt open file: %s",(char*)parameter);
|
rb->splash(HZ*2,"Couldnt open file: %s",(char*)parameter);
|
||||||
return PLUGIN_ERROR;
|
return PLUGIN_ERROR;
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_LCD_COLOR
|
||||||
|
c = rb->strchr(filename, '.');
|
||||||
|
if (c && rb->strcmp(c, ".icons"))
|
||||||
|
edit_icons_file = true;
|
||||||
|
#endif
|
||||||
/* read in the file */
|
/* read in the file */
|
||||||
while (rb->read_line(fd,temp_line,MAX_LINE_LEN))
|
while (rb->read_line(fd,temp_line,MAX_LINE_LEN))
|
||||||
{
|
{
|
||||||
|
@ -353,9 +397,50 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
{
|
{
|
||||||
case ACTION_STD_OK:
|
case ACTION_STD_OK:
|
||||||
{
|
{
|
||||||
|
bool edit_text = true;
|
||||||
|
#ifdef HAVE_LCD_COLOR
|
||||||
|
int color;
|
||||||
|
#endif
|
||||||
if (line_count)
|
if (line_count)
|
||||||
rb->strcpy(temp_line,&buffer[do_action(ACTION_GET,0,cur_sel)]);
|
rb->strcpy(temp_line,&buffer[do_action(ACTION_GET,0,cur_sel)]);
|
||||||
if (!rb->kbd_input(temp_line,MAX_LINE_LEN))
|
#ifdef HAVE_LCD_COLOR
|
||||||
|
if (edit_icons_file)
|
||||||
|
{
|
||||||
|
char *name = temp_line, *value = NULL;
|
||||||
|
char extension[MAX_LINE_LEN];
|
||||||
|
rb->settings_parseline(temp_line, &name, &value);
|
||||||
|
if (line_count)
|
||||||
|
{
|
||||||
|
MENUITEM_STRINGLIST(menu, "Edit What?", NULL,
|
||||||
|
"Extension", "Color",);
|
||||||
|
switch (rb->do_menu(&menu, NULL))
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
edit_text = true;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
edit_text = false;
|
||||||
|
if (value)
|
||||||
|
color = hex_to_rgb(value);
|
||||||
|
else color = 0;
|
||||||
|
rb->strcpy(extension, name);
|
||||||
|
rb->set_color(rb->screens[SCREEN_MAIN], name, &color, -1);
|
||||||
|
rb->snprintf(temp_line, MAX_LINE_LEN, "%s: %02X%02X%02X",
|
||||||
|
extension, RGB_UNPACK_RED(color),
|
||||||
|
RGB_UNPACK_GREEN(color),
|
||||||
|
RGB_UNPACK_BLUE(color));
|
||||||
|
if (line_count)
|
||||||
|
{
|
||||||
|
do_action(ACTION_UPDATE,temp_line,cur_sel);
|
||||||
|
}
|
||||||
|
else do_action(ACTION_INSERT,temp_line,cur_sel);
|
||||||
|
changed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (edit_text &&!rb->kbd_input(temp_line,MAX_LINE_LEN))
|
||||||
{
|
{
|
||||||
if (line_count)
|
if (line_count)
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,3 +32,4 @@ sna,viewers/zxbox,12
|
||||||
tzx,viewers/zxbox,12
|
tzx,viewers/zxbox,12
|
||||||
z80,viewers/zxbox,12
|
z80,viewers/zxbox,12
|
||||||
zzz,viewers/properties,-
|
zzz,viewers/properties,-
|
||||||
|
colors,rocks/text_editor,11
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue