woops.. forgot the attachment

On 24/08/06, Jonathan Gordon <[EMAIL PROTECTED]> wrote:
It works!! (umm.. i think... It seems to work for my tests...)

I have attached the diff if you want to have a look, all it does is
show my test menu which is just the shuffle option twice.. but it
proves it works...

The problem with the whole thing is its a bit messy to add an option...
i.e for the shuffle option the folliowing is needed...
static const struct opt_items bool_onoff[] =
{{STR(LANG_OFF)},{STR(LANG_ON)}}; <- this will only be done once, so
no big deal
static const struct option_item shuffle_option = {
&global_settings.playlist_shuffle, NULL, (const struct
opt_items**)&bool_onoff,0,0,0,0,0,0}; <- needed so set_option() can
work
static const struct menu_item_ex shuffle_mode = {
MT_SETTING_BOOL,{&shuffle_option},2, NULL, LANG_SYSFONT_SHUFFLE}; <-
needed for the menu item
then &shuffle_mode must go in a menu_item_ex array..
So, is that easier than doing functions for every setting?
Im going to play with #define's to hopefully make all that a bit
smaller, but i dont know how well that will work.

please comment.

? dir_nav.patch
? h300
? h300-sim
? ipod
? ipod.patch
? menu.diff
? menu_rework.h
? patch.patch
? recorder
? remote.patch
? tools/codepages
? tools/ipod_fw
? tools/mkboot
? tools/rdf2binary
? tools/uclpack
Index: apps/menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/menu.c,v
retrieving revision 1.104
diff -u -r1.104 menu.c
--- apps/menu.c 15 Aug 2006 12:27:04 -0000      1.104
+++ apps/menu.c 24 Aug 2006 10:52:33 -0000
@@ -165,10 +165,18 @@
     return MENU_SELECTED_EXIT;
 }
 
+static const struct opt_items bool_yesno[] = 
{{STR(LANG_SET_BOOL_NO)},{STR(LANG_SET_BOOL_YES)}};
+static const struct opt_items bool_onoff[] = {{STR(LANG_OFF)},{STR(LANG_ON)}};
 
-bool menu_run(int m)
+static const struct option_item shuffle_option = { 
&global_settings.playlist_shuffle, NULL, (const struct 
opt_items**)&bool_onoff,0,0,0,0,0,0};
+static const struct menu_item_ex shuffle_mode = { 
MT_SETTING_BOOL,{&shuffle_option},2, NULL, LANG_SYSFONT_SHUFFLE};
+static const struct menu_item_ex shuffsdf_mode = { 
MT_SETTING_CHOICE,{&shuffle_option},2, NULL, LANG_SYSFONT_SHUFFLE};
+static const struct menu_item_ex *main_menu_items[] = 
{&shuffle_mode,&shuffsdf_mode};
+static const struct menu_item_ex main_menu = {MT_MENU, 
{main_menu_items},2,"Testing...",0};
+bool menu_run(int m) 
 {
     int selected;
+    return do_menu(&main_menu);
     while (1) {
         switch (selected=menu_show(m))
         {
@@ -356,3 +364,100 @@
 #endif
     }
 }
+
+/******************************************************************/
+/*              New menu stuff here!!
+ ******************************************************************/
+#define GET_TITLE(s,t) s!=0?(char*)s:(char*)str(t)
+
+char * get_menu_item_name(int selected_item,void * data, char *buffer)
+{
+    const struct menu_item_ex *menu = (const struct menu_item_ex *)data;
+    (void)buffer;
+    /* it should always be MT_MENU in here... but the individual items could 
be anything */
+    menu = menu->submenus[selected_item];
+    return GET_TITLE(menu->title,menu->title_lang_id);
+}
+
+bool do_menu(const struct menu_item_ex *menu)
+{
+    int action;
+    bool done = false;
+    int selected;
+    struct gui_synclist lists;
+    const struct menu_item_ex *temp;
+
+    gui_synclist_init(&lists,get_menu_item_name,(void*)menu,false,1);
+    gui_synclist_set_title(&lists, GET_TITLE(menu->title,menu->title_lang_id), 
NOICON);
+    gui_synclist_set_icon_callback(&lists,NULL);
+    gui_synclist_set_nb_items(&lists,menu->item_count);
+    gui_synclist_limit_scroll(&lists,true);
+    gui_synclist_select_item(&lists, 0);
+    /*
+    if (global_settings.talk_menu)
+    {
+        if (cb_data->type == INT && !cb_data->options)
+            talk_unit(cb_data->voice_unit, *(int*)variable);
+        else talk_id(cb_data->options[selected].voice_id, false);
+    }
+    */
+    gui_synclist_draw(&lists);
+    while (!done)
+    {
+        
+        action = get_action(CONTEXT_MAINMENU,TIMEOUT_BLOCK); 
+        if (action == ACTION_NONE)
+            continue;
+        
+        if (gui_synclist_do_button(&lists,action))
+        {
+        }  
+        else if (action == ACTION_STD_CANCEL)
+        {
+            return false;
+        }
+        else if (action == ACTION_STD_OK)
+        {
+            selected = gui_synclist_get_sel_pos(&lists);
+            temp = menu->submenus[selected];
+            switch (temp->type)
+            {
+                case MT_MENU:
+                    do_menu(temp);
+                    break;
+                case MT_FUNCTION_CALL:
+                    if (temp->function() < 0)
+                        return false;
+                case MT_SETTING_BOOL:
+                    set_option(GET_TITLE(temp->title,temp->title_lang_id),
+                               (bool*)(temp->option->variable),BOOL,
+                               (const struct 
opt_items*)temp->option->options,temp->item_count,
+                               temp->option->function);
+                   break;
+                case MT_SETTING_INT:
+                    set_int(GET_TITLE(temp->title,temp->title_lang_id),
+                            temp->option->unit,temp->option->voice_unit,
+                            
(int*)(temp->option->variable),temp->option->function,
+                            
temp->option->step,temp->option->min,temp->option->max,
+                            temp->option->formatter);
+                    break;
+                case MT_SETTING_CHOICE:
+                    set_option(GET_TITLE(temp->title,temp->title_lang_id),
+                               (int*)(temp->option->variable),INT,
+                               (const struct 
opt_items*)temp->option->options,temp->item_count,
+                               temp->option->function);
+                    break;
+            }
+            gui_synclist_draw(&lists);
+        }
+        else if(default_event_handler(action) == SYS_USB_CONNECTED)
+            return true;
+        gui_syncstatusbar_draw(&statusbars, false);
+    }
+    return false;
+}
+
+
+
+
+
Index: apps/menu.h
===================================================================
RCS file: /cvsroot/rockbox/apps/menu.h,v
retrieving revision 1.44
diff -u -r1.44 menu.h
--- apps/menu.h 3 Aug 2006 20:17:14 -0000       1.44
+++ apps/menu.h 24 Aug 2006 10:52:34 -0000
@@ -145,4 +146,41 @@
 void menu_set_cursor(int menu, int position);
 void menu_talk_selected(int m);
 
+
+enum menu_item_type {
+    MT_MENU = 0,
+    MT_FUNCTION_CALL, /* used when the standard code wont work */
+    MT_SETTING_BOOL,
+    MT_SETTING_INT, /* int with min,max */
+    MT_SETTING_CHOICE, /* int where you have X choices, e.g reply mode */
+};
+
+struct option_item {
+    void *variable; /* typecast to whatever we need */
+    void (*function)(int); /* int typecast to bool for BOOL options */
+    const struct opt_items** options; /* MT_SETTING_CHOICE only */
+    /* the rest is MT_SETTING_INT only */
+    void (*formatter)(char*, int, int, const char*);
+    const char* unit;
+    int voice_unit;
+    int step;
+    int min;
+    int max;
+};
+
+struct menu_item_ex {
+    enum menu_item_type type;
+    union {
+        const void* dummy; /* NOTE: this stops compiler warnings.. never use 
this variable... */
+        const struct menu_item_ex **submenus; /* used with MT_MENU */
+        const struct option_item *option; /* used with 
MT_SETTING_CHOICE|BOOL|INT */
+        int (*function)(void); /* used with MT_FUNCTION_CALL */
+    };
+    int item_count; /* # of submenu or options items */
+    char *title;
+    int title_lang_id; /* only checked if title == NULL */
+};
+bool do_menu(const struct menu_item_ex *menu);
+
+
 #endif /* End __MENU_H__ */

Reply via email to