summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Hak <adiamas@rockbox.org>2002-05-06 08:42:20 +0000
committerRobert Hak <adiamas@rockbox.org>2002-05-06 08:42:20 +0000
commitfe6c52cc76db6605317ebaafb493d311702e8d1f (patch)
tree5a9157fb3fd1e71dfefb67c836f22b52a7987ae5
parent083e7d451b5ca220a7f54af5867bfe7fa0f24790 (diff)
Cleaned up for menu.c/h usage
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@465 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--uisimulator/app.c91
1 files changed, 17 insertions, 74 deletions
diff --git a/uisimulator/app.c b/uisimulator/app.c
index b6fc838ef2..aa77fccd94 100644
--- a/uisimulator/app.c
+++ b/uisimulator/app.c
@@ -21,125 +21,68 @@
#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();
-
+
if(!key) {
sleep(1);
continue;
}
-
+
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:
case BUTTON_PLAY:
/* 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;
default:
break;
}
-
+
lcd_update();
}
}