Previous 15994 Revisions Next

r11101 Thursday 7th April, 2011 at 07:11:30 UTC by Fabio Priuli
uiswlist.c: added a switch to choose between shortname order or description order for softlist entries (in the Internal UI),
and adapted the char input code to match shortnames or descriptions accordingly [Fabio Priuli]
[src/emu]uiswlist.c

src/emu/uiswlist.c
r11100r11101
4848   device_image_interface* image;
4949   software_entry_state *entrylist;
5050   char filename_buffer[1024];
51   int ordered_by_shortname;
52   int reorder;
5153};
5254
5355/* state of a software part */
r11100r11101
128130   }
129131}
130132
131static int compare_software_entries(const software_entry_state *e1, const software_entry_state *e2)
133static int compare_software_entries(const software_entry_state *e1, const software_entry_state *e2, int shortname)
132134{
133135   int result;
134   const char *e1_basename = (e1->short_name != NULL) ? e1->short_name : "";
135   const char *e2_basename = (e2->short_name != NULL) ? e2->short_name : "";
136   const char *e1_basename;
137   const char *e2_basename;
138
139   if (shortname)
140   {
141      e1_basename = (e1->short_name != NULL) ? e1->short_name : "";
142      e2_basename = (e2->short_name != NULL) ? e2->short_name : "";
143   }
144   else
145   {
146      e1_basename = (e1->long_name != NULL) ? e1->long_name : "";
147      e2_basename = (e2->long_name != NULL) ? e2->long_name : "";
148   }
136149   
137150   result = mame_stricmp(e1_basename, e2_basename);
138151   if (result == 0)
r11100r11101
179192   
180193   // find the end of the list
181194   entryptr = &menustate->entrylist;
182   while ((*entryptr != NULL) && (compare_software_entries(entry, *entryptr) >= 0))
195   while ((*entryptr != NULL) && (compare_software_entries(entry, *entryptr, menustate->ordered_by_shortname) >= 0))
183196      entryptr = &(*entryptr)->next;
184197   
185198   // insert the entry
r11100r11101
203216      software_list_close(list);
204217   }
205218   
219   // add an entry to change ordering
220   ui_menu_item_append(menu, "Switch Item Ordering", NULL, 0, (void *)1);
221
206222   // append all of the menu entries
207223   for (software_entry_state *entry = menustate->entrylist; entry != NULL; entry = entry->next)
208224      ui_menu_item_append(menu, entry->short_name, entry->long_name, 0, entry);
r11100r11101
228244   const software_entry_state *selected_entry = NULL;
229245   int bestmatch = 0;
230246   
231   if (!ui_menu_populated(menu))
247   if (!ui_menu_populated(menu) || sw_state->reorder)
232248   {
249      sw_state->reorder = 0;
250
233251      if (sw_state->list_name)
234252      {
235253         ui_mess_menu_populate_software_entries(machine, menu, sw_state);
r11100r11101
241259   
242260   if (event != NULL && event->itemref != NULL)
243261   {
262      if ((FPTR)event->itemref == 1 && event->iptkey == IPT_UI_SELECT)
263      {
264         sw_state->ordered_by_shortname ^= 1;
265         sw_state->reorder = 1;
266         sw_state->entrylist = NULL;
267         // reset the char buffer if we change ordering criterion
268         memset(sw_state->filename_buffer, '\0', ARRAY_LENGTH(sw_state->filename_buffer));
269
270         // reload the menu with the new order
271         ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF);
272         popmessage("Switched Order: entries now ordered by %s", sw_state->ordered_by_shortname ? "shortname" : "description");
273      }
244274      /* handle selections */
245      if (event->iptkey == IPT_UI_SELECT)
275      else if (event->iptkey == IPT_UI_SELECT)
246276      {
247277         device_image_interface *image = sw_state->image;
248278         software_entry_state *entry = (software_entry_state *) event->itemref;
r11100r11101
298328            if (ARRAY_LENGTH(sw_state->filename_buffer) > 0)
299329               ui_popup_time(ERROR_MESSAGE_TIME, "%s", sw_state->filename_buffer);
300330         }
301         
331
302332         if (update_selected)
303333         {
304            const software_entry_state *cur_selected = (const software_entry_state *)ui_menu_get_selection(menu);
305           
334            const software_entry_state *cur_selected;
335
336            // if the current selection is a software entry, start search from here
337            if ((FPTR)event->itemref != 1)
338               cur_selected= (const software_entry_state *)ui_menu_get_selection(menu);
339            // else (if we are on the 'Switch Order' entry) start from the beginning
340            else
341               cur_selected= sw_state->entrylist;
342
306343            // check for entries which matches our filename_buffer:
307344            // from current entry to the end
308345            for (entry = cur_selected; entry != NULL; entry = entry->next)
309346            {
310               if (entry->short_name != NULL && sw_state->filename_buffer != NULL)
347               const char *compare_name = sw_state->ordered_by_shortname ? entry->short_name : entry->long_name;
348
349               if (compare_name != NULL && sw_state->filename_buffer != NULL)
311350               {
312351                  int match = 0;
313352                  for (int i = 0; i < ARRAY_LENGTH(sw_state->filename_buffer); i++)
314353                  {
315                     if (mame_strnicmp(entry->short_name, sw_state->filename_buffer, i) == 0)
354                     if (mame_strnicmp(compare_name, sw_state->filename_buffer, i) == 0)
316355                        match = i;
317356                  }
318357                 
r11100r11101
326365            // and from the first entry to current one
327366            for (entry = sw_state->entrylist; entry != cur_selected; entry = entry->next)
328367            {
329               if (entry->short_name != NULL && sw_state->filename_buffer != NULL)
368               const char *compare_name = sw_state->ordered_by_shortname ? entry->short_name : entry->long_name;
369               
370               if (compare_name != NULL && sw_state->filename_buffer != NULL)
330371               {
331372                  int match = 0;
332373                  for (int i = 0; i < ARRAY_LENGTH(sw_state->filename_buffer); i++)
333374                  {
334                     if (mame_strnicmp(entry->short_name, sw_state->filename_buffer, i) == 0)
375                     if (mame_strnicmp(compare_name, sw_state->filename_buffer, i) == 0)
335376                        match = i;
336377                  }
337378                 
r11100r11101
447488      child_menustate->list_name = (char *)event->itemref;
448489      child_menustate->image = image;
449490      child_menustate->entrylist = NULL;
491      child_menustate->ordered_by_shortname = 1;
450492      ui_menu_stack_push(child_menu);
451493   }
452494}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team