2002-05-17 12:22:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Robert E. Hak
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2005-10-30 22:34:51 +00:00
|
|
|
/*
|
|
|
|
2005 Kevin Ferrare :
|
|
|
|
- Multi screen support
|
|
|
|
- Rewrote/removed a lot of code now useless with the new gui API
|
|
|
|
*/
|
2002-05-26 17:03:17 +00:00
|
|
|
#include <stdbool.h>
|
2004-03-12 10:20:33 +00:00
|
|
|
#include <stdlib.h>
|
2002-08-31 04:58:35 +00:00
|
|
|
|
2002-10-15 12:25:57 +00:00
|
|
|
#include "hwcompat.h"
|
2002-05-17 12:22:24 +00:00
|
|
|
#include "lcd.h"
|
2002-09-12 13:33:59 +00:00
|
|
|
#include "font.h"
|
2002-08-31 04:58:35 +00:00
|
|
|
#include "backlight.h"
|
2002-05-17 12:22:24 +00:00
|
|
|
#include "menu.h"
|
2002-05-21 14:25:45 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "debug.h"
|
2002-08-23 02:17:00 +00:00
|
|
|
#include "usb.h"
|
2002-08-11 09:17:47 +00:00
|
|
|
#include "panic.h"
|
2002-08-20 19:37:00 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "status.h"
|
2002-09-24 18:04:15 +00:00
|
|
|
#include "screens.h"
|
2004-03-14 21:33:53 +00:00
|
|
|
#include "talk.h"
|
2004-07-23 23:01:20 +00:00
|
|
|
#include "lang.h"
|
2004-07-26 16:06:59 +00:00
|
|
|
#include "misc.h"
|
2002-08-30 13:49:32 +00:00
|
|
|
|
2002-06-14 08:47:44 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#include "icons.h"
|
|
|
|
#endif
|
2002-08-30 13:49:32 +00:00
|
|
|
|
2005-10-30 22:34:51 +00:00
|
|
|
/* gui api */
|
|
|
|
#include "list.h"
|
|
|
|
#include "statusbar.h"
|
|
|
|
#include "buttonbar.h"
|
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
struct menu {
|
2004-03-16 13:44:56 +00:00
|
|
|
struct menu_item* items;
|
2004-03-12 10:20:33 +00:00
|
|
|
int (*callback)(int, int);
|
2005-10-30 22:34:51 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
struct gui_buttonbar buttonbar;
|
2004-03-16 13:44:56 +00:00
|
|
|
#endif
|
2005-10-30 22:34:51 +00:00
|
|
|
struct gui_synclist synclist;
|
2002-05-26 17:03:17 +00:00
|
|
|
};
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
#define MAX_MENUS 5
|
2002-05-26 17:03:17 +00:00
|
|
|
|
|
|
|
static struct menu menus[MAX_MENUS];
|
|
|
|
static bool inuse[MAX_MENUS] = { false };
|
2002-05-17 12:22:24 +00:00
|
|
|
|
2005-10-30 22:34:51 +00:00
|
|
|
char * menu_get_itemname(int selected_item, void * data, char *buffer)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
2005-10-30 22:34:51 +00:00
|
|
|
struct menu *local_menus=(struct menu *)data;
|
|
|
|
(void)buffer;
|
|
|
|
return(P2STR(local_menus->items[selected_item].desc));
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
2005-10-30 22:41:29 +00:00
|
|
|
int menu_find_free(void)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
2002-05-26 17:03:17 +00:00
|
|
|
int i;
|
2005-10-30 22:34:51 +00:00
|
|
|
/* Tries to find an unused slot to put the new menu */
|
2002-05-26 17:03:17 +00:00
|
|
|
for ( i=0; i<MAX_MENUS; i++ ) {
|
|
|
|
if ( !inuse[i] ) {
|
|
|
|
inuse[i] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( i == MAX_MENUS ) {
|
|
|
|
DEBUGF("Out of menus!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2005-10-30 22:34:51 +00:00
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
int menu_init(const struct menu_item* mitems, int count, int (*callback)(int, int),
|
|
|
|
const char *button1, const char *button2, const char *button3)
|
|
|
|
{
|
2005-10-30 22:41:29 +00:00
|
|
|
int menu=menu_find_free();
|
2005-10-30 22:34:51 +00:00
|
|
|
if(menu==-1)/* Out of menus */
|
|
|
|
return -1;
|
|
|
|
menus[menu].items = (struct menu_item*)mitems; /* de-const */
|
|
|
|
gui_synclist_init(&(menus[menu].synclist),
|
|
|
|
NULL, &menu_get_itemname, &menus[menu]);
|
|
|
|
gui_synclist_set_nb_items(&(menus[menu].synclist), count);
|
|
|
|
menus[menu].callback = callback;
|
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
gui_buttonbar_init(&(menus[menu].buttonbar));
|
|
|
|
gui_buttonbar_set_display(&(menus[menu].buttonbar), &(screens[SCREEN_MAIN]) );
|
|
|
|
gui_buttonbar_set(&(menus[menu].buttonbar), button1, button2, button3);
|
2004-03-16 13:44:56 +00:00
|
|
|
#else
|
|
|
|
(void)button1;
|
|
|
|
(void)button2;
|
|
|
|
(void)button3;
|
|
|
|
#endif
|
2005-10-30 22:34:51 +00:00
|
|
|
return menu;
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
void menu_exit(int m)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
2002-05-26 17:03:17 +00:00
|
|
|
inuse[m] = false;
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
2003-01-29 08:26:11 +00:00
|
|
|
int menu_show(int m)
|
2002-05-18 11:41:37 +00:00
|
|
|
{
|
2005-10-30 22:34:51 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
gui_buttonbar_draw(&(menus[m].buttonbar));
|
|
|
|
#endif
|
2002-09-24 17:22:12 +00:00
|
|
|
bool exit = false;
|
2004-03-12 10:20:33 +00:00
|
|
|
int key;
|
2004-03-14 21:33:53 +00:00
|
|
|
|
2005-10-30 22:34:51 +00:00
|
|
|
gui_synclist_draw(&(menus[m].synclist));
|
2005-11-04 07:18:36 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
2005-11-03 11:56:21 +00:00
|
|
|
menu_talk_selected(m);
|
2002-09-24 17:22:12 +00:00
|
|
|
while (!exit) {
|
2004-03-12 10:20:33 +00:00
|
|
|
key = button_get_w_tmo(HZ/2);
|
2005-10-30 22:34:51 +00:00
|
|
|
/*
|
2004-04-09 17:47:18 +00:00
|
|
|
* "short-circuit" the default keypresses by running the
|
|
|
|
* callback function
|
|
|
|
* The callback may return a new key value, often this will be
|
|
|
|
* BUTTON_NONE or the same key value, but it's perfectly legal
|
|
|
|
* to "simulate" key presses by returning another value.
|
2004-03-12 10:20:33 +00:00
|
|
|
*/
|
|
|
|
if( menus[m].callback != NULL )
|
2004-04-09 17:47:18 +00:00
|
|
|
key = menus[m].callback(key, m);
|
2005-11-03 11:56:21 +00:00
|
|
|
/* If moved, "say" the entry under the cursor */
|
2005-10-30 22:34:51 +00:00
|
|
|
if(gui_synclist_do_button(&(menus[m].synclist), key))
|
2005-11-03 11:56:21 +00:00
|
|
|
menu_talk_selected(m);
|
2004-03-12 10:20:33 +00:00
|
|
|
switch( key ) {
|
2004-09-19 21:58:37 +00:00
|
|
|
case MENU_ENTER:
|
|
|
|
#ifdef MENU_ENTER2
|
|
|
|
case MENU_ENTER2:
|
2005-06-12 16:10:17 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MENU_RC_ENTER
|
|
|
|
case MENU_RC_ENTER:
|
2005-10-31 18:38:48 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MENU_RC_ENTER2
|
|
|
|
case MENU_RC_ENTER2:
|
2002-05-21 14:25:45 +00:00
|
|
|
#endif
|
2005-10-30 22:34:51 +00:00
|
|
|
return gui_synclist_get_sel_pos(&(menus[m].synclist));
|
2005-10-31 18:38:48 +00:00
|
|
|
|
|
|
|
|
2004-09-19 21:58:37 +00:00
|
|
|
case MENU_EXIT:
|
|
|
|
#ifdef MENU_EXIT2
|
|
|
|
case MENU_EXIT2:
|
|
|
|
#endif
|
2005-06-23 10:11:10 +00:00
|
|
|
#ifdef MENU_EXIT_MENU
|
|
|
|
case MENU_EXIT_MENU:
|
2005-06-12 16:10:17 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MENU_RC_EXIT
|
|
|
|
case MENU_RC_EXIT:
|
2002-05-21 14:25:45 +00:00
|
|
|
#endif
|
2005-10-31 18:38:48 +00:00
|
|
|
#ifdef MENU_RC_EXIT_MENU
|
|
|
|
case MENU_RC_EXIT_MENU:
|
|
|
|
#endif
|
|
|
|
//lcd_stop_scroll();
|
2002-09-24 17:22:12 +00:00
|
|
|
exit = true;
|
|
|
|
break;
|
2002-05-21 08:47:34 +00:00
|
|
|
|
2004-07-26 16:06:59 +00:00
|
|
|
default:
|
|
|
|
if(default_event_handler(key) == SYS_USB_CONNECTED)
|
|
|
|
return MENU_ATTACHED_USB;
|
|
|
|
break;
|
2002-05-21 14:25:45 +00:00
|
|
|
}
|
2005-10-31 18:38:48 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, false);
|
2002-05-21 14:25:45 +00:00
|
|
|
}
|
2003-01-29 08:26:11 +00:00
|
|
|
return MENU_SELECTED_EXIT;
|
|
|
|
}
|
|
|
|
|
2002-08-23 12:32:52 +00:00
|
|
|
|
2003-01-29 08:26:11 +00:00
|
|
|
bool menu_run(int m)
|
|
|
|
{
|
2005-10-30 23:54:12 +00:00
|
|
|
int selected;
|
2004-09-19 21:58:37 +00:00
|
|
|
while (1) {
|
2005-10-30 23:54:12 +00:00
|
|
|
switch (selected=menu_show(m))
|
2004-09-19 21:58:37 +00:00
|
|
|
{
|
|
|
|
case MENU_SELECTED_EXIT:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case MENU_ATTACHED_USB:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2005-10-30 22:34:51 +00:00
|
|
|
{
|
|
|
|
if (menus[m].items[selected].function &&
|
|
|
|
menus[m].items[selected].function())
|
|
|
|
return true;
|
2005-10-30 23:54:12 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
2005-10-30 22:34:51 +00:00
|
|
|
}
|
2004-09-19 21:58:37 +00:00
|
|
|
}
|
2003-01-29 08:26:11 +00:00
|
|
|
}
|
2004-09-19 21:58:37 +00:00
|
|
|
return false;
|
2002-05-18 11:41:37 +00:00
|
|
|
}
|
2004-03-12 10:20:33 +00:00
|
|
|
|
2005-10-30 22:34:51 +00:00
|
|
|
/*
|
2004-03-12 10:20:33 +00:00
|
|
|
* Property function - return the current cursor for "menu"
|
|
|
|
*/
|
|
|
|
|
|
|
|
int menu_cursor(int menu)
|
|
|
|
{
|
2005-10-30 22:34:51 +00:00
|
|
|
return gui_synclist_get_sel_pos(&(menus[menu].synclist));
|
2004-03-12 10:20:33 +00:00
|
|
|
}
|
|
|
|
|
2005-10-30 22:34:51 +00:00
|
|
|
/*
|
2004-03-12 10:20:33 +00:00
|
|
|
* Property function - return the "menu" description at "position"
|
|
|
|
*/
|
|
|
|
|
|
|
|
char* menu_description(int menu, int position)
|
|
|
|
{
|
2004-07-23 23:01:20 +00:00
|
|
|
return P2STR(menus[menu].items[position].desc);
|
2004-03-12 10:20:33 +00:00
|
|
|
}
|
|
|
|
|
2005-10-30 22:34:51 +00:00
|
|
|
/*
|
2004-03-12 10:20:33 +00:00
|
|
|
* Delete the element "position" from the menu items in "menu"
|
|
|
|
*/
|
|
|
|
|
|
|
|
void menu_delete(int menu, int position)
|
|
|
|
{
|
|
|
|
int i;
|
2005-10-30 22:34:51 +00:00
|
|
|
int nb_items=gui_synclist_get_nb_items(&(menus[menu].synclist));
|
2004-03-12 10:20:33 +00:00
|
|
|
/* copy the menu item from the one below */
|
2005-10-30 22:34:51 +00:00
|
|
|
for( i = position; i < nb_items - 1; i++)
|
2004-03-12 10:20:33 +00:00
|
|
|
menus[menu].items[i] = menus[menu].items[i + 1];
|
2005-10-30 22:34:51 +00:00
|
|
|
|
|
|
|
gui_synclist_del_item(&(menus[menu].synclist));
|
2004-03-12 10:20:33 +00:00
|
|
|
}
|
|
|
|
|
2004-07-23 23:01:20 +00:00
|
|
|
void menu_insert(int menu, int position, char *desc, bool (*function) (void))
|
2004-07-05 14:26:58 +00:00
|
|
|
{
|
|
|
|
int i;
|
2005-10-30 22:34:51 +00:00
|
|
|
int nb_items=gui_synclist_get_nb_items(&(menus[menu].synclist));
|
2004-07-05 14:26:58 +00:00
|
|
|
if(position < 0)
|
2005-10-30 22:34:51 +00:00
|
|
|
position = nb_items;
|
2004-07-05 14:26:58 +00:00
|
|
|
|
|
|
|
/* Move the items below one position forward */
|
2005-10-30 22:34:51 +00:00
|
|
|
for( i = nb_items; i > position; i--)
|
2004-07-05 14:26:58 +00:00
|
|
|
menus[menu].items[i] = menus[menu].items[i - 1];
|
|
|
|
|
|
|
|
/* Update the current item */
|
|
|
|
menus[menu].items[position].desc = desc;
|
|
|
|
menus[menu].items[position].function = function;
|
2005-10-30 22:34:51 +00:00
|
|
|
gui_synclist_add_item(&(menus[menu].synclist));
|
2004-07-05 14:26:58 +00:00
|
|
|
}
|
|
|
|
|
2005-10-30 22:34:51 +00:00
|
|
|
/*
|
2005-11-03 11:56:21 +00:00
|
|
|
* Property function - return the "count" of menu items in "menu"
|
2004-03-12 10:20:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
int menu_count(int menu)
|
|
|
|
{
|
2005-10-30 22:34:51 +00:00
|
|
|
return gui_synclist_get_nb_items(&(menus[menu].synclist));
|
2004-03-12 10:20:33 +00:00
|
|
|
}
|
|
|
|
|
2005-10-30 22:34:51 +00:00
|
|
|
/*
|
|
|
|
* Allows a menu item at the current cursor position in "menu"
|
|
|
|
* to be moved up the list
|
2004-03-12 10:20:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool menu_moveup(int menu)
|
|
|
|
{
|
2004-03-16 13:44:56 +00:00
|
|
|
struct menu_item swap;
|
2005-10-30 22:34:51 +00:00
|
|
|
int selected=menu_cursor(menu);
|
2004-03-12 10:20:33 +00:00
|
|
|
/* can't be the first item ! */
|
2005-10-30 22:34:51 +00:00
|
|
|
if( selected == 0)
|
2004-03-12 10:20:33 +00:00
|
|
|
return false;
|
2005-10-30 22:34:51 +00:00
|
|
|
|
|
|
|
/* use a temporary variable to do the swap */
|
|
|
|
swap = menus[menu].items[selected - 1];
|
|
|
|
menus[menu].items[selected - 1] = menus[menu].items[selected];
|
|
|
|
menus[menu].items[selected] = swap;
|
|
|
|
|
|
|
|
gui_synclist_select_previous(&(menus[menu].synclist));
|
2004-03-12 10:20:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-10-30 22:34:51 +00:00
|
|
|
/*
|
2004-03-12 10:20:33 +00:00
|
|
|
* Allows a menu item at the current cursor position in "menu" to be moved down the list
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool menu_movedown(int menu)
|
|
|
|
{
|
2004-03-16 13:44:56 +00:00
|
|
|
struct menu_item swap;
|
2005-10-30 22:34:51 +00:00
|
|
|
int selected=menu_cursor(menu);
|
|
|
|
int nb_items=gui_synclist_get_nb_items(&(menus[menu].synclist));
|
|
|
|
|
2004-03-12 10:20:33 +00:00
|
|
|
/* can't be the last item ! */
|
2005-10-30 22:34:51 +00:00
|
|
|
if( selected == nb_items - 1)
|
2004-03-12 10:20:33 +00:00
|
|
|
return false;
|
2005-10-30 22:34:51 +00:00
|
|
|
|
2005-11-03 11:56:21 +00:00
|
|
|
/* use a temporary variable to do the swap */
|
2005-10-30 22:34:51 +00:00
|
|
|
swap = menus[menu].items[selected + 1];
|
|
|
|
menus[menu].items[selected + 1] = menus[menu].items[selected];
|
|
|
|
menus[menu].items[selected] = swap;
|
|
|
|
|
|
|
|
gui_synclist_select_next(&(menus[menu].synclist));
|
2004-03-12 10:20:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
2005-04-10 17:36:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allows to set the cursor position. Doesn't redraw by itself.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void menu_set_cursor(int menu, int position)
|
|
|
|
{
|
2005-10-30 22:34:51 +00:00
|
|
|
gui_synclist_select_item(&(menus[menu].synclist), position);
|
|
|
|
}
|
|
|
|
|
2005-11-03 11:56:21 +00:00
|
|
|
void menu_talk_selected(int m)
|
|
|
|
{
|
|
|
|
if(global_settings.talk_menu)
|
|
|
|
{
|
|
|
|
int selected=gui_synclist_get_sel_pos(&(menus[m].synclist));
|
|
|
|
int voice_id = P2ID(menus[m].items[selected].desc);
|
|
|
|
if (voice_id >= 0) /* valid ID given? */
|
|
|
|
talk_id(voice_id, false); /* say it */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_draw(int m)
|
|
|
|
{
|
|
|
|
gui_synclist_draw(&(menus[m].synclist));
|
|
|
|
}
|
|
|
|
|
2005-10-30 22:34:51 +00:00
|
|
|
/* count in letter positions, NOT pixels */
|
|
|
|
void put_cursorxy(int x, int y, bool on)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
int fh, fw;
|
|
|
|
int xpos, ypos;
|
|
|
|
|
|
|
|
/* check here instead of at every call (ugly, but cheap) */
|
|
|
|
if (global_settings.invert_cursor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lcd_getstringsize("A", &fw, &fh);
|
|
|
|
xpos = x*6;
|
|
|
|
ypos = y*fh + lcd_getymargin();
|
|
|
|
if ( fh > 8 )
|
|
|
|
ypos += (fh - 8) / 2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* place the cursor */
|
|
|
|
if(on) {
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
lcd_mono_bitmap(bitmap_icons_6x8[Icon_Cursor], xpos, ypos, 4, 8);
|
|
|
|
#else
|
|
|
|
lcd_putc(x, y, CURSOR_CHAR);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#if defined(HAVE_LCD_BITMAP)
|
|
|
|
/* I use xy here since it needs to disregard the margins */
|
|
|
|
lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
|
|
|
lcd_fillrect (xpos, ypos, 4, 8);
|
|
|
|
lcd_set_drawmode(DRMODE_SOLID);
|
|
|
|
#else
|
|
|
|
lcd_putc(x, y, ' ');
|
|
|
|
#endif
|
|
|
|
}
|
2005-04-10 17:36:55 +00:00
|
|
|
}
|