Previous 15994 Revisions Next

r13554 Sunday 11th December, 2011 at 17:02:04 UTC by Olivier Galibert
uimenu: C++-ification, second part [O. Galibert]
[src/emu]ui.c uiimage.c uiimage.h uimain.c uimain.h uimenu.c uimenu.h uiswlist.c uiswlist.h
[src/emu/debugint]debugint.c

src/emu/uimenu.c
r13553r13554
127127***************************************************************************/
128128
129129/*-------------------------------------------------
130    ui_menu_alloc - allocate a new menu
131-------------------------------------------------*/
132
133ui_menu *ui_menu_alloc(running_machine &machine, render_container *container, ui_menu_handler_func handler, void *parameter)
134{
135   return auto_alloc_clear(machine, ui_menu(machine, container, handler, parameter));
136}
137
138
139/*-------------------------------------------------
140130    ui_menu - menu constructor
141131-------------------------------------------------*/
142ui_menu::ui_menu(running_machine &machine, render_container *_container, ui_menu_handler_func _handler, void *_parameter) : m_machine(machine)
132ui_menu::ui_menu(running_machine &machine, render_container *_container) : m_machine(machine)
143133{
144134   special_main_menu = false;
145135   container = _container;
146   handler = _handler;
147   parameter = _parameter;
148136
149137   reset(UI_MENU_RESET_SELECT_FIRST);
150138}
r13553r13554
167155   /* free the item array */
168156   if (item)
169157      auto_free(machine(), item);
170
171   /* free the state */
172   if (state != NULL)
173   {
174      if (destroy_state)
175         destroy_state(this, state);
176      auto_free(machine(), state);
177   }
178158}
179159
180160
r13553r13554
337317
338318
339319/*-------------------------------------------------
340    set_custom_render - configure the menu
341    for custom rendering
342-------------------------------------------------*/
343
344void ui_menu::set_custom_render(ui_menu_custom_func customfn, float top, float bottom)
345{
346   custom = customfn;
347   customtop = top;
348   custombottom = bottom;
349}
350
351
352/*-------------------------------------------------
353    alloc_state - allocate permanent
354    memory to represent the menu's state
355-------------------------------------------------*/
356
357void *ui_menu::alloc_state(size_t size, ui_menu_destroy_state_func destroy_state_fn)
358{
359   if (state != NULL)
360   {
361      if (destroy_state != NULL)
362         destroy_state(this, state);
363      auto_free(machine(), state);
364   }
365   state = auto_alloc_array_clear(machine(), UINT8, size);
366   destroy_state = destroy_state_fn;
367
368   return state;
369}
370
371
372/*-------------------------------------------------
373320    m_pool_alloc - allocate temporary memory
374321    from the menu's memory pool
375322-------------------------------------------------*/
r13553r13554
715662               JUSTIFY_RIGHT, WRAP_WORD, DRAW_NORMAL, UI_SELECTED_COLOR, UI_SELECTED_BG_COLOR, NULL, NULL);
716663   }
717664
718   /* if there is something special to add, do it by calling the passed routine */
719   if (custom != NULL)
720   {
721      void *selectedref = (selected >= 0 && selected < numitems) ? item[selected].ref : NULL;
722      custom(machine(), this, state, selectedref, customtop, custombottom, x1, y1, x2, y2);
723   }
665   /* if there is something special to add, do it by calling the virtual method */
666   custom_render((selected >= 0 && selected < numitems) ? item[selected].ref : NULL, customtop, custombottom, x1, y1, x2, y2);
724667
725668   /* return the number of visible lines, minus 1 for top arrow and 1 for bottom arrow */
726669   visitems = visible_lines - (top_line != 0) - (top_line + visible_lines != numitems);
727670}
728671
672void ui_menu::custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2)
673{
674}
729675
730676/*-------------------------------------------------
731677    draw_text_box - draw a multiline
r13553r13554
1033979{
1034980   menu->parent = menu_stack;
1035981   menu_stack = menu;
1036   menu->reset(UI_MENU_RESET_SELECT_FIRST);
1037982   ui_input_reset(menu->machine());
1038983}
1039984
r13553r13554
10711016   return false;
10721017}
10731018
1019void ui_menu::do_handle()
1020{
1021   if(!populated())
1022      populate();
1023   handle();
1024}
10741025
10751026
10761027/***************************************************************************
r13553r13554
10861037{
10871038   /* if we have no menus stacked up, start with the main menu */
10881039   if (menu_stack == NULL)
1089      stack_push(ui_menu_alloc(machine, container, menu_main, NULL));
1040      stack_push(auto_alloc_clear(machine, ui_menu_main(machine, container)));
10901041
10911042   /* update the menu state */
10921043   if (menu_stack != NULL)
1093   {
1094      ui_menu *menu = menu_stack;
1095      (*menu->handler)(machine, menu, menu->parameter, menu->state);
1096   }
1044      menu_stack->do_handle();
10971045
10981046   /* clear up anything pending to be released */
10991047   clear_free_list(machine);
src/emu/uimenu.h
r13553r13554
5757
5858
5959/* menu-related callback functions */
60typedef void (*ui_menu_handler_func)(running_machine &machine, ui_menu *menu, void *parameter, void *state);
6160typedef void (*ui_menu_custom_func)(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
62typedef void (*ui_menu_destroy_state_func)(ui_menu *menu, void *state);
6361
6462
6563/* menu-related events */
r13553r13554
9290class ui_menu
9391{
9492public:
95   ui_menu(running_machine &machine, render_container *container, ui_menu_handler_func handler, void *parameter);
96   ~ui_menu();
93   ui_menu(running_machine &machine, render_container *container);
94   virtual ~ui_menu();
9795
9896   running_machine &machine() const { return m_machine; }
9997
10098   render_container *   container;         /* render_container we render to */
101   ui_menu_handler_func handler;         /* handler callback */
102   void *            parameter;         /* parameter */
10399   ui_menu_event      menu_event;         /* the UI menu_event that occurred */
104100   ui_menu *         parent;            /* pointer to parent menu */
105   void *            state;            /* menu-specific state */
106   ui_menu_destroy_state_func destroy_state; /* destroy state callback */
107101   int               resetpos;         /* reset position */
108102   void *            resetref;         /* reset reference */
109103   int               selected;         /* which item is selected */
r13553r13554
112106   int               numitems;         /* number of items in the menu */
113107   int               allocitems;         /* allocated size of array */
114108   ui_menu_item *      item;            /* pointer to array of items */
115   ui_menu_custom_func custom;            /* callback for custom rendering */
116109   float            customtop;         /* amount of extra height to add at the top */
117110   float            custombottom;      /* amount of extra height to add at the bottom */
118111   ui_menu_pool *      pool;            /* list of memory pools */
r13553r13554
130123   const ui_menu_event *process(UINT32 flags);
131124
132125   /* configure the menu for custom rendering */
133   void set_custom_render(ui_menu_custom_func custom, float top, float bottom);
126   virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
134127
135   /* allocate permanent memory to represent the menu's state */
136   void *alloc_state(size_t size, ui_menu_destroy_state_func destroy_state);
137
138128   /* allocate temporary memory from the menu's memory pool */
139129   void *m_pool_alloc(size_t size);
140130
r13553r13554
174164   void validate_selection(int scandir);
175165   static ui_menu *menu_stack;
176166
167   void do_handle();
168
169   /* To be reimplemented in the menu subclass */
170   virtual void populate() = 0;
171
172   /* To be reimplemented in the menu subclass */
173   virtual void handle() = 0;
174
177175private:
178176   static ui_menu *menu_free;
179177   static bitmap_t *hilight_bitmap;
r13553r13554
194192   static void render_triangle(bitmap_t &dest, const bitmap_t &source, const rectangle &sbounds, void *param);
195193};
196194
197
198
199
200/***************************************************************************
201    FUNCTION PROTOTYPES
202***************************************************************************/
203
204
205/* ----- core menu management ----- */
206
207/* allocate a new menu */
208ui_menu *ui_menu_alloc(running_machine &machine, render_container *container, ui_menu_handler_func handler, void *parameter);
209
210195#endif   /* __UIMENU_H__ */
src/emu/ui.c
r13553r13554
13851385
13861386   /* if the on-screen display isn't up and the user has toggled it, turn it on */
13871387   if ((machine.debug_flags & DEBUG_FLAG_ENABLED) == 0 && ui_input_pressed(machine, IPT_UI_ON_SCREEN_DISPLAY))
1388      return ui_set_handler(ui_slider_ui_handler, 1);
1388      return ui_set_handler(ui_menu_sliders::ui_handler, 1);
13891389
13901390   /* handle a reset request */
13911391   if (ui_input_pressed(machine, IPT_UI_RESET_MACHINE))
src/emu/uiimage.c
r13553r13554
2222#include "ui.h"
2323#include "uimenu.h"
2424#include "uiswlist.h"
25#include "uiimage.h"
2526#include "zippath.h"
2627#include "unicode.h"
2728#include "imagedev/cassette.h"
r13553r13554
4748#define ITEMREF_NO            ((void *) 0x0004)
4849#define ITEMREF_YES            ((void *) 0x0005)
4950
50
51
5251/***************************************************************************
53    TYPE DEFINITIONS
54***************************************************************************/
55
56/* menu item type in the file selector */
57enum _file_selector_entry_type
58{
59   SELECTOR_ENTRY_TYPE_EMPTY,
60   SELECTOR_ENTRY_TYPE_CREATE,
61   SELECTOR_ENTRY_TYPE_SOFTWARE_LIST,
62   SELECTOR_ENTRY_TYPE_DRIVE,
63   SELECTOR_ENTRY_TYPE_DIRECTORY,
64   SELECTOR_ENTRY_TYPE_FILE
65};
66typedef enum _file_selector_entry_type file_selector_entry_type;
67
68
69
70/* an entry within the file manager */
71typedef struct _file_selector_entry file_selector_entry;
72struct _file_selector_entry
73{
74   file_selector_entry *next;
75
76   file_selector_entry_type type;
77   const char *basename;
78   const char *fullpath;
79};
80
81
82
83/* state of the file manager */
84typedef struct _file_manager_menu_state file_manager_menu_state;
85struct _file_manager_menu_state
86{
87   device_image_interface *selected_device;
88   astring *current_directory;
89   astring *current_file;
90};
91
92
93
94/* state of the file selector menu */
95typedef struct _file_selector_menu_state file_selector_menu_state;
96struct _file_selector_menu_state
97{
98   file_manager_menu_state *manager_menustate;
99   file_selector_entry *entrylist;
100   char filename_buffer[1024];
101};
102
103
104
105/* state of the file creator menu */
106typedef struct _file_create_menu_state file_create_menu_state;
107struct _file_create_menu_state
108{
109   file_manager_menu_state *manager_menustate;
110   const image_device_format *current_format;
111   int confirm_save_as_yes;
112   char filename_buffer[1024];
113};
114
115
116/* state of the confirm save as menu */
117typedef struct _confirm_save_as_menu_state confirm_save_as_menu_state;
118struct _confirm_save_as_menu_state
119{
120   int *yes;
121};
122
123/***************************************************************************
12452    MENU HELPERS
12553***************************************************************************/
12654
r13553r13554
15179    or footer text
15280-------------------------------------------------*/
15381
154static void extra_text_draw_box(render_container &ui_container, float origx1, float origx2, float origy, float yspan, const char *text, int direction)
82static void extra_text_draw_box(render_container *container, float origx1, float origx2, float origy, float yspan, const char *text, int direction)
15583{
15684   float text_width, text_height;
15785   float width, maxwidth;
15886   float x1, y1, x2, y2, temp;
15987
16088   /* get the size of the text */
161   ui_draw_text_full(&ui_container,text, 0.0f, 0.0f, 1.0f, JUSTIFY_LEFT, WRAP_WORD,
89   ui_draw_text_full(container,text, 0.0f, 0.0f, 1.0f, JUSTIFY_LEFT, WRAP_WORD,
16290      DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &text_width, &text_height);
16391   width = text_width + (2 * UI_BOX_LR_BORDER);
16492   maxwidth = MAX(width, origx2 - origx1);
r13553r13554
177105   }
178106
179107   /* draw a box */
180   ui_draw_outlined_box(&ui_container,x1, y1, x2, y2, UI_BACKGROUND_COLOR);
108   ui_draw_outlined_box(container,x1, y1, x2, y2, UI_BACKGROUND_COLOR);
181109
182110   /* take off the borders */
183111   x1 += UI_BOX_LR_BORDER;
r13553r13554
186114   y2 -= UI_BOX_TB_BORDER;
187115
188116   /* draw the text within it */
189   ui_draw_text_full(&ui_container,text, x1, y1, text_width, JUSTIFY_LEFT, WRAP_WORD,
117   ui_draw_text_full(container,text, x1, y1, text_width, JUSTIFY_LEFT, WRAP_WORD,
190118                 DRAW_NORMAL, ARGB_WHITE, ARGB_BLACK, NULL, NULL);
191119}
192120
r13553r13554
197125    and footer text
198126-------------------------------------------------*/
199127
200static void extra_text_render(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom,
128static void extra_text_render(render_container *container, float top, float bottom,
201129   float origx1, float origy1, float origx2, float origy2,
202130   const char *header, const char *footer)
203131{
r13553r13554
205133   footer = ((footer != NULL) && (footer[0] != '\0')) ? footer : NULL;
206134
207135   if (header != NULL)
208      extra_text_draw_box(machine.render().ui_container(), origx1, origx2, origy1, top, header, -1);
136      extra_text_draw_box(container, origx1, origx2, origy1, top, header, -1);
209137   if (footer != NULL)
210      extra_text_draw_box(machine.render().ui_container(), origx1, origx2, origy2, bottom, footer, +1);
138      extra_text_draw_box(container, origx1, origx2, origy2, bottom, footer, +1);
211139}
212140
213141
r13553r13554
221149    confirm save as menu
222150-------------------------------------------------*/
223151
224static void menu_confirm_save_as_populate(running_machine &machine, ui_menu *menu, void *state)
152ui_menu_confirm_save_as::ui_menu_confirm_save_as(running_machine &machine, render_container *container, int *_yes) : ui_menu(machine, container)
225153{
226   menu->item_append("File Already Exists - Overide?", NULL, MENU_FLAG_DISABLE, NULL);
227   menu->item_append(MENU_SEPARATOR_ITEM, NULL, MENU_FLAG_DISABLE, NULL);
228   menu->item_append("No", NULL, 0, ITEMREF_NO);
229   menu->item_append("Yes", NULL, 0, ITEMREF_YES);
154   yes = _yes;
230155}
231156
157ui_menu_confirm_save_as::~ui_menu_confirm_save_as()
158{
159}
232160
161void ui_menu_confirm_save_as::populate()
162{
163   item_append("File Already Exists - Overide?", NULL, MENU_FLAG_DISABLE, NULL);
164   item_append(MENU_SEPARATOR_ITEM, NULL, MENU_FLAG_DISABLE, NULL);
165   item_append("No", NULL, 0, ITEMREF_NO);
166   item_append("Yes", NULL, 0, ITEMREF_YES);
167}
233168
234169/*-------------------------------------------------
235170    menu_confirm_save_as - confirm save as menu
236171-------------------------------------------------*/
237172
238static void menu_confirm_save_as(running_machine &machine, ui_menu *menu, void *parameter, void *state)
173void ui_menu_confirm_save_as::handle()
239174{
240   const ui_menu_event *event;
241   confirm_save_as_menu_state *menustate = (confirm_save_as_menu_state *) state;
242
243   /* if the menu isn't built, populate now */
244   if (!menu->populated())
245      menu_confirm_save_as_populate(machine, menu, state);
246
247175   /* process the menu */
248   event = menu->process(0);
176   const ui_menu_event *event = process(0);
249177
250178   /* process the event */
251179   if ((event != NULL) && (event->iptkey == IPT_UI_SELECT))
252180   {
253181      if (event->itemref == ITEMREF_YES)
254         *menustate->yes = TRUE;
182         *yes = TRUE;
255183
256184      /* no matter what, pop out */
257      ui_menu::stack_pop(machine);
185      ui_menu::stack_pop(machine());
258186   }
259187}
260188
r13553r13554
293221    special rendering
294222-------------------------------------------------*/
295223
296static void file_create_render_extra(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
224void ui_menu_file_create::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
297225{
298   file_create_menu_state *menustate = (file_create_menu_state *) state;
299
300   extra_text_render(machine, menu, state, selectedref, top, bottom, origx1, origy1, origx2, origy2,
301      astring_c(menustate->manager_menustate->current_directory),
226   extra_text_render(container, top, bottom, origx1, origy1, origx2, origy2,
227      astring_c(manager->current_directory),
302228      NULL);
303229}
304230
r13553r13554
309235    creator menu
310236-------------------------------------------------*/
311237
312static void menu_file_create_populate(running_machine &machine, ui_menu *menu, void *state, void *selection)
238ui_menu_file_create::ui_menu_file_create(running_machine &machine, render_container *container, ui_menu_file_manager *parent) : ui_menu(machine, container)
313239{
240   manager = parent;
241}
242
243ui_menu_file_create::~ui_menu_file_create()
244{
245}
246
247void ui_menu_file_create::populate()
248{
314249   astring buffer;
315   file_create_menu_state *menustate = (file_create_menu_state *) state;
316   device_image_interface *device = menustate->manager_menustate->selected_device;
250   device_image_interface *device = manager->selected_device;
317251   const image_device_format *format;
318252   const char *new_image_name;
319253
320254   /* append the "New Image Name" item */
321   if (selection == ITEMREF_NEW_IMAGE_NAME)
255   if (get_selection() == ITEMREF_NEW_IMAGE_NAME)
322256   {
323      astring_assemble_2(&buffer, menustate->filename_buffer, "_");
257      astring_assemble_2(&buffer, filename_buffer, "_");
324258      new_image_name = astring_c(&buffer);
325259   }
326260   else
327261   {
328      new_image_name = menustate->filename_buffer;
262      new_image_name = filename_buffer;
329263   }
330   menu->item_append("New Image Name:", new_image_name, 0, ITEMREF_NEW_IMAGE_NAME);
264   item_append("New Image Name:", new_image_name, 0, ITEMREF_NEW_IMAGE_NAME);
331265
332266   /* do we support multiple formats? */
333267   format = device->device_get_creatable_formats();
334268   if (ENABLE_FORMATS && (format != NULL))
335269   {
336      menu->item_append("Image Format:", menustate->current_format->m_description, 0, ITEMREF_FORMAT);
337      menustate->current_format = format;
270      item_append("Image Format:", current_format->m_description, 0, ITEMREF_FORMAT);
271      current_format = format;
338272   }
339273
340274   /* finish up the menu */
341   menu->item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL);
342   menu->item_append("Create", NULL, 0, ITEMREF_CREATE);
275   item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL);
276   item_append("Create", NULL, 0, ITEMREF_CREATE);
343277
344   /* set up custom render proc */
345   menu->set_custom_render(file_create_render_extra, ui_get_line_height(machine) + 3.0f * UI_BOX_TB_BORDER, 0);
278   customtop = ui_get_line_height(machine()) + 3.0f * UI_BOX_TB_BORDER;
346279}
347280
348281
r13553r13554
351284    create_new_image - creates a new disk image
352285-------------------------------------------------*/
353286
354static int create_new_image(device_image_interface *image, const char *directory, const char *filename, int *yes)
287int ui_menu_file_create::create_new_image(device_image_interface *image, const char *directory, const char *filename, int *yes)
355288{
356289   astring *path;
357290   osd_directory_entry *entry;
358291   osd_dir_entry_type file_type;
359292   int do_create, err;
360293   int result = FALSE;
361   ui_menu *child_menu;
362   confirm_save_as_menu_state *child_menustate;
363294
364295   /* assemble the full path */
365296   path = zippath_combine(astring_alloc(), directory, filename);
r13553r13554
383314
384315      case ENTTYPE_FILE:
385316         /* a file exists here - ask for permission from the user */
386         child_menu = ui_menu_alloc(image->device().machine(), &image->device().machine().render().ui_container(), menu_confirm_save_as, NULL);
387         child_menustate = (confirm_save_as_menu_state*)child_menu->alloc_state(sizeof(*child_menustate), NULL);
388         child_menustate->yes = yes;
389         ui_menu::stack_push(child_menu);
317         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_confirm_save_as(machine(), container, yes)));
390318         do_create = FALSE;
391319         break;
392320
r13553r13554
424352    menu_file_create - file creator menu
425353-------------------------------------------------*/
426354
427static void menu_file_create(running_machine &machine, ui_menu *menu, void *parameter, void *state)
355void ui_menu_file_create::handle()
428356{
429   void *selection;
430357   const ui_menu_event *event;
431358   ui_menu_event fake_event;
432   file_create_menu_state *menustate = (file_create_menu_state *) state;
433359
434   /* identify the selection */
435   selection = menu->get_selection();
436
437   /* rebuild the menu */
438   menu->reset(UI_MENU_RESET_REMEMBER_POSITION);
439   menu_file_create_populate(machine, menu, state, selection);
440
441   if (menustate->confirm_save_as_yes)
360   if (confirm_save_as_yes)
442361   {
443362      /* we just returned from a "confirm save as" dialog and the user said "yes" - fake an event */
444363      memset(&fake_event, 0, sizeof(fake_event));
r13553r13554
449368   else
450369   {
451370      /* process the menu */
452      event = menu->process(0);
371      event = process(0);
453372   }
454373
455374   /* process the event */
r13553r13554
462381            if ((event->itemref == ITEMREF_CREATE) || (event->itemref == ITEMREF_NEW_IMAGE_NAME))
463382            {
464383               if (create_new_image(
465                  menustate->manager_menustate->selected_device,
466                  astring_c(menustate->manager_menustate->current_directory),
467                  menustate->filename_buffer,
468                  &menustate->confirm_save_as_yes))
384                  manager->selected_device,
385                  astring_c(manager->current_directory),
386                  filename_buffer,
387                  &confirm_save_as_yes))
469388               {
470389                  /* success - pop out twice to device view */
471                  ui_menu::stack_pop(machine);
472                  ui_menu::stack_pop(machine);
390                  ui_menu::stack_pop(machine());
391                  ui_menu::stack_pop(machine());
473392               }
474393            }
475394            break;
476395
477396         case IPT_SPECIAL:
478            if (menu->get_selection() == ITEMREF_NEW_IMAGE_NAME)
397            if (get_selection() == ITEMREF_NEW_IMAGE_NAME)
479398            {
480399               input_character(
481                  menustate->filename_buffer,
482                  ARRAY_LENGTH(menustate->filename_buffer),
400                  filename_buffer,
401                  ARRAY_LENGTH(filename_buffer),
483402                  event->unichar,
484403                  is_valid_filename_char);
485404            }
r13553r13554
499418    special rendering
500419-------------------------------------------------*/
501420
502static void file_selector_render_extra(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
421void ui_menu_file_selector::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
503422{
504   file_selector_menu_state *menustate = (file_selector_menu_state *) state;
505
506   extra_text_render(machine, menu, state, selectedref, top, bottom,
423   extra_text_render(container, top, bottom,
507424      origx1, origy1, origx2, origy2,
508      astring_c(menustate->manager_menustate->current_directory),
425      astring_c(manager->current_directory),
509426      NULL);
510427}
511428
r13553r13554
516433    for file selector entries
517434-------------------------------------------------*/
518435
519static int compare_file_selector_entries(const file_selector_entry *e1, const file_selector_entry *e2)
436int ui_menu_file_selector::compare_entries(const file_selector_entry *e1, const file_selector_entry *e2)
520437{
521438   int result;
522439   const char *e1_basename = (e1->basename != NULL) ? e1->basename : "";
r13553r13554
552469
553470
554471/*-------------------------------------------------
555    append_file_selector_entry - appends a new
472    append_entry - appends a new
556473    file selector entry to an entry list
557474-------------------------------------------------*/
558475
559static file_selector_entry *append_file_selector_entry(ui_menu *menu, file_selector_menu_state *menustate,
476ui_menu_file_selector::file_selector_entry *ui_menu_file_selector::append_entry(
560477   file_selector_entry_type entry_type, const char *entry_basename, const char *entry_fullpath)
561478{
562479   file_selector_entry *entry;
563480   file_selector_entry **entryptr;
564481
565482   /* allocate a new entry */
566   entry = (file_selector_entry *) menu->m_pool_alloc(sizeof(*entry));
483   entry = (file_selector_entry *) m_pool_alloc(sizeof(*entry));
567484   memset(entry, 0, sizeof(*entry));
568485   entry->type = entry_type;
569   entry->basename = (entry_basename != NULL) ? menu->pool_strdup(entry_basename) : entry_basename;
570   entry->fullpath = (entry_fullpath != NULL) ? menu->pool_strdup(entry_fullpath) : entry_fullpath;
486   entry->basename = (entry_basename != NULL) ? pool_strdup(entry_basename) : entry_basename;
487   entry->fullpath = (entry_fullpath != NULL) ? pool_strdup(entry_fullpath) : entry_fullpath;
571488
572489   /* find the end of the list */
573   entryptr = &menustate->entrylist;
574   while ((*entryptr != NULL) && (compare_file_selector_entries(entry, *entryptr) >= 0))
490   entryptr = &entrylist;
491   while ((*entryptr != NULL) && (compare_entries(entry, *entryptr) >= 0))
575492      entryptr = &(*entryptr)->next;
576493
577494   /* insert the entry */
r13553r13554
583500
584501
585502/*-------------------------------------------------
586    append_file_selector_entry_menu_item - appends
503    append_entry_menu_item - appends
587504    a menu item for a file selector entry
588505-------------------------------------------------*/
589506
590static file_selector_entry *append_dirent_file_selector_entry(ui_menu *menu, file_selector_menu_state *menustate,
591   const osd_directory_entry *dirent)
507ui_menu_file_selector::file_selector_entry *ui_menu_file_selector::append_dirent_entry(const osd_directory_entry *dirent)
592508{
593509   astring *buffer;
594510   file_selector_entry_type entry_type;
r13553r13554
612528   /* determine the full path */
613529   buffer = zippath_combine(
614530      astring_alloc(),
615      astring_c(menustate->manager_menustate->current_directory),
531      astring_c(manager->current_directory),
616532      dirent->name);
617533
618534   /* create the file selector entry */
619   entry = append_file_selector_entry(
620      menu,
621      menustate,
535   entry = append_entry(
622536      entry_type,
623537      dirent->name,
624538      astring_c(buffer));
r13553r13554
630544
631545
632546/*-------------------------------------------------
633    append_file_selector_entry_menu_item - appends
547    append_entry_menu_item - appends
634548    a menu item for a file selector entry
635549-------------------------------------------------*/
636550
637static void append_file_selector_entry_menu_item(ui_menu *menu, const file_selector_entry *entry)
551void ui_menu_file_selector::append_entry_menu_item(const file_selector_entry *entry)
638552{
639553   const char *text = NULL;
640554   const char *subtext = NULL;
r13553r13554
668582         subtext = "[FILE]";
669583         break;
670584   }
671   menu->item_append(text, subtext, 0, (void *) entry);
585   item_append(text, subtext, 0, (void *) entry);
672586}
673587
674588
r13553r13554
677591    allocates all menu items for a directory
678592-------------------------------------------------*/
679593
680static file_error menu_file_selector_populate(running_machine &machine, ui_menu *menu, file_selector_menu_state *menustate)
594ui_menu_file_selector::ui_menu_file_selector(running_machine &machine, render_container *container, ui_menu_file_manager *parent) : ui_menu(machine, container)
681595{
596   manager = parent;
597}
598
599ui_menu_file_selector::~ui_menu_file_selector()
600{
601}
602
603void ui_menu_file_selector::populate()
604{
682605   zippath_directory *directory = NULL;
683606   file_error err = FILERR_NONE;
684607   const osd_directory_entry *dirent;
r13553r13554
686609   const file_selector_entry *selected_entry = NULL;
687610   int i;
688611   const char *volume_name;
689   device_image_interface *device = menustate->manager_menustate->selected_device;
690   const char *path = astring_c(menustate->manager_menustate->current_directory);
612   device_image_interface *device = manager->selected_device;
613   const char *path = astring_c(manager->current_directory);
691614
692615   /* open the directory */
693616   err = zippath_opendir(path, &directory);
r13553r13554
695618      goto done;
696619
697620   /* clear out the menu entries */
698   menustate->entrylist = NULL;
621   entrylist = NULL;
699622
700623   /* add the "[empty slot]" entry */
701   append_file_selector_entry(menu, menustate, SELECTOR_ENTRY_TYPE_EMPTY, NULL, NULL);
624   append_entry(SELECTOR_ENTRY_TYPE_EMPTY, NULL, NULL);
702625
703626   if (device->is_creatable() && !zippath_is_zip(directory))
704627   {
705628      /* add the "[create]" entry */
706      append_file_selector_entry(menu, menustate, SELECTOR_ENTRY_TYPE_CREATE, NULL, NULL);
629      append_entry(SELECTOR_ENTRY_TYPE_CREATE, NULL, NULL);
707630   }
708631
709632   /* add the "[software list]" entry */
710   append_file_selector_entry(menu, menustate, SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, NULL, NULL);
633   append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, NULL, NULL);
711634
712635   /* add the drives */
713636   i = 0;
714637   while((volume_name = osd_get_volume_name(i))!=NULL)
715638   {
716      append_file_selector_entry(menu, menustate, SELECTOR_ENTRY_TYPE_DRIVE,
639      append_entry(SELECTOR_ENTRY_TYPE_DRIVE,
717640         volume_name, volume_name);
718641      i++;
719642   }
r13553r13554
722645   while((dirent = zippath_readdir(directory)) != NULL)
723646   {
724647      /* append a dirent entry */
725      entry = append_dirent_file_selector_entry(menu, menustate, dirent);
648      entry = append_dirent_entry(dirent);
726649
727650      if (entry != NULL)
728651      {
r13553r13554
731654            selected_entry = entry;
732655
733656         /* do we have to select this file? */
734         if (!mame_stricmp(astring_c(menustate->manager_menustate->current_file), dirent->name))
657         if (!mame_stricmp(astring_c(manager->current_file), dirent->name))
735658            selected_entry = entry;
736659      }
737660   }
738661
739662   /* append all of the menu entries */
740   for (entry = menustate->entrylist; entry != NULL; entry = entry->next)
741      append_file_selector_entry_menu_item(menu, entry);
663   for (entry = entrylist; entry != NULL; entry = entry->next)
664      append_entry_menu_item(entry);
742665
743666   /* set the selection (if we have one) */
744667   if (selected_entry != NULL)
745      menu->set_selection((void *) selected_entry);
668      set_selection((void *) selected_entry);
746669
747670   /* set up custom render proc */
748   menu->set_custom_render(file_selector_render_extra, ui_get_line_height(machine) + 3.0f * UI_BOX_TB_BORDER, 0);
671   customtop = ui_get_line_height(machine()) + 3.0f * UI_BOX_TB_BORDER;
749672
750673done:
751674   if (directory != NULL)
752675      zippath_closedir(directory);
753   return err;
754676}
755677
756
757
758678/*-------------------------------------------------
759679    check_path - performs a quick check to see if
760680    a path exists
r13553r13554
771691    menu_file_selector - file selector menu
772692-------------------------------------------------*/
773693
774static void menu_file_selector(running_machine &machine, ui_menu *menu, void *parameter, void *state)
694void ui_menu_file_selector::handle()
775695{
776696   file_error err;
777   const ui_menu_event *event;
778   ui_menu *child_menu;
779   file_selector_menu_state *menustate;
780   file_create_menu_state *child_menustate;
781697   const file_selector_entry *entry;
782698   const file_selector_entry *selected_entry = NULL;
783699   int bestmatch = 0;
784700
785   /* get menu state */
786   menustate = (file_selector_menu_state *) state;
787
788   /* if the menu isn't built, populate now */
789   if (!menu->populated())
790   {
791      err = menu_file_selector_populate(machine, menu, menustate);
792
793      /* pop out if there was an error */
794      if (err != FILERR_NONE)
795      {
796         ui_menu::stack_pop(machine);
797         return;
798      }
799   }
800
801701   /* process the menu */
802   event = menu->process(0);
702   const ui_menu_event *event = process(0);
803703   if (event != NULL && event->itemref != NULL)
804704   {
805705      /* handle selections */
r13553r13554
810710         {
811711            case SELECTOR_ENTRY_TYPE_EMPTY:
812712               /* empty slot - unload */
813               menustate->manager_menustate->selected_device->unload();
814               ui_menu::stack_pop(machine);
713               manager->selected_device->unload();
714               ui_menu::stack_pop(machine());
815715               break;
816716
817717            case SELECTOR_ENTRY_TYPE_CREATE:
818718               /* create */
819               child_menu = ui_menu_alloc(machine, &machine.render().ui_container(), menu_file_create, NULL);
820               child_menustate = (file_create_menu_state*)child_menu->alloc_state(sizeof(*child_menustate), NULL);
821               child_menustate->manager_menustate = menustate->manager_menustate;
822               ui_menu::stack_push(child_menu);
719               ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_create(machine(), container, manager)));
823720               break;
824721            case SELECTOR_ENTRY_TYPE_SOFTWARE_LIST:
825               child_menu = ui_menu_alloc(machine, &machine.render().ui_container(), ui_image_menu_software, menustate->manager_menustate->selected_device);
826               ui_menu::stack_push(child_menu);
722               ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software(machine(), container, manager->selected_device)));
827723               break;
828724            case SELECTOR_ENTRY_TYPE_DRIVE:
829725            case SELECTOR_ENTRY_TYPE_DIRECTORY:
r13553r13554
835731                  ui_popup_time(1, "Error accessing %s", entry->fullpath);
836732                  break;
837733               }
838               astring_cpyc(menustate->manager_menustate->current_directory, entry->fullpath);
839               menu->reset((ui_menu_reset_options)0);
734               astring_cpyc(manager->current_directory, entry->fullpath);
735               reset((ui_menu_reset_options)0);
840736               break;
841737
842738            case SELECTOR_ENTRY_TYPE_FILE:
843739               /* file */
844               menustate->manager_menustate->selected_device->load(entry->fullpath);
845               ui_menu::stack_pop(machine);
740               manager->selected_device->load(entry->fullpath);
741               ui_menu::stack_pop(machine());
846742               break;
847743         }
848744
849745         // reset the char buffer when pressing IPT_UI_SELECT
850         if (menustate->filename_buffer[0] != '\0')
851            memset(menustate->filename_buffer, '\0', ARRAY_LENGTH(menustate->filename_buffer));
746         if (filename_buffer[0] != '\0')
747            memset(filename_buffer, '\0', ARRAY_LENGTH(filename_buffer));
852748      }
853749      else if (event->iptkey == IPT_SPECIAL)
854750      {
855         int buflen = strlen(menustate->filename_buffer);
751         int buflen = strlen(filename_buffer);
856752         bool update_selected = FALSE;
857753
858754         /* if it's a backspace and we can handle it, do so */
859755         if ((event->unichar == 8 || event->unichar == 0x7f) && buflen > 0)
860756         {
861            *(char *)utf8_previous_char(&menustate->filename_buffer[buflen]) = 0;
757            *(char *)utf8_previous_char(&filename_buffer[buflen]) = 0;
862758            update_selected = TRUE;
863759
864            if (ARRAY_LENGTH(menustate->filename_buffer) > 0)
865               ui_popup_time(ERROR_MESSAGE_TIME, "%s", menustate->filename_buffer);
760            if (ARRAY_LENGTH(filename_buffer) > 0)
761               ui_popup_time(ERROR_MESSAGE_TIME, "%s", filename_buffer);
866762         }
867763         /* if it's any other key and we're not maxed out, update */
868764         else if (event->unichar >= ' ' && event->unichar < 0x7f)
869765         {
870            buflen += utf8_from_uchar(&menustate->filename_buffer[buflen], ARRAY_LENGTH(menustate->filename_buffer) - buflen, event->unichar);
871            menustate->filename_buffer[buflen] = 0;
766            buflen += utf8_from_uchar(&filename_buffer[buflen], ARRAY_LENGTH(filename_buffer) - buflen, event->unichar);
767            filename_buffer[buflen] = 0;
872768            update_selected = TRUE;
873769
874            if (ARRAY_LENGTH(menustate->filename_buffer) > 0)
875               ui_popup_time(ERROR_MESSAGE_TIME, "%s", menustate->filename_buffer);
770            if (ARRAY_LENGTH(filename_buffer) > 0)
771               ui_popup_time(ERROR_MESSAGE_TIME, "%s", filename_buffer);
876772         }
877773
878774         if (update_selected)
879775         {
880            const file_selector_entry *cur_selected = (const file_selector_entry *)menu->get_selection();
776            const file_selector_entry *cur_selected = (const file_selector_entry *)get_selection();
881777
882778            // check for entries which matches our filename_buffer:
883779            // from current entry to the end
884780            for (entry = cur_selected; entry != NULL; entry = entry->next)
885781            {
886               if (entry->basename != NULL && menustate->filename_buffer != NULL)
782               if (entry->basename != NULL && filename_buffer != NULL)
887783               {
888784                  int match = 0;
889                  for (int i = 0; i < ARRAY_LENGTH(menustate->filename_buffer); i++)
785                  for (int i = 0; i < ARRAY_LENGTH(filename_buffer); i++)
890786                  {
891                     if (mame_strnicmp(entry->basename, menustate->filename_buffer, i) == 0)
787                     if (mame_strnicmp(entry->basename, filename_buffer, i) == 0)
892788                        match = i;
893789                  }
894790
r13553r13554
900796               }
901797            }
902798            // and from the first entry to current one
903            for (entry = menustate->entrylist; entry != cur_selected; entry = entry->next)
799            for (entry = entrylist; entry != cur_selected; entry = entry->next)
904800            {
905               if (entry->basename != NULL && menustate->filename_buffer != NULL)
801               if (entry->basename != NULL && filename_buffer != NULL)
906802               {
907803                  int match = 0;
908                  for (int i = 0; i < ARRAY_LENGTH(menustate->filename_buffer); i++)
804                  for (int i = 0; i < ARRAY_LENGTH(filename_buffer); i++)
909805                  {
910                     if (mame_strnicmp(entry->basename, menustate->filename_buffer, i) == 0)
806                     if (mame_strnicmp(entry->basename, filename_buffer, i) == 0)
911807                        match = i;
912808                  }
913809
r13553r13554
920816            }
921817
922818            if (selected_entry != NULL && selected_entry != cur_selected)
923               menu->set_selection((void *) selected_entry);
819               set_selection((void *) selected_entry);
924820         }
925821      }
926822      else if (event->iptkey == IPT_UI_CANCEL)
927823      {
928824         // reset the char buffer also in this case
929         if (menustate->filename_buffer[0] != '\0')
930            memset(menustate->filename_buffer, '\0', ARRAY_LENGTH(menustate->filename_buffer));
825         if (filename_buffer[0] != '\0')
826            memset(filename_buffer, '\0', ARRAY_LENGTH(filename_buffer));
931827      }
932828   }
933829}
r13553r13554
944840    "makes sense"
945841-------------------------------------------------*/
946842
947static void fix_working_directory(device_image_interface *image)
843void ui_menu_file_manager::fix_working_directory(device_image_interface *image)
948844{
949845   /* if the image exists, set the working directory to the parent directory */
950846   if (image->exists())
r13553r13554
967863    special rendering
968864-------------------------------------------------*/
969865
970static void file_manager_render_extra(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
866void ui_menu_file_manager::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
971867{
972   file_manager_menu_state *menustate = (file_manager_menu_state *) state;
973868   const char *path;
974869
975870   /* access the path */
976   path = (menustate->selected_device != NULL) ? menustate->selected_device->filename() : NULL;
977   extra_text_render(machine, menu, state, selectedref, top, bottom,
978      origx1, origy1, origx2, origy2, NULL, path);
871   path = selected_device ? selected_device->filename() : NULL;
872   extra_text_render(container, top, bottom,
873                 origx1, origy1, origx2, origy2, NULL, path);
979874}
980875
981876
r13553r13554
985880    file manager menu
986881-------------------------------------------------*/
987882
988static void menu_file_manager_populate(running_machine &machine, ui_menu *menu, void *state)
883ui_menu_file_manager::ui_menu_file_manager(running_machine &machine, render_container *container) : ui_menu(machine, container)
989884{
885   current_directory = astring_alloc();
886   current_file = astring_alloc();
887}
888
889void ui_menu_file_manager::populate()
890{
990891   char buffer[2048];
991892   device_image_interface *image = NULL;
992893   astring tmp_name;
993894
994895   /* cycle through all devices for this system */
995   for (bool gotone = machine.devicelist().first(image); gotone; gotone = image->next(image))
896   for (bool gotone = machine().devicelist().first(image); gotone; gotone = image->next(image))
996897   {
997898      /* get the image type/id */
998899      snprintf(buffer, ARRAY_LENGTH(buffer),
r13553r13554
1026927         tmp_name.cpy("---");
1027928
1028929      /* record the menu item */
1029      menu->item_append(buffer, tmp_name.cstr(), 0, (void *) image);
930      item_append(buffer, tmp_name.cstr(), 0, (void *) image);
1030931   }
1031932
1032   /* set up custom render proc */
1033   menu->set_custom_render(file_manager_render_extra, 0, ui_get_line_height(machine) + 3.0f * UI_BOX_TB_BORDER);
933   custombottom = ui_get_line_height(machine()) + 3.0f * UI_BOX_TB_BORDER;
1034934}
1035935
1036936
r13553r13554
1039939    file_manager_destroy_state - state destructor
1040940-------------------------------------------------*/
1041941
1042static void file_manager_destroy_state(ui_menu *menu, void *state)
942ui_menu_file_manager::~ui_menu_file_manager()
1043943{
1044   file_manager_menu_state *menustate = (file_manager_menu_state *) state;
1045
1046   if (menustate->current_directory != NULL)
1047      astring_free(menustate->current_directory);
1048
1049   if (menustate->current_file != NULL)
1050      astring_free(menustate->current_file);
944   astring_free(current_directory);
945   astring_free(current_file);
1051946}
1052947
1053948
r13553r13554
1056951    menu_file_manager - main file manager menu
1057952-------------------------------------------------*/
1058953
1059void ui_image_menu_file_manager(running_machine &machine, ui_menu *menu, void *parameter, void *state)
954void ui_menu_file_manager::handle()
1060955{
1061   const ui_menu_event *event;
1062   file_manager_menu_state *menustate;
1063   ui_menu *child_menu;
1064   file_selector_menu_state *child_menustate;
1065
1066   /* if no state, allocate now */
1067   if (state == NULL)
1068   {
1069      state = menu->alloc_state(sizeof(*menustate), file_manager_destroy_state);
1070      menustate = (file_manager_menu_state *) state;
1071
1072      menustate->current_directory = astring_alloc();
1073      menustate->current_file = astring_alloc();
1074   }
1075   menustate = (file_manager_menu_state *) state;
1076
1077   /* if the menu isn't built, populate now */
1078   if (!menu->populated())
1079      menu_file_manager_populate(machine, menu, state);
1080
1081956   /* update the selected device */
1082   menustate->selected_device = (device_image_interface *) menu->get_selection();
957   selected_device = (device_image_interface *) get_selection();
1083958
1084959   /* process the menu */
1085   event = menu->process(0);
960   const ui_menu_event *event = process(0);
1086961   if (event != NULL && event->iptkey == IPT_UI_SELECT)
1087962   {
1088      menustate->selected_device = (device_image_interface *) event->itemref;
1089      if (menustate->selected_device != NULL)
963      selected_device = (device_image_interface *) event->itemref;
964      if (selected_device != NULL)
1090965      {
1091966         /* ensure that the working directory for this device exists */
1092         fix_working_directory(menustate->selected_device);
967         fix_working_directory(selected_device);
1093968
1094969         /* set up current_directory and current_file - depends on whether we have an image */
1095         astring_cpyc(menustate->current_directory, menustate->selected_device->working_directory());
1096         astring_cpyc(menustate->current_file, menustate->selected_device->exists() ? menustate->selected_device->basename() : "");
970         astring_cpyc(current_directory, selected_device->working_directory());
971         astring_cpyc(current_file, selected_device->exists() ? selected_device->basename() : "");
1097972
1098973         /* reset the existing menu */
1099         menu->reset(UI_MENU_RESET_REMEMBER_POSITION);
974         reset(UI_MENU_RESET_REMEMBER_POSITION);
1100975
1101976         /* push the menu */
1102         child_menu = ui_menu_alloc(machine, &machine.render().ui_container(), menu_file_selector, NULL);
1103         child_menustate = (file_selector_menu_state *)child_menu->alloc_state(sizeof(*child_menustate), NULL);
1104         child_menustate->manager_menustate = menustate;
1105         ui_menu::stack_push(child_menu);
977         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_selector(machine(), container, this)));
1106978      }
1107979   }
1108980}
1109981
1110982/*-------------------------------------------------
1111    ui_image_menu_image_info - menu that shows info
983    ui_menu_image_info - menu that shows info
1112984    on all loaded images
1113985-------------------------------------------------*/
1114986
1115void ui_image_menu_image_info(running_machine &machine, ui_menu *menu, void *parameter, void *state)
987ui_menu_image_info::ui_menu_image_info(running_machine &machine, render_container *container) : ui_menu(machine, container)
1116988{
1117   /* if the menu isn't built, populate now */
1118   if (!menu->populated())
1119   {
1120      astring *tempstring = image_info_astring(machine, astring_alloc());
1121      menu->item_append(astring_c(tempstring), NULL, MENU_FLAG_MULTILINE, NULL);
1122      astring_free(tempstring);
1123   }
989}
1124990
991void ui_menu_image_info::populate()
992{
993   astring *tempstring = image_info_astring(machine(), astring_alloc());
994   item_append(astring_c(tempstring), NULL, MENU_FLAG_MULTILINE, NULL);
995   astring_free(tempstring);
996}
997
998ui_menu_image_info::~ui_menu_image_info()
999{
1000}
1001
1002void ui_menu_image_info::handle()
1003{
11251004   /* process the menu */
1126   menu->process(0);
1005   process(0);
11271006}
11281007
11291008/***************************************************************************
r13553r13554
11441023#define BITBANGERCMD_TUNE         ((void *) 0x0003)
11451024
11461025
1147typedef struct _tape_control_menu_state tape_control_menu_state;
1148struct _tape_control_menu_state
1026/***************************************************************************
1027    IMPLEMENTATION
1028***************************************************************************/
1029
1030ui_menu_mess_tape_control::ui_menu_mess_tape_control(running_machine &machine, render_container *container) : ui_menu(machine, container)
11491031{
1150   int index;
1151   device_image_interface *device;
1152};
1032}
11531033
1034ui_menu_mess_tape_control::~ui_menu_mess_tape_control()
1035{
1036}
11541037
1038ui_menu_mess_bitbanger_control::ui_menu_mess_bitbanger_control(running_machine &machine, render_container *container) : ui_menu(machine, container)
1039{
1040}
11551041
1156typedef struct _bitbanger_control_menu_state bitbanger_control_menu_state;
1157struct _bitbanger_control_menu_state
1042ui_menu_mess_bitbanger_control::~ui_menu_mess_bitbanger_control()
11581043{
1159   int index;
1160   device_image_interface *device;
1161};
1044}
11621045
1163
1164
1165/***************************************************************************
1166    IMPLEMENTATION
1167***************************************************************************/
1168
11691046/*-------------------------------------------------
11701047    cassette_count - returns the number of cassette
11711048    devices in the machine
11721049-------------------------------------------------*/
11731050
1174INLINE int cassette_count( running_machine &machine )
1051int ui_menu_mess_tape_control::cassette_count()
11751052{
11761053   int count = 0;
1177   device_t *device = machine.devicelist().first(CASSETTE);
1054   device_t *device = machine().devicelist().first(CASSETTE);
11781055
11791056   while ( device )
11801057   {
r13553r13554
11891066    devices in the machine
11901067-------------------------------------------------*/
11911068
1192INLINE int bitbanger_count( running_machine &machine )
1069int ui_menu_mess_bitbanger_control::bitbanger_count()
11931070{
11941071   int count = 0;
1195   device_t *device = machine.devicelist().first(BITBANGER);
1072   device_t *device = machine().devicelist().first(BITBANGER);
11961073
11971074   while ( device )
11981075   {
r13553r13554
12341111    main tape control menu
12351112-------------------------------------------------*/
12361113
1237static void menu_tape_control_populate(running_machine &machine, ui_menu *menu, tape_control_menu_state *menustate)
1114void ui_menu_mess_tape_control::populate()
12381115{
12391116   astring timepos;
12401117   cassette_state state;
1241   int count = cassette_count(machine);
1118   int count = cassette_count();
12421119   UINT32 flags = 0;
12431120
12441121   if( count > 0 )
12451122   {
1246      if( menustate->index == (count-1) )
1123      if( index == (count-1) )
12471124         flags |= MENU_FLAG_LEFT_ARROW;
12481125      else
12491126         flags |= MENU_FLAG_RIGHT_ARROW;
12501127   }
12511128
1252   if (menustate->device->exists())
1129   if (device->exists())
12531130   {
12541131      double t0, t1;
12551132      UINT32 tapeflags = 0;
1256      cassette_image_device* cassette = dynamic_cast<cassette_image_device*>(&menustate->device->device());
1133      cassette_image_device* cassette = dynamic_cast<cassette_image_device*>(&device->device());
12571134
12581135      t0 = cassette->get_position();
12591136      t1 = cassette->get_length();
r13553r13554
12671144      }
12681145
12691146      /* name of tape */
1270      menu->item_append(menustate->device->device().name(), menustate->device->filename(), flags, TAPECMD_SELECT);
1147      item_append(device->device().name(), device->filename(), flags, TAPECMD_SELECT);
12711148
12721149      /* state */
12731150      tapecontrol_gettime(&timepos, cassette, NULL, NULL);
12741151      state = cassette->get_state();
1275      menu->item_append(
1152      item_append(
12761153         (state & CASSETTE_MASK_UISTATE) == CASSETTE_STOPPED
12771154            ?   "stopped"
12781155            :   ((state & CASSETTE_MASK_UISTATE) == CASSETTE_PLAY
r13553r13554
12841161         TAPECMD_SLIDER);
12851162
12861163      /* pause or stop */
1287      menu->item_append("Pause/Stop", NULL, 0, TAPECMD_STOP);
1164      item_append("Pause/Stop", NULL, 0, TAPECMD_STOP);
12881165
12891166      /* play */
1290      menu->item_append("Play", NULL, 0, TAPECMD_PLAY);
1167      item_append("Play", NULL, 0, TAPECMD_PLAY);
12911168
12921169      /* record */
1293      menu->item_append("Record", NULL, 0, TAPECMD_RECORD);
1170      item_append("Record", NULL, 0, TAPECMD_RECORD);
12941171
12951172      /* rewind */
1296      menu->item_append("Rewind", NULL, 0, TAPECMD_REWIND);
1173      item_append("Rewind", NULL, 0, TAPECMD_REWIND);
12971174
12981175      /* fast forward */
1299      menu->item_append("Fast Forward", NULL, 0, TAPECMD_FAST_FORWARD);
1176      item_append("Fast Forward", NULL, 0, TAPECMD_FAST_FORWARD);
13001177   }
13011178   else
13021179   {
13031180      /* no tape loaded */
1304      menu->item_append("No Tape Image loaded", NULL, flags, NULL);
1181      item_append("No Tape Image loaded", NULL, flags, NULL);
13051182   }
13061183}
13071184
r13553r13554
13111188    main bitbanger control menu
13121189-------------------------------------------------*/
13131190
1314static void menu_bitbanger_control_populate(running_machine &machine, ui_menu *menu, bitbanger_control_menu_state *menustate)
1191void ui_menu_mess_bitbanger_control::populate()
13151192{
1316   bitbanger_device *bitbanger = downcast<bitbanger_device *>(&menustate->device->device());
1317   int count = bitbanger_count(machine);
1193   bitbanger_device *bitbanger = downcast<bitbanger_device *>(&device->device());
1194   int count = bitbanger_count();
13181195   UINT32 flags = 0, mode_flags = 0, baud_flags = 0, tune_flags = 0;
13191196
13201197   if( count > 0 )
13211198   {
1322      if( menustate->index == (count-1) )
1199      if( index == (count-1) )
13231200         flags |= MENU_FLAG_LEFT_ARROW;
13241201      else
13251202         flags |= MENU_FLAG_RIGHT_ARROW;
r13553r13554
13441221      tune_flags |= MENU_FLAG_LEFT_ARROW;
13451222
13461223
1347   if (menustate->device->exists())
1224   if (device->exists())
13481225   {
13491226      /* name of bitbanger file */
1350      menu->item_append(menustate->device->device().name(), menustate->device->filename(), flags, BITBANGERCMD_SELECT);
1351      menu->item_append("Device Mode:", bitbanger->mode_string(), mode_flags, BITBANGERCMD_MODE);
1352      menu->item_append("Baud:", bitbanger->baud_string(), baud_flags, BITBANGERCMD_BAUD);
1353      menu->item_append("Baud Tune:", bitbanger->tune_string(), tune_flags, BITBANGERCMD_TUNE);
1354      menu->item_append("Protocol:", "8-1-N", 0, NULL);
1227      item_append(device->device().name(), device->filename(), flags, BITBANGERCMD_SELECT);
1228      item_append("Device Mode:", bitbanger->mode_string(), mode_flags, BITBANGERCMD_MODE);
1229      item_append("Baud:", bitbanger->baud_string(), baud_flags, BITBANGERCMD_BAUD);
1230      item_append("Baud Tune:", bitbanger->tune_string(), tune_flags, BITBANGERCMD_TUNE);
1231      item_append("Protocol:", "8-1-N", 0, NULL);
13551232   }
13561233   else
13571234   {
13581235      /* no tape loaded */
1359      menu->item_append("No Bitbanger Image loaded", NULL, flags, NULL);
1236      item_append("No Bitbanger Image loaded", NULL, flags, NULL);
13601237   }
13611238}
13621239
r13553r13554
13651242    menu_tape_control - main tape control menu
13661243-------------------------------------------------*/
13671244
1368void ui_mess_menu_tape_control(running_machine &machine, ui_menu *menu, void *parameter, void *state)
1245void ui_menu_mess_tape_control::handle()
13691246{
1370   tape_control_menu_state *menustate;
1371   const ui_menu_event *event;
1372
1373   /* if no state, allocate some */
1374   if (state == NULL)
1375      state = menu->alloc_state(sizeof(*menustate), NULL);
1376   menustate = (tape_control_menu_state *) state;
1377
13781247   /* do we have to load the device? */
1379   if (menustate->device == NULL)
1248   if (device == NULL)
13801249   {
1381      int index = menustate->index;
1382      device_image_interface *device = NULL;
1383      for (bool gotone = machine.devicelist().first(device); gotone; gotone = device->next(device))
1250      int cindex = index;
1251      for (bool gotone = machine().devicelist().first(device); gotone; gotone = device->next(device))
13841252      {
13851253         if(device->device().type() == CASSETTE) {
1386            if (index==0) break;
1387            index--;
1254            if (cindex==0) break;
1255            cindex--;
13881256         }
13891257      }
1390      menustate->device = device;
1391      menu->reset((ui_menu_reset_options)0);
1258      reset((ui_menu_reset_options)0);
13921259   }
13931260
13941261   /* rebuild the menu - we have to do this so that the counter updates */
1395   menu->reset(UI_MENU_RESET_REMEMBER_POSITION);
1396   menu_tape_control_populate(machine, menu, (tape_control_menu_state*)state);
1262   reset(UI_MENU_RESET_REMEMBER_POSITION);
1263   populate();
13971264
1398   cassette_image_device* cassette = dynamic_cast<cassette_image_device*>(&menustate->device->device());
1265   cassette_image_device* cassette = dynamic_cast<cassette_image_device*>(&device->device());
13991266
14001267   /* process the menu */
1401   event = menu->process(UI_MENU_PROCESS_LR_REPEAT);
1268   const ui_menu_event *event = process(UI_MENU_PROCESS_LR_REPEAT);
14021269   if (event != NULL)
14031270   {
14041271      switch(event->iptkey)
r13553r13554
14101277            if (event->itemref==TAPECMD_SELECT)
14111278            {
14121279               /* left arrow - rotate left through cassette devices */
1413               if (menustate->index > 0)
1414                  menustate->index--;
1280               if (index > 0)
1281                  index--;
14151282               else
1416                  menustate->index = cassette_count(machine) - 1;
1417               menustate->device = NULL;
1283                  index = cassette_count() - 1;
1284               device = NULL;
14181285            }
14191286            break;
14201287
r13553r13554
14251292            if (event->itemref==TAPECMD_SELECT)
14261293            {
14271294               /* right arrow - rotate right through cassette devices */
1428               if (menustate->index < cassette_count(machine) - 1)
1429                  menustate->index++;
1295               if (index < cassette_count() - 1)
1296                  index++;
14301297               else
1431                  menustate->index = 0;
1432               menustate->device = NULL;
1298                  index = 0;
1299               device = NULL;
14331300            }
14341301            break;
14351302
r13553r13554
14641331    control menu
14651332-------------------------------------------------*/
14661333
1467void ui_mess_menu_bitbanger_control(running_machine &machine, ui_menu *menu, void *parameter, void *state)
1334void ui_menu_mess_bitbanger_control::handle()
14681335{
1469   bitbanger_control_menu_state *menustate;
1470   const ui_menu_event *event;
1471
1472   /* if no state, allocate some */
1473   if (state == NULL)
1474      state = menu->alloc_state(sizeof(*menustate), NULL);
1475   menustate = (bitbanger_control_menu_state *) state;
1476
14771336   /* do we have to load the device? */
1478   if (menustate->device == NULL)
1337   if (device == NULL)
14791338   {
1480      int index = menustate->index;
1481      device_image_interface *device = NULL;
1482      for (bool gotone = machine.devicelist().first(device); gotone; gotone = device->next(device))
1339      int cindex = index;
1340      for (bool gotone = machine().devicelist().first(device); gotone; gotone = device->next(device))
14831341      {
14841342         if(device->device().type() == BITBANGER) {
1485            if (index==0) break;
1486            index--;
1343            if (cindex==0) break;
1344            cindex--;
14871345         }
14881346      }
1489      menustate->device = device;
1490      menu->reset((ui_menu_reset_options)0);
1347      reset((ui_menu_reset_options)0);
14911348   }
14921349
14931350   /* get the bitbanger */
1494   bitbanger_device *bitbanger = downcast<bitbanger_device *>(menustate->device);
1351   bitbanger_device *bitbanger = downcast<bitbanger_device *>(device);
14951352
14961353   /* rebuild the menu */
1497   menu->reset(UI_MENU_RESET_REMEMBER_POSITION);
1498   menu_bitbanger_control_populate(machine, menu, (bitbanger_control_menu_state*)state);
1354   reset(UI_MENU_RESET_REMEMBER_POSITION);
1355   populate();
14991356
15001357   /* process the menu */
1501   event = menu->process(UI_MENU_PROCESS_LR_REPEAT);
1358   const ui_menu_event *event = process(UI_MENU_PROCESS_LR_REPEAT);
15021359   if (event != NULL)
15031360   {
15041361      switch(event->iptkey)
r13553r13554
15071364            if (event->itemref==BITBANGERCMD_SELECT)
15081365            {
15091366               /* left arrow - rotate left through cassette devices */
1510               if (menustate->index > 0)
1511                  menustate->index--;
1367               if (index > 0)
1368                  index--;
15121369               else
1513                  menustate->index = bitbanger_count(machine) - 1;
1514               menustate->device = NULL;
1370                  index = bitbanger_count() - 1;
1371               device = NULL;
15151372            }
15161373            else if (event->itemref==BITBANGERCMD_MODE)
15171374            {
r13553r13554
15311388            if (event->itemref==BITBANGERCMD_SELECT)
15321389            {
15331390               /* right arrow - rotate right through cassette devices */
1534               if (menustate->index < bitbanger_count(machine) - 1)
1535                  menustate->index++;
1391               if (index < bitbanger_count() - 1)
1392                  index++;
15361393               else
1537                  menustate->index = 0;
1538               menustate->device = NULL;
1394                  index = 0;
1395               device = NULL;
15391396            }
15401397            else if (event->itemref==BITBANGERCMD_MODE)
15411398            {
src/emu/uiimage.h
r13553r13554
1414#ifndef __UIIMAGE_H__
1515#define __UIIMAGE_H__
1616
17class ui_menu_image_info : public ui_menu {
18public:
19   ui_menu_image_info(running_machine &machine, render_container *container);
20   virtual ~ui_menu_image_info();
21   virtual void populate();
22   virtual void handle();
23};
1724
25class ui_menu_file_manager : public ui_menu {
26public:
27   astring *current_directory;
28   astring *current_file;
29   device_image_interface *selected_device;
1830
19/***************************************************************************
20    FUNCTION PROTOTYPES
21***************************************************************************/
31   ui_menu_file_manager(running_machine &machine, render_container *container);
32   virtual ~ui_menu_file_manager();
33   virtual void populate();
34   virtual void handle();
35   virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
2236
23void ui_image_menu_file_manager(running_machine &machine, ui_menu *menu, void *parameter, void *state);
37private:
38   void fix_working_directory(device_image_interface *image);
39};
2440
25void ui_image_menu_image_info(running_machine &machine, ui_menu *menu, void *parameter, void *state);
41class ui_menu_mess_tape_control : public ui_menu {
42public:
43   ui_menu_mess_tape_control(running_machine &machine, render_container *container);
44   virtual ~ui_menu_mess_tape_control();
45   virtual void populate();
46   virtual void handle();
2647
27void ui_mess_menu_bitbanger_control(running_machine &machine, ui_menu *menu, void *parameter, void *state);
48private:
49   int index;
50   device_image_interface *device;
51   int cassette_count();
52};
2853
29void ui_mess_menu_tape_control(running_machine &machine, ui_menu *menu, void *parameter, void *state);
54class ui_menu_mess_bitbanger_control : public ui_menu {
55public:
56   ui_menu_mess_bitbanger_control(running_machine &machine, render_container *container);
57   virtual ~ui_menu_mess_bitbanger_control();
58   virtual void populate();
59   virtual void handle();
3060
61private:
62   int index;
63   device_image_interface *device;
64   int bitbanger_count();
65};
66
67class ui_menu_confirm_save_as : public ui_menu {
68public:
69   ui_menu_confirm_save_as(running_machine &machine, render_container *container, int *yes);
70   virtual ~ui_menu_confirm_save_as();
71   virtual void populate();
72   virtual void handle();
73
74private:
75   int *yes;
76};
77
78class ui_menu_file_create : public ui_menu {
79public:
80   ui_menu_file_create(running_machine &machine, render_container *container, ui_menu_file_manager *parent);
81   virtual ~ui_menu_file_create();
82   virtual void populate();
83   virtual void handle();
84   virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
85
86private:
87   ui_menu_file_manager *manager;
88   const image_device_format *current_format;
89   int confirm_save_as_yes;
90   char filename_buffer[1024];
91
92   int create_new_image(device_image_interface *image, const char *directory, const char *filename, int *yes);
93};
94
95class ui_menu_file_selector : public ui_menu {
96public:
97   ui_menu_file_selector(running_machine &machine, render_container *container, ui_menu_file_manager *parent);
98   virtual ~ui_menu_file_selector();
99   virtual void populate();
100   virtual void handle();
101   virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
102
103private:
104   enum file_selector_entry_type {
105      SELECTOR_ENTRY_TYPE_EMPTY,
106      SELECTOR_ENTRY_TYPE_CREATE,
107      SELECTOR_ENTRY_TYPE_SOFTWARE_LIST,
108      SELECTOR_ENTRY_TYPE_DRIVE,
109      SELECTOR_ENTRY_TYPE_DIRECTORY,
110      SELECTOR_ENTRY_TYPE_FILE
111   };
112
113   struct file_selector_entry {
114      file_selector_entry *next;
115
116      file_selector_entry_type type;
117      const char *basename;
118      const char *fullpath;
119   };
120
121   ui_menu_file_manager *manager;
122   file_selector_entry *entrylist;
123   char filename_buffer[1024];
124
125   int compare_entries(const file_selector_entry *e1, const file_selector_entry *e2);
126   file_selector_entry *append_entry(file_selector_entry_type entry_type, const char *entry_basename, const char *entry_fullpath);
127   file_selector_entry *append_dirent_entry(const osd_directory_entry *dirent);
128   void append_entry_menu_item(const file_selector_entry *entry);
129};
130
31131#endif   /* __UIIMAGE_H__ */
src/emu/uimain.c
r13553r13554
1818#include "uiimage.h"
1919#include "uiinput.h"
2020#include "uimenu.h"
21#include "uimain.h"
2122#include "audit.h"
2223#include "crsshair.h"
2324#include <ctype.h>
r13553r13554
3031    CONSTANTS
3132***************************************************************************/
3233
33#define VISIBLE_GAMES_IN_LIST   15
34
3534#define MAX_PHYSICAL_DIPS      10
3635#define MAX_INPUT_PORTS         32
3736#define MAX_BITS_PER_PORT      32
r13553r13554
4544#define PERCENTAGE_OF_HALF_FIELD_USED 0.80f
4645#define SINGLE_TOGGLE_SWITCH_HEIGHT ((DIP_SWITCH_HEIGHT / 2) * PERCENTAGE_OF_HALF_FIELD_USED)
4746
47/*-------------------------------------------------
48    ui_slider_ui_handler - pushes the slider
49    menu on the stack and hands off to the
50    standard menu handler
51-------------------------------------------------*/
4852
49enum
53UINT32 ui_menu_sliders::ui_handler(running_machine &machine, render_container *container, UINT32 state)
5054{
51   INPUT_TYPE_DIGITAL = 0,
52   INPUT_TYPE_ANALOG = 1,
53   INPUT_TYPE_ANALOG_DEC = INPUT_TYPE_ANALOG + SEQ_TYPE_DECREMENT,
54   INPUT_TYPE_ANALOG_INC = INPUT_TYPE_ANALOG + SEQ_TYPE_INCREMENT,
55   INPUT_TYPE_TOTAL = INPUT_TYPE_ANALOG + SEQ_TYPE_TOTAL
56};
55   UINT32 result;
5756
58enum
59{
60   ANALOG_ITEM_KEYSPEED = 0,
61   ANALOG_ITEM_CENTERSPEED,
62   ANALOG_ITEM_REVERSE,
63   ANALOG_ITEM_SENSITIVITY,
64   ANALOG_ITEM_COUNT
65};
57   /* if this is the first call, push the sliders menu */
58   if (state)
59      ui_menu::stack_push(auto_alloc_clear(machine, ui_menu_sliders(machine, container, true)));
6660
67enum
68{
69   MEMCARD_ITEM_SELECT = 1,
70   MEMCARD_ITEM_LOAD,
71   MEMCARD_ITEM_EJECT,
72   MEMCARD_ITEM_CREATE
73};
61   /* handle standard menus */
62   result = ui_menu::ui_handler(machine, container, state);
7463
75enum
76{
77   VIDEO_ITEM_ROTATE = 0x80000000,
78   VIDEO_ITEM_BACKDROPS,
79   VIDEO_ITEM_OVERLAYS,
80   VIDEO_ITEM_BEZELS,
81   VIDEO_ITEM_CPANELS,
82   VIDEO_ITEM_MARQUEES,
83   VIDEO_ITEM_ZOOM,
84   VIDEO_ITEM_VIEW
85};
64   /* if we are cancelled, pop the sliders menu */
65   if (result == UI_HANDLER_CANCEL)
66      ui_menu::stack_pop(machine);
8667
68   ui_menu_sliders *uim = dynamic_cast<ui_menu_sliders *>(menu_stack);
69   return uim && uim->menuless_mode ? 0 : UI_HANDLER_CANCEL;
70}
8771
88enum
89{
90   CROSSHAIR_ITEM_VIS = 0,
91   CROSSHAIR_ITEM_PIC,
92   CROSSHAIR_ITEM_AUTO_TIME
93};
9472
73/*-------------------------------------------------
74    ui_menu_force_game_select - force the game
75    select menu to be visible and inescapable
76-------------------------------------------------*/
9577
96/***************************************************************************
97    TYPE DEFINITIONS
98***************************************************************************/
78void ui_menu_force_game_select(running_machine &machine, render_container *container)
79{
80   char *gamename = (char *)machine.options().system_name();
9981
82   /* reset the menu stack */
83   ui_menu::stack_reset(machine);
10084
85   /* add the quit entry followed by the game select entry */
86   ui_menu *quit = auto_alloc_clear(machine, ui_menu_quit_game(machine, container));
87   quit->set_special_main_menu(true);
88   ui_menu::stack_push(quit);
89   ui_menu::stack_push(auto_alloc_clear(machine, ui_menu_select_game(machine, container, gamename)));
10190
102/* internal input menu item data */
103struct input_item_data
104{
105   input_item_data *   next;            /* pointer to next item in the list */
106   const void *      ref;            /* reference to type description for global inputs or field for game inputs */
107   input_seq_type      seqtype;         /* sequence type */
108   input_seq         seq;            /* copy of the live sequence */
109   const input_seq *   defseq;            /* pointer to the default sequence */
110   const char *      name;            /* pointer to the base name of the item */
111   UINT16            sortorder;         /* sorting information */
112   UINT8            type;            /* type of port */
113};
91   /* force the menus on */
92   ui_show_menu();
11493
94   /* make sure MAME is paused */
95   machine.pause();
96}
11597
116/* internal analog menu item data */
117struct analog_item_data
118{
119   input_field_config *field;
120   int               type;
121   int               min, max;
122   int               cur;
123   int             defvalue;
124};
12598
99/***************************************************************************
100    MENU HANDLERS
101***************************************************************************/
126102
127/* DIP switch descriptor */
128struct dip_descriptor
103/*-------------------------------------------------
104    ui_menu_main constructor - populate the main menu
105-------------------------------------------------*/
106
107ui_menu_main::ui_menu_main(running_machine &machine, render_container *container) : ui_menu(machine, container)
129108{
130   dip_descriptor *   next;
131   const char *      name;
132   UINT32            mask;
133   UINT32            state;
134};
109}
135110
136
137/* extended settings menu state */
138struct settings_menu_state
111void ui_menu_main::populate()
139112{
140   dip_descriptor *   diplist;
141};
113   input_field_config *field;
114   input_port_config *port;
115   int has_configs = false;
116   int has_analog = false;
117   int has_dips = false;
118   astring menu_text;
119   /* scan the input port array to see what options we need to enable */
120   for (port = machine().m_portlist.first(); port != NULL; port = port->next())
121      for (field = port->fieldlist().first(); field != NULL; field = field->next())
122      {
123         if (field->type == IPT_DIPSWITCH)
124            has_dips = true;
125         if (field->type == IPT_CONFIG)
126            has_configs = true;
127         if (input_type_is_analog(field->type))
128            has_analog = true;
129      }
142130
131   /* add input menu items */
132   item_append("Input (general)", NULL, 0, (void *)INPUT_GROUPS);   
133   
134   menu_text.printf("Input (this %s)",emulator_info::get_capstartgamenoun());
135   item_append(menu_text.cstr(), NULL, 0, (void *)INPUT_SPECIFIC);
143136
144/* extended input menu state */
145struct input_menu_state
146{
147   UINT16            last_sortorder;
148   const void *      pollingref;
149   input_item_data *   pollingitem;
150   UINT8            record_next;
151   input_seq         starting_seq;
152};
137   /* add optional input-related menus */
138   if (has_dips)
139      item_append("Dip Switches", NULL, 0, (void *)SETTINGS_DIP_SWITCHES);
140   if (has_configs)
141      item_append("Driver Configuration", NULL, 0, (void *)SETTINGS_DRIVER_CONFIG);
142   if (has_analog)
143      item_append("Analog Controls", NULL, 0, (void *)ANALOG);
153144
145   /* add bookkeeping menu */
146   item_append("Bookkeeping Info", NULL, 0, (void *)BOOKKEEPING);
154147
155/* extended select game menu state */
156struct select_game_state
157{
158   UINT8            error;
159   UINT8            rerandomize;
160   char            search[40];
161   int               matchlist[VISIBLE_GAMES_IN_LIST];
162   const game_driver *   driverlist[1];
163};
148   /* add game info menu */
149   menu_text.printf("%s Information",emulator_info::get_capstartgamenoun());
150   item_append(menu_text.cstr(), NULL, 0, (void *)GAME_INFO);
164151
152   device_image_interface *image = NULL;
153   if (machine().devicelist().first(image))
154   {
155      /* add image info menu */
156      item_append("Image Information", NULL, 0, (void *)IMAGE_MENU_IMAGE_INFO);
165157
166/* internal crosshair menu item data */
167struct crosshair_item_data
168{
169   UINT8            type;
170   UINT8            player;
171   UINT8            min, max;
172   UINT8            cur;
173   UINT8            defvalue;
174   char            last_name[CROSSHAIR_PIC_NAME_LENGTH + 1];
175   char            next_name[CROSSHAIR_PIC_NAME_LENGTH + 1];
176};
158      /* add file manager menu */
159      item_append("File Manager", NULL, 0, (void *)IMAGE_MENU_FILE_MANAGER);
177160
161      /* add tape control menu */
162      if (machine().devicelist().first(CASSETTE))
163         item_append("Tape Control", NULL, 0, (void *)MESS_MENU_TAPE_CONTROL);
178164
165      /* add bitbanger control menu */
166      if (machine().devicelist().first(BITBANGER))
167         item_append("Bitbanger Control", NULL, 0, (void *)MESS_MENU_BITBANGER_CONTROL);
168   }
179169
180/***************************************************************************
181    GLOBAL VARIABLES
182***************************************************************************/
170   device_slot_interface *slot = NULL;
171   if (machine().devicelist().first(slot))
172   {
173      /* add image info menu */
174      item_append("Slot Devices", NULL, 0, (void *)SLOT_DEVICES);
175   }
183176
184// temporary hack until this is C++-ified
185static driver_enumerator *drivlist;
177   device_network_interface *network = NULL;
178   if (machine().devicelist().first(network))
179   {
180      /* add image info menu */
181      item_append("Network Devices", NULL, 0, (void*)NETWORK_DEVICES);
182   }
186183
187/***************************************************************************
188    FUNCTION PROTOTYPES
189***************************************************************************/
184   /* add keyboard mode menu */
185   if (input_machine_has_keyboard(machine()) && inputx_can_post(machine()))
186      item_append("Keyboard Mode", NULL, 0, (void *)KEYBOARD_MODE);
190187
191/* menu handlers */
192static void menu_main_populate(running_machine &machine, ui_menu *menu, void *state);
193static void menu_input_groups(running_machine &machine, ui_menu *menu, void *parameter, void *state);
194static void menu_input_groups_populate(running_machine &machine, ui_menu *menu, void *state);
195static void menu_input_general(running_machine &machine, ui_menu *menu, void *parameter, void *state);
196static void menu_input_general_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate, int group);
197static void menu_input_specific(running_machine &machine, ui_menu *menu, void *parameter, void *state);
198static void menu_input_specific_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate);
199static void menu_input_common(running_machine &machine, ui_menu *menu, void *parameter, void *state);
200static int CLIB_DECL menu_input_compare_items(const void *i1, const void *i2);
201static void menu_input_populate_and_sort(running_machine &machine, ui_menu *menu, input_item_data *itemlist, input_menu_state *menustate);
202static void menu_settings_dip_switches(running_machine &machine, ui_menu *menu, void *parameter, void *state);
203static void menu_settings_driver_config(running_machine &machine, ui_menu *menu, void *parameter, void *state);
204static void menu_settings_common(running_machine &machine, ui_menu *menu, void *state, UINT32 type);
205static void menu_settings_populate(running_machine &machine, ui_menu *menu, settings_menu_state *menustate, UINT32 type);
206static void menu_analog(running_machine &machine, ui_menu *menu, void *parameter, void *state);
207static void menu_analog_populate(running_machine &machine, ui_menu *menu);
208static void menu_bookkeeping(running_machine &machine, ui_menu *menu, void *parameter, void *state);
209static void menu_bookkeeping_populate(running_machine &machine, ui_menu *menu, attotime *curtime);
210static void menu_game_info(running_machine &machine, ui_menu *menu, void *parameter, void *state);
211static void menu_cheat(running_machine &machine, ui_menu *menu, void *parameter, void *state);
212static void menu_cheat_populate(running_machine &machine, ui_menu *menu);
213static void menu_memory_card(running_machine &machine, ui_menu *menu, void *parameter, void *state);
214static void menu_memory_card_populate(running_machine &machine, ui_menu *menu, int cardnum);
215static void menu_sliders(running_machine &machine, ui_menu *menu, void *parameter, void *state);
216static void menu_sliders_populate(running_machine &machine, ui_menu *menu, int menuless_mode);
217static void menu_sliders_custom_render(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom, float x1, float y1, float x2, float y2);
218static void menu_video_targets(running_machine &machine, ui_menu *menu, void *parameter, void *state);
219static void menu_video_targets_populate(running_machine &machine, ui_menu *menu);
220static void menu_video_options(running_machine &machine, ui_menu *menu, void *parameter, void *state);
221static void menu_video_options_populate(running_machine &machine, ui_menu *menu, render_target *target);
222static void menu_crosshair(running_machine &machine, ui_menu *menu, void *parameter, void *state);
223static void menu_crosshair_populate(running_machine &machine, ui_menu *menu);
224static void menu_quit_game(running_machine &machine, ui_menu *menu, void *parameter, void *state);
225static void menu_select_game(running_machine &machine, ui_menu *menu, void *parameter, void *state);
226static void menu_select_game_populate(running_machine &machine, ui_menu *menu, select_game_state *menustate);
227static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state *menustate);
228static void menu_select_game_custom_render(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
188   /* add sliders menu */
189   item_append("Slider Controls", NULL, 0, (void *)SLIDERS);
229190
230/* menu helpers */
231static void menu_settings_custom_render_one(render_container *container, float x1, float y1, float x2, float y2, const dip_descriptor *dip, UINT32 selectedmask);
232static void menu_settings_custom_render(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
191   /* add video options menu */
192   item_append("Video Options", NULL, 0, (machine().render().target_by_index(1) != NULL) ? (void *)VIDEO_TARGETS : (void *)VIDEO_OPTIONS);
233193
194   /* add crosshair options menu */
195   if (crosshair_get_usage(machine()))
196      item_append("Crosshair Options", NULL, 0, (void *)CROSSHAIR);
234197
198   /* add cheat menu */
199   if (machine().options().cheat() && machine().cheat().first() != NULL)
200      item_append("Cheat", NULL, 0, (void *)CHEAT);
235201
236/***************************************************************************
237    INLINE FUNCTIONS
238***************************************************************************/
202   /* add memory card menu */
203   if (machine().config().m_memcard_handler != NULL)
204      item_append("Memory Card", NULL, 0, (void *)MEMORY_CARD);
239205
240/*-------------------------------------------------
241    get_field_default_seq - return a pointer
242    to the default sequence for the given field
243-------------------------------------------------*/
206   /* add reset and exit menus */
207   menu_text.printf("Select New %s",emulator_info::get_capstartgamenoun());
208   item_append(menu_text.cstr(), NULL, 0, (void *)SELECT_GAME);
209}
244210
245INLINE const input_seq &get_field_default_seq(input_field_config *field, input_seq_type seqtype)
211ui_menu_main::~ui_menu_main()
246212{
247   if (field->seq[seqtype].is_default())
248      return input_type_seq(field->machine(), field->type, field->player, seqtype);
249   else
250      return field->seq[seqtype];
251213}
252214
253
254215/*-------------------------------------------------
255    toggle_none_default - toggle between "NONE"
256    and the default item
216    menu_main - handle the main menu
257217-------------------------------------------------*/
258218
259INLINE void toggle_none_default(input_seq &selected_seq, input_seq &original_seq, const input_seq &selected_defseq)
219void ui_menu_main::handle()
260220{
261   /* if we used to be "none", toggle to the default value */
262   if (original_seq.length() == 0)
263      selected_seq = selected_defseq;
221   /* process the menu */
222   const ui_menu_event *menu_event = process(0);
223   if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT) {
224      switch((long long)(menu_event->itemref)) {
225      case INPUT_GROUPS:
226         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_input_groups(machine(), container)));
227         break;
264228
265   /* otherwise, toggle to "none" */
266   else
267      selected_seq.reset();
268}
229      case INPUT_SPECIFIC:
230         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_input_specific(machine(), container)));
231         break;
269232
233      case SETTINGS_DIP_SWITCHES:
234         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_settings_dip_switches(machine(), container)));
235         break;
270236
271/*-------------------------------------------------
272    ui_slider_ui_handler - pushes the slider
273    menu on the stack and hands off to the
274    standard menu handler
275-------------------------------------------------*/
237      case SETTINGS_DRIVER_CONFIG:
238         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_settings_driver_config(machine(), container)));
239         break;
276240
277UINT32 ui_slider_ui_handler(running_machine &machine, render_container *container, UINT32 state)
278{
279   UINT32 result;
241      case ANALOG:
242         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_analog(machine(), container)));
243         break;
280244
281   /* if this is the first call, push the sliders menu */
282   if (state)
283      ui_menu::stack_push(ui_menu_alloc(machine, container, menu_sliders, (void *)1));
245      case BOOKKEEPING:
246         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_bookkeeping(machine(), container)));
247         break;
284248
285   /* handle standard menus */
286   result = ui_menu::ui_handler(machine, container, state);
249      case GAME_INFO:
250         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_game_info(machine(), container)));
251         break;
287252
288   /* if we are cancelled, pop the sliders menu */
289   if (result == UI_HANDLER_CANCEL)
290      ui_menu::stack_pop(machine);
253      case IMAGE_MENU_IMAGE_INFO:
254         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_image_info(machine(), container)));
255         break;
291256
292   return (ui_menu::menu_stack != NULL && ui_menu::menu_stack->handler == menu_sliders && ui_menu::menu_stack->parameter != NULL) ? 0 : UI_HANDLER_CANCEL;
293}
257      case IMAGE_MENU_FILE_MANAGER:
258         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_manager(machine(), container)));
259         break;
294260
261      case MESS_MENU_TAPE_CONTROL:
262         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_mess_tape_control(machine(), container)));
263         break;
295264
296/*-------------------------------------------------
297    ui_menu_force_game_select - force the game
298    select menu to be visible and inescapable
299-------------------------------------------------*/
265      case MESS_MENU_BITBANGER_CONTROL:
266         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_mess_bitbanger_control(machine(), container)));
267         break;
300268
301void ui_menu_force_game_select(running_machine &machine, render_container *container)
302{
303   char *gamename = (char *)machine.options().system_name();
269      case SLOT_DEVICES:
270         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_slot_devices(machine(), container)));
271         break;
304272
305   /* reset the menu stack */
306   ui_menu::stack_reset(machine);
273      case NETWORK_DEVICES:
274         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_network_devices(machine(), container)));
275         break;
307276
308   /* add the quit entry followed by the game select entry */
309   ui_menu *quit = ui_menu_alloc(machine, container, menu_quit_game, NULL);
310   quit->set_special_main_menu(true);
311   ui_menu::stack_push(quit);
312   ui_menu::stack_push(ui_menu_alloc(machine, container, menu_select_game, gamename));
277      case KEYBOARD_MODE:
278         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_keyboard_mode(machine(), container)));
279         break;
313280
314   /* force the menus on */
315   ui_show_menu();
281      case SLIDERS:
282         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_sliders(machine(), container, false)));
283         break;
316284
317   /* make sure MAME is paused */
318   machine.pause();
319}
285      case VIDEO_TARGETS:
286         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_video_targets(machine(), container)));
287         break;
320288
289      case VIDEO_OPTIONS:
290         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_video_options(machine(), container, machine().render().first_target())));
291         break;
321292
322/***************************************************************************
323    MENU HANDLERS
324***************************************************************************/
293      case CROSSHAIR:
294         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_crosshair(machine(), container)));
295         break;
325296
326/*-------------------------------------------------
327    menu_main - handle the main menu
328-------------------------------------------------*/
297      case CHEAT:
298         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_cheat(machine(), container)));
299         break;
329300
330void menu_main(running_machine &machine, ui_menu *menu, void *parameter, void *state)
331{
332   const ui_menu_event *menu_event;
301      case MEMORY_CARD:
302         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_memory_card(machine(), container)));
303         break;
333304
334   /* if the menu isn't built, populate now */
335   if (!menu->populated())
336      menu_main_populate(machine, menu, state);
305      case SELECT_GAME:
306         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_select_game(machine(), container, 0)));
307         break;
337308
338   /* process the menu */
339   menu_event = menu->process(0);
340   if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT)
341      ui_menu::stack_push(ui_menu_alloc(machine, menu->container, (ui_menu_handler_func)menu_event->itemref, NULL));
309      default:
310         abort();
311      }
312   }
342313}
343314
344315
r13553r13554
346317    ui_menu_keyboard_mode - menu that
347318-------------------------------------------------*/
348319
349static void ui_menu_keyboard_mode(running_machine &machine, ui_menu *menu, void *parameter, void *state)
320ui_menu_keyboard_mode::ui_menu_keyboard_mode(running_machine &machine, render_container *container) : ui_menu(machine, container)
350321{
351   const ui_menu_event *menu_event;
352   int natural = ui_get_use_natural_keyboard(machine);
322}
353323
354   /* if the menu isn't built, populate now */
355   if (!menu->populated())
356   {
357      menu->item_append("Keyboard Mode:", natural ? "Natural" : "Emulated", natural ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, NULL);
358   }
324void ui_menu_keyboard_mode::populate()
325{
326   int natural = ui_get_use_natural_keyboard(machine());
327   item_append("Keyboard Mode:", natural ? "Natural" : "Emulated", natural ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, NULL);
328}
359329
330ui_menu_keyboard_mode::~ui_menu_keyboard_mode()
331{
332}
333
334void ui_menu_keyboard_mode::handle()
335{
336   int natural = ui_get_use_natural_keyboard(machine());
337
360338   /* process the menu */
361   menu_event = menu->process(0);
339   const ui_menu_event *menu_event = process(0);
362340
363341   if (menu_event != NULL)
364342   {
365343      if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) {
366         ui_set_use_natural_keyboard(machine, natural ^ TRUE);
367         menu->reset(UI_MENU_RESET_REMEMBER_REF);
344         ui_set_use_natural_keyboard(machine(), natural ^ true);
345         reset(UI_MENU_RESET_REMEMBER_REF);
368346      }
369347   }
370348}
r13553r13554
373351/*-------------------------------------------------
374352    ui_slot_get_current_index - returns
375353-------------------------------------------------*/
376int ui_slot_get_current_index(running_machine &machine, device_slot_interface *slot)
354int ui_menu_slot_devices::slot_get_current_index(device_slot_interface *slot)
377355{
378   const char *current = machine.options().value(slot->device().tag());
356   const char *current = machine().options().value(slot->device().tag());
379357   const slot_interface* intf = slot->get_slot_interfaces();
380358   int val = -1;
381359   for (int i = 0; intf[i].name != NULL; i++) {
r13553r13554
387365/*-------------------------------------------------
388366    ui_slot_get_length - returns
389367-------------------------------------------------*/
390int ui_slot_get_length(running_machine &machine, device_slot_interface *slot)
368int ui_menu_slot_devices::slot_get_length(device_slot_interface *slot)
391369{
392370   const slot_interface* intf = slot->get_slot_interfaces();
393371   int val = 0;
r13553r13554
398376/*-------------------------------------------------
399377    ui_slot_get_next - returns
400378-------------------------------------------------*/
401const char *ui_slot_get_next(running_machine &machine, device_slot_interface *slot)
379const char *ui_menu_slot_devices::slot_get_next(device_slot_interface *slot)
402380{
403   int idx = ui_slot_get_current_index(machine, slot) + 1;
404   if (idx==ui_slot_get_length(machine,slot)) return "";
381   int idx = slot_get_current_index(slot) + 1;
382   if (idx==slot_get_length(slot)) return "";
405383   return slot->get_slot_interfaces()[idx].name;
406384}
407385
408386/*-------------------------------------------------
409387    ui_slot_get_prev - returns
410388-------------------------------------------------*/
411const char *ui_slot_get_prev(running_machine &machine, device_slot_interface *slot)
389const char *ui_menu_slot_devices::slot_get_prev(device_slot_interface *slot)
412390{
413   int idx = ui_slot_get_current_index(machine, slot) - 1;
391   int idx = slot_get_current_index(slot) - 1;
414392   if (idx==-1) return "";
415   if (idx==-2) idx = ui_slot_get_length(machine,slot) -1;
393   if (idx==-2) idx = slot_get_length(slot) -1;
416394   if (idx==-1) return "";
417395   return slot->get_slot_interfaces()[idx].name;
418396}
r13553r13554
420398/*-------------------------------------------------
421399    ui_get_slot_device - returns
422400-------------------------------------------------*/
423const char *ui_get_slot_device(running_machine &machine, device_slot_interface *slot)
401const char *ui_menu_slot_devices::get_slot_device(device_slot_interface *slot)
424402{
425   return machine.options().value(slot->device().tag());
403   return machine().options().value(slot->device().tag());
426404}
427405
428406
r13553r13554
431409    whether the natural keyboard is active
432410-------------------------------------------------*/
433411
434void ui_set_slot_device(running_machine &machine, device_slot_interface *slot, const char *val)
412void ui_menu_slot_devices::set_slot_device(device_slot_interface *slot, const char *val)
435413{
436414   astring error;
437   machine.options().set_value(slot->device().tag(), val, OPTION_PRIORITY_CMDLINE, error);
415   machine().options().set_value(slot->device().tag(), val, OPTION_PRIORITY_CMDLINE, error);
438416   assert(!error);
439417}
440418
r13553r13554
443421    slot device menu
444422-------------------------------------------------*/
445423
446static void menu_slot_devices_populate(running_machine &machine, ui_menu *menu, void *state)
424ui_menu_slot_devices::ui_menu_slot_devices(running_machine &machine, render_container *container) : ui_menu(machine, container)
447425{
426}
427
428void ui_menu_slot_devices::populate()
429{
448430   device_slot_interface *slot = NULL;
449431
450432   /* cycle through all devices for this system */
451   for (bool gotone = machine.devicelist().first(slot); gotone; gotone = slot->next(slot))
433   for (bool gotone = machine().devicelist().first(slot); gotone; gotone = slot->next(slot))
452434   {
453435      /* record the menu item */
454      const char *title = ui_get_slot_device(machine,slot);
455      menu->item_append(slot->device().tag(),  strcmp(title,"")==0 ? "------" : title, MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW, (void *)slot);
436      const char *title = get_slot_device(slot);
437      item_append(slot->device().tag(), strcmp(title,"")==0 ? "------" : title, MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW, (void *)slot);
456438   }
457   menu->item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL);
458   menu->item_append("Reset",  NULL, 0, NULL);
439   item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL);
440   item_append("Reset",  NULL, 0, NULL);
459441}
460442
443ui_menu_slot_devices::~ui_menu_slot_devices()
444{
445}
446
461447/*-------------------------------------------------
462448    ui_menu_slot_devices - menu that
463449-------------------------------------------------*/
464450
465static void ui_menu_slot_devices(running_machine &machine, ui_menu *menu, void *parameter, void *state)
451void ui_menu_slot_devices::handle()
466452{
467   const ui_menu_event *menu_event;
468
469   /* if the menu isn't built, populate now */
470   if (!menu->populated())
471   {
472      menu_slot_devices_populate(machine, menu, state);
473   }
474
475453   /* process the menu */
476   menu_event = menu->process(0);
454   const ui_menu_event *menu_event = process(0);
477455
478456   if (menu_event != NULL && menu_event->itemref != NULL)
479457   {
480458      if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) {
481459         device_slot_interface *slot = (device_slot_interface *)menu_event->itemref;
482         const char *val = (menu_event->iptkey == IPT_UI_LEFT) ? ui_slot_get_prev(machine,slot) : ui_slot_get_next(machine,slot);
483         ui_set_slot_device(machine,slot,val);
484         menu->reset(UI_MENU_RESET_REMEMBER_REF);
460         const char *val = (menu_event->iptkey == IPT_UI_LEFT) ? slot_get_prev(slot) : slot_get_next(slot);
461         set_slot_device(slot,val);
462         reset(UI_MENU_RESET_REMEMBER_REF);
485463      }
486464   } else if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT) {
487      machine.schedule_hard_reset();
465      machine().schedule_hard_reset();
488466   }
489467}
490468
469ui_menu_network_devices::ui_menu_network_devices(running_machine &machine, render_container *container) : ui_menu(machine, container)
470{
471}
491472
473ui_menu_network_devices::~ui_menu_network_devices()
474{
475}
476
492477/*-------------------------------------------------
493478    menu_network_devices_populate - populates the main
494479    network device menu
495480-------------------------------------------------*/
496481
497static void menu_network_devices_populate(running_machine &machine, ui_menu *menu, void *state)
482void ui_menu_network_devices::populate()
498483{
499484   device_network_interface *network = NULL;
500485
501486   /* cycle through all devices for this system */
502   for (bool gotone = machine.devicelist().first(network); gotone; gotone = network->next(network))
487   for (bool gotone = machine().devicelist().first(network); gotone; gotone = network->next(network))
503488   {
504489      int curr = network->get_interface();
505490      const char *title = NULL;
r13553r13554
512497         entry = entry->m_next;
513498      }
514499     
515      menu->item_append(network->device().tag(),  (title) ? title : "------", MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW, (void *)network);     
500      item_append(network->device().tag(),  (title) ? title : "------", MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW, (void *)network);     
516501   }
517502}
518503
r13553r13554
520505    ui_menu_network_devices - menu that
521506-------------------------------------------------*/
522507
523static void ui_menu_network_devices(running_machine &machine, ui_menu *menu, void *parameter, void *state)
508void ui_menu_network_devices::handle()
524509{
525   const ui_menu_event *menu_event;
526
527   /* if the menu isn't built, populate now */
528   if (!menu->populated())
529   {
530      menu_network_devices_populate(machine, menu, state);
531   }
532
533510   /* process the menu */
534   menu_event = menu->process(0);
511   const ui_menu_event *menu_event = process(0);
535512
536513   if (menu_event != NULL && menu_event->itemref != NULL)
537514   {
r13553r13554
541518         if (menu_event->iptkey == IPT_UI_LEFT) curr--; else curr++;
542519         if (curr==-2) curr = netdev_count() - 1;
543520         network->set_interface(curr);
544         menu->reset(UI_MENU_RESET_REMEMBER_REF);
521         reset(UI_MENU_RESET_REMEMBER_REF);
545522      }
546523   }
547524}
548525
549526/*-------------------------------------------------
550    menu_main_populate - populate the main menu
527    menu_input_groups_populate - populate the
528    input groups menu
551529-------------------------------------------------*/
552530
553static void menu_main_populate(running_machine &machine, ui_menu *menu, void *state)
531ui_menu_input_groups::ui_menu_input_groups(running_machine &machine, render_container *container) : ui_menu(machine, container)
554532{
555   input_field_config *field;
556   input_port_config *port;
557   int has_configs = FALSE;
558   int has_analog = FALSE;
559   int has_dips = FALSE;
560   astring menu_text;
561   /* scan the input port array to see what options we need to enable */
562   for (port = machine.m_portlist.first(); port != NULL; port = port->next())
563      for (field = port->fieldlist().first(); field != NULL; field = field->next())
564      {
565         if (field->type == IPT_DIPSWITCH)
566            has_dips = TRUE;
567         if (field->type == IPT_CONFIG)
568            has_configs = TRUE;
569         if (input_type_is_analog(field->type))
570            has_analog = TRUE;
571      }
533}
572534
573   /* add input menu items */
574   menu->item_append("Input (general)", NULL, 0, (void *)menu_input_groups);
535void ui_menu_input_groups::populate()
536{
537   int player;
575538
576   menu_text.printf("Input (this %s)",emulator_info::get_capstartgamenoun());
577   menu->item_append(menu_text.cstr(), NULL, 0, (void *)menu_input_specific);
578
579   /* add optional input-related menus */
580   if (has_dips)
581      menu->item_append("Dip Switches", NULL, 0, (void *)menu_settings_dip_switches);
582   if (has_configs)
583      menu->item_append("Driver Configuration", NULL, 0, (void *)menu_settings_driver_config);
584   if (has_analog)
585      menu->item_append("Analog Controls", NULL, 0, (void *)menu_analog);
586
587   /* add bookkeeping menu */
588   menu->item_append("Bookkeeping Info", NULL, 0, (void *)menu_bookkeeping);
589
590   /* add game info menu */
591   menu_text.printf("%s Information",emulator_info::get_capstartgamenoun());
592   menu->item_append(menu_text.cstr(), NULL, 0, (void *)menu_game_info);
593
594   device_image_interface *image = NULL;
595   if (machine.devicelist().first(image))
539   /* build up the menu */
540   item_append("User Interface", NULL, 0, (void *)(IPG_UI + 1));
541   for (player = 0; player < MAX_PLAYERS; player++)
596542   {
597      /* add image info menu */
598      menu->item_append("Image Information", NULL, 0, (void*)ui_image_menu_image_info);
599
600      /* add file manager menu */
601      menu->item_append("File Manager", NULL, 0, (void*)ui_image_menu_file_manager);
602
603      /* add tape control menu */
604      if (machine.devicelist().first(CASSETTE))
605         menu->item_append("Tape Control", NULL, 0, (void*)ui_mess_menu_tape_control);
606
607      /* add bitbanger control menu */
608      if (machine.devicelist().first(BITBANGER))
609         menu->item_append("Bitbanger Control", NULL, 0, (void*)ui_mess_menu_bitbanger_control);
543      char buffer[40];
544      sprintf(buffer, "Player %d Controls", player + 1);
545      item_append(buffer, NULL, 0, (void *)(FPTR)(IPG_PLAYER1 + player + 1));
610546   }
547   item_append("Other Controls", NULL, 0, (void *)(FPTR)(IPG_OTHER + 1));
548}
611549
612   device_slot_interface *slot = NULL;
613   if (machine.devicelist().first(slot))
614   {
615      /* add image info menu */
616      menu->item_append("Slot Devices", NULL, 0, (void*)ui_menu_slot_devices);
617   }
618
619   device_network_interface *network = NULL;
620   if (machine.devicelist().first(network))
621   {
622      /* add image info menu */
623      menu->item_append("Network Devices", NULL, 0, (void*)ui_menu_network_devices);
624   }
625
626   /* add keyboard mode menu */
627   if (input_machine_has_keyboard(machine) && inputx_can_post(machine))
628      menu->item_append("Keyboard Mode", NULL, 0, (void *)ui_menu_keyboard_mode);
629
630   /* add sliders menu */
631   menu->item_append("Slider Controls", NULL, 0, (void *)menu_sliders);
632
633   /* add video options menu */
634   menu->item_append("Video Options", NULL, 0, (machine.render().target_by_index(1) != NULL) ? (void *)menu_video_targets : (void *)menu_video_options);
635
636   /* add crosshair options menu */
637   if (crosshair_get_usage(machine))
638      menu->item_append("Crosshair Options", NULL, 0, (void *)menu_crosshair);
639
640   /* add cheat menu */
641   if (machine.options().cheat() && machine.cheat().first() != NULL)
642      menu->item_append("Cheat", NULL, 0, (void *)menu_cheat);
643
644   /* add memory card menu */
645   if (machine.config().m_memcard_handler != NULL)
646      menu->item_append("Memory Card", NULL, 0, (void *)menu_memory_card);
647
648   /* add reset and exit menus */
649   menu_text.printf("Select New %s",emulator_info::get_capstartgamenoun());
650   menu->item_append(menu_text.cstr(), NULL, 0, (void *)menu_select_game);
550ui_menu_input_groups::~ui_menu_input_groups()
551{
651552}
652553
653
654554/*-------------------------------------------------
655555    menu_input_groups - handle the input groups
656556    menu
657557-------------------------------------------------*/
658558
659static void menu_input_groups(running_machine &machine, ui_menu *menu, void *parameter, void *state)
559void ui_menu_input_groups::handle()
660560{
661   const ui_menu_event *menu_event;
662
663   /* if the menu isn't built, populate now */
664   if (!menu->populated())
665      menu_input_groups_populate(machine, menu, state);
666
667561   /* process the menu */
668   menu_event = menu->process(0);
562   const ui_menu_event *menu_event = process(0);
669563   if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT)
670      ui_menu::stack_push(ui_menu_alloc(machine, menu->container, menu_input_general, menu_event->itemref));
564      ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_input_general(machine(), container, int((long long)(menu_event->itemref)-1))));
671565}
672566
673567
674/*-------------------------------------------------
675    menu_input_groups_populate - populate the
676    input groups menu
677-------------------------------------------------*/
678568
679static void menu_input_groups_populate(running_machine &machine, ui_menu *menu, void *state)
680{
681   int player;
682
683   /* build up the menu */
684   menu->item_append("User Interface", NULL, 0, (void *)(IPG_UI + 1));
685   for (player = 0; player < MAX_PLAYERS; player++)
686   {
687      char buffer[40];
688      sprintf(buffer, "Player %d Controls", player + 1);
689      menu->item_append(buffer, NULL, 0, (void *)(FPTR)(IPG_PLAYER1 + player + 1));
690   }
691   menu->item_append("Other Controls", NULL, 0, (void *)(FPTR)(IPG_OTHER + 1));
692}
693
694
695
696569/*-------------------------------------------------
697570    menu_input_general - handle the general
698571    input menu
699572-------------------------------------------------*/
700573
701static void menu_input_general(running_machine &machine, ui_menu *menu, void *parameter, void *state)
574ui_menu_input_general::ui_menu_input_general(running_machine &machine, render_container *container, int _group) : ui_menu_input(machine, container)
702575{
703   menu_input_common(machine, menu, parameter, state);
576   group = _group;
704577}
705578
706
707/*-------------------------------------------------
708    menu_input_general_populate - populate the
709    general input menu
710-------------------------------------------------*/
711
712static void menu_input_general_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate, int group)
579void ui_menu_input_general::populate()
713580{
714581   input_item_data *itemlist = NULL;
715582   int suborder[SEQ_TYPE_TOTAL];
r13553r13554
722589   suborder[SEQ_TYPE_INCREMENT] = 2;
723590
724591   /* iterate over the input ports and add menu items */
725   for (input_type_entry *entry = input_type_list(machine).first(); entry != NULL; entry = entry->next())
592   for (input_type_entry *entry = input_type_list(machine()).first(); entry != NULL; entry = entry->next())
726593
727594      /* add if we match the group and we have a valid name */
728595      if (entry->group == group && entry->name != NULL && entry->name[0] != 0)
r13553r13554
734601         for (seqtype = SEQ_TYPE_STANDARD; seqtype < SEQ_TYPE_TOTAL; seqtype++)
735602         {
736603            /* build an entry for the standard sequence */
737            input_item_data *item = (input_item_data *)menu->m_pool_alloc(sizeof(*item));
604            input_item_data *item = (input_item_data *)m_pool_alloc(sizeof(*item));
738605            memset(item, 0, sizeof(*item));
739606            item->ref = entry;
740607            item->seqtype = seqtype;
741            item->seq = input_type_seq(machine, entry->type, entry->player, seqtype);
608            item->seq = input_type_seq(machine(), entry->type, entry->player, seqtype);
742609            item->defseq = &entry->defseq[seqtype];
743610            item->sortorder = sortorder * 4 + suborder[seqtype];
744611            item->type = input_type_is_analog(entry->type) ? (INPUT_TYPE_ANALOG + seqtype) : INPUT_TYPE_DIGITAL;
r13553r13554
753620      }
754621
755622   /* sort and populate the menu in a standard fashion */
756   menu_input_populate_and_sort(machine, menu, itemlist, menustate);
623   populate_and_sort(itemlist);
757624}
758625
626ui_menu_input_general::~ui_menu_input_general()
627{
628}
759629
760630/*-------------------------------------------------
761631    menu_input_specific - handle the game-specific
762632    input menu
763633-------------------------------------------------*/
764634
765static void menu_input_specific(running_machine &machine, ui_menu *menu, void *parameter, void *state)
635ui_menu_input_specific::ui_menu_input_specific(running_machine &machine, render_container *container) : ui_menu_input(machine, container)
766636{
767   menu_input_common(machine, menu, NULL, state);
768637}
769638
770
771/*-------------------------------------------------
772    menu_input_specific_populate - populate
773    the input menu with game-specific items
774-------------------------------------------------*/
775
776static void menu_input_specific_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate)
639void ui_menu_input_specific::populate()
777640{
778641   input_item_data *itemlist = NULL;
779642   input_field_config *field;
r13553r13554
787650   suborder[SEQ_TYPE_INCREMENT] = 2;
788651
789652   /* iterate over the input ports and add menu items */
790   for (port = machine.m_portlist.first(); port != NULL; port = port->next())
653   for (port = machine().m_portlist.first(); port != NULL; port = port->next())
791654      for (field = port->fieldlist().first(); field != NULL; field = field->next())
792655      {
793656         const char *name = input_field_name(field);
794657
795658         /* add if we match the group and we have a valid name */
796         if (name != NULL && input_condition_true(machine, &field->condition, port->owner()) &&
797            ((field->type == IPT_OTHER && field->name != NULL) || input_type_group(machine, field->type, field->player) != IPG_INVALID))
659         if (name != NULL && input_condition_true(machine(), &field->condition, port->owner()) &&
660            ((field->type == IPT_OTHER && field->name != NULL) || input_type_group(machine(), field->type, field->player) != IPG_INVALID))
798661         {
799662            input_seq_type seqtype;
800663            UINT16 sortorder;
r13553r13554
809672            for (seqtype = SEQ_TYPE_STANDARD; seqtype < SEQ_TYPE_TOTAL; seqtype++)
810673            {
811674               /* build an entry for the standard sequence */
812               input_item_data *item = (input_item_data *)menu->m_pool_alloc(sizeof(*item));
675               input_item_data *item = (input_item_data *)m_pool_alloc(sizeof(*item));
813676               memset(item, 0, sizeof(*item));
814677               item->ref = field;
815678               item->seqtype = seqtype;
r13553r13554
829692      }
830693
831694   /* sort and populate the menu in a standard fashion */
832   menu_input_populate_and_sort(machine, menu, itemlist, menustate);
695   populate_and_sort(itemlist);
833696}
834697
698ui_menu_input_specific::~ui_menu_input_specific()
699{
700}
835701
836702/*-------------------------------------------------
837703    menu_input - display a menu for inputs
838704-------------------------------------------------*/
705ui_menu_input::ui_menu_input(running_machine &machine, render_container *container) : ui_menu(machine, container)
706{
707}
839708
840static void menu_input_common(running_machine &machine, ui_menu *menu, void *parameter, void *state)
709ui_menu_input::~ui_menu_input()
841710{
842   input_item_data *seqchangeditem = NULL;
843   input_menu_state *menustate;
844   const ui_menu_event *menu_event;
845   int invalidate = FALSE;
711}
846712
847   /* if no state, allocate now */
848   if (state == NULL)
849      state = menu->alloc_state(sizeof(*menustate), NULL);
850   menustate = (input_menu_state *)state;
713/*-------------------------------------------------
714    toggle_none_default - toggle between "NONE"
715    and the default item
716-------------------------------------------------*/
851717
852   /* if the menu isn't built, populate now */
853   if (!menu->populated())
854   {
855      if (parameter != NULL)
856         menu_input_general_populate(machine, menu, menustate, (FPTR)parameter - 1);
857      else
858         menu_input_specific_populate(machine, menu, menustate);
859   }
718void ui_menu_input::toggle_none_default(input_seq &selected_seq, input_seq &original_seq, const input_seq &selected_defseq)
719{
720   /* if we used to be "none", toggle to the default value */
721   if (original_seq.length() == 0)
722      selected_seq = selected_defseq;
860723
724   /* otherwise, toggle to "none" */
725   else
726      selected_seq.reset();
727}
728
729/*-------------------------------------------------
730    get_field_default_seq - return a pointer
731    to the default sequence for the given field
732-------------------------------------------------*/
733
734const input_seq &ui_menu_input::get_field_default_seq(input_field_config *field, input_seq_type seqtype)
735{
736   if (field->seq[seqtype].is_default())
737      return input_type_seq(field->machine(), field->type, field->player, seqtype);
738   else
739      return field->seq[seqtype];
740}
741
742void ui_menu_input::handle()
743{
744   input_item_data *seqchangeditem = NULL;
745   const ui_menu_event *menu_event;
746   int invalidate = false;
747
861748   /* process the menu */
862   menu_event = menu->process((menustate->pollingitem != NULL) ? UI_MENU_PROCESS_NOKEYS : 0);
749   menu_event = process((pollingitem != NULL) ? UI_MENU_PROCESS_NOKEYS : 0);
863750
864751   /* if we are polling, handle as a special case */
865   if (menustate->pollingitem != NULL)
752   if (pollingitem != NULL)
866753   {
867      input_item_data *item = menustate->pollingitem;
754      input_item_data *item = pollingitem;
868755      input_seq newseq;
869756
870757      /* if UI_CANCEL is pressed, abort */
871      if (ui_input_pressed(machine, IPT_UI_CANCEL))
758      if (ui_input_pressed(machine(), IPT_UI_CANCEL))
872759      {
873         menustate->pollingitem = NULL;
874         menustate->record_next = FALSE;
875         toggle_none_default(item->seq, menustate->starting_seq, *item->defseq);
760         pollingitem = NULL;
761         record_next = false;
762         toggle_none_default(item->seq, starting_seq, *item->defseq);
876763         seqchangeditem = item;
877764      }
878765
879766      /* poll again; if finished, update the sequence */
880      if (machine.input().seq_poll())
767      if (machine().input().seq_poll())
881768      {
882         menustate->pollingitem = NULL;
883         menustate->record_next = TRUE;
884         item->seq = machine.input().seq_poll_final();
769         pollingitem = NULL;
770         record_next = true;
771         item->seq = machine().input().seq_poll_final();
885772         seqchangeditem = item;
886773      }
887774   }
r13553r13554
894781      {
895782         /* an item was selected: begin polling */
896783         case IPT_UI_SELECT:
897            menustate->pollingitem = item;
898            menustate->last_sortorder = item->sortorder;
899            menustate->starting_seq = item->seq;
900            machine.input().seq_poll_start((item->type == INPUT_TYPE_ANALOG) ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, menustate->record_next ? &item->seq : NULL);
901            invalidate = TRUE;
784            pollingitem = item;
785            last_sortorder = item->sortorder;
786            starting_seq = item->seq;
787            machine().input().seq_poll_start((item->type == INPUT_TYPE_ANALOG) ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, record_next ? &item->seq : NULL);
788            invalidate = true;
902789            break;
903790
904791         /* if the clear key was pressed, reset the selected item */
905792         case IPT_UI_CLEAR:
906793            toggle_none_default(item->seq, item->seq, *item->defseq);
907            menustate->record_next = FALSE;
794            record_next = false;
908795            seqchangeditem = item;
909796            break;
910797      }
911798
912799      /* if the selection changed, reset the "record next" flag */
913      if (item->sortorder != menustate->last_sortorder)
914         menustate->record_next = FALSE;
915      menustate->last_sortorder = item->sortorder;
800      if (item->sortorder != last_sortorder)
801         record_next = false;
802      last_sortorder = item->sortorder;
916803   }
917804
918805   /* if the sequence changed, update it */
919806   if (seqchangeditem != NULL)
920807   {
921      /* update a general input */
922      if (parameter != NULL)
923      {
924         const input_type_entry *entry = (const input_type_entry *)seqchangeditem->ref;
925         input_type_set_seq(machine, entry->type, entry->player, seqchangeditem->seqtype, &seqchangeditem->seq);
926      }
808      update_input(seqchangeditem);
927809
928      /* update a game-specific input */
929      else
930      {
931         input_field_user_settings settings;
932
933         input_field_get_user_settings((input_field_config *)seqchangeditem->ref, &settings);
934         settings.seq[seqchangeditem->seqtype] = seqchangeditem->seq;
935         input_field_set_user_settings((input_field_config *)seqchangeditem->ref, &settings);
936      }
937
938810      /* invalidate the menu to force an update */
939      invalidate = TRUE;
811      invalidate = true;
940812   }
941813
942814   /* if the menu is invalidated, clear it now */
943815   if (invalidate)
944816   {
945      menustate->pollingref = NULL;
946      if (menustate->pollingitem != NULL)
947         menustate->pollingref = menustate->pollingitem->ref;
948      menu->reset(UI_MENU_RESET_REMEMBER_POSITION);
817      pollingref = NULL;
818      if (pollingitem != NULL)
819         pollingref = pollingitem->ref;
820      reset(UI_MENU_RESET_REMEMBER_POSITION);
949821   }
950822}
951823
824void ui_menu_input_general::update_input(struct input_item_data *seqchangeditem)
825{
826   const input_type_entry *entry = (const input_type_entry *)seqchangeditem->ref;
827   input_type_set_seq(machine(), entry->type, entry->player, seqchangeditem->seqtype, &seqchangeditem->seq);
828}
952829
830void ui_menu_input_specific::update_input(struct input_item_data *seqchangeditem)
831{
832   input_field_user_settings settings;
833
834   input_field_get_user_settings((input_field_config *)seqchangeditem->ref, &settings);
835   settings.seq[seqchangeditem->seqtype] = seqchangeditem->seq;
836   input_field_set_user_settings((input_field_config *)seqchangeditem->ref, &settings);
837}
838
839
953840/*-------------------------------------------------
954841    menu_input_compare_items - compare two
955842    items for quicksort
956843-------------------------------------------------*/
957844
958static int menu_input_compare_items(const void *i1, const void *i2)
845int ui_menu_input::compare_items(const void *i1, const void *i2)
959846{
960847   const input_item_data * const *data1 = (const input_item_data * const *)i1;
961848   const input_item_data * const *data2 = (const input_item_data * const *)i2;
r13553r13554
973860    menu from them
974861-------------------------------------------------*/
975862
976static void menu_input_populate_and_sort(running_machine &machine, ui_menu *menu, input_item_data *itemlist, input_menu_state *menustate)
863void ui_menu_input::populate_and_sort(input_item_data *itemlist)
977864{
978865   const char *nameformat[INPUT_TYPE_TOTAL] = { 0 };
979866   input_item_data **itemarray, *item;
r13553r13554
992879      numitems++;
993880
994881   /* now allocate an array of items and fill it up */
995   itemarray = (input_item_data **)menu->m_pool_alloc(sizeof(*itemarray) * numitems);
882   itemarray = (input_item_data **)m_pool_alloc(sizeof(*itemarray) * numitems);
996883   for (item = itemlist, curitem = 0; item != NULL; item = item->next)
997884      itemarray[curitem++] = item;
998885
999886   /* sort it */
1000   qsort(itemarray, numitems, sizeof(*itemarray), menu_input_compare_items);
887   qsort(itemarray, numitems, sizeof(*itemarray), compare_items);
1001888
1002889   /* build the menu */
1003890   for (curitem = 0; curitem < numitems; curitem++)
r13553r13554
1010897      text.printf(nameformat[item->type], item->name);
1011898
1012899      /* if we're polling this item, use some spaces with left/right arrows */
1013      if (menustate->pollingref == item->ref)
900      if (pollingref == item->ref)
1014901      {
1015902         subtext.cpy("   ");
1016903         flags |= MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW;
r13553r13554
1019906      /* otherwise, generate the sequence name and invert it if different from the default */
1020907      else
1021908      {
1022         machine.input().seq_name(subtext, item->seq);
909         machine().input().seq_name(subtext, item->seq);
1023910         flags |= (item->seq != *item->defseq) ? MENU_FLAG_INVERT : 0;
1024911      }
1025912
1026913      /* add the item */
1027      menu->item_append(text, subtext, flags, item);
914      item_append(text, subtext, flags, item);
1028915   }
1029916}
1030917
r13553r13554
1034921    switches menu
1035922-------------------------------------------------*/
1036923
1037static void menu_settings_dip_switches(running_machine &machine, ui_menu *menu, void *parameter, void *state)
924ui_menu_settings_dip_switches::ui_menu_settings_dip_switches(running_machine &machine, render_container *container) : ui_menu_settings(machine, container, IPT_DIPSWITCH)
1038925{
1039   menu_settings_common(machine, menu, state, IPT_DIPSWITCH);
926   custombottom = dipcount * (DIP_SWITCH_HEIGHT + DIP_SWITCH_SPACING) + DIP_SWITCH_SPACING;
1040927}
1041928
929ui_menu_settings_dip_switches::~ui_menu_settings_dip_switches()
930{
931}
1042932
1043933/*-------------------------------------------------
1044934    menu_settings_driver_config - handle the
1045935    driver config menu
1046936-------------------------------------------------*/
1047937
1048static void menu_settings_driver_config(running_machine &machine, ui_menu *menu, void *parameter, void *state)
938ui_menu_settings_driver_config::ui_menu_settings_driver_config(running_machine &machine, render_container *container) : ui_menu_settings(machine, container, IPT_CONFIG)
1049939{
1050   menu_settings_common(machine, menu, state, IPT_CONFIG);
1051940}
1052941
942ui_menu_settings_driver_config::~ui_menu_settings_driver_config()
943{
944}
1053945
1054946/*-------------------------------------------------
1055947    menu_settings_common - handle one of the
1056948    switches menus
1057949-------------------------------------------------*/
1058950
1059static void menu_settings_common(running_machine &machine, ui_menu *menu, void *state, UINT32 type)
951void ui_menu_settings::handle()
1060952{
1061   settings_menu_state *menustate;
1062   const ui_menu_event *menu_event;
1063
1064   /* if no state, allocate now */
1065   if (state == NULL)
1066      state = menu->alloc_state(sizeof(*menustate), NULL);
1067   menustate = (settings_menu_state *)state;
1068
1069   /* if the menu isn't built, populate now */
1070   if (!menu->populated())
1071      menu_settings_populate(machine, menu, menustate, type);
1072
1073953   /* process the menu */
1074   menu_event = menu->process(0);
954   const ui_menu_event *menu_event = process(0);
1075955
1076956   /* handle events */
1077957   if (menu_event != NULL && menu_event->itemref != NULL)
1078958   {
1079959      input_field_config *field = (input_field_config *)menu_event->itemref;
1080960      input_field_user_settings settings;
1081      int changed = FALSE;
961      int changed = false;
1082962
1083963      switch (menu_event->iptkey)
1084964      {
r13553r13554
1087967            input_field_get_user_settings(field, &settings);
1088968            settings.value = field->defvalue;
1089969            input_field_set_user_settings(field, &settings);
1090            changed = TRUE;
970            changed = true;
1091971            break;
1092972
1093973         /* left goes to previous setting */
1094974         case IPT_UI_LEFT:
1095975            input_field_select_previous_setting(field);
1096            changed = TRUE;
976            changed = true;
1097977            break;
1098978
1099979         /* right goes to next setting */
1100980         case IPT_UI_RIGHT:
1101981            input_field_select_next_setting(field);
1102            changed = TRUE;
982            changed = true;
1103983            break;
1104984      }
1105985
1106986      /* if anything changed, rebuild the menu, trying to stay on the same field */
1107987      if (changed)
1108         menu->reset(UI_MENU_RESET_REMEMBER_REF);
988         reset(UI_MENU_RESET_REMEMBER_REF);
1109989   }
1110990}
1111991
r13553r13554
1115995    switches menus
1116996-------------------------------------------------*/
1117997
1118static void menu_settings_populate(running_machine &machine, ui_menu *menu, settings_menu_state *menustate, UINT32 type)
998ui_menu_settings::ui_menu_settings(running_machine &machine, render_container *container, UINT32 _type) : ui_menu(machine, container)
1119999{
1000   type = _type;
1001}
1002
1003void ui_menu_settings::populate()
1004{
11201005   input_field_config *field;
11211006   input_port_config *port;
11221007   dip_descriptor **diplist_tailptr;
1123   int dipcount = 0;
11241008
11251009   /* reset the dip switch tracking */
1126   menustate->diplist = NULL;
1127   diplist_tailptr = &menustate->diplist;
1010   dipcount = 0;
1011   diplist = NULL;
1012   diplist_tailptr = &diplist;
11281013
11291014   /* loop over input ports and set up the current values */
1130   for (port = machine.m_portlist.first(); port != NULL; port = port->next())
1015   for (port = machine().m_portlist.first(); port != NULL; port = port->next())
11311016      for (field = port->fieldlist().first(); field != NULL; field = field->next())
1132         if (field->type == type && input_condition_true(machine, &field->condition, port->owner()))
1017         if (field->type == type && input_condition_true(machine(), &field->condition, port->owner()))
11331018         {
11341019            UINT32 flags = 0;
11351020
r13553r13554
11401025               flags |= MENU_FLAG_RIGHT_ARROW;
11411026
11421027            /* add the menu item */
1143            menu->item_append(input_field_name(field), input_field_setting_name(field), flags, (void *)field);
1028            item_append(input_field_name(field), input_field_setting_name(field), flags, (void *)field);
11441029
11451030            /* for DIP switches, build up the model */
11461031            if (type == IPT_DIPSWITCH && field->diploclist().count() != 0)
r13553r13554
11591044                  dip_descriptor *dip;
11601045
11611046                  /* find the matching switch name */
1162                  for (dip = menustate->diplist; dip != NULL; dip = dip->next)
1047                  for (dip = diplist; dip != NULL; dip = dip->next)
11631048                     if (strcmp(dip->name, diploc->swname) == 0)
11641049                        break;
11651050
11661051                  /* allocate new if none */
11671052                  if (dip == NULL)
11681053                  {
1169                     dip = (dip_descriptor *)menu->m_pool_alloc(sizeof(*dip));
1054                     dip = (dip_descriptor *)m_pool_alloc(sizeof(*dip));
11701055                     dip->next = NULL;
11711056                     dip->name = diploc->swname;
11721057                     dip->mask = dip->state = 0;
r13553r13554
11861071               }
11871072            }
11881073         }
1074}
11891075
1190   /* configure the extra menu */
1191   if (type == IPT_DIPSWITCH && menustate->diplist != NULL)
1192      menu->set_custom_render(menu_settings_custom_render, 0.0f, dipcount * (DIP_SWITCH_HEIGHT + DIP_SWITCH_SPACING) + DIP_SWITCH_SPACING);
1076ui_menu_settings::~ui_menu_settings()
1077{
11931078}
11941079
1195
11961080/*-------------------------------------------------
11971081    menu_settings_custom_render - perform our special
11981082    rendering
11991083-------------------------------------------------*/
12001084
1201static void menu_settings_custom_render(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom, float x1, float y1, float x2, float y2)
1085void ui_menu_settings_dip_switches::custom_render(void *selectedref, float top, float bottom, float x1, float y1, float x2, float y2)
12021086{
12031087   input_field_config *field = (input_field_config *)selectedref;
1204   settings_menu_state *menustate = (settings_menu_state *)state;
12051088   dip_descriptor *dip;
12061089
12071090   /* add borders */
r13553r13554
12091092   y2 = y1 + bottom;
12101093
12111094   /* draw extra menu area */
1212   ui_draw_outlined_box(&machine.render().ui_container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR);
1095   ui_draw_outlined_box(container, x1, y1, x2, y2, UI_BACKGROUND_COLOR);
12131096   y1 += (float)DIP_SWITCH_SPACING;
12141097
12151098   /* iterate over DIP switches */
1216   for (dip = menustate->diplist; dip != NULL; dip = dip->next)
1099   for (dip = diplist; dip != NULL; dip = dip->next)
12171100   {
12181101      if (mame_stricmp(dip->name, "FAKE") != 0)
12191102      {
r13553r13554
12271110                  selectedmask |= 1 << (diploc->swnum - 1);
12281111
12291112         /* draw one switch */
1230         menu_settings_custom_render_one(&machine.render().ui_container(), x1, y1, x2, y1 + DIP_SWITCH_HEIGHT, dip, selectedmask);
1113         custom_render_one(x1, y1, x2, y1 + DIP_SWITCH_HEIGHT, dip, selectedmask);
12311114         y1 += (float)(DIP_SWITCH_SPACING + DIP_SWITCH_HEIGHT);
12321115      }
12331116   }
r13553r13554
12391122    DIP switch
12401123-------------------------------------------------*/
12411124
1242static void menu_settings_custom_render_one(render_container *container, float x1, float y1, float x2, float y2, const dip_descriptor *dip, UINT32 selectedmask)
1125void ui_menu_settings_dip_switches::custom_render_one(float x1, float y1, float x2, float y2, const dip_descriptor *dip, UINT32 selectedmask)
12431126{
12441127   float switch_field_width = SINGLE_TOGGLE_SWITCH_FIELD_WIDTH * container->manager().ui_aspect();
12451128   float switch_width = SINGLE_TOGGLE_SWITCH_WIDTH * container->manager().ui_aspect();
r13553r13554
13081191    menu_analog - handle the analog settings menu
13091192-------------------------------------------------*/
13101193
1311static void menu_analog(running_machine &machine, ui_menu *menu, void *parameter, void *state)
1194void ui_menu_analog::handle()
13121195{
1313   const ui_menu_event *menu_event;
1314
1315   /* if the menu isn't built, populate now */
1316   if (!menu->populated())
1317      menu_analog_populate(machine, menu);
1318
13191196   /* process the menu */
1320   menu_event = menu->process(UI_MENU_PROCESS_LR_REPEAT);
1197   const ui_menu_event *menu_event = process(UI_MENU_PROCESS_LR_REPEAT);
13211198
13221199   /* handle events */
13231200   if (menu_event != NULL && menu_event->itemref != NULL)
r13553r13554
13341211
13351212         /* left decrements */
13361213         case IPT_UI_LEFT:
1337            newval -= machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1;
1214            newval -= machine().input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1;
13381215            break;
13391216
13401217         /* right increments */
13411218         case IPT_UI_RIGHT:
1342            newval += machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1;
1219            newval += machine().input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1;
13431220            break;
13441221      }
13451222
r13553r13554
13661243         input_field_set_user_settings(data->field, &settings);
13671244
13681245         /* rebuild the menu */
1369         menu->reset(UI_MENU_RESET_REMEMBER_POSITION);
1246         reset(UI_MENU_RESET_REMEMBER_POSITION);
13701247      }
13711248   }
13721249}
r13553r13554
13771254    settings menu
13781255-------------------------------------------------*/
13791256
1380static void menu_analog_populate(running_machine &machine, ui_menu *menu)
1257ui_menu_analog::ui_menu_analog(running_machine &machine, render_container *container) : ui_menu(machine, container)
13811258{
1259}
1260
1261void ui_menu_analog::populate()
1262{
13821263   input_field_config *field;
13831264   input_port_config *port;
13841265   astring subtext;
13851266   astring text;
13861267
13871268   /* loop over input ports and add the items */
1388   for (port = machine.m_portlist.first(); port != NULL; port = port->next())
1269   for (port = machine().m_portlist.first(); port != NULL; port = port->next())
13891270      for (field = port->fieldlist().first(); field != NULL; field = field->next())
1390         if (input_type_is_analog(field->type) && input_condition_true(machine, &field->condition, port->owner()))
1271         if (input_type_is_analog(field->type) && input_condition_true(machine(), &field->condition, port->owner()))
13911272         {
13921273            input_field_user_settings settings;
1393            int use_autocenter = FALSE;
1274            int use_autocenter = false;
13941275            int type;
13951276
13961277            /* based on the type, determine if we enable autocenter */
r13553r13554
14091290               case IPT_PEDAL:
14101291               case IPT_PEDAL2:
14111292               case IPT_PEDAL3:
1412                  use_autocenter = TRUE;
1293                  use_autocenter = true;
14131294                  break;
14141295            }
14151296
r13553r13554
14241305                  UINT32 flags = 0;
14251306
14261307                  /* allocate a data item for tracking what this menu item refers to */
1427                  data = (analog_item_data *)menu->m_pool_alloc(sizeof(*data));
1308                  data = (analog_item_data *)m_pool_alloc(sizeof(*data));
14281309                  data->field = field;
14291310                  data->type = type;
14301311
r13553r13554
14761357                     flags |= MENU_FLAG_RIGHT_ARROW;
14771358
14781359                  /* append a menu item */
1479                  menu->item_append(text, subtext, flags, data);
1360                  item_append(text, subtext, flags, data);
14801361               }
14811362         }
14821363}
14831364
1365ui_menu_analog::~ui_menu_analog()
1366{
1367}
14841368
14851369/*-------------------------------------------------
14861370    menu_bookkeeping - handle the bookkeeping
14871371    information menu
14881372-------------------------------------------------*/
14891373
1490static void menu_bookkeeping(running_machine &machine, ui_menu *menu, void *parameter, void *state)
1374void ui_menu_bookkeeping::handle()
14911375{
1492   attotime *prevtime;
14931376   attotime curtime;
14941377
1495   /* if no state, allocate some */
1496   if (state == NULL)
1497      state = menu->alloc_state(sizeof(*prevtime), NULL);
1498   prevtime = (attotime *)state;
1499
15001378   /* if the time has rolled over another second, regenerate */
1501   curtime = machine.time();
1502   if (prevtime->seconds != curtime.seconds)
1379   curtime = machine().time();
1380   if (prevtime.seconds != curtime.seconds)
15031381   {
1504      menu->reset(UI_MENU_RESET_SELECT_FIRST);
1505      *prevtime = curtime;
1506      menu_bookkeeping_populate(machine, menu, prevtime);
1382      reset(UI_MENU_RESET_SELECT_FIRST);
1383      prevtime = curtime;
1384      populate();
15071385   }
15081386
15091387   /* process the menu */
1510   menu->process(0);
1388   process(0);
15111389}
15121390
15131391
r13553r13554
15151393    menu_bookkeeping - handle the bookkeeping
15161394    information menu
15171395-------------------------------------------------*/
1396ui_menu_bookkeeping::ui_menu_bookkeeping(running_machine &machine, render_container *container) : ui_menu(machine, container)
1397{
1398}
15181399
1519static void menu_bookkeeping_populate(running_machine &machine, ui_menu *menu, attotime *curtime)
1400ui_menu_bookkeeping::~ui_menu_bookkeeping()
15201401{
1521   int tickets = get_dispensed_tickets(machine);
1402}
1403
1404void ui_menu_bookkeeping::populate()
1405{
1406   int tickets = get_dispensed_tickets(machine());
15221407   astring tempstring;
15231408   int ctrnum;
15241409
15251410   /* show total time first */
1526   if (curtime->seconds >= 60 * 60)
1527      tempstring.catprintf("Uptime: %d:%02d:%02d\n\n", curtime->seconds / (60*60), (curtime->seconds / 60) % 60, curtime->seconds % 60);
1411   if (prevtime.seconds >= 60 * 60)
1412      tempstring.catprintf("Uptime: %d:%02d:%02d\n\n", prevtime.seconds / (60*60), (prevtime.seconds / 60) % 60, prevtime.seconds % 60);
15281413   else
1529      tempstring.catprintf("Uptime: %d:%02d\n\n", (curtime->seconds / 60) % 60, curtime->seconds % 60);
1414      tempstring.catprintf("Uptime: %d:%02d\n\n", (prevtime.seconds / 60) % 60, prevtime.seconds % 60);
15301415
15311416   /* show tickets at the top */
15321417   if (tickets > 0)
r13553r13554
15351420   /* loop over coin counters */
15361421   for (ctrnum = 0; ctrnum < COIN_COUNTERS; ctrnum++)
15371422   {
1538      int count = coin_counter_get_count(machine, ctrnum);
1423      int count = coin_counter_get_count(machine(), ctrnum);
15391424
15401425      /* display the coin counter number */
15411426      tempstring.catprintf("Coin %c: ", ctrnum + 'A');
r13553r13554
15471432         tempstring.catprintf("%d", count);
15481433
15491434      /* display whether or not we are locked out */
1550      if (coin_lockout_get_state(machine, ctrnum))
1435      if (coin_lockout_get_state(machine(), ctrnum))
15511436         tempstring.cat(" (locked)");
15521437      tempstring.cat("\n");
15531438   }
15541439
15551440   /* append the single item */
1556   menu->item_append(tempstring, NULL, MENU_FLAG_MULTILINE, NULL);
1441   item_append(tempstring, NULL, MENU_FLAG_MULTILINE, NULL);
15571442}
15581443
15591444
r13553r13554
15621447    menu
15631448-------------------------------------------------*/
15641449
1565static void menu_game_info(running_machine &machine, ui_menu *menu, void *parameter, void *state)
1450ui_menu_game_info::ui_menu_game_info(running_machine &machine, render_container *container) : ui_menu(machine, container)
15661451{
1567   /* if the menu isn't built, populate now */
1568   if (!menu->populated())
1569   {
1570      astring tempstring;
1571      menu->item_append(game_info_astring(machine, tempstring), NULL, MENU_FLAG_MULTILINE, NULL);
1572   }
1452}
15731453
1454void ui_menu_game_info::populate()
1455{
1456   astring tempstring;
1457   item_append(game_info_astring(machine(), tempstring), NULL, MENU_FLAG_MULTILINE, NULL);
1458}
1459
1460void ui_menu_game_info::handle()
1461{
15741462   /* process the menu */
1575   menu->process(0);
1463   process(0);
15761464}
15771465
1466ui_menu_game_info::~ui_menu_game_info()
1467{
1468}
15781469
15791470/*-------------------------------------------------
15801471    menu_cheat - handle the cheat menu
15811472-------------------------------------------------*/
15821473
1583static void menu_cheat(running_machine &machine, ui_menu *menu, void *parameter, void *state)
1474void ui_menu_cheat::handle()
15841475{
1585   const ui_menu_event *menu_event;
1586
1587   /* if the menu isn't built, populate now */
1588   if (!menu->populated())
1589      menu_cheat_populate(machine, menu);
1590
15911476   /* process the menu */
1592   menu_event = menu->process(UI_MENU_PROCESS_LR_REPEAT);
1477   const ui_menu_event *menu_event = process(UI_MENU_PROCESS_LR_REPEAT);
15931478
15941479   /* handle events */
15951480   if (menu_event != NULL && menu_event->itemref != NULL)
r13553r13554
16021487      /* handle reset all + reset all cheats for reload all option */
16031488      if ((FPTR)menu_event->itemref < 3 && menu_event->iptkey == IPT_UI_SELECT)
16041489      {
1605         for (cheat_entry *curcheat = machine.cheat().first(); curcheat != NULL; curcheat = curcheat->next())
1490         for (cheat_entry *curcheat = machine().cheat().first(); curcheat != NULL; curcheat = curcheat->next())
16061491            if (curcheat->select_default_state())
16071492               changed = true;
16081493      }
r13553r13554
16501535      if ((FPTR)menu_event->itemref == 2 && menu_event->iptkey == IPT_UI_SELECT)
16511536      {
16521537         /* re-init cheat engine and thus reload cheats/cheats have already been turned off by here */
1653         machine.cheat().reload();
1538         machine().cheat().reload();
16541539
16551540         /* display the reloaded cheats */
1656         menu->reset(UI_MENU_RESET_REMEMBER_REF);
1541         reset(UI_MENU_RESET_REMEMBER_REF);
16571542         popmessage("All cheats reloaded");
16581543      }
16591544
16601545      /* if things changed, update */
16611546      if (changed)
1662         menu->reset(UI_MENU_RESET_REMEMBER_REF);
1547         reset(UI_MENU_RESET_REMEMBER_REF);
16631548   }
16641549}
16651550
r13553r13554
16681553    menu_cheat_populate - populate the cheat menu
16691554-------------------------------------------------*/
16701555
1671static void menu_cheat_populate(running_machine &machine, ui_menu *menu)
1556ui_menu_cheat::ui_menu_cheat(running_machine &machine, render_container *container) : ui_menu(machine, container)
16721557{
1558}
1559
1560void ui_menu_cheat::populate()
1561{
16731562   /* iterate over cheats */
16741563   astring text;
16751564   astring subtext;
1676   for (cheat_entry *curcheat = machine.cheat().first(); curcheat != NULL; curcheat = curcheat->next())
1565   for (cheat_entry *curcheat = machine().cheat().first(); curcheat != NULL; curcheat = curcheat->next())
16771566   {
16781567      UINT32 flags;
16791568      curcheat->menu_text(text, subtext, flags);
1680      menu->item_append(text, subtext, flags, curcheat);
1569      item_append(text, subtext, flags, curcheat);
16811570   }
16821571
16831572   /* add a separator */
1684   menu->item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL);
1573   item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL);
16851574
16861575   /* add a reset all option */
1687   menu->item_append("Reset All", NULL, 0, (void *)1);
1576   item_append("Reset All", NULL, 0, (void *)1);
16881577
16891578   /* add a reload all cheats option */
1690   menu->item_append("Reload All", NULL, 0, (void *)2);
1579   item_append("Reload All", NULL, 0, (void *)2);
16911580}
16921581
1582ui_menu_cheat::~ui_menu_cheat()
1583{
1584}
16931585
16941586/*-------------------------------------------------
16951587    menu_memory_card - handle the memory card
16961588    menu
16971589-------------------------------------------------*/
16981590
1699static void menu_memory_card(running_machine &machine, ui_menu *menu, void *parameter, void *state)
1591void ui_menu_memory_card::handle()
17001592{
1701   const ui_menu_event *menu_event;
1702   int *cardnum;
1703
1704   /* if no state, allocate some */
1705   if (state == NULL)
1706      state = menu->alloc_state(sizeof(*cardnum), NULL);
1707   cardnum = (int *)state;
1708
1709   /* if the menu isn't built, populate now */
1710   if (!menu->populated())
1711      menu_memory_card_populate(machine, menu, *cardnum);
1712
17131593   /* process the menu */
1714   menu_event = menu->process(UI_MENU_PROCESS_LR_REPEAT);
1594   const ui_menu_event *menu_event = process(UI_MENU_PROCESS_LR_REPEAT);
17151595
17161596   /* if something was selected, act on it */
17171597   if (menu_event != NULL && menu_event->itemref != NULL)
r13553r13554
17251605         {
17261606            /* handle card loading; if we succeed, clear the menus */
17271607            case MEMCARD_ITEM_LOAD:
1728               if (memcard_insert(menu->machine(), *cardnum) == 0)
1608               if (memcard_insert(machine(), cardnum) == 0)
17291609               {
17301610                  popmessage("Memory card loaded");
1731                  ui_menu::stack_reset(menu->machine());
1611                  ui_menu::stack_reset(machine());
17321612               }
17331613               else
17341614                  popmessage("Error loading memory card");
r13553r13554
17361616
17371617            /* handle card ejecting */
17381618            case MEMCARD_ITEM_EJECT:
1739               memcard_eject(menu->machine());
1619               memcard_eject(machine());
17401620               popmessage("Memory card ejected");
17411621               break;
17421622
17431623            /* handle card creating */
17441624            case MEMCARD_ITEM_CREATE:
1745               if (memcard_create(menu->machine(), *cardnum, FALSE) == 0)
1625               if (memcard_create(machine(), cardnum, false) == 0)
17461626                  popmessage("Memory card created");
17471627               else
17481628                  popmessage("Error creating memory card\n(Card may already exist)");
r13553r13554
17571637         {
17581638            /* left decrements the card number */
17591639            case IPT_UI_LEFT:
1760               *cardnum -= 1;
1761               menu->reset(UI_MENU_RESET_REMEMBER_REF);
1640               cardnum -= 1;
1641               reset(UI_MENU_RESET_REMEMBER_REF);
17621642               break;
17631643
17641644            /* right decrements the card number */
17651645            case IPT_UI_RIGHT:
1766               *cardnum += 1;
1767               menu->reset(UI_MENU_RESET_REMEMBER_REF);
1646               cardnum += 1;
1647               reset(UI_MENU_RESET_REMEMBER_REF);
17681648               break;
17691649         }
17701650      }
r13553r13554
17771657    memory card menu
17781658-------------------------------------------------*/
17791659
1780static void menu_memory_card_populate(running_machine &machine, ui_menu *menu, int cardnum)
1660ui_menu_memory_card::ui_menu_memory_card(running_machine &machine, render_container *container) : ui_menu(machine, container)
17811661{
1662}
1663
1664void ui_menu_memory_card::populate()
1665{
17821666   char tempstring[20];
17831667   UINT32 flags = 0;
17841668
r13553r13554
17881672      flags |= MENU_FLAG_LEFT_ARROW;
17891673   if (cardnum < 1000)
17901674      flags |= MENU_FLAG_RIGHT_ARROW;
1791   menu->item_append("Card Number:", tempstring, flags, (void *)MEMCARD_ITEM_SELECT);
1675   item_append("Card Number:", tempstring, flags, (void *)MEMCARD_ITEM_SELECT);
17921676
17931677   /* add the remaining items */
1794   menu->item_append("Load Selected Card", NULL, 0, (void *)MEMCARD_ITEM_LOAD);
1795   if (memcard_present(machine) != -1)
1796      menu->item_append("Eject Current Card", NULL, 0, (void *)MEMCARD_ITEM_EJECT);
1797   menu->item_append("Create New Card", NULL, 0, (void *)MEMCARD_ITEM_CREATE);
1678   item_append("Load Selected Card", NULL, 0, (void *)MEMCARD_ITEM_LOAD);
1679   if (memcard_present(machine()) != -1)
1680      item_append("Eject Current Card", NULL, 0, (void *)MEMCARD_ITEM_EJECT);
1681   item_append("Create New Card", NULL, 0, (void *)MEMCARD_ITEM_CREATE);
17981682}
17991683
1684ui_menu_memory_card::~ui_menu_memory_card()
1685{
1686}
18001687
18011688/*-------------------------------------------------
18021689    menu_sliders - handle the sliders menu
18031690-------------------------------------------------*/
18041691
1805static void menu_sliders(running_machine &machine, ui_menu *menu, void *parameter, void *state)
1692void ui_menu_sliders::handle()
18061693{
1807   int menuless_mode = (parameter != NULL);
18081694   const ui_menu_event *menu_event;
1809   UINT8 *hidden = (UINT8 *)state;
18101695
1811   /* if no state, allocate some */
1812   if (hidden == NULL)
1813      hidden = (UINT8 *)menu->alloc_state(sizeof(*hidden), NULL);
1814   if (menuless_mode)
1815      *hidden = TRUE;
1816
1817   /* if the menu isn't built, populate now */
1818   if (!menu->populated())
1819      menu_sliders_populate(machine, menu, menuless_mode);
1820
18211696   /* process the menu */
1822   menu_event = menu->process(UI_MENU_PROCESS_LR_REPEAT | (*hidden ? UI_MENU_PROCESS_CUSTOM_ONLY : 0));
1697   menu_event = process(UI_MENU_PROCESS_LR_REPEAT | (hidden ? UI_MENU_PROCESS_CUSTOM_ONLY : 0));
18231698   if (menu_event != NULL)
18241699   {
18251700      /* handle keys if there is a valid item selected */
18261701      if (menu_event->itemref != NULL)
18271702      {
18281703         const slider_state *slider = (const slider_state *)menu_event->itemref;
1829         INT32 curvalue = (*slider->update)(machine, slider->arg, NULL, SLIDER_NOCHANGE);
1704         INT32 curvalue = (*slider->update)(machine(), slider->arg, NULL, SLIDER_NOCHANGE);
18301705         INT32 increment = 0;
18311706
18321707         switch (menu_event->iptkey)
r13553r13554
18341709            /* toggle visibility */
18351710            case IPT_UI_ON_SCREEN_DISPLAY:
18361711               if (menuless_mode)
1837                  ui_menu::stack_pop(machine);
1712                  ui_menu::stack_pop(machine());
18381713               else
1839                  *hidden = !*hidden;
1714                  hidden = !hidden;
18401715               break;
18411716
18421717            /* decrease value */
18431718            case IPT_UI_LEFT:
1844               if (machine.input().code_pressed(KEYCODE_LALT) || machine.input().code_pressed(KEYCODE_RALT))
1719               if (machine().input().code_pressed(KEYCODE_LALT) || machine().input().code_pressed(KEYCODE_RALT))
18451720                  increment = -1;
1846               else if (machine.input().code_pressed(KEYCODE_LSHIFT) || machine.input().code_pressed(KEYCODE_RSHIFT))
1721               else if (machine().input().code_pressed(KEYCODE_LSHIFT) || machine().input().code_pressed(KEYCODE_RSHIFT))
18471722                  increment = (slider->incval > 10) ? -(slider->incval / 10) : -1;
1848               else if (machine.input().code_pressed(KEYCODE_LCONTROL) || machine.input().code_pressed(KEYCODE_RCONTROL))
1723               else if (machine().input().code_pressed(KEYCODE_LCONTROL) || machine().input().code_pressed(KEYCODE_RCONTROL))
18491724                  increment = -slider->incval * 10;
18501725               else
18511726                  increment = -slider->incval;
r13553r13554
18531728
18541729            /* increase value */
18551730            case IPT_UI_RIGHT:
1856               if (machine.input().code_pressed(KEYCODE_LALT) || machine.input().code_pressed(KEYCODE_RALT))
1731               if (machine().input().code_pressed(KEYCODE_LALT) || machine().input().code_pressed(KEYCODE_RALT))
18571732                  increment = 1;
1858               else if (machine.input().code_pressed(KEYCODE_LSHIFT) || machine.input().code_pressed(KEYCODE_RSHIFT))
1733               else if (machine().input().code_pressed(KEYCODE_LSHIFT) || machine().input().code_pressed(KEYCODE_RSHIFT))
18591734                  increment = (slider->incval > 10) ? (slider->incval / 10) : 1;
1860               else if (machine.input().code_pressed(KEYCODE_LCONTROL) || machine.input().code_pressed(KEYCODE_RCONTROL))
1735               else if (machine().input().code_pressed(KEYCODE_LCONTROL) || machine().input().code_pressed(KEYCODE_RCONTROL))
18611736                  increment = slider->incval * 10;
18621737               else
18631738                  increment = slider->incval;
r13553r13554
18811756               newvalue = slider->maxval;
18821757
18831758            /* update the slider and recompute the menu */
1884            (*slider->update)(machine, slider->arg, NULL, newvalue);
1885            menu->reset(UI_MENU_RESET_REMEMBER_REF);
1759            (*slider->update)(machine(), slider->arg, NULL, newvalue);
1760            reset(UI_MENU_RESET_REMEMBER_REF);
18861761         }
18871762      }
18881763
18891764      /* if we are selecting an invalid item and we are hidden, skip to the next one */
1890      else if (*hidden)
1765      else if (hidden)
18911766      {
18921767         /* if we got here via up or page up, select the previous item */
18931768         if (menu_event->iptkey == IPT_UI_UP || menu_event->iptkey == IPT_UI_PAGE_UP)
18941769         {
1895            menu->selected = (menu->selected + menu->numitems - 1) % menu->numitems;
1896            menu->validate_selection(-1);
1770            selected = (selected + numitems - 1) % numitems;
1771            validate_selection(-1);
18971772         }
18981773
18991774         /* otherwise select the next item */
19001775         else if (menu_event->iptkey == IPT_UI_DOWN || menu_event->iptkey == IPT_UI_PAGE_DOWN)
19011776         {
1902            menu->selected = (menu->selected + 1) % menu->numitems;
1903            menu->validate_selection(1);
1777            selected = (selected + 1) % numitems;
1778            validate_selection(1);
19041779         }
19051780      }
19061781   }
r13553r13554
19121787    menu
19131788-------------------------------------------------*/
19141789
1915static void menu_sliders_populate(running_machine &machine, ui_menu *menu, int menuless_mode)
1790ui_menu_sliders::ui_menu_sliders(running_machine &machine, render_container *container, bool _menuless_mode) : ui_menu(machine, container)
19161791{
1792   menuless_mode = hidden = _menuless_mode;
1793}
1794
1795void ui_menu_sliders::populate()
1796{
19171797   const slider_state *curslider;
19181798   astring tempstring;
19191799
19201800   /* add all sliders */
19211801   for (curslider = ui_get_slider_list(); curslider != NULL; curslider = curslider->next)
19221802   {
1923      INT32 curval = (*curslider->update)(machine, curslider->arg, &tempstring, SLIDER_NOCHANGE);
1803      INT32 curval = (*curslider->update)(machine(), curslider->arg, &tempstring, SLIDER_NOCHANGE);
19241804      UINT32 flags = 0;
19251805      if (curval > curslider->minval)
19261806         flags |= MENU_FLAG_LEFT_ARROW;
19271807      if (curval < curslider->maxval)
19281808         flags |= MENU_FLAG_RIGHT_ARROW;
1929      menu->item_append(curslider->description, tempstring, flags, (void *)curslider);
1809      item_append(curslider->description, tempstring, flags, (void *)curslider);
19301810
19311811      if (menuless_mode)
19321812         break;
19331813   }
19341814
19351815   /* add all sliders */
1936   for (curslider = (slider_state*)machine.osd().get_slider_list(); curslider != NULL; curslider = curslider->next)
1816   for (curslider = (slider_state*)machine().osd().get_slider_list(); curslider != NULL; curslider = curslider->next)
19371817   {
1938      INT32 curval = (*curslider->update)(machine, curslider->arg, &tempstring, SLIDER_NOCHANGE);
1818      INT32 curval = (*curslider->update)(machine(), curslider->arg, &tempstring, SLIDER_NOCHANGE);
19391819      UINT32 flags = 0;
19401820      if (curval > curslider->minval)
19411821         flags |= MENU_FLAG_LEFT_ARROW;
19421822      if (curval < curslider->maxval)
19431823         flags |= MENU_FLAG_RIGHT_ARROW;
1944      menu->item_append(curslider->description, tempstring, flags, (void *)curslider);
1824      item_append(curslider->description, tempstring, flags, (void *)curslider);
19451825   }
19461826
1947   menu->set_custom_render(menu_sliders_custom_render, 0.0f, 2.0f * ui_get_line_height(machine) + 2.0f * UI_BOX_TB_BORDER);
1827   custombottom = 2.0f * ui_get_line_height(machine()) + 2.0f * UI_BOX_TB_BORDER;
19481828}
19491829
1830ui_menu_sliders::~ui_menu_sliders()
1831{
1832}
19501833
19511834/*-------------------------------------------------
19521835    menu_sliders_custom_render - perform our special
19531836    rendering
19541837-------------------------------------------------*/
19551838
1956static void menu_sliders_custom_render(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom, float x1, float y1, float x2, float y2)
1839void ui_menu_sliders::custom_render(void *selectedref, float top, float bottom, float x1, float y1, float x2, float y2)
19571840{
19581841   const slider_state *curslider = (const slider_state *)selectedref;
19591842   if (curslider != NULL)
19601843   {
19611844      float bar_left, bar_area_top, bar_width, bar_area_height, bar_top, bar_bottom, default_x, current_x;
1962      float line_height = ui_get_line_height(machine);
1845      float line_height = ui_get_line_height(machine());
19631846      float percentage, default_percentage;
19641847      astring tempstring;
19651848      float text_height;
19661849      INT32 curval;
19671850
19681851      /* determine the current value and text */
1969      curval = (*curslider->update)(machine, curslider->arg, &tempstring, SLIDER_NOCHANGE);
1852      curval = (*curslider->update)(machine(), curslider->arg, &tempstring, SLIDER_NOCHANGE);
19701853
19711854      /* compute the current and default percentages */
19721855      percentage = (float)(curval - curslider->minval) / (float)(curslider->maxval - curslider->minval);
r13553r13554
19821865      x2 = 1.0f - UI_BOX_LR_BORDER;
19831866
19841867      /* draw extra menu area */
1985      ui_draw_outlined_box(&machine.render().ui_container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR);
1868      ui_draw_outlined_box(container, x1, y1, x2, y2, UI_BACKGROUND_COLOR);
19861869      y1 += UI_BOX_TB_BORDER;
19871870
19881871      /* determine the text height */
1989      ui_draw_text_full(&machine.render().ui_container(), tempstring, 0, 0, x2 - x1 - 2.0f * UI_BOX_LR_BORDER,
1872      ui_draw_text_full(container, tempstring, 0, 0, x2 - x1 - 2.0f * UI_BOX_LR_BORDER,
19901873               JUSTIFY_CENTER, WRAP_TRUNCATE, DRAW_NONE, ARGB_WHITE, ARGB_BLACK, NULL, &text_height);
19911874
19921875      /* draw the thermometer */
r13553r13554
20021885      current_x = bar_left + bar_width * percentage;
20031886
20041887      /* fill in the percentage */
2005      machine.render().ui_container().add_rect(bar_left, bar_top, current_x, bar_bottom, UI_SLIDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
1888      container->add_rect(bar_left, bar_top, current_x, bar_bottom, UI_SLIDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
20061889
20071890      /* draw the top and bottom lines */
2008      machine.render().ui_container().add_line(bar_left, bar_top, bar_left + bar_width, bar_top, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
2009      machine.render().ui_container().add_line(bar_left, bar_bottom, bar_left + bar_width, bar_bottom, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
1891      container->add_line(bar_left, bar_top, bar_left + bar_width, bar_top, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
1892      container->add_line(bar_left, bar_bottom, bar_left + bar_width, bar_bottom, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
20101893
20111894      /* draw default marker */
2012      machine.render().ui_container().add_line(default_x, bar_area_top, default_x, bar_top, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
2013      machine.render().ui_container().add_line(default_x, bar_bottom, default_x, bar_area_top + bar_area_height, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
1895      container->add_line(default_x, bar_area_top, default_x, bar_top, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
1896      container->add_line(default_x, bar_bottom, default_x, bar_area_top + bar_area_height, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
20141897
20151898      /* draw the actual text */
2016      ui_draw_text_full(&machine.render().ui_container(), tempstring, x1 + UI_BOX_LR_BORDER, y1 + line_height, x2 - x1 - 2.0f * UI_BOX_LR_BORDER,
1899      ui_draw_text_full(container, tempstring, x1 + UI_BOX_LR_BORDER, y1 + line_height, x2 - x1 - 2.0f * UI_BOX_LR_BORDER,
20171900               JUSTIFY_CENTER, WRAP_WORD, DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, NULL, &text_height);
20181901   }
20191902}
r13553r13554
20241907    menu
20251908-------------------------------------------------*/
20261909
2027static void menu_video_targets(running_machine &machine, ui_menu *menu, void *parameter, void *state)
1910void ui_menu_video_targets::handle()
20281911{
2029   const ui_menu_event *menu_event;
2030
2031   /* if the menu isn't built, populate now */
2032   if (!menu->populated())
2033      menu_video_targets_populate(machine, menu);
2034
20351912   /* process the menu */
2036   menu_event = menu->process(0);
1913   const ui_menu_event *menu_event = process(0);
20371914   if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT)
2038      ui_menu::stack_push(ui_menu_alloc(machine, menu->container, menu_video_options, menu_event->itemref));
1915      ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_video_options(machine(), container, static_cast<render_target *>(menu_event->itemref))));
20391916}
20401917
20411918
r13553r13554
20441921    video targets menu
20451922-------------------------------------------------*/
20461923
2047static void menu_video_targets_populate(running_machine &machine, ui_menu *menu)
1924ui_menu_video_targets::ui_menu_video_targets(running_machine &machine, render_container *container) : ui_menu(machine, container)
20481925{
1926}
1927
1928void ui_menu_video_targets::populate()
1929{
20491930   int targetnum;
20501931
20511932   /* find the targets */
20521933   for (targetnum = 0; ; targetnum++)
20531934   {
2054      render_target *target = machine.render().target_by_index(targetnum);
1935      render_target *target = machine().render().target_by_index(targetnum);
20551936      char buffer[40];
20561937
20571938      /* stop when we run out */
r13553r13554
20601941
20611942      /* add a menu item */
20621943      sprintf(buffer, "Screen #%d", targetnum);
2063      menu->item_append(buffer, NULL, 0, target);
1944      item_append(buffer, NULL, 0, target);
20641945   }
20651946}
20661947
1948ui_menu_video_targets::~ui_menu_video_targets()
1949{
1950}
20671951
20681952/*-------------------------------------------------
20691953    menu_video_options - handle the video options
20701954    menu
20711955-------------------------------------------------*/
20721956
2073static void menu_video_options(running_machine &machine, ui_menu *menu, void *parameter, void *state)
1957void ui_menu_video_options::handle()
20741958{
2075   render_target *target = (parameter != NULL) ? (render_target *)parameter : machine.render().first_target();
2076   const ui_menu_event *menu_event;
2077   int changed = FALSE;
1959   bool changed = false;
20781960
2079   /* if the menu isn't built, populate now */
2080   if (!menu->populated())
2081      menu_video_options_populate(machine, menu, target);
2082
20831961   /* process the menu */
2084   menu_event = menu->process(0);
1962   const ui_menu_event *menu_event = process(0);
20851963   if (menu_event != NULL && menu_event->itemref != NULL)
20861964   {
20871965      switch ((FPTR)menu_event->itemref)
r13553r13554
20951973               if (target->is_ui_target())
20961974               {
20971975                  render_container::user_settings settings;
2098                  machine.render().ui_container().get_user_settings(settings);
1976                  container->get_user_settings(settings);
20991977                  settings.m_orientation = orientation_add(delta ^ ROT180, settings.m_orientation);
2100                  machine.render().ui_container().set_user_settings(settings);
1978                  container->set_user_settings(settings);
21011979               }
2102               changed = TRUE;
1980               changed = true;
21031981            }
21041982            break;
21051983
r13553r13554
21081986            if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)
21091987            {
21101988               target->set_backdrops_enabled(!target->backdrops_enabled());
2111               changed = TRUE;
1989               changed = true;
21121990            }
21131991            break;
21141992
r13553r13554
21161994            if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)
21171995            {
21181996               target->set_overlays_enabled(!target->overlays_enabled());
2119               changed = TRUE;
1997               changed = true;
21201998            }
21211999            break;
21222000
r13553r13554
21242002            if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)
21252003            {
21262004               target->set_bezels_enabled(!target->bezels_enabled());
2127               changed = TRUE;
2005               changed = true;
21282006            }
21292007            break;
21302008
r13553r13554
21322010            if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)
21332011            {
21342012               target->set_cpanels_enabled(!target->cpanels_enabled());
2135               changed = TRUE;
2013               changed = true;
21362014            }
21372015            break;
21382016
r13553r13554
21402018            if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)
21412019            {
21422020               target->set_marquees_enabled(!target->marquees_enabled());
2143               changed = TRUE;
2021               changed = true;
21442022            }
21452023            break;
21462024
r13553r13554
21482026            if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)
21492027            {
21502028               target->set_zoom_to_screen(!target->zoom_to_screen());
2151               changed = TRUE;
2029               changed = true;
21522030            }
21532031            break;
21542032
r13553r13554
21572035            if (menu_event->iptkey == IPT_UI_SELECT && (int)(FPTR)menu_event->itemref >= VIDEO_ITEM_VIEW)
21582036            {
21592037               target->set_view((FPTR)menu_event->itemref - VIDEO_ITEM_VIEW);
2160               changed = TRUE;
2038               changed = true;
21612039            }
21622040            break;
21632041      }
r13553r13554
21652043
21662044   /* if something changed, rebuild the menu */
21672045   if (changed)
2168      menu->reset(UI_MENU_RESET_REMEMBER_REF);
2046      reset(UI_MENU_RESET_REMEMBER_REF);
21692047}
21702048
21712049
r13553r13554
21742052    video options menu
21752053-------------------------------------------------*/
21762054
2177static void menu_video_options_populate(running_machine &machine, ui_menu *menu, render_target *target)
2055ui_menu_video_options::ui_menu_video_options(running_machine &machine, render_container *container, render_target *_target) : ui_menu(machine, container)
21782056{
2179   const char *subtext = "";
2057   target = _target;
2058}
2059
2060void ui_menu_video_options::populate()
2061{
2062    const char *subtext = "";
21802063   astring tempstring;
21812064   int viewnum;
21822065   int enabled;
r13553r13554
21902073
21912074      /* create a string for the item, replacing underscores with spaces */
21922075      tempstring.cpy(name).replace(0, "_", " ");
2193      menu->item_append(tempstring, NULL, 0, (void *)(FPTR)(VIDEO_ITEM_VIEW + viewnum));
2076      item_append(tempstring, NULL, 0, (void *)(FPTR)(VIDEO_ITEM_VIEW + viewnum));
21942077   }
21952078
21962079   /* add a separator */
2197   menu->item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL);
2080   item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL);
21982081
21992082   /* add a rotate item */
22002083   switch (target->orientation())
r13553r13554
22042087      case ROT180:   subtext = "180" UTF8_DEGREES;      break;
22052088      case ROT270:   subtext = "CCW 90" UTF8_DEGREES;   break;
22062089   }
2207   menu->item_append("Rotate", subtext, MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_ROTATE);
2090   item_append("Rotate", subtext, MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_ROTATE);
22082091
22092092   /* backdrop item */
22102093   enabled = target->backdrops_enabled();
2211   menu->item_append("Backdrops", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_BACKDROPS);
2094   item_append("Backdrops", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_BACKDROPS);
22122095
22132096   /* overlay item */
22142097   enabled = target->overlays_enabled();
2215   menu->item_append("Overlays", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_OVERLAYS);
2098   item_append("Overlays", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_OVERLAYS);
22162099
22172100   /* bezel item */
22182101   enabled = target->bezels_enabled();
2219   menu->item_append("Bezels", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_BEZELS);
2102   item_append("Bezels", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_BEZELS);
22202103
22212104   /* cpanel item */
22222105   enabled = target->cpanels_enabled();
2223   menu->item_append("CPanels", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_CPANELS);
2106   item_append("CPanels", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_CPANELS);
22242107
22252108   /* marquee item */
22262109   enabled = target->marquees_enabled();
2227   menu->item_append("Marquees", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_MARQUEES);
2110   item_append("Marquees", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_MARQUEES);
22282111
22292112   /* cropping */
22302113   enabled = target->zoom_to_screen();
2231   menu->item_append("View", enabled ? "Cropped" : "Full", enabled ? MENU_FLAG_RIGHT_ARROW : MENU_FLAG_LEFT_ARROW, (void *)VIDEO_ITEM_ZOOM);
2114   item_append("View", enabled ? "Cropped" : "Full", enabled ? MENU_FLAG_RIGHT_ARROW : MENU_FLAG_LEFT_ARROW, (void *)VIDEO_ITEM_ZOOM);
22322115}
22332116
2117ui_menu_video_options::~ui_menu_video_options()
2118{
2119}
22342120
22352121/*-------------------------------------------------
22362122    menu_crosshair - handle the crosshair settings
22372123    menu
22382124-------------------------------------------------*/
22392125
2240static void menu_crosshair(running_machine &machine, ui_menu *menu, void *parameter, void *state)
2126void ui_menu_crosshair::handle()
22412127{
2242   const ui_menu_event *menu_event;
2243
2244   /* if the menu isn't built, populate now */
2245   if (!menu->populated())
2246      menu_crosshair_populate(machine, menu);
2247
22482128   /* process the menu */
2249   menu_event = menu->process(UI_MENU_PROCESS_LR_REPEAT);
2129   const ui_menu_event *menu_event = process(UI_MENU_PROCESS_LR_REPEAT);
22502130
22512131   /* handle events */
22522132   if (menu_event != NULL && menu_event->itemref != NULL)
22532133   {
22542134      crosshair_user_settings settings;
22552135      crosshair_item_data *data = (crosshair_item_data *)menu_event->itemref;
2256      int changed = FALSE;
2257      //int set_def = FALSE;
2136      int changed = false;
2137      //int set_def = false;
22582138      int newval = data->cur;
22592139
22602140      /* retreive the user settings */
2261      crosshair_get_user_settings(machine, data->player, &settings);
2141      crosshair_get_user_settings(machine(), data->player, &settings);
22622142
22632143      switch (menu_event->iptkey)
22642144      {
22652145         /* if selected, reset to default value */
22662146         case IPT_UI_SELECT:
22672147            newval = data->defvalue;
2268            //set_def = TRUE;
2148            //set_def = true;
22692149            break;
22702150
22712151         /* left decrements */
22722152         case IPT_UI_LEFT:
2273            newval -= machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1;
2153            newval -= machine().input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1;
22742154            break;
22752155
22762156         /* right increments */
22772157         case IPT_UI_RIGHT:
2278            newval += machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1;
2158            newval += machine().input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1;
22792159            break;
22802160      }
22812161
r13553r13554
22932173            /* visibility state */
22942174            case CROSSHAIR_ITEM_VIS:
22952175               settings.mode = newval;
2296               changed = TRUE;
2176               changed = true;
22972177               break;
22982178
22992179            /* auto time */
23002180            case CROSSHAIR_ITEM_AUTO_TIME:
23012181               settings.auto_time = newval;
2302               changed = TRUE;
2182               changed = true;
23032183               break;
23042184         }
23052185      }
r13553r13554
23112191         {
23122192            /* clear the name string to reset to default crosshair */
23132193            settings.name[0] = 0;
2314            changed = TRUE;
2194            changed = true;
23152195         }
23162196         else if (menu_event->iptkey == IPT_UI_LEFT)
23172197         {
23182198            strcpy(settings.name, data->last_name);
2319            changed = TRUE;
2199            changed = true;
23202200         }
23212201         else if (menu_event->iptkey == IPT_UI_RIGHT)
23222202         {
23232203            strcpy(settings.name, data->next_name);
2324            changed = TRUE;
2204            changed = true;
23252205         }
23262206      }
23272207
23282208      if (changed)
23292209      {
23302210         /* save the user settings */
2331         crosshair_set_user_settings(machine, data->player, &settings);
2211         crosshair_set_user_settings(machine(), data->player, &settings);
23322212
23332213         /* rebuild the menu */
2334         menu->reset(UI_MENU_RESET_REMEMBER_POSITION);
2214         reset(UI_MENU_RESET_REMEMBER_POSITION);
23352215      }
23362216   }
23372217}
r13553r13554
23422222    crosshair settings menu
23432223-------------------------------------------------*/
23442224
2345static void menu_crosshair_populate(running_machine &machine, ui_menu *menu)
2225ui_menu_crosshair::ui_menu_crosshair(running_machine &machine, render_container *container) : ui_menu(machine, container)
23462226{
2227}
2228
2229void ui_menu_crosshair::populate()
2230{
23472231   crosshair_user_settings settings;
23482232   crosshair_item_data *data;
23492233   char temp_text[16];
23502234   int player;
2351   UINT8 use_auto = FALSE;
2235   UINT8 use_auto = false;
23522236   UINT32 flags = 0;
23532237
23542238   /* loop over player and add the manual items */
23552239   for (player = 0; player < MAX_PLAYERS; player++)
23562240   {
23572241      /* get the user settings */
2358      crosshair_get_user_settings(machine, player, &settings);
2242      crosshair_get_user_settings(machine(), player, &settings);
23592243
23602244      /* add menu items for usable crosshairs */
23612245      if (settings.used)
r13553r13554
23642248         static const char *const vis_text[] = { "Off", "On", "Auto" };
23652249
23662250         /* track if we need the auto time menu */
2367         if (settings.mode == CROSSHAIR_VISIBILITY_AUTO) use_auto = TRUE;
2251         if (settings.mode == CROSSHAIR_VISIBILITY_AUTO) use_auto = true;
23682252
23692253         /* CROSSHAIR_ITEM_VIS - allocate a data item and fill it */
2370         data = (crosshair_item_data *)menu->m_pool_alloc(sizeof(*data));
2254         data = (crosshair_item_data *)m_pool_alloc(sizeof(*data));
23712255         data->type = CROSSHAIR_ITEM_VIS;
23722256         data->player = player;
23732257         data->min = CROSSHAIR_VISIBILITY_OFF;
r13553r13554
23832267
23842268         /* add CROSSHAIR_ITEM_VIS menu */
23852269         sprintf(temp_text, "P%d Visibility", player + 1);
2386         menu->item_append(temp_text, vis_text[settings.mode], flags, data);
2270         item_append(temp_text, vis_text[settings.mode], flags, data);
23872271
23882272         /* CROSSHAIR_ITEM_PIC - allocate a data item and fill it */
2389         data = (crosshair_item_data *)menu->m_pool_alloc(sizeof(*data));
2273         data = (crosshair_item_data *)m_pool_alloc(sizeof(*data));
23902274         data->type = CROSSHAIR_ITEM_PIC;
23912275         data->player = player;
23922276         data->last_name[0] = 0;
r13553r13554
23952279         /* search for crosshair graphics */
23962280
23972281         /* open a path to the crosshairs */
2398         file_enumerator path(machine.options().crosshair_path());
2282         file_enumerator path(machine().options().crosshair_path());
23992283         const osd_directory_entry *dir;
24002284         /* reset search flags */
2401         int using_default = FALSE;
2402         int finished = FALSE;
2403         int found = FALSE;
2285         int using_default = false;
2286         int finished = false;
2287         int found = false;
24042288
24052289         /* if we are using the default, then we just need to find the first in the list */
24062290         if (strlen(settings.name) == 0)
2407            using_default = TRUE;
2291            using_default = true;
24082292
24092293         /* look for the current name, then remember the name before */
24102294         /* and find the next name */
r13553r13554
24282312                  /* get the next name */
24292313                  strncpy(data->next_name, dir->name, length);
24302314                  data->next_name[length] = 0;
2431                  finished = TRUE;
2315                  finished = true;
24322316               }
24332317               else if (!strncmp(dir->name, settings.name, length))
24342318               {
24352319                  /* we found the current name */
24362320                  /* so loop once more to find the next name */
2437                  found = TRUE;
2321                  found = true;
24382322               }
24392323               else
24402324                  /* remember last name */
r13553r13554
24492333         if (!found && !using_default)
24502334         {
24512335            data->next_name[0] = 0;
2452            finished = TRUE;
2336            finished = true;
24532337         }
24542338         /* setup the selection flags */
24552339         flags = 0;
r13553r13554
24602344
24612345         /* add CROSSHAIR_ITEM_PIC menu */
24622346         sprintf(temp_text, "P%d Crosshair", player + 1);
2463         menu->item_append(temp_text, using_default ? "DEFAULT" : settings.name, flags, data);
2347         item_append(temp_text, using_default ? "DEFAULT" : settings.name, flags, data);
24642348      }
24652349   }
24662350   if (use_auto)
24672351   {
24682352      /* any player can be used to get the autotime */
2469      crosshair_get_user_settings(machine, 0, &settings);
2353      crosshair_get_user_settings(machine(), 0, &settings);
24702354
24712355      /* CROSSHAIR_ITEM_AUTO_TIME - allocate a data item and fill it */
2472      data = (crosshair_item_data *)menu->m_pool_alloc(sizeof(*data));
2356      data = (crosshair_item_data *)m_pool_alloc(sizeof(*data));
24732357      data->type = CROSSHAIR_ITEM_AUTO_TIME;
24742358      data->min = CROSSHAIR_VISIBILITY_AUTOTIME_MIN;
24752359      data->max = CROSSHAIR_VISIBILITY_AUTOTIME_MAX;
r13553r13554
24842368
24852369      /* add CROSSHAIR_ITEM_AUTO_TIME menu */
24862370      sprintf(temp_text, "%d", settings.auto_time);
2487      menu->item_append("Visible Delay", temp_text, flags, data);
2371      item_append("Visible Delay", temp_text, flags, data);
24882372   }
24892373//  else
24902374//      /* leave a blank filler line when not in auto time so size does not rescale */
2491//      menu->item_append("", "", NULL, NULL);
2375//      item_append("", "", NULL, NULL);
24922376}
24932377
2378ui_menu_crosshair::~ui_menu_crosshair()
2379{
2380}
24942381
24952382/*-------------------------------------------------
24962383    menu_quit_game - handle the "menu" for
24972384    quitting the game
24982385-------------------------------------------------*/
24992386
2500static void menu_quit_game(running_machine &machine, ui_menu *menu, void *parameter, void *state)
2387ui_menu_quit_game::ui_menu_quit_game(running_machine &machine, render_container *container) : ui_menu(machine, container)
25012388{
2389}
2390
2391ui_menu_quit_game::~ui_menu_quit_game()
2392{
2393}
2394
2395void ui_menu_quit_game::populate()
2396{
2397}
2398
2399void ui_menu_quit_game::handle()
2400{
25022401   /* request a reset */
2503   machine.schedule_exit();
2402   machine().schedule_exit();
25042403
25052404   /* reset the menu stack */
2506   ui_menu::stack_reset(machine);
2405   ui_menu::stack_reset(machine());
25072406}
25082407
25092408
r13553r13554
25122411    menu
25132412-------------------------------------------------*/
25142413
2515static void menu_select_game(running_machine &machine, ui_menu *menu, void *parameter, void *state)
2414void ui_menu_select_game::handle()
25162415{
2517   select_game_state *menustate;
2518   const ui_menu_event *menu_event;
2519
2520   /* if no state, allocate some */
2521   if (state == NULL)
2522   {
2523      state = menu->alloc_state(sizeof(*menustate) + sizeof(menustate->driverlist) * driver_list::total(), NULL);
2524      if (parameter != NULL)
2525         strcpy(((select_game_state *)state)->search, (const char *)parameter);
2526      ((select_game_state *)state)->matchlist[0] = -1;
2527   }
2528   menustate = (select_game_state *)state;
2529
2530   /* if the menu isn't built, populate now */
2531   if (!menu->populated())
2532      menu_select_game_populate(machine, menu, menustate);
2533
25342416   /* ignore pause keys by swallowing them before we process the menu */
2535   ui_input_pressed(machine, IPT_UI_PAUSE);
2417   ui_input_pressed(machine(), IPT_UI_PAUSE);
25362418
25372419   /* process the menu */
2538   menu_event = menu->process(0);
2420   const ui_menu_event *menu_event = process(0);
25392421   if (menu_event != NULL && menu_event->itemref != NULL)
25402422   {
25412423      /* reset the error on any future menu_event */
2542      if (menustate->error)
2543         menustate->error = FALSE;
2424      if (error)
2425         error = false;
25442426
25452427      /* handle selections */
25462428      else if (menu_event->iptkey == IPT_UI_SELECT)
r13553r13554
25492431
25502432         /* special case for configure inputs */
25512433         if ((FPTR)driver == 1)
2552            ui_menu::stack_push(ui_menu_alloc(menu->machine(), menu->container, menu_input_groups, NULL));
2434            ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_input_groups(machine(), container)));
25532435
25542436         /* anything else is a driver */
25552437         else
25562438         {
25572439            // audit the game first to see if we're going to work
2558            driver_enumerator enumerator(machine.options(), *driver);
2440            driver_enumerator enumerator(machine().options(), *driver);
25592441            enumerator.next();
25602442            media_auditor auditor(enumerator);
25612443            media_auditor::summary summary = auditor.audit_media(AUDIT_VALIDATE_FAST);
r13553r13554
25632445            // if everything looks good, schedule the new driver
25642446            if (summary == media_auditor::CORRECT || summary == media_auditor::BEST_AVAILABLE)
25652447            {
2566               machine.schedule_new_driver(*driver);
2567               ui_menu::stack_reset(machine);
2448               machine().schedule_new_driver(*driver);
2449               ui_menu::stack_reset(machine());
25682450            }
25692451
25702452            // otherwise, display an error
25712453            else
25722454            {
2573               menu->reset(UI_MENU_RESET_REMEMBER_REF);
2574               menustate->error = TRUE;
2455               reset(UI_MENU_RESET_REMEMBER_REF);
2456               error = true;
25752457            }
25762458         }
25772459      }
25782460
25792461      /* escape pressed with non-empty text clears the text */
2580      else if (menu_event->iptkey == IPT_UI_CANCEL && menustate->search[0] != 0)
2462      else if (menu_event->iptkey == IPT_UI_CANCEL && search[0] != 0)
25812463      {
25822464         /* since we have already been popped, we must recreate ourself from scratch */
2583         ui_menu::stack_push(ui_menu_alloc(menu->machine(), menu->container, menu_select_game, NULL));
2465         ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_select_game(machine(), container, NULL)));
25842466      }
25852467
25862468      /* typed characters append to the buffer */
25872469      else if (menu_event->iptkey == IPT_SPECIAL)
25882470      {
2589         int buflen = strlen(menustate->search);
2471         int buflen = strlen(search);
25902472
25912473         /* if it's a backspace and we can handle it, do so */
25922474         if ((menu_event->unichar == 8 || menu_event->unichar == 0x7f) && buflen > 0)
25932475         {
2594            *(char *)utf8_previous_char(&menustate->search[buflen]) = 0;
2595            menustate->rerandomize = TRUE;
2596            menu->reset(UI_MENU_RESET_SELECT_FIRST);
2476            *(char *)utf8_previous_char(&search[buflen]) = 0;
2477            rerandomize = true;
2478            reset(UI_MENU_RESET_SELECT_FIRST);
25972479         }
25982480
25992481         /* if it's any other key and we're not maxed out, update */
26002482         else if (menu_event->unichar >= ' ' && menu_event->unichar < 0x7f)
26012483         {
2602            buflen += utf8_from_uchar(&menustate->search[buflen], ARRAY_LENGTH(menustate->search) - buflen, menu_event->unichar);
2603            menustate->search[buflen] = 0;
2604            menu->reset(UI_MENU_RESET_SELECT_FIRST);
2484            buflen += utf8_from_uchar(&search[buflen], ARRAY_LENGTH(search) - buflen, menu_event->unichar);
2485            search[buflen] = 0;
2486            reset(UI_MENU_RESET_SELECT_FIRST);
26052487         }
26062488      }
26072489   }
26082490
26092491   /* if we're in an error state, overlay an error message */
2610   if (menustate->error)
2611      ui_draw_text_box(&machine.render().ui_container(),
2492   if (error)
2493      ui_draw_text_box(container,
26122494                   "The selected game is missing one or more required ROM or CHD images. "
26132495                       "Please select a different game.\n\nPress any key to continue.",
26142496                       JUSTIFY_CENTER, 0.5f, 0.5f, UI_RED_COLOR);
r13553r13554
26192501    menu_select_game_populate - populate the game
26202502    select menu
26212503-------------------------------------------------*/
2504driver_enumerator *ui_menu_select_game::drivlist;
26222505
2623static void menu_select_game_populate(running_machine &machine, ui_menu *menu, select_game_state *menustate)
2506ui_menu_select_game::ui_menu_select_game(running_machine &machine, render_container *container, const char *gamename) : ui_menu(machine, container)
26242507{
2508   driverlist = (const game_driver **)m_pool_alloc((driver_list::total()+1)*sizeof(const game_driver *));
2509   build_driver_list();
2510   if(gamename)
2511      strcpy(search, gamename);
2512   matchlist[0] = -1;
2513}
2514
2515void ui_menu_select_game::populate()
2516{
26252517   int matchcount;
26262518   int curitem;
26272519
2628   /* update our driver list if necessary */
2629   if (menustate->driverlist[0] == NULL)
2630      menu_select_game_build_driver_list(menu, menustate);
2631   for (curitem = matchcount = 0; menustate->driverlist[curitem] != NULL && matchcount < VISIBLE_GAMES_IN_LIST; curitem++)
2632      if (!(menustate->driverlist[curitem]->flags & GAME_NO_STANDALONE))
2520   for (curitem = matchcount = 0; driverlist[curitem] != NULL && matchcount < VISIBLE_GAMES_IN_LIST; curitem++)
2521      if (!(driverlist[curitem]->flags & GAME_NO_STANDALONE))
26332522         matchcount++;
26342523
26352524   /* if nothing there, add a single multiline item and return */
r13553r13554
26422531               emulator_info::get_gamesnoun(),
26432532               emulator_info::get_configname(),
26442533               emulator_info::get_appname(),emulator_info::get_appname() );
2645      menu->item_append(txt.cstr(), NULL, MENU_FLAG_MULTILINE | MENU_FLAG_REDTEXT, NULL);
2534      item_append(txt.cstr(), NULL, MENU_FLAG_MULTILINE | MENU_FLAG_REDTEXT, NULL);
26462535      return;
26472536   }
26482537
26492538   /* otherwise, rebuild the match list */
26502539   assert(drivlist != NULL);
2651   if (menustate->search[0] != 0 || menustate->matchlist[0] == -1 || menustate->rerandomize)
2652      drivlist->find_approximate_matches(menustate->search, matchcount, menustate->matchlist);
2653   menustate->rerandomize = FALSE;
2540   if (search[0] != 0 || matchlist[0] == -1 || rerandomize)
2541      drivlist->find_approximate_matches(search, matchcount, matchlist);
2542   rerandomize = false;
26542543
26552544   /* iterate over entries */
26562545   for (curitem = 0; curitem < matchcount; curitem++)
26572546   {
2658      int curmatch = menustate->matchlist[curitem];
2547      int curmatch = matchlist[curitem];
26592548      if (curmatch != -1)
26602549      {
26612550         int cloneof = drivlist->non_bios_clone(curmatch);
2662         menu->item_append(drivlist->driver(curmatch).name, drivlist->driver(curmatch).description, (cloneof == -1) ? 0 : MENU_FLAG_INVERT, (void *)&drivlist->driver(curmatch));
2551         item_append(drivlist->driver(curmatch).name, drivlist->driver(curmatch).description, (cloneof == -1) ? 0 : MENU_FLAG_INVERT, (void *)&drivlist->driver(curmatch));
26632552      }
26642553   }
26652554
26662555   /* if we're forced into this, allow general input configuration as well */
26672556   if (ui_menu::stack_has_special_main_menu())
26682557   {
2669      menu->item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL);
2670      menu->item_append("Configure General Inputs", NULL, 0, (void *)1);
2558      item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL);
2559      item_append("Configure General Inputs", NULL, 0, (void *)1);
26712560   }
26722561
26732562   /* configure the custom rendering */
2674   menu->set_custom_render(menu_select_game_custom_render, ui_get_line_height(machine) + 3.0f * UI_BOX_TB_BORDER, 4.0f * ui_get_line_height(machine) + 3.0f * UI_BOX_TB_BORDER);
2563   customtop = ui_get_line_height(machine()) + 3.0f * UI_BOX_TB_BORDER;
2564   custombottom = 4.0f * ui_get_line_height(machine()) + 3.0f * UI_BOX_TB_BORDER;
26752565}
26762566
2567ui_menu_select_game::~ui_menu_select_game()
2568{
2569   global_free(drivlist);
2570}
26772571
26782572/*-------------------------------------------------
26792573    menu_select_game_build_driver_list - build a
26802574    list of available drivers
26812575-------------------------------------------------*/
26822576
2683static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state *menustate)
2577void ui_menu_select_game::build_driver_list()
26842578{
26852579   // start with an empty list
2686   // hack alert: use new directly here to avoid reporting this one-time static memory as unfreed
2687   if (drivlist == NULL)
2688      drivlist = global_alloc(driver_enumerator(menu->machine().options()));
2580   drivlist = global_alloc(driver_enumerator(machine().options()));
26892581   drivlist->exclude_all();
26902582
26912583   /* open a path to the ROMs and find them in the array */
2692   file_enumerator path(menu->machine().options().media_path());
2584   file_enumerator path(machine().options().media_path());
26932585   const osd_directory_entry *dir;
26942586
26952587   /* iterate while we get new objects */
r13553r13554
27132605   drivlist->reset();
27142606   int listnum = 0;
27152607   while (drivlist->next())
2716      menustate->driverlist[listnum++] = &drivlist->driver();
2608      driverlist[listnum++] = &drivlist->driver();
27172609
27182610   /* NULL-terminate */
2719   menustate->driverlist[listnum] = NULL;
2611   driverlist[listnum] = NULL;
27202612}
27212613
27222614
r13553r13554
27252617    special rendering
27262618-------------------------------------------------*/
27272619
2728static void menu_select_game_custom_render(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
2620void ui_menu_select_game::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
27292621{
2730   select_game_state *menustate = (select_game_state *)state;
27312622   const game_driver *driver;
27322623   float width, maxwidth;
27332624   float x1, y1, x2, y2;
r13553r13554
27362627   int line;
27372628
27382629   /* display the current typeahead */
2739   if (menustate->search[0] != 0)
2740      sprintf(&tempbuf[0][0], "Type name or select: %s_", menustate->search);
2630   if (search[0] != 0)
2631      sprintf(&tempbuf[0][0], "Type name or select: %s_", search);
27412632   else
27422633      sprintf(&tempbuf[0][0], "Type name or select: (random)");
27432634
27442635   /* get the size of the text */
2745   ui_draw_text_full(&machine.render().ui_container(), &tempbuf[0][0], 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE,
2636   ui_draw_text_full(container, &tempbuf[0][0], 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE,
27462637                 DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &width, NULL);
27472638   width += 2 * UI_BOX_LR_BORDER;
27482639   maxwidth = MAX(width, origx2 - origx1);
r13553r13554
27542645   y2 = origy1 - UI_BOX_TB_BORDER;
27552646
27562647   /* draw a box */
2757   ui_draw_outlined_box(&machine.render().ui_container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR);
2648   ui_draw_outlined_box(container, x1, y1, x2, y2, UI_BACKGROUND_COLOR);
27582649
27592650   /* take off the borders */
27602651   x1 += UI_BOX_LR_BORDER;
r13553r13554
27632654   y2 -= UI_BOX_TB_BORDER;
27642655
27652656   /* draw the text within it */
2766   ui_draw_text_full(&machine.render().ui_container(), &tempbuf[0][0], x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_TRUNCATE,
2657   ui_draw_text_full(container, &tempbuf[0][0], x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_TRUNCATE,
27672658                 DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, NULL, NULL);
27682659
27692660   /* determine the text to render below */
r13553r13554
28302721   maxwidth = origx2 - origx1;
28312722   for (line = 0; line < 4; line++)
28322723   {
2833      ui_draw_text_full(&machine.render().ui_container(), &tempbuf[line][0], 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE,
2724      ui_draw_text_full(container, &tempbuf[line][0], 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE,
28342725                    DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &width, NULL);
28352726      width += 2 * UI_BOX_LR_BORDER;
28362727      maxwidth = MAX(maxwidth, width);
r13553r13554
28502741      color = UI_YELLOW_COLOR;
28512742   if (driver != NULL && (driver->flags & (GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION)) != 0)
28522743      color = UI_RED_COLOR;
2853   ui_draw_outlined_box(&machine.render().ui_container(), x1, y1, x2, y2, color);
2744   ui_draw_outlined_box(container, x1, y1, x2, y2, color);
28542745
28552746   /* take off the borders */
28562747   x1 += UI_BOX_LR_BORDER;
r13553r13554
28612752   /* draw all lines */
28622753   for (line = 0; line < 4; line++)
28632754   {
2864      ui_draw_text_full(&machine.render().ui_container(), &tempbuf[line][0], x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_TRUNCATE,
2755      ui_draw_text_full(container, &tempbuf[line][0], x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_TRUNCATE,
28652756                    DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, NULL, NULL);
2866      y1 += ui_get_line_height(machine);
2757      y1 += ui_get_line_height(machine());
28672758   }
28682759}
28692760
src/emu/uiswlist.c
r13553r13554
1212#include "emu.h"
1313#include "ui.h"
1414#include "uimenu.h"
15#include "uiswlist.h"
1516#include "softlist.h"
1617
1718
r13553r13554
2728    TYPE DEFINITIONS
2829***************************************************************************/
2930
30/* state of a software entry */
31typedef struct _software_entry_state software_entry_state;
32struct _software_entry_state
31ui_menu_software_parts::ui_menu_software_parts(running_machine &machine, render_container *container, ui_menu_software_entry_info *_entry) : ui_menu(machine, container)
3332{
34   software_entry_state *next;
33   entry = _entry;
34}
3535
36   const char *short_name;
37   const char *long_name;
38   const char *interface;
39   char *list_name;
40   device_image_interface* image;
41};
42
43/* state of the software menu */
44typedef struct _software_menu_state software_menu_state;
45struct _software_menu_state
36void ui_menu_software_parts::populate()
4637{
47   char *list_name;   /* currently selected list */
48   device_image_interface* image;
49   software_entry_state *entrylist;
50   char filename_buffer[1024];
51   int ordered_by_shortname;
52   int reorder;
53};
38   if(entry->list_name) {
39      software_list *list = software_list_open(machine().options(), entry->list_name, false, NULL);
5440
55/* state of a software part */
56typedef struct _software_part_state software_part_state;
57struct _software_part_state
58{
59   const char *part_name;
60   const char *interface;
61};
62
63
64static void ui_mess_menu_populate_software_parts(running_machine &machine, ui_menu *menu, const char *swlist, const char *swinfo, const char *interface)
65{
66   software_list *list = software_list_open(machine.options(), swlist, FALSE, NULL);
67
68   if (list)
69   {
70      software_info *info = software_list_find(list, swinfo, NULL);
71
72      if (info)
41      if (list)
7342      {
74         for (software_part *swpart = software_find_part(info, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart))
43         software_info *info = software_list_find(list, entry->short_name, NULL);
44
45         if (info)
7546         {
76            if (strcmp(interface, swpart->interface_) == 0)
47            for (software_part *swpart = software_find_part(info, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart))
7748            {
78               software_part_state *entry = (software_part_state *) menu->m_pool_alloc(sizeof(*entry));
79               // check if the available parts have specific part_id to be displayed (e.g. "Map Disc", "Bonus Disc", etc.)
80               // if not, we simply display "part_name"; if yes we display "part_name (part_id)"
81               astring menu_part_name(swpart->name);
82               if (software_part_get_feature(swpart, "part_id") != NULL)
49               if (strcmp(entry->interface, swpart->interface_) == 0)
8350               {
84                  menu_part_name.cat(" (");
85                  menu_part_name.cat(software_part_get_feature(swpart, "part_id"));
86                  menu_part_name.cat(")");
51                  software_part_info *entry = (software_part_info *) m_pool_alloc(sizeof(*entry));
52                  // check if the available parts have specific part_id to be displayed (e.g. "Map Disc", "Bonus Disc", etc.)
53                  // if not, we simply display "part_name"; if yes we display "part_name (part_id)"
54                  astring menu_part_name(swpart->name);
55                  if (software_part_get_feature(swpart, "part_id") != NULL)
56                  {
57                     menu_part_name.cat(" (");
58                     menu_part_name.cat(software_part_get_feature(swpart, "part_id"));
59                     menu_part_name.cat(")");
60                  }
61                  entry->part_name = pool_strdup(swpart->name);   // part_name is later used to build up the filename to load, so we use swpart->name!
62                  entry->interface = pool_strdup(swpart->interface_);
63                  item_append(info->shortname, menu_part_name.cstr(), 0, entry);
8764               }
88               entry->part_name = menu->pool_strdup(swpart->name);   // part_name is later used to build up the filename to load, so we use swpart->name!
89               entry->interface = menu->pool_strdup(swpart->interface_);
90               menu->item_append(info->shortname, menu_part_name.cstr(), 0, entry);
9165            }
9266         }
93      }
9467
95      software_list_close(list);
68         software_list_close(list);
69      }
9670   }
9771}
9872
99void ui_mess_menu_software_parts(running_machine &machine, ui_menu *menu, void *parameter, void *state)
73ui_menu_software_parts::~ui_menu_software_parts()
10074{
101   const ui_menu_event *event;
102   software_entry_state *sw_state = (software_entry_state *)state;
103   const char *swlist = sw_state->list_name;
104   const char *swinfo = sw_state->short_name;
105   const char *interface = sw_state->interface;
75}
10676
107   // generate list of available parts
108   if (!menu->populated())
109   {
110      if (sw_state->list_name)
111      {
112         ui_mess_menu_populate_software_parts(machine, menu, swlist, swinfo, interface);
113      }
114   }
115
77void ui_menu_software_parts::handle()
78{
11679   /* process the menu */
117   event = menu->process(0);
80   const ui_menu_event *event = process(0);
11881
11982   if (event != NULL && event->iptkey == IPT_UI_SELECT && event->itemref != NULL)
12083   {
121      software_part_state *entry = (software_part_state *) event->itemref;
84      software_part_info *pentry = (software_part_info *) event->itemref;
12285
12386      // build the name for the part to be loaded
124      astring temp_name(sw_state->short_name);
87      astring temp_name(entry->short_name);
12588      temp_name.cat(":");
126      temp_name.cat(entry->part_name);
89      temp_name.cat(pentry->part_name);
12790      //printf("%s\n", temp_name.cstr());
12891
129      sw_state->image->load(temp_name.cstr());
92      entry->image->load(temp_name.cstr());
13093   }
13194}
13295
133static int compare_software_entries(const software_entry_state *e1, const software_entry_state *e2, int shortname)
96int ui_menu_software_list::compare_entries(const ui_menu_software_entry_info *e1, const ui_menu_software_entry_info *e2, bool shortname)
13497{
13598   int result;
13699   const char *e1_basename;
r13553r13554
165128
166129/* populate a specific list */
167130
168static software_entry_state *append_software_entry(ui_menu *menu, software_menu_state *menustate,
169                                       software_info *swinfo, char *list_name, device_image_interface* image)
131ui_menu_software_entry_info *ui_menu_software_list::append_software_entry(software_info *swinfo, char *list_name, device_image_interface* image)
170132{
171   software_entry_state *entry = NULL;
172   software_entry_state **entryptr;
133   ui_menu_software_entry_info *entry = NULL;
134   ui_menu_software_entry_info **entryptr;
173135   const char *interface = image->image_interface();
174136
175137   // check if at least one of the parts has the correct interface and add a menu entry only in this case
r13553r13554
178140      if (strcmp(interface, swpart->interface_) == 0)
179141      {
180142         // allocate a new entry
181         entry = (software_entry_state *) menu->m_pool_alloc(sizeof(*entry));
143         entry = (ui_menu_software_entry_info *) m_pool_alloc(sizeof(*entry));
182144         memset(entry, 0, sizeof(*entry));
183145
184         entry->short_name = menu->pool_strdup(swinfo->shortname);
185         entry->long_name = menu->pool_strdup(swinfo->longname);
146         entry->short_name = pool_strdup(swinfo->shortname);
147         entry->long_name = pool_strdup(swinfo->longname);
186148         entry->list_name = list_name;
187149         entry->image = image;
188         entry->interface = menu->pool_strdup(swpart->interface_);
150         entry->interface = pool_strdup(swpart->interface_);
189151         break;
190152      }
191153   }
192154
193155   // find the end of the list
194   entryptr = &menustate->entrylist;
195   while ((*entryptr != NULL) && (compare_software_entries(entry, *entryptr, menustate->ordered_by_shortname) >= 0))
156   entryptr = &entrylist;
157   while ((*entryptr != NULL) && (compare_entries(entry, *entryptr, ordered_by_shortname) >= 0))
196158      entryptr = &(*entryptr)->next;
197159
198160   // insert the entry
r13553r13554
202164   return entry;
203165}
204166
167ui_menu_software_list::ui_menu_software_list(running_machine &machine, render_container *container, char *_list_name, device_image_interface *_image) : ui_menu(machine, container)
168{
169   list_name = _list_name;
170   image = _image;
171   entrylist = NULL;
172   ordered_by_shortname = true;
173}
205174
206static void ui_mess_menu_populate_software_entries(running_machine &machine, ui_menu *menu, software_menu_state *menustate)
175ui_menu_software_list::~ui_menu_software_list()
207176{
208   software_list *list = software_list_open(machine.options(), menustate->list_name, FALSE, NULL);
177}
209178
179void ui_menu_software_list::populate()
180{
181   software_list *list = software_list_open(machine().options(), list_name, false, NULL);
182
210183   // build up the list of entries for the menu
211184   if (list)
212185   {
213186      for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo))
214         append_software_entry(menu, menustate, swinfo, menustate->list_name, menustate->image);
187         append_software_entry(swinfo, list_name, image);
215188
216189      software_list_close(list);
217190   }
218191
219192   // add an entry to change ordering
220   menu->item_append("Switch Item Ordering", NULL, 0, (void *)1);
193   item_append("Switch Item Ordering", NULL, 0, (void *)1);
221194
222195   // append all of the menu entries
223   for (software_entry_state *entry = menustate->entrylist; entry != NULL; entry = entry->next)
224      menu->item_append(entry->short_name, entry->long_name, 0, entry);
196   for (ui_menu_software_entry_info *entry = entrylist; entry != NULL; entry = entry->next)
197      item_append(entry->short_name, entry->long_name, 0, entry);
225198}
226199
227bool swinfo_has_multiple_parts(software_info *swinfo, const char *interface)
200bool ui_menu_software_list::swinfo_has_multiple_parts(software_info *swinfo, const char *interface)
228201{
229202   int count = 0;
230203
r13553r13554
233206      if (strcmp(interface, swpart->interface_) == 0)
234207         count++;
235208   }
236   return (count > 1) ? TRUE : FALSE;
209   return (count > 1) ? true : false;
237210}
238211
239void ui_mess_menu_software_list(running_machine &machine, ui_menu *menu, void *parameter, void *state)
212void ui_menu_software_list::handle()
240213{
241   const ui_menu_event *event;
242   software_menu_state *sw_state = (software_menu_state *)state;
243   const software_entry_state *entry;
244   const software_entry_state *selected_entry = NULL;
214   const ui_menu_software_entry_info *entry;
215   const ui_menu_software_entry_info *selected_entry = NULL;
245216   int bestmatch = 0;
246217
247   if (!menu->populated() || sw_state->reorder)
248   {
249      sw_state->reorder = 0;
250
251      if (sw_state->list_name)
252      {
253         ui_mess_menu_populate_software_entries(machine, menu, sw_state);
254      }
255   }
256
257218   /* process the menu */
258   event = menu->process(0);
219   const ui_menu_event *event = process(0);
259220
260221   if (event != NULL && event->itemref != NULL)
261222   {
262223      if ((FPTR)event->itemref == 1 && event->iptkey == IPT_UI_SELECT)
263224      {
264         sw_state->ordered_by_shortname ^= 1;
265         sw_state->reorder = 1;
266         sw_state->entrylist = NULL;
225         ordered_by_shortname = !ordered_by_shortname;
226         entrylist = NULL;
267227         // reset the char buffer if we change ordering criterion
268         memset(sw_state->filename_buffer, '\0', ARRAY_LENGTH(sw_state->filename_buffer));
228         memset(filename_buffer, '\0', ARRAY_LENGTH(filename_buffer));
269229
270230         // reload the menu with the new order
271         menu->reset(UI_MENU_RESET_REMEMBER_REF);
272         popmessage("Switched Order: entries now ordered by %s", sw_state->ordered_by_shortname ? "shortname" : "description");
231         reset(UI_MENU_RESET_REMEMBER_REF);
232         popmessage("Switched Order: entries now ordered by %s", ordered_by_shortname ? "shortname" : "description");
273233      }
274234      /* handle selections */
275235      else if (event->iptkey == IPT_UI_SELECT)
276236      {
277         device_image_interface *image = sw_state->image;
278         software_entry_state *entry = (software_entry_state *) event->itemref;
279         software_list *tmp_list = software_list_open(machine.options(), sw_state->list_name, FALSE, NULL);
237         ui_menu_software_entry_info *entry = (ui_menu_software_entry_info *) event->itemref;
238         software_list *tmp_list = software_list_open(machine().options(), list_name, false, NULL);
280239         software_info *tmp_info = software_list_find(tmp_list, entry->short_name, NULL);
281240
282241         // if the selected software has multiple parts that can be loaded, open the submenu
283242         if (swinfo_has_multiple_parts(tmp_info, image->image_interface()))
284243         {
244#if 0
285245            ui_menu *child_menu = ui_menu_alloc(machine, &machine.render().ui_container(), ui_mess_menu_software_parts, entry);
286            software_entry_state *child_menustate = (software_entry_state *)child_menu->alloc_state(sizeof(*child_menustate), NULL);
246            ui_menu_software_entry_info *child_menustate = (ui_menu_software_entry_info *)child_menu->alloc_state(sizeof(*child_menustate), NULL);
287247            child_menustate->short_name = entry->short_name;
288248            child_menustate->interface = image->image_interface();
289            child_menustate->list_name = sw_state->list_name;
249            child_menustate->list_name = list_name;
290250            child_menustate->image = image;
291251            ui_menu::stack_push(child_menu);
252#endif
292253         }
293254         else
294255         {
r13553r13554
298259         software_list_close(tmp_list);
299260
300261         // reset the char buffer when pressing IPT_UI_SELECT
301         if (sw_state->filename_buffer[0] != '\0')
302            memset(sw_state->filename_buffer, '\0', ARRAY_LENGTH(sw_state->filename_buffer));
262         if (filename_buffer[0] != '\0')
263            memset(filename_buffer, '\0', ARRAY_LENGTH(filename_buffer));
303264      }
304265      else if (event->iptkey == IPT_SPECIAL)
305266      {
306         int buflen = strlen(sw_state->filename_buffer);
307         bool update_selected = FALSE;
267         int buflen = strlen(filename_buffer);
268         bool update_selected = false;
308269
309270         /* if it's a backspace and we can handle it, do so */
310271         if ((event->unichar == 8 || event->unichar == 0x7f) && buflen > 0)
311272         {
312            *(char *)utf8_previous_char(&sw_state->filename_buffer[buflen]) = 0;
313            update_selected = TRUE;
273            *(char *)utf8_previous_char(&filename_buffer[buflen]) = 0;
274            update_selected = true;
314275
315            if (ARRAY_LENGTH(sw_state->filename_buffer) > 0)
316               ui_popup_time(ERROR_MESSAGE_TIME, "%s", sw_state->filename_buffer);
276            if (ARRAY_LENGTH(filename_buffer) > 0)
277               ui_popup_time(ERROR_MESSAGE_TIME, "%s", filename_buffer);
317278         }
318279         /* if it's any other key and we're not maxed out, update */
319280         else if (event->unichar >= ' ' && event->unichar < 0x7f)
320281         {
321            buflen += utf8_from_uchar(&sw_state->filename_buffer[buflen], ARRAY_LENGTH(sw_state->filename_buffer) - buflen, event->unichar);
322            sw_state->filename_buffer[buflen] = 0;
323            update_selected = TRUE;
282            buflen += utf8_from_uchar(&filename_buffer[buflen], ARRAY_LENGTH(filename_buffer) - buflen, event->unichar);
283            filename_buffer[buflen] = 0;
284            update_selected = true;
324285
325            if (ARRAY_LENGTH(sw_state->filename_buffer) > 0)
326               ui_popup_time(ERROR_MESSAGE_TIME, "%s", sw_state->filename_buffer);
286            if (ARRAY_LENGTH(filename_buffer) > 0)
287               ui_popup_time(ERROR_MESSAGE_TIME, "%s", filename_buffer);
327288         }
328289
329290         if (update_selected)
330291         {
331            const software_entry_state *cur_selected;
292            const ui_menu_software_entry_info *cur_selected;
332293
333294            // if the current selection is a software entry, start search from here
334295            if ((FPTR)event->itemref != 1)
335               cur_selected= (const software_entry_state *)menu->get_selection();
296               cur_selected= (const ui_menu_software_entry_info *)get_selection();
336297            // else (if we are on the 'Switch Order' entry) start from the beginning
337298            else
338               cur_selected= sw_state->entrylist;
299               cur_selected= entrylist;
339300
340301            // check for entries which matches our filename_buffer:
341302            // from current entry to the end
342303            for (entry = cur_selected; entry != NULL; entry = entry->next)
343304            {
344               const char *compare_name = sw_state->ordered_by_shortname ? entry->short_name : entry->long_name;
305               const char *compare_name = ordered_by_shortname ? entry->short_name : entry->long_name;
345306
346               if (compare_name != NULL && sw_state->filename_buffer != NULL)
307               if (compare_name != NULL && filename_buffer != NULL)
347308               {
348309                  int match = 0;
349                  for (int i = 0; i < ARRAY_LENGTH(sw_state->filename_buffer); i++)
310                  for (int i = 0; i < ARRAY_LENGTH(filename_buffer); i++)
350311                  {
351                     if (mame_strnicmp(compare_name, sw_state->filename_buffer, i) == 0)
312                     if (mame_strnicmp(compare_name, filename_buffer, i) == 0)
352313                        match = i;
353314                  }
354315
r13553r13554
360321               }
361322            }
362323            // and from the first entry to current one
363            for (entry = sw_state->entrylist; entry != cur_selected; entry = entry->next)
324            for (entry = entrylist; entry != cur_selected; entry = entry->next)
364325            {
365               const char *compare_name = sw_state->ordered_by_shortname ? entry->short_name : entry->long_name;
326               const char *compare_name = ordered_by_shortname ? entry->short_name : entry->long_name;
366327
367               if (compare_name != NULL && sw_state->filename_buffer != NULL)
328               if (compare_name != NULL && filename_buffer != NULL)
368329               {
369330                  int match = 0;
370                  for (int i = 0; i < ARRAY_LENGTH(sw_state->filename_buffer); i++)
331                  for (int i = 0; i < ARRAY_LENGTH(filename_buffer); i++)
371332                  {
372                     if (mame_strnicmp(compare_name, sw_state->filename_buffer, i) == 0)
333                     if (mame_strnicmp(compare_name, filename_buffer, i) == 0)
373334                        match = i;
374335                  }
375336
r13553r13554
382343            }
383344
384345            if (selected_entry != NULL && selected_entry != cur_selected)
385               menu->set_selection((void *) selected_entry);
346               set_selection((void *) selected_entry);
386347         }
387348      }
388349      else if (event->iptkey == IPT_UI_CANCEL)
389350      {
390351         // reset the char buffer also in this case
391         if (sw_state->filename_buffer[0] != '\0')
392            memset(sw_state->filename_buffer, '\0', ARRAY_LENGTH(sw_state->filename_buffer));
352         if (filename_buffer[0] != '\0')
353            memset(filename_buffer, '\0', ARRAY_LENGTH(filename_buffer));
393354      }
394355   }
395356}
396357
397358/* list of available software lists - i.e. cartridges, floppies */
398static void ui_mess_menu_populate_software_list(running_machine &machine, ui_menu *menu, device_image_interface* image)
359ui_menu_software::ui_menu_software(running_machine &machine, render_container *container, device_image_interface* _image) : ui_menu(machine, container)
399360{
400   bool haveCompatible = FALSE;
361   image = _image;
362}
363
364void ui_menu_software::populate()
365{
366   bool haveCompatible = false;
401367   const char *interface = image->image_interface();
402368
403369   // Add original software lists for this system
404   for (const device_t *dev = machine.config().devicelist().first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext())
370   for (const device_t *dev = machine().config().devicelist().first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext())
405371   {
406372      software_list_config *swlist = (software_list_config *)downcast<const legacy_device_base *>(dev)->inline_config();
407373
r13553r13554
409375      {
410376         if (swlist->list_name[i] && (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM))
411377         {
412            software_list *list = software_list_open(machine.options(), swlist->list_name[i], FALSE, NULL);
378            software_list *list = software_list_open(machine().options(), swlist->list_name[i], false, NULL);
413379
414380            if (list)
415381            {
416               bool found = FALSE;
382               bool found = false;
417383               for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo))
418384               {
419385                  software_part *part = software_find_part(swinfo, NULL, NULL);
420386                  if (strcmp(interface,part->interface_)==0) {
421                     found = TRUE;
387                     found = true;
422388                  }
423389               }
424390               if (found) {
425                  menu->item_append(list->description, NULL, 0, swlist->list_name[i]);
391                  item_append(list->description, NULL, 0, swlist->list_name[i]);
426392               }
427393
428394               software_list_close(list);
r13553r13554
432398   }
433399
434400   // Add compatible software lists for this system
435   for (const device_t *dev = machine.config().devicelist().first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext())
401   for (const device_t *dev = machine().config().devicelist().first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext())
436402   {
437403      software_list_config *swlist = (software_list_config *)downcast<const legacy_device_base *>(dev)->inline_config();
438404
r13553r13554
440406      {
441407         if (swlist->list_name[i] && (swlist->list_type == SOFTWARE_LIST_COMPATIBLE_SYSTEM))
442408         {
443            software_list *list = software_list_open(machine.options(), swlist->list_name[i], FALSE, NULL);
409            software_list *list = software_list_open(machine().options(), swlist->list_name[i], false, NULL);
444410
445411            if (list)
446412            {
447               bool found = FALSE;
413               bool found = false;
448414               for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo))
449415               {
450416                  software_part *part = software_find_part(swinfo, NULL, NULL);
451417                  if (strcmp(interface,part->interface_)==0) {
452                     found = TRUE;
418                     found = true;
453419                  }
454420               }
455421               if (found) {
456422                  if (!haveCompatible) {
457                     menu->item_append("[compatible lists]", NULL, MENU_FLAG_DISABLE, NULL);
423                     item_append("[compatible lists]", NULL, MENU_FLAG_DISABLE, NULL);
458424                  }
459                  menu->item_append(list->description, NULL, 0, swlist->list_name[i]);
425                  item_append(list->description, NULL, 0, swlist->list_name[i]);
460426               }
461427
462               haveCompatible = TRUE;
428               haveCompatible = true;
463429               software_list_close(list);
464430            }
465431         }
r13553r13554
468434
469435}
470436
471void ui_image_menu_software(running_machine &machine, ui_menu *menu, void *parameter, void *state)
437ui_menu_software::~ui_menu_software()
472438{
473   const ui_menu_event *event;
474   device_image_interface* image = (device_image_interface*)parameter;
475   if (!menu->populated())
476      ui_mess_menu_populate_software_list(machine, menu, image);
439}
477440
441void ui_menu_software::handle()
442{
478443   /* process the menu */
479   event = menu->process(0);
444   const ui_menu_event *event = process(0);
480445
481446   if (event != NULL && event->iptkey == IPT_UI_SELECT)
482   {
483      ui_menu *child_menu = ui_menu_alloc(machine, &machine.render().ui_container(), ui_mess_menu_software_list, NULL);
484      software_menu_state *child_menustate = (software_menu_state *)child_menu->alloc_state(sizeof(*child_menustate), NULL);
485      child_menustate->list_name = (char *)event->itemref;
486      child_menustate->image = image;
487      child_menustate->entrylist = NULL;
488      child_menustate->ordered_by_shortname = 1;
489      ui_menu::stack_push(child_menu);
490   }
447      ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_list(machine(), container, (char *)event->itemref, image)));
491448}
src/emu/uimain.h
r13553r13554
1414#ifndef __UIMAIN_H__
1515#define __UIMAIN_H__
1616
17/* slider handler */
18UINT32 ui_slider_ui_handler(running_machine &machine, render_container *container, UINT32 state);
17#include "crsshair.h"
1918
19class ui_menu_main : public ui_menu {
20public:
21   ui_menu_main(running_machine &machine, render_container *container);
22   virtual ~ui_menu_main();
23   virtual void populate();
24   virtual void handle();
25
26private:
27   enum {
28      INPUT_GROUPS,
29      INPUT_SPECIFIC,
30      SETTINGS_DIP_SWITCHES,
31      SETTINGS_DRIVER_CONFIG,
32      ANALOG,
33      BOOKKEEPING,
34      GAME_INFO,
35      IMAGE_MENU_IMAGE_INFO,
36      IMAGE_MENU_FILE_MANAGER,
37      MESS_MENU_TAPE_CONTROL,
38      MESS_MENU_BITBANGER_CONTROL,
39      SLOT_DEVICES,
40      NETWORK_DEVICES,
41      KEYBOARD_MODE,
42      SLIDERS,
43      VIDEO_TARGETS,
44      VIDEO_OPTIONS,
45      CROSSHAIR,
46      CHEAT,
47      MEMORY_CARD,
48      SELECT_GAME,
49   };
50};
51
52class ui_menu_keyboard_mode : public ui_menu {
53public:
54   ui_menu_keyboard_mode(running_machine &machine, render_container *container);
55   virtual ~ui_menu_keyboard_mode();
56   virtual void populate();
57   virtual void handle();
58};
59
60class ui_menu_slot_devices : public ui_menu {
61public:
62   ui_menu_slot_devices(running_machine &machine, render_container *container);
63   virtual ~ui_menu_slot_devices();
64   virtual void populate();
65   virtual void handle();
66
67private:
68   int slot_get_current_index(device_slot_interface *slot);
69   int slot_get_length(device_slot_interface *slot);
70   const char *slot_get_next(device_slot_interface *slot);
71   const char *slot_get_prev(device_slot_interface *slot);
72   const char *get_slot_device(device_slot_interface *slot);
73   void set_slot_device(device_slot_interface *slot, const char *val);
74};
75
76class ui_menu_network_devices : public ui_menu {
77public:
78   ui_menu_network_devices(running_machine &machine, render_container *container);
79   virtual ~ui_menu_network_devices();
80   virtual void populate();
81   virtual void handle();
82};
83
84class ui_menu_input_groups : public ui_menu {
85public:
86   ui_menu_input_groups(running_machine &machine, render_container *container);
87   virtual ~ui_menu_input_groups();
88   virtual void populate();
89   virtual void handle();
90};
91
92class ui_menu_input : public ui_menu {
93public:
94   ui_menu_input(running_machine &machine, render_container *container);
95   virtual ~ui_menu_input();
96   virtual void handle();
97
98protected:
99   enum {
100      INPUT_TYPE_DIGITAL = 0,
101      INPUT_TYPE_ANALOG = 1,
102      INPUT_TYPE_ANALOG_DEC = INPUT_TYPE_ANALOG + SEQ_TYPE_DECREMENT,
103      INPUT_TYPE_ANALOG_INC = INPUT_TYPE_ANALOG + SEQ_TYPE_INCREMENT,
104      INPUT_TYPE_TOTAL = INPUT_TYPE_ANALOG + SEQ_TYPE_TOTAL
105   };
106
107   /* internal input menu item data */
108   struct input_item_data {
109      input_item_data *   next;            /* pointer to next item in the list */
110      const void *      ref;            /* reference to type description for global inputs or field for game inputs */
111      input_seq_type      seqtype;         /* sequence type */
112      input_seq         seq;            /* copy of the live sequence */
113      const input_seq *   defseq;            /* pointer to the default sequence */
114      const char *      name;            /* pointer to the base name of the item */
115      UINT16            sortorder;         /* sorting information */
116      UINT8            type;            /* type of port */
117   };
118
119   void populate_and_sort(struct input_item_data *itemlist);
120   virtual void update_input(struct input_item_data *seqchangeditem) = 0;
121   void toggle_none_default(input_seq &selected_seq, input_seq &original_seq, const input_seq &selected_defseq);
122   const input_seq &get_field_default_seq(input_field_config *field, input_seq_type seqtype);
123
124private:
125   UINT16            last_sortorder;
126   const void *      pollingref;
127   input_item_data *   pollingitem;
128   bool            record_next;
129   input_seq         starting_seq;
130
131   static int compare_items(const void *i1, const void *i2);
132};
133
134class ui_menu_input_general : public ui_menu_input {
135public:
136   ui_menu_input_general(running_machine &machine, render_container *container, int group);
137   virtual ~ui_menu_input_general();
138   virtual void populate();
139
140protected:
141   int group;
142   virtual void update_input(struct input_item_data *seqchangeditem);
143};
144
145class ui_menu_input_specific : public ui_menu_input {
146public:
147   ui_menu_input_specific(running_machine &machine, render_container *container);
148   virtual ~ui_menu_input_specific();
149   virtual void populate();
150
151protected:
152   virtual void update_input(struct input_item_data *seqchangeditem);
153};
154
155class ui_menu_settings : public ui_menu {
156public:
157   ui_menu_settings(running_machine &machine, render_container *container, UINT32 type);
158   virtual ~ui_menu_settings();
159   virtual void populate();
160   virtual void handle();
161
162protected:
163   /* DIP switch descriptor */
164   struct dip_descriptor {
165      dip_descriptor *   next;
166      const char *      name;
167      UINT32            mask;
168      UINT32            state;
169   };
170
171   dip_descriptor *   diplist;
172   int dipcount;
173   int type;
174};
175
176class ui_menu_settings_dip_switches : public ui_menu_settings {
177public:
178   ui_menu_settings_dip_switches(running_machine &machine, render_container *container);
179   virtual ~ui_menu_settings_dip_switches();
180
181   virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
182private:
183   void custom_render_one(float x1, float y1, float x2, float y2, const dip_descriptor *dip, UINT32 selectedmask);
184};
185
186class ui_menu_settings_driver_config : public ui_menu_settings {
187public:
188   ui_menu_settings_driver_config(running_machine &machine, render_container *container);
189   virtual ~ui_menu_settings_driver_config();
190};
191
192class ui_menu_analog : public ui_menu {
193public:
194   ui_menu_analog(running_machine &machine, render_container *container);
195   virtual ~ui_menu_analog();
196   virtual void populate();
197   virtual void handle();
198
199private:
200   enum {
201      ANALOG_ITEM_KEYSPEED = 0,
202      ANALOG_ITEM_CENTERSPEED,
203      ANALOG_ITEM_REVERSE,
204      ANALOG_ITEM_SENSITIVITY,
205      ANALOG_ITEM_COUNT
206   };
207
208   /* internal analog menu item data */
209   struct analog_item_data {
210      input_field_config *field;
211      int               type;
212      int               min, max;
213      int               cur;
214      int             defvalue;
215   };
216};
217
218class ui_menu_bookkeeping : public ui_menu {
219public:
220   ui_menu_bookkeeping(running_machine &machine, render_container *container);
221   virtual ~ui_menu_bookkeeping();
222   virtual void populate();
223   virtual void handle();
224
225private:
226   attotime prevtime;
227};
228
229class ui_menu_game_info : public ui_menu {
230public:
231   ui_menu_game_info(running_machine &machine, render_container *container);
232   virtual ~ui_menu_game_info();
233   virtual void populate();
234   virtual void handle();
235};
236
237class ui_menu_cheat : public ui_menu {
238public:
239   ui_menu_cheat(running_machine &machine, render_container *container);
240   virtual ~ui_menu_cheat();
241   virtual void populate();
242   virtual void handle();
243};
244
245class ui_menu_memory_card : public ui_menu {
246public:
247   ui_menu_memory_card(running_machine &machine, render_container *container);
248   virtual ~ui_menu_memory_card();
249   virtual void populate();
250   virtual void handle();
251
252private:
253   enum {
254      MEMCARD_ITEM_SELECT = 1,
255      MEMCARD_ITEM_LOAD,
256      MEMCARD_ITEM_EJECT,
257      MEMCARD_ITEM_CREATE
258   };
259
260   int cardnum;
261};
262
263class ui_menu_sliders : public ui_menu {
264public:
265   ui_menu_sliders(running_machine &machine, render_container *container, bool menuless_mode);
266   virtual ~ui_menu_sliders();
267   virtual void populate();
268   virtual void handle();
269
270   virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
271
272   static UINT32 ui_handler(running_machine &machine, render_container *container, UINT32 state);
273
274private:
275   bool menuless_mode, hidden;
276};
277
278class ui_menu_video_targets : public ui_menu {
279public:
280   ui_menu_video_targets(running_machine &machine, render_container *container);
281   virtual ~ui_menu_video_targets();
282   virtual void populate();
283   virtual void handle();
284};
285
286class ui_menu_video_options : public ui_menu {
287public:
288   ui_menu_video_options(running_machine &machine, render_container *container, render_target *target);
289   virtual ~ui_menu_video_options();
290   virtual void populate();
291   virtual void handle();
292
293private:
294   enum {
295      VIDEO_ITEM_ROTATE = 0x80000000,
296      VIDEO_ITEM_BACKDROPS,
297      VIDEO_ITEM_OVERLAYS,
298      VIDEO_ITEM_BEZELS,
299      VIDEO_ITEM_CPANELS,
300      VIDEO_ITEM_MARQUEES,
301      VIDEO_ITEM_ZOOM,
302      VIDEO_ITEM_VIEW
303   };
304
305   render_target *target;
306};
307
308class ui_menu_crosshair : public ui_menu {
309public:
310   ui_menu_crosshair(running_machine &machine, render_container *container);
311   virtual ~ui_menu_crosshair();
312   virtual void populate();
313   virtual void handle();
314
315private:
316   enum {
317      CROSSHAIR_ITEM_VIS = 0,
318      CROSSHAIR_ITEM_PIC,
319      CROSSHAIR_ITEM_AUTO_TIME
320   };
321
322   /* internal crosshair menu item data */
323   struct crosshair_item_data {
324      UINT8            type;
325      UINT8            player;
326      UINT8            min, max;
327      UINT8            cur;
328      UINT8            defvalue;
329      char            last_name[CROSSHAIR_PIC_NAME_LENGTH + 1];
330      char            next_name[CROSSHAIR_PIC_NAME_LENGTH + 1];
331   };
332};
333
334class ui_menu_quit_game : public ui_menu {
335public:
336   ui_menu_quit_game(running_machine &machine, render_container *container);
337   virtual ~ui_menu_quit_game();
338   virtual void populate();
339   virtual void handle();
340};
341
342class ui_menu_select_game : public ui_menu {
343public:
344   ui_menu_select_game(running_machine &machine, render_container *container, const char *gamename);
345   virtual ~ui_menu_select_game();
346   virtual void populate();
347   virtual void handle();
348   virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
349
350private:
351   enum { VISIBLE_GAMES_IN_LIST = 15 };
352   UINT8            error;
353   UINT8            rerandomize;
354   char            search[40];
355   int               matchlist[VISIBLE_GAMES_IN_LIST];
356   const game_driver   **driverlist;
357
358   // Still a hack, but a vaguely clearner one
359   static driver_enumerator *drivlist;
360
361   void build_driver_list();
362};
363
20364/* force game select menu */
21365void ui_menu_force_game_select(running_machine &machine, render_container *container);
22366
23/* handle the main menu */
24void menu_main(running_machine &machine, ui_menu *menu, void *parameter, void *state);
25
26367#endif   /* __UIMAIN_H__ */
src/emu/uiswlist.h
r13553r13554
1212#ifndef __UISWLIST_H__
1313#define __UISWLIST_H__
1414
15struct ui_menu_software_entry_info {
16   ui_menu_software_entry_info *next;
1517
16/***************************************************************************
17    FUNCTION PROTOTYPES
18***************************************************************************/
18   const char *short_name;
19   const char *long_name;
20   const char *interface;
21   char *list_name;
22   device_image_interface* image;
23};
1924
20void ui_image_menu_software(running_machine &machine, ui_menu *menu, void *parameter, void *state);
25class ui_menu_software_parts : public ui_menu {
26public:
27   ui_menu_software_parts(running_machine &machine, render_container *container, ui_menu_software_entry_info *entry);
28   virtual ~ui_menu_software_parts();
29   virtual void populate();
30   virtual void handle();
2131
32private:
33   struct software_part_info {
34      const char *part_name;
35      const char *interface;
36   };
37
38   ui_menu_software_entry_info *entry;
39};
40
41class ui_menu_software_list : public ui_menu {
42public:
43   ui_menu_software_list(running_machine &machine, render_container *container, char *list_name, device_image_interface *image);
44   virtual ~ui_menu_software_list();
45   virtual void populate();
46   virtual void handle();
47
48private:
49   char *list_name;   /* currently selected list */
50   device_image_interface *image;
51   ui_menu_software_entry_info *entrylist;
52   char filename_buffer[1024];
53   bool ordered_by_shortname;
54
55   int compare_entries(const ui_menu_software_entry_info *e1, const ui_menu_software_entry_info *e2, bool shortname);
56   ui_menu_software_entry_info *append_software_entry(software_info *swinfo, char *list_name, device_image_interface* image);
57   bool swinfo_has_multiple_parts(software_info *swinfo, const char *interface);
58};
59
60class ui_menu_software : public ui_menu {
61public:
62   ui_menu_software(running_machine &machine, render_container *container, device_image_interface *device);
63   virtual ~ui_menu_software();
64   virtual void populate();
65   virtual void handle();
66
67private:
68   device_image_interface *image;
69};
70
2271#endif   /* __UISWLIST_H__ */
src/emu/debugint/debugint.c
r13553r13554
11591159    menu_main_populate - populate the main menu
11601160  -------------------------------------------------*/
11611161
1162class ui_menu_what_the_hell : public ui_menu {
1163public:
1164   ui_menu_what_the_hell(running_machine &machine, render_container *container) : ui_menu(machine, container) {}
1165   virtual ~ui_menu_what_the_hell() {}
1166   virtual void populate() {}
1167   virtual void handle() {}
1168};
1169
11621170static void CreateMainMenu(running_machine &machine)
11631171{
11641172   const char *subtext = "";
r13553r13554
11671175
11681176   if (menu)
11691177      auto_free(machine, menu);
1170   menu = ui_menu_alloc(machine, &machine.render().ui_container(),NULL,NULL);
1178   menu = auto_alloc_clear(machine, ui_menu_what_the_hell(machine, &machine.render().ui_container()));
11711179
11721180   switch (focus_view->type)
11731181   {

Previous 15994 Revisions Next


© 1998-2018 The MESS Team