forked from len0rd/rockbox
Menu cursor now wraps around top and bottom. Reworked drawing of cursor
to be a bit more friendly. Made use of lcd_clear_display instead of lcd_clearrect with the full display for x, y. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@395 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
46f5461ac7
commit
67dc94786b
1 changed files with 94 additions and 59 deletions
|
|
@ -26,30 +26,57 @@
|
||||||
|
|
||||||
extern void tetris(void);
|
extern void tetris(void);
|
||||||
|
|
||||||
#define LINE_HEIGHT 8
|
#define MENU_ITEM_FONT 0
|
||||||
|
#define MENU_ITEM_Y_LOC 6
|
||||||
|
#define MENU_LINE_HEIGHT 8
|
||||||
|
|
||||||
#define MAX_LINE 3 /* the last index with info, starting on 0 */
|
/* menu ids */
|
||||||
|
#define ITEM_TETRIS 0
|
||||||
|
#define ITEM_SCREENSAVER 1
|
||||||
|
#define ITEM_BROWSE 2
|
||||||
|
#define ITEM_ROCKABOX 3
|
||||||
|
|
||||||
/* global cursor */
|
/* the last index with info, starting on 0 */
|
||||||
int cursor = 0;
|
#define MAX_LINE 3
|
||||||
|
|
||||||
|
int menu_top = 0;
|
||||||
|
int menu_bottom = MAX_LINE;
|
||||||
|
|
||||||
|
void add_menu_item(int location, char *string)
|
||||||
|
{
|
||||||
|
lcd_puts(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location,
|
||||||
|
string, MENU_ITEM_FONT);
|
||||||
|
if (location < menu_top)
|
||||||
|
menu_top = location;
|
||||||
|
if (location > menu_bottom)
|
||||||
|
menu_bottom = location;
|
||||||
|
}
|
||||||
|
|
||||||
void menu_init(void)
|
void menu_init(void)
|
||||||
{
|
{
|
||||||
lcd_puts(6, 0, "Rockabox", 0);
|
/* x, y, string, font */
|
||||||
lcd_puts(6, 8, "Screen Saver", 0);
|
/* lcd_puts(6, 0, "Rockabox", 0);*/
|
||||||
#define LINE_SS 1
|
add_menu_item(ITEM_ROCKABOX, "Rockabox");
|
||||||
lcd_puts(6, 16, "Browse", 0);
|
add_menu_item(ITEM_SCREENSAVER, "Screen Saver");
|
||||||
#define LINE_BROWSE 2
|
add_menu_item(ITEM_BROWSE, "Browse");
|
||||||
lcd_puts(6, 24, "Tetris", 0);
|
add_menu_item(ITEM_TETRIS, "Tetris");
|
||||||
#define LINE_TETRIS 3
|
|
||||||
lcd_puts(8, 38, "Rockbox!", 2);
|
|
||||||
|
|
||||||
lcd_puts(0, cursor, "-", 0);
|
lcd_puts(8, 38, "Rockbox!", 2);
|
||||||
|
put_cursor(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move the cursor to a particular id */
|
||||||
|
int put_cursor(int current, int target)
|
||||||
|
{
|
||||||
|
lcd_puts(0, current*MENU_LINE_HEIGHT, " ", 0);
|
||||||
|
lcd_puts(0, target*MENU_LINE_HEIGHT, "-", 0);
|
||||||
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
int key;
|
int key;
|
||||||
|
int cursor = 0;
|
||||||
|
|
||||||
menu_init();
|
menu_init();
|
||||||
|
|
||||||
|
|
@ -62,39 +89,47 @@ void app_main(void)
|
||||||
}
|
}
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case BUTTON_UP:
|
case BUTTON_UP:
|
||||||
if(cursor) {
|
if(cursor == menu_top ){
|
||||||
lcd_puts(0, cursor, " ", 0);
|
/* wrap around to menu bottom */
|
||||||
cursor-= LINE_HEIGHT;
|
printf("from (%d) to (%d)\n", cursor, menu_bottom);
|
||||||
lcd_puts(0, cursor, "-", 0);
|
cursor = put_cursor(cursor, menu_bottom);
|
||||||
|
} else {
|
||||||
|
/* move up */
|
||||||
|
printf("from (%d) to (%d)\n", cursor, cursor-1);
|
||||||
|
cursor = put_cursor(cursor, cursor-1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BUTTON_DOWN:
|
case BUTTON_DOWN:
|
||||||
if(cursor<(MAX_LINE*LINE_HEIGHT)) {
|
if(cursor == menu_bottom ){
|
||||||
lcd_puts(0, cursor, " ", 0);
|
/* wrap around to menu top */
|
||||||
cursor+=LINE_HEIGHT;
|
printf("from (%d) to (%d)\n", cursor, menu_top);
|
||||||
lcd_puts(0, cursor, "-", 0);
|
cursor = put_cursor(cursor, menu_top);
|
||||||
|
} else {
|
||||||
|
/* move down */
|
||||||
|
printf("from (%d) to (%d)\n", cursor, cursor+1);
|
||||||
|
cursor = put_cursor(cursor, cursor+1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BUTTON_RIGHT:
|
case BUTTON_RIGHT:
|
||||||
case BUTTON_PLAY:
|
case BUTTON_PLAY:
|
||||||
|
/* Erase current display state */
|
||||||
|
lcd_clear_display();
|
||||||
|
|
||||||
switch(cursor) {
|
switch(cursor) {
|
||||||
case (LINE_TETRIS * LINE_HEIGHT):
|
case ITEM_TETRIS:
|
||||||
lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
|
|
||||||
tetris();
|
tetris();
|
||||||
lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
|
|
||||||
menu_init();
|
|
||||||
break;
|
break;
|
||||||
case (LINE_BROWSE * LINE_HEIGHT):
|
case ITEM_BROWSE:
|
||||||
dirbrowse("/");
|
dirbrowse("/");
|
||||||
lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
|
|
||||||
menu_init();
|
|
||||||
break;
|
break;
|
||||||
case (LINE_SS * LINE_HEIGHT):
|
case ITEM_SCREENSAVER:
|
||||||
screensaver();
|
screensaver();
|
||||||
lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
|
|
||||||
menu_init();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return to previous display state */
|
||||||
|
lcd_clear_display();
|
||||||
|
menu_init();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lcd_update();
|
lcd_update();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue