Changeset 862

Show
Ignore:
Timestamp:
04/29/08 21:12:02 (4 months ago)
Author:
takkaria
Message:

Simplify the ui-menu interface a little by removing some abstraction. Fix the list of menu "skins" to those implemented, rename them so they're obviously skins, and make them entirely internal to ui-menu.c.

Also, remove an unused struct member which was never initialised or used.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cmd0.c

    r759 r862  
    474474        menu.count = list->len; 
    475475        menu.menu_data = list->list; 
    476         menu_init2(&menu, find_menu_skin(MN_SCROLL), &commands_menu, &area); 
     476        menu_init2(&menu, MN_SKIN_SCROLL, &commands_menu, &area); 
    477477 
    478478        /* Set up the screen */ 
     
    539539        menu.count = N_ELEMENTS(cmds_all) - 1; 
    540540        menu.menu_data = &chosen_command; 
    541         menu_init2(&menu, find_menu_skin(MN_SCROLL), &commands_menu, &area); 
     541        menu_init2(&menu, MN_SKIN_SCROLL, &commands_menu, &area); 
    542542 
    543543        /* Set up the screen */ 
  • trunk/src/cmd4.c

    r823 r862  
    480480        o_funcs.is_visual = FALSE; 
    481481 
    482         menu_init(&group_menu, MN_SCROLL, MN_STRINGS, &group_region); 
    483         menu_init2(&object_menu, find_menu_skin(MN_SCROLL), &object_iter, &object_region); 
     482        menu_init(&group_menu, MN_SKIN_SCROLL, MN_STRINGS, &group_region); 
     483        menu_init2(&object_menu, MN_SKIN_SCROLL, &object_iter, &object_region); 
    484484 
    485485 
     
    42234223        menu->cmd_keys = cmd_keys; 
    42244224        menu->count = N_ELEMENTS(option_actions); 
    4225         menu_init2(menu, find_menu_skin(MN_SCROLL), &options_iter, &SCREEN_REGION); 
     4225        menu_init2(menu, MN_SKIN_SCROLL, &options_iter, &SCREEN_REGION); 
    42264226 
    42274227        /* Initialize the options toggle menu */ 
     
    42334233        menu->count = OPT_PAGE_PER; 
    42344234        menu->flags = MN_DBL_TAP; 
    4235         menu_init2(menu, find_menu_skin(MN_SCROLL), &options_toggle_iter, &SCREEN_REGION); 
     4235        menu_init2(menu, MN_SKIN_SCROLL, &options_toggle_iter, &SCREEN_REGION); 
    42364236 
    42374237        /* macro menu */ 
     
    42444244        menu->menu_data = macro_actions; 
    42454245        menu->count = N_ELEMENTS(macro_actions); 
    4246         menu_init(menu, MN_SCROLL, MN_ACTIONS, &SCREEN_REGION); 
     4246        menu_init(menu, MN_SKIN_SCROLL, MN_ACTIONS, &SCREEN_REGION); 
    42474247 
    42484248        /* visuals menu */ 
     
    42554255        menu->menu_data = visual_menu_items; 
    42564256        menu->count = N_ELEMENTS(visual_menu_items); 
    4257         menu_init(menu, MN_SCROLL, MN_ACTIONS, &SCREEN_REGION); 
     4257        menu_init(menu, MN_SKIN_SCROLL, MN_ACTIONS, &SCREEN_REGION); 
    42584258 
    42594259        /* colors menu */ 
     
    42664266        menu->menu_data = color_events; 
    42674267        menu->count = N_ELEMENTS(color_events); 
    4268         menu_init(menu, MN_SCROLL, MN_ACTIONS, &SCREEN_REGION); 
     4268        menu_init(menu, MN_SKIN_SCROLL, MN_ACTIONS, &SCREEN_REGION); 
    42694269 
    42704270        /* knowledge menu */ 
     
    42754275        menu->menu_data = knowledge_actions; 
    42764276        menu->count = N_ELEMENTS(knowledge_actions), 
    4277         menu_init(menu, MN_SCROLL, MN_ITEMS, &SCREEN_REGION); 
     4277        menu_init(menu, MN_SKIN_SCROLL, MN_ITEMS, &SCREEN_REGION); 
    42784278 
    42794279        /* initialize other static variables */ 
  • trunk/src/death.c

    r815 r862  
    472472        menu->count = N_ELEMENTS(death_actions); 
    473473 
    474         menu_init2(menu, find_menu_skin(MN_SCROLL), &death_iter, &area); 
     474        menu_init2(menu, MN_SKIN_SCROLL, &death_iter, &area); 
    475475 
    476476        while (TRUE) 
  • trunk/src/squelch.c

    r794 r862  
    630630                menu.count = area.page_rows = SQUELCH_BAD + 1; 
    631631 
    632         menu_init2(&menu, find_menu_skin(MN_SCROLL), &menu_f, &area); 
     632        menu_init2(&menu, MN_SKIN_SCROLL, &menu_f, &area); 
    633633        window_make(area.col - 2, area.row - 1, area.col + area.width + 2, area.row + area.page_rows); 
    634634 
     
    669669        menu.cmd_keys = " \n\r"; 
    670670        menu.count = TYPE_MAX; 
    671         menu_init2(&menu, find_menu_skin(MN_SCROLL), &menu_f, &area); 
     671        menu_init2(&menu, MN_SKIN_SCROLL, &menu_f, &area); 
    672672 
    673673        /* Select an entry */ 
     
    797797        menu.count = num; 
    798798        menu.menu_data = choice; 
    799         menu_init2(&menu, find_menu_skin(MN_SCROLL), &menu_f, &area); 
     799        menu_init2(&menu, MN_SKIN_SCROLL, &menu_f, &area); 
    800800 
    801801        /* Select an entry */ 
     
    934934        menu.cmd_keys = cmd_keys; 
    935935        menu.count = N_ELEMENTS(sval_dependent) + N_ELEMENTS(extra_item_options) + 1; 
    936         menu_init2(&menu, find_menu_skin(MN_SCROLL), &options_item_iter, &SCREEN_REGION); 
     936        menu_init2(&menu, MN_SKIN_SCROLL, &options_item_iter, &SCREEN_REGION); 
    937937 
    938938        menu_layout(&menu, &SCREEN_REGION); 
  • trunk/src/store.c

    r859 r862  
    28442844 
    28452845                /* Init the menu structure */ 
    2846                 menu_init2(&menu, find_menu_skin(MN_SCROLL), cur_menu, &items_region); 
     2846                menu_init2(&menu, MN_SKIN_SCROLL, cur_menu, &items_region); 
    28472847 
    28482848                if (menu.count > items_region.page_rows) 
  • trunk/src/ui-birth.c

    r815 r862  
    350350        /* Get ui-menu to initialise whatever it wants to to give us a scrollable 
    351351           menu. */ 
    352         menu_init2(menu, find_menu_skin(MN_SCROLL), &birth_iter, reg); 
     352        menu_init2(menu, MN_SKIN_SCROLL, &birth_iter, reg); 
    353353} 
    354354 
  • trunk/src/ui-menu.c

    r552 r862  
    244244const menu_skin menu_skin_scroll = 
    245245{ 
    246         MN_SCROLL, 
    247246        scrolling_get_cursor, 
    248247        display_scrolling, 
     
    304303static const menu_skin menu_skin_column = 
    305304{ 
    306         MN_COLUMNS, 
    307305        columns_get_cursor, 
    308306        display_columns, 
     
    323321static const menu_skin menu_skin_key_select = 
    324322{ 
    325         MN_KEY_ONLY, 
    326323        no_cursor, 
    327324        display_nothing, 
     325        NULL, 
    328326}; 
    329327 
     
    822820 
    823821/* 
    824  * The menu skin registry.  In the unlikely event you need to register 
    825  * more skins, make the array bigger. 
    826  */ 
    827 static menu_skin const *menu_skin_reg[20] = 
    828 { 
    829         &menu_skin_scroll, 
    830         &menu_skin_column, 
    831         &menu_skin_key_select, 
    832         0 
    833 }; 
    834  
    835 /*  
    836822 * The menu row-iterator registry. 
    837823 * Note that there's no need to register "anonymous" row iterators, that is, 
    838824 * iterators always accessed by address, and not available in pref files. 
    839825 */ 
    840 static menu_iter const *menu_iter_reg[20] = 
     826static menu_iter const *menu_iter_reg[] = 
    841827{ 
    842828        &menu_iter_actions, 
     
    858844} 
    859845 
    860 const menu_skin *find_menu_skin(skin_id id) 
    861 { 
    862         size_t i; 
    863         for (i = 0; i < N_ELEMENTS(menu_skin_reg) && menu_skin_reg[i]; i++) 
    864         { 
    865                 if (menu_skin_reg[i]->id == id) 
    866                         return menu_skin_reg[i]; 
    867         } 
    868         return NULL; 
    869 } 
    870  
    871 void add_menu_skin(const menu_skin *skin, skin_id id) 
    872 { 
    873         size_t i; 
    874  
    875         assert(skin->id == id); 
    876         for (i = 0; i < N_ELEMENTS(menu_skin_reg) && menu_skin_reg[i]; i++) 
    877                 assert(skin->id != menu_skin_reg[id]->id); 
    878  
    879         if (i == N_ELEMENTS(menu_skin_reg)) 
    880                 quit("too many registered skins!"); 
    881  
    882         menu_skin_reg[i] = skin; 
    883 } 
    884846 
    885847void add_menu_iter(const menu_iter * iter, menu_iter_id id) 
     
    896858        menu_iter_reg[i] = iter; 
    897859} 
     860 
     861/* 
     862 * Return the skin behaviour struct for a given skin ID. 
     863 */ 
     864static const menu_skin *find_menu_skin(skin_id id) 
     865{ 
     866        switch (id) 
     867        { 
     868                case MN_SKIN_SCROLL: 
     869                        return &menu_skin_scroll; 
     870 
     871                case MN_SKIN_COLUMNS: 
     872                        return &menu_skin_column; 
     873 
     874                case MN_SKIN_KEY_ONLY: 
     875                        return &menu_skin_key_select; 
     876        } 
     877 
     878        return NULL; 
     879} 
     880 
    898881 
    899882/* 
     
    966949 
    967950 
    968 /*  
     951/* 
    969952 * Correctly initialise the menu block at 'menu' so that it's ready to use. 
    970953 * Use the display skin given in 'skin' and the iterator in 'iter', and set 
    971  * up to use the region of the window given in 'loc'  
     954 * up to use the region of the window given in 'loc' 
    972955 * 
    973956 * Returns FALSE if something goes wrong, and TRUE otherwise (i.e. always). 
    974957*/ 
    975 bool menu_init2(menu_type *menu, const menu_skin *skin, const menu_iter *iter, const region *loc) 
    976 
     958bool menu_init2(menu_type *menu, skin_id skin_id, const menu_iter *iter, const region *loc) 
     959
     960        const menu_skin *skin = find_menu_skin(skin_id); 
     961        assert(skin && "menu skin not found!"); 
     962 
    977963        /* Default value for the parameter, effectively. */ 
    978964        if (!loc) loc = &SCREEN_REGION; 
     
    1009995bool menu_init(menu_type *menu, skin_id skin_id, menu_iter_id iter_id, const region *loc) 
    1010996{ 
    1011         const menu_skin *skin = find_menu_skin(skin_id); 
    1012997        const menu_iter *iter = find_menu_iter(iter_id); 
    1013998 
    1014         if (!iter || !skin
    1015         { 
    1016                 msg_format("could not find menu VTAB (%d, %d)!", skin_id, iter_id); 
     999        if (!iter
     1000        { 
     1001                msg_format("could not find menu VTAB (%d, %d)!", iter_id); 
    10171002                return FALSE; 
    10181003        } 
    10191004 
    1020         return menu_init2(menu, skin, iter, loc); 
    1021 } 
    1022  
     1005        return menu_init2(menu, skin_id, iter, loc); 
     1006} 
     1007 
  • trunk/src/ui-menu.h

    r861 r862  
    149149                                /* key-binding.  */ 
    150150 
    151 /* Identifier for the type of menu layout to use */ 
     151 
     152/** Identifier for the type of menu layout to use */ 
    152153typedef enum 
    153154{ 
    154         /* Skins */ 
    155         MN_SCROLL       = 0x0000, /* Ordinary scrollable single-column list */ 
    156         MN_COLUMNS      = 0x0002, /* multicolumn view */ 
    157         MN_NATIVE       = 0x0003, /* Not implemented -- OS menu */ 
    158         MN_KEY_ONLY     = 0x0004, /* No display */ 
    159         MN_USER         = 0x0005  /* Anonymous, user defined. */ 
     155        MN_SKIN_SCROLL = 1,   /**< Ordinary scrollable single-column list */ 
     156        MN_SKIN_COLUMNS = 2,  /**< Multicolumn view */ 
     157        MN_SKIN_KEY_ONLY = 3, /**< No display */ 
    160158} skin_id; 
    161159 
     160 
    162161/* Class functions for menu layout */ 
    163 struct menu_skin  
    164 
    165         /* Identifier from the above list */ 
    166         skin_id id; 
     162struct menu_skin 
     163
    167164        /* Determines the cursor index given a (mouse) location */ 
    168165        int (*get_cursor)(int row, int col, int n, int top, region *loc); 
     
    171168        /* Specifies the relative menu item given the state of the menu */ 
    172169        char (*get_tag)(menu_type *menu, int pos); 
    173         /* Superclass pointer. Not currently used */ 
    174         const menu_skin *super; 
    175170}; 
    176171 
     
    282277 
    283278 
    284 /* Initialize a menu given a pointer to a skin and an iterator */ 
    285 bool menu_init2(menu_type *menu, const menu_skin *skin, 
    286                const menu_iter *iter, const region *loc); 
     279/* Initialize a menu given skin ID and an iterator */ 
     280bool menu_init2(menu_type *menu, skin_id skin, const menu_iter *iter, const region *loc); 
    287281 
    288282/* Initialise a menu block given skin and iterator IDs */ 
     
    294288/* Menu VTAB registry */ 
    295289const menu_iter *find_menu_iter(menu_iter_id iter_id); 
    296 const menu_skin *find_menu_skin(skin_id skin_id); 
    297  
    298 void add_menu_skin(const menu_skin *skin, skin_id id); 
    299290void add_menu_iter(const menu_iter *skin, menu_iter_id id); 
    300291