Singularity/Library/PackageCache/com.unity.2d.psdimporter@6.0.7/Editor/PSDPlugin/PDNWrapper/BitmapLayer.cs
2024-05-06 11:45:45 -07:00

62 lines
2.1 KiB
C#

using System.Collections.Generic;
namespace PDNWrapper
{
internal static class Layer
{
public static BitmapLayer CreateBackgroundLayer(int w, int h)
{
return new BitmapLayer(new Rectangle(0, 0, w, h));
}
}
internal class BitmapLayer
{
public int LayerID { get; set; }
public bool IsGroup {get; set; }
public BitmapLayer ParentLayer {get; set; }
public IEnumerable<BitmapLayer> ChildLayer => m_ChildLayers;
public string Name { get; set; }
public byte Opacity { get; set; }
public bool Visible { get; set; }
public LayerBlendMode BlendMode { get; set; }
public Surface Surface { get; }
public Rectangle documentRect { get; private set; }
public Rectangle localRect { get; }
readonly List<BitmapLayer> m_ChildLayers;
public void Dispose()
{
Surface.Dispose();
foreach (var layer in m_ChildLayers)
layer.Dispose();
}
public BitmapLayer(Rectangle documentRect)
{
localRect = new Rectangle(0, 0, documentRect.Width, documentRect.Height);
this.documentRect = documentRect;
Surface = new Surface(localRect.Width, localRect.Height);
m_ChildLayers = new List<BitmapLayer>();
IsGroup = false;
}
public void AddChildLayer(BitmapLayer c)
{
m_ChildLayers.Add(c);
var bound = c.documentRect;
foreach (var child in ChildLayer)
{
bound.Y = bound.Y > child.documentRect.Y ? child.documentRect.Y : bound.Y;
bound.X = bound.X > child.documentRect.X ? child.documentRect.X : bound.X;
bound.Width = bound.Right < child.documentRect.Right ? child.documentRect.Right - bound.X : bound.Width;
bound.Height = bound.Bottom < child.documentRect.Bottom ? child.documentRect.Bottom - bound.Y : bound.Height;
}
documentRect = bound;
}
}
}