summaryrefslogtreecommitdiff
path: root/uisimulator/app.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/app.c')
-rw-r--r--uisimulator/app.c155
1 files changed, 95 insertions, 60 deletions
diff --git a/uisimulator/app.c b/uisimulator/app.c
index d64017735d..d6d12451b8 100644
--- a/uisimulator/app.c
+++ b/uisimulator/app.c
@@ -26,77 +26,112 @@
26 26
27extern void tetris(void); 27extern void tetris(void);
28 28
29#define LINE_HEIGHT 8 29#define MENU_ITEM_FONT 0
30#define MENU_ITEM_Y_LOC 6
31#define MENU_LINE_HEIGHT 8
30 32
31#define MAX_LINE 3 /* the last index with info, starting on 0 */ 33/* menu ids */
34#define ITEM_TETRIS 0
35#define ITEM_SCREENSAVER 1
36#define ITEM_BROWSE 2
37#define ITEM_ROCKABOX 3
32 38
33/* global cursor */ 39/* the last index with info, starting on 0 */
34int cursor = 0; 40#define MAX_LINE 3
41
42int menu_top = 0;
43int menu_bottom = MAX_LINE;
44
45void add_menu_item(int location, char *string)
46{
47 lcd_puts(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location,
48 string, MENU_ITEM_FONT);
49 if (location < menu_top)
50 menu_top = location;
51 if (location > menu_bottom)
52 menu_bottom = location;
53}
35 54
36void menu_init(void) 55void menu_init(void)
37{ 56{
38 lcd_puts(6, 0, "Rockabox", 0); 57 /* x, y, string, font */
39 lcd_puts(6, 8, "Screen Saver", 0); 58 /* lcd_puts(6, 0, "Rockabox", 0);*/
40#define LINE_SS 1 59 add_menu_item(ITEM_ROCKABOX, "Rockabox");
41 lcd_puts(6, 16, "Browse", 0); 60 add_menu_item(ITEM_SCREENSAVER, "Screen Saver");
42#define LINE_BROWSE 2 61 add_menu_item(ITEM_BROWSE, "Browse");
43 lcd_puts(6, 24, "Tetris", 0); 62 add_menu_item(ITEM_TETRIS, "Tetris");
44#define LINE_TETRIS 3 63
45 lcd_puts(8, 38, "Rockbox!", 2); 64 lcd_puts(8, 38, "Rockbox!", 2);
46 65 put_cursor(0, 0);
47 lcd_puts(0, cursor, "-", 0); 66}
67
68/* Move the cursor to a particular id */
69int put_cursor(int current, int target)
70{
71 lcd_puts(0, current*MENU_LINE_HEIGHT, " ", 0);
72 lcd_puts(0, target*MENU_LINE_HEIGHT, "-", 0);
73 return target;
48} 74}
49 75
50void app_main(void) 76void app_main(void)
51{ 77{
52 int key; 78 int key;
79 int cursor = 0;
53 80
54 menu_init(); 81 menu_init();
55 82
56 while(1) { 83 while(1) {
57 key = button_get(); 84 key = button_get();
58 85
59 if(!key) { 86 if(!key) {
60 sleep(1); 87 sleep(1);
61 continue; 88 continue;
62 } 89 }
63 switch(key) { 90 switch(key) {
64 case BUTTON_UP: 91 case BUTTON_UP:
65 if(cursor) { 92 if(cursor == menu_top ){
66 lcd_puts(0, cursor, " ", 0); 93 /* wrap around to menu bottom */
67 cursor-= LINE_HEIGHT; 94 printf("from (%d) to (%d)\n", cursor, menu_bottom);
68 lcd_puts(0, cursor, "-", 0); 95 cursor = put_cursor(cursor, menu_bottom);
69 } 96 } else {
70 break; 97 /* move up */
71 case BUTTON_DOWN: 98 printf("from (%d) to (%d)\n", cursor, cursor-1);
72 if(cursor<(MAX_LINE*LINE_HEIGHT)) { 99 cursor = put_cursor(cursor, cursor-1);
73 lcd_puts(0, cursor, " ", 0); 100 }
74 cursor+=LINE_HEIGHT; 101 break;
75 lcd_puts(0, cursor, "-", 0); 102 case BUTTON_DOWN:
76 } 103 if(cursor == menu_bottom ){
77 break; 104 /* wrap around to menu top */
78 case BUTTON_RIGHT: 105 printf("from (%d) to (%d)\n", cursor, menu_top);
79 case BUTTON_PLAY: 106 cursor = put_cursor(cursor, menu_top);
80 switch(cursor) { 107 } else {
81 case (LINE_TETRIS * LINE_HEIGHT): 108 /* move down */
82 lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT); 109 printf("from (%d) to (%d)\n", cursor, cursor+1);
83 tetris(); 110 cursor = put_cursor(cursor, cursor+1);
84 lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT); 111 }
85 menu_init(); 112 break;
86 break; 113 case BUTTON_RIGHT:
87 case (LINE_BROWSE * LINE_HEIGHT): 114 case BUTTON_PLAY:
88 dirbrowse("/"); 115 /* Erase current display state */
89 lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT); 116 lcd_clear_display();
90 menu_init(); 117
91 break; 118 switch(cursor) {
92 case (LINE_SS * LINE_HEIGHT): 119 case ITEM_TETRIS:
93 screensaver(); 120 tetris();
94 lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT); 121 break;
95 menu_init(); 122 case ITEM_BROWSE:
96 break; 123 dirbrowse("/");
97 } 124 break;
98 break; 125 case ITEM_SCREENSAVER:
126 screensaver();
127 break;
128 }
129
130 /* Return to previous display state */
131 lcd_clear_display();
132 menu_init();
133 break;
134 }
135 lcd_update();
99 } 136 }
100 lcd_update();
101 }
102} 137}