Sdk/Binding: Bind Rect
As requested Former-commit-id: 97fcb06de0505341f39418147c57d240e4210159
This commit is contained in:
parent
fa90d3fd69
commit
98867fee19
|
|
@ -102,6 +102,36 @@ namespace Nz
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Rectd* rect, TypeTag<Rectd>)
|
||||||
|
{
|
||||||
|
instance.CheckType(index, LuaType_Table);
|
||||||
|
|
||||||
|
rect->x = instance.CheckField<double>("x", index);
|
||||||
|
rect->y = instance.CheckField<double>("y", index);
|
||||||
|
rect->width = instance.CheckField<double>("width", index);
|
||||||
|
rect->height = instance.CheckField<double>("height", index);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Rectf* rect, TypeTag<Rectf>)
|
||||||
|
{
|
||||||
|
Rectd rectDouble;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &rectDouble, TypeTag<Rectd>());
|
||||||
|
|
||||||
|
rect->Set(rectDouble);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Rectui* rect, TypeTag<Rectui>)
|
||||||
|
{
|
||||||
|
Rectd rectDouble;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &rectDouble, TypeTag<Rectd>());
|
||||||
|
|
||||||
|
rect->Set(rectDouble);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag<Quaterniond>)
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag<Quaterniond>)
|
||||||
{
|
{
|
||||||
switch (instance.GetType(index))
|
switch (instance.GetType(index))
|
||||||
|
|
@ -341,6 +371,24 @@ namespace Nz
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, Rectd&& val, TypeTag<Rectf>)
|
||||||
|
{
|
||||||
|
instance.PushInstance<Rectd>("Rect", val);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, Rectf&& val, TypeTag<Rectf>)
|
||||||
|
{
|
||||||
|
instance.PushInstance<Rectd>("Rect", val);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, Rectui&& val, TypeTag<Rectui>)
|
||||||
|
{
|
||||||
|
instance.PushInstance<Rectd>("Rect", val);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2d&& val, TypeTag<Vector2d>)
|
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2d&& val, TypeTag<Vector2d>)
|
||||||
{
|
{
|
||||||
instance.PushInstance<Vector2d>("Vector2", val);
|
instance.PushInstance<Vector2d>("Vector2", val);
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ namespace Ndk
|
||||||
// Math
|
// Math
|
||||||
Nz::LuaClass<Nz::EulerAnglesd> eulerAnglesClass;
|
Nz::LuaClass<Nz::EulerAnglesd> eulerAnglesClass;
|
||||||
Nz::LuaClass<Nz::Quaterniond> quaternionClass;
|
Nz::LuaClass<Nz::Quaterniond> quaternionClass;
|
||||||
|
Nz::LuaClass<Nz::Rectd> rectClass;
|
||||||
Nz::LuaClass<Nz::Vector2d> vector2dClass;
|
Nz::LuaClass<Nz::Vector2d> vector2dClass;
|
||||||
Nz::LuaClass<Nz::Vector3d> vector3dClass;
|
Nz::LuaClass<Nz::Vector3d> vector3dClass;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ namespace Ndk
|
||||||
// Math
|
// Math
|
||||||
eulerAnglesClass("EulerAngles"),
|
eulerAnglesClass("EulerAngles"),
|
||||||
quaternionClass("Quaternion"),
|
quaternionClass("Quaternion"),
|
||||||
|
rectClass("Rect"),
|
||||||
vector2dClass("Vector2"),
|
vector2dClass("Vector2"),
|
||||||
vector3dClass("Vector3"),
|
vector3dClass("Vector3"),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,152 @@ namespace Ndk
|
||||||
return false;
|
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 **********************************/
|
/*********************************** Nz::Quaternion **********************************/
|
||||||
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* quaternion)
|
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* quaternion)
|
||||||
{
|
{
|
||||||
|
|
@ -494,6 +640,7 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
eulerAnglesClass.Register(instance);
|
eulerAnglesClass.Register(instance);
|
||||||
quaternionClass.Register(instance);
|
quaternionClass.Register(instance);
|
||||||
|
rectClass.Register(instance);
|
||||||
vector2dClass.Register(instance);
|
vector2dClass.Register(instance);
|
||||||
vector3dClass.Register(instance);
|
vector3dClass.Register(instance);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue