smrendererv3/SMCode/SM2D/Scene/ItemCollection.cs
2021-03-28 17:33:52 +02:00

46 lines
No EOL
1 KiB
C#

#region usings
using System;
using SM.Base.Scene;
using SM.Base.Types;
using SM.Base.Window;
using SM2D.Types;
#endregion
namespace SM2D.Scene
{
/// <inheritdoc />
public class ItemCollection : GenericItemCollection<Transformation>
{
/// <inheritdoc />
public ItemCollection()
{
Transform.Size = new CVector2(1);
}
/// <inheritdoc />
public override void Draw(DrawContext context)
{
this.Sort(Comparitor);
base.Draw(context);
}
private int Comparitor(IShowItem a, IShowItem b)
{
if (a is ITransformItem<Transformation> ta)
{
if (b is ITransformItem<Transformation> tb)
{
return (int)((ta.Transform.GetMatrix()[3, 2] - tb.Transform.GetMatrix()[3, 2]) * Transformation.ZIndexPercision);
}
else return 1;
}
else
{
return -1;
}
}
}
}