1
0
Fork 0
forked from len0rd/rockbox

a bit of code polish for rockpaint and disktidy.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22187 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2009-08-06 12:44:12 +00:00
parent c3aec89bec
commit c4dc61a2a6
2 changed files with 65 additions and 65 deletions

View file

@ -141,7 +141,7 @@ bool tidy_remove_item(char *item, int attr)
if (file[rb->strlen(file)-1] == '*') if (file[rb->strlen(file)-1] == '*')
{ {
if (!rb->strncmp(file, item, rb->strlen(file)-1)) if (!rb->strncmp(file, item, rb->strlen(file)-1))
rem = true; rem = true;
} }
else if (!rb->strcmp(file, item)) else if (!rb->strcmp(file, item))
rem = true; rem = true;
@ -192,12 +192,12 @@ enum tidy_return tidy_removedir(const char *name, int *removed)
int button; int button;
DIR *dir; DIR *dir;
char fullname[MAX_PATH]; char fullname[MAX_PATH];
/* display status text */ /* display status text */
tidy_lcd_status(name, removed); tidy_lcd_status(name, removed);
rb->yield(); rb->yield();
dir = rb->opendir(name); dir = rb->opendir(name);
if (dir) if (dir)
{ {
@ -216,12 +216,12 @@ enum tidy_return tidy_removedir(const char *name, int *removed)
rb->closedir(dir); rb->closedir(dir);
return TIDY_RETURN_USB; return TIDY_RETURN_USB;
} }
rb->yield(); rb->yield();
/* get absolute path */ /* get absolute path */
tidy_get_absolute_path(entry, fullname, name); tidy_get_absolute_path(entry, fullname, name);
if (entry->attribute & ATTR_DIRECTORY) if (entry->attribute & ATTR_DIRECTORY)
{ {
/* dir ignore "." and ".." */ /* dir ignore "." and ".." */
@ -259,12 +259,12 @@ enum tidy_return tidy_clean(const char *name, int *removed)
int del; /* has the item been deleted */ int del; /* has the item been deleted */
DIR *dir; DIR *dir;
char fullname[MAX_PATH]; char fullname[MAX_PATH];
/* display status text */ /* display status text */
tidy_lcd_status(name, removed); tidy_lcd_status(name, removed);
rb->yield(); rb->yield();
dir = rb->opendir(name); dir = rb->opendir(name);
if (dir) if (dir)
{ {
@ -283,9 +283,9 @@ enum tidy_return tidy_clean(const char *name, int *removed)
rb->closedir(dir); rb->closedir(dir);
return TIDY_RETURN_USB; return TIDY_RETURN_USB;
} }
rb->yield(); rb->yield();
if (entry->attribute & ATTR_DIRECTORY) if (entry->attribute & ATTR_DIRECTORY)
{ {
/* directory ignore "." and ".." */ /* directory ignore "." and ".." */
@ -293,17 +293,17 @@ enum tidy_return tidy_clean(const char *name, int *removed)
(rb->strcmp(entry->d_name, "..") != 0)) (rb->strcmp(entry->d_name, "..") != 0))
{ {
del = 0; del = 0;
/* get absolute path */ /* get absolute path */
tidy_get_absolute_path(entry, fullname, name); tidy_get_absolute_path(entry, fullname, name);
if (tidy_remove_item(entry->d_name, entry->attribute)) if (tidy_remove_item(entry->d_name, entry->attribute))
{ {
/* delete dir */ /* delete dir */
tidy_removedir(fullname, removed); tidy_removedir(fullname, removed);
del = 1; del = 1;
} }
if (del == 0) if (del == 0)
{ {
/* dir not deleted so clean it */ /* dir not deleted so clean it */
@ -318,11 +318,11 @@ enum tidy_return tidy_clean(const char *name, int *removed)
if (tidy_remove_item(entry->d_name, entry->attribute)) if (tidy_remove_item(entry->d_name, entry->attribute))
{ {
*removed += 1; /* increment removed files counter */ *removed += 1; /* increment removed files counter */
/* get absolute path */ /* get absolute path */
char fullname[MAX_PATH]; char fullname[MAX_PATH];
tidy_get_absolute_path(entry, fullname, name); tidy_get_absolute_path(entry, fullname, name);
/* delete file */ /* delete file */
rb->remove(fullname); rb->remove(fullname);
del = 1; del = 1;
@ -338,23 +338,23 @@ enum tidy_return tidy_clean(const char *name, int *removed)
} }
} }
enum plugin_status tidy_do(void) enum tidy_return tidy_do(void)
{ {
/* clean disk and display num of items removed */ /* clean disk and display num of items removed */
int removed = 0; int removed = 0;
enum tidy_return status; enum tidy_return status;
char text[24]; /* "Cleaned up nnnnn items" */ char text[24]; /* "Cleaned up nnnnn items" */
#ifdef HAVE_ADJUSTABLE_CPU_FREQ #ifdef HAVE_ADJUSTABLE_CPU_FREQ
rb->cpu_boost(true); rb->cpu_boost(true);
#endif #endif
status = tidy_clean("/", &removed); status = tidy_clean("/", &removed);
#ifdef HAVE_ADJUSTABLE_CPU_FREQ #ifdef HAVE_ADJUSTABLE_CPU_FREQ
rb->cpu_boost(false); rb->cpu_boost(false);
#endif #endif
if ((status == TIDY_RETURN_OK) || (status == TIDY_RETURN_ABORT)) if ((status == TIDY_RETURN_OK) || (status == TIDY_RETURN_ABORT))
{ {
rb->lcd_clear_display(); rb->lcd_clear_display();
@ -436,29 +436,32 @@ int list_action_callback(int action, struct gui_synclist *lists)
return action; return action;
} }
int tidy_lcd_menu(void) enum tidy_return tidy_lcd_menu(void)
{ {
int selection, ret = 3; int selection = 0;
enum tidy_return status = TIDY_RETURN_OK;
bool menu_quit = false; bool menu_quit = false;
MENUITEM_STRINGLIST(menu,"Disktidy Menu",NULL,"Start Cleaning", MENUITEM_STRINGLIST(menu, "Disktidy Menu", NULL,
"Files to Clean","Quit"); "Start Cleaning", "Files to Clean",
"Quit");
while (!menu_quit) while (!menu_quit)
{ {
switch(rb->do_menu(&menu, &selection, NULL, false)) switch(rb->do_menu(&menu, &selection, NULL, false))
{ {
case 0: case 0:
menu_quit = true; /* start cleaning */ menu_quit = true; /* start cleaning */
break; break;
case 1: case 1:
{ {
bool show_icons = rb->global_settings->show_icons; bool show_icons = rb->global_settings->show_icons;
struct simplelist_info list; struct simplelist_info list;
rb->global_settings->show_icons = true; /* force the icons so its readable */ /* force the icons so its readable */
rb->simplelist_info_init(&list, "Files to Clean", tidy_type_count, NULL); rb->global_settings->show_icons = true;
rb->simplelist_info_init(&list, "Files to Clean",
tidy_type_count, NULL);
list.get_icon = get_icon; list.get_icon = get_icon;
list.get_name = get_name; list.get_name = get_name;
list.action_callback = list_action_callback; list.action_callback = list_action_callback;
@ -466,21 +469,20 @@ int tidy_lcd_menu(void)
rb->global_settings->show_icons = show_icons; rb->global_settings->show_icons = show_icons;
} }
break; break;
default: default:
ret = 99; /* exit plugin */ status = TIDY_RETURN_ABORT; /* exit plugin */
menu_quit = true; menu_quit = true;
break; break;
} }
} }
return ret; return status;
} }
/* this is the plugin entry point */ /* this is the plugin entry point */
enum plugin_status plugin_start(const void* parameter) enum plugin_status plugin_start(const void* parameter)
{ {
enum tidy_return status; enum tidy_return status;
int ret;
(void)parameter; (void)parameter;
tidy_type_count = 0; tidy_type_count = 0;
@ -491,7 +493,7 @@ enum plugin_status plugin_start(const void* parameter)
rb->splash(3*HZ, "Missing disktidy.config file"); rb->splash(3*HZ, "Missing disktidy.config file");
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
ret = tidy_lcd_menu(); status = tidy_lcd_menu();
if (tidy_loaded_and_changed) if (tidy_loaded_and_changed)
{ {
int fd = rb->creat(CUSTOM_FILES); int fd = rb->creat(CUSTOM_FILES);
@ -507,7 +509,7 @@ enum plugin_status plugin_start(const void* parameter)
rb->close(fd); rb->close(fd);
} }
} }
if (ret == 99) if (status == TIDY_RETURN_ABORT)
return PLUGIN_OK; return PLUGIN_OK;
while (true) while (true)
{ {
@ -520,17 +522,16 @@ enum plugin_status plugin_start(const void* parameter)
case TIDY_RETURN_ERROR: case TIDY_RETURN_ERROR:
return PLUGIN_ERROR; return PLUGIN_ERROR;
case TIDY_RETURN_USB: case TIDY_RETURN_USB:
return PLUGIN_USB_CONNECTED; return PLUGIN_USB_CONNECTED;
case TIDY_RETURN_ABORT: case TIDY_RETURN_ABORT:
return PLUGIN_OK; return PLUGIN_OK;
} }
} }
if (rb->default_event_handler(rb->button_get(false)) == SYS_USB_CONNECTED) if (rb->default_event_handler(rb->button_get(false)) == SYS_USB_CONNECTED)
return PLUGIN_USB_CONNECTED; return PLUGIN_USB_CONNECTED;
rb->yield(); rb->yield();
return PLUGIN_OK; return PLUGIN_OK;
} }

View file

@ -312,16 +312,11 @@ static void goto_menu(void);
static int load_bitmap( const char *filename ); static int load_bitmap( const char *filename );
static int save_bitmap( char *filename ); static int save_bitmap( char *filename );
static void draw_rect_full( int x1, int y1, int x2, int y2 ); static void draw_rect_full( int x1, int y1, int x2, int y2 );
extern int errno;
/*********************************************************************** /***********************************************************************
* Global variables * Global variables
***********************************************************************/ ***********************************************************************/
#if !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__)
int errno;
#endif
static int drawcolor=0; /* Current color (in palette) */ static int drawcolor=0; /* Current color (in palette) */
static int bgdrawcolor=9; /* Current background color (in palette) */ static int bgdrawcolor=9; /* Current background color (in palette) */
bool isbg = false; /* gruik ugly hack alert */ bool isbg = false; /* gruik ugly hack alert */
@ -518,7 +513,8 @@ static void buffer_putsxyofs( fb_data *buf, int buf_width, int buf_height,
bits = rb->font_get_bits( pf, ch ); bits = rb->font_get_bits( pf, ch );
buffer_mono_bitmap_part( buf, buf_width, buf_height, bits, ofs, 0, width, x, y, width - ofs, pf->height); buffer_mono_bitmap_part( buf, buf_width, buf_height, bits, ofs, 0,
width, x, y, width - ofs, pf->height);
x += width - ofs; x += width - ofs;
ofs = 0; ofs = 0;
@ -539,9 +535,9 @@ enum {
}; };
enum { enum {
/* Select action menu */ /* Select action menu */
SELECT_MENU_CUT, SELECT_MENU_COPY, SELECT_MENU_INVERT, SELECT_MENU_CUT, SELECT_MENU_COPY,
SELECT_MENU_HFLIP, SELECT_MENU_VFLIP, SELECT_MENU_ROTATE90, SELECT_MENU_INVERT, SELECT_MENU_HFLIP, SELECT_MENU_VFLIP,
SELECT_MENU_ROTATE180, SELECT_MENU_ROTATE270, SELECT_MENU_ROTATE90, SELECT_MENU_ROTATE180, SELECT_MENU_ROTATE270,
SELECT_MENU_CANCEL, SELECT_MENU_CANCEL,
}; };
enum { enum {
@ -562,9 +558,10 @@ MENUITEM_STRINGLIST(speed_menu, "Choose Speed", NULL,
MENUITEM_STRINGLIST(gridsize_menu, "Grid Size", NULL, MENUITEM_STRINGLIST(gridsize_menu, "Grid Size", NULL,
"No grid", "5px", "10px", "20px"); "No grid", "5px", "10px", "20px");
MENUITEM_STRINGLIST(select_menu, "Select...", NULL, MENUITEM_STRINGLIST(select_menu, "Select...", NULL,
"Cut", "Copy", "Invert", "Horizontal Flip" , "Cut", "Copy",
"Vertical Flip", "Rotate 90°", "Invert", "Horizontal Flip", "Vertical Flip",
"Rotate 180°", "Rotate 270°", "Cancel"); "Rotate 90°", "Rotate 180°", "Rotate 270°",
"Cancel");
MENUITEM_STRINGLIST(text_menu, "Text", NULL, MENUITEM_STRINGLIST(text_menu, "Text", NULL,
"Set Text", "Change Font", "Set Text", "Change Font",
"Preview", "Apply", "Cancel"); "Preview", "Apply", "Cancel");
@ -1574,20 +1571,20 @@ static void draw_line( int x1, int y1, int x2, int y2 )
int deltax = x2 - x1; int deltax = x2 - x1;
int deltay = y2 - y1; int deltay = y2 - y1;
int i; int i;
int xerr = abs(deltax); int xerr = abs(deltax);
int yerr = abs(deltay); int yerr = abs(deltay);
int xstep = deltax > 0 ? 1 : -1; int xstep = deltax > 0 ? 1 : -1;
int ystep = deltay > 0 ? 1 : -1; int ystep = deltay > 0 ? 1 : -1;
int err; int err;
if (yerr > xerr) if (yerr > xerr)
{ {
/* more vertical */ /* more vertical */
err = yerr; err = yerr;
xerr <<= 1; xerr <<= 1;
yerr <<= 1; yerr <<= 1;
/* to leave off the last pixel of the line, leave off the "+ 1" */ /* to leave off the last pixel of the line, leave off the "+ 1" */
for (i = abs(deltay) + 1; i; --i) for (i = abs(deltay) + 1; i; --i)
{ {
@ -1606,7 +1603,7 @@ static void draw_line( int x1, int y1, int x2, int y2 )
err = xerr; err = xerr;
xerr <<= 1; xerr <<= 1;
yerr <<= 1; yerr <<= 1;
for (i = abs(deltax) + 1; i; --i) for (i = abs(deltax) + 1; i; --i)
{ {
draw_pixel(x, y); draw_pixel(x, y);
@ -1702,7 +1699,7 @@ static void draw_curve( int x1, int y1, int x2, int y2,
draw_line( ((xl1>>3)+1)>>1, ((yl1>>3)+1)>>1, draw_line( ((xl1>>3)+1)>>1, ((yl1>>3)+1)>>1,
((xr3>>3)+1)>>1, ((yr3>>3)+1)>>1 ); ((xr3>>3)+1)>>1, ((yr3>>3)+1)>>1 );
} }
} }
#undef PUSH #undef PUSH
#undef POP #undef POP
} }
@ -2090,8 +2087,8 @@ static void linear_gradient( int x1, int y1, int x2, int y2 )
rgb2hsv( r2, g2, b2, &h2, &s2, &v2 ); rgb2hsv( r2, g2, b2, &h2, &s2, &v2 );
#define PUSH( x0, y0 ) \ #define PUSH( x0, y0 ) \
buffer.coord[i].x = (short)(x0); \ buffer.coord[i].x = (short)(x0); \
buffer.coord[i].y = (short)(y0); \ buffer.coord[i].y = (short)(y0); \
i++; i++;
#define POP( a, b ) \ #define POP( a, b ) \
i--; \ i--; \
@ -2186,8 +2183,8 @@ static void radial_gradient( int x1, int y1, int x2, int y2 )
rgb2hsv( r2, g2, b2, &h2, &s2, &v2 ); rgb2hsv( r2, g2, b2, &h2, &s2, &v2 );
#define PUSH( x0, y0 ) \ #define PUSH( x0, y0 ) \
buffer.coord[i].x = (short)(x0); \ buffer.coord[i].x = (short)(x0); \
buffer.coord[i].y = (short)(y0); \ buffer.coord[i].y = (short)(y0); \
i++; i++;
#define POP( a, b ) \ #define POP( a, b ) \
i--; \ i--; \
@ -2564,7 +2561,9 @@ static bool rockpaint_loop( void )
int button=0,i,j; int button=0,i,j;
int accelaration; int accelaration;
x = 10;
toolbar(); toolbar();
x = 0; y = 0;
restore_screen(); restore_screen();
inv_cursor(true); inv_cursor(true);