mirror of
https://github.com/holub/mame
synced 2025-07-08 11:21:56 +03:00
Cleanups to src/frontend/mame/ui/slotopt.[cpp|h]
Did the following: 1. Polished up residual traces of this code's pre-C++ heritage 2. Moved completely private code to an anonymous namespace 3. Created device_slot_interface::slot_name() to wrap the pattern of taking the tag and removing the initial colon
This commit is contained in:
parent
ec51a23602
commit
1a8a7c810d
@ -145,6 +145,7 @@ public:
|
||||
virtual std::string get_default_card_software(get_default_card_software_hook &hook) const { return std::string(); }
|
||||
device_t *get_card_device() { return m_card_device; }
|
||||
void set_card_device(device_t *dev) { m_card_device = dev; }
|
||||
const char *slot_name() const { return device().tag() + 1; }
|
||||
|
||||
private:
|
||||
// internal state
|
||||
|
@ -18,56 +18,22 @@
|
||||
#include "mameopts.h"
|
||||
|
||||
|
||||
namespace ui {
|
||||
/*-------------------------------------------------
|
||||
slot_get_current_option - returns
|
||||
-------------------------------------------------*/
|
||||
device_slot_option *menu_slot_devices::slot_get_current_option(device_slot_interface &slot)
|
||||
{
|
||||
std::string current;
|
||||
/***************************************************************************
|
||||
UTILITY
|
||||
***************************************************************************/
|
||||
|
||||
const char *slot_option_name = slot.device().tag() + 1;
|
||||
if (!slot.fixed() && machine().options().slot_options().count(slot_option_name) > 0)
|
||||
{
|
||||
current = machine().options().slot_options()[slot_option_name].value();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (slot.default_option() == nullptr)
|
||||
return nullptr;
|
||||
current.assign(slot.default_option());
|
||||
}
|
||||
namespace {
|
||||
|
||||
return slot.option(current.c_str());
|
||||
}
|
||||
// constants
|
||||
void *ITEMREF_RESET = ((void *)1);
|
||||
char DIVIDER[] = "------";
|
||||
|
||||
/*-------------------------------------------------
|
||||
slot_get_current_index - returns
|
||||
-------------------------------------------------*/
|
||||
int menu_slot_devices::slot_get_current_index(device_slot_interface &slot)
|
||||
{
|
||||
const device_slot_option *current = slot_get_current_option(slot);
|
||||
|
||||
if (current != nullptr)
|
||||
{
|
||||
int val = 0;
|
||||
for (auto &option : slot.option_list())
|
||||
{
|
||||
if (option.second.get() == current)
|
||||
return val;
|
||||
//-------------------------------------------------
|
||||
// get_slot_length
|
||||
//-------------------------------------------------
|
||||
|
||||
if (option.second->selectable())
|
||||
val++;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
slot_get_length - returns
|
||||
-------------------------------------------------*/
|
||||
int menu_slot_devices::slot_get_length(device_slot_interface &slot)
|
||||
int get_slot_length(const device_slot_interface &slot)
|
||||
{
|
||||
int val = 0;
|
||||
for (auto &option : slot.option_list())
|
||||
@ -77,44 +43,12 @@ int menu_slot_devices::slot_get_length(device_slot_interface &slot)
|
||||
return val;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
slot_get_next - returns
|
||||
-------------------------------------------------*/
|
||||
const char *menu_slot_devices::slot_get_next(device_slot_interface &slot)
|
||||
{
|
||||
int idx = slot_get_current_index(slot);
|
||||
if (idx < 0)
|
||||
idx = 0;
|
||||
else
|
||||
idx++;
|
||||
|
||||
if (idx >= slot_get_length(slot))
|
||||
return "";
|
||||
//-------------------------------------------------
|
||||
// get_slot_option
|
||||
//-------------------------------------------------
|
||||
|
||||
return slot_get_option(slot, idx);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
slot_get_prev - returns
|
||||
-------------------------------------------------*/
|
||||
const char *menu_slot_devices::slot_get_prev(device_slot_interface &slot)
|
||||
{
|
||||
int idx = slot_get_current_index(slot);
|
||||
if (idx < 0)
|
||||
idx = slot_get_length(slot) - 1;
|
||||
else
|
||||
idx--;
|
||||
|
||||
if (idx < 0)
|
||||
return "";
|
||||
|
||||
return slot_get_option(slot, idx);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
slot_get_option - returns
|
||||
-------------------------------------------------*/
|
||||
const char *menu_slot_devices::slot_get_option(device_slot_interface &slot, int index)
|
||||
const char *get_slot_option(device_slot_interface &slot, int index)
|
||||
{
|
||||
if (index >= 0)
|
||||
{
|
||||
@ -132,28 +66,135 @@ const char *menu_slot_devices::slot_get_option(device_slot_interface &slot, int
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
/***************************************************************************
|
||||
SLOT MENU
|
||||
***************************************************************************/
|
||||
|
||||
/*-------------------------------------------------
|
||||
set_use_natural_keyboard - specifies
|
||||
whether the natural keyboard is active
|
||||
-------------------------------------------------*/
|
||||
namespace ui {
|
||||
|
||||
void menu_slot_devices::set_slot_device(device_slot_interface &slot, const char *val)
|
||||
{
|
||||
std::string error;
|
||||
machine().options().set_value(slot.device().tag()+1, val, OPTION_PRIORITY_CMDLINE, error);
|
||||
assert(error.empty());
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
menu_slot_devices_populate - populates the main
|
||||
slot device menu
|
||||
-------------------------------------------------*/
|
||||
//-------------------------------------------------
|
||||
// menu_slot_devices constructor
|
||||
//-------------------------------------------------
|
||||
|
||||
menu_slot_devices::menu_slot_devices(mame_ui_manager &mui, render_container &container) : menu(mui, container)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// menu_slot_devices destructor
|
||||
//-------------------------------------------------
|
||||
|
||||
menu_slot_devices::~menu_slot_devices()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// get_current_option - returns the current
|
||||
// slot option
|
||||
//-------------------------------------------------
|
||||
|
||||
device_slot_option *menu_slot_devices::get_current_option(device_slot_interface &slot) const
|
||||
{
|
||||
std::string current;
|
||||
|
||||
const char *slot_option_name = slot.slot_name();
|
||||
if (!slot.fixed() && machine().options().slot_options().count(slot_option_name) > 0)
|
||||
{
|
||||
current = machine().options().slot_options()[slot_option_name].value();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (slot.default_option() == nullptr)
|
||||
return nullptr;
|
||||
current.assign(slot.default_option());
|
||||
}
|
||||
|
||||
return slot.option(current.c_str());
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// get_current_index
|
||||
//-------------------------------------------------
|
||||
|
||||
int menu_slot_devices::get_current_index(device_slot_interface &slot) const
|
||||
{
|
||||
const device_slot_option *current = get_current_option(slot);
|
||||
|
||||
if (current != nullptr)
|
||||
{
|
||||
int val = 0;
|
||||
for (auto &option : slot.option_list())
|
||||
{
|
||||
if (option.second.get() == current)
|
||||
return val;
|
||||
|
||||
if (option.second->selectable())
|
||||
val++;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// get_next_slot
|
||||
//-------------------------------------------------
|
||||
|
||||
const char *menu_slot_devices::get_next_slot(device_slot_interface &slot) const
|
||||
{
|
||||
int idx = get_current_index(slot);
|
||||
if (idx < 0)
|
||||
idx = 0;
|
||||
else
|
||||
idx++;
|
||||
|
||||
if (idx >= get_slot_length(slot))
|
||||
return "";
|
||||
|
||||
return get_slot_option(slot, idx);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// get_previous_slot
|
||||
//-------------------------------------------------
|
||||
|
||||
const char *menu_slot_devices::get_previous_slot(device_slot_interface &slot) const
|
||||
{
|
||||
int idx = get_current_index(slot);
|
||||
if (idx < 0)
|
||||
idx = get_slot_length(slot) - 1;
|
||||
else
|
||||
idx--;
|
||||
|
||||
if (idx < 0)
|
||||
return "";
|
||||
|
||||
return get_slot_option(slot, idx);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// set_slot_device
|
||||
//-------------------------------------------------
|
||||
|
||||
void menu_slot_devices::set_slot_device(device_slot_interface &slot, const char *val)
|
||||
{
|
||||
std::string error;
|
||||
machine().options().set_value(slot.slot_name(), val, OPTION_PRIORITY_CMDLINE, error);
|
||||
assert(error.empty());
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// populate
|
||||
//-------------------------------------------------
|
||||
|
||||
void menu_slot_devices::populate(float &customtop, float &custombottom)
|
||||
{
|
||||
// cycle through all devices for this system
|
||||
@ -163,8 +204,8 @@ void menu_slot_devices::populate(float &customtop, float &custombottom)
|
||||
bool has_selectable_options = slot.has_selectable_options();
|
||||
|
||||
// name this option
|
||||
std::string opt_name("------");
|
||||
const device_slot_option *option = slot_get_current_option(slot);
|
||||
std::string opt_name(DIVIDER);
|
||||
const device_slot_option *option = get_current_option(slot);
|
||||
if (option)
|
||||
{
|
||||
opt_name = has_selectable_options
|
||||
@ -177,28 +218,25 @@ void menu_slot_devices::populate(float &customtop, float &custombottom)
|
||||
? FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW
|
||||
: FLAG_DISABLE;
|
||||
|
||||
item_append(slot.device().tag() + 1, opt_name, item_flags, (void *)&slot);
|
||||
item_append(slot.slot_name(), opt_name, item_flags, (void *)&slot);
|
||||
}
|
||||
item_append(menu_item_type::SEPARATOR);
|
||||
item_append(_("Reset"), "", 0, (void *)1);
|
||||
item_append(_("Reset"), "", 0, ITEMREF_RESET);
|
||||
}
|
||||
|
||||
menu_slot_devices::~menu_slot_devices()
|
||||
{
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
menu_slot_devices - menu that
|
||||
-------------------------------------------------*/
|
||||
//-------------------------------------------------
|
||||
// handle
|
||||
//-------------------------------------------------
|
||||
|
||||
void menu_slot_devices::handle()
|
||||
{
|
||||
/* process the menu */
|
||||
// process the menu
|
||||
const event *menu_event = process(0);
|
||||
|
||||
if (menu_event != nullptr && menu_event->itemref != nullptr)
|
||||
{
|
||||
if ((uintptr_t)menu_event->itemref == 1 && menu_event->iptkey == IPT_UI_SELECT)
|
||||
if (menu_event->itemref == ITEMREF_RESET && menu_event->iptkey == IPT_UI_SELECT)
|
||||
{
|
||||
mame_options::add_slot_options(machine().options());
|
||||
machine().schedule_hard_reset();
|
||||
@ -206,14 +244,14 @@ void menu_slot_devices::handle()
|
||||
else if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)
|
||||
{
|
||||
device_slot_interface *slot = (device_slot_interface *)menu_event->itemref;
|
||||
const char *val = (menu_event->iptkey == IPT_UI_LEFT) ? slot_get_prev(*slot) : slot_get_next(*slot);
|
||||
const char *val = (menu_event->iptkey == IPT_UI_LEFT) ? get_previous_slot(*slot) : get_next_slot(*slot);
|
||||
set_slot_device(*slot, val);
|
||||
reset(reset_options::REMEMBER_REF);
|
||||
}
|
||||
else if (menu_event->iptkey == IPT_UI_SELECT)
|
||||
{
|
||||
device_slot_interface *slot = (device_slot_interface *)menu_event->itemref;
|
||||
device_slot_option *option = slot_get_current_option(*slot);
|
||||
device_slot_option *option = get_current_option(*slot);
|
||||
if (option)
|
||||
menu::stack_push<menu_device_config>(ui(), container(), slot, option);
|
||||
}
|
||||
|
@ -27,12 +27,10 @@ private:
|
||||
virtual void populate(float &customtop, float &custombottom) override;
|
||||
virtual void handle() override;
|
||||
|
||||
device_slot_option *slot_get_current_option(device_slot_interface &slot);
|
||||
int slot_get_current_index(device_slot_interface &slot);
|
||||
int slot_get_length(device_slot_interface &slot);
|
||||
const char *slot_get_next(device_slot_interface &slot);
|
||||
const char *slot_get_prev(device_slot_interface &slot);
|
||||
const char *slot_get_option(device_slot_interface &slot, int index);
|
||||
device_slot_option *get_current_option(device_slot_interface &slot) const;
|
||||
int get_current_index(device_slot_interface &slot) const;
|
||||
const char *get_next_slot(device_slot_interface &slot) const;
|
||||
const char *get_previous_slot(device_slot_interface &slot) const;
|
||||
void set_slot_device(device_slot_interface &slot, const char *val);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user