EllipseObject.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Controls.Shapes;
  4. using Avalonia.Media;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace InABox.Avalonia.Components.ImageEditing;
  11. internal class EllipseObject : IImageEditorObject
  12. {
  13. public IBrush? PrimaryBrush { get; set; }
  14. public IBrush? SecondaryBrush { get; set; }
  15. public double Thickness { get; set; } = 1.0;
  16. public Point Point1 { get; set; }
  17. public Point Point2 { get; set; }
  18. private Ellipse Control = new();
  19. public Control GetControl() => Control;
  20. public void Update()
  21. {
  22. Control.Stroke = PrimaryBrush;
  23. Control.Fill = SecondaryBrush;
  24. Control.StrokeThickness = Thickness;
  25. var topLeft = new Point(
  26. Math.Min(Point1.X, Point2.X),
  27. Math.Min(Point1.Y, Point2.Y));
  28. Canvas.SetLeft(Control, topLeft.X);
  29. Canvas.SetTop(Control, topLeft.Y);
  30. Control.Width = Math.Abs(Point2.X - Point1.X);
  31. Control.Height = Math.Abs(Point2.Y - Point1.Y);
  32. }
  33. public void SetActive(bool active)
  34. {
  35. }
  36. }