Daniel Stenberg | 1c0c861 | 2002-05-17 12:22:24 +0000 | [diff] [blame^] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 Robert E. Hak |
| 11 | * |
| 12 | * All files in this archive are subject to the GNU General Public License. |
| 13 | * See the file COPYING in the source tree root for full license agreement. |
| 14 | * |
| 15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 16 | * KIND, either express or implied. |
| 17 | * |
| 18 | ****************************************************************************/ |
| 19 | |
| 20 | #include "lcd.h" |
| 21 | #include "menu.h" |
| 22 | |
| 23 | #include "tree.h" |
| 24 | |
| 25 | #ifdef HAVE_LCD_BITMAP |
| 26 | |
| 27 | #include "screensaver.h" |
| 28 | extern void tetris(void); |
| 29 | |
| 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, 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 | }; |
| 44 | |
| 45 | /* Global values for menuing */ |
| 46 | int menu_top; |
| 47 | int menu_bottom; |
| 48 | int menu_line_height; |
| 49 | int cursor; |
| 50 | |
| 51 | int get_line_height(void) |
| 52 | { |
| 53 | return menu_line_height; |
| 54 | } |
| 55 | |
| 56 | int is_cursor_menu_top(void) |
| 57 | { |
| 58 | return ((cursor == menu_top) ? 1 : 0); |
| 59 | } |
| 60 | |
| 61 | int is_cursor_menu_bottom(void) |
| 62 | { |
| 63 | return ((cursor == menu_bottom) ? 1 : 0); |
| 64 | } |
| 65 | |
| 66 | void put_cursor_menu_top(void) |
| 67 | { |
| 68 | put_cursor(menu_top); |
| 69 | } |
| 70 | |
| 71 | void put_cursor_menu_bottom(void) |
| 72 | { |
| 73 | put_cursor(menu_bottom); |
| 74 | } |
| 75 | |
| 76 | void move_cursor_up(void) |
| 77 | { |
| 78 | put_cursor(cursor-1); |
| 79 | } |
| 80 | |
| 81 | void move_cursor_down(void) |
| 82 | { |
| 83 | put_cursor(cursor+1); |
| 84 | } |
| 85 | |
| 86 | void redraw_cursor(void) |
| 87 | { |
| 88 | lcd_putsxy(0, cursor*menu_line_height, "-", 0); |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * Move the cursor to a particular id, |
| 93 | * current: where it is now |
| 94 | * target: where you want it to be |
| 95 | */ |
| 96 | void put_cursor(int target) |
| 97 | { |
| 98 | lcd_putsxy(0, cursor*menu_line_height, " ",0); |
| 99 | cursor = target; |
| 100 | lcd_putsxy(0, cursor*menu_line_height, "-",0); |
| 101 | } |
| 102 | |
| 103 | /* We call the function pointer related to the current cursor position */ |
| 104 | void execute_menu_item(void) |
| 105 | { |
| 106 | /* call the proper function for this line */ |
| 107 | items[cursor].function(); |
| 108 | } |
| 109 | |
| 110 | void add_menu_item(int location, char *string) |
| 111 | { |
| 112 | lcd_putsxy(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location, string, |
| 113 | MENU_ITEM_FONT); |
| 114 | if (location < menu_top) |
| 115 | menu_top = location; |
| 116 | if (location > menu_bottom) |
| 117 | menu_bottom = location; |
| 118 | } |
| 119 | |
| 120 | void show_logo(void) |
| 121 | { |
| 122 | unsigned char buffer[112 * 8]; |
| 123 | |
| 124 | int failure; |
| 125 | int width=0; |
| 126 | int height=0; |
| 127 | |
| 128 | failure = read_bmp_file("/rockbox112.bmp", &width, &height, buffer); |
| 129 | |
| 130 | debugf("read_bmp_file() returned %d, width %d height %d\n", |
| 131 | failure, width, height); |
| 132 | |
| 133 | if(!failure) { |
| 134 | int i; |
| 135 | int eline; |
| 136 | for(i=0, eline=0; i< height; i+=8, eline++) { |
| 137 | int x,y; |
| 138 | |
| 139 | /* the bitmap function doesn't work with full-height bitmaps |
| 140 | so we "stripe" the logo output */ |
| 141 | |
| 142 | lcd_bitmap(&buffer[eline*width], 0, 24+i, width, |
| 143 | (height-i)>8?8:height-i, false); |
| 144 | |
| 145 | #if 0 |
| 146 | /* for screen output debugging */ |
| 147 | for(y=0; y<8 && (i+y < height); y++) { |
| 148 | for(x=0; x < width; x++) { |
| 149 | |
| 150 | if(buffer[eline*width + x] & (1<<y)) { |
| 151 | printf("*"); |
| 152 | } |
| 153 | else |
| 154 | printf(" "); |
| 155 | } |
| 156 | printf("\n"); |
| 157 | } |
| 158 | #endif |
| 159 | } |
| 160 | |
| 161 | lcd_update(); |
| 162 | } |
| 163 | |
| 164 | } |
| 165 | |
| 166 | void menu_init(void) |
| 167 | { |
| 168 | menu_top = Tetris; |
| 169 | menu_bottom = Last_Id-1; |
| 170 | menu_line_height = MENU_LINE_HEIGHT; |
| 171 | cursor = menu_top; |
| 172 | } |
| 173 | |
| 174 | void menu_draw(void) |
| 175 | { |
| 176 | int i = 0; |
| 177 | |
| 178 | for (i = i; i < Last_Id; i++) |
| 179 | add_menu_item(items[i].menu_id, (char *) items[i].menu_desc); |
| 180 | |
| 181 | show_logo(); |
| 182 | redraw_cursor(); |
| 183 | } |
| 184 | |
| 185 | #endif /* end HAVE_LCD_BITMAP */ |
| 186 | |
| 187 | |