diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-05-21 14:25:45 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-05-21 14:25:45 +0000 |
commit | b21a3bd240d04fcba296021da6eb1276fde84a73 (patch) | |
tree | b5a85b3b0f18c317b36a8955db5f2e3b0193fe1c /apps/menu.c | |
parent | 5d8e4c21562629481167eedfc70f3e9d7b3abfb1 (diff) | |
download | rockbox-b21a3bd240d04fcba296021da6eb1276fde84a73.tar.gz rockbox-b21a3bd240d04fcba296021da6eb1276fde84a73.zip |
Abstracted the menu interface
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@641 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/menu.c')
-rw-r--r-- | apps/menu.c | 228 |
1 files changed, 102 insertions, 126 deletions
diff --git a/apps/menu.c b/apps/menu.c index 3cd5038612..aaa0c94ff6 100644 --- a/apps/menu.c +++ b/apps/menu.c | |||
@@ -19,40 +19,26 @@ | |||
19 | 19 | ||
20 | #include "lcd.h" | 20 | #include "lcd.h" |
21 | #include "menu.h" | 21 | #include "menu.h" |
22 | 22 | #include "button.h" | |
23 | #include "tree.h" | 23 | #include "kernel.h" |
24 | #include "credits.h" | 24 | #include "debug.h" |
25 | |||
26 | #ifdef HAVE_LCD_BITMAP | ||
27 | |||
28 | #include "screensaver.h" | ||
29 | extern void tetris(void); | ||
30 | |||
31 | #define MENU_ITEM_FONT 0 | ||
32 | #define MENU_ITEM_Y_LOC 6 | ||
33 | #define MENU_LINE_HEIGHT 8 | ||
34 | |||
35 | enum Main_Menu_Ids { | ||
36 | Tetris, Screen_Saver, Browse, Splash, Credits, Last_Id | ||
37 | }; | ||
38 | |||
39 | struct main_menu_items items[] = { | ||
40 | { Tetris, "Tetris", tetris }, | ||
41 | { Screen_Saver, "Screen Saver", screensaver }, | ||
42 | { Browse, "Browse", browse_root }, | ||
43 | { Splash, "Splash", show_splash }, | ||
44 | { Credits, "Credits", show_credits }, | ||
45 | }; | ||
46 | 25 | ||
47 | /* Global values for menuing */ | 26 | /* Global values for menuing */ |
48 | int menu_top; | 27 | static int menu_top; |
49 | int menu_bottom; | 28 | static int menu_bottom; |
50 | int menu_line_height; | 29 | static int cursor; |
51 | int cursor; | 30 | static struct menu_items* items; |
31 | static int itemcount; | ||
52 | 32 | ||
53 | int get_line_height(void) | 33 | /* |
34 | * Move the cursor to a particular id, | ||
35 | * target: where you want it to be | ||
36 | */ | ||
37 | void put_cursor(int target) | ||
54 | { | 38 | { |
55 | return menu_line_height; | 39 | lcd_puts(0, cursor, " "); |
40 | cursor = target; | ||
41 | lcd_puts(0, cursor, "-"); | ||
56 | } | 42 | } |
57 | 43 | ||
58 | int is_cursor_menu_top(void) | 44 | int is_cursor_menu_top(void) |
@@ -87,18 +73,7 @@ void move_cursor_down(void) | |||
87 | 73 | ||
88 | void redraw_cursor(void) | 74 | void redraw_cursor(void) |
89 | { | 75 | { |
90 | lcd_putsxy(0, cursor*menu_line_height, "-", 0); | 76 | lcd_puts(0, cursor, "-"); |
91 | } | ||
92 | |||
93 | /* | ||
94 | * Move the cursor to a particular id, | ||
95 | * target: where you want it to be | ||
96 | */ | ||
97 | void put_cursor(int target) | ||
98 | { | ||
99 | lcd_putsxy(0, cursor*menu_line_height, " ",0); | ||
100 | cursor = target; | ||
101 | lcd_putsxy(0, cursor*menu_line_height, "-",0); | ||
102 | } | 77 | } |
103 | 78 | ||
104 | /* We call the function pointer related to the current cursor position */ | 79 | /* We call the function pointer related to the current cursor position */ |
@@ -108,104 +83,105 @@ void execute_menu_item(void) | |||
108 | items[cursor].function(); | 83 | items[cursor].function(); |
109 | } | 84 | } |
110 | 85 | ||
111 | void add_menu_item(int location, char *string) | 86 | void menu_init(struct menu_items* mitems, int count) |
112 | { | ||
113 | lcd_putsxy(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location, string, | ||
114 | MENU_ITEM_FONT); | ||
115 | if (location < menu_top) | ||
116 | menu_top = location; | ||
117 | if (location > menu_bottom) | ||
118 | menu_bottom = location; | ||
119 | } | ||
120 | |||
121 | int show_logo(void) | ||
122 | { | ||
123 | unsigned char buffer[112 * 8]; | ||
124 | |||
125 | int failure; | ||
126 | int width=0; | ||
127 | int height=0; | ||
128 | |||
129 | failure = read_bmp_file("/rockbox112.bmp", &width, &height, buffer); | ||
130 | |||
131 | debugf("read_bmp_file() returned %d, width %d height %d\n", | ||
132 | failure, width, height); | ||
133 | |||
134 | if (failure) { | ||
135 | debugf("Unable to find \"/rockbox112.bmp\"\n"); | ||
136 | return -1; | ||
137 | } else { | ||
138 | |||
139 | int i; | ||
140 | int eline; | ||
141 | |||
142 | for(i=0, eline=0; i< height; i+=8, eline++) { | ||
143 | int x,y; | ||
144 | |||
145 | /* the bitmap function doesn't work with full-height bitmaps | ||
146 | so we "stripe" the logo output */ | ||
147 | |||
148 | lcd_bitmap(&buffer[eline*width], 0, 10+i, width, | ||
149 | (height-i)>8?8:height-i, false); | ||
150 | |||
151 | #if 0 | ||
152 | /* for screen output debugging */ | ||
153 | for(y=0; y<8 && (i+y < height); y++) { | ||
154 | for(x=0; x < width; x++) { | ||
155 | |||
156 | if(buffer[eline*width + x] & (1<<y)) { | ||
157 | printf("*"); | ||
158 | } | ||
159 | else | ||
160 | printf(" "); | ||
161 | } | ||
162 | printf("\n"); | ||
163 | } | ||
164 | #endif | ||
165 | } | ||
166 | } | ||
167 | |||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | void menu_init(void) | ||
172 | { | 87 | { |
173 | menu_top = Tetris; | 88 | items = mitems; |
174 | menu_bottom = Last_Id-1; | 89 | itemcount = count; |
175 | menu_line_height = MENU_LINE_HEIGHT; | 90 | menu_top = items[0].id; |
91 | menu_bottom = count-1; | ||
176 | cursor = menu_top; | 92 | cursor = menu_top; |
177 | lcd_clear_display(); | 93 | #ifdef HAVE_LCD_BITMAP |
178 | lcd_update(); | 94 | lcd_setmargins(0,0); |
95 | lcd_setfont(0); | ||
96 | #endif | ||
97 | lcd_clear_display(); | ||
98 | lcd_update(); | ||
179 | } | 99 | } |
180 | 100 | ||
181 | void menu_draw(void) | 101 | void menu_draw(void) |
182 | { | 102 | { |
183 | int i = 0; | 103 | int i = 0; |
184 | 104 | ||
185 | for (i = i; i < Last_Id; i++) | 105 | for (i = 0; i < itemcount; i++) { |
186 | add_menu_item(items[i].menu_id, (char *) items[i].menu_desc); | 106 | lcd_puts(1, i, items[i].desc); |
107 | if (i < menu_top) | ||
108 | menu_top = i; | ||
109 | if (i > menu_bottom) | ||
110 | menu_bottom = i; | ||
111 | } | ||
187 | 112 | ||
188 | redraw_cursor(); | 113 | redraw_cursor(); |
189 | lcd_update(); | 114 | lcd_update(); |
190 | } | 115 | } |
191 | 116 | ||
192 | #endif /* end HAVE_LCD_BITMAP */ | 117 | void menu_run(void) |
193 | |||
194 | |||
195 | |||
196 | void show_splash(void) | ||
197 | { | 118 | { |
198 | 119 | int key; | |
199 | char *rockbox = "ROCKbox!"; | 120 | |
200 | lcd_clear_display(); | 121 | menu_draw(); |
201 | 122 | put_cursor_menu_top(); | |
202 | #ifdef HAVE_LCD_BITMAP | 123 | |
203 | if (show_logo() != 0) | 124 | while(1) { |
204 | return; | 125 | key = button_get(); |
126 | if(!key) { | ||
127 | sleep(1); | ||
128 | continue; | ||
129 | } | ||
130 | |||
131 | switch(key) { | ||
132 | #ifdef HAVE_RECORDER_KEYPAD | ||
133 | case BUTTON_UP: | ||
134 | #else | ||
135 | case BUTTON_LEFT: | ||
136 | #endif | ||
137 | if(is_cursor_menu_top()){ | ||
138 | /* wrap around to menu bottom */ | ||
139 | put_cursor_menu_bottom(); | ||
140 | } else { | ||
141 | /* move up */ | ||
142 | move_cursor_up(); | ||
143 | } | ||
144 | break; | ||
145 | |||
146 | #ifdef HAVE_RECORDER_KEYPAD | ||
147 | case BUTTON_DOWN: | ||
205 | #else | 148 | #else |
206 | lcd_puts(0, 0, rockbox); | 149 | case BUTTON_RIGHT: |
207 | #endif | 150 | #endif |
151 | if(is_cursor_menu_bottom() ){ | ||
152 | /* wrap around to menu top */ | ||
153 | put_cursor_menu_top(); | ||
154 | } else { | ||
155 | /* move down */ | ||
156 | move_cursor_down(); | ||
157 | } | ||
158 | break; | ||
159 | |||
160 | #ifdef HAVE_RECORDER_KEYPAD | ||
161 | case BUTTON_RIGHT: | ||
162 | #endif | ||
163 | case BUTTON_PLAY: | ||
164 | /* Erase current display state */ | ||
165 | lcd_clear_display(); | ||
166 | |||
167 | execute_menu_item(); | ||
168 | |||
169 | /* Return to previous display state */ | ||
170 | lcd_clear_display(); | ||
171 | menu_draw(); | ||
172 | break; | ||
173 | |||
174 | #ifdef HAVE_RECORDER_KEYPAD | ||
175 | case BUTTON_LEFT: | ||
176 | #else | ||
177 | case BUTTON_STOP: | ||
178 | #endif | ||
179 | return; | ||
208 | 180 | ||
209 | lcd_update(); | 181 | default: |
210 | busy_wait(); | 182 | break; |
183 | } | ||
184 | |||
185 | lcd_update(); | ||
186 | } | ||
211 | } | 187 | } |