summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/input
diff options
context:
space:
mode:
author Vas Crabb <cuavas@users.noreply.github.com>2022-06-11 21:47:19 +1000
committer GitHub <noreply@github.com>2022-06-11 21:47:19 +1000
commitf47f9c3db3c7d20bea0526425cdbc469d5a10868 (patch)
tree4dd7ac860eb10169b511521eecb31b8760011434 /src/osd/modules/input
parent5214d7f31c6e682315a7803484ade265130cfb6b (diff)
ui, docs: Added menus to fill a couple of gaps, improved consistency. (#9915)
Added menus for controlling toggle inputs, and showing recognised input devices and control state. Moved input menu options off main menu to a submenu, as there are a lot of them now. Moved menu heading drawing into base class, added headings to more menus, and made headings more consistent with the menu items used to reach them. Also made terminology more consistent. Changed the default names for buttons and hat switches/D-pads to use 1-based numbering. DirectInput still returns 0-based button numbers for some devices. Removed local copy of MinGW xaudio2.h as it’s now included in the MSYS2 package. Also fixed building the DirectSound sound output module with the SDL OSD on Windows - the Windows headers are sensitive to include order. Started adding documentation for menus, to hopefully help people find menus they remember seeing but can't recall how to access. For translators, this makes terminology more consistent. In particular: * "Settings" is preferred over "configuration" in a number of places, as the latter can be construed as referring specifically to settings stored in .cfg files in the cfg_directory folder. Also, references to saving machine configuration could be interpreted as relating to the settings on the "Machine Configuration" menu. * The controls on host input devices (e.g. keys, buttons, joystick axes) are referred to as "controls", while emulated inputs are referred to as "inputs". * The menus for assigning host controls to emulated inputs are called "input assignments" menus to distinguish them from other input settings menus. * Combinations of controls that can be assigned to emulated inputs are referred to as "combinations" rather than "sequences". * The potentially confusing term "ROM set" has been removed altogether. Use "short name" to refer to a device or system's identifier. * "System" is used in almost places to refer to a complete, runnable system rather than "Machine". * "Driver" is now only used to refer to source files where systems or devices are defined - it is no longer used to refer to individual systems. * A few more menus have message context for the messages. This makes it a bit easier to guess where the messages are used. It also means you can use different translations in different places if necessary (e.g. if the same English text should be translated differently as an item in one menu and as a heading in another).
Diffstat (limited to 'src/osd/modules/input')
-rw-r--r--src/osd/modules/input/input_common.h18
-rw-r--r--src/osd/modules/input/input_dinput.cpp30
-rw-r--r--src/osd/modules/input/input_sdl.cpp8
3 files changed, 23 insertions, 33 deletions
diff --git a/src/osd/modules/input/input_common.h b/src/osd/modules/input/input_common.h
index a26d6f5375e..c030d8f17b2 100644
--- a/src/osd/modules/input/input_common.h
+++ b/src/osd/modules/input/input_common.h
@@ -333,7 +333,7 @@ public:
}
template <typename TActual, typename... TArgs>
- TActual &create_device(running_machine &machine, std::string &&name, std::string &&id, input_module &module, TArgs&&... args)
+ TActual &create_device(running_machine &machine, std::string &&name, std::string &&id, input_module &module, TArgs &&... args)
{
// allocate the device object
auto devinfo = std::make_unique<TActual>(machine, std::move(name), std::move(id), module, std::forward<TArgs>(args)...);
@@ -342,7 +342,7 @@ public:
}
template <typename TActual>
- TActual &add_device(running_machine &machine, std::unique_ptr<TActual> devinfo)
+ TActual &add_device(running_machine &machine, std::unique_ptr<TActual> &&devinfo)
{
// Add the device to the machine
devinfo->m_device = &machine.input().device_class(devinfo->deviceclass()).add_device(devinfo->name(), devinfo->id(), devinfo.get());
@@ -510,7 +510,7 @@ public:
protected:
virtual int init_internal() { return 0; }
virtual bool should_poll_devices(running_machine &machine) = 0;
- virtual void before_poll(running_machine &machine) {}
+ virtual void before_poll(running_machine &machine) { }
};
template <class TItem>
@@ -539,22 +539,18 @@ int generic_axis_get_state(void *device_internal, void *item_internal)
// default_button_name
//============================================================
-inline const char *default_button_name(int which)
+inline std::string default_button_name(int which)
{
- static char buffer[20];
- snprintf(buffer, std::size(buffer), "B%d", which);
- return buffer;
+ return util::string_format("Button %d", which + 1);
}
//============================================================
// default_pov_name
//============================================================
-inline const char *default_pov_name(int which)
+inline std::string default_pov_name(int which)
{
- static char buffer[20];
- snprintf(buffer, std::size(buffer), "POV%d", which);
- return buffer;
+ return util::string_format("Hat %d", which + 1);
}
// default axis names
diff --git a/src/osd/modules/input/input_dinput.cpp b/src/osd/modules/input/input_dinput.cpp
index c6a9d17afb9..fa273e5fdb1 100644
--- a/src/osd/modules/input/input_dinput.cpp
+++ b/src/osd/modules/input/input_dinput.cpp
@@ -115,7 +115,7 @@ public:
fatalerror("DirectInput: Unable to enumerate devices (result=%08X)\n", uint32_t(result));
}
- static std::string device_item_name(dinput_device * devinfo, int offset, const char * defstring, const TCHAR * suffix)
+ static std::string device_item_name(dinput_device *devinfo, int offset, const char *defstring, const char *suffix)
{
DIDEVICEOBJECTINSTANCE instance = { 0 };
HRESULT result;
@@ -131,21 +131,19 @@ public:
return nullptr;
// Return the default value
- return std::string(defstring);
+ std::string result(defstring);
+ if (suffix)
+ result.append(" ").append(suffix);
+ return result;
}
// convert the name to utf8
std::string namestring = osd::text::from_tstring(instance.tszName);
// if no suffix, return as-is
- if (suffix == nullptr)
- return namestring;
-
- // convert the suffix to utf8
- std::string suffix_utf8 = osd::text::from_tstring(suffix);
-
- // Concat the name and suffix
- return namestring + " " + suffix_utf8;
+ if (suffix)
+ namestring.append(" ").append(suffix);
+ return namestring;
}
protected:
@@ -251,7 +249,7 @@ public:
auto offset = reinterpret_cast<uintptr_t>(&static_cast<DIMOUSESTATE *>(nullptr)->rgbButtons[butnum]);
// add to the mouse device
- std::string name = device_item_name(devinfo, offset, default_button_name(butnum), nullptr);
+ std::string name = device_item_name(devinfo, offset, default_button_name(butnum).c_str(), nullptr);
devinfo->device()->add_item(
name,
static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum),
@@ -494,19 +492,19 @@ int dinput_joystick_device::configure()
std::string name;
// left
- name = dinput_module::device_item_name(this, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum), TEXT("L"));
+ name = dinput_module::device_item_name(this, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum).c_str(), "Left");
device()->add_item(name, ITEM_ID_OTHER_SWITCH, dinput_joystick_pov_get_state, reinterpret_cast<void *>(static_cast<uintptr_t>(povnum * 4 + POVDIR_LEFT)));
// right
- name = dinput_module::device_item_name(this, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum), TEXT("R"));
+ name = dinput_module::device_item_name(this, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum).c_str(), "Right");
device()->add_item(name, ITEM_ID_OTHER_SWITCH, dinput_joystick_pov_get_state, reinterpret_cast<void *>(static_cast<uintptr_t>(povnum * 4 + POVDIR_RIGHT)));
// up
- name = dinput_module::device_item_name(this, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum), TEXT("U"));
+ name = dinput_module::device_item_name(this, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum).c_str(), "Up");
device()->add_item(name, ITEM_ID_OTHER_SWITCH, dinput_joystick_pov_get_state, reinterpret_cast<void *>(static_cast<uintptr_t>(povnum * 4 + POVDIR_UP)));
// down
- name = dinput_module::device_item_name(this, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum), TEXT("D"));
+ name = dinput_module::device_item_name(this, offsetof(DIJOYSTATE2, rgdwPOV) + povnum * sizeof(DWORD), default_pov_name(povnum).c_str(), "Down");
device()->add_item(name, ITEM_ID_OTHER_SWITCH, dinput_joystick_pov_get_state, reinterpret_cast<void *>(static_cast<uintptr_t>(povnum * 4 + POVDIR_DOWN)));
}
@@ -514,7 +512,7 @@ int dinput_joystick_device::configure()
for (uint32_t butnum = 0; butnum < dinput.caps.dwButtons; butnum++)
{
auto offset = reinterpret_cast<uintptr_t>(&static_cast<DIJOYSTATE2 *>(nullptr)->rgbButtons[butnum]);
- std::string name = dinput_module::device_item_name(this, offset, default_button_name(butnum), nullptr);
+ std::string name = dinput_module::device_item_name(this, offset, default_button_name(butnum).c_str(), nullptr);
input_item_id itemid;
diff --git a/src/osd/modules/input/input_sdl.cpp b/src/osd/modules/input/input_sdl.cpp
index 4c5f99680f5..73d722525fa 100644
--- a/src/osd/modules/input/input_sdl.cpp
+++ b/src/osd/modules/input/input_sdl.cpp
@@ -965,10 +965,7 @@ public:
for (int button = 0; button < 4; button++)
{
input_item_id itemid = (input_item_id)(ITEM_ID_BUTTON1 + button);
- char defname[20];
- snprintf(defname, sizeof(defname), "B%d", button + 1);
-
- devinfo.device()->add_item(defname, itemid, generic_button_get_state<std::int32_t>, &devinfo.mouse.buttons[button]);
+ devinfo.device()->add_item(default_button_name(button), itemid, generic_button_get_state<std::int32_t>, &devinfo.mouse.buttons[button]);
}
osd_printf_verbose("Mouse: Registered %s\n", devinfo.name());
@@ -1144,8 +1141,7 @@ public:
else
itemid = ITEM_ID_OTHER_SWITCH;
- snprintf(tempname, sizeof(tempname), "Button %d", button + 1);
- devinfo->device()->add_item(tempname, itemid, generic_button_get_state<std::int32_t>, &devinfo->joystick.buttons[button]);
+ devinfo->device()->add_item(default_button_name(button), itemid, generic_button_get_state<std::int32_t>, &devinfo->joystick.buttons[button]);
}
// loop over all hats