mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
Removed layouts from devices
This commit is contained in:
parent
d4bb0bd9fd
commit
226d29156d
@ -46,7 +46,7 @@ namespace RGB.NET.Core
|
|||||||
public Size Size
|
public Size Size
|
||||||
{
|
{
|
||||||
get => _size;
|
get => _size;
|
||||||
protected set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _size, value))
|
if (SetProperty(ref _size, value))
|
||||||
UpdateActualData();
|
UpdateActualData();
|
||||||
@ -106,10 +106,10 @@ namespace RGB.NET.Core
|
|||||||
#region Indexer
|
#region Indexer
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
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.LedRectangle.Contains(location));
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
IEnumerable<Led> IRGBDevice.this[Rectangle referenceRect, double minOverlayPercentage]
|
IEnumerable<Led> IRGBDevice.this[Rectangle referenceRect, double minOverlayPercentage]
|
||||||
@ -164,15 +164,6 @@ namespace RGB.NET.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract void UpdateLeds(IEnumerable<Led> ledsToUpdate);
|
protected abstract void UpdateLeds(IEnumerable<Led> ledsToUpdate);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the <see cref="Led"/> with the specified id.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ledId">The <see cref="LedId"/> to initialize.</param>
|
|
||||||
/// <param name="ledRectangle">The <see cref="Rectangle"/> representing the position of the <see cref="Led"/> to initialize.</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[Obsolete("Use InitializeLed(LedId ledId, Point location, Size size) instead.")]
|
|
||||||
protected virtual Led InitializeLed(LedId ledId, Rectangle rectangle) => InitializeLed(ledId, rectangle.Location, rectangle.Size);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the <see cref="Led"/> with the specified id.
|
/// Initializes the <see cref="Led"/> with the specified id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -180,66 +171,24 @@ namespace RGB.NET.Core
|
|||||||
/// <param name="location">The location of the <see cref="Led"/> to initialize.</param>
|
/// <param name="location">The location of the <see cref="Led"/> to initialize.</param>
|
||||||
/// <param name="size">The size of the <see cref="Led"/> to initialize.</param>
|
/// <param name="size">The size of the <see cref="Led"/> to initialize.</param>
|
||||||
/// <returns>The initialized led.</returns>
|
/// <returns>The initialized led.</returns>
|
||||||
protected virtual Led InitializeLed(LedId ledId, Point location, Size size)
|
public virtual Led? AddLed(LedId ledId, Point location, Size size, object? customData = null)
|
||||||
{
|
{
|
||||||
if ((ledId == LedId.Invalid) || LedMapping.ContainsKey(ledId)) return null;
|
if ((ledId == LedId.Invalid) || LedMapping.ContainsKey(ledId)) return null;
|
||||||
|
|
||||||
Led led = new Led(this, ledId, location, size, CreateLedCustomData(ledId));
|
Led led = new(this, ledId, location, size, customData);
|
||||||
LedMapping.Add(ledId, led);
|
LedMapping.Add(ledId, led);
|
||||||
return led;
|
return led;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public virtual Led? RemoveLed(LedId ledId)
|
||||||
/// Applies the given layout.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="layoutPath">The file containing the layout.</param>
|
|
||||||
/// <param name="imageLayout">The name of the layout used to get the images of the leds.</param>
|
|
||||||
/// <param name="createMissingLeds">If set to true a new led is initialized for every id in the layout if it doesn't already exist.</param>
|
|
||||||
protected virtual DeviceLayout ApplyLayoutFromFile(string layoutPath, string imageLayout, bool createMissingLeds = false)
|
|
||||||
{
|
{
|
||||||
DeviceLayout layout = DeviceLayout.Load(layoutPath);
|
if (ledId == LedId.Invalid) return null;
|
||||||
if (layout != null)
|
if (!LedMapping.TryGetValue(ledId, out Led? led)) return null;
|
||||||
{
|
|
||||||
string imageBasePath = string.IsNullOrWhiteSpace(layout.ImageBasePath) ? null : PathHelper.GetAbsolutePath(this, layout.ImageBasePath);
|
|
||||||
if ((imageBasePath != null) && !string.IsNullOrWhiteSpace(layout.DeviceImage) && (DeviceInfo != null))
|
|
||||||
DeviceInfo.Image = new Uri(Path.Combine(imageBasePath, layout.DeviceImage), UriKind.Absolute);
|
|
||||||
|
|
||||||
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
|
LedMapping.Remove(ledId);
|
||||||
|
return led;
|
||||||
Size = new Size(layout.Width, layout.Height);
|
|
||||||
|
|
||||||
if (layout.Leds != null)
|
|
||||||
foreach (LedLayout layoutLed in layout.Leds)
|
|
||||||
{
|
|
||||||
if (Enum.TryParse(layoutLed.Id, true, out LedId ledId))
|
|
||||||
{
|
|
||||||
if (!LedMapping.TryGetValue(ledId, out Led led) && createMissingLeds)
|
|
||||||
led = InitializeLed(ledId, new Point(), new Size());
|
|
||||||
|
|
||||||
if (led != null)
|
|
||||||
{
|
|
||||||
led.Location = new Point(layoutLed.X, layoutLed.Y);
|
|
||||||
led.Size = new Size(layoutLed.Width, layoutLed.Height);
|
|
||||||
led.Shape = layoutLed.Shape;
|
|
||||||
led.ShapeData = layoutLed.ShapeData;
|
|
||||||
|
|
||||||
LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id);
|
|
||||||
if ((imageBasePath != null) && !string.IsNullOrEmpty(image?.Image))
|
|
||||||
led.Image = new Uri(Path.Combine(imageBasePath, image.Image), UriKind.Absolute);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return layout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates provider-specific data associated with this <see cref="LedId"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ledId">The <see cref="LedId"/>.</param>
|
|
||||||
protected virtual object CreateLedCustomData(LedId ledId) => null;
|
|
||||||
|
|
||||||
#region Enumerator
|
#region Enumerator
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -60,14 +60,14 @@ namespace RGB.NET.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ledId">The <see cref="LedId"/> of the <see cref="Led"/> to get.</param>
|
/// <param name="ledId">The <see cref="LedId"/> of the <see cref="Led"/> to get.</param>
|
||||||
/// <returns>The <see cref="Led"/> with the specified <see cref="LedId"/> or null if no <see cref="Led"/> is found.</returns>
|
/// <returns>The <see cref="Led"/> with the specified <see cref="LedId"/> or null if no <see cref="Led"/> is found.</returns>
|
||||||
Led this[LedId ledId] { get; }
|
Led? this[LedId ledId] { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="Led" /> at the given physical location.
|
/// Gets the <see cref="Led" /> at the given physical location.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="location">The <see cref="Point"/> to get the location from.</param>
|
/// <param name="location">The <see cref="Point"/> to get the location from.</param>
|
||||||
/// <returns>The <see cref="Led"/> at the given <see cref="Point"/> or null if no location is found.</returns>
|
/// <returns>The <see cref="Led"/> at the given <see cref="Point"/> or null if no location is found.</returns>
|
||||||
Led this[Point location] { get; }
|
Led? this[Point location] { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a list of <see cref="Led" /> inside the given <see cref="Rectangle"/>.
|
/// Gets a list of <see cref="Led" /> inside the given <see cref="Rectangle"/>.
|
||||||
|
|||||||
@ -124,7 +124,7 @@ namespace RGB.NET.Core
|
|||||||
/// <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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDirty => RequestedColor.HasValue && (RequestedColor != InternalColor);
|
public bool IsDirty => RequestedColor.HasValue && (RequestedColor != Color);
|
||||||
|
|
||||||
private Color? _requestedColor;
|
private Color? _requestedColor;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -152,36 +152,13 @@ namespace RGB.NET.Core
|
|||||||
get => _color;
|
get => _color;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!IsLocked)
|
if (RequestedColor.HasValue)
|
||||||
{
|
RequestedColor = RequestedColor.Value + value;
|
||||||
if (RequestedColor.HasValue)
|
else
|
||||||
RequestedColor = RequestedColor.Value + value;
|
RequestedColor = value;
|
||||||
else
|
|
||||||
RequestedColor = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or set the <see cref="Color"/> ignoring all workflows regarding locks and update-requests. />
|
|
||||||
/// </summary>
|
|
||||||
internal Color InternalColor
|
|
||||||
{
|
|
||||||
get => _color;
|
|
||||||
set => SetProperty(ref _color, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _isLocked;
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets if the color of this LED can be changed.
|
|
||||||
/// </summary>
|
|
||||||
public bool IsLocked
|
|
||||||
{
|
|
||||||
get => _isLocked;
|
|
||||||
set => SetProperty(ref _isLocked, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the URI of an image of the <see cref="Led"/> or null if there is no image.
|
/// Gets the URI of an image of the <see cref="Led"/> or null if there is no image.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -287,7 +264,6 @@ namespace RGB.NET.Core
|
|||||||
{
|
{
|
||||||
_color = Color.Transparent;
|
_color = Color.Transparent;
|
||||||
RequestedColor = null;
|
RequestedColor = null;
|
||||||
IsLocked = false;
|
|
||||||
|
|
||||||
// ReSharper disable once ExplicitCallerInfoArgument
|
// ReSharper disable once ExplicitCallerInfoArgument
|
||||||
OnPropertyChanged(nameof(Color));
|
OnPropertyChanged(nameof(Color));
|
||||||
@ -301,13 +277,13 @@ namespace RGB.NET.Core
|
|||||||
/// Converts a <see cref="Led" /> to a <see cref="Core.Color" />.
|
/// Converts a <see cref="Led" /> to a <see cref="Core.Color" />.
|
||||||
/// </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 Color(Led led) => led?.Color ?? Color.Transparent;
|
public static implicit operator Color(Led led) => led.Color;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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.LedRectangle;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user