Added functions to get the platform dependent name for a joystick or game controller

This commit is contained in:
Sam Lantinga
2022-04-26 14:54:14 -07:00
parent b293888c7d
commit e551384a99
28 changed files with 306 additions and 26 deletions

View File

@@ -64,15 +64,15 @@ extern "C"
char name[B_OS_NAME_LENGTH];
/* Search for attached joysticks */
nports = joystick.CountDevices();
numjoysticks = 0;
SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport));
SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname));
nports = joystick.CountDevices();
numjoysticks = 0;
SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport));
SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname));
for (i = 0; (numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i)
{
if (joystick.GetDeviceName(i, name) == B_OK) {
if (joystick.Open(name) != B_ERROR) {
BString stick_name;
BString stick_name;
joystick.GetControllerName(&stick_name);
SDL_joyport[numjoysticks] = SDL_strdup(name);
SDL_joyname[numjoysticks] = SDL_CreateJoystickName(0, 0, NULL, stick_name.String());
@@ -93,12 +93,16 @@ extern "C"
{
}
/* Function to get the device-dependent name of a joystick */
static const char *HAIKU_JoystickGetDeviceName(int device_index)
{
return SDL_joyname[device_index];
}
static const char *HAIKU_JoystickGetDevicePath(int device_index)
{
return SDL_joyport[device_index];
}
static int HAIKU_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
@@ -298,6 +302,7 @@ extern "C"
HAIKU_JoystickGetCount,
HAIKU_JoystickDetect,
HAIKU_JoystickGetDeviceName,
HAIKU_JoystickGetDevicePath,
HAIKU_JoystickGetDevicePlayerIndex,
HAIKU_JoystickSetDevicePlayerIndex,
HAIKU_JoystickGetDeviceGUID,