using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Shapes; using Avalonia.Media; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InABox.Avalonia.Components.ImageEditing; internal class SelectionObject : IImageEditorObject { public IBrush? PrimaryBrush { get; set; } public Point Point1 { get; set; } public Point Point2 { get; set; } private Rectangle Control = new(); public Control GetControl() => Control; public Point GetTopLeft() { return new( Math.Min(Point1.X, Point2.X), Math.Min(Point1.Y, Point2.Y)); } public Size GetSize() { return new( Math.Abs(Point2.X - Point1.X), Math.Abs(Point2.Y - Point1.Y)); } public void Update() { Control.Stroke = GetBrush(); Control.StrokeThickness = 5; Control.StrokeDashArray = [2, 2]; var topLeft = GetTopLeft(); var size = GetSize(); Canvas.SetLeft(Control, topLeft.X); Canvas.SetTop(Control, topLeft.Y); Control.Width = size.Width; Control.Height = size.Height; } private IBrush? GetBrush() { var brush = new VisualBrush { TileMode = TileMode.Tile, DestinationRect = new(0, 0, 4, 4, RelativeUnit.Absolute) }; var canvas = new Canvas { Width = 10, Height = 10 }; var rect1 = new Rectangle { Width = 5, Height = 5 }; var rect2 = new Rectangle { Width = 5, Height = 5 }; var rect3 = new Rectangle { Width = 5, Height = 5 }; var rect4 = new Rectangle { Width = 5, Height = 5 }; Canvas.SetLeft(rect2, 5); Canvas.SetTop(rect2, 0); Canvas.SetLeft(rect3, 5); Canvas.SetTop(rect3, 5); Canvas.SetLeft(rect4, 0); Canvas.SetTop(rect4, 5); rect1.Fill = new SolidColorBrush(Colors.White); rect2.Fill = new SolidColorBrush(Colors.Black); rect3.Fill = new SolidColorBrush(Colors.White); rect4.Fill = new SolidColorBrush(Colors.Black); canvas.Children.Add(rect1); canvas.Children.Add(rect2); canvas.Children.Add(rect3); brush.Visual = canvas; return brush; } public void SetActive(bool active) { } }