diff options
-rw-r--r-- | uisimulator/app.c | 10 | ||||
-rw-r--r-- | uisimulator/menu.c | 12 | ||||
-rw-r--r-- | uisimulator/play.c | 94 | ||||
-rw-r--r-- | uisimulator/screensaver.c | 10 | ||||
-rw-r--r-- | uisimulator/tetris.c | 12 | ||||
-rw-r--r-- | uisimulator/tree.c | 401 | ||||
-rw-r--r-- | uisimulator/x11/Makefile | 4 | ||||
-rw-r--r-- | uisimulator/x11/lcd-x11.c | 3 |
8 files changed, 294 insertions, 252 deletions
diff --git a/uisimulator/app.c b/uisimulator/app.c index aa77fccd94..7c28e7a3da 100644 --- a/uisimulator/app.c +++ b/uisimulator/app.c @@ -97,15 +97,7 @@ void app_main(void) lcd_puts(0,0, "Mooo!"); lcd_puts(1,1, " Rockbox!"); - while(1) { - key = button_get(); - - if(!key) { - sleep(1); - continue; - } - - } + browse_root(); } diff --git a/uisimulator/menu.c b/uisimulator/menu.c index 0dc1599fe9..1619b33676 100644 --- a/uisimulator/menu.c +++ b/uisimulator/menu.c @@ -86,7 +86,7 @@ void move_cursor_down(void) void redraw_cursor(void) { - lcd_puts(0, cursor*menu_line_height, "-", 0); + lcd_putsxy(0, cursor*menu_line_height, "-", 0); } /* @@ -96,9 +96,9 @@ void redraw_cursor(void) */ void put_cursor(int target) { - lcd_puts(0, cursor*menu_line_height, " ", 0); + lcd_putsxy(0, cursor*menu_line_height, " ",0); cursor = target; - lcd_puts(0, cursor*menu_line_height, "-", 0); + lcd_putsxy(0, cursor*menu_line_height, "-",0); } /* We call the function pointer related to the current cursor position */ @@ -110,8 +110,8 @@ void execute_menu_item(void) void add_menu_item(int location, char *string) { - lcd_puts(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location, - string, MENU_ITEM_FONT); + lcd_putsxy(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location, string, + MENU_ITEM_FONT); if (location < menu_top) menu_top = location; if (location > menu_bottom) @@ -130,7 +130,7 @@ void menu_init(void) for (i = i; i < Last_Id; i++) add_menu_item(items[i].menu_id, (char *) items[i].menu_desc); - lcd_puts(8, 38, "Rockbox!", 2); + lcd_putsxy(8, 38, "Rockbox!",2); redraw_cursor(); } diff --git a/uisimulator/play.c b/uisimulator/play.c index f9877134eb..735597962e 100644 --- a/uisimulator/play.c +++ b/uisimulator/play.c @@ -26,6 +26,7 @@ #include <button.h> #include "kernel.h" #include "tree.h" +#include "debug.h" #include "id3.h" @@ -33,63 +34,70 @@ #include "x11/mpegplay.h" #endif -#define LINE_Y 8 /* initial line */ -#define LINE_HEIGTH 8 /* line height in pixels */ +#define LINE_Y 1 /* initial line */ void playtune(char *dir, char *file) { - char buffer[256]; - int fd; - mp3entry mp3; - bool good=1; + char buffer[256]; + int fd; + mp3entry mp3; + bool good=1; - sprintf(buffer, "%s/%s", dir, file); + sprintf(buffer, "%s/%s", dir, file); - if(mp3info(&mp3, buffer)) { - debugf("id3 failure!"); - good=0; - } + if(mp3info(&mp3, buffer)) { + DEBUGF("id3 failure!"); + good=0; + } + lcd_clear_display(); #ifdef HAVE_LCD_BITMAP - lcd_clear_display(); - if(!good) { - lcd_puts(0, 0, "[no id3 info]", 0); - } - else { - lcd_puts(0, 0, "[id3 info]", 0); - lcd_puts(0, LINE_Y, mp3.title?mp3.title:"", 0); - lcd_puts(0, LINE_Y+1*LINE_HEIGTH, mp3.album?mp3.album:"", 0); - lcd_puts(0, LINE_Y+2*LINE_HEIGTH, mp3.artist?mp3.artist:"", 0); + lcd_setmargins(0,0); + lcd_setfont(0); +#endif + + if(!good) { + lcd_puts(0, 0, "[no id3 info]"); + } + else { +#ifdef HAVE_LCD_BITMAP + lcd_puts(0, 0, "[id3 info]"); + lcd_puts(0, LINE_Y, mp3.title?mp3.title:""); + lcd_puts(0, LINE_Y+1, mp3.album?mp3.album:""); + lcd_puts(0, LINE_Y+2, mp3.artist?mp3.artist:""); - sprintf(buffer, "%d ms", mp3.length); - lcd_puts(0, LINE_Y+3*LINE_HEIGTH, buffer, 0); + sprintf(buffer, "%d ms", mp3.length); + lcd_puts(0, LINE_Y+3, buffer); - sprintf(buffer, "%d kbits", mp3.bitrate); - lcd_puts(0, LINE_Y+4*LINE_HEIGTH, buffer, 0); + sprintf(buffer, "%d kbits", mp3.bitrate); + lcd_puts(0, LINE_Y+4, buffer); - sprintf(buffer, "%d Hz", mp3.frequency); - lcd_puts(0, LINE_Y+5*LINE_HEIGTH, buffer, 0); - } - lcd_update(); + sprintf(buffer, "%d Hz", mp3.frequency); + lcd_puts(0, LINE_Y+5, buffer); +#else + lcd_puts(0, 0, mp3.artist?mp3.artist:"<no artist>"); + lcd_puts(0, 1, mp3.title?mp3.title:"<no title>"); #endif + } + lcd_update(); #ifdef MPEG_PLAY - sprintf(buffer, "%s/%s", dir, file); - mpeg_play(buffer); - return; + sprintf(buffer, "%s/%s", dir, file); + mpeg_play(buffer); + return; #endif - while(1) { - int key = button_get(); + while(1) { + int key = button_get(); - if(!key) { - sleep(30); - continue; - } - switch(key) { - case BUTTON_OFF: - case BUTTON_LEFT: - return; - break; + if(!key) { + sleep(30); + continue; + } + switch(key) { + case BUTTON_OFF: + case BUTTON_LEFT: + return; + break; + } } - } } diff --git a/uisimulator/screensaver.c b/uisimulator/screensaver.c index a4166f20b4..a85ccf965d 100644 --- a/uisimulator/screensaver.c +++ b/uisimulator/screensaver.c @@ -84,11 +84,11 @@ void ss_loop(void) void screensaver(void) { - char w, h; + int w, h; char *off = "[Off] to stop"; int len = strlen(SS_TITLE); - lcd_fontsize(SS_TITLE_FONT, &w, &h); + lcd_getfontsize(SS_TITLE_FONT, &w, &h); /* Get horizontel centering for text */ len *= w; @@ -103,10 +103,10 @@ void screensaver(void) h /= 2; lcd_clear_display(); - lcd_puts(LCD_WIDTH/2-len, (LCD_HEIGHT/2)-h, SS_TITLE, SS_TITLE_FONT); + lcd_putsxy(LCD_WIDTH/2-len, (LCD_HEIGHT/2)-h, SS_TITLE, SS_TITLE_FONT); len = strlen(off); - lcd_fontsize(0, &w, &h); + lcd_getfontsize(0, &w, &h); /* Get horizontel centering for text */ len *= w; @@ -120,7 +120,7 @@ void screensaver(void) else h /= 2; - lcd_puts(LCD_WIDTH/2-len, LCD_HEIGHT-(2*h), off, 0); + lcd_putsxy(LCD_WIDTH/2-len, LCD_HEIGHT-(2*h), off,0); lcd_update(); sleep(150); diff --git a/uisimulator/tetris.c b/uisimulator/tetris.c index 2f02e042d4..8884fd8964 100644 --- a/uisimulator/tetris.c +++ b/uisimulator/tetris.c @@ -310,14 +310,14 @@ void game_loop(void) sleep(10); } if(gameover()) { - char w, h; + int w, h; - lcd_fontsize(TETRIS_TITLE_FONT, &w, &h); + lcd_getfontsize(TETRIS_TITLE_FONT, &w, &h); lcd_clearrect(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, TETRIS_TITLE_XLOC+(w*sizeof(TETRIS_TITLE)), TETRIS_TITLE_YLOC-h); - lcd_puts(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, - "You lose!", TETRIS_TITLE_FONT); + lcd_putsxy(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, "You lose!", + TETRIS_TITLE_FONT); lcd_update(); sleep(2); return; @@ -349,8 +349,8 @@ void tetris(void) init_tetris(); draw_frame(start_x-1,start_x+max_x,start_y-1,start_y+max_y); - lcd_puts(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, - TETRIS_TITLE, TETRIS_TITLE_FONT); + lcd_putsxy(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, TETRIS_TITLE, + TETRIS_TITLE_FONT); lcd_update(); next_b = t_rand(blocks); diff --git a/uisimulator/tree.c b/uisimulator/tree.c index ed7ebad000..0382547590 100644 --- a/uisimulator/tree.c +++ b/uisimulator/tree.c @@ -32,13 +32,8 @@ #include "play.h" -#define TREE_MAX_FILENAMELEN 64 -#define TREE_MAX_ON_SCREEN 7 -#define TREE_MAX_LEN_DISPLAY 16 /* max length that fits on screen */ - -void browse_root(void) { - dirbrowse("/"); -} + +#define TREE_MAX_FILENAMELEN 128 struct entry { int file; /* TRUE if file, FALSE if dir */ @@ -46,204 +41,250 @@ struct entry { int namelen; }; -#define LINE_Y 8 /* Y position the entry-list starts at */ -#define LINE_X 12 /* X position the entry-list starts at */ -#define LINE_HEIGTH 8 /* pixels for each text line */ +void browse_root(void) +{ + dirbrowse("/"); +} + #ifdef HAVE_LCD_BITMAP +#define TREE_MAX_ON_SCREEN 7 +#define TREE_MAX_LEN_DISPLAY 16 /* max length that fits on screen */ + +#define MARGIN_Y 8 /* Y pixel margin */ +#define MARGIN_X 12 /* X pixel margin */ +#define LINE_Y 0 /* Y position the entry-list starts at */ +#define LINE_X 2 /* X position the entry-list starts at */ +#define LINE_HEIGTH 8 /* pixels for each text line */ + extern unsigned char bitmap_icons_6x8[LastIcon][6]; extern icons_6x8; +#else /* HAVE_LCD_BITMAP */ + +#define TREE_MAX_ON_SCREEN 2 +#define TREE_MAX_LEN_DISPLAY 11 /* max length that fits on screen */ +#define LINE_Y 0 /* Y position the entry-list starts at */ +#define LINE_X 1 /* X position the entry-list starts at */ + +#endif /* HAVE_LCD_BITMAP */ + int static showdir(char *path, struct entry *buffer, int start, int scrollpos, int* at_end) { - int i; - int j=0; - int icon_type = 0; - DIR *dir = opendir(path); - struct dirent *entry; - - if(!dir) - return -1; /* not a directory */ - - i=start; - *at_end=0; /* Have we displayed the last directory entry? */ - while((entry = readdir(dir))) { - int len; - - if(entry->d_name[0] == '.') - /* skip names starting with a dot */ - continue; - - if(j++ < scrollpos) - continue ; - - len = strlen(entry->d_name); - if(len < TREE_MAX_FILENAMELEN) - /* strncpy() is evil, we memcpy() instead, +1 includes the - trailing zero */ - memcpy(buffer[i].name, entry->d_name, len+1); - else - memcpy(buffer[i].name, "too long", 9); - - buffer[i].file = !(entry->attribute&ATTR_DIRECTORY); - - buffer[i].file?(icon_type=File):(icon_type=Folder); - lcd_bitmap(bitmap_icons_6x8[icon_type], 6, LINE_Y+i*LINE_HEIGTH, 6, - 8, TRUE); - - if(len < TREE_MAX_LEN_DISPLAY) - lcd_puts(LINE_X, LINE_Y+i*LINE_HEIGTH, buffer[i].name, 0); - else { - char storage = buffer[i].name[TREE_MAX_LEN_DISPLAY]; - buffer[i].name[TREE_MAX_LEN_DISPLAY]=0; - lcd_puts(LINE_X, LINE_Y+i*LINE_HEIGTH, buffer[i].name, 0); - buffer[i].name[TREE_MAX_LEN_DISPLAY]=storage; - } + int i; + int j=0; + int icon_type = 0; + DIR *dir = opendir(path); + struct dirent *entry; - if(++i >= TREE_MAX_ON_SCREEN) - break; - } - - if (entry==0) { - *at_end=1; - } else { - *at_end=(readdir(dir)==0); - } - j = i ; - while (j++ < TREE_MAX_ON_SCREEN) { - lcd_puts(LINE_X, LINE_Y+j*LINE_HEIGTH," ", 0); - } - closedir(dir); - - return i; -} + if(!dir) + return -1; /* not a directory */ + + i=start; + *at_end=0; /* Have we displayed the last directory entry? */ + while((entry = readdir(dir))) { + int len; + if(entry->d_name[0] == '.') + /* skip names starting with a dot */ + continue; + + if(j++ < scrollpos) + continue ; + + len = strlen(entry->d_name); + if(len < TREE_MAX_FILENAMELEN) + /* strncpy() is evil, we memcpy() instead, +1 includes the + trailing zero */ + memcpy(buffer[i].name, entry->d_name, len+1); + else + memcpy(buffer[i].name, "too long", 9); + + buffer[i].file = !(entry->attribute&ATTR_DIRECTORY); + +#ifdef HAVE_LCD_BITMAP + if ( buffer[i].file ) + icon_type=File; + else + icon_type=Folder; + lcd_bitmap(bitmap_icons_6x8[icon_type], 6, MARGIN_Y+i*LINE_HEIGTH, 6, + 8, TRUE); #endif + if(len < TREE_MAX_LEN_DISPLAY) + lcd_puts(LINE_X, LINE_Y+i, buffer[i].name); + else { + char storage = buffer[i].name[TREE_MAX_LEN_DISPLAY]; + buffer[i].name[TREE_MAX_LEN_DISPLAY]=0; + lcd_puts(LINE_X, LINE_Y+i, buffer[i].name); + buffer[i].name[TREE_MAX_LEN_DISPLAY]=storage; + } + + if(++i >= TREE_MAX_ON_SCREEN) + break; + } + + if (entry==0) { + *at_end=1; + } else { + *at_end=(readdir(dir)==0); + } + j = i ; + while (j++ < TREE_MAX_ON_SCREEN) { + lcd_puts(LINE_X, LINE_Y+j," "); + } + closedir(dir); + + return i; +} + bool dirbrowse(char *root) { - struct entry buffer[TREE_MAX_ON_SCREEN]; - int numentries; - char buf[255]; - char currdir[255]; - int dircursor=0; - int i; - int start=0; - int at_end=0; + struct entry buffer[TREE_MAX_ON_SCREEN]; + int numentries; + char buf[255]; + char currdir[255]; + int dircursor=0; + int i; + int start=0; + int at_end=0; -#ifdef HAVE_LCD_BITMAP - lcd_clear_display(); + lcd_clear_display(); - lcd_puts(0,0, "[Browse]", 0); - memcpy(currdir,root,sizeof(currdir)); +#ifdef HAVE_LCD_BITMAP + lcd_putsxy(0,0, "[Browse]",0); + lcd_setmargins(0,MARGIN_Y); + lcd_setfont(0); +#endif + memcpy(currdir,root,sizeof(currdir)); - numentries = showdir(root, buffer, 0, start, &at_end); + numentries = showdir(root, buffer, 0, start, &at_end); - if (numentries == -1) return -1; /* root is not a directory */ + if (numentries == -1) + return -1; /* root is not a directory */ - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); + lcd_puts(0, dircursor, "-"); + lcd_update(); - lcd_update(); + while(1) { + int key = button_get(); - while(1) { - int key = button_get(); + if(!key) { + sleep(1); + continue; + } + switch(key) { + case BUTTON_OFF: + return FALSE; + break; + + case BUTTON_LEFT: + i=strlen(currdir); + if (i==1) { + return FALSE; + } + else { + while (currdir[i-1]!='/') + i--; + strcpy(buf,&currdir[i]); + if (i==1) + currdir[i]=0; + else + currdir[i-1]=0; + + lcd_clear_display(); +#ifdef HAVE_LCD_BITMAP + lcd_putsxy(0,0, "[Browse]",0); +#endif + numentries = showdir(currdir, buffer, 0, 0, &at_end); + dircursor=0; + start=0; + while ( (dircursor < TREE_MAX_ON_SCREEN) && + (strcmp(buffer[dircursor].name,buf)!=0)) + dircursor++; + if (dircursor==TREE_MAX_ON_SCREEN) + dircursor=0; + lcd_puts(0, LINE_Y+dircursor, "-"); + lcd_update(); + } + + break; + + case BUTTON_RIGHT: + case BUTTON_PLAY: + if ((currdir[0]=='/') && (currdir[1]==0)) { + sprintf(buf,"%s%s",currdir,buffer[dircursor].name); + } else { + sprintf(buf,"%s/%s",currdir,buffer[dircursor].name); + } + + if (!buffer[dircursor].file) { + memcpy(currdir,buf,sizeof(currdir)); + dircursor=0; + start=0; + } else { + playtune(currdir, buffer[dircursor].name); +#ifdef HAVE_LCD_BITMAP + lcd_setmargins(0, MARGIN_Y); + lcd_setfont(0); +#endif + } - if(!key) { - sleep(1); - continue; - } - switch(key) { - case BUTTON_OFF: - return FALSE; - break; - - case BUTTON_LEFT: - i=strlen(currdir); - if (i==1) { - return FALSE; - } else { - while (currdir[i-1]!='/') i--; - strcpy(buf,&currdir[i]); - if (i==1) currdir[i]=0; - else currdir[i-1]=0; - - lcd_clear_display(); - lcd_puts(0,0, "[Browse]", 0); - numentries = showdir(currdir, buffer, 0, 0, &at_end); - dircursor=0; - start=0; - while ( (dircursor < TREE_MAX_ON_SCREEN) && - (strcmp(buffer[dircursor].name,buf)!=0)) dircursor++; - if (dircursor==TREE_MAX_ON_SCREEN) dircursor=0; - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); - lcd_update(); - } - - break; - - case BUTTON_RIGHT: - case BUTTON_PLAY: - if ((currdir[0]=='/') && (currdir[1]==0)) { - sprintf(buf,"%s%s",currdir,buffer[dircursor].name); - } else { - sprintf(buf,"%s/%s",currdir,buffer[dircursor].name); - } - - if (!buffer[dircursor].file) { - memcpy(currdir,buf,sizeof(currdir)); - dircursor=0; - start=0; - } else { - playtune(currdir, buffer[dircursor].name); - } - - lcd_clear_display(); - lcd_puts(0,0, "[Browse]", 0); - numentries = showdir(currdir, buffer, 0, start, &at_end); - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); - lcd_update(); - break; + lcd_clear_display(); + numentries = showdir(currdir, buffer, 0, start, &at_end); +#ifdef HAVE_LCD_BITMAP + lcd_putsxy(0,0, "[Browse]",0); +#endif + lcd_puts(0, LINE_Y+dircursor, "-"); + lcd_update(); + break; - case BUTTON_UP: - if(dircursor) { - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0); - dircursor--; - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); - lcd_update(); - } else - { - if (start) { - lcd_clear_display(); - lcd_puts(0,0, "[Browse]", 0); - numentries = showdir(currdir, buffer, 0, --start, &at_end); - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); - lcd_update(); - } - } - break; - case BUTTON_DOWN: - if(dircursor+1 < numentries) { - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0); - dircursor++; - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); - lcd_update(); - } else - { - if (!at_end) { - lcd_clear_display(); - lcd_puts(0,0, "[Browse]", 0); - numentries = showdir(currdir, buffer, 0, ++start, &at_end); - - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); - lcd_update(); + case BUTTON_UP: + if(dircursor) { + lcd_puts(0, LINE_Y+dircursor, " "); + dircursor--; + lcd_puts(0, LINE_Y+dircursor, "-"); + lcd_update(); + } else + { + if (start) { + lcd_clear_display(); + start--; + numentries = showdir(currdir, buffer, 0, + start, &at_end); +#ifdef HAVE_LCD_BITMAP + lcd_putsxy(0,0, "[Browse]",0); +#endif + lcd_puts(0, LINE_Y+dircursor, "-"); + lcd_update(); + } + } + break; + case BUTTON_DOWN: + if(dircursor+1 < numentries) { + lcd_puts(0, LINE_Y+dircursor, " "); + dircursor++; + lcd_puts(0, LINE_Y+dircursor, "-"); + lcd_update(); + } else + { + if (!at_end) { + lcd_clear_display(); + start++; + numentries = showdir(currdir, buffer, 0, + start, &at_end); +#ifdef HAVE_LCD_BITMAP + lcd_putsxy(0,0, "[Browse]",0); +#endif + lcd_puts(0, LINE_Y+dircursor, "-"); + lcd_update(); + } + } + break; } - } - break; } - } -#endif - return FALSE; + return FALSE; } diff --git a/uisimulator/x11/Makefile b/uisimulator/x11/Makefile index 7cc8b088c3..1858ea5090 100644 --- a/uisimulator/x11/Makefile +++ b/uisimulator/x11/Makefile @@ -28,8 +28,8 @@ CC = gcc RM = rm -f DEBUG = -g -#DISPLAY = -DHAVE_LCD_CHARCELLS -DISPLAY = -DHAVE_LCD_BITMAP +DISPLAY = -DHAVE_LCD_CHARCELLS +#DISPLAY = -DHAVE_LCD_BITMAP DEFINES = -DHAVE_CONFIG_H -DGETTIMEOFDAY_TWO_ARGS -DSIMULATOR \ -DHAVE_RECORDER_KEYPAD $(DISPLAY) diff --git a/uisimulator/x11/lcd-x11.c b/uisimulator/x11/lcd-x11.c index 4d2eb4be54..d454532aa2 100644 --- a/uisimulator/x11/lcd-x11.c +++ b/uisimulator/x11/lcd-x11.c @@ -120,6 +120,7 @@ void lcd_puts(int x, int y, char *string) strncpy(buffer, string, 11); buffer[11]=0; - sim_lcd_puts(x*6, y*8, buffer, 0); + debugf("lcd_puts(%d,%d,%s)\n",x,y,string); + sim_lcd_puts(x, y, buffer, 0); } #endif |