src/emu/uimenu.c
| r13466 | r13467 | |
| 13 | 13 | #include "emuopts.h" |
| 14 | 14 | #include "ui.h" |
| 15 | 15 | #include "rendutil.h" |
| 16 | | #include "cheat.h" |
| 17 | | #include "uiimage.h" |
| 18 | 16 | #include "uiinput.h" |
| 19 | | #include "uimenu.h" |
| 20 | | #include "audit.h" |
| 21 | | #include "crsshair.h" |
| 17 | #include "cheat.h" |
| 18 | #include "uimain.h" |
| 22 | 19 | #include <ctype.h> |
| 23 | | #include "imagedev/cassette.h" |
| 24 | | #include "imagedev/bitbngr.h" |
| 25 | 20 | |
| 26 | 21 | |
| 27 | 22 | |
| r13466 | r13467 | |
| 32 | 27 | #define UI_MENU_POOL_SIZE 65536 |
| 33 | 28 | #define UI_MENU_ALLOC_ITEMS 256 |
| 34 | 29 | |
| 35 | | #define VISIBLE_GAMES_IN_LIST 15 |
| 36 | | |
| 37 | | #define MAX_PHYSICAL_DIPS 10 |
| 38 | | #define MAX_INPUT_PORTS 32 |
| 39 | | #define MAX_BITS_PER_PORT 32 |
| 40 | | |
| 41 | | /* DIP switch rendering parameters */ |
| 42 | | #define DIP_SWITCH_HEIGHT 0.05f |
| 43 | | #define DIP_SWITCH_SPACING 0.01 |
| 44 | | #define SINGLE_TOGGLE_SWITCH_FIELD_WIDTH 0.025f |
| 45 | | #define SINGLE_TOGGLE_SWITCH_WIDTH 0.020f |
| 46 | | /* make the switch 80% of the width space and 1/2 of the switch height */ |
| 47 | | #define PERCENTAGE_OF_HALF_FIELD_USED 0.80f |
| 48 | | #define SINGLE_TOGGLE_SWITCH_HEIGHT ((DIP_SWITCH_HEIGHT / 2) * PERCENTAGE_OF_HALF_FIELD_USED) |
| 49 | | |
| 50 | | |
| 51 | | enum |
| 52 | | { |
| 53 | | INPUT_TYPE_DIGITAL = 0, |
| 54 | | INPUT_TYPE_ANALOG = 1, |
| 55 | | INPUT_TYPE_ANALOG_DEC = INPUT_TYPE_ANALOG + SEQ_TYPE_DECREMENT, |
| 56 | | INPUT_TYPE_ANALOG_INC = INPUT_TYPE_ANALOG + SEQ_TYPE_INCREMENT, |
| 57 | | INPUT_TYPE_TOTAL = INPUT_TYPE_ANALOG + SEQ_TYPE_TOTAL |
| 58 | | }; |
| 59 | | |
| 60 | | enum |
| 61 | | { |
| 62 | | ANALOG_ITEM_KEYSPEED = 0, |
| 63 | | ANALOG_ITEM_CENTERSPEED, |
| 64 | | ANALOG_ITEM_REVERSE, |
| 65 | | ANALOG_ITEM_SENSITIVITY, |
| 66 | | ANALOG_ITEM_COUNT |
| 67 | | }; |
| 68 | | |
| 69 | | enum |
| 70 | | { |
| 71 | | MEMCARD_ITEM_SELECT = 1, |
| 72 | | MEMCARD_ITEM_LOAD, |
| 73 | | MEMCARD_ITEM_EJECT, |
| 74 | | MEMCARD_ITEM_CREATE |
| 75 | | }; |
| 76 | | |
| 77 | | enum |
| 78 | | { |
| 79 | | VIDEO_ITEM_ROTATE = 0x80000000, |
| 80 | | VIDEO_ITEM_BACKDROPS, |
| 81 | | VIDEO_ITEM_OVERLAYS, |
| 82 | | VIDEO_ITEM_BEZELS, |
| 83 | | VIDEO_ITEM_CPANELS, |
| 84 | | VIDEO_ITEM_MARQUEES, |
| 85 | | VIDEO_ITEM_ZOOM, |
| 86 | | VIDEO_ITEM_VIEW |
| 87 | | }; |
| 88 | | |
| 89 | | |
| 90 | | enum |
| 91 | | { |
| 92 | | CROSSHAIR_ITEM_VIS = 0, |
| 93 | | CROSSHAIR_ITEM_PIC, |
| 94 | | CROSSHAIR_ITEM_AUTO_TIME |
| 95 | | }; |
| 96 | | |
| 97 | | |
| 98 | 30 | /*************************************************************************** |
| 99 | | TYPE DEFINITIONS |
| 100 | | ***************************************************************************/ |
| 101 | | |
| 102 | | typedef struct _ui_menu_pool ui_menu_pool; |
| 103 | | struct _ui_menu_pool |
| 104 | | { |
| 105 | | ui_menu_pool * next; /* chain to next one */ |
| 106 | | UINT8 * top; /* top of the pool */ |
| 107 | | UINT8 * end; /* end of the pool */ |
| 108 | | }; |
| 109 | | |
| 110 | | |
| 111 | | typedef struct _ui_menu_item ui_menu_item; |
| 112 | | struct _ui_menu_item |
| 113 | | { |
| 114 | | const char * text; |
| 115 | | const char * subtext; |
| 116 | | UINT32 flags; |
| 117 | | void * ref; |
| 118 | | }; |
| 119 | | |
| 120 | | |
| 121 | | class ui_menu |
| 122 | | { |
| 123 | | public: |
| 124 | | ui_menu(running_machine &machine) |
| 125 | | : m_machine(machine) { } |
| 126 | | |
| 127 | | running_machine &machine() const { return m_machine; } |
| 128 | | |
| 129 | | render_container * container; /* render_container we render to */ |
| 130 | | ui_menu_handler_func handler; /* handler callback */ |
| 131 | | void * parameter; /* parameter */ |
| 132 | | ui_menu_event menu_event; /* the UI menu_event that occurred */ |
| 133 | | ui_menu * parent; /* pointer to parent menu */ |
| 134 | | void * state; /* menu-specific state */ |
| 135 | | ui_menu_destroy_state_func destroy_state; /* destroy state callback */ |
| 136 | | int resetpos; /* reset position */ |
| 137 | | void * resetref; /* reset reference */ |
| 138 | | int selected; /* which item is selected */ |
| 139 | | int hover; /* which item is being hovered over */ |
| 140 | | int visitems; /* number of visible items */ |
| 141 | | int numitems; /* number of items in the menu */ |
| 142 | | int allocitems; /* allocated size of array */ |
| 143 | | ui_menu_item * item; /* pointer to array of items */ |
| 144 | | ui_menu_custom_func custom; /* callback for custom rendering */ |
| 145 | | float customtop; /* amount of extra height to add at the top */ |
| 146 | | float custombottom; /* amount of extra height to add at the bottom */ |
| 147 | | ui_menu_pool * pool; /* list of memory pools */ |
| 148 | | |
| 149 | | private: |
| 150 | | running_machine & m_machine; /* machine we are attached to */ |
| 151 | | }; |
| 152 | | |
| 153 | | |
| 154 | | /* internal input menu item data */ |
| 155 | | typedef struct _input_item_data input_item_data; |
| 156 | | struct _input_item_data |
| 157 | | { |
| 158 | | input_item_data * next; /* pointer to next item in the list */ |
| 159 | | const void * ref; /* reference to type description for global inputs or field for game inputs */ |
| 160 | | input_seq_type seqtype; /* sequence type */ |
| 161 | | input_seq seq; /* copy of the live sequence */ |
| 162 | | const input_seq * defseq; /* pointer to the default sequence */ |
| 163 | | const char * name; /* pointer to the base name of the item */ |
| 164 | | UINT16 sortorder; /* sorting information */ |
| 165 | | UINT8 type; /* type of port */ |
| 166 | | }; |
| 167 | | |
| 168 | | |
| 169 | | /* internal analog menu item data */ |
| 170 | | typedef struct _analog_item_data analog_item_data; |
| 171 | | struct _analog_item_data |
| 172 | | { |
| 173 | | input_field_config *field; |
| 174 | | int type; |
| 175 | | int min, max; |
| 176 | | int cur; |
| 177 | | int defvalue; |
| 178 | | }; |
| 179 | | |
| 180 | | |
| 181 | | /* DIP switch descriptor */ |
| 182 | | typedef struct _dip_descriptor dip_descriptor; |
| 183 | | struct _dip_descriptor |
| 184 | | { |
| 185 | | dip_descriptor * next; |
| 186 | | const char * name; |
| 187 | | UINT32 mask; |
| 188 | | UINT32 state; |
| 189 | | }; |
| 190 | | |
| 191 | | |
| 192 | | /* extended settings menu state */ |
| 193 | | typedef struct _settings_menu_state settings_menu_state; |
| 194 | | struct _settings_menu_state |
| 195 | | { |
| 196 | | dip_descriptor * diplist; |
| 197 | | }; |
| 198 | | |
| 199 | | |
| 200 | | /* extended input menu state */ |
| 201 | | typedef struct _input_menu_state input_menu_state; |
| 202 | | struct _input_menu_state |
| 203 | | { |
| 204 | | UINT16 last_sortorder; |
| 205 | | const void * pollingref; |
| 206 | | input_item_data * pollingitem; |
| 207 | | UINT8 record_next; |
| 208 | | input_seq starting_seq; |
| 209 | | }; |
| 210 | | |
| 211 | | |
| 212 | | /* extended select game menu state */ |
| 213 | | typedef struct _select_game_state select_game_state; |
| 214 | | struct _select_game_state |
| 215 | | { |
| 216 | | UINT8 error; |
| 217 | | UINT8 rerandomize; |
| 218 | | char search[40]; |
| 219 | | int matchlist[VISIBLE_GAMES_IN_LIST]; |
| 220 | | const game_driver * driverlist[1]; |
| 221 | | }; |
| 222 | | |
| 223 | | |
| 224 | | /* internal crosshair menu item data */ |
| 225 | | typedef struct _crosshair_item_data crosshair_item_data; |
| 226 | | struct _crosshair_item_data |
| 227 | | { |
| 228 | | UINT8 type; |
| 229 | | UINT8 player; |
| 230 | | UINT8 min, max; |
| 231 | | UINT8 cur; |
| 232 | | UINT8 defvalue; |
| 233 | | char last_name[CROSSHAIR_PIC_NAME_LENGTH + 1]; |
| 234 | | char next_name[CROSSHAIR_PIC_NAME_LENGTH + 1]; |
| 235 | | }; |
| 236 | | |
| 237 | | |
| 238 | | |
| 239 | | /*************************************************************************** |
| 240 | 31 | GLOBAL VARIABLES |
| 241 | 32 | ***************************************************************************/ |
| 242 | 33 | |
| 243 | | /* menu states */ |
| 244 | | static ui_menu *menu_stack; |
| 245 | | static ui_menu *menu_free; |
| 34 | ui_menu *ui_menu::menu_stack; |
| 35 | ui_menu *ui_menu::menu_free; |
| 36 | bitmap_t *ui_menu::hilight_bitmap; |
| 37 | render_texture *ui_menu::hilight_texture; |
| 38 | render_texture *ui_menu::arrow_texture; |
| 246 | 39 | |
| 247 | | static bitmap_t *hilight_bitmap; |
| 248 | | static render_texture *hilight_texture; |
| 249 | | |
| 250 | | static render_texture *arrow_texture; |
| 251 | | |
| 252 | | static const char priortext[] = "Return to Prior Menu"; |
| 253 | | static const char exittext[] = "Exit"; |
| 254 | | |
| 255 | | // temporary hack until this is C++-ified |
| 256 | | static driver_enumerator *drivlist; |
| 257 | | |
| 258 | | |
| 259 | | |
| 260 | 40 | /*************************************************************************** |
| 261 | | FUNCTION PROTOTYPES |
| 262 | | ***************************************************************************/ |
| 263 | | |
| 264 | | static void ui_menu_exit(running_machine &machine); |
| 265 | | |
| 266 | | /* internal menu processing */ |
| 267 | | static void ui_menu_draw(running_machine &machine, ui_menu *menu, int customonly); |
| 268 | | static void ui_menu_draw_text_box(ui_menu *menu); |
| 269 | | static void ui_menu_handle_events(ui_menu *menu); |
| 270 | | static void ui_menu_handle_keys(ui_menu *menu, UINT32 flags); |
| 271 | | static void ui_menu_validate_selection(ui_menu *menu, int scandir); |
| 272 | | static void ui_menu_clear_free_list(running_machine &machine); |
| 273 | | |
| 274 | | /* menu handlers */ |
| 275 | | static void menu_main(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 276 | | static void menu_main_populate(running_machine &machine, ui_menu *menu, void *state); |
| 277 | | static void menu_input_groups(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 278 | | static void menu_input_groups_populate(running_machine &machine, ui_menu *menu, void *state); |
| 279 | | static void menu_input_general(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 280 | | static void menu_input_general_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate, int group); |
| 281 | | static void menu_input_specific(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 282 | | static void menu_input_specific_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate); |
| 283 | | static void menu_input_common(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 284 | | static int CLIB_DECL menu_input_compare_items(const void *i1, const void *i2); |
| 285 | | static void menu_input_populate_and_sort(running_machine &machine, ui_menu *menu, input_item_data *itemlist, input_menu_state *menustate); |
| 286 | | static void menu_settings_dip_switches(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 287 | | static void menu_settings_driver_config(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 288 | | static void menu_settings_common(running_machine &machine, ui_menu *menu, void *state, UINT32 type); |
| 289 | | static void menu_settings_populate(running_machine &machine, ui_menu *menu, settings_menu_state *menustate, UINT32 type); |
| 290 | | static void menu_analog(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 291 | | static void menu_analog_populate(running_machine &machine, ui_menu *menu); |
| 292 | | static void menu_bookkeeping(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 293 | | static void menu_bookkeeping_populate(running_machine &machine, ui_menu *menu, attotime *curtime); |
| 294 | | static void menu_game_info(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 295 | | static void menu_cheat(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 296 | | static void menu_cheat_populate(running_machine &machine, ui_menu *menu); |
| 297 | | static void menu_memory_card(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 298 | | static void menu_memory_card_populate(running_machine &machine, ui_menu *menu, int cardnum); |
| 299 | | static void menu_sliders(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 300 | | static void menu_sliders_populate(running_machine &machine, ui_menu *menu, int menuless_mode); |
| 301 | | static 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); |
| 302 | | static void menu_video_targets(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 303 | | static void menu_video_targets_populate(running_machine &machine, ui_menu *menu); |
| 304 | | static void menu_video_options(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 305 | | static void menu_video_options_populate(running_machine &machine, ui_menu *menu, render_target *target); |
| 306 | | static void menu_crosshair(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 307 | | static void menu_crosshair_populate(running_machine &machine, ui_menu *menu); |
| 308 | | static void menu_quit_game(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 309 | | static void menu_select_game(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 310 | | static void menu_select_game_populate(running_machine &machine, ui_menu *menu, select_game_state *menustate); |
| 311 | | static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state *menustate); |
| 312 | | static 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); |
| 313 | | |
| 314 | | /* menu helpers */ |
| 315 | | static void menu_render_triangle(bitmap_t &dest, const bitmap_t &source, const rectangle &sbounds, void *param); |
| 316 | | static void menu_settings_custom_render_one(render_container *container, float x1, float y1, float x2, float y2, const dip_descriptor *dip, UINT32 selectedmask); |
| 317 | | static 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); |
| 318 | | |
| 319 | | |
| 320 | | |
| 321 | | /*************************************************************************** |
| 322 | 41 | INLINE FUNCTIONS |
| 323 | 42 | ***************************************************************************/ |
| 324 | 43 | |
| 325 | 44 | /*------------------------------------------------- |
| 326 | | get_field_default_seq - return a pointer |
| 327 | | to the default sequence for the given field |
| 328 | | -------------------------------------------------*/ |
| 329 | | |
| 330 | | INLINE const input_seq &get_field_default_seq(input_field_config *field, input_seq_type seqtype) |
| 331 | | { |
| 332 | | if (field->seq[seqtype].is_default()) |
| 333 | | return input_type_seq(field->machine(), field->type, field->player, seqtype); |
| 334 | | else |
| 335 | | return field->seq[seqtype]; |
| 336 | | } |
| 337 | | |
| 338 | | |
| 339 | | /*------------------------------------------------- |
| 340 | | toggle_none_default - toggle between "NONE" |
| 341 | | and the default item |
| 342 | | -------------------------------------------------*/ |
| 343 | | |
| 344 | | INLINE void toggle_none_default(input_seq &selected_seq, input_seq &original_seq, const input_seq &selected_defseq) |
| 345 | | { |
| 346 | | /* if we used to be "none", toggle to the default value */ |
| 347 | | if (original_seq.length() == 0) |
| 348 | | selected_seq = selected_defseq; |
| 349 | | |
| 350 | | /* otherwise, toggle to "none" */ |
| 351 | | else |
| 352 | | selected_seq.reset(); |
| 353 | | } |
| 354 | | |
| 355 | | |
| 356 | | /*------------------------------------------------- |
| 357 | | item_is_selectable - return TRUE if the given |
| 45 | is_selectable - return TRUE if the given |
| 358 | 46 | item is selectable |
| 359 | 47 | -------------------------------------------------*/ |
| 360 | 48 | |
| 361 | | INLINE int item_is_selectable(const ui_menu_item *item) |
| 49 | inline bool ui_menu_item::is_selectable() const |
| 362 | 50 | { |
| 363 | | return ((item->flags & (MENU_FLAG_MULTILINE | MENU_FLAG_DISABLE)) == 0 && strcmp(item->text, MENU_SEPARATOR_ITEM) != 0); |
| 51 | return ((flags & (MENU_FLAG_MULTILINE | MENU_FLAG_DISABLE)) == 0 && strcmp(text, MENU_SEPARATOR_ITEM) != 0); |
| 364 | 52 | } |
| 365 | 53 | |
| 366 | 54 | |
| r13466 | r13467 | |
| 370 | 58 | reported a key |
| 371 | 59 | -------------------------------------------------*/ |
| 372 | 60 | |
| 373 | | INLINE int exclusive_input_pressed(ui_menu *menu, int key, int repeat) |
| 61 | inline bool ui_menu::exclusive_input_pressed(int key, int repeat) |
| 374 | 62 | { |
| 375 | | if (menu->menu_event.iptkey == IPT_INVALID && ui_input_pressed_repeat(menu->machine(), key, repeat)) |
| 63 | if (menu_event.iptkey == IPT_INVALID && ui_input_pressed_repeat(machine(), key, repeat)) |
| 376 | 64 | { |
| 377 | | menu->menu_event.iptkey = key; |
| 378 | | return TRUE; |
| 65 | menu_event.iptkey = key; |
| 66 | return true; |
| 379 | 67 | } |
| 380 | | return FALSE; |
| 68 | return false; |
| 381 | 69 | } |
| 382 | 70 | |
| 383 | 71 | |
| r13466 | r13467 | |
| 387 | 75 | ***************************************************************************/ |
| 388 | 76 | |
| 389 | 77 | /*------------------------------------------------- |
| 390 | | ui_menu_init - initialize the menu system |
| 78 | init - initialize the menu system |
| 391 | 79 | -------------------------------------------------*/ |
| 392 | 80 | |
| 393 | | void ui_menu_init(running_machine &machine) |
| 81 | void ui_menu::init(running_machine &machine) |
| 394 | 82 | { |
| 395 | 83 | int x; |
| 396 | 84 | |
| 397 | 85 | /* initialize the menu stack */ |
| 398 | | ui_menu_stack_reset(machine); |
| 86 | ui_menu::stack_reset(machine); |
| 399 | 87 | |
| 400 | 88 | /* create a texture for hilighting items */ |
| 401 | 89 | hilight_bitmap = auto_bitmap_alloc(machine, 256, 1, BITMAP_FORMAT_ARGB32); |
| r13466 | r13467 | |
| 410 | 98 | hilight_texture->set_bitmap(hilight_bitmap, NULL, TEXFORMAT_ARGB32); |
| 411 | 99 | |
| 412 | 100 | /* create a texture for arrow icons */ |
| 413 | | arrow_texture = machine.render().texture_alloc(menu_render_triangle); |
| 101 | arrow_texture = machine.render().texture_alloc(render_triangle); |
| 414 | 102 | |
| 415 | 103 | /* add an exit callback to free memory */ |
| 416 | | machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(ui_menu_exit), &machine)); |
| 104 | machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(ui_menu::exit), &machine)); |
| 417 | 105 | } |
| 418 | 106 | |
| 419 | 107 | |
| 420 | 108 | /*------------------------------------------------- |
| 421 | | ui_menu_exit - clean up after ourselves |
| 109 | exit - clean up after ourselves |
| 422 | 110 | -------------------------------------------------*/ |
| 423 | 111 | |
| 424 | | static void ui_menu_exit(running_machine &machine) |
| 112 | void ui_menu::exit(running_machine &machine) |
| 425 | 113 | { |
| 426 | 114 | /* free menus */ |
| 427 | | ui_menu_stack_reset(machine); |
| 428 | | ui_menu_clear_free_list(machine); |
| 115 | ui_menu::stack_reset(machine); |
| 116 | ui_menu::clear_free_list(machine); |
| 429 | 117 | |
| 430 | 118 | /* free textures */ |
| 431 | 119 | machine.render().texture_free(hilight_texture); |
| 432 | 120 | machine.render().texture_free(arrow_texture); |
| 433 | | |
| 434 | | if (drivlist) |
| 435 | | { |
| 436 | | global_free(drivlist); |
| 437 | | drivlist = NULL; |
| 438 | | } |
| 439 | 121 | } |
| 440 | 122 | |
| 441 | 123 | |
| r13466 | r13467 | |
| 450 | 132 | |
| 451 | 133 | ui_menu *ui_menu_alloc(running_machine &machine, render_container *container, ui_menu_handler_func handler, void *parameter) |
| 452 | 134 | { |
| 453 | | ui_menu *menu; |
| 135 | return auto_alloc_clear(machine, ui_menu(machine, container, handler, parameter)); |
| 136 | } |
| 454 | 137 | |
| 455 | | /* allocate and clear memory for the menu and the state */ |
| 456 | | menu = auto_alloc_clear(machine, ui_menu(machine)); |
| 457 | 138 | |
| 458 | | /* initialize the state */ |
| 459 | | menu->container = container; |
| 460 | | menu->handler = handler; |
| 461 | | menu->parameter = parameter; |
| 139 | /*------------------------------------------------- |
| 140 | ui_menu - menu constructor |
| 141 | -------------------------------------------------*/ |
| 142 | ui_menu::ui_menu(running_machine &machine, render_container *_container, ui_menu_handler_func _handler, void *_parameter) : m_machine(machine) |
| 143 | { |
| 144 | special_main_menu = false; |
| 145 | container = _container; |
| 146 | handler = _handler; |
| 147 | parameter = _parameter; |
| 462 | 148 | |
| 463 | | /* reset the menu (adds a default entry) */ |
| 464 | | ui_menu_reset(menu, UI_MENU_RESET_SELECT_FIRST); |
| 465 | | return menu; |
| 149 | reset(UI_MENU_RESET_SELECT_FIRST); |
| 466 | 150 | } |
| 467 | 151 | |
| 468 | 152 | |
| 469 | 153 | /*------------------------------------------------- |
| 470 | | ui_menu_free - free a menu |
| 154 | ~ui_menu - menu destructor |
| 471 | 155 | -------------------------------------------------*/ |
| 472 | 156 | |
| 473 | | void ui_menu_free(ui_menu *menu) |
| 157 | ui_menu::~ui_menu() |
| 474 | 158 | { |
| 475 | 159 | /* free the pools */ |
| 476 | | while (menu->pool != NULL) |
| 160 | while (pool) |
| 477 | 161 | { |
| 478 | | ui_menu_pool *pool = menu->pool; |
| 479 | | menu->pool = pool->next; |
| 480 | | auto_free(menu->machine(), pool); |
| 162 | ui_menu_pool *ppool = pool; |
| 163 | pool = pool->next; |
| 164 | auto_free(machine(), ppool); |
| 481 | 165 | } |
| 482 | 166 | |
| 483 | 167 | /* free the item array */ |
| 484 | | if (menu->item != NULL) |
| 485 | | auto_free(menu->machine(), menu->item); |
| 168 | if (item) |
| 169 | auto_free(machine(), item); |
| 486 | 170 | |
| 487 | 171 | /* free the state */ |
| 488 | | if (menu->state != NULL) |
| 172 | if (state != NULL) |
| 489 | 173 | { |
| 490 | | if (menu->destroy_state != NULL) |
| 491 | | (*menu->destroy_state)(menu, menu->state); |
| 492 | | auto_free(menu->machine(), menu->state); |
| 174 | if (destroy_state) |
| 175 | destroy_state(this, state); |
| 176 | auto_free(machine(), state); |
| 493 | 177 | } |
| 494 | | |
| 495 | | /* free the menu */ |
| 496 | | auto_free(menu->machine(), menu); |
| 497 | 178 | } |
| 498 | 179 | |
| 499 | 180 | |
| 500 | 181 | /*------------------------------------------------- |
| 501 | | ui_menu_reset - free all items in the menu, |
| 182 | reset - free all items in the menu, |
| 502 | 183 | and all memory allocated from the memory pool |
| 503 | 184 | -------------------------------------------------*/ |
| 504 | 185 | |
| 505 | | void ui_menu_reset(ui_menu *menu, ui_menu_reset_options options) |
| 186 | void ui_menu::reset(ui_menu_reset_options options) |
| 506 | 187 | { |
| 507 | | ui_menu_pool *pool; |
| 508 | | |
| 509 | 188 | /* based on the reset option, set the reset info */ |
| 510 | | menu->resetpos = 0; |
| 511 | | menu->resetref = NULL; |
| 189 | resetpos = 0; |
| 190 | resetref = NULL; |
| 512 | 191 | if (options == UI_MENU_RESET_REMEMBER_POSITION) |
| 513 | | menu->resetpos = menu->selected; |
| 192 | resetpos = selected; |
| 514 | 193 | else if (options == UI_MENU_RESET_REMEMBER_REF) |
| 515 | | menu->resetref = menu->item[menu->selected].ref; |
| 194 | resetref = item[selected].ref; |
| 516 | 195 | |
| 517 | 196 | /* reset all the pools and the numitems back to 0 */ |
| 518 | | for (pool = menu->pool; pool != NULL; pool = pool->next) |
| 519 | | pool->top = (UINT8 *)(pool + 1); |
| 520 | | menu->numitems = 0; |
| 521 | | menu->visitems = 0; |
| 522 | | menu->selected = 0; |
| 197 | for (ui_menu_pool *ppool = pool; ppool != NULL; ppool = ppool->next) |
| 198 | ppool->top = (UINT8 *)(ppool + 1); |
| 199 | numitems = 0; |
| 200 | visitems = 0; |
| 201 | selected = 0; |
| 523 | 202 | astring backtext; |
| 524 | 203 | backtext.printf("Return to %s",emulator_info::get_capstartgamenoun()); |
| 525 | 204 | |
| 526 | 205 | /* add an item to return */ |
| 527 | | if (menu->parent == NULL) |
| 528 | | ui_menu_item_append(menu, backtext.cstr(), NULL, 0, NULL); |
| 529 | | else if (menu->parent->handler == menu_quit_game) |
| 530 | | ui_menu_item_append(menu, exittext, NULL, 0, NULL); |
| 206 | if (parent == NULL) |
| 207 | item_append(backtext.cstr(), NULL, 0, NULL); |
| 208 | else if (parent->is_special_main_menu()) |
| 209 | item_append("Exit", NULL, 0, NULL); |
| 531 | 210 | else |
| 532 | | ui_menu_item_append(menu, priortext, NULL, 0, NULL); |
| 211 | item_append("Return to Prior Menu", NULL, 0, NULL); |
| 533 | 212 | } |
| 534 | 213 | |
| 535 | 214 | |
| 536 | 215 | /*------------------------------------------------- |
| 537 | | ui_menu_populated - returns TRUE if the menu |
| 216 | is_special_main_menu - returns whether the |
| 217 | menu has special needs |
| 218 | -------------------------------------------------*/ |
| 219 | bool ui_menu::is_special_main_menu() const |
| 220 | { |
| 221 | return special_main_menu; |
| 222 | } |
| 223 | |
| 224 | |
| 225 | /*------------------------------------------------- |
| 226 | set_special_main_menu - set whether the |
| 227 | menu has special needs |
| 228 | -------------------------------------------------*/ |
| 229 | void ui_menu::set_special_main_menu(bool special) |
| 230 | { |
| 231 | special_main_menu = special; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | /*------------------------------------------------- |
| 236 | populated - returns true if the menu |
| 538 | 237 | has any non-default items in it |
| 539 | 238 | -------------------------------------------------*/ |
| 540 | 239 | |
| 541 | | int ui_menu_populated(ui_menu *menu) |
| 240 | bool ui_menu::populated() |
| 542 | 241 | { |
| 543 | | return (menu->numitems > 1); |
| 242 | return numitems > 1; |
| 544 | 243 | } |
| 545 | 244 | |
| 546 | 245 | |
| 547 | 246 | /*------------------------------------------------- |
| 548 | | ui_menu_item_append - append a new item to the |
| 247 | item_append - append a new item to the |
| 549 | 248 | end of the menu |
| 550 | 249 | -------------------------------------------------*/ |
| 551 | 250 | |
| 552 | | void ui_menu_item_append(ui_menu *menu, const char *text, const char *subtext, UINT32 flags, void *ref) |
| 251 | void ui_menu::item_append(const char *text, const char *subtext, UINT32 flags, void *ref) |
| 553 | 252 | { |
| 554 | | ui_menu_item *item; |
| 253 | ui_menu_item *pitem; |
| 555 | 254 | int index; |
| 556 | 255 | |
| 557 | 256 | /* only allow multiline as the first item */ |
| 558 | 257 | if ((flags & MENU_FLAG_MULTILINE) != 0) |
| 559 | | assert(menu->numitems == 1); |
| 258 | assert(numitems == 1); |
| 560 | 259 | |
| 561 | 260 | /* only allow a single multi-line item */ |
| 562 | | else if (menu->numitems >= 2) |
| 563 | | assert((menu->item[0].flags & MENU_FLAG_MULTILINE) == 0); |
| 261 | else if (numitems >= 2) |
| 262 | assert((item[0].flags & MENU_FLAG_MULTILINE) == 0); |
| 564 | 263 | |
| 565 | 264 | /* realloc the item array if necessary */ |
| 566 | | if (menu->numitems >= menu->allocitems) |
| 265 | if (numitems >= allocitems) |
| 567 | 266 | { |
| 568 | | int olditems = menu->allocitems; |
| 569 | | menu->allocitems += UI_MENU_ALLOC_ITEMS; |
| 570 | | ui_menu_item *newitems = auto_alloc_array(menu->machine(), ui_menu_item, menu->allocitems); |
| 267 | int olditems = allocitems; |
| 268 | allocitems += UI_MENU_ALLOC_ITEMS; |
| 269 | ui_menu_item *newitems = auto_alloc_array(machine(), ui_menu_item, allocitems); |
| 571 | 270 | for (int itemnum = 0; itemnum < olditems; itemnum++) |
| 572 | | newitems[itemnum] = menu->item[itemnum]; |
| 573 | | auto_free(menu->machine(), menu->item); |
| 574 | | menu->item = newitems; |
| 271 | newitems[itemnum] = item[itemnum]; |
| 272 | auto_free(machine(), item); |
| 273 | item = newitems; |
| 575 | 274 | } |
| 576 | | index = menu->numitems++; |
| 275 | index = numitems++; |
| 577 | 276 | |
| 578 | 277 | /* copy the previous last item to the next one */ |
| 579 | 278 | if (index != 0) |
| 580 | 279 | { |
| 581 | 280 | index--; |
| 582 | | menu->item[index + 1] = menu->item[index]; |
| 281 | item[index + 1] = item[index]; |
| 583 | 282 | } |
| 584 | 283 | |
| 585 | 284 | /* allocate a new item and populte it */ |
| 586 | | item = &menu->item[index]; |
| 587 | | item->text = (text != NULL) ? ui_menu_pool_strdup(menu, text) : NULL; |
| 588 | | item->subtext = (subtext != NULL) ? ui_menu_pool_strdup(menu, subtext) : NULL; |
| 589 | | item->flags = flags; |
| 590 | | item->ref = ref; |
| 285 | pitem = &item[index]; |
| 286 | pitem->text = (text != NULL) ? pool_strdup(text) : NULL; |
| 287 | pitem->subtext = (subtext != NULL) ? pool_strdup(subtext) : NULL; |
| 288 | pitem->flags = flags; |
| 289 | pitem->ref = ref; |
| 591 | 290 | |
| 592 | 291 | /* update the selection if we need to */ |
| 593 | | if (menu->resetpos == index || (menu->resetref != NULL && menu->resetref == ref)) |
| 594 | | menu->selected = index; |
| 595 | | if (menu->resetpos == menu->numitems - 1) |
| 596 | | menu->selected = menu->numitems - 1; |
| 292 | if (resetpos == index || (resetref != NULL && resetref == ref)) |
| 293 | selected = index; |
| 294 | if (resetpos == numitems - 1) |
| 295 | selected = numitems - 1; |
| 597 | 296 | } |
| 598 | 297 | |
| 599 | 298 | |
| 600 | 299 | /*------------------------------------------------- |
| 601 | | ui_menu_process - process a menu, drawing it |
| 300 | process - process a menu, drawing it |
| 602 | 301 | and returning any interesting events |
| 603 | 302 | -------------------------------------------------*/ |
| 604 | 303 | |
| 605 | | const ui_menu_event *ui_menu_process(running_machine &machine, ui_menu *menu, UINT32 flags) |
| 304 | const ui_menu_event *ui_menu::process(UINT32 flags) |
| 606 | 305 | { |
| 607 | 306 | /* reset the menu_event */ |
| 608 | | menu->menu_event.iptkey = IPT_INVALID; |
| 307 | menu_event.iptkey = IPT_INVALID; |
| 609 | 308 | |
| 610 | 309 | /* first make sure our selection is valid */ |
| 611 | | ui_menu_validate_selection(menu, 1); |
| 310 | validate_selection(1); |
| 612 | 311 | |
| 613 | 312 | /* draw the menu */ |
| 614 | | if (menu->numitems > 1 && (menu->item[0].flags & MENU_FLAG_MULTILINE) != 0) |
| 615 | | ui_menu_draw_text_box(menu); |
| 313 | if (numitems > 1 && (item[0].flags & MENU_FLAG_MULTILINE) != 0) |
| 314 | draw_text_box(); |
| 616 | 315 | else |
| 617 | | ui_menu_draw(machine, menu, (flags & UI_MENU_PROCESS_CUSTOM_ONLY) != 0); |
| 316 | draw(flags & UI_MENU_PROCESS_CUSTOM_ONLY); |
| 618 | 317 | |
| 619 | 318 | /* process input */ |
| 620 | 319 | if (!(flags & UI_MENU_PROCESS_NOKEYS)) |
| 621 | 320 | { |
| 622 | 321 | /* read events */ |
| 623 | | ui_menu_handle_events(menu); |
| 322 | handle_events(); |
| 624 | 323 | |
| 625 | 324 | /* handle the keys if we don't already have an menu_event */ |
| 626 | | if (menu->menu_event.iptkey == IPT_INVALID) |
| 627 | | ui_menu_handle_keys(menu, flags); |
| 325 | if (menu_event.iptkey == IPT_INVALID) |
| 326 | handle_keys(flags); |
| 628 | 327 | } |
| 629 | 328 | |
| 630 | 329 | /* update the selected item in the menu_event */ |
| 631 | | if (menu->menu_event.iptkey != IPT_INVALID && menu->selected >= 0 && menu->selected < menu->numitems) |
| 330 | if (menu_event.iptkey != IPT_INVALID && selected >= 0 && selected < numitems) |
| 632 | 331 | { |
| 633 | | menu->menu_event.itemref = menu->item[menu->selected].ref; |
| 634 | | return &menu->menu_event; |
| 332 | menu_event.itemref = item[selected].ref; |
| 333 | return &menu_event; |
| 635 | 334 | } |
| 636 | 335 | return NULL; |
| 637 | 336 | } |
| 638 | 337 | |
| 639 | 338 | |
| 640 | 339 | /*------------------------------------------------- |
| 641 | | ui_menu_set_custom_render - configure the menu |
| 340 | set_custom_render - configure the menu |
| 642 | 341 | for custom rendering |
| 643 | 342 | -------------------------------------------------*/ |
| 644 | 343 | |
| 645 | | void ui_menu_set_custom_render(ui_menu *menu, ui_menu_custom_func custom, float top, float bottom) |
| 344 | void ui_menu::set_custom_render(ui_menu_custom_func customfn, float top, float bottom) |
| 646 | 345 | { |
| 647 | | menu->custom = custom; |
| 648 | | menu->customtop = top; |
| 649 | | menu->custombottom = bottom; |
| 346 | custom = customfn; |
| 347 | customtop = top; |
| 348 | custombottom = bottom; |
| 650 | 349 | } |
| 651 | 350 | |
| 652 | 351 | |
| 653 | 352 | /*------------------------------------------------- |
| 654 | | ui_menu_alloc_state - allocate permanent |
| 353 | alloc_state - allocate permanent |
| 655 | 354 | memory to represent the menu's state |
| 656 | 355 | -------------------------------------------------*/ |
| 657 | 356 | |
| 658 | | void *ui_menu_alloc_state(ui_menu *menu, size_t size, ui_menu_destroy_state_func destroy_state) |
| 357 | void *ui_menu::alloc_state(size_t size, ui_menu_destroy_state_func destroy_state_fn) |
| 659 | 358 | { |
| 660 | | if (menu->state != NULL) |
| 359 | if (state != NULL) |
| 661 | 360 | { |
| 662 | | if (menu->destroy_state != NULL) |
| 663 | | (*menu->destroy_state)(menu, menu->state); |
| 664 | | auto_free(menu->machine(), menu->state); |
| 361 | if (destroy_state != NULL) |
| 362 | destroy_state(this, state); |
| 363 | auto_free(machine(), state); |
| 665 | 364 | } |
| 666 | | menu->state = auto_alloc_array_clear(menu->machine(), UINT8, size); |
| 667 | | menu->destroy_state = destroy_state; |
| 365 | state = auto_alloc_array_clear(machine(), UINT8, size); |
| 366 | destroy_state = destroy_state_fn; |
| 668 | 367 | |
| 669 | | return menu->state; |
| 368 | return state; |
| 670 | 369 | } |
| 671 | 370 | |
| 672 | 371 | |
| 673 | 372 | /*------------------------------------------------- |
| 674 | | ui_menu_pool_alloc - allocate temporary memory |
| 373 | m_pool_alloc - allocate temporary memory |
| 675 | 374 | from the menu's memory pool |
| 676 | 375 | -------------------------------------------------*/ |
| 677 | 376 | |
| 678 | | void *ui_menu_pool_alloc(ui_menu *menu, size_t size) |
| 377 | void *ui_menu::m_pool_alloc(size_t size) |
| 679 | 378 | { |
| 680 | | ui_menu_pool *pool; |
| 379 | ui_menu_pool *ppool; |
| 681 | 380 | |
| 682 | 381 | assert(size < UI_MENU_POOL_SIZE); |
| 683 | 382 | |
| 684 | 383 | /* find a pool with enough room */ |
| 685 | | for (pool = menu->pool; pool != NULL; pool = pool->next) |
| 686 | | if (pool->end - pool->top >= size) |
| 384 | for (ppool = pool; ppool != NULL; ppool = ppool->next) |
| 385 | if (ppool->end - ppool->top >= size) |
| 687 | 386 | { |
| 688 | | void *result = pool->top; |
| 689 | | pool->top += size; |
| 387 | void *result = ppool->top; |
| 388 | ppool->top += size; |
| 690 | 389 | return result; |
| 691 | 390 | } |
| 692 | 391 | |
| 693 | 392 | /* allocate a new pool */ |
| 694 | | pool = (ui_menu_pool *)auto_alloc_array_clear(menu->machine(), UINT8, sizeof(*pool) + UI_MENU_POOL_SIZE); |
| 393 | ppool = (ui_menu_pool *)auto_alloc_array_clear(machine(), UINT8, sizeof(*ppool) + UI_MENU_POOL_SIZE); |
| 695 | 394 | |
| 696 | 395 | /* wire it up */ |
| 697 | | pool->next = menu->pool; |
| 698 | | menu->pool = pool; |
| 699 | | pool->top = (UINT8 *)(pool + 1); |
| 700 | | pool->end = pool->top + UI_MENU_POOL_SIZE; |
| 701 | | return ui_menu_pool_alloc(menu, size); |
| 396 | ppool->next = pool; |
| 397 | pool = ppool; |
| 398 | ppool->top = (UINT8 *)(ppool + 1); |
| 399 | ppool->end = ppool->top + UI_MENU_POOL_SIZE; |
| 400 | return m_pool_alloc(size); |
| 702 | 401 | } |
| 703 | 402 | |
| 704 | 403 | |
| 705 | 404 | /*------------------------------------------------- |
| 706 | | ui_menu_pool_strdup - make a temporary string |
| 405 | pool_strdup - make a temporary string |
| 707 | 406 | copy in the menu's memory pool |
| 708 | 407 | -------------------------------------------------*/ |
| 709 | 408 | |
| 710 | | const char *ui_menu_pool_strdup(ui_menu *menu, const char *string) |
| 409 | const char *ui_menu::pool_strdup(const char *string) |
| 711 | 410 | { |
| 712 | | return strcpy((char *)ui_menu_pool_alloc(menu, strlen(string) + 1), string); |
| 411 | return strcpy((char *)m_pool_alloc(strlen(string) + 1), string); |
| 713 | 412 | } |
| 714 | 413 | |
| 715 | 414 | |
| 716 | 415 | /*------------------------------------------------- |
| 717 | | ui_menu_get_selection - retrieves the index |
| 416 | get_selection - retrieves the index |
| 718 | 417 | of the currently selected menu item |
| 719 | 418 | -------------------------------------------------*/ |
| 720 | 419 | |
| 721 | | void *ui_menu_get_selection(ui_menu *menu) |
| 420 | void *ui_menu::get_selection() |
| 722 | 421 | { |
| 723 | | return (menu->selected >= 0 && menu->selected < menu->numitems) ? menu->item[menu->selected].ref : NULL; |
| 422 | return (selected >= 0 && selected < numitems) ? item[selected].ref : NULL; |
| 724 | 423 | } |
| 725 | 424 | |
| 726 | 425 | |
| 727 | 426 | /*------------------------------------------------- |
| 728 | | ui_menu_set_selection - changes the index |
| 427 | set_selection - changes the index |
| 729 | 428 | of the currently selected menu item |
| 730 | 429 | -------------------------------------------------*/ |
| 731 | 430 | |
| 732 | | void ui_menu_set_selection(ui_menu *menu, void *selected_itemref) |
| 431 | void ui_menu::set_selection(void *selected_itemref) |
| 733 | 432 | { |
| 734 | 433 | int itemnum; |
| 735 | 434 | |
| 736 | | menu->selected = -1; |
| 737 | | for (itemnum = 0; itemnum < menu->numitems; itemnum++) |
| 738 | | if (menu->item[itemnum].ref == selected_itemref) |
| 435 | selected = -1; |
| 436 | for (itemnum = 0; itemnum < numitems; itemnum++) |
| 437 | if (item[itemnum].ref == selected_itemref) |
| 739 | 438 | { |
| 740 | | menu->selected = itemnum; |
| 439 | selected = itemnum; |
| 741 | 440 | break; |
| 742 | 441 | } |
| 743 | 442 | } |
| r13466 | r13467 | |
| 749 | 448 | ***************************************************************************/ |
| 750 | 449 | |
| 751 | 450 | /*------------------------------------------------- |
| 752 | | ui_menu_draw - draw a menu |
| 451 | draw - draw a menu |
| 753 | 452 | -------------------------------------------------*/ |
| 754 | 453 | |
| 755 | | static void ui_menu_draw(running_machine &machine, ui_menu *menu, int customonly) |
| 454 | void ui_menu::draw(bool customonly) |
| 756 | 455 | { |
| 757 | | float line_height = ui_get_line_height(machine); |
| 758 | | float lr_arrow_width = 0.4f * line_height * machine.render().ui_aspect(); |
| 759 | | float ud_arrow_width = line_height * machine.render().ui_aspect(); |
| 456 | float line_height = ui_get_line_height(machine()); |
| 457 | float lr_arrow_width = 0.4f * line_height * machine().render().ui_aspect(); |
| 458 | float ud_arrow_width = line_height * machine().render().ui_aspect(); |
| 760 | 459 | float gutter_width = lr_arrow_width * 1.3f; |
| 761 | 460 | float x1, y1, x2, y2; |
| 762 | 461 | |
| r13466 | r13467 | |
| 776 | 475 | /* compute the width and height of the full menu */ |
| 777 | 476 | visible_width = 0; |
| 778 | 477 | visible_main_menu_height = 0; |
| 779 | | for (itemnum = 0; itemnum < menu->numitems; itemnum++) |
| 478 | for (itemnum = 0; itemnum < numitems; itemnum++) |
| 780 | 479 | { |
| 781 | | const ui_menu_item *item = &menu->item[itemnum]; |
| 480 | const ui_menu_item &pitem = item[itemnum]; |
| 782 | 481 | float total_width; |
| 783 | 482 | |
| 784 | 483 | /* compute width of left hand side */ |
| 785 | | total_width = gutter_width + ui_get_string_width(machine, item->text) + gutter_width; |
| 484 | total_width = gutter_width + ui_get_string_width(machine(), pitem.text) + gutter_width; |
| 786 | 485 | |
| 787 | 486 | /* add in width of right hand side */ |
| 788 | | if (item->subtext) |
| 789 | | total_width += 2.0f * gutter_width + ui_get_string_width(machine, item->subtext); |
| 487 | if (pitem.subtext) |
| 488 | total_width += 2.0f * gutter_width + ui_get_string_width(machine(), pitem.subtext); |
| 790 | 489 | |
| 791 | 490 | /* track the maximum */ |
| 792 | 491 | if (total_width > visible_width) |
| r13466 | r13467 | |
| 797 | 496 | } |
| 798 | 497 | |
| 799 | 498 | /* account for extra space at the top and bottom */ |
| 800 | | visible_extra_menu_height = menu->customtop + menu->custombottom; |
| 499 | visible_extra_menu_height = customtop + custombottom; |
| 801 | 500 | |
| 802 | 501 | /* add a little bit of slop for rounding */ |
| 803 | 502 | visible_width += 0.01f; |
| r13466 | r13467 | |
| 819 | 518 | visible_top = (1.0f - (visible_main_menu_height + visible_extra_menu_height)) * 0.5f; |
| 820 | 519 | |
| 821 | 520 | /* if the menu is at the bottom of the extra, adjust */ |
| 822 | | visible_top += menu->customtop; |
| 521 | visible_top += customtop; |
| 823 | 522 | |
| 824 | 523 | /* first add us a box */ |
| 825 | 524 | x1 = visible_left - UI_BOX_LR_BORDER; |
| r13466 | r13467 | |
| 827 | 526 | x2 = visible_left + visible_width + UI_BOX_LR_BORDER; |
| 828 | 527 | y2 = visible_top + visible_main_menu_height + UI_BOX_TB_BORDER; |
| 829 | 528 | if (!customonly) |
| 830 | | ui_draw_outlined_box(menu->container, x1, y1, x2, y2, UI_BACKGROUND_COLOR); |
| 529 | ui_draw_outlined_box(container, x1, y1, x2, y2, UI_BACKGROUND_COLOR); |
| 831 | 530 | |
| 832 | 531 | /* determine the first visible line based on the current selection */ |
| 833 | | top_line = menu->selected - visible_lines / 2; |
| 532 | top_line = selected - visible_lines / 2; |
| 834 | 533 | if (top_line < 0) |
| 835 | 534 | top_line = 0; |
| 836 | | if (top_line + visible_lines >= menu->numitems) |
| 837 | | top_line = menu->numitems - visible_lines; |
| 535 | if (top_line + visible_lines >= numitems) |
| 536 | top_line = numitems - visible_lines; |
| 838 | 537 | |
| 839 | 538 | /* determine effective positions taking into account the hilighting arrows */ |
| 840 | 539 | effective_width = visible_width - 2.0f * gutter_width; |
| r13466 | r13467 | |
| 845 | 544 | mouse_button = FALSE; |
| 846 | 545 | if (!customonly) |
| 847 | 546 | { |
| 848 | | mouse_target = ui_input_find_mouse(machine, &mouse_target_x, &mouse_target_y, &mouse_button); |
| 547 | mouse_target = ui_input_find_mouse(machine(), &mouse_target_x, &mouse_target_y, &mouse_button); |
| 849 | 548 | if (mouse_target != NULL) |
| 850 | | if (mouse_target->map_point_container(mouse_target_x, mouse_target_y, *menu->container, mouse_x, mouse_y)) |
| 549 | if (mouse_target->map_point_container(mouse_target_x, mouse_target_y, *container, mouse_x, mouse_y)) |
| 851 | 550 | mouse_hit = TRUE; |
| 852 | 551 | } |
| 853 | 552 | |
| 854 | 553 | /* loop over visible lines */ |
| 855 | | menu->hover = menu->numitems + 1; |
| 554 | hover = numitems + 1; |
| 856 | 555 | if (!customonly) |
| 857 | 556 | for (linenum = 0; linenum < visible_lines; linenum++) |
| 858 | 557 | { |
| 859 | 558 | float line_y = visible_top + (float)linenum * line_height; |
| 860 | 559 | itemnum = top_line + linenum; |
| 861 | | const ui_menu_item *item = &menu->item[itemnum]; |
| 862 | | const char *itemtext = item->text; |
| 560 | const ui_menu_item &pitem = item[itemnum]; |
| 561 | const char *itemtext = pitem.text; |
| 863 | 562 | rgb_t fgcolor = UI_TEXT_COLOR; |
| 864 | 563 | rgb_t bgcolor = UI_TEXT_BG_COLOR; |
| 865 | 564 | rgb_t fgcolor2 = UI_SUBITEM_COLOR; |
| r13466 | r13467 | |
| 870 | 569 | float line_y1 = line_y + line_height; |
| 871 | 570 | |
| 872 | 571 | /* set the hover if this is our item */ |
| 873 | | if (mouse_hit && line_x0 <= mouse_x && line_x1 > mouse_x && line_y0 <= mouse_y && line_y1 > mouse_y && item_is_selectable(item)) |
| 874 | | menu->hover = itemnum; |
| 572 | if (mouse_hit && line_x0 <= mouse_x && line_x1 > mouse_x && line_y0 <= mouse_y && line_y1 > mouse_y && pitem.is_selectable()) |
| 573 | hover = itemnum; |
| 875 | 574 | |
| 876 | 575 | /* if we're selected, draw with a different background */ |
| 877 | | if (itemnum == menu->selected) |
| 576 | if (itemnum == selected) |
| 878 | 577 | { |
| 879 | 578 | fgcolor = UI_SELECTED_COLOR; |
| 880 | 579 | bgcolor = UI_SELECTED_BG_COLOR; |
| r13466 | r13467 | |
| 883 | 582 | } |
| 884 | 583 | |
| 885 | 584 | /* else if the mouse is over this item, draw with a different background */ |
| 886 | | else if (itemnum == menu->hover) |
| 585 | else if (itemnum == hover) |
| 887 | 586 | { |
| 888 | 587 | fgcolor = UI_MOUSEOVER_COLOR; |
| 889 | 588 | bgcolor = UI_MOUSEOVER_BG_COLOR; |
| r13466 | r13467 | |
| 893 | 592 | |
| 894 | 593 | /* if we have some background hilighting to do, add a quad behind everything else */ |
| 895 | 594 | if (bgcolor != UI_TEXT_BG_COLOR) |
| 896 | | menu->container->add_quad(line_x0, line_y0, line_x1, line_y1, bgcolor, hilight_texture, |
| 595 | container->add_quad(line_x0, line_y0, line_x1, line_y1, bgcolor, hilight_texture, |
| 897 | 596 | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(TRUE)); |
| 898 | 597 | |
| 899 | 598 | /* if we're on the top line, display the up arrow */ |
| 900 | 599 | if (linenum == 0 && top_line != 0) |
| 901 | 600 | { |
| 902 | | menu->container->add_quad( |
| 601 | container->add_quad( |
| 903 | 602 | 0.5f * (x1 + x2) - 0.5f * ud_arrow_width, |
| 904 | 603 | line_y + 0.25f * line_height, |
| 905 | 604 | 0.5f * (x1 + x2) + 0.5f * ud_arrow_width, |
| r13466 | r13467 | |
| 907 | 606 | fgcolor, |
| 908 | 607 | arrow_texture, |
| 909 | 608 | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXORIENT(ROT0)); |
| 910 | | if (menu->hover == itemnum) |
| 911 | | menu->hover = -2; |
| 609 | if (hover == itemnum) |
| 610 | hover = -2; |
| 912 | 611 | } |
| 913 | 612 | |
| 914 | 613 | /* if we're on the bottom line, display the down arrow */ |
| 915 | | else if (linenum == visible_lines - 1 && itemnum != menu->numitems - 1) |
| 614 | else if (linenum == visible_lines - 1 && itemnum != numitems - 1) |
| 916 | 615 | { |
| 917 | | menu->container->add_quad( |
| 616 | container->add_quad( |
| 918 | 617 | 0.5f * (x1 + x2) - 0.5f * ud_arrow_width, |
| 919 | 618 | line_y + 0.25f * line_height, |
| 920 | 619 | 0.5f * (x1 + x2) + 0.5f * ud_arrow_width, |
| r13466 | r13467 | |
| 922 | 621 | fgcolor, |
| 923 | 622 | arrow_texture, |
| 924 | 623 | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXORIENT(ROT0 ^ ORIENTATION_FLIP_Y)); |
| 925 | | if (menu->hover == itemnum) |
| 926 | | menu->hover = -1; |
| 624 | if (hover == itemnum) |
| 625 | hover = -1; |
| 927 | 626 | } |
| 928 | 627 | |
| 929 | 628 | /* if we're just a divider, draw a line */ |
| 930 | 629 | else if (strcmp(itemtext, MENU_SEPARATOR_ITEM) == 0) |
| 931 | | menu->container->add_line(visible_left, line_y + 0.5f * line_height, visible_left + visible_width, line_y + 0.5f * line_height, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 630 | container->add_line(visible_left, line_y + 0.5f * line_height, visible_left + visible_width, line_y + 0.5f * line_height, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 932 | 631 | |
| 933 | 632 | /* if we don't have a subitem, just draw the string centered */ |
| 934 | | else if (item->subtext == NULL) |
| 935 | | ui_draw_text_full(menu->container, itemtext, effective_left, line_y, effective_width, |
| 633 | else if (pitem.subtext == NULL) |
| 634 | ui_draw_text_full(container, itemtext, effective_left, line_y, effective_width, |
| 936 | 635 | JUSTIFY_CENTER, WRAP_TRUNCATE, DRAW_NORMAL, fgcolor, bgcolor, NULL, NULL); |
| 937 | 636 | |
| 938 | 637 | /* otherwise, draw the item on the left and the subitem text on the right */ |
| 939 | 638 | else |
| 940 | 639 | { |
| 941 | | int subitem_invert = item->flags & MENU_FLAG_INVERT; |
| 942 | | const char *subitem_text = item->subtext; |
| 640 | int subitem_invert = pitem.flags & MENU_FLAG_INVERT; |
| 641 | const char *subitem_text = pitem.subtext; |
| 943 | 642 | float item_width, subitem_width; |
| 944 | 643 | |
| 945 | 644 | /* draw the left-side text */ |
| 946 | | ui_draw_text_full(menu->container, itemtext, effective_left, line_y, effective_width, |
| 645 | ui_draw_text_full(container, itemtext, effective_left, line_y, effective_width, |
| 947 | 646 | JUSTIFY_LEFT, WRAP_TRUNCATE, DRAW_NORMAL, fgcolor, bgcolor, &item_width, NULL); |
| 948 | 647 | |
| 949 | 648 | /* give 2 spaces worth of padding */ |
| 950 | 649 | item_width += 2.0f * gutter_width; |
| 951 | 650 | |
| 952 | 651 | /* if the subitem doesn't fit here, display dots */ |
| 953 | | if (ui_get_string_width(machine, subitem_text) > effective_width - item_width) |
| 652 | if (ui_get_string_width(machine(), subitem_text) > effective_width - item_width) |
| 954 | 653 | { |
| 955 | 654 | subitem_text = "..."; |
| 956 | | if (itemnum == menu->selected) |
| 655 | if (itemnum == selected) |
| 957 | 656 | selected_subitem_too_big = TRUE; |
| 958 | 657 | } |
| 959 | 658 | |
| 960 | 659 | /* draw the subitem right-justified */ |
| 961 | | ui_draw_text_full(menu->container, subitem_text, effective_left + item_width, line_y, effective_width - item_width, |
| 660 | ui_draw_text_full(container, subitem_text, effective_left + item_width, line_y, effective_width - item_width, |
| 962 | 661 | JUSTIFY_RIGHT, WRAP_TRUNCATE, DRAW_NORMAL, subitem_invert ? fgcolor3 : fgcolor2, bgcolor, &subitem_width, NULL); |
| 963 | 662 | |
| 964 | 663 | /* apply arrows */ |
| 965 | | if (itemnum == menu->selected && (item->flags & MENU_FLAG_LEFT_ARROW)) |
| 664 | if (itemnum == selected && (pitem.flags & MENU_FLAG_LEFT_ARROW)) |
| 966 | 665 | { |
| 967 | | menu->container->add_quad( |
| 666 | container->add_quad( |
| 968 | 667 | effective_left + effective_width - subitem_width - gutter_width, |
| 969 | 668 | line_y + 0.1f * line_height, |
| 970 | 669 | effective_left + effective_width - subitem_width - gutter_width + lr_arrow_width, |
| r13466 | r13467 | |
| 973 | 672 | arrow_texture, |
| 974 | 673 | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXORIENT(ROT90 ^ ORIENTATION_FLIP_X)); |
| 975 | 674 | } |
| 976 | | if (itemnum == menu->selected && (item->flags & MENU_FLAG_RIGHT_ARROW)) |
| 675 | if (itemnum == selected && (pitem.flags & MENU_FLAG_RIGHT_ARROW)) |
| 977 | 676 | { |
| 978 | | menu->container->add_quad( |
| 677 | container->add_quad( |
| 979 | 678 | effective_left + effective_width + gutter_width - lr_arrow_width, |
| 980 | 679 | line_y + 0.1f * line_height, |
| 981 | 680 | effective_left + effective_width + gutter_width, |
| r13466 | r13467 | |
| 990 | 689 | /* if the selected subitem is too big, display it in a separate offset box */ |
| 991 | 690 | if (selected_subitem_too_big) |
| 992 | 691 | { |
| 993 | | const ui_menu_item *item = &menu->item[menu->selected]; |
| 994 | | int subitem_invert = item->flags & MENU_FLAG_INVERT; |
| 995 | | linenum = menu->selected - top_line; |
| 692 | const ui_menu_item &pitem = item[selected]; |
| 693 | int subitem_invert = pitem.flags & MENU_FLAG_INVERT; |
| 694 | linenum = selected - top_line; |
| 996 | 695 | float line_y = visible_top + (float)linenum * line_height; |
| 997 | 696 | float target_width, target_height; |
| 998 | 697 | float target_x, target_y; |
| 999 | 698 | |
| 1000 | 699 | /* compute the multi-line target width/height */ |
| 1001 | | ui_draw_text_full(menu->container, item->subtext, 0, 0, visible_width * 0.75f, |
| 700 | ui_draw_text_full(container, pitem.subtext, 0, 0, visible_width * 0.75f, |
| 1002 | 701 | JUSTIFY_RIGHT, WRAP_WORD, DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &target_width, &target_height); |
| 1003 | 702 | |
| 1004 | 703 | /* determine the target location */ |
| r13466 | r13467 | |
| 1008 | 707 | target_y = line_y - target_height - UI_BOX_TB_BORDER; |
| 1009 | 708 | |
| 1010 | 709 | /* add a box around that */ |
| 1011 | | ui_draw_outlined_box(menu->container, target_x - UI_BOX_LR_BORDER, |
| 710 | ui_draw_outlined_box(container, target_x - UI_BOX_LR_BORDER, |
| 1012 | 711 | target_y - UI_BOX_TB_BORDER, |
| 1013 | 712 | target_x + target_width + UI_BOX_LR_BORDER, |
| 1014 | 713 | target_y + target_height + UI_BOX_TB_BORDER, subitem_invert ? UI_SELECTED_BG_COLOR : UI_BACKGROUND_COLOR); |
| 1015 | | ui_draw_text_full(menu->container, item->subtext, target_x, target_y, target_width, |
| 714 | ui_draw_text_full(container, pitem.subtext, target_x, target_y, target_width, |
| 1016 | 715 | JUSTIFY_RIGHT, WRAP_WORD, DRAW_NORMAL, UI_SELECTED_COLOR, UI_SELECTED_BG_COLOR, NULL, NULL); |
| 1017 | 716 | } |
| 1018 | 717 | |
| 1019 | 718 | /* if there is something special to add, do it by calling the passed routine */ |
| 1020 | | if (menu->custom != NULL) |
| 719 | if (custom != NULL) |
| 1021 | 720 | { |
| 1022 | | void *selectedref = (menu->selected >= 0 && menu->selected < menu->numitems) ? menu->item[menu->selected].ref : NULL; |
| 1023 | | (*menu->custom)(menu->machine(), menu, menu->state, selectedref, menu->customtop, menu->custombottom, x1, y1, x2, y2); |
| 721 | void *selectedref = (selected >= 0 && selected < numitems) ? item[selected].ref : NULL; |
| 722 | custom(machine(), this, state, selectedref, customtop, custombottom, x1, y1, x2, y2); |
| 1024 | 723 | } |
| 1025 | 724 | |
| 1026 | 725 | /* return the number of visible lines, minus 1 for top arrow and 1 for bottom arrow */ |
| 1027 | | menu->visitems = visible_lines - (top_line != 0) - (top_line + visible_lines != menu->numitems); |
| 726 | visitems = visible_lines - (top_line != 0) - (top_line + visible_lines != numitems); |
| 1028 | 727 | } |
| 1029 | 728 | |
| 1030 | 729 | |
| 1031 | 730 | /*------------------------------------------------- |
| 1032 | | ui_menu_draw_text_box - draw a multiline |
| 731 | draw_text_box - draw a multiline |
| 1033 | 732 | word-wrapped text box with a menu item at the |
| 1034 | 733 | bottom |
| 1035 | 734 | -------------------------------------------------*/ |
| 1036 | 735 | |
| 1037 | | static void ui_menu_draw_text_box(ui_menu *menu) |
| 736 | void ui_menu::draw_text_box() |
| 1038 | 737 | { |
| 1039 | | const char *text = menu->item[0].text; |
| 1040 | | const char *backtext = menu->item[1].text; |
| 1041 | | float line_height = ui_get_line_height(menu->machine()); |
| 1042 | | float lr_arrow_width = 0.4f * line_height * menu->machine().render().ui_aspect(); |
| 738 | const char *text = item[0].text; |
| 739 | const char *backtext = item[1].text; |
| 740 | float line_height = ui_get_line_height(machine()); |
| 741 | float lr_arrow_width = 0.4f * line_height * machine().render().ui_aspect(); |
| 1043 | 742 | float gutter_width = lr_arrow_width; |
| 1044 | 743 | float target_width, target_height, prior_width; |
| 1045 | 744 | float target_x, target_y; |
| 1046 | 745 | |
| 1047 | 746 | /* compute the multi-line target width/height */ |
| 1048 | | ui_draw_text_full(menu->container, text, 0, 0, 1.0f - 2.0f * UI_BOX_LR_BORDER - 2.0f * gutter_width, |
| 747 | ui_draw_text_full(container, text, 0, 0, 1.0f - 2.0f * UI_BOX_LR_BORDER - 2.0f * gutter_width, |
| 1049 | 748 | JUSTIFY_LEFT, WRAP_WORD, DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &target_width, &target_height); |
| 1050 | 749 | target_height += 2.0f * line_height; |
| 1051 | 750 | if (target_height > 1.0f - 2.0f * UI_BOX_TB_BORDER) |
| 1052 | 751 | target_height = floor((1.0f - 2.0f * UI_BOX_TB_BORDER) / line_height) * line_height; |
| 1053 | 752 | |
| 1054 | 753 | /* maximum against "return to prior menu" text */ |
| 1055 | | prior_width = ui_get_string_width(menu->machine(), backtext) + 2.0f * gutter_width; |
| 754 | prior_width = ui_get_string_width(machine(), backtext) + 2.0f * gutter_width; |
| 1056 | 755 | target_width = MAX(target_width, prior_width); |
| 1057 | 756 | |
| 1058 | 757 | /* determine the target location */ |
| r13466 | r13467 | |
| 1070 | 769 | target_y = 1.0f - UI_BOX_TB_BORDER - target_height; |
| 1071 | 770 | |
| 1072 | 771 | /* add a box around that */ |
| 1073 | | ui_draw_outlined_box(menu->container, target_x - UI_BOX_LR_BORDER - gutter_width, |
| 772 | ui_draw_outlined_box(container, target_x - UI_BOX_LR_BORDER - gutter_width, |
| 1074 | 773 | target_y - UI_BOX_TB_BORDER, |
| 1075 | 774 | target_x + target_width + gutter_width + UI_BOX_LR_BORDER, |
| 1076 | | target_y + target_height + UI_BOX_TB_BORDER, (menu->item[0].flags & MENU_FLAG_REDTEXT) ? UI_RED_COLOR : UI_BACKGROUND_COLOR); |
| 1077 | | ui_draw_text_full(menu->container, text, target_x, target_y, target_width, |
| 775 | target_y + target_height + UI_BOX_TB_BORDER, (item[0].flags & MENU_FLAG_REDTEXT) ? UI_RED_COLOR : UI_BACKGROUND_COLOR); |
| 776 | ui_draw_text_full(container, text, target_x, target_y, target_width, |
| 1078 | 777 | JUSTIFY_LEFT, WRAP_WORD, DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, NULL, NULL); |
| 1079 | 778 | |
| 1080 | 779 | /* draw the "return to prior menu" text with a hilight behind it */ |
| 1081 | | menu->container->add_quad( |
| 780 | container->add_quad( |
| 1082 | 781 | target_x + 0.5f * UI_LINE_WIDTH, |
| 1083 | 782 | target_y + target_height - line_height, |
| 1084 | 783 | target_x + target_width - 0.5f * UI_LINE_WIDTH, |
| r13466 | r13467 | |
| 1086 | 785 | UI_SELECTED_BG_COLOR, |
| 1087 | 786 | hilight_texture, |
| 1088 | 787 | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(TRUE)); |
| 1089 | | ui_draw_text_full(menu->container, backtext, target_x, target_y + target_height - line_height, target_width, |
| 788 | ui_draw_text_full(container, backtext, target_x, target_y + target_height - line_height, target_width, |
| 1090 | 789 | JUSTIFY_CENTER, WRAP_TRUNCATE, DRAW_NORMAL, UI_SELECTED_COLOR, UI_SELECTED_BG_COLOR, NULL, NULL); |
| 1091 | 790 | |
| 1092 | 791 | /* artificially set the hover to the last item so a double-click exits */ |
| 1093 | | menu->hover = menu->numitems - 1; |
| 792 | hover = numitems - 1; |
| 1094 | 793 | } |
| 1095 | 794 | |
| 1096 | 795 | |
| 1097 | 796 | /*------------------------------------------------- |
| 1098 | | ui_menu_handle_events - generically handle |
| 797 | handle_events - generically handle |
| 1099 | 798 | input events for a menu |
| 1100 | 799 | -------------------------------------------------*/ |
| 1101 | 800 | |
| 1102 | | static void ui_menu_handle_events(ui_menu *menu) |
| 801 | void ui_menu::handle_events() |
| 1103 | 802 | { |
| 1104 | 803 | int stop = FALSE; |
| 1105 | | ui_event menu_event; |
| 804 | ui_event local_menu_event; |
| 1106 | 805 | |
| 1107 | 806 | /* loop while we have interesting events */ |
| 1108 | | while (ui_input_pop_event(menu->machine(), &menu_event) && !stop) |
| 807 | while (ui_input_pop_event(machine(), &local_menu_event) && !stop) |
| 1109 | 808 | { |
| 1110 | | switch (menu_event.event_type) |
| 809 | switch (local_menu_event.event_type) |
| 1111 | 810 | { |
| 1112 | 811 | /* if we are hovering over a valid item, select it with a single click */ |
| 1113 | 812 | case UI_EVENT_MOUSE_DOWN: |
| 1114 | | if (menu->hover >= 0 && menu->hover < menu->numitems) |
| 1115 | | menu->selected = menu->hover; |
| 1116 | | else if (menu->hover == -2) |
| 813 | if (hover >= 0 && hover < numitems) |
| 814 | selected = hover; |
| 815 | else if (hover == -2) |
| 1117 | 816 | { |
| 1118 | | menu->selected -= menu->visitems - 1; |
| 1119 | | ui_menu_validate_selection(menu, 1); |
| 817 | selected -= visitems - 1; |
| 818 | validate_selection(1); |
| 1120 | 819 | } |
| 1121 | | else if (menu->hover == -1) |
| 820 | else if (hover == -1) |
| 1122 | 821 | { |
| 1123 | | menu->selected += menu->visitems - 1; |
| 1124 | | ui_menu_validate_selection(menu, 1); |
| 822 | selected += visitems - 1; |
| 823 | validate_selection(1); |
| 1125 | 824 | } |
| 1126 | 825 | break; |
| 1127 | 826 | |
| 1128 | 827 | /* if we are hovering over a valid item, fake a UI_SELECT with a double-click */ |
| 1129 | 828 | case UI_EVENT_MOUSE_DOUBLE_CLICK: |
| 1130 | | if (menu->hover >= 0 && menu->hover < menu->numitems) |
| 829 | if (hover >= 0 && hover < numitems) |
| 1131 | 830 | { |
| 1132 | | menu->selected = menu->hover; |
| 1133 | | if (menu_event.event_type == UI_EVENT_MOUSE_DOUBLE_CLICK) |
| 831 | selected = hover; |
| 832 | if (local_menu_event.event_type == UI_EVENT_MOUSE_DOUBLE_CLICK) |
| 1134 | 833 | { |
| 1135 | | menu->menu_event.iptkey = IPT_UI_SELECT; |
| 1136 | | if (menu->selected == menu->numitems - 1) |
| 834 | menu_event.iptkey = IPT_UI_SELECT; |
| 835 | if (selected == numitems - 1) |
| 1137 | 836 | { |
| 1138 | | menu->menu_event.iptkey = IPT_UI_CANCEL; |
| 1139 | | ui_menu_stack_pop(menu->machine()); |
| 837 | menu_event.iptkey = IPT_UI_CANCEL; |
| 838 | ui_menu::stack_pop(machine()); |
| 1140 | 839 | } |
| 1141 | 840 | } |
| 1142 | 841 | stop = TRUE; |
| r13466 | r13467 | |
| 1145 | 844 | |
| 1146 | 845 | /* translate CHAR events into specials */ |
| 1147 | 846 | case UI_EVENT_CHAR: |
| 1148 | | menu->menu_event.iptkey = IPT_SPECIAL; |
| 1149 | | menu->menu_event.unichar = menu_event.ch; |
| 847 | menu_event.iptkey = IPT_SPECIAL; |
| 848 | menu_event.unichar = local_menu_event.ch; |
| 1150 | 849 | stop = TRUE; |
| 1151 | 850 | break; |
| 1152 | 851 | |
| r13466 | r13467 | |
| 1159 | 858 | |
| 1160 | 859 | |
| 1161 | 860 | /*------------------------------------------------- |
| 1162 | | ui_menu_handle_keys - generically handle |
| 861 | handle_keys - generically handle |
| 1163 | 862 | keys for a menu |
| 1164 | 863 | -------------------------------------------------*/ |
| 1165 | 864 | |
| 1166 | | static void ui_menu_handle_keys(ui_menu *menu, UINT32 flags) |
| 865 | void ui_menu::handle_keys(UINT32 flags) |
| 1167 | 866 | { |
| 1168 | | int ignorepause = ui_menu_is_force_game_select(); |
| 867 | int ignorepause = ui_menu::stack_has_special_main_menu(); |
| 1169 | 868 | int ignoreright = FALSE; |
| 1170 | 869 | int ignoreleft = FALSE; |
| 1171 | 870 | int code; |
| 1172 | 871 | |
| 1173 | 872 | /* bail if no items */ |
| 1174 | | if (menu->numitems == 0) |
| 873 | if (numitems == 0) |
| 1175 | 874 | return; |
| 1176 | 875 | |
| 1177 | 876 | /* if we hit select, return TRUE or pop the stack, depending on the item */ |
| 1178 | | if (exclusive_input_pressed(menu, IPT_UI_SELECT, 0)) |
| 877 | if (exclusive_input_pressed(IPT_UI_SELECT, 0)) |
| 1179 | 878 | { |
| 1180 | | if (menu->selected == menu->numitems - 1) |
| 879 | if (selected == numitems - 1) |
| 1181 | 880 | { |
| 1182 | | menu->menu_event.iptkey = IPT_UI_CANCEL; |
| 1183 | | ui_menu_stack_pop(menu->machine()); |
| 881 | menu_event.iptkey = IPT_UI_CANCEL; |
| 882 | ui_menu::stack_pop(machine()); |
| 1184 | 883 | } |
| 1185 | 884 | return; |
| 1186 | 885 | } |
| 1187 | 886 | |
| 1188 | 887 | /* hitting cancel also pops the stack */ |
| 1189 | | if (exclusive_input_pressed(menu, IPT_UI_CANCEL, 0)) |
| 888 | if (exclusive_input_pressed(IPT_UI_CANCEL, 0)) |
| 1190 | 889 | { |
| 1191 | | ui_menu_stack_pop(menu->machine()); |
| 890 | ui_menu::stack_pop(machine()); |
| 1192 | 891 | return; |
| 1193 | 892 | } |
| 1194 | 893 | |
| 1195 | 894 | /* validate the current selection */ |
| 1196 | | ui_menu_validate_selection(menu, 1); |
| 895 | validate_selection(1); |
| 1197 | 896 | |
| 1198 | 897 | /* swallow left/right keys if they are not appropriate */ |
| 1199 | | ignoreleft = ((menu->item[menu->selected].flags & MENU_FLAG_LEFT_ARROW) == 0); |
| 1200 | | ignoreright = ((menu->item[menu->selected].flags & MENU_FLAG_RIGHT_ARROW) == 0); |
| 898 | ignoreleft = ((item[selected].flags & MENU_FLAG_LEFT_ARROW) == 0); |
| 899 | ignoreright = ((item[selected].flags & MENU_FLAG_RIGHT_ARROW) == 0); |
| 1201 | 900 | |
| 1202 | 901 | /* accept left/right keys as-is with repeat */ |
| 1203 | | if (!ignoreleft && exclusive_input_pressed(menu, IPT_UI_LEFT, (flags & UI_MENU_PROCESS_LR_REPEAT) ? 6 : 0)) |
| 902 | if (!ignoreleft && exclusive_input_pressed(IPT_UI_LEFT, (flags & UI_MENU_PROCESS_LR_REPEAT) ? 6 : 0)) |
| 1204 | 903 | return; |
| 1205 | | if (!ignoreright && exclusive_input_pressed(menu, IPT_UI_RIGHT, (flags & UI_MENU_PROCESS_LR_REPEAT) ? 6 : 0)) |
| 904 | if (!ignoreright && exclusive_input_pressed(IPT_UI_RIGHT, (flags & UI_MENU_PROCESS_LR_REPEAT) ? 6 : 0)) |
| 1206 | 905 | return; |
| 1207 | 906 | |
| 1208 | 907 | /* up backs up by one item */ |
| 1209 | | if (exclusive_input_pressed(menu, IPT_UI_UP, 6)) |
| 908 | if (exclusive_input_pressed(IPT_UI_UP, 6)) |
| 1210 | 909 | { |
| 1211 | | menu->selected = (menu->selected + menu->numitems - 1) % menu->numitems; |
| 1212 | | ui_menu_validate_selection(menu, -1); |
| 910 | selected = (selected + numitems - 1) % numitems; |
| 911 | validate_selection(-1); |
| 1213 | 912 | } |
| 1214 | 913 | |
| 1215 | 914 | /* down advances by one item */ |
| 1216 | | if (exclusive_input_pressed(menu, IPT_UI_DOWN, 6)) |
| 915 | if (exclusive_input_pressed(IPT_UI_DOWN, 6)) |
| 1217 | 916 | { |
| 1218 | | menu->selected = (menu->selected + 1) % menu->numitems; |
| 1219 | | ui_menu_validate_selection(menu, 1); |
| 917 | selected = (selected + 1) % numitems; |
| 918 | validate_selection(1); |
| 1220 | 919 | } |
| 1221 | 920 | |
| 1222 | 921 | /* page up backs up by visitems */ |
| 1223 | | if (exclusive_input_pressed(menu, IPT_UI_PAGE_UP, 6)) |
| 922 | if (exclusive_input_pressed(IPT_UI_PAGE_UP, 6)) |
| 1224 | 923 | { |
| 1225 | | menu->selected -= menu->visitems - 1; |
| 1226 | | ui_menu_validate_selection(menu, 1); |
| 924 | selected -= visitems - 1; |
| 925 | validate_selection(1); |
| 1227 | 926 | } |
| 1228 | 927 | |
| 1229 | 928 | /* page down advances by visitems */ |
| 1230 | | if (exclusive_input_pressed(menu, IPT_UI_PAGE_DOWN, 6)) |
| 929 | if (exclusive_input_pressed(IPT_UI_PAGE_DOWN, 6)) |
| 1231 | 930 | { |
| 1232 | | menu->selected += menu->visitems - 1; |
| 1233 | | ui_menu_validate_selection(menu, -1); |
| 931 | selected += visitems - 1; |
| 932 | validate_selection(-1); |
| 1234 | 933 | } |
| 1235 | 934 | |
| 1236 | 935 | /* home goes to the start */ |
| 1237 | | if (exclusive_input_pressed(menu, IPT_UI_HOME, 0)) |
| 936 | if (exclusive_input_pressed(IPT_UI_HOME, 0)) |
| 1238 | 937 | { |
| 1239 | | menu->selected = 0; |
| 1240 | | ui_menu_validate_selection(menu, 1); |
| 938 | selected = 0; |
| 939 | validate_selection(1); |
| 1241 | 940 | } |
| 1242 | 941 | |
| 1243 | 942 | /* end goes to the last */ |
| 1244 | | if (exclusive_input_pressed(menu, IPT_UI_END, 0)) |
| 943 | if (exclusive_input_pressed(IPT_UI_END, 0)) |
| 1245 | 944 | { |
| 1246 | | menu->selected = menu->numitems - 1; |
| 1247 | | ui_menu_validate_selection(menu, -1); |
| 945 | selected = numitems - 1; |
| 946 | validate_selection(-1); |
| 1248 | 947 | } |
| 1249 | 948 | |
| 1250 | 949 | /* pause enables/disables pause */ |
| 1251 | | if (!ignorepause && exclusive_input_pressed(menu, IPT_UI_PAUSE, 0)) |
| 950 | if (!ignorepause && exclusive_input_pressed(IPT_UI_PAUSE, 0)) |
| 1252 | 951 | { |
| 1253 | | if (menu->machine().paused()) |
| 1254 | | menu->machine().resume(); |
| 952 | if (machine().paused()) |
| 953 | machine().resume(); |
| 1255 | 954 | else |
| 1256 | | menu->machine().pause(); |
| 955 | machine().pause(); |
| 1257 | 956 | } |
| 1258 | 957 | |
| 1259 | 958 | /* handle a toggle cheats request */ |
| 1260 | | if (ui_input_pressed_repeat(menu->machine(), IPT_UI_TOGGLE_CHEAT, 0)) |
| 1261 | | menu->machine().cheat().set_enable(!menu->machine().cheat().enabled()); |
| 959 | if (ui_input_pressed_repeat(machine(), IPT_UI_TOGGLE_CHEAT, 0)) |
| 960 | machine().cheat().set_enable(!machine().cheat().enabled()); |
| 1262 | 961 | |
| 1263 | 962 | /* see if any other UI keys are pressed */ |
| 1264 | | if (menu->menu_event.iptkey == IPT_INVALID) |
| 963 | if (menu_event.iptkey == IPT_INVALID) |
| 1265 | 964 | for (code = __ipt_ui_start; code <= __ipt_ui_end; code++) |
| 1266 | 965 | { |
| 1267 | 966 | if (code == IPT_UI_CONFIGURE || (code == IPT_UI_LEFT && ignoreleft) || (code == IPT_UI_RIGHT && ignoreright) || (code == IPT_UI_PAUSE && ignorepause)) |
| 1268 | 967 | continue; |
| 1269 | | if (exclusive_input_pressed(menu, code, 0)) |
| 968 | if (exclusive_input_pressed(code, 0)) |
| 1270 | 969 | break; |
| 1271 | 970 | } |
| 1272 | 971 | } |
| 1273 | 972 | |
| 1274 | 973 | |
| 1275 | 974 | /*------------------------------------------------- |
| 1276 | | ui_menu_validate_selection - validate the |
| 975 | validate_selection - validate the |
| 1277 | 976 | current selection and ensure it is on a |
| 1278 | 977 | correct item |
| 1279 | 978 | -------------------------------------------------*/ |
| 1280 | 979 | |
| 1281 | | static void ui_menu_validate_selection(ui_menu *menu, int scandir) |
| 980 | void ui_menu::validate_selection(int scandir) |
| 1282 | 981 | { |
| 1283 | 982 | /* clamp to be in range */ |
| 1284 | | if (menu->selected < 0) |
| 1285 | | menu->selected = 0; |
| 1286 | | else if (menu->selected >= menu->numitems) |
| 1287 | | menu->selected = menu->numitems - 1; |
| 983 | if (selected < 0) |
| 984 | selected = 0; |
| 985 | else if (selected >= numitems) |
| 986 | selected = numitems - 1; |
| 1288 | 987 | |
| 1289 | 988 | /* skip past unselectable items */ |
| 1290 | | while (!item_is_selectable(&menu->item[menu->selected])) |
| 1291 | | menu->selected = (menu->selected + menu->numitems + scandir) % menu->numitems; |
| 989 | while (!item[selected].is_selectable()) |
| 990 | selected = (selected + numitems + scandir) % numitems; |
| 1292 | 991 | } |
| 1293 | 992 | |
| 1294 | 993 | |
| 1295 | 994 | |
| 1296 | 995 | /*------------------------------------------------- |
| 1297 | | ui_menu_clear_free_list - clear out anything |
| 996 | clear_free_list - clear out anything |
| 1298 | 997 | accumulated in the free list |
| 1299 | 998 | -------------------------------------------------*/ |
| 1300 | 999 | |
| 1301 | | static void ui_menu_clear_free_list(running_machine &machine) |
| 1000 | void ui_menu::clear_free_list(running_machine &machine) |
| 1302 | 1001 | { |
| 1303 | 1002 | while (menu_free != NULL) |
| 1304 | 1003 | { |
| 1305 | 1004 | ui_menu *menu = menu_free; |
| 1306 | 1005 | menu_free = menu->parent; |
| 1307 | | ui_menu_free(menu); |
| 1006 | auto_free(machine, menu); |
| 1308 | 1007 | } |
| 1309 | 1008 | } |
| 1310 | 1009 | |
| r13466 | r13467 | |
| 1315 | 1014 | ***************************************************************************/ |
| 1316 | 1015 | |
| 1317 | 1016 | /*------------------------------------------------- |
| 1318 | | ui_menu_stack_reset - reset the menu stack |
| 1017 | ui_menu::stack_reset - reset the menu stack |
| 1319 | 1018 | -------------------------------------------------*/ |
| 1320 | 1019 | |
| 1321 | | void ui_menu_stack_reset(running_machine &machine) |
| 1020 | void ui_menu::stack_reset(running_machine &machine) |
| 1322 | 1021 | { |
| 1323 | 1022 | while (menu_stack != NULL) |
| 1324 | | ui_menu_stack_pop(machine); |
| 1023 | ui_menu::stack_pop(machine); |
| 1325 | 1024 | } |
| 1326 | 1025 | |
| 1327 | 1026 | |
| 1328 | 1027 | /*------------------------------------------------- |
| 1329 | | ui_menu_stack_push - push a new menu onto the |
| 1028 | stack_push - push a new menu onto the |
| 1330 | 1029 | stack |
| 1331 | 1030 | -------------------------------------------------*/ |
| 1332 | 1031 | |
| 1333 | | void ui_menu_stack_push(ui_menu *menu) |
| 1032 | void ui_menu::stack_push(ui_menu *menu) |
| 1334 | 1033 | { |
| 1335 | 1034 | menu->parent = menu_stack; |
| 1336 | 1035 | menu_stack = menu; |
| 1337 | | ui_menu_reset(menu, UI_MENU_RESET_SELECT_FIRST); |
| 1036 | menu->reset(UI_MENU_RESET_SELECT_FIRST); |
| 1338 | 1037 | ui_input_reset(menu->machine()); |
| 1339 | 1038 | } |
| 1340 | 1039 | |
| 1341 | 1040 | |
| 1342 | 1041 | /*------------------------------------------------- |
| 1343 | | ui_menu_stack_pop - pop a menu from the stack |
| 1042 | stack_pop - pop a menu from the stack |
| 1344 | 1043 | -------------------------------------------------*/ |
| 1345 | 1044 | |
| 1346 | | void ui_menu_stack_pop(running_machine &machine) |
| 1045 | void ui_menu::stack_pop(running_machine &machine) |
| 1347 | 1046 | { |
| 1348 | 1047 | if (menu_stack != NULL) |
| 1349 | 1048 | { |
| r13466 | r13467 | |
| 1356 | 1055 | } |
| 1357 | 1056 | |
| 1358 | 1057 | |
| 1058 | /*------------------------------------------------- |
| 1059 | ui_menu::stack_has_special_main_menu - |
| 1060 | check in the special main menu is in the stack |
| 1061 | -------------------------------------------------*/ |
| 1359 | 1062 | |
| 1063 | bool ui_menu::stack_has_special_main_menu() |
| 1064 | { |
| 1065 | ui_menu *menu; |
| 1066 | |
| 1067 | for (menu = menu_stack; menu != NULL; menu = menu->parent) |
| 1068 | if (menu->is_special_main_menu()) |
| 1069 | return true; |
| 1070 | |
| 1071 | return false; |
| 1072 | } |
| 1073 | |
| 1074 | |
| 1075 | |
| 1360 | 1076 | /*************************************************************************** |
| 1361 | 1077 | UI SYSTEM INTERACTION |
| 1362 | 1078 | ***************************************************************************/ |
| r13466 | r13467 | |
| 1366 | 1082 | and calls the menu handler |
| 1367 | 1083 | -------------------------------------------------*/ |
| 1368 | 1084 | |
| 1369 | | UINT32 ui_menu_ui_handler(running_machine &machine, render_container *container, UINT32 state) |
| 1085 | UINT32 ui_menu::ui_handler(running_machine &machine, render_container *container, UINT32 state) |
| 1370 | 1086 | { |
| 1371 | 1087 | /* if we have no menus stacked up, start with the main menu */ |
| 1372 | 1088 | if (menu_stack == NULL) |
| 1373 | | ui_menu_stack_push(ui_menu_alloc(machine, container, menu_main, NULL)); |
| 1089 | stack_push(ui_menu_alloc(machine, container, menu_main, NULL)); |
| 1374 | 1090 | |
| 1375 | 1091 | /* update the menu state */ |
| 1376 | 1092 | if (menu_stack != NULL) |
| r13466 | r13467 | |
| 1380 | 1096 | } |
| 1381 | 1097 | |
| 1382 | 1098 | /* clear up anything pending to be released */ |
| 1383 | | ui_menu_clear_free_list(machine); |
| 1099 | clear_free_list(machine); |
| 1384 | 1100 | |
| 1385 | 1101 | /* if the menus are to be hidden, return a cancel here */ |
| 1386 | | if ((ui_input_pressed(machine, IPT_UI_CONFIGURE) && !ui_menu_is_force_game_select()) || menu_stack == NULL) |
| 1102 | if ((ui_input_pressed(machine, IPT_UI_CONFIGURE) && !stack_has_special_main_menu()) || menu_stack == NULL) |
| 1387 | 1103 | return UI_HANDLER_CANCEL; |
| 1388 | 1104 | |
| 1389 | 1105 | return 0; |
| 1390 | 1106 | } |
| 1391 | 1107 | |
| 1392 | | |
| 1393 | | /*------------------------------------------------- |
| 1394 | | ui_slider_ui_handler - pushes the slider |
| 1395 | | menu on the stack and hands off to the |
| 1396 | | standard menu handler |
| 1397 | | -------------------------------------------------*/ |
| 1398 | | |
| 1399 | | UINT32 ui_slider_ui_handler(running_machine &machine, render_container *container, UINT32 state) |
| 1400 | | { |
| 1401 | | UINT32 result; |
| 1402 | | |
| 1403 | | /* if this is the first call, push the sliders menu */ |
| 1404 | | if (state) |
| 1405 | | ui_menu_stack_push(ui_menu_alloc(machine, container, menu_sliders, (void *)1)); |
| 1406 | | |
| 1407 | | /* handle standard menus */ |
| 1408 | | result = ui_menu_ui_handler(machine, container, state); |
| 1409 | | |
| 1410 | | /* if we are cancelled, pop the sliders menu */ |
| 1411 | | if (result == UI_HANDLER_CANCEL) |
| 1412 | | ui_menu_stack_pop(machine); |
| 1413 | | |
| 1414 | | return (menu_stack != NULL && menu_stack->handler == menu_sliders && menu_stack->parameter != NULL) ? 0 : UI_HANDLER_CANCEL; |
| 1415 | | } |
| 1416 | | |
| 1417 | | |
| 1418 | | /*------------------------------------------------- |
| 1419 | | ui_menu_force_game_select - force the game |
| 1420 | | select menu to be visible and inescapable |
| 1421 | | -------------------------------------------------*/ |
| 1422 | | |
| 1423 | | void ui_menu_force_game_select(running_machine &machine, render_container *container) |
| 1424 | | { |
| 1425 | | char *gamename = (char *)machine.options().system_name(); |
| 1426 | | |
| 1427 | | /* reset the menu stack */ |
| 1428 | | ui_menu_stack_reset(machine); |
| 1429 | | |
| 1430 | | /* add the quit entry followed by the game select entry */ |
| 1431 | | ui_menu_stack_push(ui_menu_alloc(machine, container, menu_quit_game, NULL)); |
| 1432 | | ui_menu_stack_push(ui_menu_alloc(machine, container, menu_select_game, gamename)); |
| 1433 | | |
| 1434 | | /* force the menus on */ |
| 1435 | | ui_show_menu(); |
| 1436 | | |
| 1437 | | /* make sure MAME is paused */ |
| 1438 | | machine.pause(); |
| 1439 | | } |
| 1440 | | |
| 1441 | | |
| 1442 | | /*------------------------------------------------- |
| 1443 | | ui_menu_is_force_game_select - return true |
| 1444 | | if we are currently in "force game select" |
| 1445 | | mode |
| 1446 | | -------------------------------------------------*/ |
| 1447 | | |
| 1448 | | int ui_menu_is_force_game_select(void) |
| 1449 | | { |
| 1450 | | ui_menu *menu; |
| 1451 | | |
| 1452 | | for (menu = menu_stack; menu != NULL; menu = menu->parent) |
| 1453 | | if (menu->handler == menu_quit_game && menu->parent == NULL) |
| 1454 | | return TRUE; |
| 1455 | | |
| 1456 | | return FALSE; |
| 1457 | | } |
| 1458 | | |
| 1459 | | |
| 1460 | | |
| 1461 | 1108 | /*************************************************************************** |
| 1462 | | MENU HANDLERS |
| 1463 | | ***************************************************************************/ |
| 1464 | | |
| 1465 | | /*------------------------------------------------- |
| 1466 | | menu_main - handle the main menu |
| 1467 | | -------------------------------------------------*/ |
| 1468 | | |
| 1469 | | static void menu_main(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1470 | | { |
| 1471 | | const ui_menu_event *menu_event; |
| 1472 | | |
| 1473 | | /* if the menu isn't built, populate now */ |
| 1474 | | if (!ui_menu_populated(menu)) |
| 1475 | | menu_main_populate(machine, menu, state); |
| 1476 | | |
| 1477 | | /* process the menu */ |
| 1478 | | menu_event = ui_menu_process(machine, menu, 0); |
| 1479 | | if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT) |
| 1480 | | ui_menu_stack_push(ui_menu_alloc(machine, menu->container, (ui_menu_handler_func)menu_event->itemref, NULL)); |
| 1481 | | } |
| 1482 | | |
| 1483 | | |
| 1484 | | /*------------------------------------------------- |
| 1485 | | ui_menu_keyboard_mode - menu that |
| 1486 | | -------------------------------------------------*/ |
| 1487 | | |
| 1488 | | static void ui_menu_keyboard_mode(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1489 | | { |
| 1490 | | const ui_menu_event *menu_event; |
| 1491 | | int natural = ui_get_use_natural_keyboard(machine); |
| 1492 | | |
| 1493 | | /* if the menu isn't built, populate now */ |
| 1494 | | if (!ui_menu_populated(menu)) |
| 1495 | | { |
| 1496 | | ui_menu_item_append(menu, "Keyboard Mode:", natural ? "Natural" : "Emulated", natural ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, NULL); |
| 1497 | | } |
| 1498 | | |
| 1499 | | /* process the menu */ |
| 1500 | | menu_event = ui_menu_process(machine, menu, 0); |
| 1501 | | |
| 1502 | | if (menu_event != NULL) |
| 1503 | | { |
| 1504 | | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) { |
| 1505 | | ui_set_use_natural_keyboard(machine, natural ^ TRUE); |
| 1506 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF); |
| 1507 | | } |
| 1508 | | } |
| 1509 | | } |
| 1510 | | |
| 1511 | | |
| 1512 | | /*------------------------------------------------- |
| 1513 | | ui_slot_get_current_index - returns |
| 1514 | | -------------------------------------------------*/ |
| 1515 | | int ui_slot_get_current_index(running_machine &machine, device_slot_interface *slot) |
| 1516 | | { |
| 1517 | | const char *current = machine.options().value(slot->device().tag()); |
| 1518 | | const slot_interface* intf = slot->get_slot_interfaces(); |
| 1519 | | int val = -1; |
| 1520 | | for (int i = 0; intf[i].name != NULL; i++) { |
| 1521 | | if (strcmp(current, intf[i].name) == 0) val = i; |
| 1522 | | } |
| 1523 | | return val; |
| 1524 | | } |
| 1525 | | |
| 1526 | | /*------------------------------------------------- |
| 1527 | | ui_slot_get_length - returns |
| 1528 | | -------------------------------------------------*/ |
| 1529 | | int ui_slot_get_length(running_machine &machine, device_slot_interface *slot) |
| 1530 | | { |
| 1531 | | const slot_interface* intf = slot->get_slot_interfaces(); |
| 1532 | | int val = 0; |
| 1533 | | for (int i = 0; intf[i].name != NULL; i++) val++; |
| 1534 | | return val; |
| 1535 | | } |
| 1536 | | |
| 1537 | | /*------------------------------------------------- |
| 1538 | | ui_slot_get_next - returns |
| 1539 | | -------------------------------------------------*/ |
| 1540 | | const char *ui_slot_get_next(running_machine &machine, device_slot_interface *slot) |
| 1541 | | { |
| 1542 | | int idx = ui_slot_get_current_index(machine, slot) + 1; |
| 1543 | | if (idx==ui_slot_get_length(machine,slot)) return ""; |
| 1544 | | return slot->get_slot_interfaces()[idx].name; |
| 1545 | | } |
| 1546 | | |
| 1547 | | /*------------------------------------------------- |
| 1548 | | ui_slot_get_prev - returns |
| 1549 | | -------------------------------------------------*/ |
| 1550 | | const char *ui_slot_get_prev(running_machine &machine, device_slot_interface *slot) |
| 1551 | | { |
| 1552 | | int idx = ui_slot_get_current_index(machine, slot) - 1; |
| 1553 | | if (idx==-1) return ""; |
| 1554 | | if (idx==-2) idx = ui_slot_get_length(machine,slot) -1; |
| 1555 | | if (idx==-1) return ""; |
| 1556 | | return slot->get_slot_interfaces()[idx].name; |
| 1557 | | } |
| 1558 | | |
| 1559 | | /*------------------------------------------------- |
| 1560 | | ui_get_slot_device - returns |
| 1561 | | -------------------------------------------------*/ |
| 1562 | | const char *ui_get_slot_device(running_machine &machine, device_slot_interface *slot) |
| 1563 | | { |
| 1564 | | return machine.options().value(slot->device().tag()); |
| 1565 | | } |
| 1566 | | |
| 1567 | | |
| 1568 | | /*------------------------------------------------- |
| 1569 | | ui_set_use_natural_keyboard - specifies |
| 1570 | | whether the natural keyboard is active |
| 1571 | | -------------------------------------------------*/ |
| 1572 | | |
| 1573 | | void ui_set_slot_device(running_machine &machine, device_slot_interface *slot, const char *val) |
| 1574 | | { |
| 1575 | | astring error; |
| 1576 | | machine.options().set_value(slot->device().tag(), val, OPTION_PRIORITY_CMDLINE, error); |
| 1577 | | assert(!error); |
| 1578 | | } |
| 1579 | | |
| 1580 | | /*------------------------------------------------- |
| 1581 | | menu_slot_devices_populate - populates the main |
| 1582 | | slot device menu |
| 1583 | | -------------------------------------------------*/ |
| 1584 | | |
| 1585 | | static void menu_slot_devices_populate(running_machine &machine, ui_menu *menu, void *state) |
| 1586 | | { |
| 1587 | | device_slot_interface *slot = NULL; |
| 1588 | | |
| 1589 | | /* cycle through all devices for this system */ |
| 1590 | | for (bool gotone = machine.devicelist().first(slot); gotone; gotone = slot->next(slot)) |
| 1591 | | { |
| 1592 | | /* record the menu item */ |
| 1593 | | const char *title = ui_get_slot_device(machine,slot); |
| 1594 | | ui_menu_item_append(menu, slot->device().tag(), strcmp(title,"")==0 ? "------" : title, MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW, (void *)slot); |
| 1595 | | } |
| 1596 | | ui_menu_item_append(menu, MENU_SEPARATOR_ITEM, NULL, 0, NULL); |
| 1597 | | ui_menu_item_append(menu, "Reset", NULL, 0, NULL); |
| 1598 | | } |
| 1599 | | |
| 1600 | | /*------------------------------------------------- |
| 1601 | | ui_menu_slot_devices - menu that |
| 1602 | | -------------------------------------------------*/ |
| 1603 | | |
| 1604 | | static void ui_menu_slot_devices(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1605 | | { |
| 1606 | | const ui_menu_event *menu_event; |
| 1607 | | |
| 1608 | | /* if the menu isn't built, populate now */ |
| 1609 | | if (!ui_menu_populated(menu)) |
| 1610 | | { |
| 1611 | | menu_slot_devices_populate(machine, menu, state); |
| 1612 | | } |
| 1613 | | |
| 1614 | | /* process the menu */ |
| 1615 | | menu_event = ui_menu_process(machine, menu, 0); |
| 1616 | | |
| 1617 | | if (menu_event != NULL && menu_event->itemref != NULL) |
| 1618 | | { |
| 1619 | | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) { |
| 1620 | | device_slot_interface *slot = (device_slot_interface *)menu_event->itemref; |
| 1621 | | const char *val = (menu_event->iptkey == IPT_UI_LEFT) ? ui_slot_get_prev(machine,slot) : ui_slot_get_next(machine,slot); |
| 1622 | | ui_set_slot_device(machine,slot,val); |
| 1623 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF); |
| 1624 | | } |
| 1625 | | } else if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT) { |
| 1626 | | machine.schedule_hard_reset(); |
| 1627 | | } |
| 1628 | | } |
| 1629 | | |
| 1630 | | |
| 1631 | | /*------------------------------------------------- |
| 1632 | | menu_main_populate - populate the main menu |
| 1633 | | -------------------------------------------------*/ |
| 1634 | | |
| 1635 | | static void menu_main_populate(running_machine &machine, ui_menu *menu, void *state) |
| 1636 | | { |
| 1637 | | input_field_config *field; |
| 1638 | | input_port_config *port; |
| 1639 | | int has_configs = FALSE; |
| 1640 | | int has_analog = FALSE; |
| 1641 | | int has_dips = FALSE; |
| 1642 | | astring menu_text; |
| 1643 | | /* scan the input port array to see what options we need to enable */ |
| 1644 | | for (port = machine.m_portlist.first(); port != NULL; port = port->next()) |
| 1645 | | for (field = port->fieldlist().first(); field != NULL; field = field->next()) |
| 1646 | | { |
| 1647 | | if (field->type == IPT_DIPSWITCH) |
| 1648 | | has_dips = TRUE; |
| 1649 | | if (field->type == IPT_CONFIG) |
| 1650 | | has_configs = TRUE; |
| 1651 | | if (input_type_is_analog(field->type)) |
| 1652 | | has_analog = TRUE; |
| 1653 | | } |
| 1654 | | |
| 1655 | | /* add input menu items */ |
| 1656 | | ui_menu_item_append(menu, "Input (general)", NULL, 0, (void *)menu_input_groups); |
| 1657 | | |
| 1658 | | menu_text.printf("Input (this %s)",emulator_info::get_capstartgamenoun()); |
| 1659 | | ui_menu_item_append(menu, menu_text.cstr(), NULL, 0, (void *)menu_input_specific); |
| 1660 | | |
| 1661 | | /* add optional input-related menus */ |
| 1662 | | if (has_dips) |
| 1663 | | ui_menu_item_append(menu, "Dip Switches", NULL, 0, (void *)menu_settings_dip_switches); |
| 1664 | | if (has_configs) |
| 1665 | | ui_menu_item_append(menu, "Driver Configuration", NULL, 0, (void *)menu_settings_driver_config); |
| 1666 | | if (has_analog) |
| 1667 | | ui_menu_item_append(menu, "Analog Controls", NULL, 0, (void *)menu_analog); |
| 1668 | | |
| 1669 | | /* add bookkeeping menu */ |
| 1670 | | ui_menu_item_append(menu, "Bookkeeping Info", NULL, 0, (void *)menu_bookkeeping); |
| 1671 | | |
| 1672 | | /* add game info menu */ |
| 1673 | | menu_text.printf("%s Information",emulator_info::get_capstartgamenoun()); |
| 1674 | | ui_menu_item_append(menu, menu_text.cstr(), NULL, 0, (void *)menu_game_info); |
| 1675 | | |
| 1676 | | device_image_interface *image = NULL; |
| 1677 | | if (machine.devicelist().first(image)) |
| 1678 | | { |
| 1679 | | /* add image info menu */ |
| 1680 | | ui_menu_item_append(menu, "Image Information", NULL, 0, (void*)ui_image_menu_image_info); |
| 1681 | | |
| 1682 | | /* add file manager menu */ |
| 1683 | | ui_menu_item_append(menu, "File Manager", NULL, 0, (void*)ui_image_menu_file_manager); |
| 1684 | | |
| 1685 | | /* add tape control menu */ |
| 1686 | | if (machine.devicelist().first(CASSETTE)) |
| 1687 | | ui_menu_item_append(menu, "Tape Control", NULL, 0, (void*)ui_mess_menu_tape_control); |
| 1688 | | |
| 1689 | | /* add bitbanger control menu */ |
| 1690 | | if (machine.devicelist().first(BITBANGER)) |
| 1691 | | ui_menu_item_append(menu, "Bitbanger Control", NULL, 0, (void*)ui_mess_menu_bitbanger_control); |
| 1692 | | } |
| 1693 | | |
| 1694 | | device_slot_interface *slot = NULL; |
| 1695 | | if (machine.devicelist().first(slot)) |
| 1696 | | { |
| 1697 | | /* add image info menu */ |
| 1698 | | ui_menu_item_append(menu, "Slot Devices", NULL, 0, (void*)ui_menu_slot_devices); |
| 1699 | | } |
| 1700 | | |
| 1701 | | /* add keyboard mode menu */ |
| 1702 | | if (input_machine_has_keyboard(machine) && inputx_can_post(machine)) |
| 1703 | | ui_menu_item_append(menu, "Keyboard Mode", NULL, 0, (void *)ui_menu_keyboard_mode); |
| 1704 | | |
| 1705 | | /* add sliders menu */ |
| 1706 | | ui_menu_item_append(menu, "Slider Controls", NULL, 0, (void *)menu_sliders); |
| 1707 | | |
| 1708 | | /* add video options menu */ |
| 1709 | | ui_menu_item_append(menu, "Video Options", NULL, 0, (machine.render().target_by_index(1) != NULL) ? (void *)menu_video_targets : (void *)menu_video_options); |
| 1710 | | |
| 1711 | | /* add crosshair options menu */ |
| 1712 | | if (crosshair_get_usage(machine)) |
| 1713 | | ui_menu_item_append(menu, "Crosshair Options", NULL, 0, (void *)menu_crosshair); |
| 1714 | | |
| 1715 | | /* add cheat menu */ |
| 1716 | | if (machine.options().cheat() && machine.cheat().first() != NULL) |
| 1717 | | ui_menu_item_append(menu, "Cheat", NULL, 0, (void *)menu_cheat); |
| 1718 | | |
| 1719 | | /* add memory card menu */ |
| 1720 | | if (machine.config().m_memcard_handler != NULL) |
| 1721 | | ui_menu_item_append(menu, "Memory Card", NULL, 0, (void *)menu_memory_card); |
| 1722 | | |
| 1723 | | /* add reset and exit menus */ |
| 1724 | | menu_text.printf("Select New %s",emulator_info::get_capstartgamenoun()); |
| 1725 | | ui_menu_item_append(menu, menu_text.cstr(), NULL, 0, (void *)menu_select_game); |
| 1726 | | } |
| 1727 | | |
| 1728 | | |
| 1729 | | /*------------------------------------------------- |
| 1730 | | menu_input_groups - handle the input groups |
| 1731 | | menu |
| 1732 | | -------------------------------------------------*/ |
| 1733 | | |
| 1734 | | static void menu_input_groups(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1735 | | { |
| 1736 | | const ui_menu_event *menu_event; |
| 1737 | | |
| 1738 | | /* if the menu isn't built, populate now */ |
| 1739 | | if (!ui_menu_populated(menu)) |
| 1740 | | menu_input_groups_populate(machine, menu, state); |
| 1741 | | |
| 1742 | | /* process the menu */ |
| 1743 | | menu_event = ui_menu_process(machine, menu, 0); |
| 1744 | | if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT) |
| 1745 | | ui_menu_stack_push(ui_menu_alloc(machine, menu->container, menu_input_general, menu_event->itemref)); |
| 1746 | | } |
| 1747 | | |
| 1748 | | |
| 1749 | | /*------------------------------------------------- |
| 1750 | | menu_input_groups_populate - populate the |
| 1751 | | input groups menu |
| 1752 | | -------------------------------------------------*/ |
| 1753 | | |
| 1754 | | static void menu_input_groups_populate(running_machine &machine, ui_menu *menu, void *state) |
| 1755 | | { |
| 1756 | | int player; |
| 1757 | | |
| 1758 | | /* build up the menu */ |
| 1759 | | ui_menu_item_append(menu, "User Interface", NULL, 0, (void *)(IPG_UI + 1)); |
| 1760 | | for (player = 0; player < MAX_PLAYERS; player++) |
| 1761 | | { |
| 1762 | | char buffer[40]; |
| 1763 | | sprintf(buffer, "Player %d Controls", player + 1); |
| 1764 | | ui_menu_item_append(menu, buffer, NULL, 0, (void *)(FPTR)(IPG_PLAYER1 + player + 1)); |
| 1765 | | } |
| 1766 | | ui_menu_item_append(menu, "Other Controls", NULL, 0, (void *)(FPTR)(IPG_OTHER + 1)); |
| 1767 | | } |
| 1768 | | |
| 1769 | | |
| 1770 | | |
| 1771 | | /*------------------------------------------------- |
| 1772 | | menu_input_general - handle the general |
| 1773 | | input menu |
| 1774 | | -------------------------------------------------*/ |
| 1775 | | |
| 1776 | | static void menu_input_general(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1777 | | { |
| 1778 | | menu_input_common(machine, menu, parameter, state); |
| 1779 | | } |
| 1780 | | |
| 1781 | | |
| 1782 | | /*------------------------------------------------- |
| 1783 | | menu_input_general_populate - populate the |
| 1784 | | general input menu |
| 1785 | | -------------------------------------------------*/ |
| 1786 | | |
| 1787 | | static void menu_input_general_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate, int group) |
| 1788 | | { |
| 1789 | | input_item_data *itemlist = NULL; |
| 1790 | | int suborder[SEQ_TYPE_TOTAL]; |
| 1791 | | astring tempstring; |
| 1792 | | int sortorder = 1; |
| 1793 | | |
| 1794 | | /* create a mini lookup table for sort order based on sequence type */ |
| 1795 | | suborder[SEQ_TYPE_STANDARD] = 0; |
| 1796 | | suborder[SEQ_TYPE_DECREMENT] = 1; |
| 1797 | | suborder[SEQ_TYPE_INCREMENT] = 2; |
| 1798 | | |
| 1799 | | /* iterate over the input ports and add menu items */ |
| 1800 | | for (input_type_entry *entry = input_type_list(machine).first(); entry != NULL; entry = entry->next()) |
| 1801 | | |
| 1802 | | /* add if we match the group and we have a valid name */ |
| 1803 | | if (entry->group == group && entry->name != NULL && entry->name[0] != 0) |
| 1804 | | { |
| 1805 | | input_seq_type seqtype; |
| 1806 | | |
| 1807 | | /* loop over all sequence types */ |
| 1808 | | sortorder++; |
| 1809 | | for (seqtype = SEQ_TYPE_STANDARD; seqtype < SEQ_TYPE_TOTAL; seqtype++) |
| 1810 | | { |
| 1811 | | /* build an entry for the standard sequence */ |
| 1812 | | input_item_data *item = (input_item_data *)ui_menu_pool_alloc(menu, sizeof(*item)); |
| 1813 | | memset(item, 0, sizeof(*item)); |
| 1814 | | item->ref = entry; |
| 1815 | | item->seqtype = seqtype; |
| 1816 | | item->seq = input_type_seq(machine, entry->type, entry->player, seqtype); |
| 1817 | | item->defseq = &entry->defseq[seqtype]; |
| 1818 | | item->sortorder = sortorder * 4 + suborder[seqtype]; |
| 1819 | | item->type = input_type_is_analog(entry->type) ? (INPUT_TYPE_ANALOG + seqtype) : INPUT_TYPE_DIGITAL; |
| 1820 | | item->name = entry->name; |
| 1821 | | item->next = itemlist; |
| 1822 | | itemlist = item; |
| 1823 | | |
| 1824 | | /* stop after one, unless we're analog */ |
| 1825 | | if (item->type == INPUT_TYPE_DIGITAL) |
| 1826 | | break; |
| 1827 | | } |
| 1828 | | } |
| 1829 | | |
| 1830 | | /* sort and populate the menu in a standard fashion */ |
| 1831 | | menu_input_populate_and_sort(machine, menu, itemlist, menustate); |
| 1832 | | } |
| 1833 | | |
| 1834 | | |
| 1835 | | /*------------------------------------------------- |
| 1836 | | menu_input_specific - handle the game-specific |
| 1837 | | input menu |
| 1838 | | -------------------------------------------------*/ |
| 1839 | | |
| 1840 | | static void menu_input_specific(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1841 | | { |
| 1842 | | menu_input_common(machine, menu, NULL, state); |
| 1843 | | } |
| 1844 | | |
| 1845 | | |
| 1846 | | /*------------------------------------------------- |
| 1847 | | menu_input_specific_populate - populate |
| 1848 | | the input menu with game-specific items |
| 1849 | | -------------------------------------------------*/ |
| 1850 | | |
| 1851 | | static void menu_input_specific_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate) |
| 1852 | | { |
| 1853 | | input_item_data *itemlist = NULL; |
| 1854 | | input_field_config *field; |
| 1855 | | input_port_config *port; |
| 1856 | | int suborder[SEQ_TYPE_TOTAL]; |
| 1857 | | astring tempstring; |
| 1858 | | |
| 1859 | | /* create a mini lookup table for sort order based on sequence type */ |
| 1860 | | suborder[SEQ_TYPE_STANDARD] = 0; |
| 1861 | | suborder[SEQ_TYPE_DECREMENT] = 1; |
| 1862 | | suborder[SEQ_TYPE_INCREMENT] = 2; |
| 1863 | | |
| 1864 | | /* iterate over the input ports and add menu items */ |
| 1865 | | for (port = machine.m_portlist.first(); port != NULL; port = port->next()) |
| 1866 | | for (field = port->fieldlist().first(); field != NULL; field = field->next()) |
| 1867 | | { |
| 1868 | | const char *name = input_field_name(field); |
| 1869 | | |
| 1870 | | /* add if we match the group and we have a valid name */ |
| 1871 | | if (name != NULL && input_condition_true(machine, &field->condition, port->owner()) && |
| 1872 | | ((field->type == IPT_OTHER && field->name != NULL) || input_type_group(machine, field->type, field->player) != IPG_INVALID)) |
| 1873 | | { |
| 1874 | | input_seq_type seqtype; |
| 1875 | | UINT16 sortorder; |
| 1876 | | |
| 1877 | | /* determine the sorting order */ |
| 1878 | | if (field->type >= IPT_START1 && field->type <= __ipt_analog_end) |
| 1879 | | sortorder = (field->type << 2) | (field->player << 12); |
| 1880 | | else |
| 1881 | | sortorder = field->type | 0xf000; |
| 1882 | | |
| 1883 | | /* loop over all sequence types */ |
| 1884 | | for (seqtype = SEQ_TYPE_STANDARD; seqtype < SEQ_TYPE_TOTAL; seqtype++) |
| 1885 | | { |
| 1886 | | /* build an entry for the standard sequence */ |
| 1887 | | input_item_data *item = (input_item_data *)ui_menu_pool_alloc(menu, sizeof(*item)); |
| 1888 | | memset(item, 0, sizeof(*item)); |
| 1889 | | item->ref = field; |
| 1890 | | item->seqtype = seqtype; |
| 1891 | | item->seq = input_field_seq(field, seqtype); |
| 1892 | | item->defseq = &get_field_default_seq(field, seqtype); |
| 1893 | | item->sortorder = sortorder + suborder[seqtype]; |
| 1894 | | item->type = input_type_is_analog(field->type) ? (INPUT_TYPE_ANALOG + seqtype) : INPUT_TYPE_DIGITAL; |
| 1895 | | item->name = name; |
| 1896 | | item->next = itemlist; |
| 1897 | | itemlist = item; |
| 1898 | | |
| 1899 | | /* stop after one, unless we're analog */ |
| 1900 | | if (item->type == INPUT_TYPE_DIGITAL) |
| 1901 | | break; |
| 1902 | | } |
| 1903 | | } |
| 1904 | | } |
| 1905 | | |
| 1906 | | /* sort and populate the menu in a standard fashion */ |
| 1907 | | menu_input_populate_and_sort(machine, menu, itemlist, menustate); |
| 1908 | | } |
| 1909 | | |
| 1910 | | |
| 1911 | | /*------------------------------------------------- |
| 1912 | | menu_input - display a menu for inputs |
| 1913 | | -------------------------------------------------*/ |
| 1914 | | |
| 1915 | | static void menu_input_common(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1916 | | { |
| 1917 | | input_item_data *seqchangeditem = NULL; |
| 1918 | | input_menu_state *menustate; |
| 1919 | | const ui_menu_event *menu_event; |
| 1920 | | int invalidate = FALSE; |
| 1921 | | |
| 1922 | | /* if no state, allocate now */ |
| 1923 | | if (state == NULL) |
| 1924 | | state = ui_menu_alloc_state(menu, sizeof(*menustate), NULL); |
| 1925 | | menustate = (input_menu_state *)state; |
| 1926 | | |
| 1927 | | /* if the menu isn't built, populate now */ |
| 1928 | | if (!ui_menu_populated(menu)) |
| 1929 | | { |
| 1930 | | if (parameter != NULL) |
| 1931 | | menu_input_general_populate(machine, menu, menustate, (FPTR)parameter - 1); |
| 1932 | | else |
| 1933 | | menu_input_specific_populate(machine, menu, menustate); |
| 1934 | | } |
| 1935 | | |
| 1936 | | /* process the menu */ |
| 1937 | | menu_event = ui_menu_process(machine, menu, (menustate->pollingitem != NULL) ? UI_MENU_PROCESS_NOKEYS : 0); |
| 1938 | | |
| 1939 | | /* if we are polling, handle as a special case */ |
| 1940 | | if (menustate->pollingitem != NULL) |
| 1941 | | { |
| 1942 | | input_item_data *item = menustate->pollingitem; |
| 1943 | | input_seq newseq; |
| 1944 | | |
| 1945 | | /* if UI_CANCEL is pressed, abort */ |
| 1946 | | if (ui_input_pressed(machine, IPT_UI_CANCEL)) |
| 1947 | | { |
| 1948 | | menustate->pollingitem = NULL; |
| 1949 | | menustate->record_next = FALSE; |
| 1950 | | toggle_none_default(item->seq, menustate->starting_seq, *item->defseq); |
| 1951 | | seqchangeditem = item; |
| 1952 | | } |
| 1953 | | |
| 1954 | | /* poll again; if finished, update the sequence */ |
| 1955 | | if (machine.input().seq_poll()) |
| 1956 | | { |
| 1957 | | menustate->pollingitem = NULL; |
| 1958 | | menustate->record_next = TRUE; |
| 1959 | | item->seq = machine.input().seq_poll_final(); |
| 1960 | | seqchangeditem = item; |
| 1961 | | } |
| 1962 | | } |
| 1963 | | |
| 1964 | | /* otherwise, handle the events */ |
| 1965 | | else if (menu_event != NULL && menu_event->itemref != NULL) |
| 1966 | | { |
| 1967 | | input_item_data *item = (input_item_data *)menu_event->itemref; |
| 1968 | | switch (menu_event->iptkey) |
| 1969 | | { |
| 1970 | | /* an item was selected: begin polling */ |
| 1971 | | case IPT_UI_SELECT: |
| 1972 | | menustate->pollingitem = item; |
| 1973 | | menustate->last_sortorder = item->sortorder; |
| 1974 | | menustate->starting_seq = item->seq; |
| 1975 | | machine.input().seq_poll_start((item->type == INPUT_TYPE_ANALOG) ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, menustate->record_next ? &item->seq : NULL); |
| 1976 | | invalidate = TRUE; |
| 1977 | | break; |
| 1978 | | |
| 1979 | | /* if the clear key was pressed, reset the selected item */ |
| 1980 | | case IPT_UI_CLEAR: |
| 1981 | | toggle_none_default(item->seq, item->seq, *item->defseq); |
| 1982 | | menustate->record_next = FALSE; |
| 1983 | | seqchangeditem = item; |
| 1984 | | break; |
| 1985 | | } |
| 1986 | | |
| 1987 | | /* if the selection changed, reset the "record next" flag */ |
| 1988 | | if (item->sortorder != menustate->last_sortorder) |
| 1989 | | menustate->record_next = FALSE; |
| 1990 | | menustate->last_sortorder = item->sortorder; |
| 1991 | | } |
| 1992 | | |
| 1993 | | /* if the sequence changed, update it */ |
| 1994 | | if (seqchangeditem != NULL) |
| 1995 | | { |
| 1996 | | /* update a general input */ |
| 1997 | | if (parameter != NULL) |
| 1998 | | { |
| 1999 | | const input_type_entry *entry = (const input_type_entry *)seqchangeditem->ref; |
| 2000 | | input_type_set_seq(machine, entry->type, entry->player, seqchangeditem->seqtype, &seqchangeditem->seq); |
| 2001 | | } |
| 2002 | | |
| 2003 | | /* update a game-specific input */ |
| 2004 | | else |
| 2005 | | { |
| 2006 | | input_field_user_settings settings; |
| 2007 | | |
| 2008 | | input_field_get_user_settings((input_field_config *)seqchangeditem->ref, &settings); |
| 2009 | | settings.seq[seqchangeditem->seqtype] = seqchangeditem->seq; |
| 2010 | | input_field_set_user_settings((input_field_config *)seqchangeditem->ref, &settings); |
| 2011 | | } |
| 2012 | | |
| 2013 | | /* invalidate the menu to force an update */ |
| 2014 | | invalidate = TRUE; |
| 2015 | | } |
| 2016 | | |
| 2017 | | /* if the menu is invalidated, clear it now */ |
| 2018 | | if (invalidate) |
| 2019 | | { |
| 2020 | | menustate->pollingref = NULL; |
| 2021 | | if (menustate->pollingitem != NULL) |
| 2022 | | menustate->pollingref = menustate->pollingitem->ref; |
| 2023 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_POSITION); |
| 2024 | | } |
| 2025 | | } |
| 2026 | | |
| 2027 | | |
| 2028 | | /*------------------------------------------------- |
| 2029 | | menu_input_compare_items - compare two |
| 2030 | | items for quicksort |
| 2031 | | -------------------------------------------------*/ |
| 2032 | | |
| 2033 | | static int menu_input_compare_items(const void *i1, const void *i2) |
| 2034 | | { |
| 2035 | | const input_item_data * const *data1 = (const input_item_data * const *)i1; |
| 2036 | | const input_item_data * const *data2 = (const input_item_data * const *)i2; |
| 2037 | | if ((*data1)->sortorder < (*data2)->sortorder) |
| 2038 | | return -1; |
| 2039 | | if ((*data1)->sortorder > (*data2)->sortorder) |
| 2040 | | return 1; |
| 2041 | | return 0; |
| 2042 | | } |
| 2043 | | |
| 2044 | | |
| 2045 | | /*------------------------------------------------- |
| 2046 | | menu_input_populate_and_sort - take a list |
| 2047 | | of input_item_data objects and build up the |
| 2048 | | menu from them |
| 2049 | | -------------------------------------------------*/ |
| 2050 | | |
| 2051 | | static void menu_input_populate_and_sort(running_machine &machine, ui_menu *menu, input_item_data *itemlist, input_menu_state *menustate) |
| 2052 | | { |
| 2053 | | const char *nameformat[INPUT_TYPE_TOTAL] = { 0 }; |
| 2054 | | input_item_data **itemarray, *item; |
| 2055 | | int numitems = 0, curitem; |
| 2056 | | astring subtext; |
| 2057 | | astring text; |
| 2058 | | |
| 2059 | | /* create a mini lookup table for name format based on type */ |
| 2060 | | nameformat[INPUT_TYPE_DIGITAL] = "%s"; |
| 2061 | | nameformat[INPUT_TYPE_ANALOG] = "%s Analog"; |
| 2062 | | nameformat[INPUT_TYPE_ANALOG_INC] = "%s Analog Inc"; |
| 2063 | | nameformat[INPUT_TYPE_ANALOG_DEC] = "%s Analog Dec"; |
| 2064 | | |
| 2065 | | /* first count the number of items */ |
| 2066 | | for (item = itemlist; item != NULL; item = item->next) |
| 2067 | | numitems++; |
| 2068 | | |
| 2069 | | /* now allocate an array of items and fill it up */ |
| 2070 | | itemarray = (input_item_data **)ui_menu_pool_alloc(menu, sizeof(*itemarray) * numitems); |
| 2071 | | for (item = itemlist, curitem = 0; item != NULL; item = item->next) |
| 2072 | | itemarray[curitem++] = item; |
| 2073 | | |
| 2074 | | /* sort it */ |
| 2075 | | qsort(itemarray, numitems, sizeof(*itemarray), menu_input_compare_items); |
| 2076 | | |
| 2077 | | /* build the menu */ |
| 2078 | | for (curitem = 0; curitem < numitems; curitem++) |
| 2079 | | { |
| 2080 | | UINT32 flags = 0; |
| 2081 | | |
| 2082 | | /* generate the name of the item itself, based off the base name and the type */ |
| 2083 | | item = itemarray[curitem]; |
| 2084 | | assert(nameformat[item->type] != NULL); |
| 2085 | | text.printf(nameformat[item->type], item->name); |
| 2086 | | |
| 2087 | | /* if we're polling this item, use some spaces with left/right arrows */ |
| 2088 | | if (menustate->pollingref == item->ref) |
| 2089 | | { |
| 2090 | | subtext.cpy(" "); |
| 2091 | | flags |= MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW; |
| 2092 | | } |
| 2093 | | |
| 2094 | | /* otherwise, generate the sequence name and invert it if different from the default */ |
| 2095 | | else |
| 2096 | | { |
| 2097 | | machine.input().seq_name(subtext, item->seq); |
| 2098 | | flags |= (item->seq != *item->defseq) ? MENU_FLAG_INVERT : 0; |
| 2099 | | } |
| 2100 | | |
| 2101 | | /* add the item */ |
| 2102 | | ui_menu_item_append(menu, text, subtext, flags, item); |
| 2103 | | } |
| 2104 | | } |
| 2105 | | |
| 2106 | | |
| 2107 | | /*------------------------------------------------- |
| 2108 | | menu_settings_dip_switches - handle the DIP |
| 2109 | | switches menu |
| 2110 | | -------------------------------------------------*/ |
| 2111 | | |
| 2112 | | static void menu_settings_dip_switches(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2113 | | { |
| 2114 | | menu_settings_common(machine, menu, state, IPT_DIPSWITCH); |
| 2115 | | } |
| 2116 | | |
| 2117 | | |
| 2118 | | /*------------------------------------------------- |
| 2119 | | menu_settings_driver_config - handle the |
| 2120 | | driver config menu |
| 2121 | | -------------------------------------------------*/ |
| 2122 | | |
| 2123 | | static void menu_settings_driver_config(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2124 | | { |
| 2125 | | menu_settings_common(machine, menu, state, IPT_CONFIG); |
| 2126 | | } |
| 2127 | | |
| 2128 | | |
| 2129 | | /*------------------------------------------------- |
| 2130 | | menu_settings_common - handle one of the |
| 2131 | | switches menus |
| 2132 | | -------------------------------------------------*/ |
| 2133 | | |
| 2134 | | static void menu_settings_common(running_machine &machine, ui_menu *menu, void *state, UINT32 type) |
| 2135 | | { |
| 2136 | | settings_menu_state *menustate; |
| 2137 | | const ui_menu_event *menu_event; |
| 2138 | | |
| 2139 | | /* if no state, allocate now */ |
| 2140 | | if (state == NULL) |
| 2141 | | state = ui_menu_alloc_state(menu, sizeof(*menustate), NULL); |
| 2142 | | menustate = (settings_menu_state *)state; |
| 2143 | | |
| 2144 | | /* if the menu isn't built, populate now */ |
| 2145 | | if (!ui_menu_populated(menu)) |
| 2146 | | menu_settings_populate(machine, menu, menustate, type); |
| 2147 | | |
| 2148 | | /* process the menu */ |
| 2149 | | menu_event = ui_menu_process(machine, menu, 0); |
| 2150 | | |
| 2151 | | /* handle events */ |
| 2152 | | if (menu_event != NULL && menu_event->itemref != NULL) |
| 2153 | | { |
| 2154 | | input_field_config *field = (input_field_config *)menu_event->itemref; |
| 2155 | | input_field_user_settings settings; |
| 2156 | | int changed = FALSE; |
| 2157 | | |
| 2158 | | switch (menu_event->iptkey) |
| 2159 | | { |
| 2160 | | /* if selected, reset to default value */ |
| 2161 | | case IPT_UI_SELECT: |
| 2162 | | input_field_get_user_settings(field, &settings); |
| 2163 | | settings.value = field->defvalue; |
| 2164 | | input_field_set_user_settings(field, &settings); |
| 2165 | | changed = TRUE; |
| 2166 | | break; |
| 2167 | | |
| 2168 | | /* left goes to previous setting */ |
| 2169 | | case IPT_UI_LEFT: |
| 2170 | | input_field_select_previous_setting(field); |
| 2171 | | changed = TRUE; |
| 2172 | | break; |
| 2173 | | |
| 2174 | | /* right goes to next setting */ |
| 2175 | | case IPT_UI_RIGHT: |
| 2176 | | input_field_select_next_setting(field); |
| 2177 | | changed = TRUE; |
| 2178 | | break; |
| 2179 | | } |
| 2180 | | |
| 2181 | | /* if anything changed, rebuild the menu, trying to stay on the same field */ |
| 2182 | | if (changed) |
| 2183 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF); |
| 2184 | | } |
| 2185 | | } |
| 2186 | | |
| 2187 | | |
| 2188 | | /*------------------------------------------------- |
| 2189 | | menu_settings_populate - populate one of the |
| 2190 | | switches menus |
| 2191 | | -------------------------------------------------*/ |
| 2192 | | |
| 2193 | | static void menu_settings_populate(running_machine &machine, ui_menu *menu, settings_menu_state *menustate, UINT32 type) |
| 2194 | | { |
| 2195 | | input_field_config *field; |
| 2196 | | input_port_config *port; |
| 2197 | | dip_descriptor **diplist_tailptr; |
| 2198 | | int dipcount = 0; |
| 2199 | | |
| 2200 | | /* reset the dip switch tracking */ |
| 2201 | | menustate->diplist = NULL; |
| 2202 | | diplist_tailptr = &menustate->diplist; |
| 2203 | | |
| 2204 | | /* loop over input ports and set up the current values */ |
| 2205 | | for (port = machine.m_portlist.first(); port != NULL; port = port->next()) |
| 2206 | | for (field = port->fieldlist().first(); field != NULL; field = field->next()) |
| 2207 | | if (field->type == type && input_condition_true(machine, &field->condition, port->owner())) |
| 2208 | | { |
| 2209 | | UINT32 flags = 0; |
| 2210 | | |
| 2211 | | /* set the left/right flags appropriately */ |
| 2212 | | if (input_field_has_previous_setting(field)) |
| 2213 | | flags |= MENU_FLAG_LEFT_ARROW; |
| 2214 | | if (input_field_has_next_setting(field)) |
| 2215 | | flags |= MENU_FLAG_RIGHT_ARROW; |
| 2216 | | |
| 2217 | | /* add the menu item */ |
| 2218 | | ui_menu_item_append(menu, input_field_name(field), input_field_setting_name(field), flags, (void *)field); |
| 2219 | | |
| 2220 | | /* for DIP switches, build up the model */ |
| 2221 | | if (type == IPT_DIPSWITCH && field->diploclist().count() != 0) |
| 2222 | | { |
| 2223 | | const input_field_diplocation *diploc; |
| 2224 | | input_field_user_settings settings; |
| 2225 | | UINT32 accummask = field->mask; |
| 2226 | | |
| 2227 | | /* get current settings */ |
| 2228 | | input_field_get_user_settings(field, &settings); |
| 2229 | | |
| 2230 | | /* iterate over each bit in the field */ |
| 2231 | | for (diploc = field->diploclist().first(); diploc != NULL; diploc = diploc->next()) |
| 2232 | | { |
| 2233 | | UINT32 mask = accummask & ~(accummask - 1); |
| 2234 | | dip_descriptor *dip; |
| 2235 | | |
| 2236 | | /* find the matching switch name */ |
| 2237 | | for (dip = menustate->diplist; dip != NULL; dip = dip->next) |
| 2238 | | if (strcmp(dip->name, diploc->swname) == 0) |
| 2239 | | break; |
| 2240 | | |
| 2241 | | /* allocate new if none */ |
| 2242 | | if (dip == NULL) |
| 2243 | | { |
| 2244 | | dip = (dip_descriptor *)ui_menu_pool_alloc(menu, sizeof(*dip)); |
| 2245 | | dip->next = NULL; |
| 2246 | | dip->name = diploc->swname; |
| 2247 | | dip->mask = dip->state = 0; |
| 2248 | | *diplist_tailptr = dip; |
| 2249 | | diplist_tailptr = &dip->next; |
| 2250 | | if (mame_stricmp(dip->name, "FAKE") != 0) |
| 2251 | | dipcount++; |
| 2252 | | } |
| 2253 | | |
| 2254 | | /* apply the bits */ |
| 2255 | | dip->mask |= 1 << (diploc->swnum - 1); |
| 2256 | | if (((settings.value & mask) != 0 && !diploc->invert) || ((settings.value & mask) == 0 && diploc->invert)) |
| 2257 | | dip->state |= 1 << (diploc->swnum - 1); |
| 2258 | | |
| 2259 | | /* clear the relevant bit in the accumulated mask */ |
| 2260 | | accummask &= ~mask; |
| 2261 | | } |
| 2262 | | } |
| 2263 | | } |
| 2264 | | |
| 2265 | | /* configure the extra menu */ |
| 2266 | | if (type == IPT_DIPSWITCH && menustate->diplist != NULL) |
| 2267 | | ui_menu_set_custom_render(menu, menu_settings_custom_render, 0.0f, dipcount * (DIP_SWITCH_HEIGHT + DIP_SWITCH_SPACING) + DIP_SWITCH_SPACING); |
| 2268 | | } |
| 2269 | | |
| 2270 | | |
| 2271 | | /*------------------------------------------------- |
| 2272 | | menu_settings_custom_render - perform our special |
| 2273 | | rendering |
| 2274 | | -------------------------------------------------*/ |
| 2275 | | |
| 2276 | | static 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) |
| 2277 | | { |
| 2278 | | input_field_config *field = (input_field_config *)selectedref; |
| 2279 | | settings_menu_state *menustate = (settings_menu_state *)state; |
| 2280 | | dip_descriptor *dip; |
| 2281 | | |
| 2282 | | /* add borders */ |
| 2283 | | y1 = y2 + UI_BOX_TB_BORDER; |
| 2284 | | y2 = y1 + bottom; |
| 2285 | | |
| 2286 | | /* draw extra menu area */ |
| 2287 | | ui_draw_outlined_box(menu->container, x1, y1, x2, y2, UI_BACKGROUND_COLOR); |
| 2288 | | y1 += (float)DIP_SWITCH_SPACING; |
| 2289 | | |
| 2290 | | /* iterate over DIP switches */ |
| 2291 | | for (dip = menustate->diplist; dip != NULL; dip = dip->next) |
| 2292 | | { |
| 2293 | | if (mame_stricmp(dip->name, "FAKE") != 0) |
| 2294 | | { |
| 2295 | | const input_field_diplocation *diploc; |
| 2296 | | UINT32 selectedmask = 0; |
| 2297 | | |
| 2298 | | /* determine the mask of selected bits */ |
| 2299 | | if (field != NULL) |
| 2300 | | for (diploc = field->diploclist().first(); diploc != NULL; diploc = diploc->next()) |
| 2301 | | if (strcmp(dip->name, diploc->swname) == 0) |
| 2302 | | selectedmask |= 1 << (diploc->swnum - 1); |
| 2303 | | |
| 2304 | | /* draw one switch */ |
| 2305 | | menu_settings_custom_render_one(menu->container, x1, y1, x2, y1 + DIP_SWITCH_HEIGHT, dip, selectedmask); |
| 2306 | | y1 += (float)(DIP_SWITCH_SPACING + DIP_SWITCH_HEIGHT); |
| 2307 | | } |
| 2308 | | } |
| 2309 | | } |
| 2310 | | |
| 2311 | | |
| 2312 | | /*------------------------------------------------- |
| 2313 | | menu_settings_custom_render_one - draw a single |
| 2314 | | DIP switch |
| 2315 | | -------------------------------------------------*/ |
| 2316 | | |
| 2317 | | static void menu_settings_custom_render_one(render_container *container, float x1, float y1, float x2, float y2, const dip_descriptor *dip, UINT32 selectedmask) |
| 2318 | | { |
| 2319 | | float switch_field_width = SINGLE_TOGGLE_SWITCH_FIELD_WIDTH * container->manager().ui_aspect(); |
| 2320 | | float switch_width = SINGLE_TOGGLE_SWITCH_WIDTH * container->manager().ui_aspect(); |
| 2321 | | int numtoggles, toggle; |
| 2322 | | float switch_toggle_gap; |
| 2323 | | float y1_off, y1_on; |
| 2324 | | |
| 2325 | | /* determine the number of toggles in the DIP */ |
| 2326 | | numtoggles = 32 - count_leading_zeros(dip->mask); |
| 2327 | | |
| 2328 | | /* center based on the number of switches */ |
| 2329 | | x1 += (x2 - x1 - numtoggles * switch_field_width) / 2; |
| 2330 | | |
| 2331 | | /* draw the dip switch name */ |
| 2332 | | ui_draw_text_full( container, |
| 2333 | | dip->name, |
| 2334 | | 0, |
| 2335 | | y1 + (DIP_SWITCH_HEIGHT - UI_TARGET_FONT_HEIGHT) / 2, |
| 2336 | | x1 - ui_get_string_width(container->manager().machine(), " "), |
| 2337 | | JUSTIFY_RIGHT, |
| 2338 | | WRAP_NEVER, |
| 2339 | | DRAW_NORMAL, |
| 2340 | | UI_TEXT_COLOR, |
| 2341 | | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA), |
| 2342 | | NULL , |
| 2343 | | NULL); |
| 2344 | | |
| 2345 | | /* compute top and bottom for on and off positions */ |
| 2346 | | switch_toggle_gap = ((DIP_SWITCH_HEIGHT/2) - SINGLE_TOGGLE_SWITCH_HEIGHT)/2; |
| 2347 | | y1_off = y1 + UI_LINE_WIDTH + switch_toggle_gap; |
| 2348 | | y1_on = y1 + DIP_SWITCH_HEIGHT/2 + switch_toggle_gap; |
| 2349 | | |
| 2350 | | /* iterate over toggles */ |
| 2351 | | for (toggle = 0; toggle < numtoggles; toggle++) |
| 2352 | | { |
| 2353 | | float innerx1; |
| 2354 | | |
| 2355 | | /* first outline the switch */ |
| 2356 | | ui_draw_outlined_box(container, x1, y1, x1 + switch_field_width, y2, UI_BACKGROUND_COLOR); |
| 2357 | | |
| 2358 | | /* compute x1/x2 for the inner filled in switch */ |
| 2359 | | innerx1 = x1 + (switch_field_width - switch_width) / 2; |
| 2360 | | |
| 2361 | | /* see if the switch is actually used */ |
| 2362 | | if (dip->mask & (1 << toggle)) |
| 2363 | | { |
| 2364 | | float innery1 = (dip->state & (1 << toggle)) ? y1_on : y1_off; |
| 2365 | | container->add_rect(innerx1, innery1, innerx1 + switch_width, innery1 + SINGLE_TOGGLE_SWITCH_HEIGHT, |
| 2366 | | (selectedmask & (1 << toggle)) ? UI_DIPSW_COLOR : UI_TEXT_COLOR, |
| 2367 | | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 2368 | | } |
| 2369 | | else |
| 2370 | | { |
| 2371 | | container->add_rect(innerx1, y1_off, innerx1 + switch_width, y1_on + SINGLE_TOGGLE_SWITCH_HEIGHT, |
| 2372 | | UI_UNAVAILABLE_COLOR, |
| 2373 | | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 2374 | | } |
| 2375 | | |
| 2376 | | /* advance to the next switch */ |
| 2377 | | x1 += switch_field_width; |
| 2378 | | } |
| 2379 | | } |
| 2380 | | |
| 2381 | | |
| 2382 | | /*------------------------------------------------- |
| 2383 | | menu_analog - handle the analog settings menu |
| 2384 | | -------------------------------------------------*/ |
| 2385 | | |
| 2386 | | static void menu_analog(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2387 | | { |
| 2388 | | const ui_menu_event *menu_event; |
| 2389 | | |
| 2390 | | /* if the menu isn't built, populate now */ |
| 2391 | | if (!ui_menu_populated(menu)) |
| 2392 | | menu_analog_populate(machine, menu); |
| 2393 | | |
| 2394 | | /* process the menu */ |
| 2395 | | menu_event = ui_menu_process(machine, menu, UI_MENU_PROCESS_LR_REPEAT); |
| 2396 | | |
| 2397 | | /* handle events */ |
| 2398 | | if (menu_event != NULL && menu_event->itemref != NULL) |
| 2399 | | { |
| 2400 | | analog_item_data *data = (analog_item_data *)menu_event->itemref; |
| 2401 | | int newval = data->cur; |
| 2402 | | |
| 2403 | | switch (menu_event->iptkey) |
| 2404 | | { |
| 2405 | | /* if selected, reset to default value */ |
| 2406 | | case IPT_UI_SELECT: |
| 2407 | | newval = data->defvalue; |
| 2408 | | break; |
| 2409 | | |
| 2410 | | /* left decrements */ |
| 2411 | | case IPT_UI_LEFT: |
| 2412 | | newval -= machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1; |
| 2413 | | break; |
| 2414 | | |
| 2415 | | /* right increments */ |
| 2416 | | case IPT_UI_RIGHT: |
| 2417 | | newval += machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1; |
| 2418 | | break; |
| 2419 | | } |
| 2420 | | |
| 2421 | | /* clamp to range */ |
| 2422 | | if (newval < data->min) |
| 2423 | | newval = data->min; |
| 2424 | | if (newval > data->max) |
| 2425 | | newval = data->max; |
| 2426 | | |
| 2427 | | /* if things changed, update */ |
| 2428 | | if (newval != data->cur) |
| 2429 | | { |
| 2430 | | input_field_user_settings settings; |
| 2431 | | |
| 2432 | | /* get the settings and set the new value */ |
| 2433 | | input_field_get_user_settings(data->field, &settings); |
| 2434 | | switch (data->type) |
| 2435 | | { |
| 2436 | | case ANALOG_ITEM_KEYSPEED: settings.delta = newval; break; |
| 2437 | | case ANALOG_ITEM_CENTERSPEED: settings.centerdelta = newval; break; |
| 2438 | | case ANALOG_ITEM_REVERSE: settings.reverse = newval; break; |
| 2439 | | case ANALOG_ITEM_SENSITIVITY: settings.sensitivity = newval; break; |
| 2440 | | } |
| 2441 | | input_field_set_user_settings(data->field, &settings); |
| 2442 | | |
| 2443 | | /* rebuild the menu */ |
| 2444 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_POSITION); |
| 2445 | | } |
| 2446 | | } |
| 2447 | | } |
| 2448 | | |
| 2449 | | |
| 2450 | | /*------------------------------------------------- |
| 2451 | | menu_analog_populate - populate the analog |
| 2452 | | settings menu |
| 2453 | | -------------------------------------------------*/ |
| 2454 | | |
| 2455 | | static void menu_analog_populate(running_machine &machine, ui_menu *menu) |
| 2456 | | { |
| 2457 | | input_field_config *field; |
| 2458 | | input_port_config *port; |
| 2459 | | astring subtext; |
| 2460 | | astring text; |
| 2461 | | |
| 2462 | | /* loop over input ports and add the items */ |
| 2463 | | for (port = machine.m_portlist.first(); port != NULL; port = port->next()) |
| 2464 | | for (field = port->fieldlist().first(); field != NULL; field = field->next()) |
| 2465 | | if (input_type_is_analog(field->type) && input_condition_true(machine, &field->condition, port->owner())) |
| 2466 | | { |
| 2467 | | input_field_user_settings settings; |
| 2468 | | int use_autocenter = FALSE; |
| 2469 | | int type; |
| 2470 | | |
| 2471 | | /* based on the type, determine if we enable autocenter */ |
| 2472 | | switch (field->type) |
| 2473 | | { |
| 2474 | | case IPT_POSITIONAL: |
| 2475 | | case IPT_POSITIONAL_V: |
| 2476 | | if (field->flags & ANALOG_FLAG_WRAPS) |
| 2477 | | break; |
| 2478 | | |
| 2479 | | case IPT_AD_STICK_X: |
| 2480 | | case IPT_AD_STICK_Y: |
| 2481 | | case IPT_AD_STICK_Z: |
| 2482 | | case IPT_PADDLE: |
| 2483 | | case IPT_PADDLE_V: |
| 2484 | | case IPT_PEDAL: |
| 2485 | | case IPT_PEDAL2: |
| 2486 | | case IPT_PEDAL3: |
| 2487 | | use_autocenter = TRUE; |
| 2488 | | break; |
| 2489 | | } |
| 2490 | | |
| 2491 | | /* get the user settings */ |
| 2492 | | input_field_get_user_settings(field, &settings); |
| 2493 | | |
| 2494 | | /* iterate over types */ |
| 2495 | | for (type = 0; type < ANALOG_ITEM_COUNT; type++) |
| 2496 | | if (type != ANALOG_ITEM_CENTERSPEED || use_autocenter) |
| 2497 | | { |
| 2498 | | analog_item_data *data; |
| 2499 | | UINT32 flags = 0; |
| 2500 | | |
| 2501 | | /* allocate a data item for tracking what this menu item refers to */ |
| 2502 | | data = (analog_item_data *)ui_menu_pool_alloc(menu, sizeof(*data)); |
| 2503 | | data->field = field; |
| 2504 | | data->type = type; |
| 2505 | | |
| 2506 | | /* determine the properties of this item */ |
| 2507 | | switch (type) |
| 2508 | | { |
| 2509 | | default: |
| 2510 | | case ANALOG_ITEM_KEYSPEED: |
| 2511 | | text.printf("%s Digital Speed", input_field_name(field)); |
| 2512 | | subtext.printf("%d", settings.delta); |
| 2513 | | data->min = 0; |
| 2514 | | data->max = 255; |
| 2515 | | data->cur = settings.delta; |
| 2516 | | data->defvalue = field->delta; |
| 2517 | | break; |
| 2518 | | |
| 2519 | | case ANALOG_ITEM_CENTERSPEED: |
| 2520 | | text.printf("%s Autocenter Speed", input_field_name(field)); |
| 2521 | | subtext.printf("%d", settings.centerdelta); |
| 2522 | | data->min = 0; |
| 2523 | | data->max = 255; |
| 2524 | | data->cur = settings.centerdelta; |
| 2525 | | data->defvalue = field->centerdelta; |
| 2526 | | break; |
| 2527 | | |
| 2528 | | case ANALOG_ITEM_REVERSE: |
| 2529 | | text.printf("%s Reverse", input_field_name(field)); |
| 2530 | | subtext.cpy(settings.reverse ? "On" : "Off"); |
| 2531 | | data->min = 0; |
| 2532 | | data->max = 1; |
| 2533 | | data->cur = settings.reverse; |
| 2534 | | data->defvalue = ((field->flags & ANALOG_FLAG_REVERSE) != 0); |
| 2535 | | break; |
| 2536 | | |
| 2537 | | case ANALOG_ITEM_SENSITIVITY: |
| 2538 | | text.printf("%s Sensitivity", input_field_name(field)); |
| 2539 | | subtext.printf("%d", settings.sensitivity); |
| 2540 | | data->min = 1; |
| 2541 | | data->max = 255; |
| 2542 | | data->cur = settings.sensitivity; |
| 2543 | | data->defvalue = field->sensitivity; |
| 2544 | | break; |
| 2545 | | } |
| 2546 | | |
| 2547 | | /* put on arrows */ |
| 2548 | | if (data->cur > data->min) |
| 2549 | | flags |= MENU_FLAG_LEFT_ARROW; |
| 2550 | | if (data->cur < data->max) |
| 2551 | | flags |= MENU_FLAG_RIGHT_ARROW; |
| 2552 | | |
| 2553 | | /* append a menu item */ |
| 2554 | | ui_menu_item_append(menu, text, subtext, flags, data); |
| 2555 | | } |
| 2556 | | } |
| 2557 | | } |
| 2558 | | |
| 2559 | | |
| 2560 | | /*------------------------------------------------- |
| 2561 | | menu_bookkeeping - handle the bookkeeping |
| 2562 | | information menu |
| 2563 | | -------------------------------------------------*/ |
| 2564 | | |
| 2565 | | static void menu_bookkeeping(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2566 | | { |
| 2567 | | attotime *prevtime; |
| 2568 | | attotime curtime; |
| 2569 | | |
| 2570 | | /* if no state, allocate some */ |
| 2571 | | if (state == NULL) |
| 2572 | | state = ui_menu_alloc_state(menu, sizeof(*prevtime), NULL); |
| 2573 | | prevtime = (attotime *)state; |
| 2574 | | |
| 2575 | | /* if the time has rolled over another second, regenerate */ |
| 2576 | | curtime = machine.time(); |
| 2577 | | if (prevtime->seconds != curtime.seconds) |
| 2578 | | { |
| 2579 | | ui_menu_reset(menu, UI_MENU_RESET_SELECT_FIRST); |
| 2580 | | *prevtime = curtime; |
| 2581 | | menu_bookkeeping_populate(machine, menu, prevtime); |
| 2582 | | } |
| 2583 | | |
| 2584 | | /* process the menu */ |
| 2585 | | ui_menu_process(machine, menu, 0); |
| 2586 | | } |
| 2587 | | |
| 2588 | | |
| 2589 | | /*------------------------------------------------- |
| 2590 | | menu_bookkeeping - handle the bookkeeping |
| 2591 | | information menu |
| 2592 | | -------------------------------------------------*/ |
| 2593 | | |
| 2594 | | static void menu_bookkeeping_populate(running_machine &machine, ui_menu *menu, attotime *curtime) |
| 2595 | | { |
| 2596 | | int tickets = get_dispensed_tickets(machine); |
| 2597 | | astring tempstring; |
| 2598 | | int ctrnum; |
| 2599 | | |
| 2600 | | /* show total time first */ |
| 2601 | | if (curtime->seconds >= 60 * 60) |
| 2602 | | tempstring.catprintf("Uptime: %d:%02d:%02d\n\n", curtime->seconds / (60*60), (curtime->seconds / 60) % 60, curtime->seconds % 60); |
| 2603 | | else |
| 2604 | | tempstring.catprintf("Uptime: %d:%02d\n\n", (curtime->seconds / 60) % 60, curtime->seconds % 60); |
| 2605 | | |
| 2606 | | /* show tickets at the top */ |
| 2607 | | if (tickets > 0) |
| 2608 | | tempstring.catprintf("Tickets dispensed: %d\n\n", tickets); |
| 2609 | | |
| 2610 | | /* loop over coin counters */ |
| 2611 | | for (ctrnum = 0; ctrnum < COIN_COUNTERS; ctrnum++) |
| 2612 | | { |
| 2613 | | int count = coin_counter_get_count(machine, ctrnum); |
| 2614 | | |
| 2615 | | /* display the coin counter number */ |
| 2616 | | tempstring.catprintf("Coin %c: ", ctrnum + 'A'); |
| 2617 | | |
| 2618 | | /* display how many coins */ |
| 2619 | | if (count == 0) |
| 2620 | | tempstring.cat("NA"); |
| 2621 | | else |
| 2622 | | tempstring.catprintf("%d", count); |
| 2623 | | |
| 2624 | | /* display whether or not we are locked out */ |
| 2625 | | if (coin_lockout_get_state(machine, ctrnum)) |
| 2626 | | tempstring.cat(" (locked)"); |
| 2627 | | tempstring.cat("\n"); |
| 2628 | | } |
| 2629 | | |
| 2630 | | /* append the single item */ |
| 2631 | | ui_menu_item_append(menu, tempstring, NULL, MENU_FLAG_MULTILINE, NULL); |
| 2632 | | } |
| 2633 | | |
| 2634 | | |
| 2635 | | /*------------------------------------------------- |
| 2636 | | menu_game_info - handle the game information |
| 2637 | | menu |
| 2638 | | -------------------------------------------------*/ |
| 2639 | | |
| 2640 | | static void menu_game_info(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2641 | | { |
| 2642 | | /* if the menu isn't built, populate now */ |
| 2643 | | if (!ui_menu_populated(menu)) |
| 2644 | | { |
| 2645 | | astring tempstring; |
| 2646 | | ui_menu_item_append(menu, game_info_astring(machine, tempstring), NULL, MENU_FLAG_MULTILINE, NULL); |
| 2647 | | } |
| 2648 | | |
| 2649 | | /* process the menu */ |
| 2650 | | ui_menu_process(machine, menu, 0); |
| 2651 | | } |
| 2652 | | |
| 2653 | | |
| 2654 | | /*------------------------------------------------- |
| 2655 | | menu_cheat - handle the cheat menu |
| 2656 | | -------------------------------------------------*/ |
| 2657 | | |
| 2658 | | static void menu_cheat(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2659 | | { |
| 2660 | | const ui_menu_event *menu_event; |
| 2661 | | |
| 2662 | | /* if the menu isn't built, populate now */ |
| 2663 | | if (!ui_menu_populated(menu)) |
| 2664 | | menu_cheat_populate(machine, menu); |
| 2665 | | |
| 2666 | | /* process the menu */ |
| 2667 | | menu_event = ui_menu_process(machine, menu, UI_MENU_PROCESS_LR_REPEAT); |
| 2668 | | |
| 2669 | | /* handle events */ |
| 2670 | | if (menu_event != NULL && menu_event->itemref != NULL) |
| 2671 | | { |
| 2672 | | bool changed = false; |
| 2673 | | |
| 2674 | | /* clear cheat comment on any movement or keypress */ |
| 2675 | | popmessage(NULL); |
| 2676 | | |
| 2677 | | /* handle reset all + reset all cheats for reload all option */ |
| 2678 | | if ((FPTR)menu_event->itemref < 3 && menu_event->iptkey == IPT_UI_SELECT) |
| 2679 | | { |
| 2680 | | for (cheat_entry *curcheat = machine.cheat().first(); curcheat != NULL; curcheat = curcheat->next()) |
| 2681 | | if (curcheat->select_default_state()) |
| 2682 | | changed = true; |
| 2683 | | } |
| 2684 | | |
| 2685 | | |
| 2686 | | /* handle individual cheats */ |
| 2687 | | else if ((FPTR)menu_event->itemref > 2) |
| 2688 | | { |
| 2689 | | cheat_entry *curcheat = reinterpret_cast<cheat_entry *>(menu_event->itemref); |
| 2690 | | const char *string; |
| 2691 | | switch (menu_event->iptkey) |
| 2692 | | { |
| 2693 | | /* if selected, activate a oneshot */ |
| 2694 | | case IPT_UI_SELECT: |
| 2695 | | changed = curcheat->activate(); |
| 2696 | | break; |
| 2697 | | |
| 2698 | | /* if cleared, reset to default value */ |
| 2699 | | case IPT_UI_CLEAR: |
| 2700 | | changed = curcheat->select_default_state(); |
| 2701 | | break; |
| 2702 | | |
| 2703 | | /* left decrements */ |
| 2704 | | case IPT_UI_LEFT: |
| 2705 | | changed = curcheat->select_previous_state(); |
| 2706 | | break; |
| 2707 | | |
| 2708 | | /* right increments */ |
| 2709 | | case IPT_UI_RIGHT: |
| 2710 | | changed = curcheat->select_next_state(); |
| 2711 | | break; |
| 2712 | | |
| 2713 | | /* bring up display comment if one exists */ |
| 2714 | | case IPT_UI_DISPLAY_COMMENT: |
| 2715 | | case IPT_UI_UP: |
| 2716 | | case IPT_UI_DOWN: |
| 2717 | | string = curcheat->comment(); |
| 2718 | | if (string != NULL && string[0] != 0) |
| 2719 | | popmessage("Cheat Comment:\n%s", string); |
| 2720 | | break; |
| 2721 | | } |
| 2722 | | } |
| 2723 | | |
| 2724 | | /* handle reload all */ |
| 2725 | | if ((FPTR)menu_event->itemref == 2 && menu_event->iptkey == IPT_UI_SELECT) |
| 2726 | | { |
| 2727 | | /* re-init cheat engine and thus reload cheats/cheats have already been turned off by here */ |
| 2728 | | machine.cheat().reload(); |
| 2729 | | |
| 2730 | | /* display the reloaded cheats */ |
| 2731 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF); |
| 2732 | | popmessage("All cheats reloaded"); |
| 2733 | | } |
| 2734 | | |
| 2735 | | /* if things changed, update */ |
| 2736 | | if (changed) |
| 2737 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF); |
| 2738 | | } |
| 2739 | | } |
| 2740 | | |
| 2741 | | |
| 2742 | | /*------------------------------------------------- |
| 2743 | | menu_cheat_populate - populate the cheat menu |
| 2744 | | -------------------------------------------------*/ |
| 2745 | | |
| 2746 | | static void menu_cheat_populate(running_machine &machine, ui_menu *menu) |
| 2747 | | { |
| 2748 | | /* iterate over cheats */ |
| 2749 | | astring text; |
| 2750 | | astring subtext; |
| 2751 | | for (cheat_entry *curcheat = machine.cheat().first(); curcheat != NULL; curcheat = curcheat->next()) |
| 2752 | | { |
| 2753 | | UINT32 flags; |
| 2754 | | curcheat->menu_text(text, subtext, flags); |
| 2755 | | ui_menu_item_append(menu, text, subtext, flags, curcheat); |
| 2756 | | } |
| 2757 | | |
| 2758 | | /* add a separator */ |
| 2759 | | ui_menu_item_append(menu, MENU_SEPARATOR_ITEM, NULL, 0, NULL); |
| 2760 | | |
| 2761 | | /* add a reset all option */ |
| 2762 | | ui_menu_item_append(menu, "Reset All", NULL, 0, (void *)1); |
| 2763 | | |
| 2764 | | /* add a reload all cheats option */ |
| 2765 | | ui_menu_item_append(menu, "Reload All", NULL, 0, (void *)2); |
| 2766 | | } |
| 2767 | | |
| 2768 | | |
| 2769 | | /*------------------------------------------------- |
| 2770 | | menu_memory_card - handle the memory card |
| 2771 | | menu |
| 2772 | | -------------------------------------------------*/ |
| 2773 | | |
| 2774 | | static void menu_memory_card(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2775 | | { |
| 2776 | | const ui_menu_event *menu_event; |
| 2777 | | int *cardnum; |
| 2778 | | |
| 2779 | | /* if no state, allocate some */ |
| 2780 | | if (state == NULL) |
| 2781 | | state = ui_menu_alloc_state(menu, sizeof(*cardnum), NULL); |
| 2782 | | cardnum = (int *)state; |
| 2783 | | |
| 2784 | | /* if the menu isn't built, populate now */ |
| 2785 | | if (!ui_menu_populated(menu)) |
| 2786 | | menu_memory_card_populate(machine, menu, *cardnum); |
| 2787 | | |
| 2788 | | /* process the menu */ |
| 2789 | | menu_event = ui_menu_process(machine, menu, UI_MENU_PROCESS_LR_REPEAT); |
| 2790 | | |
| 2791 | | /* if something was selected, act on it */ |
| 2792 | | if (menu_event != NULL && menu_event->itemref != NULL) |
| 2793 | | { |
| 2794 | | FPTR item = (FPTR)menu_event->itemref; |
| 2795 | | |
| 2796 | | /* select executes actions on some of the items */ |
| 2797 | | if (menu_event->iptkey == IPT_UI_SELECT) |
| 2798 | | { |
| 2799 | | switch (item) |
| 2800 | | { |
| 2801 | | /* handle card loading; if we succeed, clear the menus */ |
| 2802 | | case MEMCARD_ITEM_LOAD: |
| 2803 | | if (memcard_insert(menu->machine(), *cardnum) == 0) |
| 2804 | | { |
| 2805 | | popmessage("Memory card loaded"); |
| 2806 | | ui_menu_stack_reset(menu->machine()); |
| 2807 | | } |
| 2808 | | else |
| 2809 | | popmessage("Error loading memory card"); |
| 2810 | | break; |
| 2811 | | |
| 2812 | | /* handle card ejecting */ |
| 2813 | | case MEMCARD_ITEM_EJECT: |
| 2814 | | memcard_eject(menu->machine()); |
| 2815 | | popmessage("Memory card ejected"); |
| 2816 | | break; |
| 2817 | | |
| 2818 | | /* handle card creating */ |
| 2819 | | case MEMCARD_ITEM_CREATE: |
| 2820 | | if (memcard_create(menu->machine(), *cardnum, FALSE) == 0) |
| 2821 | | popmessage("Memory card created"); |
| 2822 | | else |
| 2823 | | popmessage("Error creating memory card\n(Card may already exist)"); |
| 2824 | | break; |
| 2825 | | } |
| 2826 | | } |
| 2827 | | |
| 2828 | | /* the select item has extra keys */ |
| 2829 | | else if (item == MEMCARD_ITEM_SELECT) |
| 2830 | | { |
| 2831 | | switch (menu_event->iptkey) |
| 2832 | | { |
| 2833 | | /* left decrements the card number */ |
| 2834 | | case IPT_UI_LEFT: |
| 2835 | | *cardnum -= 1; |
| 2836 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF); |
| 2837 | | break; |
| 2838 | | |
| 2839 | | /* right decrements the card number */ |
| 2840 | | case IPT_UI_RIGHT: |
| 2841 | | *cardnum += 1; |
| 2842 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF); |
| 2843 | | break; |
| 2844 | | } |
| 2845 | | } |
| 2846 | | } |
| 2847 | | } |
| 2848 | | |
| 2849 | | |
| 2850 | | /*------------------------------------------------- |
| 2851 | | menu_memory_card_populate - populate the |
| 2852 | | memory card menu |
| 2853 | | -------------------------------------------------*/ |
| 2854 | | |
| 2855 | | static void menu_memory_card_populate(running_machine &machine, ui_menu *menu, int cardnum) |
| 2856 | | { |
| 2857 | | char tempstring[20]; |
| 2858 | | UINT32 flags = 0; |
| 2859 | | |
| 2860 | | /* add the card select menu */ |
| 2861 | | sprintf(tempstring, "%d", cardnum); |
| 2862 | | if (cardnum > 0) |
| 2863 | | flags |= MENU_FLAG_LEFT_ARROW; |
| 2864 | | if (cardnum < 1000) |
| 2865 | | flags |= MENU_FLAG_RIGHT_ARROW; |
| 2866 | | ui_menu_item_append(menu, "Card Number:", tempstring, flags, (void *)MEMCARD_ITEM_SELECT); |
| 2867 | | |
| 2868 | | /* add the remaining items */ |
| 2869 | | ui_menu_item_append(menu, "Load Selected Card", NULL, 0, (void *)MEMCARD_ITEM_LOAD); |
| 2870 | | if (memcard_present(machine) != -1) |
| 2871 | | ui_menu_item_append(menu, "Eject Current Card", NULL, 0, (void *)MEMCARD_ITEM_EJECT); |
| 2872 | | ui_menu_item_append(menu, "Create New Card", NULL, 0, (void *)MEMCARD_ITEM_CREATE); |
| 2873 | | } |
| 2874 | | |
| 2875 | | |
| 2876 | | /*------------------------------------------------- |
| 2877 | | menu_sliders - handle the sliders menu |
| 2878 | | -------------------------------------------------*/ |
| 2879 | | |
| 2880 | | static void menu_sliders(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2881 | | { |
| 2882 | | int menuless_mode = (parameter != NULL); |
| 2883 | | const ui_menu_event *menu_event; |
| 2884 | | UINT8 *hidden = (UINT8 *)state; |
| 2885 | | |
| 2886 | | /* if no state, allocate some */ |
| 2887 | | if (hidden == NULL) |
| 2888 | | hidden = (UINT8 *)ui_menu_alloc_state(menu, sizeof(*hidden), NULL); |
| 2889 | | if (menuless_mode) |
| 2890 | | *hidden = TRUE; |
| 2891 | | |
| 2892 | | /* if the menu isn't built, populate now */ |
| 2893 | | if (!ui_menu_populated(menu)) |
| 2894 | | menu_sliders_populate(machine, menu, menuless_mode); |
| 2895 | | |
| 2896 | | /* process the menu */ |
| 2897 | | menu_event = ui_menu_process(machine, menu, UI_MENU_PROCESS_LR_REPEAT | (*hidden ? UI_MENU_PROCESS_CUSTOM_ONLY : 0)); |
| 2898 | | if (menu_event != NULL) |
| 2899 | | { |
| 2900 | | /* handle keys if there is a valid item selected */ |
| 2901 | | if (menu_event->itemref != NULL) |
| 2902 | | { |
| 2903 | | const slider_state *slider = (const slider_state *)menu_event->itemref; |
| 2904 | | INT32 curvalue = (*slider->update)(machine, slider->arg, NULL, SLIDER_NOCHANGE); |
| 2905 | | INT32 increment = 0; |
| 2906 | | |
| 2907 | | switch (menu_event->iptkey) |
| 2908 | | { |
| 2909 | | /* toggle visibility */ |
| 2910 | | case IPT_UI_ON_SCREEN_DISPLAY: |
| 2911 | | if (menuless_mode) |
| 2912 | | ui_menu_stack_pop(machine); |
| 2913 | | else |
| 2914 | | *hidden = !*hidden; |
| 2915 | | break; |
| 2916 | | |
| 2917 | | /* decrease value */ |
| 2918 | | case IPT_UI_LEFT: |
| 2919 | | if (machine.input().code_pressed(KEYCODE_LALT) || machine.input().code_pressed(KEYCODE_RALT)) |
| 2920 | | increment = -1; |
| 2921 | | else if (machine.input().code_pressed(KEYCODE_LSHIFT) || machine.input().code_pressed(KEYCODE_RSHIFT)) |
| 2922 | | increment = (slider->incval > 10) ? -(slider->incval / 10) : -1; |
| 2923 | | else if (machine.input().code_pressed(KEYCODE_LCONTROL) || machine.input().code_pressed(KEYCODE_RCONTROL)) |
| 2924 | | increment = -slider->incval * 10; |
| 2925 | | else |
| 2926 | | increment = -slider->incval; |
| 2927 | | break; |
| 2928 | | |
| 2929 | | /* increase value */ |
| 2930 | | case IPT_UI_RIGHT: |
| 2931 | | if (machine.input().code_pressed(KEYCODE_LALT) || machine.input().code_pressed(KEYCODE_RALT)) |
| 2932 | | increment = 1; |
| 2933 | | else if (machine.input().code_pressed(KEYCODE_LSHIFT) || machine.input().code_pressed(KEYCODE_RSHIFT)) |
| 2934 | | increment = (slider->incval > 10) ? (slider->incval / 10) : 1; |
| 2935 | | else if (machine.input().code_pressed(KEYCODE_LCONTROL) || machine.input().code_pressed(KEYCODE_RCONTROL)) |
| 2936 | | increment = slider->incval * 10; |
| 2937 | | else |
| 2938 | | increment = slider->incval; |
| 2939 | | break; |
| 2940 | | |
| 2941 | | /* restore default */ |
| 2942 | | case IPT_UI_SELECT: |
| 2943 | | increment = slider->defval - curvalue; |
| 2944 | | break; |
| 2945 | | } |
| 2946 | | |
| 2947 | | /* handle any changes */ |
| 2948 | | if (increment != 0) |
| 2949 | | { |
| 2950 | | INT32 newvalue = curvalue + increment; |
| 2951 | | |
| 2952 | | /* clamp within bounds */ |
| 2953 | | if (newvalue < slider->minval) |
| 2954 | | newvalue = slider->minval; |
| 2955 | | if (newvalue > slider->maxval) |
| 2956 | | newvalue = slider->maxval; |
| 2957 | | |
| 2958 | | /* update the slider and recompute the menu */ |
| 2959 | | (*slider->update)(machine, slider->arg, NULL, newvalue); |
| 2960 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF); |
| 2961 | | } |
| 2962 | | } |
| 2963 | | |
| 2964 | | /* if we are selecting an invalid item and we are hidden, skip to the next one */ |
| 2965 | | else if (*hidden) |
| 2966 | | { |
| 2967 | | /* if we got here via up or page up, select the previous item */ |
| 2968 | | if (menu_event->iptkey == IPT_UI_UP || menu_event->iptkey == IPT_UI_PAGE_UP) |
| 2969 | | { |
| 2970 | | menu->selected = (menu->selected + menu->numitems - 1) % menu->numitems; |
| 2971 | | ui_menu_validate_selection(menu, -1); |
| 2972 | | } |
| 2973 | | |
| 2974 | | /* otherwise select the next item */ |
| 2975 | | else if (menu_event->iptkey == IPT_UI_DOWN || menu_event->iptkey == IPT_UI_PAGE_DOWN) |
| 2976 | | { |
| 2977 | | menu->selected = (menu->selected + 1) % menu->numitems; |
| 2978 | | ui_menu_validate_selection(menu, 1); |
| 2979 | | } |
| 2980 | | } |
| 2981 | | } |
| 2982 | | } |
| 2983 | | |
| 2984 | | |
| 2985 | | /*------------------------------------------------- |
| 2986 | | menu_sliders_populate - populate the sliders |
| 2987 | | menu |
| 2988 | | -------------------------------------------------*/ |
| 2989 | | |
| 2990 | | static void menu_sliders_populate(running_machine &machine, ui_menu *menu, int menuless_mode) |
| 2991 | | { |
| 2992 | | const slider_state *curslider; |
| 2993 | | astring tempstring; |
| 2994 | | |
| 2995 | | /* add all sliders */ |
| 2996 | | for (curslider = ui_get_slider_list(); curslider != NULL; curslider = curslider->next) |
| 2997 | | { |
| 2998 | | INT32 curval = (*curslider->update)(machine, curslider->arg, &tempstring, SLIDER_NOCHANGE); |
| 2999 | | UINT32 flags = 0; |
| 3000 | | if (curval > curslider->minval) |
| 3001 | | flags |= MENU_FLAG_LEFT_ARROW; |
| 3002 | | if (curval < curslider->maxval) |
| 3003 | | flags |= MENU_FLAG_RIGHT_ARROW; |
| 3004 | | ui_menu_item_append(menu, curslider->description, tempstring, flags, (void *)curslider); |
| 3005 | | |
| 3006 | | if (menuless_mode) |
| 3007 | | break; |
| 3008 | | } |
| 3009 | | |
| 3010 | | /* add all sliders */ |
| 3011 | | for (curslider = (slider_state*)machine.osd().get_slider_list(); curslider != NULL; curslider = curslider->next) |
| 3012 | | { |
| 3013 | | INT32 curval = (*curslider->update)(machine, curslider->arg, &tempstring, SLIDER_NOCHANGE); |
| 3014 | | UINT32 flags = 0; |
| 3015 | | if (curval > curslider->minval) |
| 3016 | | flags |= MENU_FLAG_LEFT_ARROW; |
| 3017 | | if (curval < curslider->maxval) |
| 3018 | | flags |= MENU_FLAG_RIGHT_ARROW; |
| 3019 | | ui_menu_item_append(menu, curslider->description, tempstring, flags, (void *)curslider); |
| 3020 | | } |
| 3021 | | |
| 3022 | | ui_menu_set_custom_render(menu, menu_sliders_custom_render, 0.0f, 2.0f * ui_get_line_height(machine) + 2.0f * UI_BOX_TB_BORDER); |
| 3023 | | } |
| 3024 | | |
| 3025 | | |
| 3026 | | /*------------------------------------------------- |
| 3027 | | menu_sliders_custom_render - perform our special |
| 3028 | | rendering |
| 3029 | | -------------------------------------------------*/ |
| 3030 | | |
| 3031 | | static 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) |
| 3032 | | { |
| 3033 | | const slider_state *curslider = (const slider_state *)selectedref; |
| 3034 | | if (curslider != NULL) |
| 3035 | | { |
| 3036 | | float bar_left, bar_area_top, bar_width, bar_area_height, bar_top, bar_bottom, default_x, current_x; |
| 3037 | | float line_height = ui_get_line_height(machine); |
| 3038 | | float percentage, default_percentage; |
| 3039 | | astring tempstring; |
| 3040 | | float text_height; |
| 3041 | | INT32 curval; |
| 3042 | | |
| 3043 | | /* determine the current value and text */ |
| 3044 | | curval = (*curslider->update)(machine, curslider->arg, &tempstring, SLIDER_NOCHANGE); |
| 3045 | | |
| 3046 | | /* compute the current and default percentages */ |
| 3047 | | percentage = (float)(curval - curslider->minval) / (float)(curslider->maxval - curslider->minval); |
| 3048 | | default_percentage = (float)(curslider->defval - curslider->minval) / (float)(curslider->maxval - curslider->minval); |
| 3049 | | |
| 3050 | | /* assemble the the text */ |
| 3051 | | tempstring.ins(0, " ").ins(0, curslider->description); |
| 3052 | | |
| 3053 | | /* move us to the bottom of the screen, and expand to full width */ |
| 3054 | | y2 = 1.0f - UI_BOX_TB_BORDER; |
| 3055 | | y1 = y2 - bottom; |
| 3056 | | x1 = UI_BOX_LR_BORDER; |
| 3057 | | x2 = 1.0f - UI_BOX_LR_BORDER; |
| 3058 | | |
| 3059 | | /* draw extra menu area */ |
| 3060 | | ui_draw_outlined_box(menu->container, x1, y1, x2, y2, UI_BACKGROUND_COLOR); |
| 3061 | | y1 += UI_BOX_TB_BORDER; |
| 3062 | | |
| 3063 | | /* determine the text height */ |
| 3064 | | ui_draw_text_full(menu->container, tempstring, 0, 0, x2 - x1 - 2.0f * UI_BOX_LR_BORDER, |
| 3065 | | JUSTIFY_CENTER, WRAP_TRUNCATE, DRAW_NONE, ARGB_WHITE, ARGB_BLACK, NULL, &text_height); |
| 3066 | | |
| 3067 | | /* draw the thermometer */ |
| 3068 | | bar_left = x1 + UI_BOX_LR_BORDER; |
| 3069 | | bar_area_top = y1; |
| 3070 | | bar_width = x2 - x1 - 2.0f * UI_BOX_LR_BORDER; |
| 3071 | | bar_area_height = line_height; |
| 3072 | | |
| 3073 | | /* compute positions */ |
| 3074 | | bar_top = bar_area_top + 0.125f * bar_area_height; |
| 3075 | | bar_bottom = bar_area_top + 0.875f * bar_area_height; |
| 3076 | | default_x = bar_left + bar_width * default_percentage; |
| 3077 | | current_x = bar_left + bar_width * percentage; |
| 3078 | | |
| 3079 | | /* fill in the percentage */ |
| 3080 | | menu->container->add_rect(bar_left, bar_top, current_x, bar_bottom, UI_SLIDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 3081 | | |
| 3082 | | /* draw the top and bottom lines */ |
| 3083 | | menu->container->add_line(bar_left, bar_top, bar_left + bar_width, bar_top, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 3084 | | menu->container->add_line(bar_left, bar_bottom, bar_left + bar_width, bar_bottom, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 3085 | | |
| 3086 | | /* draw default marker */ |
| 3087 | | menu->container->add_line(default_x, bar_area_top, default_x, bar_top, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 3088 | | menu->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)); |
| 3089 | | |
| 3090 | | /* draw the actual text */ |
| 3091 | | ui_draw_text_full(menu->container, tempstring, x1 + UI_BOX_LR_BORDER, y1 + line_height, x2 - x1 - 2.0f * UI_BOX_LR_BORDER, |
| 3092 | | JUSTIFY_CENTER, WRAP_WORD, DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, NULL, &text_height); |
| 3093 | | } |
| 3094 | | } |
| 3095 | | |
| 3096 | | |
| 3097 | | /*------------------------------------------------- |
| 3098 | | menu_video_targets - handle the video targets |
| 3099 | | menu |
| 3100 | | -------------------------------------------------*/ |
| 3101 | | |
| 3102 | | static void menu_video_targets(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 3103 | | { |
| 3104 | | const ui_menu_event *menu_event; |
| 3105 | | |
| 3106 | | /* if the menu isn't built, populate now */ |
| 3107 | | if (!ui_menu_populated(menu)) |
| 3108 | | menu_video_targets_populate(machine, menu); |
| 3109 | | |
| 3110 | | /* process the menu */ |
| 3111 | | menu_event = ui_menu_process(machine, menu, 0); |
| 3112 | | if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT) |
| 3113 | | ui_menu_stack_push(ui_menu_alloc(machine, menu->container, menu_video_options, menu_event->itemref)); |
| 3114 | | } |
| 3115 | | |
| 3116 | | |
| 3117 | | /*------------------------------------------------- |
| 3118 | | menu_video_targets_populate - populate the |
| 3119 | | video targets menu |
| 3120 | | -------------------------------------------------*/ |
| 3121 | | |
| 3122 | | static void menu_video_targets_populate(running_machine &machine, ui_menu *menu) |
| 3123 | | { |
| 3124 | | int targetnum; |
| 3125 | | |
| 3126 | | /* find the targets */ |
| 3127 | | for (targetnum = 0; ; targetnum++) |
| 3128 | | { |
| 3129 | | render_target *target = machine.render().target_by_index(targetnum); |
| 3130 | | char buffer[40]; |
| 3131 | | |
| 3132 | | /* stop when we run out */ |
| 3133 | | if (target == NULL) |
| 3134 | | break; |
| 3135 | | |
| 3136 | | /* add a menu item */ |
| 3137 | | sprintf(buffer, "Screen #%d", targetnum); |
| 3138 | | ui_menu_item_append(menu, buffer, NULL, 0, target); |
| 3139 | | } |
| 3140 | | } |
| 3141 | | |
| 3142 | | |
| 3143 | | /*------------------------------------------------- |
| 3144 | | menu_video_options - handle the video options |
| 3145 | | menu |
| 3146 | | -------------------------------------------------*/ |
| 3147 | | |
| 3148 | | static void menu_video_options(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 3149 | | { |
| 3150 | | render_target *target = (parameter != NULL) ? (render_target *)parameter : machine.render().first_target(); |
| 3151 | | const ui_menu_event *menu_event; |
| 3152 | | int changed = FALSE; |
| 3153 | | |
| 3154 | | /* if the menu isn't built, populate now */ |
| 3155 | | if (!ui_menu_populated(menu)) |
| 3156 | | menu_video_options_populate(machine, menu, target); |
| 3157 | | |
| 3158 | | /* process the menu */ |
| 3159 | | menu_event = ui_menu_process(machine, menu, 0); |
| 3160 | | if (menu_event != NULL && menu_event->itemref != NULL) |
| 3161 | | { |
| 3162 | | switch ((FPTR)menu_event->itemref) |
| 3163 | | { |
| 3164 | | /* rotate adds rotation depending on the direction */ |
| 3165 | | case VIDEO_ITEM_ROTATE: |
| 3166 | | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 3167 | | { |
| 3168 | | int delta = (menu_event->iptkey == IPT_UI_LEFT) ? ROT270 : ROT90; |
| 3169 | | target->set_orientation(orientation_add(delta, target->orientation())); |
| 3170 | | if (target->is_ui_target()) |
| 3171 | | { |
| 3172 | | render_container::user_settings settings; |
| 3173 | | menu->container->get_user_settings(settings); |
| 3174 | | settings.m_orientation = orientation_add(delta ^ ROT180, settings.m_orientation); |
| 3175 | | menu->container->set_user_settings(settings); |
| 3176 | | } |
| 3177 | | changed = TRUE; |
| 3178 | | } |
| 3179 | | break; |
| 3180 | | |
| 3181 | | /* layer config bitmasks handle left/right keys the same (toggle) */ |
| 3182 | | case VIDEO_ITEM_BACKDROPS: |
| 3183 | | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 3184 | | { |
| 3185 | | target->set_backdrops_enabled(!target->backdrops_enabled()); |
| 3186 | | changed = TRUE; |
| 3187 | | } |
| 3188 | | break; |
| 3189 | | |
| 3190 | | case VIDEO_ITEM_OVERLAYS: |
| 3191 | | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 3192 | | { |
| 3193 | | target->set_overlays_enabled(!target->overlays_enabled()); |
| 3194 | | changed = TRUE; |
| 3195 | | } |
| 3196 | | break; |
| 3197 | | |
| 3198 | | case VIDEO_ITEM_BEZELS: |
| 3199 | | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 3200 | | { |
| 3201 | | target->set_bezels_enabled(!target->bezels_enabled()); |
| 3202 | | changed = TRUE; |
| 3203 | | } |
| 3204 | | break; |
| 3205 | | |
| 3206 | | case VIDEO_ITEM_CPANELS: |
| 3207 | | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 3208 | | { |
| 3209 | | target->set_cpanels_enabled(!target->cpanels_enabled()); |
| 3210 | | changed = TRUE; |
| 3211 | | } |
| 3212 | | break; |
| 3213 | | |
| 3214 | | case VIDEO_ITEM_MARQUEES: |
| 3215 | | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 3216 | | { |
| 3217 | | target->set_marquees_enabled(!target->marquees_enabled()); |
| 3218 | | changed = TRUE; |
| 3219 | | } |
| 3220 | | break; |
| 3221 | | |
| 3222 | | case VIDEO_ITEM_ZOOM: |
| 3223 | | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 3224 | | { |
| 3225 | | target->set_zoom_to_screen(!target->zoom_to_screen()); |
| 3226 | | changed = TRUE; |
| 3227 | | } |
| 3228 | | break; |
| 3229 | | |
| 3230 | | /* anything else is a view item */ |
| 3231 | | default: |
| 3232 | | if (menu_event->iptkey == IPT_UI_SELECT && (int)(FPTR)menu_event->itemref >= VIDEO_ITEM_VIEW) |
| 3233 | | { |
| 3234 | | target->set_view((FPTR)menu_event->itemref - VIDEO_ITEM_VIEW); |
| 3235 | | changed = TRUE; |
| 3236 | | } |
| 3237 | | break; |
| 3238 | | } |
| 3239 | | } |
| 3240 | | |
| 3241 | | /* if something changed, rebuild the menu */ |
| 3242 | | if (changed) |
| 3243 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF); |
| 3244 | | } |
| 3245 | | |
| 3246 | | |
| 3247 | | /*------------------------------------------------- |
| 3248 | | menu_video_options_populate - populate the |
| 3249 | | video options menu |
| 3250 | | -------------------------------------------------*/ |
| 3251 | | |
| 3252 | | static void menu_video_options_populate(running_machine &machine, ui_menu *menu, render_target *target) |
| 3253 | | { |
| 3254 | | const char *subtext = ""; |
| 3255 | | astring tempstring; |
| 3256 | | int viewnum; |
| 3257 | | int enabled; |
| 3258 | | |
| 3259 | | /* add items for each view */ |
| 3260 | | for (viewnum = 0; ; viewnum++) |
| 3261 | | { |
| 3262 | | const char *name = target->view_name(viewnum); |
| 3263 | | if (name == NULL) |
| 3264 | | break; |
| 3265 | | |
| 3266 | | /* create a string for the item, replacing underscores with spaces */ |
| 3267 | | tempstring.cpy(name).replace(0, "_", " "); |
| 3268 | | ui_menu_item_append(menu, tempstring, NULL, 0, (void *)(FPTR)(VIDEO_ITEM_VIEW + viewnum)); |
| 3269 | | } |
| 3270 | | |
| 3271 | | /* add a separator */ |
| 3272 | | ui_menu_item_append(menu, MENU_SEPARATOR_ITEM, NULL, 0, NULL); |
| 3273 | | |
| 3274 | | /* add a rotate item */ |
| 3275 | | switch (target->orientation()) |
| 3276 | | { |
| 3277 | | case ROT0: subtext = "None"; break; |
| 3278 | | case ROT90: subtext = "CW 90" UTF8_DEGREES; break; |
| 3279 | | case ROT180: subtext = "180" UTF8_DEGREES; break; |
| 3280 | | case ROT270: subtext = "CCW 90" UTF8_DEGREES; break; |
| 3281 | | } |
| 3282 | | ui_menu_item_append(menu, "Rotate", subtext, MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_ROTATE); |
| 3283 | | |
| 3284 | | /* backdrop item */ |
| 3285 | | enabled = target->backdrops_enabled(); |
| 3286 | | ui_menu_item_append(menu, "Backdrops", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_BACKDROPS); |
| 3287 | | |
| 3288 | | /* overlay item */ |
| 3289 | | enabled = target->overlays_enabled(); |
| 3290 | | ui_menu_item_append(menu, "Overlays", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_OVERLAYS); |
| 3291 | | |
| 3292 | | /* bezel item */ |
| 3293 | | enabled = target->bezels_enabled(); |
| 3294 | | ui_menu_item_append(menu, "Bezels", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_BEZELS); |
| 3295 | | |
| 3296 | | /* cpanel item */ |
| 3297 | | enabled = target->cpanels_enabled(); |
| 3298 | | ui_menu_item_append(menu, "CPanels", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_CPANELS); |
| 3299 | | |
| 3300 | | /* marquee item */ |
| 3301 | | enabled = target->marquees_enabled(); |
| 3302 | | ui_menu_item_append(menu, "Marquees", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_MARQUEES); |
| 3303 | | |
| 3304 | | /* cropping */ |
| 3305 | | enabled = target->zoom_to_screen(); |
| 3306 | | ui_menu_item_append(menu, "View", enabled ? "Cropped" : "Full", enabled ? MENU_FLAG_RIGHT_ARROW : MENU_FLAG_LEFT_ARROW, (void *)VIDEO_ITEM_ZOOM); |
| 3307 | | } |
| 3308 | | |
| 3309 | | |
| 3310 | | /*------------------------------------------------- |
| 3311 | | menu_crosshair - handle the crosshair settings |
| 3312 | | menu |
| 3313 | | -------------------------------------------------*/ |
| 3314 | | |
| 3315 | | static void menu_crosshair(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 3316 | | { |
| 3317 | | const ui_menu_event *menu_event; |
| 3318 | | |
| 3319 | | /* if the menu isn't built, populate now */ |
| 3320 | | if (!ui_menu_populated(menu)) |
| 3321 | | menu_crosshair_populate(machine, menu); |
| 3322 | | |
| 3323 | | /* process the menu */ |
| 3324 | | menu_event = ui_menu_process(machine, menu, UI_MENU_PROCESS_LR_REPEAT); |
| 3325 | | |
| 3326 | | /* handle events */ |
| 3327 | | if (menu_event != NULL && menu_event->itemref != NULL) |
| 3328 | | { |
| 3329 | | crosshair_user_settings settings; |
| 3330 | | crosshair_item_data *data = (crosshair_item_data *)menu_event->itemref; |
| 3331 | | int changed = FALSE; |
| 3332 | | //int set_def = FALSE; |
| 3333 | | int newval = data->cur; |
| 3334 | | |
| 3335 | | /* retreive the user settings */ |
| 3336 | | crosshair_get_user_settings(machine, data->player, &settings); |
| 3337 | | |
| 3338 | | switch (menu_event->iptkey) |
| 3339 | | { |
| 3340 | | /* if selected, reset to default value */ |
| 3341 | | case IPT_UI_SELECT: |
| 3342 | | newval = data->defvalue; |
| 3343 | | //set_def = TRUE; |
| 3344 | | break; |
| 3345 | | |
| 3346 | | /* left decrements */ |
| 3347 | | case IPT_UI_LEFT: |
| 3348 | | newval -= machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1; |
| 3349 | | break; |
| 3350 | | |
| 3351 | | /* right increments */ |
| 3352 | | case IPT_UI_RIGHT: |
| 3353 | | newval += machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1; |
| 3354 | | break; |
| 3355 | | } |
| 3356 | | |
| 3357 | | /* clamp to range */ |
| 3358 | | if (newval < data->min) |
| 3359 | | newval = data->min; |
| 3360 | | if (newval > data->max) |
| 3361 | | newval = data->max; |
| 3362 | | |
| 3363 | | /* if things changed, update */ |
| 3364 | | if (newval != data->cur) |
| 3365 | | { |
| 3366 | | switch (data->type) |
| 3367 | | { |
| 3368 | | /* visibility state */ |
| 3369 | | case CROSSHAIR_ITEM_VIS: |
| 3370 | | settings.mode = newval; |
| 3371 | | changed = TRUE; |
| 3372 | | break; |
| 3373 | | |
| 3374 | | /* auto time */ |
| 3375 | | case CROSSHAIR_ITEM_AUTO_TIME: |
| 3376 | | settings.auto_time = newval; |
| 3377 | | changed = TRUE; |
| 3378 | | break; |
| 3379 | | } |
| 3380 | | } |
| 3381 | | |
| 3382 | | /* crosshair graphic name */ |
| 3383 | | if (data->type == CROSSHAIR_ITEM_PIC) |
| 3384 | | { |
| 3385 | | if (menu_event->iptkey == IPT_UI_SELECT) |
| 3386 | | { |
| 3387 | | /* clear the name string to reset to default crosshair */ |
| 3388 | | settings.name[0] = 0; |
| 3389 | | changed = TRUE; |
| 3390 | | } |
| 3391 | | else if (menu_event->iptkey == IPT_UI_LEFT) |
| 3392 | | { |
| 3393 | | strcpy(settings.name, data->last_name); |
| 3394 | | changed = TRUE; |
| 3395 | | } |
| 3396 | | else if (menu_event->iptkey == IPT_UI_RIGHT) |
| 3397 | | { |
| 3398 | | strcpy(settings.name, data->next_name); |
| 3399 | | changed = TRUE; |
| 3400 | | } |
| 3401 | | } |
| 3402 | | |
| 3403 | | if (changed) |
| 3404 | | { |
| 3405 | | /* save the user settings */ |
| 3406 | | crosshair_set_user_settings(machine, data->player, &settings); |
| 3407 | | |
| 3408 | | /* rebuild the menu */ |
| 3409 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_POSITION); |
| 3410 | | } |
| 3411 | | } |
| 3412 | | } |
| 3413 | | |
| 3414 | | |
| 3415 | | /*------------------------------------------------- |
| 3416 | | menu_crosshair_populate - populate the |
| 3417 | | crosshair settings menu |
| 3418 | | -------------------------------------------------*/ |
| 3419 | | |
| 3420 | | static void menu_crosshair_populate(running_machine &machine, ui_menu *menu) |
| 3421 | | { |
| 3422 | | crosshair_user_settings settings; |
| 3423 | | crosshair_item_data *data; |
| 3424 | | char temp_text[16]; |
| 3425 | | int player; |
| 3426 | | UINT8 use_auto = FALSE; |
| 3427 | | UINT32 flags = 0; |
| 3428 | | |
| 3429 | | /* loop over player and add the manual items */ |
| 3430 | | for (player = 0; player < MAX_PLAYERS; player++) |
| 3431 | | { |
| 3432 | | /* get the user settings */ |
| 3433 | | crosshair_get_user_settings(machine, player, &settings); |
| 3434 | | |
| 3435 | | /* add menu items for usable crosshairs */ |
| 3436 | | if (settings.used) |
| 3437 | | { |
| 3438 | | /* Make sure to keep these matched to the CROSSHAIR_VISIBILITY_xxx types */ |
| 3439 | | static const char *const vis_text[] = { "Off", "On", "Auto" }; |
| 3440 | | |
| 3441 | | /* track if we need the auto time menu */ |
| 3442 | | if (settings.mode == CROSSHAIR_VISIBILITY_AUTO) use_auto = TRUE; |
| 3443 | | |
| 3444 | | /* CROSSHAIR_ITEM_VIS - allocate a data item and fill it */ |
| 3445 | | data = (crosshair_item_data *)ui_menu_pool_alloc(menu, sizeof(*data)); |
| 3446 | | data->type = CROSSHAIR_ITEM_VIS; |
| 3447 | | data->player = player; |
| 3448 | | data->min = CROSSHAIR_VISIBILITY_OFF; |
| 3449 | | data->max = CROSSHAIR_VISIBILITY_AUTO; |
| 3450 | | data->defvalue = CROSSHAIR_VISIBILITY_DEFAULT; |
| 3451 | | data->cur = settings.mode; |
| 3452 | | |
| 3453 | | /* put on arrows */ |
| 3454 | | if (data->cur > data->min) |
| 3455 | | flags |= MENU_FLAG_LEFT_ARROW; |
| 3456 | | if (data->cur < data->max) |
| 3457 | | flags |= MENU_FLAG_RIGHT_ARROW; |
| 3458 | | |
| 3459 | | /* add CROSSHAIR_ITEM_VIS menu */ |
| 3460 | | sprintf(temp_text, "P%d Visibility", player + 1); |
| 3461 | | ui_menu_item_append(menu, temp_text, vis_text[settings.mode], flags, data); |
| 3462 | | |
| 3463 | | /* CROSSHAIR_ITEM_PIC - allocate a data item and fill it */ |
| 3464 | | data = (crosshair_item_data *)ui_menu_pool_alloc(menu, sizeof(*data)); |
| 3465 | | data->type = CROSSHAIR_ITEM_PIC; |
| 3466 | | data->player = player; |
| 3467 | | data->last_name[0] = 0; |
| 3468 | | /* other data item not used by this menu */ |
| 3469 | | |
| 3470 | | /* search for crosshair graphics */ |
| 3471 | | |
| 3472 | | /* open a path to the crosshairs */ |
| 3473 | | file_enumerator path(machine.options().crosshair_path()); |
| 3474 | | const osd_directory_entry *dir; |
| 3475 | | /* reset search flags */ |
| 3476 | | int using_default = FALSE; |
| 3477 | | int finished = FALSE; |
| 3478 | | int found = FALSE; |
| 3479 | | |
| 3480 | | /* if we are using the default, then we just need to find the first in the list */ |
| 3481 | | if (strlen(settings.name) == 0) |
| 3482 | | using_default = TRUE; |
| 3483 | | |
| 3484 | | /* look for the current name, then remember the name before */ |
| 3485 | | /* and find the next name */ |
| 3486 | | while (((dir = path.next()) != NULL) && !finished) |
| 3487 | | { |
| 3488 | | int length = strlen(dir->name); |
| 3489 | | |
| 3490 | | /* look for files ending in .png with a name not larger then 9 chars*/ |
| 3491 | | if ((length > 4) && (length <= CROSSHAIR_PIC_NAME_LENGTH + 4) && |
| 3492 | | dir->name[length - 4] == '.' && |
| 3493 | | tolower((UINT8)dir->name[length - 3]) == 'p' && |
| 3494 | | tolower((UINT8)dir->name[length - 2]) == 'n' && |
| 3495 | | tolower((UINT8)dir->name[length - 1]) == 'g') |
| 3496 | | |
| 3497 | | { |
| 3498 | | /* remove .png from length */ |
| 3499 | | length -= 4; |
| 3500 | | |
| 3501 | | if (found || using_default) |
| 3502 | | { |
| 3503 | | /* get the next name */ |
| 3504 | | strncpy(data->next_name, dir->name, length); |
| 3505 | | data->next_name[length] = 0; |
| 3506 | | finished = TRUE; |
| 3507 | | } |
| 3508 | | else if (!strncmp(dir->name, settings.name, length)) |
| 3509 | | { |
| 3510 | | /* we found the current name */ |
| 3511 | | /* so loop once more to find the next name */ |
| 3512 | | found = TRUE; |
| 3513 | | } |
| 3514 | | else |
| 3515 | | /* remember last name */ |
| 3516 | | /* we will do it here in case files get added to the directory */ |
| 3517 | | { |
| 3518 | | strncpy(data->last_name, dir->name, length); |
| 3519 | | data->last_name[length] = 0; |
| 3520 | | } |
| 3521 | | } |
| 3522 | | } |
| 3523 | | /* if name not found then next item is DEFAULT */ |
| 3524 | | if (!found && !using_default) |
| 3525 | | { |
| 3526 | | data->next_name[0] = 0; |
| 3527 | | finished = TRUE; |
| 3528 | | } |
| 3529 | | /* setup the selection flags */ |
| 3530 | | flags = 0; |
| 3531 | | if (finished) |
| 3532 | | flags |= MENU_FLAG_RIGHT_ARROW; |
| 3533 | | if (found) |
| 3534 | | flags |= MENU_FLAG_LEFT_ARROW; |
| 3535 | | |
| 3536 | | /* add CROSSHAIR_ITEM_PIC menu */ |
| 3537 | | sprintf(temp_text, "P%d Crosshair", player + 1); |
| 3538 | | ui_menu_item_append(menu, temp_text, using_default ? "DEFAULT" : settings.name, flags, data); |
| 3539 | | } |
| 3540 | | } |
| 3541 | | if (use_auto) |
| 3542 | | { |
| 3543 | | /* any player can be used to get the autotime */ |
| 3544 | | crosshair_get_user_settings(machine, 0, &settings); |
| 3545 | | |
| 3546 | | /* CROSSHAIR_ITEM_AUTO_TIME - allocate a data item and fill it */ |
| 3547 | | data = (crosshair_item_data *)ui_menu_pool_alloc(menu, sizeof(*data)); |
| 3548 | | data->type = CROSSHAIR_ITEM_AUTO_TIME; |
| 3549 | | data->min = CROSSHAIR_VISIBILITY_AUTOTIME_MIN; |
| 3550 | | data->max = CROSSHAIR_VISIBILITY_AUTOTIME_MAX; |
| 3551 | | data->defvalue = CROSSHAIR_VISIBILITY_AUTOTIME_DEFAULT; |
| 3552 | | data->cur = settings.auto_time; |
| 3553 | | |
| 3554 | | /* put on arrows in visible menu */ |
| 3555 | | if (data->cur > data->min) |
| 3556 | | flags |= MENU_FLAG_LEFT_ARROW; |
| 3557 | | if (data->cur < data->max) |
| 3558 | | flags |= MENU_FLAG_RIGHT_ARROW; |
| 3559 | | |
| 3560 | | /* add CROSSHAIR_ITEM_AUTO_TIME menu */ |
| 3561 | | sprintf(temp_text, "%d", settings.auto_time); |
| 3562 | | ui_menu_item_append(menu, "Visible Delay", temp_text, flags, data); |
| 3563 | | } |
| 3564 | | // else |
| 3565 | | // /* leave a blank filler line when not in auto time so size does not rescale */ |
| 3566 | | // ui_menu_item_append(menu, "", "", NULL, NULL); |
| 3567 | | } |
| 3568 | | |
| 3569 | | |
| 3570 | | /*------------------------------------------------- |
| 3571 | | menu_quit_game - handle the "menu" for |
| 3572 | | quitting the game |
| 3573 | | -------------------------------------------------*/ |
| 3574 | | |
| 3575 | | static void menu_quit_game(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 3576 | | { |
| 3577 | | /* request a reset */ |
| 3578 | | machine.schedule_exit(); |
| 3579 | | |
| 3580 | | /* reset the menu stack */ |
| 3581 | | ui_menu_stack_reset(machine); |
| 3582 | | } |
| 3583 | | |
| 3584 | | |
| 3585 | | /*------------------------------------------------- |
| 3586 | | menu_select_game - handle the game select |
| 3587 | | menu |
| 3588 | | -------------------------------------------------*/ |
| 3589 | | |
| 3590 | | static void menu_select_game(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 3591 | | { |
| 3592 | | select_game_state *menustate; |
| 3593 | | const ui_menu_event *menu_event; |
| 3594 | | |
| 3595 | | /* if no state, allocate some */ |
| 3596 | | if (state == NULL) |
| 3597 | | { |
| 3598 | | state = ui_menu_alloc_state(menu, sizeof(*menustate) + sizeof(menustate->driverlist) * driver_list::total(), NULL); |
| 3599 | | if (parameter != NULL) |
| 3600 | | strcpy(((select_game_state *)state)->search, (const char *)parameter); |
| 3601 | | ((select_game_state *)state)->matchlist[0] = -1; |
| 3602 | | } |
| 3603 | | menustate = (select_game_state *)state; |
| 3604 | | |
| 3605 | | /* if the menu isn't built, populate now */ |
| 3606 | | if (!ui_menu_populated(menu)) |
| 3607 | | menu_select_game_populate(machine, menu, menustate); |
| 3608 | | |
| 3609 | | /* ignore pause keys by swallowing them before we process the menu */ |
| 3610 | | ui_input_pressed(machine, IPT_UI_PAUSE); |
| 3611 | | |
| 3612 | | /* process the menu */ |
| 3613 | | menu_event = ui_menu_process(machine, menu, 0); |
| 3614 | | if (menu_event != NULL && menu_event->itemref != NULL) |
| 3615 | | { |
| 3616 | | /* reset the error on any future menu_event */ |
| 3617 | | if (menustate->error) |
| 3618 | | menustate->error = FALSE; |
| 3619 | | |
| 3620 | | /* handle selections */ |
| 3621 | | else if (menu_event->iptkey == IPT_UI_SELECT) |
| 3622 | | { |
| 3623 | | const game_driver *driver = (const game_driver *)menu_event->itemref; |
| 3624 | | |
| 3625 | | /* special case for configure inputs */ |
| 3626 | | if ((FPTR)driver == 1) |
| 3627 | | ui_menu_stack_push(ui_menu_alloc(menu->machine(), menu->container, menu_input_groups, NULL)); |
| 3628 | | |
| 3629 | | /* anything else is a driver */ |
| 3630 | | else |
| 3631 | | { |
| 3632 | | // audit the game first to see if we're going to work |
| 3633 | | driver_enumerator enumerator(machine.options(), *driver); |
| 3634 | | enumerator.next(); |
| 3635 | | media_auditor auditor(enumerator); |
| 3636 | | media_auditor::summary summary = auditor.audit_media(AUDIT_VALIDATE_FAST); |
| 3637 | | |
| 3638 | | // if everything looks good, schedule the new driver |
| 3639 | | if (summary == media_auditor::CORRECT || summary == media_auditor::BEST_AVAILABLE) |
| 3640 | | { |
| 3641 | | machine.schedule_new_driver(*driver); |
| 3642 | | ui_menu_stack_reset(machine); |
| 3643 | | } |
| 3644 | | |
| 3645 | | // otherwise, display an error |
| 3646 | | else |
| 3647 | | { |
| 3648 | | ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF); |
| 3649 | | menustate->error = TRUE; |
| 3650 | | } |
| 3651 | | } |
| 3652 | | } |
| 3653 | | |
| 3654 | | /* escape pressed with non-empty text clears the text */ |
| 3655 | | else if (menu_event->iptkey == IPT_UI_CANCEL && menustate->search[0] != 0) |
| 3656 | | { |
| 3657 | | /* since we have already been popped, we must recreate ourself from scratch */ |
| 3658 | | ui_menu_stack_push(ui_menu_alloc(menu->machine(), menu->container, menu_select_game, NULL)); |
| 3659 | | } |
| 3660 | | |
| 3661 | | /* typed characters append to the buffer */ |
| 3662 | | else if (menu_event->iptkey == IPT_SPECIAL) |
| 3663 | | { |
| 3664 | | int buflen = strlen(menustate->search); |
| 3665 | | |
| 3666 | | /* if it's a backspace and we can handle it, do so */ |
| 3667 | | if ((menu_event->unichar == 8 || menu_event->unichar == 0x7f) && buflen > 0) |
| 3668 | | { |
| 3669 | | *(char *)utf8_previous_char(&menustate->search[buflen]) = 0; |
| 3670 | | menustate->rerandomize = TRUE; |
| 3671 | | ui_menu_reset(menu, UI_MENU_RESET_SELECT_FIRST); |
| 3672 | | } |
| 3673 | | |
| 3674 | | /* if it's any other key and we're not maxed out, update */ |
| 3675 | | else if (menu_event->unichar >= ' ' && menu_event->unichar < 0x7f) |
| 3676 | | { |
| 3677 | | buflen += utf8_from_uchar(&menustate->search[buflen], ARRAY_LENGTH(menustate->search) - buflen, menu_event->unichar); |
| 3678 | | menustate->search[buflen] = 0; |
| 3679 | | ui_menu_reset(menu, UI_MENU_RESET_SELECT_FIRST); |
| 3680 | | } |
| 3681 | | } |
| 3682 | | } |
| 3683 | | |
| 3684 | | /* if we're in an error state, overlay an error message */ |
| 3685 | | if (menustate->error) |
| 3686 | | ui_draw_text_box(menu->container, |
| 3687 | | "The selected game is missing one or more required ROM or CHD images. " |
| 3688 | | "Please select a different game.\n\nPress any key to continue.", |
| 3689 | | JUSTIFY_CENTER, 0.5f, 0.5f, UI_RED_COLOR); |
| 3690 | | } |
| 3691 | | |
| 3692 | | |
| 3693 | | /*------------------------------------------------- |
| 3694 | | menu_select_game_populate - populate the game |
| 3695 | | select menu |
| 3696 | | -------------------------------------------------*/ |
| 3697 | | |
| 3698 | | static void menu_select_game_populate(running_machine &machine, ui_menu *menu, select_game_state *menustate) |
| 3699 | | { |
| 3700 | | int matchcount; |
| 3701 | | int curitem; |
| 3702 | | |
| 3703 | | /* update our driver list if necessary */ |
| 3704 | | if (menustate->driverlist[0] == NULL) |
| 3705 | | menu_select_game_build_driver_list(menu, menustate); |
| 3706 | | for (curitem = matchcount = 0; menustate->driverlist[curitem] != NULL && matchcount < VISIBLE_GAMES_IN_LIST; curitem++) |
| 3707 | | if (!(menustate->driverlist[curitem]->flags & GAME_NO_STANDALONE)) |
| 3708 | | matchcount++; |
| 3709 | | |
| 3710 | | /* if nothing there, add a single multiline item and return */ |
| 3711 | | if (matchcount == 0) |
| 3712 | | { |
| 3713 | | astring txt; |
| 3714 | | txt.printf("No %s found. Please check the rompath specified in the %s.ini file.\n\n" |
| 3715 | | "If this is your first time using %s, please see the config.txt file in " |
| 3716 | | "the docs directory for information on configuring %s.", |
| 3717 | | emulator_info::get_gamesnoun(), |
| 3718 | | emulator_info::get_configname(), |
| 3719 | | emulator_info::get_appname(),emulator_info::get_appname() ); |
| 3720 | | ui_menu_item_append(menu, txt.cstr(), NULL, MENU_FLAG_MULTILINE | MENU_FLAG_REDTEXT, NULL); |
| 3721 | | return; |
| 3722 | | } |
| 3723 | | |
| 3724 | | /* otherwise, rebuild the match list */ |
| 3725 | | assert(drivlist != NULL); |
| 3726 | | if (menustate->search[0] != 0 || menustate->matchlist[0] == -1 || menustate->rerandomize) |
| 3727 | | drivlist->find_approximate_matches(menustate->search, matchcount, menustate->matchlist); |
| 3728 | | menustate->rerandomize = FALSE; |
| 3729 | | |
| 3730 | | /* iterate over entries */ |
| 3731 | | for (curitem = 0; curitem < matchcount; curitem++) |
| 3732 | | { |
| 3733 | | int curmatch = menustate->matchlist[curitem]; |
| 3734 | | if (curmatch != -1) |
| 3735 | | { |
| 3736 | | int cloneof = drivlist->non_bios_clone(curmatch); |
| 3737 | | ui_menu_item_append(menu, drivlist->driver(curmatch).name, drivlist->driver(curmatch).description, (cloneof == -1) ? 0 : MENU_FLAG_INVERT, (void *)&drivlist->driver(curmatch)); |
| 3738 | | } |
| 3739 | | } |
| 3740 | | |
| 3741 | | /* if we're forced into this, allow general input configuration as well */ |
| 3742 | | if (ui_menu_is_force_game_select()) |
| 3743 | | { |
| 3744 | | ui_menu_item_append(menu, MENU_SEPARATOR_ITEM, NULL, 0, NULL); |
| 3745 | | ui_menu_item_append(menu, "Configure General Inputs", NULL, 0, (void *)1); |
| 3746 | | } |
| 3747 | | |
| 3748 | | /* configure the custom rendering */ |
| 3749 | | ui_menu_set_custom_render(menu, 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); |
| 3750 | | } |
| 3751 | | |
| 3752 | | |
| 3753 | | /*------------------------------------------------- |
| 3754 | | menu_select_game_build_driver_list - build a |
| 3755 | | list of available drivers |
| 3756 | | -------------------------------------------------*/ |
| 3757 | | |
| 3758 | | static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state *menustate) |
| 3759 | | { |
| 3760 | | // start with an empty list |
| 3761 | | // hack alert: use new directly here to avoid reporting this one-time static memory as unfreed |
| 3762 | | if (drivlist == NULL) |
| 3763 | | drivlist = global_alloc(driver_enumerator(menu->machine().options())); |
| 3764 | | drivlist->exclude_all(); |
| 3765 | | |
| 3766 | | /* open a path to the ROMs and find them in the array */ |
| 3767 | | file_enumerator path(menu->machine().options().media_path()); |
| 3768 | | const osd_directory_entry *dir; |
| 3769 | | |
| 3770 | | /* iterate while we get new objects */ |
| 3771 | | while ((dir = path.next()) != NULL) |
| 3772 | | { |
| 3773 | | char drivername[50]; |
| 3774 | | char *dst = drivername; |
| 3775 | | const char *src; |
| 3776 | | |
| 3777 | | /* build a name for it */ |
| 3778 | | for (src = dir->name; *src != 0 && *src != '.' && dst < &drivername[ARRAY_LENGTH(drivername) - 1]; src++) |
| 3779 | | *dst++ = tolower((UINT8)*src); |
| 3780 | | *dst = 0; |
| 3781 | | |
| 3782 | | int drivnum = drivlist->find(drivername); |
| 3783 | | if (drivnum != -1) |
| 3784 | | drivlist->include(drivnum); |
| 3785 | | } |
| 3786 | | |
| 3787 | | /* now build the final list */ |
| 3788 | | drivlist->reset(); |
| 3789 | | int listnum = 0; |
| 3790 | | while (drivlist->next()) |
| 3791 | | menustate->driverlist[listnum++] = &drivlist->driver(); |
| 3792 | | |
| 3793 | | /* NULL-terminate */ |
| 3794 | | menustate->driverlist[listnum] = NULL; |
| 3795 | | } |
| 3796 | | |
| 3797 | | |
| 3798 | | /*------------------------------------------------- |
| 3799 | | menu_select_game_custom_render - perform our |
| 3800 | | special rendering |
| 3801 | | -------------------------------------------------*/ |
| 3802 | | |
| 3803 | | static 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) |
| 3804 | | { |
| 3805 | | select_game_state *menustate = (select_game_state *)state; |
| 3806 | | const game_driver *driver; |
| 3807 | | float width, maxwidth; |
| 3808 | | float x1, y1, x2, y2; |
| 3809 | | char tempbuf[4][256]; |
| 3810 | | rgb_t color; |
| 3811 | | int line; |
| 3812 | | |
| 3813 | | /* display the current typeahead */ |
| 3814 | | if (menustate->search[0] != 0) |
| 3815 | | sprintf(&tempbuf[0][0], "Type name or select: %s_", menustate->search); |
| 3816 | | else |
| 3817 | | sprintf(&tempbuf[0][0], "Type name or select: (random)"); |
| 3818 | | |
| 3819 | | /* get the size of the text */ |
| 3820 | | ui_draw_text_full(menu->container, &tempbuf[0][0], 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE, |
| 3821 | | DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &width, NULL); |
| 3822 | | width += 2 * UI_BOX_LR_BORDER; |
| 3823 | | maxwidth = MAX(width, origx2 - origx1); |
| 3824 | | |
| 3825 | | /* compute our bounds */ |
| 3826 | | x1 = 0.5f - 0.5f * maxwidth; |
| 3827 | | x2 = x1 + maxwidth; |
| 3828 | | y1 = origy1 - top; |
| 3829 | | y2 = origy1 - UI_BOX_TB_BORDER; |
| 3830 | | |
| 3831 | | /* draw a box */ |
| 3832 | | ui_draw_outlined_box(menu->container, x1, y1, x2, y2, UI_BACKGROUND_COLOR); |
| 3833 | | |
| 3834 | | /* take off the borders */ |
| 3835 | | x1 += UI_BOX_LR_BORDER; |
| 3836 | | x2 -= UI_BOX_LR_BORDER; |
| 3837 | | y1 += UI_BOX_TB_BORDER; |
| 3838 | | y2 -= UI_BOX_TB_BORDER; |
| 3839 | | |
| 3840 | | /* draw the text within it */ |
| 3841 | | ui_draw_text_full(menu->container, &tempbuf[0][0], x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_TRUNCATE, |
| 3842 | | DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, NULL, NULL); |
| 3843 | | |
| 3844 | | /* determine the text to render below */ |
| 3845 | | driver = ((FPTR)selectedref > 1) ? (const game_driver *)selectedref : NULL; |
| 3846 | | if ((FPTR)driver > 1) |
| 3847 | | { |
| 3848 | | const char *gfxstat, *soundstat; |
| 3849 | | |
| 3850 | | /* first line is game name */ |
| 3851 | | sprintf(&tempbuf[0][0], "%-.100s", driver->description); |
| 3852 | | |
| 3853 | | /* next line is year, manufacturer */ |
| 3854 | | sprintf(&tempbuf[1][0], "%s, %-.100s", driver->year, driver->manufacturer); |
| 3855 | | |
| 3856 | | /* next line is overall driver status */ |
| 3857 | | if (driver->flags & GAME_NOT_WORKING) |
| 3858 | | strcpy(&tempbuf[2][0], "Overall: NOT WORKING"); |
| 3859 | | else if (driver->flags & GAME_UNEMULATED_PROTECTION) |
| 3860 | | strcpy(&tempbuf[2][0], "Overall: Unemulated Protection"); |
| 3861 | | else |
| 3862 | | strcpy(&tempbuf[2][0], "Overall: Working"); |
| 3863 | | |
| 3864 | | /* next line is graphics, sound status */ |
| 3865 | | if (driver->flags & (GAME_IMPERFECT_GRAPHICS | GAME_WRONG_COLORS | GAME_IMPERFECT_COLORS)) |
| 3866 | | gfxstat = "Imperfect"; |
| 3867 | | else |
| 3868 | | gfxstat = "OK"; |
| 3869 | | |
| 3870 | | if (driver->flags & GAME_NO_SOUND) |
| 3871 | | soundstat = "Unimplemented"; |
| 3872 | | else if (driver->flags & GAME_IMPERFECT_SOUND) |
| 3873 | | soundstat = "Imperfect"; |
| 3874 | | else |
| 3875 | | soundstat = "OK"; |
| 3876 | | |
| 3877 | | sprintf(&tempbuf[3][0], "Gfx: %s, Sound: %s", gfxstat, soundstat); |
| 3878 | | } |
| 3879 | | else |
| 3880 | | { |
| 3881 | | const char *s = emulator_info::get_copyright(); |
| 3882 | | line = 0; |
| 3883 | | int col = 0; |
| 3884 | | |
| 3885 | | /* first line is version string */ |
| 3886 | | sprintf(&tempbuf[line++][0], "%s %s", emulator_info::get_applongname(), build_version); |
| 3887 | | |
| 3888 | | /* output message */ |
| 3889 | | while (line < ARRAY_LENGTH(tempbuf)) |
| 3890 | | { |
| 3891 | | if (*s == 0 || *s == '\n') |
| 3892 | | { |
| 3893 | | tempbuf[line++][col] = 0; |
| 3894 | | col = 0; |
| 3895 | | } |
| 3896 | | else |
| 3897 | | tempbuf[line][col++] = *s; |
| 3898 | | |
| 3899 | | if (*s != 0) |
| 3900 | | s++; |
| 3901 | | } |
| 3902 | | } |
| 3903 | | |
| 3904 | | /* get the size of the text */ |
| 3905 | | maxwidth = origx2 - origx1; |
| 3906 | | for (line = 0; line < 4; line++) |
| 3907 | | { |
| 3908 | | ui_draw_text_full(menu->container, &tempbuf[line][0], 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE, |
| 3909 | | DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &width, NULL); |
| 3910 | | width += 2 * UI_BOX_LR_BORDER; |
| 3911 | | maxwidth = MAX(maxwidth, width); |
| 3912 | | } |
| 3913 | | |
| 3914 | | /* compute our bounds */ |
| 3915 | | x1 = 0.5f - 0.5f * maxwidth; |
| 3916 | | x2 = x1 + maxwidth; |
| 3917 | | y1 = origy2 + UI_BOX_TB_BORDER; |
| 3918 | | y2 = origy2 + bottom; |
| 3919 | | |
| 3920 | | /* draw a box */ |
| 3921 | | color = UI_BACKGROUND_COLOR; |
| 3922 | | if (driver != NULL) |
| 3923 | | color = UI_GREEN_COLOR; |
| 3924 | | if (driver != NULL && (driver->flags & (GAME_IMPERFECT_GRAPHICS | GAME_WRONG_COLORS | GAME_IMPERFECT_COLORS | GAME_NO_SOUND | GAME_IMPERFECT_SOUND)) != 0) |
| 3925 | | color = UI_YELLOW_COLOR; |
| 3926 | | if (driver != NULL && (driver->flags & (GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION)) != 0) |
| 3927 | | color = UI_RED_COLOR; |
| 3928 | | ui_draw_outlined_box(menu->container, x1, y1, x2, y2, color); |
| 3929 | | |
| 3930 | | /* take off the borders */ |
| 3931 | | x1 += UI_BOX_LR_BORDER; |
| 3932 | | x2 -= UI_BOX_LR_BORDER; |
| 3933 | | y1 += UI_BOX_TB_BORDER; |
| 3934 | | y2 -= UI_BOX_TB_BORDER; |
| 3935 | | |
| 3936 | | /* draw all lines */ |
| 3937 | | for (line = 0; line < 4; line++) |
| 3938 | | { |
| 3939 | | ui_draw_text_full(menu->container, &tempbuf[line][0], x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_TRUNCATE, |
| 3940 | | DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, NULL, NULL); |
| 3941 | | y1 += ui_get_line_height(machine); |
| 3942 | | } |
| 3943 | | } |
| 3944 | | |
| 3945 | | |
| 3946 | | |
| 3947 | | /*************************************************************************** |
| 3948 | 1109 | MENU HELPERS |
| 3949 | 1110 | ***************************************************************************/ |
| 3950 | 1111 | |
| 3951 | 1112 | /*------------------------------------------------- |
| 3952 | | menu_render_triangle - render a triangle that |
| 1113 | render_triangle - render a triangle that |
| 3953 | 1114 | is used for up/down arrows and left/right |
| 3954 | 1115 | indicators |
| 3955 | 1116 | -------------------------------------------------*/ |
| 3956 | 1117 | |
| 3957 | | static void menu_render_triangle(bitmap_t &dest, const bitmap_t &source, const rectangle &sbounds, void *param) |
| 1118 | void ui_menu::render_triangle(bitmap_t &dest, const bitmap_t &source, const rectangle &sbounds, void *param) |
| 3958 | 1119 | { |
| 3959 | 1120 | int halfwidth = dest.width / 2; |
| 3960 | 1121 | int height = dest.height; |
src/emu/uimain.c
| r0 | r13467 | |
| 1 | /********************************************************************* |
| 2 | |
| 3 | uimenu.c |
| 4 | |
| 5 | Internal MAME menus for the user interface. |
| 6 | |
| 7 | Copyright Nicola Salmoria and the MAME Team. |
| 8 | Visit http://mamedev.org for licensing and usage restrictions. |
| 9 | |
| 10 | *********************************************************************/ |
| 11 | |
| 12 | #include "emu.h" |
| 13 | #include "emuopts.h" |
| 14 | #include "ui.h" |
| 15 | #include "rendutil.h" |
| 16 | #include "cheat.h" |
| 17 | #include "uiimage.h" |
| 18 | #include "uiinput.h" |
| 19 | #include "uimenu.h" |
| 20 | #include "audit.h" |
| 21 | #include "crsshair.h" |
| 22 | #include <ctype.h> |
| 23 | #include "imagedev/cassette.h" |
| 24 | #include "imagedev/bitbngr.h" |
| 25 | |
| 26 | |
| 27 | |
| 28 | /*************************************************************************** |
| 29 | CONSTANTS |
| 30 | ***************************************************************************/ |
| 31 | |
| 32 | #define VISIBLE_GAMES_IN_LIST 15 |
| 33 | |
| 34 | #define MAX_PHYSICAL_DIPS 10 |
| 35 | #define MAX_INPUT_PORTS 32 |
| 36 | #define MAX_BITS_PER_PORT 32 |
| 37 | |
| 38 | /* DIP switch rendering parameters */ |
| 39 | #define DIP_SWITCH_HEIGHT 0.05f |
| 40 | #define DIP_SWITCH_SPACING 0.01 |
| 41 | #define SINGLE_TOGGLE_SWITCH_FIELD_WIDTH 0.025f |
| 42 | #define SINGLE_TOGGLE_SWITCH_WIDTH 0.020f |
| 43 | /* make the switch 80% of the width space and 1/2 of the switch height */ |
| 44 | #define PERCENTAGE_OF_HALF_FIELD_USED 0.80f |
| 45 | #define SINGLE_TOGGLE_SWITCH_HEIGHT ((DIP_SWITCH_HEIGHT / 2) * PERCENTAGE_OF_HALF_FIELD_USED) |
| 46 | |
| 47 | |
| 48 | enum |
| 49 | { |
| 50 | INPUT_TYPE_DIGITAL = 0, |
| 51 | INPUT_TYPE_ANALOG = 1, |
| 52 | INPUT_TYPE_ANALOG_DEC = INPUT_TYPE_ANALOG + SEQ_TYPE_DECREMENT, |
| 53 | INPUT_TYPE_ANALOG_INC = INPUT_TYPE_ANALOG + SEQ_TYPE_INCREMENT, |
| 54 | INPUT_TYPE_TOTAL = INPUT_TYPE_ANALOG + SEQ_TYPE_TOTAL |
| 55 | }; |
| 56 | |
| 57 | enum |
| 58 | { |
| 59 | ANALOG_ITEM_KEYSPEED = 0, |
| 60 | ANALOG_ITEM_CENTERSPEED, |
| 61 | ANALOG_ITEM_REVERSE, |
| 62 | ANALOG_ITEM_SENSITIVITY, |
| 63 | ANALOG_ITEM_COUNT |
| 64 | }; |
| 65 | |
| 66 | enum |
| 67 | { |
| 68 | MEMCARD_ITEM_SELECT = 1, |
| 69 | MEMCARD_ITEM_LOAD, |
| 70 | MEMCARD_ITEM_EJECT, |
| 71 | MEMCARD_ITEM_CREATE |
| 72 | }; |
| 73 | |
| 74 | enum |
| 75 | { |
| 76 | VIDEO_ITEM_ROTATE = 0x80000000, |
| 77 | VIDEO_ITEM_BACKDROPS, |
| 78 | VIDEO_ITEM_OVERLAYS, |
| 79 | VIDEO_ITEM_BEZELS, |
| 80 | VIDEO_ITEM_CPANELS, |
| 81 | VIDEO_ITEM_MARQUEES, |
| 82 | VIDEO_ITEM_ZOOM, |
| 83 | VIDEO_ITEM_VIEW |
| 84 | }; |
| 85 | |
| 86 | |
| 87 | enum |
| 88 | { |
| 89 | CROSSHAIR_ITEM_VIS = 0, |
| 90 | CROSSHAIR_ITEM_PIC, |
| 91 | CROSSHAIR_ITEM_AUTO_TIME |
| 92 | }; |
| 93 | |
| 94 | |
| 95 | /*************************************************************************** |
| 96 | TYPE DEFINITIONS |
| 97 | ***************************************************************************/ |
| 98 | |
| 99 | |
| 100 | |
| 101 | /* internal input menu item data */ |
| 102 | struct input_item_data |
| 103 | { |
| 104 | input_item_data * next; /* pointer to next item in the list */ |
| 105 | const void * ref; /* reference to type description for global inputs or field for game inputs */ |
| 106 | input_seq_type seqtype; /* sequence type */ |
| 107 | input_seq seq; /* copy of the live sequence */ |
| 108 | const input_seq * defseq; /* pointer to the default sequence */ |
| 109 | const char * name; /* pointer to the base name of the item */ |
| 110 | UINT16 sortorder; /* sorting information */ |
| 111 | UINT8 type; /* type of port */ |
| 112 | }; |
| 113 | |
| 114 | |
| 115 | /* internal analog menu item data */ |
| 116 | struct analog_item_data |
| 117 | { |
| 118 | input_field_config *field; |
| 119 | int type; |
| 120 | int min, max; |
| 121 | int cur; |
| 122 | int defvalue; |
| 123 | }; |
| 124 | |
| 125 | |
| 126 | /* DIP switch descriptor */ |
| 127 | struct dip_descriptor |
| 128 | { |
| 129 | dip_descriptor * next; |
| 130 | const char * name; |
| 131 | UINT32 mask; |
| 132 | UINT32 state; |
| 133 | }; |
| 134 | |
| 135 | |
| 136 | /* extended settings menu state */ |
| 137 | struct settings_menu_state |
| 138 | { |
| 139 | dip_descriptor * diplist; |
| 140 | }; |
| 141 | |
| 142 | |
| 143 | /* extended input menu state */ |
| 144 | struct input_menu_state |
| 145 | { |
| 146 | UINT16 last_sortorder; |
| 147 | const void * pollingref; |
| 148 | input_item_data * pollingitem; |
| 149 | UINT8 record_next; |
| 150 | input_seq starting_seq; |
| 151 | }; |
| 152 | |
| 153 | |
| 154 | /* extended select game menu state */ |
| 155 | struct select_game_state |
| 156 | { |
| 157 | UINT8 error; |
| 158 | UINT8 rerandomize; |
| 159 | char search[40]; |
| 160 | int matchlist[VISIBLE_GAMES_IN_LIST]; |
| 161 | const game_driver * driverlist[1]; |
| 162 | }; |
| 163 | |
| 164 | |
| 165 | /* internal crosshair menu item data */ |
| 166 | struct crosshair_item_data |
| 167 | { |
| 168 | UINT8 type; |
| 169 | UINT8 player; |
| 170 | UINT8 min, max; |
| 171 | UINT8 cur; |
| 172 | UINT8 defvalue; |
| 173 | char last_name[CROSSHAIR_PIC_NAME_LENGTH + 1]; |
| 174 | char next_name[CROSSHAIR_PIC_NAME_LENGTH + 1]; |
| 175 | }; |
| 176 | |
| 177 | |
| 178 | |
| 179 | /*************************************************************************** |
| 180 | GLOBAL VARIABLES |
| 181 | ***************************************************************************/ |
| 182 | |
| 183 | // temporary hack until this is C++-ified |
| 184 | static driver_enumerator *drivlist; |
| 185 | |
| 186 | /*************************************************************************** |
| 187 | FUNCTION PROTOTYPES |
| 188 | ***************************************************************************/ |
| 189 | |
| 190 | /* menu handlers */ |
| 191 | static void menu_main_populate(running_machine &machine, ui_menu *menu, void *state); |
| 192 | static void menu_input_groups(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 193 | static void menu_input_groups_populate(running_machine &machine, ui_menu *menu, void *state); |
| 194 | static void menu_input_general(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 195 | static void menu_input_general_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate, int group); |
| 196 | static void menu_input_specific(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 197 | static void menu_input_specific_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate); |
| 198 | static void menu_input_common(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 199 | static int CLIB_DECL menu_input_compare_items(const void *i1, const void *i2); |
| 200 | static void menu_input_populate_and_sort(running_machine &machine, ui_menu *menu, input_item_data *itemlist, input_menu_state *menustate); |
| 201 | static void menu_settings_dip_switches(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 202 | static void menu_settings_driver_config(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 203 | static void menu_settings_common(running_machine &machine, ui_menu *menu, void *state, UINT32 type); |
| 204 | static void menu_settings_populate(running_machine &machine, ui_menu *menu, settings_menu_state *menustate, UINT32 type); |
| 205 | static void menu_analog(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 206 | static void menu_analog_populate(running_machine &machine, ui_menu *menu); |
| 207 | static void menu_bookkeeping(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 208 | static void menu_bookkeeping_populate(running_machine &machine, ui_menu *menu, attotime *curtime); |
| 209 | static void menu_game_info(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 210 | static void menu_cheat(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 211 | static void menu_cheat_populate(running_machine &machine, ui_menu *menu); |
| 212 | static void menu_memory_card(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 213 | static void menu_memory_card_populate(running_machine &machine, ui_menu *menu, int cardnum); |
| 214 | static void menu_sliders(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 215 | static void menu_sliders_populate(running_machine &machine, ui_menu *menu, int menuless_mode); |
| 216 | static 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); |
| 217 | static void menu_video_targets(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 218 | static void menu_video_targets_populate(running_machine &machine, ui_menu *menu); |
| 219 | static void menu_video_options(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 220 | static void menu_video_options_populate(running_machine &machine, ui_menu *menu, render_target *target); |
| 221 | static void menu_crosshair(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 222 | static void menu_crosshair_populate(running_machine &machine, ui_menu *menu); |
| 223 | static void menu_quit_game(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 224 | static void menu_select_game(running_machine &machine, ui_menu *menu, void *parameter, void *state); |
| 225 | static void menu_select_game_populate(running_machine &machine, ui_menu *menu, select_game_state *menustate); |
| 226 | static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state *menustate); |
| 227 | static 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); |
| 228 | |
| 229 | /* menu helpers */ |
| 230 | static void menu_settings_custom_render_one(render_container *container, float x1, float y1, float x2, float y2, const dip_descriptor *dip, UINT32 selectedmask); |
| 231 | static 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); |
| 232 | |
| 233 | |
| 234 | |
| 235 | /*************************************************************************** |
| 236 | INLINE FUNCTIONS |
| 237 | ***************************************************************************/ |
| 238 | |
| 239 | /*------------------------------------------------- |
| 240 | get_field_default_seq - return a pointer |
| 241 | to the default sequence for the given field |
| 242 | -------------------------------------------------*/ |
| 243 | |
| 244 | INLINE const input_seq &get_field_default_seq(input_field_config *field, input_seq_type seqtype) |
| 245 | { |
| 246 | if (field->seq[seqtype].is_default()) |
| 247 | return input_type_seq(field->machine(), field->type, field->player, seqtype); |
| 248 | else |
| 249 | return field->seq[seqtype]; |
| 250 | } |
| 251 | |
| 252 | |
| 253 | /*------------------------------------------------- |
| 254 | toggle_none_default - toggle between "NONE" |
| 255 | and the default item |
| 256 | -------------------------------------------------*/ |
| 257 | |
| 258 | INLINE void toggle_none_default(input_seq &selected_seq, input_seq &original_seq, const input_seq &selected_defseq) |
| 259 | { |
| 260 | /* if we used to be "none", toggle to the default value */ |
| 261 | if (original_seq.length() == 0) |
| 262 | selected_seq = selected_defseq; |
| 263 | |
| 264 | /* otherwise, toggle to "none" */ |
| 265 | else |
| 266 | selected_seq.reset(); |
| 267 | } |
| 268 | |
| 269 | |
| 270 | /*------------------------------------------------- |
| 271 | ui_slider_ui_handler - pushes the slider |
| 272 | menu on the stack and hands off to the |
| 273 | standard menu handler |
| 274 | -------------------------------------------------*/ |
| 275 | |
| 276 | UINT32 ui_slider_ui_handler(running_machine &machine, render_container *container, UINT32 state) |
| 277 | { |
| 278 | UINT32 result; |
| 279 | |
| 280 | /* if this is the first call, push the sliders menu */ |
| 281 | if (state) |
| 282 | ui_menu::stack_push(ui_menu_alloc(machine, container, menu_sliders, (void *)1)); |
| 283 | |
| 284 | /* handle standard menus */ |
| 285 | result = ui_menu::ui_handler(machine, container, state); |
| 286 | |
| 287 | /* if we are cancelled, pop the sliders menu */ |
| 288 | if (result == UI_HANDLER_CANCEL) |
| 289 | ui_menu::stack_pop(machine); |
| 290 | |
| 291 | return (ui_menu::menu_stack != NULL && ui_menu::menu_stack->handler == menu_sliders && ui_menu::menu_stack->parameter != NULL) ? 0 : UI_HANDLER_CANCEL; |
| 292 | } |
| 293 | |
| 294 | |
| 295 | /*------------------------------------------------- |
| 296 | ui_menu_force_game_select - force the game |
| 297 | select menu to be visible and inescapable |
| 298 | -------------------------------------------------*/ |
| 299 | |
| 300 | void ui_menu_force_game_select(running_machine &machine, render_container *container) |
| 301 | { |
| 302 | char *gamename = (char *)machine.options().system_name(); |
| 303 | |
| 304 | /* reset the menu stack */ |
| 305 | ui_menu::stack_reset(machine); |
| 306 | |
| 307 | /* add the quit entry followed by the game select entry */ |
| 308 | ui_menu *quit = ui_menu_alloc(machine, container, menu_quit_game, NULL); |
| 309 | quit->set_special_main_menu(true); |
| 310 | ui_menu::stack_push(quit); |
| 311 | ui_menu::stack_push(ui_menu_alloc(machine, container, menu_select_game, gamename)); |
| 312 | |
| 313 | /* force the menus on */ |
| 314 | ui_show_menu(); |
| 315 | |
| 316 | /* make sure MAME is paused */ |
| 317 | machine.pause(); |
| 318 | } |
| 319 | |
| 320 | |
| 321 | /*************************************************************************** |
| 322 | MENU HANDLERS |
| 323 | ***************************************************************************/ |
| 324 | |
| 325 | /*------------------------------------------------- |
| 326 | menu_main - handle the main menu |
| 327 | -------------------------------------------------*/ |
| 328 | |
| 329 | void menu_main(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 330 | { |
| 331 | const ui_menu_event *menu_event; |
| 332 | |
| 333 | /* if the menu isn't built, populate now */ |
| 334 | if (!menu->populated()) |
| 335 | menu_main_populate(machine, menu, state); |
| 336 | |
| 337 | /* process the menu */ |
| 338 | menu_event = menu->process(0); |
| 339 | if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT) |
| 340 | ui_menu::stack_push(ui_menu_alloc(machine, menu->container, (ui_menu_handler_func)menu_event->itemref, NULL)); |
| 341 | } |
| 342 | |
| 343 | |
| 344 | /*------------------------------------------------- |
| 345 | ui_menu_keyboard_mode - menu that |
| 346 | -------------------------------------------------*/ |
| 347 | |
| 348 | static void ui_menu_keyboard_mode(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 349 | { |
| 350 | const ui_menu_event *menu_event; |
| 351 | int natural = ui_get_use_natural_keyboard(machine); |
| 352 | |
| 353 | /* if the menu isn't built, populate now */ |
| 354 | if (!menu->populated()) |
| 355 | { |
| 356 | menu->item_append("Keyboard Mode:", natural ? "Natural" : "Emulated", natural ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, NULL); |
| 357 | } |
| 358 | |
| 359 | /* process the menu */ |
| 360 | menu_event = menu->process(0); |
| 361 | |
| 362 | if (menu_event != NULL) |
| 363 | { |
| 364 | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) { |
| 365 | ui_set_use_natural_keyboard(machine, natural ^ TRUE); |
| 366 | menu->reset(UI_MENU_RESET_REMEMBER_REF); |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | |
| 372 | /*------------------------------------------------- |
| 373 | ui_slot_get_current_index - returns |
| 374 | -------------------------------------------------*/ |
| 375 | int ui_slot_get_current_index(running_machine &machine, device_slot_interface *slot) |
| 376 | { |
| 377 | const char *current = machine.options().value(slot->device().tag()); |
| 378 | const slot_interface* intf = slot->get_slot_interfaces(); |
| 379 | int val = -1; |
| 380 | for (int i = 0; intf[i].name != NULL; i++) { |
| 381 | if (strcmp(current, intf[i].name) == 0) val = i; |
| 382 | } |
| 383 | return val; |
| 384 | } |
| 385 | |
| 386 | /*------------------------------------------------- |
| 387 | ui_slot_get_length - returns |
| 388 | -------------------------------------------------*/ |
| 389 | int ui_slot_get_length(running_machine &machine, device_slot_interface *slot) |
| 390 | { |
| 391 | const slot_interface* intf = slot->get_slot_interfaces(); |
| 392 | int val = 0; |
| 393 | for (int i = 0; intf[i].name != NULL; i++) val++; |
| 394 | return val; |
| 395 | } |
| 396 | |
| 397 | /*------------------------------------------------- |
| 398 | ui_slot_get_next - returns |
| 399 | -------------------------------------------------*/ |
| 400 | const char *ui_slot_get_next(running_machine &machine, device_slot_interface *slot) |
| 401 | { |
| 402 | int idx = ui_slot_get_current_index(machine, slot) + 1; |
| 403 | if (idx==ui_slot_get_length(machine,slot)) return ""; |
| 404 | return slot->get_slot_interfaces()[idx].name; |
| 405 | } |
| 406 | |
| 407 | /*------------------------------------------------- |
| 408 | ui_slot_get_prev - returns |
| 409 | -------------------------------------------------*/ |
| 410 | const char *ui_slot_get_prev(running_machine &machine, device_slot_interface *slot) |
| 411 | { |
| 412 | int idx = ui_slot_get_current_index(machine, slot) - 1; |
| 413 | if (idx==-1) return ""; |
| 414 | if (idx==-2) idx = ui_slot_get_length(machine,slot) -1; |
| 415 | if (idx==-1) return ""; |
| 416 | return slot->get_slot_interfaces()[idx].name; |
| 417 | } |
| 418 | |
| 419 | /*------------------------------------------------- |
| 420 | ui_get_slot_device - returns |
| 421 | -------------------------------------------------*/ |
| 422 | const char *ui_get_slot_device(running_machine &machine, device_slot_interface *slot) |
| 423 | { |
| 424 | return machine.options().value(slot->device().tag()); |
| 425 | } |
| 426 | |
| 427 | |
| 428 | /*------------------------------------------------- |
| 429 | ui_set_use_natural_keyboard - specifies |
| 430 | whether the natural keyboard is active |
| 431 | -------------------------------------------------*/ |
| 432 | |
| 433 | void ui_set_slot_device(running_machine &machine, device_slot_interface *slot, const char *val) |
| 434 | { |
| 435 | astring error; |
| 436 | machine.options().set_value(slot->device().tag(), val, OPTION_PRIORITY_CMDLINE, error); |
| 437 | assert(!error); |
| 438 | } |
| 439 | |
| 440 | /*------------------------------------------------- |
| 441 | menu_slot_devices_populate - populates the main |
| 442 | slot device menu |
| 443 | -------------------------------------------------*/ |
| 444 | |
| 445 | static void menu_slot_devices_populate(running_machine &machine, ui_menu *menu, void *state) |
| 446 | { |
| 447 | device_slot_interface *slot = NULL; |
| 448 | |
| 449 | /* cycle through all devices for this system */ |
| 450 | for (bool gotone = machine.devicelist().first(slot); gotone; gotone = slot->next(slot)) |
| 451 | { |
| 452 | /* record the menu item */ |
| 453 | const char *title = ui_get_slot_device(machine,slot); |
| 454 | menu->item_append(slot->device().tag(), strcmp(title,"")==0 ? "------" : title, MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW, (void *)slot); |
| 455 | } |
| 456 | menu->item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL); |
| 457 | menu->item_append("Reset", NULL, 0, NULL); |
| 458 | } |
| 459 | |
| 460 | /*------------------------------------------------- |
| 461 | ui_menu_slot_devices - menu that |
| 462 | -------------------------------------------------*/ |
| 463 | |
| 464 | static void ui_menu_slot_devices(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 465 | { |
| 466 | const ui_menu_event *menu_event; |
| 467 | |
| 468 | /* if the menu isn't built, populate now */ |
| 469 | if (!menu->populated()) |
| 470 | { |
| 471 | menu_slot_devices_populate(machine, menu, state); |
| 472 | } |
| 473 | |
| 474 | /* process the menu */ |
| 475 | menu_event = menu->process(0); |
| 476 | |
| 477 | if (menu_event != NULL && menu_event->itemref != NULL) |
| 478 | { |
| 479 | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) { |
| 480 | device_slot_interface *slot = (device_slot_interface *)menu_event->itemref; |
| 481 | const char *val = (menu_event->iptkey == IPT_UI_LEFT) ? ui_slot_get_prev(machine,slot) : ui_slot_get_next(machine,slot); |
| 482 | ui_set_slot_device(machine,slot,val); |
| 483 | menu->reset(UI_MENU_RESET_REMEMBER_REF); |
| 484 | } |
| 485 | } else if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT) { |
| 486 | machine.schedule_hard_reset(); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | |
| 491 | /*------------------------------------------------- |
| 492 | menu_main_populate - populate the main menu |
| 493 | -------------------------------------------------*/ |
| 494 | |
| 495 | static void menu_main_populate(running_machine &machine, ui_menu *menu, void *state) |
| 496 | { |
| 497 | input_field_config *field; |
| 498 | input_port_config *port; |
| 499 | int has_configs = FALSE; |
| 500 | int has_analog = FALSE; |
| 501 | int has_dips = FALSE; |
| 502 | astring menu_text; |
| 503 | /* scan the input port array to see what options we need to enable */ |
| 504 | for (port = machine.m_portlist.first(); port != NULL; port = port->next()) |
| 505 | for (field = port->fieldlist().first(); field != NULL; field = field->next()) |
| 506 | { |
| 507 | if (field->type == IPT_DIPSWITCH) |
| 508 | has_dips = TRUE; |
| 509 | if (field->type == IPT_CONFIG) |
| 510 | has_configs = TRUE; |
| 511 | if (input_type_is_analog(field->type)) |
| 512 | has_analog = TRUE; |
| 513 | } |
| 514 | |
| 515 | /* add input menu items */ |
| 516 | menu->item_append("Input (general)", NULL, 0, (void *)menu_input_groups); |
| 517 | |
| 518 | menu_text.printf("Input (this %s)",emulator_info::get_capstartgamenoun()); |
| 519 | menu->item_append(menu_text.cstr(), NULL, 0, (void *)menu_input_specific); |
| 520 | |
| 521 | /* add optional input-related menus */ |
| 522 | if (has_dips) |
| 523 | menu->item_append("Dip Switches", NULL, 0, (void *)menu_settings_dip_switches); |
| 524 | if (has_configs) |
| 525 | menu->item_append("Driver Configuration", NULL, 0, (void *)menu_settings_driver_config); |
| 526 | if (has_analog) |
| 527 | menu->item_append("Analog Controls", NULL, 0, (void *)menu_analog); |
| 528 | |
| 529 | /* add bookkeeping menu */ |
| 530 | menu->item_append("Bookkeeping Info", NULL, 0, (void *)menu_bookkeeping); |
| 531 | |
| 532 | /* add game info menu */ |
| 533 | menu_text.printf("%s Information",emulator_info::get_capstartgamenoun()); |
| 534 | menu->item_append(menu_text.cstr(), NULL, 0, (void *)menu_game_info); |
| 535 | |
| 536 | device_image_interface *image = NULL; |
| 537 | if (machine.devicelist().first(image)) |
| 538 | { |
| 539 | /* add image info menu */ |
| 540 | menu->item_append("Image Information", NULL, 0, (void*)ui_image_menu_image_info); |
| 541 | |
| 542 | /* add file manager menu */ |
| 543 | menu->item_append("File Manager", NULL, 0, (void*)ui_image_menu_file_manager); |
| 544 | |
| 545 | /* add tape control menu */ |
| 546 | if (machine.devicelist().first(CASSETTE)) |
| 547 | menu->item_append("Tape Control", NULL, 0, (void*)ui_mess_menu_tape_control); |
| 548 | |
| 549 | /* add bitbanger control menu */ |
| 550 | if (machine.devicelist().first(BITBANGER)) |
| 551 | menu->item_append("Bitbanger Control", NULL, 0, (void*)ui_mess_menu_bitbanger_control); |
| 552 | } |
| 553 | |
| 554 | device_slot_interface *slot = NULL; |
| 555 | if (machine.devicelist().first(slot)) |
| 556 | { |
| 557 | /* add image info menu */ |
| 558 | menu->item_append("Slot Devices", NULL, 0, (void*)ui_menu_slot_devices); |
| 559 | } |
| 560 | |
| 561 | /* add keyboard mode menu */ |
| 562 | if (input_machine_has_keyboard(machine) && inputx_can_post(machine)) |
| 563 | menu->item_append("Keyboard Mode", NULL, 0, (void *)ui_menu_keyboard_mode); |
| 564 | |
| 565 | /* add sliders menu */ |
| 566 | menu->item_append("Slider Controls", NULL, 0, (void *)menu_sliders); |
| 567 | |
| 568 | /* add video options menu */ |
| 569 | menu->item_append("Video Options", NULL, 0, (machine.render().target_by_index(1) != NULL) ? (void *)menu_video_targets : (void *)menu_video_options); |
| 570 | |
| 571 | /* add crosshair options menu */ |
| 572 | if (crosshair_get_usage(machine)) |
| 573 | menu->item_append("Crosshair Options", NULL, 0, (void *)menu_crosshair); |
| 574 | |
| 575 | /* add cheat menu */ |
| 576 | if (machine.options().cheat() && machine.cheat().first() != NULL) |
| 577 | menu->item_append("Cheat", NULL, 0, (void *)menu_cheat); |
| 578 | |
| 579 | /* add memory card menu */ |
| 580 | if (machine.config().m_memcard_handler != NULL) |
| 581 | menu->item_append("Memory Card", NULL, 0, (void *)menu_memory_card); |
| 582 | |
| 583 | /* add reset and exit menus */ |
| 584 | menu_text.printf("Select New %s",emulator_info::get_capstartgamenoun()); |
| 585 | menu->item_append(menu_text.cstr(), NULL, 0, (void *)menu_select_game); |
| 586 | } |
| 587 | |
| 588 | |
| 589 | /*------------------------------------------------- |
| 590 | menu_input_groups - handle the input groups |
| 591 | menu |
| 592 | -------------------------------------------------*/ |
| 593 | |
| 594 | static void menu_input_groups(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 595 | { |
| 596 | const ui_menu_event *menu_event; |
| 597 | |
| 598 | /* if the menu isn't built, populate now */ |
| 599 | if (!menu->populated()) |
| 600 | menu_input_groups_populate(machine, menu, state); |
| 601 | |
| 602 | /* process the menu */ |
| 603 | menu_event = menu->process(0); |
| 604 | if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT) |
| 605 | ui_menu::stack_push(ui_menu_alloc(machine, menu->container, menu_input_general, menu_event->itemref)); |
| 606 | } |
| 607 | |
| 608 | |
| 609 | /*------------------------------------------------- |
| 610 | menu_input_groups_populate - populate the |
| 611 | input groups menu |
| 612 | -------------------------------------------------*/ |
| 613 | |
| 614 | static void menu_input_groups_populate(running_machine &machine, ui_menu *menu, void *state) |
| 615 | { |
| 616 | int player; |
| 617 | |
| 618 | /* build up the menu */ |
| 619 | menu->item_append("User Interface", NULL, 0, (void *)(IPG_UI + 1)); |
| 620 | for (player = 0; player < MAX_PLAYERS; player++) |
| 621 | { |
| 622 | char buffer[40]; |
| 623 | sprintf(buffer, "Player %d Controls", player + 1); |
| 624 | menu->item_append(buffer, NULL, 0, (void *)(FPTR)(IPG_PLAYER1 + player + 1)); |
| 625 | } |
| 626 | menu->item_append("Other Controls", NULL, 0, (void *)(FPTR)(IPG_OTHER + 1)); |
| 627 | } |
| 628 | |
| 629 | |
| 630 | |
| 631 | /*------------------------------------------------- |
| 632 | menu_input_general - handle the general |
| 633 | input menu |
| 634 | -------------------------------------------------*/ |
| 635 | |
| 636 | static void menu_input_general(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 637 | { |
| 638 | menu_input_common(machine, menu, parameter, state); |
| 639 | } |
| 640 | |
| 641 | |
| 642 | /*------------------------------------------------- |
| 643 | menu_input_general_populate - populate the |
| 644 | general input menu |
| 645 | -------------------------------------------------*/ |
| 646 | |
| 647 | static void menu_input_general_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate, int group) |
| 648 | { |
| 649 | input_item_data *itemlist = NULL; |
| 650 | int suborder[SEQ_TYPE_TOTAL]; |
| 651 | astring tempstring; |
| 652 | int sortorder = 1; |
| 653 | |
| 654 | /* create a mini lookup table for sort order based on sequence type */ |
| 655 | suborder[SEQ_TYPE_STANDARD] = 0; |
| 656 | suborder[SEQ_TYPE_DECREMENT] = 1; |
| 657 | suborder[SEQ_TYPE_INCREMENT] = 2; |
| 658 | |
| 659 | /* iterate over the input ports and add menu items */ |
| 660 | for (input_type_entry *entry = input_type_list(machine).first(); entry != NULL; entry = entry->next()) |
| 661 | |
| 662 | /* add if we match the group and we have a valid name */ |
| 663 | if (entry->group == group && entry->name != NULL && entry->name[0] != 0) |
| 664 | { |
| 665 | input_seq_type seqtype; |
| 666 | |
| 667 | /* loop over all sequence types */ |
| 668 | sortorder++; |
| 669 | for (seqtype = SEQ_TYPE_STANDARD; seqtype < SEQ_TYPE_TOTAL; seqtype++) |
| 670 | { |
| 671 | /* build an entry for the standard sequence */ |
| 672 | input_item_data *item = (input_item_data *)menu->m_pool_alloc(sizeof(*item)); |
| 673 | memset(item, 0, sizeof(*item)); |
| 674 | item->ref = entry; |
| 675 | item->seqtype = seqtype; |
| 676 | item->seq = input_type_seq(machine, entry->type, entry->player, seqtype); |
| 677 | item->defseq = &entry->defseq[seqtype]; |
| 678 | item->sortorder = sortorder * 4 + suborder[seqtype]; |
| 679 | item->type = input_type_is_analog(entry->type) ? (INPUT_TYPE_ANALOG + seqtype) : INPUT_TYPE_DIGITAL; |
| 680 | item->name = entry->name; |
| 681 | item->next = itemlist; |
| 682 | itemlist = item; |
| 683 | |
| 684 | /* stop after one, unless we're analog */ |
| 685 | if (item->type == INPUT_TYPE_DIGITAL) |
| 686 | break; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | /* sort and populate the menu in a standard fashion */ |
| 691 | menu_input_populate_and_sort(machine, menu, itemlist, menustate); |
| 692 | } |
| 693 | |
| 694 | |
| 695 | /*------------------------------------------------- |
| 696 | menu_input_specific - handle the game-specific |
| 697 | input menu |
| 698 | -------------------------------------------------*/ |
| 699 | |
| 700 | static void menu_input_specific(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 701 | { |
| 702 | menu_input_common(machine, menu, NULL, state); |
| 703 | } |
| 704 | |
| 705 | |
| 706 | /*------------------------------------------------- |
| 707 | menu_input_specific_populate - populate |
| 708 | the input menu with game-specific items |
| 709 | -------------------------------------------------*/ |
| 710 | |
| 711 | static void menu_input_specific_populate(running_machine &machine, ui_menu *menu, input_menu_state *menustate) |
| 712 | { |
| 713 | input_item_data *itemlist = NULL; |
| 714 | input_field_config *field; |
| 715 | input_port_config *port; |
| 716 | int suborder[SEQ_TYPE_TOTAL]; |
| 717 | astring tempstring; |
| 718 | |
| 719 | /* create a mini lookup table for sort order based on sequence type */ |
| 720 | suborder[SEQ_TYPE_STANDARD] = 0; |
| 721 | suborder[SEQ_TYPE_DECREMENT] = 1; |
| 722 | suborder[SEQ_TYPE_INCREMENT] = 2; |
| 723 | |
| 724 | /* iterate over the input ports and add menu items */ |
| 725 | for (port = machine.m_portlist.first(); port != NULL; port = port->next()) |
| 726 | for (field = port->fieldlist().first(); field != NULL; field = field->next()) |
| 727 | { |
| 728 | const char *name = input_field_name(field); |
| 729 | |
| 730 | /* add if we match the group and we have a valid name */ |
| 731 | if (name != NULL && input_condition_true(machine, &field->condition, port->owner()) && |
| 732 | ((field->type == IPT_OTHER && field->name != NULL) || input_type_group(machine, field->type, field->player) != IPG_INVALID)) |
| 733 | { |
| 734 | input_seq_type seqtype; |
| 735 | UINT16 sortorder; |
| 736 | |
| 737 | /* determine the sorting order */ |
| 738 | if (field->type >= IPT_START1 && field->type <= __ipt_analog_end) |
| 739 | sortorder = (field->type << 2) | (field->player << 12); |
| 740 | else |
| 741 | sortorder = field->type | 0xf000; |
| 742 | |
| 743 | /* loop over all sequence types */ |
| 744 | for (seqtype = SEQ_TYPE_STANDARD; seqtype < SEQ_TYPE_TOTAL; seqtype++) |
| 745 | { |
| 746 | /* build an entry for the standard sequence */ |
| 747 | input_item_data *item = (input_item_data *)menu->m_pool_alloc(sizeof(*item)); |
| 748 | memset(item, 0, sizeof(*item)); |
| 749 | item->ref = field; |
| 750 | item->seqtype = seqtype; |
| 751 | item->seq = input_field_seq(field, seqtype); |
| 752 | item->defseq = &get_field_default_seq(field, seqtype); |
| 753 | item->sortorder = sortorder + suborder[seqtype]; |
| 754 | item->type = input_type_is_analog(field->type) ? (INPUT_TYPE_ANALOG + seqtype) : INPUT_TYPE_DIGITAL; |
| 755 | item->name = name; |
| 756 | item->next = itemlist; |
| 757 | itemlist = item; |
| 758 | |
| 759 | /* stop after one, unless we're analog */ |
| 760 | if (item->type == INPUT_TYPE_DIGITAL) |
| 761 | break; |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /* sort and populate the menu in a standard fashion */ |
| 767 | menu_input_populate_and_sort(machine, menu, itemlist, menustate); |
| 768 | } |
| 769 | |
| 770 | |
| 771 | /*------------------------------------------------- |
| 772 | menu_input - display a menu for inputs |
| 773 | -------------------------------------------------*/ |
| 774 | |
| 775 | static void menu_input_common(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 776 | { |
| 777 | input_item_data *seqchangeditem = NULL; |
| 778 | input_menu_state *menustate; |
| 779 | const ui_menu_event *menu_event; |
| 780 | int invalidate = FALSE; |
| 781 | |
| 782 | /* if no state, allocate now */ |
| 783 | if (state == NULL) |
| 784 | state = menu->alloc_state(sizeof(*menustate), NULL); |
| 785 | menustate = (input_menu_state *)state; |
| 786 | |
| 787 | /* if the menu isn't built, populate now */ |
| 788 | if (!menu->populated()) |
| 789 | { |
| 790 | if (parameter != NULL) |
| 791 | menu_input_general_populate(machine, menu, menustate, (FPTR)parameter - 1); |
| 792 | else |
| 793 | menu_input_specific_populate(machine, menu, menustate); |
| 794 | } |
| 795 | |
| 796 | /* process the menu */ |
| 797 | menu_event = menu->process((menustate->pollingitem != NULL) ? UI_MENU_PROCESS_NOKEYS : 0); |
| 798 | |
| 799 | /* if we are polling, handle as a special case */ |
| 800 | if (menustate->pollingitem != NULL) |
| 801 | { |
| 802 | input_item_data *item = menustate->pollingitem; |
| 803 | input_seq newseq; |
| 804 | |
| 805 | /* if UI_CANCEL is pressed, abort */ |
| 806 | if (ui_input_pressed(machine, IPT_UI_CANCEL)) |
| 807 | { |
| 808 | menustate->pollingitem = NULL; |
| 809 | menustate->record_next = FALSE; |
| 810 | toggle_none_default(item->seq, menustate->starting_seq, *item->defseq); |
| 811 | seqchangeditem = item; |
| 812 | } |
| 813 | |
| 814 | /* poll again; if finished, update the sequence */ |
| 815 | if (machine.input().seq_poll()) |
| 816 | { |
| 817 | menustate->pollingitem = NULL; |
| 818 | menustate->record_next = TRUE; |
| 819 | item->seq = machine.input().seq_poll_final(); |
| 820 | seqchangeditem = item; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | /* otherwise, handle the events */ |
| 825 | else if (menu_event != NULL && menu_event->itemref != NULL) |
| 826 | { |
| 827 | input_item_data *item = (input_item_data *)menu_event->itemref; |
| 828 | switch (menu_event->iptkey) |
| 829 | { |
| 830 | /* an item was selected: begin polling */ |
| 831 | case IPT_UI_SELECT: |
| 832 | menustate->pollingitem = item; |
| 833 | menustate->last_sortorder = item->sortorder; |
| 834 | menustate->starting_seq = item->seq; |
| 835 | machine.input().seq_poll_start((item->type == INPUT_TYPE_ANALOG) ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, menustate->record_next ? &item->seq : NULL); |
| 836 | invalidate = TRUE; |
| 837 | break; |
| 838 | |
| 839 | /* if the clear key was pressed, reset the selected item */ |
| 840 | case IPT_UI_CLEAR: |
| 841 | toggle_none_default(item->seq, item->seq, *item->defseq); |
| 842 | menustate->record_next = FALSE; |
| 843 | seqchangeditem = item; |
| 844 | break; |
| 845 | } |
| 846 | |
| 847 | /* if the selection changed, reset the "record next" flag */ |
| 848 | if (item->sortorder != menustate->last_sortorder) |
| 849 | menustate->record_next = FALSE; |
| 850 | menustate->last_sortorder = item->sortorder; |
| 851 | } |
| 852 | |
| 853 | /* if the sequence changed, update it */ |
| 854 | if (seqchangeditem != NULL) |
| 855 | { |
| 856 | /* update a general input */ |
| 857 | if (parameter != NULL) |
| 858 | { |
| 859 | const input_type_entry *entry = (const input_type_entry *)seqchangeditem->ref; |
| 860 | input_type_set_seq(machine, entry->type, entry->player, seqchangeditem->seqtype, &seqchangeditem->seq); |
| 861 | } |
| 862 | |
| 863 | /* update a game-specific input */ |
| 864 | else |
| 865 | { |
| 866 | input_field_user_settings settings; |
| 867 | |
| 868 | input_field_get_user_settings((input_field_config *)seqchangeditem->ref, &settings); |
| 869 | settings.seq[seqchangeditem->seqtype] = seqchangeditem->seq; |
| 870 | input_field_set_user_settings((input_field_config *)seqchangeditem->ref, &settings); |
| 871 | } |
| 872 | |
| 873 | /* invalidate the menu to force an update */ |
| 874 | invalidate = TRUE; |
| 875 | } |
| 876 | |
| 877 | /* if the menu is invalidated, clear it now */ |
| 878 | if (invalidate) |
| 879 | { |
| 880 | menustate->pollingref = NULL; |
| 881 | if (menustate->pollingitem != NULL) |
| 882 | menustate->pollingref = menustate->pollingitem->ref; |
| 883 | menu->reset(UI_MENU_RESET_REMEMBER_POSITION); |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | |
| 888 | /*------------------------------------------------- |
| 889 | menu_input_compare_items - compare two |
| 890 | items for quicksort |
| 891 | -------------------------------------------------*/ |
| 892 | |
| 893 | static int menu_input_compare_items(const void *i1, const void *i2) |
| 894 | { |
| 895 | const input_item_data * const *data1 = (const input_item_data * const *)i1; |
| 896 | const input_item_data * const *data2 = (const input_item_data * const *)i2; |
| 897 | if ((*data1)->sortorder < (*data2)->sortorder) |
| 898 | return -1; |
| 899 | if ((*data1)->sortorder > (*data2)->sortorder) |
| 900 | return 1; |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | |
| 905 | /*------------------------------------------------- |
| 906 | menu_input_populate_and_sort - take a list |
| 907 | of input_item_data objects and build up the |
| 908 | menu from them |
| 909 | -------------------------------------------------*/ |
| 910 | |
| 911 | static void menu_input_populate_and_sort(running_machine &machine, ui_menu *menu, input_item_data *itemlist, input_menu_state *menustate) |
| 912 | { |
| 913 | const char *nameformat[INPUT_TYPE_TOTAL] = { 0 }; |
| 914 | input_item_data **itemarray, *item; |
| 915 | int numitems = 0, curitem; |
| 916 | astring subtext; |
| 917 | astring text; |
| 918 | |
| 919 | /* create a mini lookup table for name format based on type */ |
| 920 | nameformat[INPUT_TYPE_DIGITAL] = "%s"; |
| 921 | nameformat[INPUT_TYPE_ANALOG] = "%s Analog"; |
| 922 | nameformat[INPUT_TYPE_ANALOG_INC] = "%s Analog Inc"; |
| 923 | nameformat[INPUT_TYPE_ANALOG_DEC] = "%s Analog Dec"; |
| 924 | |
| 925 | /* first count the number of items */ |
| 926 | for (item = itemlist; item != NULL; item = item->next) |
| 927 | numitems++; |
| 928 | |
| 929 | /* now allocate an array of items and fill it up */ |
| 930 | itemarray = (input_item_data **)menu->m_pool_alloc(sizeof(*itemarray) * numitems); |
| 931 | for (item = itemlist, curitem = 0; item != NULL; item = item->next) |
| 932 | itemarray[curitem++] = item; |
| 933 | |
| 934 | /* sort it */ |
| 935 | qsort(itemarray, numitems, sizeof(*itemarray), menu_input_compare_items); |
| 936 | |
| 937 | /* build the menu */ |
| 938 | for (curitem = 0; curitem < numitems; curitem++) |
| 939 | { |
| 940 | UINT32 flags = 0; |
| 941 | |
| 942 | /* generate the name of the item itself, based off the base name and the type */ |
| 943 | item = itemarray[curitem]; |
| 944 | assert(nameformat[item->type] != NULL); |
| 945 | text.printf(nameformat[item->type], item->name); |
| 946 | |
| 947 | /* if we're polling this item, use some spaces with left/right arrows */ |
| 948 | if (menustate->pollingref == item->ref) |
| 949 | { |
| 950 | subtext.cpy(" "); |
| 951 | flags |= MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW; |
| 952 | } |
| 953 | |
| 954 | /* otherwise, generate the sequence name and invert it if different from the default */ |
| 955 | else |
| 956 | { |
| 957 | machine.input().seq_name(subtext, item->seq); |
| 958 | flags |= (item->seq != *item->defseq) ? MENU_FLAG_INVERT : 0; |
| 959 | } |
| 960 | |
| 961 | /* add the item */ |
| 962 | menu->item_append(text, subtext, flags, item); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | |
| 967 | /*------------------------------------------------- |
| 968 | menu_settings_dip_switches - handle the DIP |
| 969 | switches menu |
| 970 | -------------------------------------------------*/ |
| 971 | |
| 972 | static void menu_settings_dip_switches(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 973 | { |
| 974 | menu_settings_common(machine, menu, state, IPT_DIPSWITCH); |
| 975 | } |
| 976 | |
| 977 | |
| 978 | /*------------------------------------------------- |
| 979 | menu_settings_driver_config - handle the |
| 980 | driver config menu |
| 981 | -------------------------------------------------*/ |
| 982 | |
| 983 | static void menu_settings_driver_config(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 984 | { |
| 985 | menu_settings_common(machine, menu, state, IPT_CONFIG); |
| 986 | } |
| 987 | |
| 988 | |
| 989 | /*------------------------------------------------- |
| 990 | menu_settings_common - handle one of the |
| 991 | switches menus |
| 992 | -------------------------------------------------*/ |
| 993 | |
| 994 | static void menu_settings_common(running_machine &machine, ui_menu *menu, void *state, UINT32 type) |
| 995 | { |
| 996 | settings_menu_state *menustate; |
| 997 | const ui_menu_event *menu_event; |
| 998 | |
| 999 | /* if no state, allocate now */ |
| 1000 | if (state == NULL) |
| 1001 | state = menu->alloc_state(sizeof(*menustate), NULL); |
| 1002 | menustate = (settings_menu_state *)state; |
| 1003 | |
| 1004 | /* if the menu isn't built, populate now */ |
| 1005 | if (!menu->populated()) |
| 1006 | menu_settings_populate(machine, menu, menustate, type); |
| 1007 | |
| 1008 | /* process the menu */ |
| 1009 | menu_event = menu->process(0); |
| 1010 | |
| 1011 | /* handle events */ |
| 1012 | if (menu_event != NULL && menu_event->itemref != NULL) |
| 1013 | { |
| 1014 | input_field_config *field = (input_field_config *)menu_event->itemref; |
| 1015 | input_field_user_settings settings; |
| 1016 | int changed = FALSE; |
| 1017 | |
| 1018 | switch (menu_event->iptkey) |
| 1019 | { |
| 1020 | /* if selected, reset to default value */ |
| 1021 | case IPT_UI_SELECT: |
| 1022 | input_field_get_user_settings(field, &settings); |
| 1023 | settings.value = field->defvalue; |
| 1024 | input_field_set_user_settings(field, &settings); |
| 1025 | changed = TRUE; |
| 1026 | break; |
| 1027 | |
| 1028 | /* left goes to previous setting */ |
| 1029 | case IPT_UI_LEFT: |
| 1030 | input_field_select_previous_setting(field); |
| 1031 | changed = TRUE; |
| 1032 | break; |
| 1033 | |
| 1034 | /* right goes to next setting */ |
| 1035 | case IPT_UI_RIGHT: |
| 1036 | input_field_select_next_setting(field); |
| 1037 | changed = TRUE; |
| 1038 | break; |
| 1039 | } |
| 1040 | |
| 1041 | /* if anything changed, rebuild the menu, trying to stay on the same field */ |
| 1042 | if (changed) |
| 1043 | menu->reset(UI_MENU_RESET_REMEMBER_REF); |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | /*------------------------------------------------- |
| 1049 | menu_settings_populate - populate one of the |
| 1050 | switches menus |
| 1051 | -------------------------------------------------*/ |
| 1052 | |
| 1053 | static void menu_settings_populate(running_machine &machine, ui_menu *menu, settings_menu_state *menustate, UINT32 type) |
| 1054 | { |
| 1055 | input_field_config *field; |
| 1056 | input_port_config *port; |
| 1057 | dip_descriptor **diplist_tailptr; |
| 1058 | int dipcount = 0; |
| 1059 | |
| 1060 | /* reset the dip switch tracking */ |
| 1061 | menustate->diplist = NULL; |
| 1062 | diplist_tailptr = &menustate->diplist; |
| 1063 | |
| 1064 | /* loop over input ports and set up the current values */ |
| 1065 | for (port = machine.m_portlist.first(); port != NULL; port = port->next()) |
| 1066 | for (field = port->fieldlist().first(); field != NULL; field = field->next()) |
| 1067 | if (field->type == type && input_condition_true(machine, &field->condition, port->owner())) |
| 1068 | { |
| 1069 | UINT32 flags = 0; |
| 1070 | |
| 1071 | /* set the left/right flags appropriately */ |
| 1072 | if (input_field_has_previous_setting(field)) |
| 1073 | flags |= MENU_FLAG_LEFT_ARROW; |
| 1074 | if (input_field_has_next_setting(field)) |
| 1075 | flags |= MENU_FLAG_RIGHT_ARROW; |
| 1076 | |
| 1077 | /* add the menu item */ |
| 1078 | menu->item_append(input_field_name(field), input_field_setting_name(field), flags, (void *)field); |
| 1079 | |
| 1080 | /* for DIP switches, build up the model */ |
| 1081 | if (type == IPT_DIPSWITCH && field->diploclist().count() != 0) |
| 1082 | { |
| 1083 | const input_field_diplocation *diploc; |
| 1084 | input_field_user_settings settings; |
| 1085 | UINT32 accummask = field->mask; |
| 1086 | |
| 1087 | /* get current settings */ |
| 1088 | input_field_get_user_settings(field, &settings); |
| 1089 | |
| 1090 | /* iterate over each bit in the field */ |
| 1091 | for (diploc = field->diploclist().first(); diploc != NULL; diploc = diploc->next()) |
| 1092 | { |
| 1093 | UINT32 mask = accummask & ~(accummask - 1); |
| 1094 | dip_descriptor *dip; |
| 1095 | |
| 1096 | /* find the matching switch name */ |
| 1097 | for (dip = menustate->diplist; dip != NULL; dip = dip->next) |
| 1098 | if (strcmp(dip->name, diploc->swname) == 0) |
| 1099 | break; |
| 1100 | |
| 1101 | /* allocate new if none */ |
| 1102 | if (dip == NULL) |
| 1103 | { |
| 1104 | dip = (dip_descriptor *)menu->m_pool_alloc(sizeof(*dip)); |
| 1105 | dip->next = NULL; |
| 1106 | dip->name = diploc->swname; |
| 1107 | dip->mask = dip->state = 0; |
| 1108 | *diplist_tailptr = dip; |
| 1109 | diplist_tailptr = &dip->next; |
| 1110 | if (mame_stricmp(dip->name, "FAKE") != 0) |
| 1111 | dipcount++; |
| 1112 | } |
| 1113 | |
| 1114 | /* apply the bits */ |
| 1115 | dip->mask |= 1 << (diploc->swnum - 1); |
| 1116 | if (((settings.value & mask) != 0 && !diploc->invert) || ((settings.value & mask) == 0 && diploc->invert)) |
| 1117 | dip->state |= 1 << (diploc->swnum - 1); |
| 1118 | |
| 1119 | /* clear the relevant bit in the accumulated mask */ |
| 1120 | accummask &= ~mask; |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | /* configure the extra menu */ |
| 1126 | if (type == IPT_DIPSWITCH && menustate->diplist != NULL) |
| 1127 | menu->set_custom_render(menu_settings_custom_render, 0.0f, dipcount * (DIP_SWITCH_HEIGHT + DIP_SWITCH_SPACING) + DIP_SWITCH_SPACING); |
| 1128 | } |
| 1129 | |
| 1130 | |
| 1131 | /*------------------------------------------------- |
| 1132 | menu_settings_custom_render - perform our special |
| 1133 | rendering |
| 1134 | -------------------------------------------------*/ |
| 1135 | |
| 1136 | static 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) |
| 1137 | { |
| 1138 | input_field_config *field = (input_field_config *)selectedref; |
| 1139 | settings_menu_state *menustate = (settings_menu_state *)state; |
| 1140 | dip_descriptor *dip; |
| 1141 | |
| 1142 | /* add borders */ |
| 1143 | y1 = y2 + UI_BOX_TB_BORDER; |
| 1144 | y2 = y1 + bottom; |
| 1145 | |
| 1146 | /* draw extra menu area */ |
| 1147 | ui_draw_outlined_box(&machine.render().ui_container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR); |
| 1148 | y1 += (float)DIP_SWITCH_SPACING; |
| 1149 | |
| 1150 | /* iterate over DIP switches */ |
| 1151 | for (dip = menustate->diplist; dip != NULL; dip = dip->next) |
| 1152 | { |
| 1153 | if (mame_stricmp(dip->name, "FAKE") != 0) |
| 1154 | { |
| 1155 | const input_field_diplocation *diploc; |
| 1156 | UINT32 selectedmask = 0; |
| 1157 | |
| 1158 | /* determine the mask of selected bits */ |
| 1159 | if (field != NULL) |
| 1160 | for (diploc = field->diploclist().first(); diploc != NULL; diploc = diploc->next()) |
| 1161 | if (strcmp(dip->name, diploc->swname) == 0) |
| 1162 | selectedmask |= 1 << (diploc->swnum - 1); |
| 1163 | |
| 1164 | /* draw one switch */ |
| 1165 | menu_settings_custom_render_one(&machine.render().ui_container(), x1, y1, x2, y1 + DIP_SWITCH_HEIGHT, dip, selectedmask); |
| 1166 | y1 += (float)(DIP_SWITCH_SPACING + DIP_SWITCH_HEIGHT); |
| 1167 | } |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | |
| 1172 | /*------------------------------------------------- |
| 1173 | menu_settings_custom_render_one - draw a single |
| 1174 | DIP switch |
| 1175 | -------------------------------------------------*/ |
| 1176 | |
| 1177 | static void menu_settings_custom_render_one(render_container *container, float x1, float y1, float x2, float y2, const dip_descriptor *dip, UINT32 selectedmask) |
| 1178 | { |
| 1179 | float switch_field_width = SINGLE_TOGGLE_SWITCH_FIELD_WIDTH * container->manager().ui_aspect(); |
| 1180 | float switch_width = SINGLE_TOGGLE_SWITCH_WIDTH * container->manager().ui_aspect(); |
| 1181 | int numtoggles, toggle; |
| 1182 | float switch_toggle_gap; |
| 1183 | float y1_off, y1_on; |
| 1184 | |
| 1185 | /* determine the number of toggles in the DIP */ |
| 1186 | numtoggles = 32 - count_leading_zeros(dip->mask); |
| 1187 | |
| 1188 | /* center based on the number of switches */ |
| 1189 | x1 += (x2 - x1 - numtoggles * switch_field_width) / 2; |
| 1190 | |
| 1191 | /* draw the dip switch name */ |
| 1192 | ui_draw_text_full( container, |
| 1193 | dip->name, |
| 1194 | 0, |
| 1195 | y1 + (DIP_SWITCH_HEIGHT - UI_TARGET_FONT_HEIGHT) / 2, |
| 1196 | x1 - ui_get_string_width(container->manager().machine(), " "), |
| 1197 | JUSTIFY_RIGHT, |
| 1198 | WRAP_NEVER, |
| 1199 | DRAW_NORMAL, |
| 1200 | UI_TEXT_COLOR, |
| 1201 | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA), |
| 1202 | NULL , |
| 1203 | NULL); |
| 1204 | |
| 1205 | /* compute top and bottom for on and off positions */ |
| 1206 | switch_toggle_gap = ((DIP_SWITCH_HEIGHT/2) - SINGLE_TOGGLE_SWITCH_HEIGHT)/2; |
| 1207 | y1_off = y1 + UI_LINE_WIDTH + switch_toggle_gap; |
| 1208 | y1_on = y1 + DIP_SWITCH_HEIGHT/2 + switch_toggle_gap; |
| 1209 | |
| 1210 | /* iterate over toggles */ |
| 1211 | for (toggle = 0; toggle < numtoggles; toggle++) |
| 1212 | { |
| 1213 | float innerx1; |
| 1214 | |
| 1215 | /* first outline the switch */ |
| 1216 | ui_draw_outlined_box(container, x1, y1, x1 + switch_field_width, y2, UI_BACKGROUND_COLOR); |
| 1217 | |
| 1218 | /* compute x1/x2 for the inner filled in switch */ |
| 1219 | innerx1 = x1 + (switch_field_width - switch_width) / 2; |
| 1220 | |
| 1221 | /* see if the switch is actually used */ |
| 1222 | if (dip->mask & (1 << toggle)) |
| 1223 | { |
| 1224 | float innery1 = (dip->state & (1 << toggle)) ? y1_on : y1_off; |
| 1225 | container->add_rect(innerx1, innery1, innerx1 + switch_width, innery1 + SINGLE_TOGGLE_SWITCH_HEIGHT, |
| 1226 | (selectedmask & (1 << toggle)) ? UI_DIPSW_COLOR : UI_TEXT_COLOR, |
| 1227 | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 1228 | } |
| 1229 | else |
| 1230 | { |
| 1231 | container->add_rect(innerx1, y1_off, innerx1 + switch_width, y1_on + SINGLE_TOGGLE_SWITCH_HEIGHT, |
| 1232 | UI_UNAVAILABLE_COLOR, |
| 1233 | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 1234 | } |
| 1235 | |
| 1236 | /* advance to the next switch */ |
| 1237 | x1 += switch_field_width; |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | /*------------------------------------------------- |
| 1243 | menu_analog - handle the analog settings menu |
| 1244 | -------------------------------------------------*/ |
| 1245 | |
| 1246 | static void menu_analog(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1247 | { |
| 1248 | const ui_menu_event *menu_event; |
| 1249 | |
| 1250 | /* if the menu isn't built, populate now */ |
| 1251 | if (!menu->populated()) |
| 1252 | menu_analog_populate(machine, menu); |
| 1253 | |
| 1254 | /* process the menu */ |
| 1255 | menu_event = menu->process(UI_MENU_PROCESS_LR_REPEAT); |
| 1256 | |
| 1257 | /* handle events */ |
| 1258 | if (menu_event != NULL && menu_event->itemref != NULL) |
| 1259 | { |
| 1260 | analog_item_data *data = (analog_item_data *)menu_event->itemref; |
| 1261 | int newval = data->cur; |
| 1262 | |
| 1263 | switch (menu_event->iptkey) |
| 1264 | { |
| 1265 | /* if selected, reset to default value */ |
| 1266 | case IPT_UI_SELECT: |
| 1267 | newval = data->defvalue; |
| 1268 | break; |
| 1269 | |
| 1270 | /* left decrements */ |
| 1271 | case IPT_UI_LEFT: |
| 1272 | newval -= machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1; |
| 1273 | break; |
| 1274 | |
| 1275 | /* right increments */ |
| 1276 | case IPT_UI_RIGHT: |
| 1277 | newval += machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1; |
| 1278 | break; |
| 1279 | } |
| 1280 | |
| 1281 | /* clamp to range */ |
| 1282 | if (newval < data->min) |
| 1283 | newval = data->min; |
| 1284 | if (newval > data->max) |
| 1285 | newval = data->max; |
| 1286 | |
| 1287 | /* if things changed, update */ |
| 1288 | if (newval != data->cur) |
| 1289 | { |
| 1290 | input_field_user_settings settings; |
| 1291 | |
| 1292 | /* get the settings and set the new value */ |
| 1293 | input_field_get_user_settings(data->field, &settings); |
| 1294 | switch (data->type) |
| 1295 | { |
| 1296 | case ANALOG_ITEM_KEYSPEED: settings.delta = newval; break; |
| 1297 | case ANALOG_ITEM_CENTERSPEED: settings.centerdelta = newval; break; |
| 1298 | case ANALOG_ITEM_REVERSE: settings.reverse = newval; break; |
| 1299 | case ANALOG_ITEM_SENSITIVITY: settings.sensitivity = newval; break; |
| 1300 | } |
| 1301 | input_field_set_user_settings(data->field, &settings); |
| 1302 | |
| 1303 | /* rebuild the menu */ |
| 1304 | menu->reset(UI_MENU_RESET_REMEMBER_POSITION); |
| 1305 | } |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | |
| 1310 | /*------------------------------------------------- |
| 1311 | menu_analog_populate - populate the analog |
| 1312 | settings menu |
| 1313 | -------------------------------------------------*/ |
| 1314 | |
| 1315 | static void menu_analog_populate(running_machine &machine, ui_menu *menu) |
| 1316 | { |
| 1317 | input_field_config *field; |
| 1318 | input_port_config *port; |
| 1319 | astring subtext; |
| 1320 | astring text; |
| 1321 | |
| 1322 | /* loop over input ports and add the items */ |
| 1323 | for (port = machine.m_portlist.first(); port != NULL; port = port->next()) |
| 1324 | for (field = port->fieldlist().first(); field != NULL; field = field->next()) |
| 1325 | if (input_type_is_analog(field->type) && input_condition_true(machine, &field->condition, port->owner())) |
| 1326 | { |
| 1327 | input_field_user_settings settings; |
| 1328 | int use_autocenter = FALSE; |
| 1329 | int type; |
| 1330 | |
| 1331 | /* based on the type, determine if we enable autocenter */ |
| 1332 | switch (field->type) |
| 1333 | { |
| 1334 | case IPT_POSITIONAL: |
| 1335 | case IPT_POSITIONAL_V: |
| 1336 | if (field->flags & ANALOG_FLAG_WRAPS) |
| 1337 | break; |
| 1338 | |
| 1339 | case IPT_AD_STICK_X: |
| 1340 | case IPT_AD_STICK_Y: |
| 1341 | case IPT_AD_STICK_Z: |
| 1342 | case IPT_PADDLE: |
| 1343 | case IPT_PADDLE_V: |
| 1344 | case IPT_PEDAL: |
| 1345 | case IPT_PEDAL2: |
| 1346 | case IPT_PEDAL3: |
| 1347 | use_autocenter = TRUE; |
| 1348 | break; |
| 1349 | } |
| 1350 | |
| 1351 | /* get the user settings */ |
| 1352 | input_field_get_user_settings(field, &settings); |
| 1353 | |
| 1354 | /* iterate over types */ |
| 1355 | for (type = 0; type < ANALOG_ITEM_COUNT; type++) |
| 1356 | if (type != ANALOG_ITEM_CENTERSPEED || use_autocenter) |
| 1357 | { |
| 1358 | analog_item_data *data; |
| 1359 | UINT32 flags = 0; |
| 1360 | |
| 1361 | /* allocate a data item for tracking what this menu item refers to */ |
| 1362 | data = (analog_item_data *)menu->m_pool_alloc(sizeof(*data)); |
| 1363 | data->field = field; |
| 1364 | data->type = type; |
| 1365 | |
| 1366 | /* determine the properties of this item */ |
| 1367 | switch (type) |
| 1368 | { |
| 1369 | default: |
| 1370 | case ANALOG_ITEM_KEYSPEED: |
| 1371 | text.printf("%s Digital Speed", input_field_name(field)); |
| 1372 | subtext.printf("%d", settings.delta); |
| 1373 | data->min = 0; |
| 1374 | data->max = 255; |
| 1375 | data->cur = settings.delta; |
| 1376 | data->defvalue = field->delta; |
| 1377 | break; |
| 1378 | |
| 1379 | case ANALOG_ITEM_CENTERSPEED: |
| 1380 | text.printf("%s Autocenter Speed", input_field_name(field)); |
| 1381 | subtext.printf("%d", settings.centerdelta); |
| 1382 | data->min = 0; |
| 1383 | data->max = 255; |
| 1384 | data->cur = settings.centerdelta; |
| 1385 | data->defvalue = field->centerdelta; |
| 1386 | break; |
| 1387 | |
| 1388 | case ANALOG_ITEM_REVERSE: |
| 1389 | text.printf("%s Reverse", input_field_name(field)); |
| 1390 | subtext.cpy(settings.reverse ? "On" : "Off"); |
| 1391 | data->min = 0; |
| 1392 | data->max = 1; |
| 1393 | data->cur = settings.reverse; |
| 1394 | data->defvalue = ((field->flags & ANALOG_FLAG_REVERSE) != 0); |
| 1395 | break; |
| 1396 | |
| 1397 | case ANALOG_ITEM_SENSITIVITY: |
| 1398 | text.printf("%s Sensitivity", input_field_name(field)); |
| 1399 | subtext.printf("%d", settings.sensitivity); |
| 1400 | data->min = 1; |
| 1401 | data->max = 255; |
| 1402 | data->cur = settings.sensitivity; |
| 1403 | data->defvalue = field->sensitivity; |
| 1404 | break; |
| 1405 | } |
| 1406 | |
| 1407 | /* put on arrows */ |
| 1408 | if (data->cur > data->min) |
| 1409 | flags |= MENU_FLAG_LEFT_ARROW; |
| 1410 | if (data->cur < data->max) |
| 1411 | flags |= MENU_FLAG_RIGHT_ARROW; |
| 1412 | |
| 1413 | /* append a menu item */ |
| 1414 | menu->item_append(text, subtext, flags, data); |
| 1415 | } |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | |
| 1420 | /*------------------------------------------------- |
| 1421 | menu_bookkeeping - handle the bookkeeping |
| 1422 | information menu |
| 1423 | -------------------------------------------------*/ |
| 1424 | |
| 1425 | static void menu_bookkeeping(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1426 | { |
| 1427 | attotime *prevtime; |
| 1428 | attotime curtime; |
| 1429 | |
| 1430 | /* if no state, allocate some */ |
| 1431 | if (state == NULL) |
| 1432 | state = menu->alloc_state(sizeof(*prevtime), NULL); |
| 1433 | prevtime = (attotime *)state; |
| 1434 | |
| 1435 | /* if the time has rolled over another second, regenerate */ |
| 1436 | curtime = machine.time(); |
| 1437 | if (prevtime->seconds != curtime.seconds) |
| 1438 | { |
| 1439 | menu->reset(UI_MENU_RESET_SELECT_FIRST); |
| 1440 | *prevtime = curtime; |
| 1441 | menu_bookkeeping_populate(machine, menu, prevtime); |
| 1442 | } |
| 1443 | |
| 1444 | /* process the menu */ |
| 1445 | menu->process(0); |
| 1446 | } |
| 1447 | |
| 1448 | |
| 1449 | /*------------------------------------------------- |
| 1450 | menu_bookkeeping - handle the bookkeeping |
| 1451 | information menu |
| 1452 | -------------------------------------------------*/ |
| 1453 | |
| 1454 | static void menu_bookkeeping_populate(running_machine &machine, ui_menu *menu, attotime *curtime) |
| 1455 | { |
| 1456 | int tickets = get_dispensed_tickets(machine); |
| 1457 | astring tempstring; |
| 1458 | int ctrnum; |
| 1459 | |
| 1460 | /* show total time first */ |
| 1461 | if (curtime->seconds >= 60 * 60) |
| 1462 | tempstring.catprintf("Uptime: %d:%02d:%02d\n\n", curtime->seconds / (60*60), (curtime->seconds / 60) % 60, curtime->seconds % 60); |
| 1463 | else |
| 1464 | tempstring.catprintf("Uptime: %d:%02d\n\n", (curtime->seconds / 60) % 60, curtime->seconds % 60); |
| 1465 | |
| 1466 | /* show tickets at the top */ |
| 1467 | if (tickets > 0) |
| 1468 | tempstring.catprintf("Tickets dispensed: %d\n\n", tickets); |
| 1469 | |
| 1470 | /* loop over coin counters */ |
| 1471 | for (ctrnum = 0; ctrnum < COIN_COUNTERS; ctrnum++) |
| 1472 | { |
| 1473 | int count = coin_counter_get_count(machine, ctrnum); |
| 1474 | |
| 1475 | /* display the coin counter number */ |
| 1476 | tempstring.catprintf("Coin %c: ", ctrnum + 'A'); |
| 1477 | |
| 1478 | /* display how many coins */ |
| 1479 | if (count == 0) |
| 1480 | tempstring.cat("NA"); |
| 1481 | else |
| 1482 | tempstring.catprintf("%d", count); |
| 1483 | |
| 1484 | /* display whether or not we are locked out */ |
| 1485 | if (coin_lockout_get_state(machine, ctrnum)) |
| 1486 | tempstring.cat(" (locked)"); |
| 1487 | tempstring.cat("\n"); |
| 1488 | } |
| 1489 | |
| 1490 | /* append the single item */ |
| 1491 | menu->item_append(tempstring, NULL, MENU_FLAG_MULTILINE, NULL); |
| 1492 | } |
| 1493 | |
| 1494 | |
| 1495 | /*------------------------------------------------- |
| 1496 | menu_game_info - handle the game information |
| 1497 | menu |
| 1498 | -------------------------------------------------*/ |
| 1499 | |
| 1500 | static void menu_game_info(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1501 | { |
| 1502 | /* if the menu isn't built, populate now */ |
| 1503 | if (!menu->populated()) |
| 1504 | { |
| 1505 | astring tempstring; |
| 1506 | menu->item_append(game_info_astring(machine, tempstring), NULL, MENU_FLAG_MULTILINE, NULL); |
| 1507 | } |
| 1508 | |
| 1509 | /* process the menu */ |
| 1510 | menu->process(0); |
| 1511 | } |
| 1512 | |
| 1513 | |
| 1514 | /*------------------------------------------------- |
| 1515 | menu_cheat - handle the cheat menu |
| 1516 | -------------------------------------------------*/ |
| 1517 | |
| 1518 | static void menu_cheat(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1519 | { |
| 1520 | const ui_menu_event *menu_event; |
| 1521 | |
| 1522 | /* if the menu isn't built, populate now */ |
| 1523 | if (!menu->populated()) |
| 1524 | menu_cheat_populate(machine, menu); |
| 1525 | |
| 1526 | /* process the menu */ |
| 1527 | menu_event = menu->process(UI_MENU_PROCESS_LR_REPEAT); |
| 1528 | |
| 1529 | /* handle events */ |
| 1530 | if (menu_event != NULL && menu_event->itemref != NULL) |
| 1531 | { |
| 1532 | bool changed = false; |
| 1533 | |
| 1534 | /* clear cheat comment on any movement or keypress */ |
| 1535 | popmessage(NULL); |
| 1536 | |
| 1537 | /* handle reset all + reset all cheats for reload all option */ |
| 1538 | if ((FPTR)menu_event->itemref < 3 && menu_event->iptkey == IPT_UI_SELECT) |
| 1539 | { |
| 1540 | for (cheat_entry *curcheat = machine.cheat().first(); curcheat != NULL; curcheat = curcheat->next()) |
| 1541 | if (curcheat->select_default_state()) |
| 1542 | changed = true; |
| 1543 | } |
| 1544 | |
| 1545 | |
| 1546 | /* handle individual cheats */ |
| 1547 | else if ((FPTR)menu_event->itemref > 2) |
| 1548 | { |
| 1549 | cheat_entry *curcheat = reinterpret_cast<cheat_entry *>(menu_event->itemref); |
| 1550 | const char *string; |
| 1551 | switch (menu_event->iptkey) |
| 1552 | { |
| 1553 | /* if selected, activate a oneshot */ |
| 1554 | case IPT_UI_SELECT: |
| 1555 | changed = curcheat->activate(); |
| 1556 | break; |
| 1557 | |
| 1558 | /* if cleared, reset to default value */ |
| 1559 | case IPT_UI_CLEAR: |
| 1560 | changed = curcheat->select_default_state(); |
| 1561 | break; |
| 1562 | |
| 1563 | /* left decrements */ |
| 1564 | case IPT_UI_LEFT: |
| 1565 | changed = curcheat->select_previous_state(); |
| 1566 | break; |
| 1567 | |
| 1568 | /* right increments */ |
| 1569 | case IPT_UI_RIGHT: |
| 1570 | changed = curcheat->select_next_state(); |
| 1571 | break; |
| 1572 | |
| 1573 | /* bring up display comment if one exists */ |
| 1574 | case IPT_UI_DISPLAY_COMMENT: |
| 1575 | case IPT_UI_UP: |
| 1576 | case IPT_UI_DOWN: |
| 1577 | string = curcheat->comment(); |
| 1578 | if (string != NULL && string[0] != 0) |
| 1579 | popmessage("Cheat Comment:\n%s", string); |
| 1580 | break; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | /* handle reload all */ |
| 1585 | if ((FPTR)menu_event->itemref == 2 && menu_event->iptkey == IPT_UI_SELECT) |
| 1586 | { |
| 1587 | /* re-init cheat engine and thus reload cheats/cheats have already been turned off by here */ |
| 1588 | machine.cheat().reload(); |
| 1589 | |
| 1590 | /* display the reloaded cheats */ |
| 1591 | menu->reset(UI_MENU_RESET_REMEMBER_REF); |
| 1592 | popmessage("All cheats reloaded"); |
| 1593 | } |
| 1594 | |
| 1595 | /* if things changed, update */ |
| 1596 | if (changed) |
| 1597 | menu->reset(UI_MENU_RESET_REMEMBER_REF); |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | |
| 1602 | /*------------------------------------------------- |
| 1603 | menu_cheat_populate - populate the cheat menu |
| 1604 | -------------------------------------------------*/ |
| 1605 | |
| 1606 | static void menu_cheat_populate(running_machine &machine, ui_menu *menu) |
| 1607 | { |
| 1608 | /* iterate over cheats */ |
| 1609 | astring text; |
| 1610 | astring subtext; |
| 1611 | for (cheat_entry *curcheat = machine.cheat().first(); curcheat != NULL; curcheat = curcheat->next()) |
| 1612 | { |
| 1613 | UINT32 flags; |
| 1614 | curcheat->menu_text(text, subtext, flags); |
| 1615 | menu->item_append(text, subtext, flags, curcheat); |
| 1616 | } |
| 1617 | |
| 1618 | /* add a separator */ |
| 1619 | menu->item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL); |
| 1620 | |
| 1621 | /* add a reset all option */ |
| 1622 | menu->item_append("Reset All", NULL, 0, (void *)1); |
| 1623 | |
| 1624 | /* add a reload all cheats option */ |
| 1625 | menu->item_append("Reload All", NULL, 0, (void *)2); |
| 1626 | } |
| 1627 | |
| 1628 | |
| 1629 | /*------------------------------------------------- |
| 1630 | menu_memory_card - handle the memory card |
| 1631 | menu |
| 1632 | -------------------------------------------------*/ |
| 1633 | |
| 1634 | static void menu_memory_card(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1635 | { |
| 1636 | const ui_menu_event *menu_event; |
| 1637 | int *cardnum; |
| 1638 | |
| 1639 | /* if no state, allocate some */ |
| 1640 | if (state == NULL) |
| 1641 | state = menu->alloc_state(sizeof(*cardnum), NULL); |
| 1642 | cardnum = (int *)state; |
| 1643 | |
| 1644 | /* if the menu isn't built, populate now */ |
| 1645 | if (!menu->populated()) |
| 1646 | menu_memory_card_populate(machine, menu, *cardnum); |
| 1647 | |
| 1648 | /* process the menu */ |
| 1649 | menu_event = menu->process(UI_MENU_PROCESS_LR_REPEAT); |
| 1650 | |
| 1651 | /* if something was selected, act on it */ |
| 1652 | if (menu_event != NULL && menu_event->itemref != NULL) |
| 1653 | { |
| 1654 | FPTR item = (FPTR)menu_event->itemref; |
| 1655 | |
| 1656 | /* select executes actions on some of the items */ |
| 1657 | if (menu_event->iptkey == IPT_UI_SELECT) |
| 1658 | { |
| 1659 | switch (item) |
| 1660 | { |
| 1661 | /* handle card loading; if we succeed, clear the menus */ |
| 1662 | case MEMCARD_ITEM_LOAD: |
| 1663 | if (memcard_insert(menu->machine(), *cardnum) == 0) |
| 1664 | { |
| 1665 | popmessage("Memory card loaded"); |
| 1666 | ui_menu::stack_reset(menu->machine()); |
| 1667 | } |
| 1668 | else |
| 1669 | popmessage("Error loading memory card"); |
| 1670 | break; |
| 1671 | |
| 1672 | /* handle card ejecting */ |
| 1673 | case MEMCARD_ITEM_EJECT: |
| 1674 | memcard_eject(menu->machine()); |
| 1675 | popmessage("Memory card ejected"); |
| 1676 | break; |
| 1677 | |
| 1678 | /* handle card creating */ |
| 1679 | case MEMCARD_ITEM_CREATE: |
| 1680 | if (memcard_create(menu->machine(), *cardnum, FALSE) == 0) |
| 1681 | popmessage("Memory card created"); |
| 1682 | else |
| 1683 | popmessage("Error creating memory card\n(Card may already exist)"); |
| 1684 | break; |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | /* the select item has extra keys */ |
| 1689 | else if (item == MEMCARD_ITEM_SELECT) |
| 1690 | { |
| 1691 | switch (menu_event->iptkey) |
| 1692 | { |
| 1693 | /* left decrements the card number */ |
| 1694 | case IPT_UI_LEFT: |
| 1695 | *cardnum -= 1; |
| 1696 | menu->reset(UI_MENU_RESET_REMEMBER_REF); |
| 1697 | break; |
| 1698 | |
| 1699 | /* right decrements the card number */ |
| 1700 | case IPT_UI_RIGHT: |
| 1701 | *cardnum += 1; |
| 1702 | menu->reset(UI_MENU_RESET_REMEMBER_REF); |
| 1703 | break; |
| 1704 | } |
| 1705 | } |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | |
| 1710 | /*------------------------------------------------- |
| 1711 | menu_memory_card_populate - populate the |
| 1712 | memory card menu |
| 1713 | -------------------------------------------------*/ |
| 1714 | |
| 1715 | static void menu_memory_card_populate(running_machine &machine, ui_menu *menu, int cardnum) |
| 1716 | { |
| 1717 | char tempstring[20]; |
| 1718 | UINT32 flags = 0; |
| 1719 | |
| 1720 | /* add the card select menu */ |
| 1721 | sprintf(tempstring, "%d", cardnum); |
| 1722 | if (cardnum > 0) |
| 1723 | flags |= MENU_FLAG_LEFT_ARROW; |
| 1724 | if (cardnum < 1000) |
| 1725 | flags |= MENU_FLAG_RIGHT_ARROW; |
| 1726 | menu->item_append("Card Number:", tempstring, flags, (void *)MEMCARD_ITEM_SELECT); |
| 1727 | |
| 1728 | /* add the remaining items */ |
| 1729 | menu->item_append("Load Selected Card", NULL, 0, (void *)MEMCARD_ITEM_LOAD); |
| 1730 | if (memcard_present(machine) != -1) |
| 1731 | menu->item_append("Eject Current Card", NULL, 0, (void *)MEMCARD_ITEM_EJECT); |
| 1732 | menu->item_append("Create New Card", NULL, 0, (void *)MEMCARD_ITEM_CREATE); |
| 1733 | } |
| 1734 | |
| 1735 | |
| 1736 | /*------------------------------------------------- |
| 1737 | menu_sliders - handle the sliders menu |
| 1738 | -------------------------------------------------*/ |
| 1739 | |
| 1740 | static void menu_sliders(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1741 | { |
| 1742 | int menuless_mode = (parameter != NULL); |
| 1743 | const ui_menu_event *menu_event; |
| 1744 | UINT8 *hidden = (UINT8 *)state; |
| 1745 | |
| 1746 | /* if no state, allocate some */ |
| 1747 | if (hidden == NULL) |
| 1748 | hidden = (UINT8 *)menu->alloc_state(sizeof(*hidden), NULL); |
| 1749 | if (menuless_mode) |
| 1750 | *hidden = TRUE; |
| 1751 | |
| 1752 | /* if the menu isn't built, populate now */ |
| 1753 | if (!menu->populated()) |
| 1754 | menu_sliders_populate(machine, menu, menuless_mode); |
| 1755 | |
| 1756 | /* process the menu */ |
| 1757 | menu_event = menu->process(UI_MENU_PROCESS_LR_REPEAT | (*hidden ? UI_MENU_PROCESS_CUSTOM_ONLY : 0)); |
| 1758 | if (menu_event != NULL) |
| 1759 | { |
| 1760 | /* handle keys if there is a valid item selected */ |
| 1761 | if (menu_event->itemref != NULL) |
| 1762 | { |
| 1763 | const slider_state *slider = (const slider_state *)menu_event->itemref; |
| 1764 | INT32 curvalue = (*slider->update)(machine, slider->arg, NULL, SLIDER_NOCHANGE); |
| 1765 | INT32 increment = 0; |
| 1766 | |
| 1767 | switch (menu_event->iptkey) |
| 1768 | { |
| 1769 | /* toggle visibility */ |
| 1770 | case IPT_UI_ON_SCREEN_DISPLAY: |
| 1771 | if (menuless_mode) |
| 1772 | ui_menu::stack_pop(machine); |
| 1773 | else |
| 1774 | *hidden = !*hidden; |
| 1775 | break; |
| 1776 | |
| 1777 | /* decrease value */ |
| 1778 | case IPT_UI_LEFT: |
| 1779 | if (machine.input().code_pressed(KEYCODE_LALT) || machine.input().code_pressed(KEYCODE_RALT)) |
| 1780 | increment = -1; |
| 1781 | else if (machine.input().code_pressed(KEYCODE_LSHIFT) || machine.input().code_pressed(KEYCODE_RSHIFT)) |
| 1782 | increment = (slider->incval > 10) ? -(slider->incval / 10) : -1; |
| 1783 | else if (machine.input().code_pressed(KEYCODE_LCONTROL) || machine.input().code_pressed(KEYCODE_RCONTROL)) |
| 1784 | increment = -slider->incval * 10; |
| 1785 | else |
| 1786 | increment = -slider->incval; |
| 1787 | break; |
| 1788 | |
| 1789 | /* increase value */ |
| 1790 | case IPT_UI_RIGHT: |
| 1791 | if (machine.input().code_pressed(KEYCODE_LALT) || machine.input().code_pressed(KEYCODE_RALT)) |
| 1792 | increment = 1; |
| 1793 | else if (machine.input().code_pressed(KEYCODE_LSHIFT) || machine.input().code_pressed(KEYCODE_RSHIFT)) |
| 1794 | increment = (slider->incval > 10) ? (slider->incval / 10) : 1; |
| 1795 | else if (machine.input().code_pressed(KEYCODE_LCONTROL) || machine.input().code_pressed(KEYCODE_RCONTROL)) |
| 1796 | increment = slider->incval * 10; |
| 1797 | else |
| 1798 | increment = slider->incval; |
| 1799 | break; |
| 1800 | |
| 1801 | /* restore default */ |
| 1802 | case IPT_UI_SELECT: |
| 1803 | increment = slider->defval - curvalue; |
| 1804 | break; |
| 1805 | } |
| 1806 | |
| 1807 | /* handle any changes */ |
| 1808 | if (increment != 0) |
| 1809 | { |
| 1810 | INT32 newvalue = curvalue + increment; |
| 1811 | |
| 1812 | /* clamp within bounds */ |
| 1813 | if (newvalue < slider->minval) |
| 1814 | newvalue = slider->minval; |
| 1815 | if (newvalue > slider->maxval) |
| 1816 | newvalue = slider->maxval; |
| 1817 | |
| 1818 | /* update the slider and recompute the menu */ |
| 1819 | (*slider->update)(machine, slider->arg, NULL, newvalue); |
| 1820 | menu->reset(UI_MENU_RESET_REMEMBER_REF); |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | /* if we are selecting an invalid item and we are hidden, skip to the next one */ |
| 1825 | else if (*hidden) |
| 1826 | { |
| 1827 | /* if we got here via up or page up, select the previous item */ |
| 1828 | if (menu_event->iptkey == IPT_UI_UP || menu_event->iptkey == IPT_UI_PAGE_UP) |
| 1829 | { |
| 1830 | menu->selected = (menu->selected + menu->numitems - 1) % menu->numitems; |
| 1831 | menu->validate_selection(-1); |
| 1832 | } |
| 1833 | |
| 1834 | /* otherwise select the next item */ |
| 1835 | else if (menu_event->iptkey == IPT_UI_DOWN || menu_event->iptkey == IPT_UI_PAGE_DOWN) |
| 1836 | { |
| 1837 | menu->selected = (menu->selected + 1) % menu->numitems; |
| 1838 | menu->validate_selection(1); |
| 1839 | } |
| 1840 | } |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | |
| 1845 | /*------------------------------------------------- |
| 1846 | menu_sliders_populate - populate the sliders |
| 1847 | menu |
| 1848 | -------------------------------------------------*/ |
| 1849 | |
| 1850 | static void menu_sliders_populate(running_machine &machine, ui_menu *menu, int menuless_mode) |
| 1851 | { |
| 1852 | const slider_state *curslider; |
| 1853 | astring tempstring; |
| 1854 | |
| 1855 | /* add all sliders */ |
| 1856 | for (curslider = ui_get_slider_list(); curslider != NULL; curslider = curslider->next) |
| 1857 | { |
| 1858 | INT32 curval = (*curslider->update)(machine, curslider->arg, &tempstring, SLIDER_NOCHANGE); |
| 1859 | UINT32 flags = 0; |
| 1860 | if (curval > curslider->minval) |
| 1861 | flags |= MENU_FLAG_LEFT_ARROW; |
| 1862 | if (curval < curslider->maxval) |
| 1863 | flags |= MENU_FLAG_RIGHT_ARROW; |
| 1864 | menu->item_append(curslider->description, tempstring, flags, (void *)curslider); |
| 1865 | |
| 1866 | if (menuless_mode) |
| 1867 | break; |
| 1868 | } |
| 1869 | |
| 1870 | /* add all sliders */ |
| 1871 | for (curslider = (slider_state*)machine.osd().get_slider_list(); curslider != NULL; curslider = curslider->next) |
| 1872 | { |
| 1873 | INT32 curval = (*curslider->update)(machine, curslider->arg, &tempstring, SLIDER_NOCHANGE); |
| 1874 | UINT32 flags = 0; |
| 1875 | if (curval > curslider->minval) |
| 1876 | flags |= MENU_FLAG_LEFT_ARROW; |
| 1877 | if (curval < curslider->maxval) |
| 1878 | flags |= MENU_FLAG_RIGHT_ARROW; |
| 1879 | menu->item_append(curslider->description, tempstring, flags, (void *)curslider); |
| 1880 | } |
| 1881 | |
| 1882 | menu->set_custom_render(menu_sliders_custom_render, 0.0f, 2.0f * ui_get_line_height(machine) + 2.0f * UI_BOX_TB_BORDER); |
| 1883 | } |
| 1884 | |
| 1885 | |
| 1886 | /*------------------------------------------------- |
| 1887 | menu_sliders_custom_render - perform our special |
| 1888 | rendering |
| 1889 | -------------------------------------------------*/ |
| 1890 | |
| 1891 | static 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) |
| 1892 | { |
| 1893 | const slider_state *curslider = (const slider_state *)selectedref; |
| 1894 | if (curslider != NULL) |
| 1895 | { |
| 1896 | float bar_left, bar_area_top, bar_width, bar_area_height, bar_top, bar_bottom, default_x, current_x; |
| 1897 | float line_height = ui_get_line_height(machine); |
| 1898 | float percentage, default_percentage; |
| 1899 | astring tempstring; |
| 1900 | float text_height; |
| 1901 | INT32 curval; |
| 1902 | |
| 1903 | /* determine the current value and text */ |
| 1904 | curval = (*curslider->update)(machine, curslider->arg, &tempstring, SLIDER_NOCHANGE); |
| 1905 | |
| 1906 | /* compute the current and default percentages */ |
| 1907 | percentage = (float)(curval - curslider->minval) / (float)(curslider->maxval - curslider->minval); |
| 1908 | default_percentage = (float)(curslider->defval - curslider->minval) / (float)(curslider->maxval - curslider->minval); |
| 1909 | |
| 1910 | /* assemble the the text */ |
| 1911 | tempstring.ins(0, " ").ins(0, curslider->description); |
| 1912 | |
| 1913 | /* move us to the bottom of the screen, and expand to full width */ |
| 1914 | y2 = 1.0f - UI_BOX_TB_BORDER; |
| 1915 | y1 = y2 - bottom; |
| 1916 | x1 = UI_BOX_LR_BORDER; |
| 1917 | x2 = 1.0f - UI_BOX_LR_BORDER; |
| 1918 | |
| 1919 | /* draw extra menu area */ |
| 1920 | ui_draw_outlined_box(&machine.render().ui_container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR); |
| 1921 | y1 += UI_BOX_TB_BORDER; |
| 1922 | |
| 1923 | /* determine the text height */ |
| 1924 | ui_draw_text_full(&machine.render().ui_container(), tempstring, 0, 0, x2 - x1 - 2.0f * UI_BOX_LR_BORDER, |
| 1925 | JUSTIFY_CENTER, WRAP_TRUNCATE, DRAW_NONE, ARGB_WHITE, ARGB_BLACK, NULL, &text_height); |
| 1926 | |
| 1927 | /* draw the thermometer */ |
| 1928 | bar_left = x1 + UI_BOX_LR_BORDER; |
| 1929 | bar_area_top = y1; |
| 1930 | bar_width = x2 - x1 - 2.0f * UI_BOX_LR_BORDER; |
| 1931 | bar_area_height = line_height; |
| 1932 | |
| 1933 | /* compute positions */ |
| 1934 | bar_top = bar_area_top + 0.125f * bar_area_height; |
| 1935 | bar_bottom = bar_area_top + 0.875f * bar_area_height; |
| 1936 | default_x = bar_left + bar_width * default_percentage; |
| 1937 | current_x = bar_left + bar_width * percentage; |
| 1938 | |
| 1939 | /* fill in the percentage */ |
| 1940 | machine.render().ui_container().add_rect(bar_left, bar_top, current_x, bar_bottom, UI_SLIDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 1941 | |
| 1942 | /* draw the top and bottom lines */ |
| 1943 | 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)); |
| 1944 | 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)); |
| 1945 | |
| 1946 | /* draw default marker */ |
| 1947 | 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)); |
| 1948 | 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)); |
| 1949 | |
| 1950 | /* draw the actual text */ |
| 1951 | 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, |
| 1952 | JUSTIFY_CENTER, WRAP_WORD, DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, NULL, &text_height); |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | |
| 1957 | /*------------------------------------------------- |
| 1958 | menu_video_targets - handle the video targets |
| 1959 | menu |
| 1960 | -------------------------------------------------*/ |
| 1961 | |
| 1962 | static void menu_video_targets(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 1963 | { |
| 1964 | const ui_menu_event *menu_event; |
| 1965 | |
| 1966 | /* if the menu isn't built, populate now */ |
| 1967 | if (!menu->populated()) |
| 1968 | menu_video_targets_populate(machine, menu); |
| 1969 | |
| 1970 | /* process the menu */ |
| 1971 | menu_event = menu->process(0); |
| 1972 | if (menu_event != NULL && menu_event->iptkey == IPT_UI_SELECT) |
| 1973 | ui_menu::stack_push(ui_menu_alloc(machine, menu->container, menu_video_options, menu_event->itemref)); |
| 1974 | } |
| 1975 | |
| 1976 | |
| 1977 | /*------------------------------------------------- |
| 1978 | menu_video_targets_populate - populate the |
| 1979 | video targets menu |
| 1980 | -------------------------------------------------*/ |
| 1981 | |
| 1982 | static void menu_video_targets_populate(running_machine &machine, ui_menu *menu) |
| 1983 | { |
| 1984 | int targetnum; |
| 1985 | |
| 1986 | /* find the targets */ |
| 1987 | for (targetnum = 0; ; targetnum++) |
| 1988 | { |
| 1989 | render_target *target = machine.render().target_by_index(targetnum); |
| 1990 | char buffer[40]; |
| 1991 | |
| 1992 | /* stop when we run out */ |
| 1993 | if (target == NULL) |
| 1994 | break; |
| 1995 | |
| 1996 | /* add a menu item */ |
| 1997 | sprintf(buffer, "Screen #%d", targetnum); |
| 1998 | menu->item_append(buffer, NULL, 0, target); |
| 1999 | } |
| 2000 | } |
| 2001 | |
| 2002 | |
| 2003 | /*------------------------------------------------- |
| 2004 | menu_video_options - handle the video options |
| 2005 | menu |
| 2006 | -------------------------------------------------*/ |
| 2007 | |
| 2008 | static void menu_video_options(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2009 | { |
| 2010 | render_target *target = (parameter != NULL) ? (render_target *)parameter : machine.render().first_target(); |
| 2011 | const ui_menu_event *menu_event; |
| 2012 | int changed = FALSE; |
| 2013 | |
| 2014 | /* if the menu isn't built, populate now */ |
| 2015 | if (!menu->populated()) |
| 2016 | menu_video_options_populate(machine, menu, target); |
| 2017 | |
| 2018 | /* process the menu */ |
| 2019 | menu_event = menu->process(0); |
| 2020 | if (menu_event != NULL && menu_event->itemref != NULL) |
| 2021 | { |
| 2022 | switch ((FPTR)menu_event->itemref) |
| 2023 | { |
| 2024 | /* rotate adds rotation depending on the direction */ |
| 2025 | case VIDEO_ITEM_ROTATE: |
| 2026 | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 2027 | { |
| 2028 | int delta = (menu_event->iptkey == IPT_UI_LEFT) ? ROT270 : ROT90; |
| 2029 | target->set_orientation(orientation_add(delta, target->orientation())); |
| 2030 | if (target->is_ui_target()) |
| 2031 | { |
| 2032 | render_container::user_settings settings; |
| 2033 | machine.render().ui_container().get_user_settings(settings); |
| 2034 | settings.m_orientation = orientation_add(delta ^ ROT180, settings.m_orientation); |
| 2035 | machine.render().ui_container().set_user_settings(settings); |
| 2036 | } |
| 2037 | changed = TRUE; |
| 2038 | } |
| 2039 | break; |
| 2040 | |
| 2041 | /* layer config bitmasks handle left/right keys the same (toggle) */ |
| 2042 | case VIDEO_ITEM_BACKDROPS: |
| 2043 | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 2044 | { |
| 2045 | target->set_backdrops_enabled(!target->backdrops_enabled()); |
| 2046 | changed = TRUE; |
| 2047 | } |
| 2048 | break; |
| 2049 | |
| 2050 | case VIDEO_ITEM_OVERLAYS: |
| 2051 | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 2052 | { |
| 2053 | target->set_overlays_enabled(!target->overlays_enabled()); |
| 2054 | changed = TRUE; |
| 2055 | } |
| 2056 | break; |
| 2057 | |
| 2058 | case VIDEO_ITEM_BEZELS: |
| 2059 | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 2060 | { |
| 2061 | target->set_bezels_enabled(!target->bezels_enabled()); |
| 2062 | changed = TRUE; |
| 2063 | } |
| 2064 | break; |
| 2065 | |
| 2066 | case VIDEO_ITEM_CPANELS: |
| 2067 | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 2068 | { |
| 2069 | target->set_cpanels_enabled(!target->cpanels_enabled()); |
| 2070 | changed = TRUE; |
| 2071 | } |
| 2072 | break; |
| 2073 | |
| 2074 | case VIDEO_ITEM_MARQUEES: |
| 2075 | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 2076 | { |
| 2077 | target->set_marquees_enabled(!target->marquees_enabled()); |
| 2078 | changed = TRUE; |
| 2079 | } |
| 2080 | break; |
| 2081 | |
| 2082 | case VIDEO_ITEM_ZOOM: |
| 2083 | if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) |
| 2084 | { |
| 2085 | target->set_zoom_to_screen(!target->zoom_to_screen()); |
| 2086 | changed = TRUE; |
| 2087 | } |
| 2088 | break; |
| 2089 | |
| 2090 | /* anything else is a view item */ |
| 2091 | default: |
| 2092 | if (menu_event->iptkey == IPT_UI_SELECT && (int)(FPTR)menu_event->itemref >= VIDEO_ITEM_VIEW) |
| 2093 | { |
| 2094 | target->set_view((FPTR)menu_event->itemref - VIDEO_ITEM_VIEW); |
| 2095 | changed = TRUE; |
| 2096 | } |
| 2097 | break; |
| 2098 | } |
| 2099 | } |
| 2100 | |
| 2101 | /* if something changed, rebuild the menu */ |
| 2102 | if (changed) |
| 2103 | menu->reset(UI_MENU_RESET_REMEMBER_REF); |
| 2104 | } |
| 2105 | |
| 2106 | |
| 2107 | /*------------------------------------------------- |
| 2108 | menu_video_options_populate - populate the |
| 2109 | video options menu |
| 2110 | -------------------------------------------------*/ |
| 2111 | |
| 2112 | static void menu_video_options_populate(running_machine &machine, ui_menu *menu, render_target *target) |
| 2113 | { |
| 2114 | const char *subtext = ""; |
| 2115 | astring tempstring; |
| 2116 | int viewnum; |
| 2117 | int enabled; |
| 2118 | |
| 2119 | /* add items for each view */ |
| 2120 | for (viewnum = 0; ; viewnum++) |
| 2121 | { |
| 2122 | const char *name = target->view_name(viewnum); |
| 2123 | if (name == NULL) |
| 2124 | break; |
| 2125 | |
| 2126 | /* create a string for the item, replacing underscores with spaces */ |
| 2127 | tempstring.cpy(name).replace(0, "_", " "); |
| 2128 | menu->item_append(tempstring, NULL, 0, (void *)(FPTR)(VIDEO_ITEM_VIEW + viewnum)); |
| 2129 | } |
| 2130 | |
| 2131 | /* add a separator */ |
| 2132 | menu->item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL); |
| 2133 | |
| 2134 | /* add a rotate item */ |
| 2135 | switch (target->orientation()) |
| 2136 | { |
| 2137 | case ROT0: subtext = "None"; break; |
| 2138 | case ROT90: subtext = "CW 90" UTF8_DEGREES; break; |
| 2139 | case ROT180: subtext = "180" UTF8_DEGREES; break; |
| 2140 | case ROT270: subtext = "CCW 90" UTF8_DEGREES; break; |
| 2141 | } |
| 2142 | menu->item_append("Rotate", subtext, MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_ROTATE); |
| 2143 | |
| 2144 | /* backdrop item */ |
| 2145 | enabled = target->backdrops_enabled(); |
| 2146 | menu->item_append("Backdrops", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_BACKDROPS); |
| 2147 | |
| 2148 | /* overlay item */ |
| 2149 | enabled = target->overlays_enabled(); |
| 2150 | menu->item_append("Overlays", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_OVERLAYS); |
| 2151 | |
| 2152 | /* bezel item */ |
| 2153 | enabled = target->bezels_enabled(); |
| 2154 | menu->item_append("Bezels", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_BEZELS); |
| 2155 | |
| 2156 | /* cpanel item */ |
| 2157 | enabled = target->cpanels_enabled(); |
| 2158 | menu->item_append("CPanels", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_CPANELS); |
| 2159 | |
| 2160 | /* marquee item */ |
| 2161 | enabled = target->marquees_enabled(); |
| 2162 | menu->item_append("Marquees", enabled ? "Enabled" : "Disabled", enabled ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, (void *)VIDEO_ITEM_MARQUEES); |
| 2163 | |
| 2164 | /* cropping */ |
| 2165 | enabled = target->zoom_to_screen(); |
| 2166 | menu->item_append("View", enabled ? "Cropped" : "Full", enabled ? MENU_FLAG_RIGHT_ARROW : MENU_FLAG_LEFT_ARROW, (void *)VIDEO_ITEM_ZOOM); |
| 2167 | } |
| 2168 | |
| 2169 | |
| 2170 | /*------------------------------------------------- |
| 2171 | menu_crosshair - handle the crosshair settings |
| 2172 | menu |
| 2173 | -------------------------------------------------*/ |
| 2174 | |
| 2175 | static void menu_crosshair(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2176 | { |
| 2177 | const ui_menu_event *menu_event; |
| 2178 | |
| 2179 | /* if the menu isn't built, populate now */ |
| 2180 | if (!menu->populated()) |
| 2181 | menu_crosshair_populate(machine, menu); |
| 2182 | |
| 2183 | /* process the menu */ |
| 2184 | menu_event = menu->process(UI_MENU_PROCESS_LR_REPEAT); |
| 2185 | |
| 2186 | /* handle events */ |
| 2187 | if (menu_event != NULL && menu_event->itemref != NULL) |
| 2188 | { |
| 2189 | crosshair_user_settings settings; |
| 2190 | crosshair_item_data *data = (crosshair_item_data *)menu_event->itemref; |
| 2191 | int changed = FALSE; |
| 2192 | //int set_def = FALSE; |
| 2193 | int newval = data->cur; |
| 2194 | |
| 2195 | /* retreive the user settings */ |
| 2196 | crosshair_get_user_settings(machine, data->player, &settings); |
| 2197 | |
| 2198 | switch (menu_event->iptkey) |
| 2199 | { |
| 2200 | /* if selected, reset to default value */ |
| 2201 | case IPT_UI_SELECT: |
| 2202 | newval = data->defvalue; |
| 2203 | //set_def = TRUE; |
| 2204 | break; |
| 2205 | |
| 2206 | /* left decrements */ |
| 2207 | case IPT_UI_LEFT: |
| 2208 | newval -= machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1; |
| 2209 | break; |
| 2210 | |
| 2211 | /* right increments */ |
| 2212 | case IPT_UI_RIGHT: |
| 2213 | newval += machine.input().code_pressed(KEYCODE_LSHIFT) ? 10 : 1; |
| 2214 | break; |
| 2215 | } |
| 2216 | |
| 2217 | /* clamp to range */ |
| 2218 | if (newval < data->min) |
| 2219 | newval = data->min; |
| 2220 | if (newval > data->max) |
| 2221 | newval = data->max; |
| 2222 | |
| 2223 | /* if things changed, update */ |
| 2224 | if (newval != data->cur) |
| 2225 | { |
| 2226 | switch (data->type) |
| 2227 | { |
| 2228 | /* visibility state */ |
| 2229 | case CROSSHAIR_ITEM_VIS: |
| 2230 | settings.mode = newval; |
| 2231 | changed = TRUE; |
| 2232 | break; |
| 2233 | |
| 2234 | /* auto time */ |
| 2235 | case CROSSHAIR_ITEM_AUTO_TIME: |
| 2236 | settings.auto_time = newval; |
| 2237 | changed = TRUE; |
| 2238 | break; |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | /* crosshair graphic name */ |
| 2243 | if (data->type == CROSSHAIR_ITEM_PIC) |
| 2244 | { |
| 2245 | if (menu_event->iptkey == IPT_UI_SELECT) |
| 2246 | { |
| 2247 | /* clear the name string to reset to default crosshair */ |
| 2248 | settings.name[0] = 0; |
| 2249 | changed = TRUE; |
| 2250 | } |
| 2251 | else if (menu_event->iptkey == IPT_UI_LEFT) |
| 2252 | { |
| 2253 | strcpy(settings.name, data->last_name); |
| 2254 | changed = TRUE; |
| 2255 | } |
| 2256 | else if (menu_event->iptkey == IPT_UI_RIGHT) |
| 2257 | { |
| 2258 | strcpy(settings.name, data->next_name); |
| 2259 | changed = TRUE; |
| 2260 | } |
| 2261 | } |
| 2262 | |
| 2263 | if (changed) |
| 2264 | { |
| 2265 | /* save the user settings */ |
| 2266 | crosshair_set_user_settings(machine, data->player, &settings); |
| 2267 | |
| 2268 | /* rebuild the menu */ |
| 2269 | menu->reset(UI_MENU_RESET_REMEMBER_POSITION); |
| 2270 | } |
| 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | |
| 2275 | /*------------------------------------------------- |
| 2276 | menu_crosshair_populate - populate the |
| 2277 | crosshair settings menu |
| 2278 | -------------------------------------------------*/ |
| 2279 | |
| 2280 | static void menu_crosshair_populate(running_machine &machine, ui_menu *menu) |
| 2281 | { |
| 2282 | crosshair_user_settings settings; |
| 2283 | crosshair_item_data *data; |
| 2284 | char temp_text[16]; |
| 2285 | int player; |
| 2286 | UINT8 use_auto = FALSE; |
| 2287 | UINT32 flags = 0; |
| 2288 | |
| 2289 | /* loop over player and add the manual items */ |
| 2290 | for (player = 0; player < MAX_PLAYERS; player++) |
| 2291 | { |
| 2292 | /* get the user settings */ |
| 2293 | crosshair_get_user_settings(machine, player, &settings); |
| 2294 | |
| 2295 | /* add menu items for usable crosshairs */ |
| 2296 | if (settings.used) |
| 2297 | { |
| 2298 | /* Make sure to keep these matched to the CROSSHAIR_VISIBILITY_xxx types */ |
| 2299 | static const char *const vis_text[] = { "Off", "On", "Auto" }; |
| 2300 | |
| 2301 | /* track if we need the auto time menu */ |
| 2302 | if (settings.mode == CROSSHAIR_VISIBILITY_AUTO) use_auto = TRUE; |
| 2303 | |
| 2304 | /* CROSSHAIR_ITEM_VIS - allocate a data item and fill it */ |
| 2305 | data = (crosshair_item_data *)menu->m_pool_alloc(sizeof(*data)); |
| 2306 | data->type = CROSSHAIR_ITEM_VIS; |
| 2307 | data->player = player; |
| 2308 | data->min = CROSSHAIR_VISIBILITY_OFF; |
| 2309 | data->max = CROSSHAIR_VISIBILITY_AUTO; |
| 2310 | data->defvalue = CROSSHAIR_VISIBILITY_DEFAULT; |
| 2311 | data->cur = settings.mode; |
| 2312 | |
| 2313 | /* put on arrows */ |
| 2314 | if (data->cur > data->min) |
| 2315 | flags |= MENU_FLAG_LEFT_ARROW; |
| 2316 | if (data->cur < data->max) |
| 2317 | flags |= MENU_FLAG_RIGHT_ARROW; |
| 2318 | |
| 2319 | /* add CROSSHAIR_ITEM_VIS menu */ |
| 2320 | sprintf(temp_text, "P%d Visibility", player + 1); |
| 2321 | menu->item_append(temp_text, vis_text[settings.mode], flags, data); |
| 2322 | |
| 2323 | /* CROSSHAIR_ITEM_PIC - allocate a data item and fill it */ |
| 2324 | data = (crosshair_item_data *)menu->m_pool_alloc(sizeof(*data)); |
| 2325 | data->type = CROSSHAIR_ITEM_PIC; |
| 2326 | data->player = player; |
| 2327 | data->last_name[0] = 0; |
| 2328 | /* other data item not used by this menu */ |
| 2329 | |
| 2330 | /* search for crosshair graphics */ |
| 2331 | |
| 2332 | /* open a path to the crosshairs */ |
| 2333 | file_enumerator path(machine.options().crosshair_path()); |
| 2334 | const osd_directory_entry *dir; |
| 2335 | /* reset search flags */ |
| 2336 | int using_default = FALSE; |
| 2337 | int finished = FALSE; |
| 2338 | int found = FALSE; |
| 2339 | |
| 2340 | /* if we are using the default, then we just need to find the first in the list */ |
| 2341 | if (strlen(settings.name) == 0) |
| 2342 | using_default = TRUE; |
| 2343 | |
| 2344 | /* look for the current name, then remember the name before */ |
| 2345 | /* and find the next name */ |
| 2346 | while (((dir = path.next()) != NULL) && !finished) |
| 2347 | { |
| 2348 | int length = strlen(dir->name); |
| 2349 | |
| 2350 | /* look for files ending in .png with a name not larger then 9 chars*/ |
| 2351 | if ((length > 4) && (length <= CROSSHAIR_PIC_NAME_LENGTH + 4) && |
| 2352 | dir->name[length - 4] == '.' && |
| 2353 | tolower((UINT8)dir->name[length - 3]) == 'p' && |
| 2354 | tolower((UINT8)dir->name[length - 2]) == 'n' && |
| 2355 | tolower((UINT8)dir->name[length - 1]) == 'g') |
| 2356 | |
| 2357 | { |
| 2358 | /* remove .png from length */ |
| 2359 | length -= 4; |
| 2360 | |
| 2361 | if (found || using_default) |
| 2362 | { |
| 2363 | /* get the next name */ |
| 2364 | strncpy(data->next_name, dir->name, length); |
| 2365 | data->next_name[length] = 0; |
| 2366 | finished = TRUE; |
| 2367 | } |
| 2368 | else if (!strncmp(dir->name, settings.name, length)) |
| 2369 | { |
| 2370 | /* we found the current name */ |
| 2371 | /* so loop once more to find the next name */ |
| 2372 | found = TRUE; |
| 2373 | } |
| 2374 | else |
| 2375 | /* remember last name */ |
| 2376 | /* we will do it here in case files get added to the directory */ |
| 2377 | { |
| 2378 | strncpy(data->last_name, dir->name, length); |
| 2379 | data->last_name[length] = 0; |
| 2380 | } |
| 2381 | } |
| 2382 | } |
| 2383 | /* if name not found then next item is DEFAULT */ |
| 2384 | if (!found && !using_default) |
| 2385 | { |
| 2386 | data->next_name[0] = 0; |
| 2387 | finished = TRUE; |
| 2388 | } |
| 2389 | /* setup the selection flags */ |
| 2390 | flags = 0; |
| 2391 | if (finished) |
| 2392 | flags |= MENU_FLAG_RIGHT_ARROW; |
| 2393 | if (found) |
| 2394 | flags |= MENU_FLAG_LEFT_ARROW; |
| 2395 | |
| 2396 | /* add CROSSHAIR_ITEM_PIC menu */ |
| 2397 | sprintf(temp_text, "P%d Crosshair", player + 1); |
| 2398 | menu->item_append(temp_text, using_default ? "DEFAULT" : settings.name, flags, data); |
| 2399 | } |
| 2400 | } |
| 2401 | if (use_auto) |
| 2402 | { |
| 2403 | /* any player can be used to get the autotime */ |
| 2404 | crosshair_get_user_settings(machine, 0, &settings); |
| 2405 | |
| 2406 | /* CROSSHAIR_ITEM_AUTO_TIME - allocate a data item and fill it */ |
| 2407 | data = (crosshair_item_data *)menu->m_pool_alloc(sizeof(*data)); |
| 2408 | data->type = CROSSHAIR_ITEM_AUTO_TIME; |
| 2409 | data->min = CROSSHAIR_VISIBILITY_AUTOTIME_MIN; |
| 2410 | data->max = CROSSHAIR_VISIBILITY_AUTOTIME_MAX; |
| 2411 | data->defvalue = CROSSHAIR_VISIBILITY_AUTOTIME_DEFAULT; |
| 2412 | data->cur = settings.auto_time; |
| 2413 | |
| 2414 | /* put on arrows in visible menu */ |
| 2415 | if (data->cur > data->min) |
| 2416 | flags |= MENU_FLAG_LEFT_ARROW; |
| 2417 | if (data->cur < data->max) |
| 2418 | flags |= MENU_FLAG_RIGHT_ARROW; |
| 2419 | |
| 2420 | /* add CROSSHAIR_ITEM_AUTO_TIME menu */ |
| 2421 | sprintf(temp_text, "%d", settings.auto_time); |
| 2422 | menu->item_append("Visible Delay", temp_text, flags, data); |
| 2423 | } |
| 2424 | // else |
| 2425 | // /* leave a blank filler line when not in auto time so size does not rescale */ |
| 2426 | // menu->item_append("", "", NULL, NULL); |
| 2427 | } |
| 2428 | |
| 2429 | |
| 2430 | /*------------------------------------------------- |
| 2431 | menu_quit_game - handle the "menu" for |
| 2432 | quitting the game |
| 2433 | -------------------------------------------------*/ |
| 2434 | |
| 2435 | static void menu_quit_game(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2436 | { |
| 2437 | /* request a reset */ |
| 2438 | machine.schedule_exit(); |
| 2439 | |
| 2440 | /* reset the menu stack */ |
| 2441 | ui_menu::stack_reset(machine); |
| 2442 | } |
| 2443 | |
| 2444 | |
| 2445 | /*------------------------------------------------- |
| 2446 | menu_select_game - handle the game select |
| 2447 | menu |
| 2448 | -------------------------------------------------*/ |
| 2449 | |
| 2450 | static void menu_select_game(running_machine &machine, ui_menu *menu, void *parameter, void *state) |
| 2451 | { |
| 2452 | select_game_state *menustate; |
| 2453 | const ui_menu_event *menu_event; |
| 2454 | |
| 2455 | /* if no state, allocate some */ |
| 2456 | if (state == NULL) |
| 2457 | { |
| 2458 | state = menu->alloc_state(sizeof(*menustate) + sizeof(menustate->driverlist) * driver_list::total(), NULL); |
| 2459 | if (parameter != NULL) |
| 2460 | strcpy(((select_game_state *)state)->search, (const char *)parameter); |
| 2461 | ((select_game_state *)state)->matchlist[0] = -1; |
| 2462 | } |
| 2463 | menustate = (select_game_state *)state; |
| 2464 | |
| 2465 | /* if the menu isn't built, populate now */ |
| 2466 | if (!menu->populated()) |
| 2467 | menu_select_game_populate(machine, menu, menustate); |
| 2468 | |
| 2469 | /* ignore pause keys by swallowing them before we process the menu */ |
| 2470 | ui_input_pressed(machine, IPT_UI_PAUSE); |
| 2471 | |
| 2472 | /* process the menu */ |
| 2473 | menu_event = menu->process(0); |
| 2474 | if (menu_event != NULL && menu_event->itemref != NULL) |
| 2475 | { |
| 2476 | /* reset the error on any future menu_event */ |
| 2477 | if (menustate->error) |
| 2478 | menustate->error = FALSE; |
| 2479 | |
| 2480 | /* handle selections */ |
| 2481 | else if (menu_event->iptkey == IPT_UI_SELECT) |
| 2482 | { |
| 2483 | const game_driver *driver = (const game_driver *)menu_event->itemref; |
| 2484 | |
| 2485 | /* special case for configure inputs */ |
| 2486 | if ((FPTR)driver == 1) |
| 2487 | ui_menu::stack_push(ui_menu_alloc(menu->machine(), menu->container, menu_input_groups, NULL)); |
| 2488 | |
| 2489 | /* anything else is a driver */ |
| 2490 | else |
| 2491 | { |
| 2492 | // audit the game first to see if we're going to work |
| 2493 | driver_enumerator enumerator(machine.options(), *driver); |
| 2494 | enumerator.next(); |
| 2495 | media_auditor auditor(enumerator); |
| 2496 | media_auditor::summary summary = auditor.audit_media(AUDIT_VALIDATE_FAST); |
| 2497 | |
| 2498 | // if everything looks good, schedule the new driver |
| 2499 | if (summary == media_auditor::CORRECT || summary == media_auditor::BEST_AVAILABLE) |
| 2500 | { |
| 2501 | machine.schedule_new_driver(*driver); |
| 2502 | ui_menu::stack_reset(machine); |
| 2503 | } |
| 2504 | |
| 2505 | // otherwise, display an error |
| 2506 | else |
| 2507 | { |
| 2508 | menu->reset(UI_MENU_RESET_REMEMBER_REF); |
| 2509 | menustate->error = TRUE; |
| 2510 | } |
| 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | /* escape pressed with non-empty text clears the text */ |
| 2515 | else if (menu_event->iptkey == IPT_UI_CANCEL && menustate->search[0] != 0) |
| 2516 | { |
| 2517 | /* since we have already been popped, we must recreate ourself from scratch */ |
| 2518 | ui_menu::stack_push(ui_menu_alloc(menu->machine(), menu->container, menu_select_game, NULL)); |
| 2519 | } |
| 2520 | |
| 2521 | /* typed characters append to the buffer */ |
| 2522 | else if (menu_event->iptkey == IPT_SPECIAL) |
| 2523 | { |
| 2524 | int buflen = strlen(menustate->search); |
| 2525 | |
| 2526 | /* if it's a backspace and we can handle it, do so */ |
| 2527 | if ((menu_event->unichar == 8 || menu_event->unichar == 0x7f) && buflen > 0) |
| 2528 | { |
| 2529 | *(char *)utf8_previous_char(&menustate->search[buflen]) = 0; |
| 2530 | menustate->rerandomize = TRUE; |
| 2531 | menu->reset(UI_MENU_RESET_SELECT_FIRST); |
| 2532 | } |
| 2533 | |
| 2534 | /* if it's any other key and we're not maxed out, update */ |
| 2535 | else if (menu_event->unichar >= ' ' && menu_event->unichar < 0x7f) |
| 2536 | { |
| 2537 | buflen += utf8_from_uchar(&menustate->search[buflen], ARRAY_LENGTH(menustate->search) - buflen, menu_event->unichar); |
| 2538 | menustate->search[buflen] = 0; |
| 2539 | menu->reset(UI_MENU_RESET_SELECT_FIRST); |
| 2540 | } |
| 2541 | } |
| 2542 | } |
| 2543 | |
| 2544 | /* if we're in an error state, overlay an error message */ |
| 2545 | if (menustate->error) |
| 2546 | ui_draw_text_box(&machine.render().ui_container(), |
| 2547 | "The selected game is missing one or more required ROM or CHD images. " |
| 2548 | "Please select a different game.\n\nPress any key to continue.", |
| 2549 | JUSTIFY_CENTER, 0.5f, 0.5f, UI_RED_COLOR); |
| 2550 | } |
| 2551 | |
| 2552 | |
| 2553 | /*------------------------------------------------- |
| 2554 | menu_select_game_populate - populate the game |
| 2555 | select menu |
| 2556 | -------------------------------------------------*/ |
| 2557 | |
| 2558 | static void menu_select_game_populate(running_machine &machine, ui_menu *menu, select_game_state *menustate) |
| 2559 | { |
| 2560 | int matchcount; |
| 2561 | int curitem; |
| 2562 | |
| 2563 | /* update our driver list if necessary */ |
| 2564 | if (menustate->driverlist[0] == NULL) |
| 2565 | menu_select_game_build_driver_list(menu, menustate); |
| 2566 | for (curitem = matchcount = 0; menustate->driverlist[curitem] != NULL && matchcount < VISIBLE_GAMES_IN_LIST; curitem++) |
| 2567 | if (!(menustate->driverlist[curitem]->flags & GAME_NO_STANDALONE)) |
| 2568 | matchcount++; |
| 2569 | |
| 2570 | /* if nothing there, add a single multiline item and return */ |
| 2571 | if (matchcount == 0) |
| 2572 | { |
| 2573 | astring txt; |
| 2574 | txt.printf("No %s found. Please check the rompath specified in the %s.ini file.\n\n" |
| 2575 | "If this is your first time using %s, please see the config.txt file in " |
| 2576 | "the docs directory for information on configuring %s.", |
| 2577 | emulator_info::get_gamesnoun(), |
| 2578 | emulator_info::get_configname(), |
| 2579 | emulator_info::get_appname(),emulator_info::get_appname() ); |
| 2580 | menu->item_append(txt.cstr(), NULL, MENU_FLAG_MULTILINE | MENU_FLAG_REDTEXT, NULL); |
| 2581 | return; |
| 2582 | } |
| 2583 | |
| 2584 | /* otherwise, rebuild the match list */ |
| 2585 | assert(drivlist != NULL); |
| 2586 | if (menustate->search[0] != 0 || menustate->matchlist[0] == -1 || menustate->rerandomize) |
| 2587 | drivlist->find_approximate_matches(menustate->search, matchcount, menustate->matchlist); |
| 2588 | menustate->rerandomize = FALSE; |
| 2589 | |
| 2590 | /* iterate over entries */ |
| 2591 | for (curitem = 0; curitem < matchcount; curitem++) |
| 2592 | { |
| 2593 | int curmatch = menustate->matchlist[curitem]; |
| 2594 | if (curmatch != -1) |
| 2595 | { |
| 2596 | int cloneof = drivlist->non_bios_clone(curmatch); |
| 2597 | menu->item_append(drivlist->driver(curmatch).name, drivlist->driver(curmatch).description, (cloneof == -1) ? 0 : MENU_FLAG_INVERT, (void *)&drivlist->driver(curmatch)); |
| 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | /* if we're forced into this, allow general input configuration as well */ |
| 2602 | if (ui_menu::stack_has_special_main_menu()) |
| 2603 | { |
| 2604 | menu->item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL); |
| 2605 | menu->item_append("Configure General Inputs", NULL, 0, (void *)1); |
| 2606 | } |
| 2607 | |
| 2608 | /* configure the custom rendering */ |
| 2609 | 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); |
| 2610 | } |
| 2611 | |
| 2612 | |
| 2613 | /*------------------------------------------------- |
| 2614 | menu_select_game_build_driver_list - build a |
| 2615 | list of available drivers |
| 2616 | -------------------------------------------------*/ |
| 2617 | |
| 2618 | static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state *menustate) |
| 2619 | { |
| 2620 | // start with an empty list |
| 2621 | // hack alert: use new directly here to avoid reporting this one-time static memory as unfreed |
| 2622 | if (drivlist == NULL) |
| 2623 | drivlist = global_alloc(driver_enumerator(menu->machine().options())); |
| 2624 | drivlist->exclude_all(); |
| 2625 | |
| 2626 | /* open a path to the ROMs and find them in the array */ |
| 2627 | file_enumerator path(menu->machine().options().media_path()); |
| 2628 | const osd_directory_entry *dir; |
| 2629 | |
| 2630 | /* iterate while we get new objects */ |
| 2631 | while ((dir = path.next()) != NULL) |
| 2632 | { |
| 2633 | char drivername[50]; |
| 2634 | char *dst = drivername; |
| 2635 | const char *src; |
| 2636 | |
| 2637 | /* build a name for it */ |
| 2638 | for (src = dir->name; *src != 0 && *src != '.' && dst < &drivername[ARRAY_LENGTH(drivername) - 1]; src++) |
| 2639 | *dst++ = tolower((UINT8)*src); |
| 2640 | *dst = 0; |
| 2641 | |
| 2642 | int drivnum = drivlist->find(drivername); |
| 2643 | if (drivnum != -1) |
| 2644 | drivlist->include(drivnum); |
| 2645 | } |
| 2646 | |
| 2647 | /* now build the final list */ |
| 2648 | drivlist->reset(); |
| 2649 | int listnum = 0; |
| 2650 | while (drivlist->next()) |
| 2651 | menustate->driverlist[listnum++] = &drivlist->driver(); |
| 2652 | |
| 2653 | /* NULL-terminate */ |
| 2654 | menustate->driverlist[listnum] = NULL; |
| 2655 | } |
| 2656 | |
| 2657 | |
| 2658 | /*------------------------------------------------- |
| 2659 | menu_select_game_custom_render - perform our |
| 2660 | special rendering |
| 2661 | -------------------------------------------------*/ |
| 2662 | |
| 2663 | static 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) |
| 2664 | { |
| 2665 | select_game_state *menustate = (select_game_state *)state; |
| 2666 | const game_driver *driver; |
| 2667 | float width, maxwidth; |
| 2668 | float x1, y1, x2, y2; |
| 2669 | char tempbuf[4][256]; |
| 2670 | rgb_t color; |
| 2671 | int line; |
| 2672 | |
| 2673 | /* display the current typeahead */ |
| 2674 | if (menustate->search[0] != 0) |
| 2675 | sprintf(&tempbuf[0][0], "Type name or select: %s_", menustate->search); |
| 2676 | else |
| 2677 | sprintf(&tempbuf[0][0], "Type name or select: (random)"); |
| 2678 | |
| 2679 | /* get the size of the text */ |
| 2680 | ui_draw_text_full(&machine.render().ui_container(), &tempbuf[0][0], 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE, |
| 2681 | DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &width, NULL); |
| 2682 | width += 2 * UI_BOX_LR_BORDER; |
| 2683 | maxwidth = MAX(width, origx2 - origx1); |
| 2684 | |
| 2685 | /* compute our bounds */ |
| 2686 | x1 = 0.5f - 0.5f * maxwidth; |
| 2687 | x2 = x1 + maxwidth; |
| 2688 | y1 = origy1 - top; |
| 2689 | y2 = origy1 - UI_BOX_TB_BORDER; |
| 2690 | |
| 2691 | /* draw a box */ |
| 2692 | ui_draw_outlined_box(&machine.render().ui_container(), x1, y1, x2, y2, UI_BACKGROUND_COLOR); |
| 2693 | |
| 2694 | /* take off the borders */ |
| 2695 | x1 += UI_BOX_LR_BORDER; |
| 2696 | x2 -= UI_BOX_LR_BORDER; |
| 2697 | y1 += UI_BOX_TB_BORDER; |
| 2698 | y2 -= UI_BOX_TB_BORDER; |
| 2699 | |
| 2700 | /* draw the text within it */ |
| 2701 | ui_draw_text_full(&machine.render().ui_container(), &tempbuf[0][0], x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_TRUNCATE, |
| 2702 | DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, NULL, NULL); |
| 2703 | |
| 2704 | /* determine the text to render below */ |
| 2705 | driver = ((FPTR)selectedref > 1) ? (const game_driver *)selectedref : NULL; |
| 2706 | if ((FPTR)driver > 1) |
| 2707 | { |
| 2708 | const char *gfxstat, *soundstat; |
| 2709 | |
| 2710 | /* first line is game name */ |
| 2711 | sprintf(&tempbuf[0][0], "%-.100s", driver->description); |
| 2712 | |
| 2713 | /* next line is year, manufacturer */ |
| 2714 | sprintf(&tempbuf[1][0], "%s, %-.100s", driver->year, driver->manufacturer); |
| 2715 | |
| 2716 | /* next line is overall driver status */ |
| 2717 | if (driver->flags & GAME_NOT_WORKING) |
| 2718 | strcpy(&tempbuf[2][0], "Overall: NOT WORKING"); |
| 2719 | else if (driver->flags & GAME_UNEMULATED_PROTECTION) |
| 2720 | strcpy(&tempbuf[2][0], "Overall: Unemulated Protection"); |
| 2721 | else |
| 2722 | strcpy(&tempbuf[2][0], "Overall: Working"); |
| 2723 | |
| 2724 | /* next line is graphics, sound status */ |
| 2725 | if (driver->flags & (GAME_IMPERFECT_GRAPHICS | GAME_WRONG_COLORS | GAME_IMPERFECT_COLORS)) |
| 2726 | gfxstat = "Imperfect"; |
| 2727 | else |
| 2728 | gfxstat = "OK"; |
| 2729 | |
| 2730 | if (driver->flags & GAME_NO_SOUND) |
| 2731 | soundstat = "Unimplemented"; |
| 2732 | else if (driver->flags & GAME_IMPERFECT_SOUND) |
| 2733 | soundstat = "Imperfect"; |
| 2734 | else |
| 2735 | soundstat = "OK"; |
| 2736 | |
| 2737 | sprintf(&tempbuf[3][0], "Gfx: %s, Sound: %s", gfxstat, soundstat); |
| 2738 | } |
| 2739 | else |
| 2740 | { |
| 2741 | const char *s = emulator_info::get_copyright(); |
| 2742 | line = 0; |
| 2743 | int col = 0; |
| 2744 | |
| 2745 | /* first line is version string */ |
| 2746 | sprintf(&tempbuf[line++][0], "%s %s", emulator_info::get_applongname(), build_version); |
| 2747 | |
| 2748 | /* output message */ |
| 2749 | while (line < ARRAY_LENGTH(tempbuf)) |
| 2750 | { |
| 2751 | if (*s == 0 || *s == '\n') |
| 2752 | { |
| 2753 | tempbuf[line++][col] = 0; |
| 2754 | col = 0; |
| 2755 | } |
| 2756 | else |
| 2757 | tempbuf[line][col++] = *s; |
| 2758 | |
| 2759 | if (*s != 0) |
| 2760 | s++; |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | /* get the size of the text */ |
| 2765 | maxwidth = origx2 - origx1; |
| 2766 | for (line = 0; line < 4; line++) |
| 2767 | { |
| 2768 | ui_draw_text_full(&machine.render().ui_container(), &tempbuf[line][0], 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE, |
| 2769 | DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &width, NULL); |
| 2770 | width += 2 * UI_BOX_LR_BORDER; |
| 2771 | maxwidth = MAX(maxwidth, width); |
| 2772 | } |
| 2773 | |
| 2774 | /* compute our bounds */ |
| 2775 | x1 = 0.5f - 0.5f * maxwidth; |
| 2776 | x2 = x1 + maxwidth; |
| 2777 | y1 = origy2 + UI_BOX_TB_BORDER; |
| 2778 | y2 = origy2 + bottom; |
| 2779 | |
| 2780 | /* draw a box */ |
| 2781 | color = UI_BACKGROUND_COLOR; |
| 2782 | if (driver != NULL) |
| 2783 | color = UI_GREEN_COLOR; |
| 2784 | if (driver != NULL && (driver->flags & (GAME_IMPERFECT_GRAPHICS | GAME_WRONG_COLORS | GAME_IMPERFECT_COLORS | GAME_NO_SOUND | GAME_IMPERFECT_SOUND)) != 0) |
| 2785 | color = UI_YELLOW_COLOR; |
| 2786 | if (driver != NULL && (driver->flags & (GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION)) != 0) |
| 2787 | color = UI_RED_COLOR; |
| 2788 | ui_draw_outlined_box(&machine.render().ui_container(), x1, y1, x2, y2, color); |
| 2789 | |
| 2790 | /* take off the borders */ |
| 2791 | x1 += UI_BOX_LR_BORDER; |
| 2792 | x2 -= UI_BOX_LR_BORDER; |
| 2793 | y1 += UI_BOX_TB_BORDER; |
| 2794 | y2 -= UI_BOX_TB_BORDER; |
| 2795 | |
| 2796 | /* draw all lines */ |
| 2797 | for (line = 0; line < 4; line++) |
| 2798 | { |
| 2799 | ui_draw_text_full(&machine.render().ui_container(), &tempbuf[line][0], x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_TRUNCATE, |
| 2800 | DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, NULL, NULL); |
| 2801 | y1 += ui_get_line_height(machine); |
| 2802 | } |
| 2803 | } |
| 2804 | |
| 2805 | |
| 2806 | |