2002-04-27 23:41:18 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2002-04-28 20:35:33 +00:00
|
|
|
* Copyright (C) 2002 Daniel Stenberg
|
2002-04-27 23:41:18 +00:00
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "button.h"
|
2002-04-28 08:37:15 +00:00
|
|
|
#include "kernel.h"
|
2002-04-27 23:41:18 +00:00
|
|
|
|
2002-04-30 13:17:11 +00:00
|
|
|
#include "tree.h"
|
|
|
|
|
2002-04-28 08:37:15 +00:00
|
|
|
extern void tetris(void);
|
2002-04-27 23:41:18 +00:00
|
|
|
|
2002-05-03 05:21:58 +00:00
|
|
|
#define MENU_ITEM_FONT 0
|
|
|
|
#define MENU_ITEM_Y_LOC 6
|
|
|
|
#define MENU_LINE_HEIGHT 8
|
2002-04-27 23:41:18 +00:00
|
|
|
|
2002-05-03 05:21:58 +00:00
|
|
|
/* menu ids */
|
|
|
|
#define ITEM_TETRIS 0
|
|
|
|
#define ITEM_SCREENSAVER 1
|
|
|
|
#define ITEM_BROWSE 2
|
2002-04-27 23:41:18 +00:00
|
|
|
|
2002-05-03 05:21:58 +00:00
|
|
|
/* the last index with info, starting on 0 */
|
2002-05-03 06:11:39 +00:00
|
|
|
#define MAX_LINE ITEM_BROWSE
|
2002-05-03 05:21:58 +00:00
|
|
|
|
|
|
|
int menu_top = 0;
|
|
|
|
int menu_bottom = MAX_LINE;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2002-04-28 00:11:50 +00:00
|
|
|
|
|
|
|
void menu_init(void)
|
2002-04-27 23:41:18 +00:00
|
|
|
{
|
2002-05-03 05:21:58 +00:00
|
|
|
add_menu_item(ITEM_SCREENSAVER, "Screen Saver");
|
|
|
|
add_menu_item(ITEM_BROWSE, "Browse");
|
|
|
|
add_menu_item(ITEM_TETRIS, "Tetris");
|
|
|
|
|
|
|
|
lcd_puts(8, 38, "Rockbox!", 2);
|
|
|
|
}
|
|
|
|
|
2002-05-03 06:11:39 +00:00
|
|
|
/*
|
|
|
|
* Move the cursor to a particular id,
|
|
|
|
* current: where it is now
|
|
|
|
* target: where you want it to be
|
|
|
|
* Returns: the new current location
|
|
|
|
*/
|
2002-05-03 05:21:58 +00:00
|
|
|
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;
|
2002-04-28 00:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void app_main(void)
|
|
|
|
{
|
2002-05-03 05:21:58 +00:00
|
|
|
int key;
|
|
|
|
int cursor = 0;
|
2002-04-27 23:41:18 +00:00
|
|
|
|
2002-05-03 05:21:58 +00:00
|
|
|
menu_init();
|
2002-05-03 06:00:54 +00:00
|
|
|
cursor = put_cursor(menu_top, menu_top);
|
2002-04-28 00:11:50 +00:00
|
|
|
|
2002-05-03 05:21:58 +00:00
|
|
|
while(1) {
|
|
|
|
key = button_get();
|
2002-04-27 23:41:18 +00:00
|
|
|
|
2002-05-03 05:21:58 +00:00
|
|
|
if(!key) {
|
|
|
|
sleep(1);
|
|
|
|
continue;
|
|
|
|
}
|
2002-05-03 06:00:54 +00:00
|
|
|
|
2002-05-03 05:21:58 +00:00
|
|
|
switch(key) {
|
|
|
|
case BUTTON_UP:
|
|
|
|
if(cursor == menu_top ){
|
|
|
|
/* wrap around to menu bottom */
|
|
|
|
cursor = put_cursor(cursor, menu_bottom);
|
|
|
|
} else {
|
|
|
|
/* move up */
|
|
|
|
cursor = put_cursor(cursor, cursor-1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BUTTON_DOWN:
|
|
|
|
if(cursor == menu_bottom ){
|
|
|
|
/* wrap around to menu top */
|
|
|
|
cursor = put_cursor(cursor, menu_top);
|
|
|
|
} else {
|
|
|
|
/* move down */
|
|
|
|
cursor = put_cursor(cursor, cursor+1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
/* Erase current display state */
|
|
|
|
lcd_clear_display();
|
|
|
|
|
|
|
|
switch(cursor) {
|
|
|
|
case ITEM_TETRIS:
|
|
|
|
tetris();
|
|
|
|
break;
|
|
|
|
case ITEM_BROWSE:
|
|
|
|
dirbrowse("/");
|
|
|
|
break;
|
|
|
|
case ITEM_SCREENSAVER:
|
|
|
|
screensaver();
|
|
|
|
break;
|
2002-05-03 06:00:54 +00:00
|
|
|
default:
|
|
|
|
continue;
|
2002-05-03 05:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return to previous display state */
|
|
|
|
lcd_clear_display();
|
|
|
|
menu_init();
|
2002-05-03 06:00:54 +00:00
|
|
|
cursor = put_cursor(cursor, cursor);
|
|
|
|
break;
|
|
|
|
case BUTTON_OFF:
|
|
|
|
return;
|
|
|
|
default:
|
2002-05-03 05:21:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-05-03 06:00:54 +00:00
|
|
|
|
2002-05-03 05:21:58 +00:00
|
|
|
lcd_update();
|
2002-04-27 23:41:18 +00:00
|
|
|
}
|
|
|
|
}
|
2002-05-03 06:00:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|