Sdk/Binding: Bind Rect
As requested Former-commit-id: 97fcb06de0505341f39418147c57d240e4210159
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Ndk
|
||||
// Math
|
||||
eulerAnglesClass("EulerAngles"),
|
||||
quaternionClass("Quaternion"),
|
||||
rectClass("Rect"),
|
||||
vector2dClass("Vector2"),
|
||||
vector3dClass("Vector3"),
|
||||
|
||||
|
||||
@@ -149,6 +149,152 @@ namespace Ndk
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Rect **********************************/
|
||||
rectClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* rect)
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 4:
|
||||
PlacementNew(rect, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0), lua.CheckNumber(4, 0.0));
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, "Rect"))
|
||||
PlacementNew(rect, *static_cast<Nz::Rectd*>(lua.ToUserdata(1)));
|
||||
else if (lua.IsOfType(1, Nz::LuaType_Table))
|
||||
{
|
||||
// TODO => Faire sans avoir à mettre de nom dans la table et prendre les éléments un à un pour créer le Rectd
|
||||
PlacementNew(rect, lua.CheckField<double>("x", 1),
|
||||
lua.CheckField<double>("y", 1),
|
||||
lua.CheckField<double>("width", 1),
|
||||
lua.CheckField<double>("height", 1));
|
||||
}
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
PlacementNew(rect, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||
else
|
||||
break;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number) && lua.IsOfType(2, Nz::LuaType_Number))
|
||||
PlacementNew(rect, lua.CheckNumber(1), lua.CheckNumber(2));
|
||||
else if (lua.IsOfType(1, "Vector2") && lua.IsOfType(2, "Vector2"))
|
||||
PlacementNew(rect, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)), *static_cast<Nz::Vector2d*>(lua.ToUserdata(2)));
|
||||
else
|
||||
break;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for Rect constructor");
|
||||
return false;
|
||||
});
|
||||
|
||||
rectClass.BindMethod("__tostring", &Nz::Rectd::ToString);
|
||||
|
||||
rectClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 4)
|
||||
return false;
|
||||
|
||||
lua.Push(instance[index - 1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xywh = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
switch (xywh[0])
|
||||
{
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
|
||||
case 'w':
|
||||
lua.Push(instance.width);
|
||||
return true;
|
||||
|
||||
case 'h':
|
||||
lua.Push(instance.height);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
rectClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 4)
|
||||
return false;
|
||||
|
||||
instance[index - 1] = lua.CheckNumber(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xywh = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (xywh[0])
|
||||
{
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
|
||||
case 'w':
|
||||
instance.width = value;
|
||||
return true;
|
||||
|
||||
case 'h':
|
||||
instance.height = value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Quaternion **********************************/
|
||||
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* quaternion)
|
||||
{
|
||||
@@ -494,6 +640,7 @@ namespace Ndk
|
||||
{
|
||||
eulerAnglesClass.Register(instance);
|
||||
quaternionClass.Register(instance);
|
||||
rectClass.Register(instance);
|
||||
vector2dClass.Register(instance);
|
||||
vector3dClass.Register(instance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user