First pass at extending virtual controller functionality

Added the ability to specify a name and the product VID/PID for a virtual controller

Also added a test case to testgamecontroller, if you pass --virtual as a parameter
This commit is contained in:
Sam Lantinga 2022-05-15 20:01:12 -07:00
parent 7ad15c5b8f
commit 94eeb587c1
9 changed files with 509 additions and 203 deletions

View file

@ -522,9 +522,23 @@ SDL_JoystickOpen(int device_index)
int
SDL_JoystickAttachVirtual(SDL_JoystickType type,
int naxes, int nbuttons, int nhats)
{
SDL_VirtualJoystickDesc desc;
SDL_zero(desc);
desc.version = SDL_VIRTUAL_JOYSTICK_DESC_VERSION;
desc.type = (Uint16)type;
desc.naxes = (Uint16)naxes;
desc.nbuttons = (Uint16)nbuttons;
desc.nhats = (Uint16)nhats;
return SDL_JoystickAttachVirtualEx(&desc);
}
int
SDL_JoystickAttachVirtualEx(const SDL_VirtualJoystickDesc *desc)
{
#if SDL_JOYSTICK_VIRTUAL
return SDL_JoystickAttachVirtualInner(type, naxes, nbuttons, nhats);
return SDL_JoystickAttachVirtualInner(desc);
#else
return SDL_SetError("SDL not built with virtual-joystick support");
#endif