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,78 +21,23 @@
|
|||
#include "lcd.h"
|
||||
#include "button.h"
|
||||
#include "kernel.h"
|
||||
#include "menu.h"
|
||||
|
||||
/* Apps to include */
|
||||
#include "tree.h"
|
||||
#include "screensaver.h"
|
||||
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
|
||||
extern void tetris(void);
|
||||
/*#include "screensaver.h"*/
|
||||
|
||||
#define MENU_ITEM_FONT 0
|
||||
#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;
|
||||
}
|
||||
/*extern void tetris(void);*/
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
int key;
|
||||
int cursor = 0;
|
||||
|
||||
menu_init();
|
||||
cursor = put_cursor(menu_top, menu_top);
|
||||
put_cursor_menu_top();
|
||||
|
||||
while(1) {
|
||||
key = button_get();
|
||||
|
@ -104,21 +49,21 @@ void app_main(void)
|
|||
|
||||
switch(key) {
|
||||
case BUTTON_UP:
|
||||
if(cursor == menu_top ){
|
||||
if(is_cursor_menu_top()){
|
||||
/* wrap around to menu bottom */
|
||||
cursor = put_cursor(cursor, menu_bottom);
|
||||
put_cursor_menu_bottom();
|
||||
} else {
|
||||
/* move up */
|
||||
cursor = put_cursor(cursor, cursor-1);
|
||||
move_cursor_up();
|
||||
}
|
||||
break;
|
||||
case BUTTON_DOWN:
|
||||
if(cursor == menu_bottom ){
|
||||
if(is_cursor_menu_bottom() ){
|
||||
/* wrap around to menu top */
|
||||
cursor = put_cursor(cursor, menu_top);
|
||||
put_cursor_menu_top();
|
||||
} else {
|
||||
/* move down */
|
||||
cursor = put_cursor(cursor, cursor+1);
|
||||
move_cursor_down();
|
||||
}
|
||||
break;
|
||||
case BUTTON_RIGHT:
|
||||
|
@ -126,13 +71,11 @@ void app_main(void)
|
|||
/* Erase current display state */
|
||||
lcd_clear_display();
|
||||
|
||||
/* call the proper function for this line */
|
||||
items[cursor].function();
|
||||
execute_menu_item();
|
||||
|
||||
/* Return to previous display state */
|
||||
lcd_clear_display();
|
||||
menu_init();
|
||||
cursor = put_cursor(cursor, cursor);
|
||||
break;
|
||||
case BUTTON_OFF:
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue