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 />
|
/// <inheritdoc />
|
||||||
public Size Size
|
public Size Size
|
||||||
{
|
{
|
||||||
get => _size;
|
get => _size * Scale;
|
||||||
set => SetProperty(ref _size, value);
|
protected set => SetProperty(ref _size, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point _location = new Point(0, 0);
|
private Point _location = new Point(0, 0);
|
||||||
@ -43,6 +43,18 @@ namespace RGB.NET.Core
|
|||||||
set => SetProperty(ref _location, value);
|
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>
|
/// <summary>
|
||||||
/// Gets or sets if the device needs to be flushed on every update.
|
/// Gets or sets if the device needs to be flushed on every update.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -67,11 +79,11 @@ namespace RGB.NET.Core
|
|||||||
Led IRGBDevice.this[LedId ledId] => LedMapping.TryGetValue(ledId, out Led led) ? led : null;
|
Led IRGBDevice.this[LedId ledId] => LedMapping.TryGetValue(ledId, out Led led) ? led : null;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <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 />
|
/// <inheritdoc />
|
||||||
IEnumerable<Led> IRGBDevice.this[Rectangle referenceRect, double minOverlayPercentage]
|
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
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,8 @@ namespace RGB.NET.Core
|
|||||||
/// Gets a copy of the <see cref="Size"/> of the whole <see cref="IRGBDevice"/>.
|
/// Gets a copy of the <see cref="Size"/> of the whole <see cref="IRGBDevice"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Size Size { get; }
|
Size Size { get; }
|
||||||
|
|
||||||
|
Scale Scale { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="DeviceUpdateMode"/> of the <see cref="IRGBDevice"/>.
|
/// Gets or sets the <see cref="DeviceUpdateMode"/> of the <see cref="IRGBDevice"/>.
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace RGB.NET.Core
|
namespace RGB.NET.Core
|
||||||
@ -54,14 +55,19 @@ namespace RGB.NET.Core
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _ledRectangle, value))
|
if (SetProperty(ref _ledRectangle, value))
|
||||||
|
{
|
||||||
|
OnPropertyChanged(nameof(ActualLedRectangle));
|
||||||
OnPropertyChanged(nameof(AbsoluteLedRectangle));
|
OnPropertyChanged(nameof(AbsoluteLedRectangle));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Rectangle ActualLedRectangle => new Rectangle(LedRectangle.Location * Device.Scale, LedRectangle.Size * Device.Scale);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a rectangle representing the physical location of the <see cref="Led"/> on the <see cref="RGBSurface"/>.
|
/// Gets a rectangle representing the physical location of the <see cref="Led"/> on the <see cref="RGBSurface"/>.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Indicates whether the <see cref="Led" /> is about to change it's color.
|
/// 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.LedRectangle = ledRectangle;
|
||||||
this.CustomData = customData;
|
this.CustomData = customData;
|
||||||
|
|
||||||
device.PropertyChanged += (sender, args) =>
|
device.PropertyChanged += DevicePropertyChanged;
|
||||||
{
|
|
||||||
OnPropertyChanged(nameof(LedRectangle));
|
|
||||||
OnPropertyChanged(nameof(AbsoluteLedRectangle));
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#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>
|
/// <summary>
|
||||||
/// Converts the <see cref="Id"/> and the <see cref="Color"/> of this <see cref="Led"/> to a human-readable string.
|
/// Converts the <see cref="Id"/> and the <see cref="Color"/> of this <see cref="Led"/> to a human-readable string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -210,7 +225,7 @@ namespace RGB.NET.Core
|
|||||||
/// Converts a <see cref="Led" /> to a <see cref="Rectangle" />.
|
/// Converts a <see cref="Led" /> to a <see cref="Rectangle" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="led">The <see cref="Led"/> to convert.</param>
|
/// <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
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -149,6 +149,8 @@ namespace RGB.NET.Core
|
|||||||
return new Point(point1.X / point2.X, point1.Y / point2.Y);
|
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
|
#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
|
#endregion
|
||||||
|
|
||||||
#region Operators
|
#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>
|
/// <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, 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
|
#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="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>
|
/// <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)
|
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 />
|
/// <inheritdoc />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user