forked from len0rd/rockbox
Cleaned up for menu.c/h usage
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@465 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
083e7d451b
commit
fe6c52cc76
1 changed files with 17 additions and 74 deletions
|
@ -21,125 +21,68 @@
|
||||||
#include "lcd.h"
|
#include "lcd.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
#include "menu.h"
|
||||||
|
|
||||||
/* Apps to include */
|
/* Apps to include */
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
#include "screensaver.h"
|
|
||||||
|
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
|
|
||||||
extern void tetris(void);
|
/*#include "screensaver.h"*/
|
||||||
|
|
||||||
#define MENU_ITEM_FONT 0
|
/*extern void tetris(void);*/
|
||||||
#define MENU_ITEM_Y_LOC 6
|
|
||||||
#define MENU_LINE_HEIGHT 8
|
|
||||||
|
|
||||||
enum Menu_Ids {
|
|
||||||
Tetris, Screen_Saver, Browse, Last_Id
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Menu_Items {
|
|
||||||
int menu_id;
|
|
||||||
const char *menu_desc;
|
|
||||||
void (*function) (void);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Menu_Items items[] = {
|
|
||||||
{ Tetris, "Tetris", tetris },
|
|
||||||
{ Screen_Saver, "Screen Saver", screensaver },
|
|
||||||
{ Browse, "Browse", browse_root },
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
int menu_top = Tetris;
|
|
||||||
int menu_bottom = Last_Id-1;
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Move the cursor to a particular id,
|
|
||||||
* current: where it is now
|
|
||||||
* target: where you want it to be
|
|
||||||
* Returns: the new current location
|
|
||||||
*/
|
|
||||||
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();
|
||||||
cursor = put_cursor(menu_top, menu_top);
|
put_cursor_menu_top();
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
key = button_get();
|
key = button_get();
|
||||||
|
|
||||||
if(!key) {
|
if(!key) {
|
||||||
sleep(1);
|
sleep(1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case BUTTON_UP:
|
case BUTTON_UP:
|
||||||
if(cursor == menu_top ){
|
if(is_cursor_menu_top()){
|
||||||
/* wrap around to menu bottom */
|
/* wrap around to menu bottom */
|
||||||
cursor = put_cursor(cursor, menu_bottom);
|
put_cursor_menu_bottom();
|
||||||
} else {
|
} else {
|
||||||
/* move up */
|
/* move up */
|
||||||
cursor = put_cursor(cursor, cursor-1);
|
move_cursor_up();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BUTTON_DOWN:
|
case BUTTON_DOWN:
|
||||||
if(cursor == menu_bottom ){
|
if(is_cursor_menu_bottom() ){
|
||||||
/* wrap around to menu top */
|
/* wrap around to menu top */
|
||||||
cursor = put_cursor(cursor, menu_top);
|
put_cursor_menu_top();
|
||||||
} else {
|
} else {
|
||||||
/* move down */
|
/* move down */
|
||||||
cursor = put_cursor(cursor, cursor+1);
|
move_cursor_down();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BUTTON_RIGHT:
|
case BUTTON_RIGHT:
|
||||||
case BUTTON_PLAY:
|
case BUTTON_PLAY:
|
||||||
/* Erase current display state */
|
/* Erase current display state */
|
||||||
lcd_clear_display();
|
lcd_clear_display();
|
||||||
|
|
||||||
/* call the proper function for this line */
|
execute_menu_item();
|
||||||
items[cursor].function();
|
|
||||||
|
|
||||||
/* Return to previous display state */
|
/* Return to previous display state */
|
||||||
lcd_clear_display();
|
lcd_clear_display();
|
||||||
menu_init();
|
menu_init();
|
||||||
cursor = put_cursor(cursor, cursor);
|
|
||||||
break;
|
break;
|
||||||
case BUTTON_OFF:
|
case BUTTON_OFF:
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
lcd_update();
|
lcd_update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue