summaryrefslogtreecommitdiff
path: root/uisimulator
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 /uisimulator
parent083e7d451b5ca220a7f54af5867bfe7fa0f24790 (diff)
downloadrockbox-fe6c52cc76db6605317ebaafb493d311702e8d1f.tar.gz
rockbox-fe6c52cc76db6605317ebaafb493d311702e8d1f.zip
Cleaned up for menu.c/h usage
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@465 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator')
-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 @@
21#include "lcd.h" 21#include "lcd.h"
22#include "button.h" 22#include "button.h"
23#include "kernel.h" 23#include "kernel.h"
24#include "menu.h"
24 25
25/* Apps to include */ 26/* Apps to include */
26#include "tree.h" 27#include "tree.h"
27#include "screensaver.h"
28 28
29#ifdef HAVE_LCD_BITMAP 29#ifdef HAVE_LCD_BITMAP
30 30
31extern void tetris(void); 31/*#include "screensaver.h"*/
32 32
33#define MENU_ITEM_FONT 0 33/*extern void tetris(void);*/
34#define MENU_ITEM_Y_LOC 6
35#define MENU_LINE_HEIGHT 8
36
37enum Menu_Ids {
38 Tetris, Screen_Saver, Browse, Last_Id
39};
40
41struct Menu_Items {
42 int menu_id;
43 const char *menu_desc;
44 void (*function) (void);
45};
46
47struct Menu_Items items[] = {
48 { Tetris, "Tetris", tetris },
49 { Screen_Saver, "Screen Saver", screensaver },
50 { Browse, "Browse", browse_root },
51};
52
53
54int menu_top = Tetris;
55int menu_bottom = Last_Id-1;
56
57void add_menu_item(int location, char *string)
58{
59 lcd_puts(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location,
60 string, MENU_ITEM_FONT);
61 if (location < menu_top)
62 menu_top = location;
63 if (location > menu_bottom)
64 menu_bottom = location;
65}
66
67void menu_init(void)
68{
69 int i = 0;
70 for (i = i; i < Last_Id; i++)
71 add_menu_item(items[i].menu_id, (char *) items[i].menu_desc);
72
73 lcd_puts(8, 38, "Rockbox!", 2);
74}
75
76/*
77 * Move the cursor to a particular id,
78 * current: where it is now
79 * target: where you want it to be
80 * Returns: the new current location
81 */
82int put_cursor(int current, int target)
83{
84 lcd_puts(0, current*MENU_LINE_HEIGHT, " ", 0);
85 lcd_puts(0, target*MENU_LINE_HEIGHT, "-", 0);
86 return target;
87}
88 34
89void app_main(void) 35void app_main(void)
90{ 36{
91 int key; 37 int key;
92 int cursor = 0; 38
93
94 menu_init(); 39 menu_init();
95 cursor = put_cursor(menu_top, menu_top); 40 put_cursor_menu_top();
96 41
97 while(1) { 42 while(1) {
98 key = button_get(); 43 key = button_get();
99 44
100 if(!key) { 45 if(!key) {
101 sleep(1); 46 sleep(1);
102 continue; 47 continue;
103 } 48 }
104 49
105 switch(key) { 50 switch(key) {
106 case BUTTON_UP: 51 case BUTTON_UP:
107 if(cursor == menu_top ){ 52 if(is_cursor_menu_top()){
108 /* wrap around to menu bottom */ 53 /* wrap around to menu bottom */
109 cursor = put_cursor(cursor, menu_bottom); 54 put_cursor_menu_bottom();
110 } else { 55 } else {
111 /* move up */ 56 /* move up */
112 cursor = put_cursor(cursor, cursor-1); 57 move_cursor_up();
113 } 58 }
114 break; 59 break;
115 case BUTTON_DOWN: 60 case BUTTON_DOWN:
116 if(cursor == menu_bottom ){ 61 if(is_cursor_menu_bottom() ){
117 /* wrap around to menu top */ 62 /* wrap around to menu top */
118 cursor = put_cursor(cursor, menu_top); 63 put_cursor_menu_top();
119 } else { 64 } else {
120 /* move down */ 65 /* move down */
121 cursor = put_cursor(cursor, cursor+1); 66 move_cursor_down();
122 } 67 }
123 break; 68 break;
124 case BUTTON_RIGHT: 69 case BUTTON_RIGHT:
125 case BUTTON_PLAY: 70 case BUTTON_PLAY:
126 /* Erase current display state */ 71 /* Erase current display state */
127 lcd_clear_display(); 72 lcd_clear_display();
128 73
129 /* call the proper function for this line */ 74 execute_menu_item();
130 items[cursor].function();
131 75
132 /* Return to previous display state */ 76 /* Return to previous display state */
133 lcd_clear_display(); 77 lcd_clear_display();
134 menu_init(); 78 menu_init();
135 cursor = put_cursor(cursor, cursor);
136 break; 79 break;
137 case BUTTON_OFF: 80 case BUTTON_OFF:
138 return; 81 return;
139 default: 82 default:
140 break; 83 break;
141 } 84 }
142 85
143 lcd_update(); 86 lcd_update();
144 } 87 }
145} 88}