155 lines
5.2 KiB
C#
155 lines
5.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;
|
|
using System.Windows.Media;
|
|
|
|
namespace AuroraUIComponent.UserControls
|
|
{
|
|
public class RectPattern : IPattern
|
|
{
|
|
public ObservableCollection<Rect> Entities { get => _Entities; set => SetProperty(ref _Entities, value); }
|
|
private ObservableCollection<Rect> _Entities = new ObservableCollection<Rect>();
|
|
|
|
public RectPattern()
|
|
{
|
|
Entities = new ObservableCollection<Rect>();
|
|
//Entities.Add(new Rect());
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
Entities.Clear();
|
|
//Entities.Add(new Rect());
|
|
}
|
|
|
|
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 = maxX = Entities[0].START_X;
|
|
minY = maxY = Entities[0].START_Y;
|
|
foreach (var item in Entities) {
|
|
if (minX > item.START_X) minX = item.START_X;
|
|
if (minY > item.START_Y) minY = item.START_Y;
|
|
if (maxX < item.START_X) maxX = item.START_X;
|
|
if (maxY < item.START_Y) maxY = item.START_Y;
|
|
if (minX > item.END_X) minX = item.END_X;
|
|
if (minY > item.END_Y) minY = item.END_Y;
|
|
if (maxX < item.END_X) maxX = item.END_X;
|
|
if (maxY < item.END_Y) maxY = item.END_Y;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public class Rect : NotifyPropertyChangedBase
|
|
{
|
|
public double START_X { get => _START_X; set => SetProperty(ref _START_X, value); }
|
|
private double _START_X;
|
|
public double START_Y { get => _START_Y; set => SetProperty(ref _START_Y, value); }
|
|
private double _START_Y;
|
|
public double END_X { get => _END_X; set => SetProperty(ref _END_X, value); }
|
|
private double _END_X;
|
|
public double END_Y { get => _END_Y; set => SetProperty(ref _END_Y, value); }
|
|
private double _END_Y;
|
|
|
|
public string Label { get => _Label; set => SetProperty(ref _Label, value); }
|
|
private string _Label;
|
|
|
|
public Brush LineBrush = null;
|
|
public Brush FillBrush = null;
|
|
|
|
public bool IsMovable { get => _IsMovable; set => SetProperty(ref _IsMovable, value); }
|
|
private bool _IsMovable;
|
|
|
|
public System.Windows.Rect _Rect;
|
|
public void SetRectShape(System.Windows.Rect rect)
|
|
{
|
|
_Rect = rect;
|
|
}
|
|
public System.Windows.Rect GetRectShape()
|
|
{
|
|
return _Rect;
|
|
}
|
|
public double OffsetX { get => _OffsetX; set => SetProperty(ref _OffsetX, value); }
|
|
private double _OffsetX;
|
|
public double OffsetY { get => _OffsetY; set => SetProperty(ref _OffsetY, value); }
|
|
private double _OffsetY;
|
|
|
|
|
|
public Rect(double x1, double y1, double x2, double y2, string lineBrush = null, string fillBrush = null, string label = null)
|
|
{
|
|
START_X = x1;
|
|
START_Y = y1;
|
|
END_X = x2;
|
|
END_Y = y2;
|
|
|
|
if (lineBrush != null) {
|
|
LineBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(lineBrush));
|
|
}
|
|
if (fillBrush != null) {
|
|
FillBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(fillBrush));
|
|
}
|
|
Label = label;
|
|
}
|
|
|
|
public Rect() : this(0, 0, 0, 0)
|
|
{
|
|
|
|
}
|
|
|
|
public void Copy(Rect copyPattern)
|
|
{
|
|
if (copyPattern != null) {
|
|
START_X = copyPattern.START_X;
|
|
START_Y = copyPattern.START_Y;
|
|
END_X = copyPattern.END_X;
|
|
END_Y = copyPattern.END_Y;
|
|
|
|
LineBrush = copyPattern.LineBrush;
|
|
FillBrush = copyPattern.FillBrush;
|
|
Label = copyPattern.Label;
|
|
}
|
|
}
|
|
|
|
public void Shift(double x, double y)
|
|
{
|
|
START_X += x;
|
|
START_Y += y;
|
|
END_X += x;
|
|
END_Y += y;
|
|
}
|
|
|
|
public bool Contains(Point point)
|
|
{
|
|
double width = Math.Abs(_START_X - _END_X);
|
|
double height = Math.Abs(_START_Y - _END_Y);
|
|
|
|
if (point.X >= START_X && point.X - width <= START_X && point.Y >= START_Y) {
|
|
return point.Y - height <= START_Y;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|