mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Add Joystick:getDeviceInfo(). Returns USB vendor id, product id, and product version numbers (consistent across operating systems).
Can be used to show different icons, etc. for different gamepads.
This commit is contained in:
@@ -160,6 +160,8 @@ public:
|
|||||||
virtual int getInstanceID() const = 0;
|
virtual int getInstanceID() const = 0;
|
||||||
virtual int getID() const = 0;
|
virtual int getID() const = 0;
|
||||||
|
|
||||||
|
virtual void getDeviceInfo(int &vendorID, int &productID, int &productVersion) const = 0;
|
||||||
|
|
||||||
virtual bool isVibrationSupported() = 0;
|
virtual bool isVibrationSupported() = 0;
|
||||||
virtual bool setVibration(float left, float right, float duration = -1.0f) = 0;
|
virtual bool setVibration(float left, float right, float duration = -1.0f) = 0;
|
||||||
virtual bool setVibration() = 0;
|
virtual bool setVibration() = 0;
|
||||||
|
|||||||
@@ -322,6 +322,24 @@ int Joystick::getID() const
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Joystick::getDeviceInfo(int &vendorID, int &productID, int &productVersion) const
|
||||||
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 6)
|
||||||
|
if (joyhandle != nullptr)
|
||||||
|
{
|
||||||
|
vendorID = SDL_JoystickGetVendor(joyhandle);
|
||||||
|
productID = SDL_JoystickGetProduct(joyhandle);
|
||||||
|
productVersion = SDL_JoystickGetProductVersion(joyhandle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
vendorID = 0;
|
||||||
|
productID = 0;
|
||||||
|
productVersion = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Joystick::checkCreateHaptic()
|
bool Joystick::checkCreateHaptic()
|
||||||
{
|
{
|
||||||
if (!isConnected())
|
if (!isConnected())
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ public:
|
|||||||
int getInstanceID() const override;
|
int getInstanceID() const override;
|
||||||
int getID() const override;
|
int getID() const override;
|
||||||
|
|
||||||
|
void getDeviceInfo(int &vendorID, int &productID, int &productVersion) const override;
|
||||||
|
|
||||||
bool isVibrationSupported() override;
|
bool isVibrationSupported() override;
|
||||||
bool setVibration(float left, float right, float duration = -1.0f) override;
|
bool setVibration(float left, float right, float duration = -1.0f) override;
|
||||||
bool setVibration() override;
|
bool setVibration() override;
|
||||||
|
|||||||
@@ -71,6 +71,20 @@ int w_Joystick_getGUID(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_Joystick_getDeviceInfo(lua_State *L)
|
||||||
|
{
|
||||||
|
Joystick *j = luax_checkjoystick(L, 1);
|
||||||
|
|
||||||
|
int vendorID = 0, productID = 0, productVersion = 0;
|
||||||
|
j->getDeviceInfo(vendorID, productID, productVersion);
|
||||||
|
|
||||||
|
lua_pushnumber(L, vendorID);
|
||||||
|
lua_pushnumber(L, productID);
|
||||||
|
lua_pushnumber(L, productVersion);
|
||||||
|
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
int w_Joystick_getAxisCount(lua_State *L)
|
int w_Joystick_getAxisCount(lua_State *L)
|
||||||
{
|
{
|
||||||
Joystick *j = luax_checkjoystick(L, 1);
|
Joystick *j = luax_checkjoystick(L, 1);
|
||||||
@@ -324,6 +338,7 @@ static const luaL_Reg w_Joystick_functions[] =
|
|||||||
{ "getName", w_Joystick_getName },
|
{ "getName", w_Joystick_getName },
|
||||||
{ "getID", w_Joystick_getID },
|
{ "getID", w_Joystick_getID },
|
||||||
{ "getGUID", w_Joystick_getGUID },
|
{ "getGUID", w_Joystick_getGUID },
|
||||||
|
{ "getDeviceInfo", w_Joystick_getDeviceInfo },
|
||||||
{ "getAxisCount", w_Joystick_getAxisCount },
|
{ "getAxisCount", w_Joystick_getAxisCount },
|
||||||
{ "getButtonCount", w_Joystick_getButtonCount },
|
{ "getButtonCount", w_Joystick_getButtonCount },
|
||||||
{ "getHatCount", w_Joystick_getHatCount },
|
{ "getHatCount", w_Joystick_getHatCount },
|
||||||
|
|||||||
Reference in New Issue
Block a user