mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
Added Device-Scaling
This commit is contained in:
parent
65abc89605
commit
2cf8609173
@ -31,8 +31,8 @@ namespace RGB.NET.Core
|
||||
/// <inheritdoc />
|
||||
public Size Size
|
||||
{
|
||||
get => _size;
|
||||
set => SetProperty(ref _size, value);
|
||||
get => _size * Scale;
|
||||
protected set => SetProperty(ref _size, value);
|
||||
}
|
||||
|
||||
private Point _location = new Point(0, 0);
|
||||
@ -43,6 +43,18 @@ namespace RGB.NET.Core
|
||||
set => SetProperty(ref _location, value);
|
||||
}
|
||||
|
||||
private Scale _scale = new Scale(1);
|
||||
/// <inheritdoc />
|
||||
public Scale Scale
|
||||
{
|
||||
get => _scale;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _scale, value))
|
||||
OnPropertyChanged(nameof(Size));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the device needs to be flushed on every update.
|
||||
/// </summary>
|
||||
@ -67,11 +79,11 @@ namespace RGB.NET.Core
|
||||
Led IRGBDevice.this[LedId ledId] => LedMapping.TryGetValue(ledId, out Led led) ? led : null;
|
||||
|
||||
/// <inheritdoc />
|
||||
Led IRGBDevice.this[Point location] => LedMapping.Values.FirstOrDefault(x => x.LedRectangle.Contains(location));
|
||||
Led IRGBDevice.this[Point location] => LedMapping.Values.FirstOrDefault(x => x.ActualLedRectangle.Contains(location));
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerable<Led> IRGBDevice.this[Rectangle referenceRect, double minOverlayPercentage]
|
||||
=> LedMapping.Values.Where(x => referenceRect.CalculateIntersectPercentage(x.LedRectangle) >= minOverlayPercentage);
|
||||
=> LedMapping.Values.Where(x => referenceRect.CalculateIntersectPercentage(x.ActualLedRectangle) >= minOverlayPercentage);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -27,6 +27,8 @@ namespace RGB.NET.Core
|
||||
/// Gets a copy of the <see cref="Size"/> of the whole <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
Size Size { get; }
|
||||
|
||||
Scale Scale { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="DeviceUpdateMode"/> of the <see cref="IRGBDevice"/>.
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
@ -54,14 +55,19 @@ namespace RGB.NET.Core
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _ledRectangle, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(ActualLedRectangle));
|
||||
OnPropertyChanged(nameof(AbsoluteLedRectangle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle ActualLedRectangle => new Rectangle(LedRectangle.Location * Device.Scale, LedRectangle.Size * Device.Scale);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a rectangle representing the physical location of the <see cref="Led"/> on the <see cref="RGBSurface"/>.
|
||||
/// </summary>
|
||||
public Rectangle AbsoluteLedRectangle => (LedRectangle.Location + Device.Location) + new Size(LedRectangle.Size.Width, LedRectangle.Size.Height);
|
||||
public Rectangle AbsoluteLedRectangle => new Rectangle(ActualLedRectangle.Location + Device.Location, ActualLedRectangle.Size);
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the <see cref="Led" /> is about to change it's color.
|
||||
@ -152,17 +158,26 @@ namespace RGB.NET.Core
|
||||
this.LedRectangle = ledRectangle;
|
||||
this.CustomData = customData;
|
||||
|
||||
device.PropertyChanged += (sender, args) =>
|
||||
{
|
||||
OnPropertyChanged(nameof(LedRectangle));
|
||||
OnPropertyChanged(nameof(AbsoluteLedRectangle));
|
||||
};
|
||||
device.PropertyChanged += DevicePropertyChanged;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void DevicePropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if ((e.PropertyName == nameof(IRGBDevice.Location)))
|
||||
{
|
||||
OnPropertyChanged(nameof(AbsoluteLedRectangle));
|
||||
}
|
||||
else if ((e.PropertyName == nameof(IRGBDevice.Scale)))
|
||||
{
|
||||
OnPropertyChanged(nameof(ActualLedRectangle));
|
||||
OnPropertyChanged(nameof(AbsoluteLedRectangle));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the <see cref="Id"/> and the <see cref="Color"/> of this <see cref="Led"/> to a human-readable string.
|
||||
/// </summary>
|
||||
@ -210,7 +225,7 @@ namespace RGB.NET.Core
|
||||
/// Converts a <see cref="Led" /> to a <see cref="Rectangle" />.
|
||||
/// </summary>
|
||||
/// <param name="led">The <see cref="Led"/> to convert.</param>
|
||||
public static implicit operator Rectangle(Led led) => led?.LedRectangle ?? new Rectangle();
|
||||
public static implicit operator Rectangle(Led led) => led?.ActualLedRectangle ?? new Rectangle();
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -149,6 +149,8 @@ namespace RGB.NET.Core
|
||||
return new Point(point1.X / point2.X, point1.Y / point2.Y);
|
||||
}
|
||||
|
||||
public static Point operator *(Point point, Scale scale) => new Point(point.X * scale.Horizontal, point.Y * scale.Vertical);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
46
RGB.NET.Core/Positioning/Scale.cs
Normal file
46
RGB.NET.Core/Positioning/Scale.cs
Normal file
@ -0,0 +1,46 @@
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
public struct Scale
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public double Horizontal { get; }
|
||||
public double Vertical { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public Scale(double scale = 1.0) : this(scale, scale)
|
||||
{ }
|
||||
|
||||
public Scale(double horizontal, double vertical)
|
||||
{
|
||||
this.Horizontal = horizontal;
|
||||
this.Vertical = vertical;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public bool Equals(Scale other) => Horizontal.EqualsInTolerance(other.Horizontal) && Vertical.EqualsInTolerance(other.Vertical);
|
||||
public override bool Equals(object obj) => obj is Scale other && Equals(other);
|
||||
public override int GetHashCode() { unchecked { return (Horizontal.GetHashCode() * 397) ^ Vertical.GetHashCode(); } }
|
||||
|
||||
public void Deconstruct(out double horizontalScale, out double verticalScale)
|
||||
{
|
||||
horizontalScale = Horizontal;
|
||||
verticalScale = Vertical;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
public static implicit operator Scale(double scale) => new Scale(scale);
|
||||
public static implicit operator Scale((double horizontal, double vertical) scale) => new Scale(scale.horizontal, scale.vertical);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -94,6 +94,12 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
public void Deconstruct(out double width, out double height)
|
||||
{
|
||||
width = Width;
|
||||
height = Height;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
@ -172,6 +178,8 @@ namespace RGB.NET.Core
|
||||
/// <returns>A new <see cref="Size"/> representing the division of the <see cref="Size"/> and the provided factor.</returns>
|
||||
public static Size operator /(Size size, double factor) => factor.EqualsInTolerance(0) ? Invalid : new Size(size.Width / factor, size.Height / factor);
|
||||
|
||||
public static Size operator *(Size size, Scale scale) => new Size(size.Width * scale.Horizontal, size.Height * scale.Vertical);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ namespace RGB.NET.Groups
|
||||
/// <param name="minOverlayPercentage">(optional) The minimal percentage overlay a <see cref="T:RGB.NET.Core.Led" /> must have with the <see cref="P:RGB.NET.Groups.RectangleLedGroup.Rectangle" /> to be taken into the <see cref="T:RGB.NET.Groups.RectangleLedGroup" />. (default: 0.5)</param>
|
||||
/// <param name="autoAttach">(optional) Specifies whether this <see cref="T:RGB.NET.Groups.RectangleLedGroup" /> should be automatically attached or not. (default: true)</param>
|
||||
public RectangleLedGroup(Led fromLed, Led toLed, double minOverlayPercentage = 0.5, bool autoAttach = true)
|
||||
: this(new Rectangle(fromLed.LedRectangle, toLed.LedRectangle), minOverlayPercentage, autoAttach)
|
||||
: this(new Rectangle(fromLed.ActualLedRectangle, toLed.ActualLedRectangle), minOverlayPercentage, autoAttach)
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user