using Avalonia.Platform;
using Avalonia.Utilities;
namespace Avalonia.Rendering.SceneGraph
{
///
/// A node in the scene graph which represents an image draw.
///
internal class ImageNode : DrawOperationWithTransform
{
///
/// Initializes a new instance of the class.
///
/// The transform.
/// The image to draw.
/// The draw opacity.
/// The source rect.
/// The destination rect.
public ImageNode(Matrix transform, IRef source, double opacity, Rect sourceRect, Rect destRect)
: base(destRect, transform)
{
Source = source.Clone();
Opacity = opacity;
SourceRect = sourceRect;
DestRect = destRect;
SourceVersion = Source.Item.Version;
}
///
/// Gets the image to draw.
///
public IRef Source { get; }
///
/// Source bitmap Version
///
public int SourceVersion { get; }
///
/// Gets the draw opacity.
///
public double Opacity { get; }
///
/// Gets the source rect.
///
public Rect SourceRect { get; }
///
/// Gets the destination rect.
///
public Rect DestRect { get; }
///
/// Determines if this draw operation equals another.
///
/// The transform of the other draw operation.
/// The image of the other draw operation.
/// The opacity of the other draw operation.
/// The source rect of the other draw operation.
/// The dest rect of the other draw operation.
/// True if the draw operations are the same, otherwise false.
///
/// The properties of the other draw operation are passed in as arguments to prevent
/// allocation of a not-yet-constructed draw operation object.
///
public bool Equals(Matrix transform, IRef source, double opacity, Rect sourceRect, Rect destRect)
{
return transform == Transform &&
Equals(source.Item, Source.Item) &&
source.Item.Version == SourceVersion &&
opacity == Opacity &&
sourceRect == SourceRect &&
destRect == DestRect;
}
///
public override void Render(IDrawingContextImpl context)
{
context.DrawBitmap(Source, Opacity, SourceRect, DestRect);
}
///
public override bool HitTestTransformed(Point p) => DestRect.ContainsExclusive(p);
public override void Dispose()
{
Source?.Dispose();
}
}
}