ImageNode.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using Avalonia.Media;
  5. using Avalonia.Platform;
  6. namespace Avalonia.Rendering.SceneGraph
  7. {
  8. public class ImageNode : IGeometryNode
  9. {
  10. public ImageNode(Matrix transform, IBitmapImpl source, double opacity, Rect sourceRect, Rect destRect)
  11. {
  12. Transform = transform;
  13. Source = source;
  14. Opacity = opacity;
  15. SourceRect = sourceRect;
  16. DestRect = destRect;
  17. }
  18. public Matrix Transform { get; }
  19. public IBitmapImpl Source { get; }
  20. public double Opacity { get; }
  21. public Rect SourceRect { get; }
  22. public Rect DestRect { get; }
  23. public bool Equals(Matrix transform, IBitmapImpl source, double opacity, Rect sourceRect, Rect destRect)
  24. {
  25. return transform == Transform &&
  26. Equals(source, Source) &&
  27. opacity == Opacity &&
  28. sourceRect == SourceRect &&
  29. destRect == DestRect;
  30. }
  31. public void Render(IDrawingContextImpl context)
  32. {
  33. context.Transform = Transform;
  34. context.DrawImage(Source, Opacity, SourceRect, DestRect);
  35. }
  36. public bool HitTest(Point p)
  37. {
  38. return (DestRect * Transform).Contains(p);
  39. }
  40. }
  41. }