using System.Numerics;
using ComputeSharp.D2D1.Helpers;
using ComputeSharp.D2D1.Shaders.Interop.Factories;
namespace ComputeSharp.D2D1.Interop;
///
/// Provides built-in transform mapper factories for common transform mapping operations.
///
/// The type of D2D1 pixel shader associated to the transform mapper.
public static class D2D1TransformMapperFactory
where T : unmanaged, ID2D1PixelShader
{
///
/// Creates an instance for an inflate transform.
///
/// The fixed inflate amount to use (applies to all edges of the input area).
/// The resulting instance for an inflate transform.
public static ID2D1TransformMapperFactory Inflate(int amount)
{
return new D2D1InflateTransformMapperFactory { ParametersAccessor = new D2D1InflateTransformMapperFactory.ConstantAmount { Amount = amount } };
}
///
/// Creates an instance for an inflate transform.
///
/// The fixed left inflate amount to use.
/// The fixed top inflate amount to use.
/// The fixed right inflate amount to use.
/// The fixed bottom inflate amount to use.
/// The resulting instance for an inflate transform.
public static ID2D1TransformMapperFactory Inflate(int left, int top, int right, int bottom)
{
return new D2D1InflateTransformMapperFactory { ParametersAccessor = new D2D1InflateTransformMapperFactory.ConstantLeftTopRightBottomAmount { Left = left, Top = top, Right = right, Bottom = bottom } };
}
///
/// Creates an instance for an inflate transform.
///
/// The input instance to retrieve the inflate amount to use (applies to all edges of the input area).
/// The resulting instance for an inflate transform.
public static ID2D1TransformMapperFactory Inflate(Accessor accessor)
{
if (accessor is null)
{
ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory.Accessor object cannot be null.");
}
return new D2D1InflateTransformMapperFactory { ParametersAccessor = new D2D1InflateTransformMapperFactory.DynamicAmount { Accessor = accessor } };
}
///
/// Creates an instance for an inflate transform.
///
/// The input instance to retrieve the inflate amount to use.
/// The resulting instance for an inflate transform.
public static ID2D1TransformMapperFactory Inflate(Accessor<(int Left, int Top, int Right, int Bottom)> accessor)
{
if (accessor is null)
{
ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory.Accessor<(int Left, int Top, int Right, int Bottom)> object cannot be null.");
}
return new D2D1InflateTransformMapperFactory { ParametersAccessor = new D2D1InflateTransformMapperFactory.DynamicLeftTopRightBottomAmount { Accessor = accessor } };
}
///
/// Creates an instance for an affine transform.
///
/// The fixed transformation matrix to use.
/// The resulting instance for an affine transform.
public static ID2D1TransformMapperFactory Transform(Matrix3x2 matrix)
{
return new D2D1AffineTransformMapperFactory.For { ParametersAccessor = new D2D1AffineTransformMapperFactory.For.ConstantMatrix { Amount = matrix } };
}
///
/// Creates an instance for an affine transform.
///
/// The input instance to retrieve the transformation matrix to use.
/// The resulting instance for an affine transform.
public static ID2D1TransformMapperFactory Transform(Accessor accessor)
{
if (accessor is null)
{
ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory.Accessor object cannot be null.");
}
return new D2D1AffineTransformMapperFactory.For { ParametersAccessor = new D2D1AffineTransformMapperFactory.For.DynamicMatrix { Accessor = accessor } };
}
///
/// An accessor of parameters to be used in D2D1 transform mapping implementations.
///
/// The type of parameters that the transform mapper will use.
/// The input D2D1 pixel shader being executed on the current effect (this can be used to retrieve shader properties).
/// The resulting parameters to be used by the transform mapper.
public delegate TResult Accessor(in T shader);
}