Skip to content

Commit

Permalink
model: allow group of models for sub-menus.
Browse files Browse the repository at this point in the history
This commit allows models to have a group associated with them.  The
groups are then used to form sub-menus of the Model menu, making
browsing this menu much tidier with a large number of models.
  • Loading branch information
Steve Fosdick committed Jan 1, 2025
1 parent d087c92 commit 4bd48c3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
51 changes: 45 additions & 6 deletions src/gui-allegro.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,53 @@ static void update_rom_menu(void)

static ALLEGRO_MENU *create_model_menu(void)
{
ALLEGRO_MENU *menu = al_create_menu();
menu_map_t *map = malloc(model_count * sizeof(menu_map_t));
menu_map_t *map = calloc(model_count * 2, sizeof(menu_map_t));
if (map) {
for (int i = 0; i < model_count; i++) {
map[i].label = models[i].name;
map[i].itemno = i;
ALLEGRO_MENU *menu = al_create_menu();
menu_map_t *groups = map + model_count;
int ngroup = 0;
for (int model_no = 0; model_no < model_count; ++model_no) {
const char *group = models[model_no].group;
if (group) {
bool found = false;
for (int group_no = 0; group_no < ngroup; ++group_no) {
if (!strcmp(group, groups[group_no].label)) {
found = true;
break;
}
}
if (!found) {
groups[ngroup].label = group;
groups[ngroup].itemno = ngroup;
++ngroup;
}
}
}
qsort(groups, ngroup, sizeof(menu_map_t), menu_cmp);
for (int group_no = 0; group_no < ngroup; ++group_no) {
const char *group_label = groups[group_no].label;
int item_no = 0;
for (int model_no = 0; model_no < model_count; ++model_no) {
const char *model_group = models[model_no].group;
if (model_group && !strcmp(model_group, group_label)) {
map[item_no].label = models[model_no].name;
map[item_no].itemno = model_no;
++item_no;
}
}
ALLEGRO_MENU *sub = al_create_menu();
add_sorted_set(sub, map, item_no, IDM_MODEL, curmodel);
al_append_menu_item(menu, groups[group_no].label, 0, 0, NULL, sub);
}
int item_no = 0;
for (int model_no = 0; model_no < model_count; ++model_no) {
if (!models[model_no].group) {
map[item_no].label = models[model_no].name;
map[item_no].itemno = model_no;
++item_no;
}
}
add_sorted_set(menu, map, model_count, IDM_MODEL, curmodel);
add_sorted_set(menu, map, item_no, IDM_MODEL, curmodel);
free(map);
return menu;
}
Expand Down
1 change: 1 addition & 0 deletions src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ void model_loadcfg(void)
MODEL *ptr = models + num;
ptr->cfgsect = sect;
ptr->name = get_config_string(sect, "name", sect);
ptr->group = al_get_config_value(bem_cfg, sect, "group");
ptr->fdc_type = model_find_fdc(get_config_string(sect, "fdc", "none"), ptr->name);
ptr->x65c02 = get_config_bool(sect, "65c02", false);
ptr->bplus = get_config_bool(sect, "b+", false);
Expand Down
3 changes: 3 additions & 0 deletions src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef struct
const char *name;
const char *os;
const char *cmos;
const char *group;
rom_setup_t *romsetup;
fdc_type_t fdc_type;
uint8_t x65c02:1;
Expand All @@ -43,6 +44,8 @@ typedef struct

extern MODEL *models;
extern int model_count;
extern const char **model_groups;
extern int model_ngroup;

typedef struct
{
Expand Down

0 comments on commit 4bd48c3

Please sign in to comment.