mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Added caching for actual layout data
This commit is contained in:
parent
fab502e0e4
commit
1126408069
@ -43,22 +43,23 @@ namespace RGB.NET.Core
|
||||
protected set
|
||||
{
|
||||
if (SetProperty(ref _size, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(ActualSize));
|
||||
OnPropertyChanged(nameof(DeviceRectangle));
|
||||
}
|
||||
UpdateActualData();
|
||||
}
|
||||
}
|
||||
|
||||
private Size _actualSize;
|
||||
/// <inheritdoc />
|
||||
public Size ActualSize => Size * Scale;
|
||||
public Size ActualSize
|
||||
{
|
||||
get => _actualSize;
|
||||
private set => SetProperty(ref _actualSize, value);
|
||||
}
|
||||
|
||||
private Rectangle _deviceRectangle;
|
||||
public Rectangle DeviceRectangle
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Rectangle(Location, new Rectangle(new Rectangle(Location, ActualSize).Rotate(Rotation)).Size);
|
||||
}
|
||||
get => _deviceRectangle;
|
||||
private set => SetProperty(ref _deviceRectangle, value);
|
||||
}
|
||||
|
||||
private Scale _scale = new Scale(1);
|
||||
@ -69,10 +70,7 @@ namespace RGB.NET.Core
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _scale, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(ActualSize));
|
||||
OnPropertyChanged(nameof(DeviceRectangle));
|
||||
}
|
||||
UpdateActualData();
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,9 +82,7 @@ namespace RGB.NET.Core
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _rotation, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(DeviceRectangle));
|
||||
}
|
||||
UpdateActualData();
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,6 +122,12 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
private void UpdateActualData()
|
||||
{
|
||||
ActualSize = Size * Scale;
|
||||
DeviceRectangle = new Rectangle(Location, new Rectangle(new Rectangle(Location, ActualSize).Rotate(Rotation)).Size);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Update(bool flushLeds = false)
|
||||
{
|
||||
|
||||
@ -45,53 +45,67 @@ namespace RGB.NET.Core
|
||||
set => SetProperty(ref _shapeData, value);
|
||||
}
|
||||
|
||||
public Point Location { get; set; }
|
||||
|
||||
public Size Size { get; set; }
|
||||
|
||||
public Point ActualLocation
|
||||
private Point _location;
|
||||
public Point Location
|
||||
{
|
||||
get
|
||||
get => _location;
|
||||
set
|
||||
{
|
||||
Point point = (Location * Device.Scale);
|
||||
if (!Device.Rotation.Radians.EqualsInTolerance(0))
|
||||
if (SetProperty(ref _location, value))
|
||||
{
|
||||
Point deviceCenter = new Rectangle(Device.ActualSize).Center;
|
||||
Point actualDeviceCenter = Device.DeviceRectangle.Center;
|
||||
Point centerOffset = new Point(actualDeviceCenter.X - deviceCenter.X, actualDeviceCenter.Y - deviceCenter.Y);
|
||||
point = point.Rotate(Device.Rotation, new Rectangle(Device.ActualSize).Center) + centerOffset;
|
||||
UpdateActualData();
|
||||
UpdateAbsoluteData();
|
||||
}
|
||||
|
||||
return point;
|
||||
}
|
||||
}
|
||||
|
||||
public Size ActualSize => Size * Device.Scale;
|
||||
private Size _size;
|
||||
public Size Size
|
||||
{
|
||||
get => _size;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _size, value))
|
||||
{
|
||||
UpdateActualData();
|
||||
UpdateAbsoluteData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Point _actualLocation;
|
||||
public Point ActualLocation
|
||||
{
|
||||
get => _actualLocation;
|
||||
private set => SetProperty(ref _actualLocation, value);
|
||||
}
|
||||
|
||||
private Size _actualSize;
|
||||
public Size ActualSize
|
||||
{
|
||||
get => _actualSize;
|
||||
private set => SetProperty(ref _actualSize, value);
|
||||
}
|
||||
|
||||
private Rectangle _ledRectangle;
|
||||
/// <summary>
|
||||
/// Gets a rectangle representing the logical location of the <see cref="Led"/> relative to the <see cref="Device"/>.
|
||||
/// </summary>
|
||||
public Rectangle LedRectangle
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle rect = new Rectangle(Location * Device.Scale, Size * Device.Scale);
|
||||
if (!Device.Rotation.Radians.EqualsInTolerance(0))
|
||||
{
|
||||
Point deviceCenter = new Rectangle(Device.ActualSize).Center;
|
||||
Point actualDeviceCenter = Device.DeviceRectangle.Center;
|
||||
Point centerOffset = new Point(actualDeviceCenter.X - deviceCenter.X, actualDeviceCenter.Y - deviceCenter.Y);
|
||||
rect = new Rectangle(rect.Rotate(Device.Rotation, new Rectangle(Device.ActualSize).Center)).Translate(centerOffset);
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
get => _ledRectangle;
|
||||
private set => SetProperty(ref _ledRectangle, value);
|
||||
}
|
||||
|
||||
private Rectangle _absoluteLedRectangle;
|
||||
/// <summary>
|
||||
/// Gets a rectangle representing the logical location of the <see cref="Led"/> on the <see cref="RGBSurface"/>.
|
||||
/// </summary>
|
||||
public Rectangle AbsoluteLedRectangle => LedRectangle.Translate(Device.Location);
|
||||
public Rectangle AbsoluteLedRectangle
|
||||
{
|
||||
get => _absoluteLedRectangle;
|
||||
private set => SetProperty(ref _absoluteLedRectangle, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the <see cref="Led" /> is about to change it's color.
|
||||
@ -194,18 +208,40 @@ namespace RGB.NET.Core
|
||||
private void DevicePropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if ((e.PropertyName == nameof(IRGBDevice.Location)))
|
||||
{
|
||||
OnPropertyChanged(nameof(AbsoluteLedRectangle));
|
||||
}
|
||||
UpdateAbsoluteData();
|
||||
else if ((e.PropertyName == nameof(IRGBDevice.Scale)) || (e.PropertyName == nameof(IRGBDevice.Rotation)))
|
||||
{
|
||||
OnPropertyChanged(nameof(LedRectangle));
|
||||
OnPropertyChanged(nameof(AbsoluteLedRectangle));
|
||||
OnPropertyChanged(nameof(ActualLocation));
|
||||
OnPropertyChanged(nameof(ActualSize));
|
||||
UpdateActualData();
|
||||
UpdateAbsoluteData();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateActualData()
|
||||
{
|
||||
ActualSize = Size * Device.Scale;
|
||||
|
||||
Point actualLocation = (Location * Device.Scale);
|
||||
Rectangle ledRectangle = new Rectangle(Location * Device.Scale, Size * Device.Scale);
|
||||
|
||||
if (Device.Rotation.IsRotated)
|
||||
{
|
||||
Point deviceCenter = new Rectangle(Device.ActualSize).Center;
|
||||
Point actualDeviceCenter = Device.DeviceRectangle.Center;
|
||||
Point centerOffset = new Point(actualDeviceCenter.X - deviceCenter.X, actualDeviceCenter.Y - deviceCenter.Y);
|
||||
|
||||
actualLocation = actualLocation.Rotate(Device.Rotation, new Rectangle(Device.ActualSize).Center) + centerOffset;
|
||||
ledRectangle = new Rectangle(ledRectangle.Rotate(Device.Rotation, new Rectangle(Device.ActualSize).Center)).Translate(centerOffset);
|
||||
}
|
||||
|
||||
ActualLocation = actualLocation;
|
||||
LedRectangle = ledRectangle;
|
||||
}
|
||||
|
||||
private void UpdateAbsoluteData()
|
||||
{
|
||||
AbsoluteLedRectangle = LedRectangle.Translate(Device.Location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the <see cref="Id"/> and the <see cref="Color"/> of this <see cref="Led"/> to a human-readable string.
|
||||
/// </summary>
|
||||
|
||||
@ -17,6 +17,8 @@ namespace RGB.NET.Core
|
||||
public double Degrees { get; }
|
||||
public double Radians { get; }
|
||||
|
||||
public bool IsRotated => !Degrees.EqualsInTolerance(0);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user