2026-01-26 14:51:28 +09:00

136 lines
4.2 KiB
C#

/*
* Copyright (c) 2022 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using Aurora.View;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace AuroraUIComponent.UserControls
{
public class CrossPattern : IPattern
{
public ObservableCollection<Cross> Entities { get => _Entities; set => SetProperty(ref _Entities, value); }
private ObservableCollection<Cross> _Entities = new ObservableCollection<Cross>();
public CrossPattern()
{
Entities = new ObservableCollection<Cross>();
//Entities.Add(new Cross());
}
public void Clear()
{
Entities.Clear();
//Entities.Add(new Cross());
}
public override void Shift(double x, double y)
{
foreach (var item in Entities) {
item.Shift(x, y);
}
}
public override bool GetMinMax(out double minX, out double maxX, out double minY, out double maxY)
{
if (Entities.Count == 0) {
return base.GetMinMax(out minX, out maxX, out minY, out maxY);
}
minX = Entities[0].GetMinX();
maxX = Entities[0].GetMaxX();
minY = Entities[0].GetMinY();
maxY = Entities[0].GetMaxY();
foreach (var item in Entities) {
if (minX > item.GetMinX()) minX = item.GetMinX();
if (minY > item.GetMinY()) minY = item.GetMinY();
if (maxX < item.GetMaxX()) maxX = item.GetMaxX();
if (maxY < item.GetMaxY()) maxY = item.GetMaxY();
}
return true;
}
public class Cross : NotifyPropertyChangedBase
{
public double CENTER_X { get => _CENTER_X; set => SetProperty(ref _CENTER_X, value); }
private double _CENTER_X;
public double CENTER_Y { get => _CENTER_Y; set => SetProperty(ref _CENTER_Y, value); }
private double _CENTER_Y;
public double LENGTH_X { get => _LENGTH_X; set => SetProperty(ref _LENGTH_X, value); }
private double _LENGTH_X;
public double LENGTH_Y { get => _LENGTH_Y; set => SetProperty(ref _LENGTH_Y, value); }
private double _LENGTH_Y;
public double DASH { get => _DASH; set => SetProperty(ref _DASH, value); }
private double _DASH;
public Brush CustomBrush = null;
public Cross(double centerX, double centerY, double lengthX = 10, double lengthY = 10, double dash = -1, string brush = null)
{
CENTER_X = centerX;
CENTER_Y = centerY;
LENGTH_X = lengthX;
LENGTH_Y = lengthY;
DASH = dash;
if (brush != null) {
CustomBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(brush));
}
}
public Cross() : this(0, 0, 0, 0)
{
}
public double GetMinX()
{
return CENTER_X - Math.Abs(LENGTH_X);
}
public double GetMaxX()
{
return CENTER_X + Math.Abs(LENGTH_X);
}
public double GetMinY()
{
return CENTER_Y - Math.Abs(LENGTH_Y);
}
public double GetMaxY()
{
return CENTER_Y + Math.Abs(LENGTH_Y);
}
public void Copy(Cross copyPattern)
{
if (copyPattern != null) {
CENTER_X = copyPattern.CENTER_X;
CENTER_Y = copyPattern.CENTER_Y;
LENGTH_X = copyPattern.LENGTH_X;
LENGTH_Y = copyPattern.LENGTH_Y;
DASH = copyPattern.DASH;
CustomBrush = copyPattern.CustomBrush;
}
}
public void Shift(double x, double y)
{
CENTER_X += x;
CENTER_Y += y;
}
}
}
}