diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs
index f9c88d4..e79d582 100644
--- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs
+++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs
@@ -46,7 +46,7 @@ namespace RGB.NET.Core
public Size Size
{
get => _size;
- protected set
+ set
{
if (SetProperty(ref _size, value))
UpdateActualData();
@@ -106,10 +106,10 @@ namespace RGB.NET.Core
#region Indexer
///
- 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;
///
- 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));
///
IEnumerable IRGBDevice.this[Rectangle referenceRect, double minOverlayPercentage]
@@ -164,15 +164,6 @@ namespace RGB.NET.Core
///
protected abstract void UpdateLeds(IEnumerable ledsToUpdate);
- ///
- /// Initializes the with the specified id.
- ///
- /// The to initialize.
- /// The representing the position of the to initialize.
- ///
- [Obsolete("Use InitializeLed(LedId ledId, Point location, Size size) instead.")]
- protected virtual Led InitializeLed(LedId ledId, Rectangle rectangle) => InitializeLed(ledId, rectangle.Location, rectangle.Size);
-
///
/// Initializes the with the specified id.
///
@@ -180,66 +171,24 @@ namespace RGB.NET.Core
/// The location of the to initialize.
/// The size of the to initialize.
/// The initialized led.
- 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;
- Led led = new Led(this, ledId, location, size, CreateLedCustomData(ledId));
+ Led led = new(this, ledId, location, size, customData);
LedMapping.Add(ledId, led);
return led;
}
- ///
- /// Applies the given layout.
- ///
- /// The file containing the layout.
- /// The name of the layout used to get the images of the leds.
- /// If set to true a new led is initialized for every id in the layout if it doesn't already exist.
- protected virtual DeviceLayout ApplyLayoutFromFile(string layoutPath, string imageLayout, bool createMissingLeds = false)
+ public virtual Led? RemoveLed(LedId ledId)
{
- DeviceLayout layout = DeviceLayout.Load(layoutPath);
- if (layout != 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);
+ if (ledId == LedId.Invalid) return null;
+ if (!LedMapping.TryGetValue(ledId, out Led? led)) return null;
- LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
-
- 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;
+ LedMapping.Remove(ledId);
+ return led;
}
- ///
- /// Creates provider-specific data associated with this .
- ///
- /// The .
- protected virtual object CreateLedCustomData(LedId ledId) => null;
-
#region Enumerator
///
diff --git a/RGB.NET.Core/Devices/IRGBDevice.cs b/RGB.NET.Core/Devices/IRGBDevice.cs
index d526bae..b979a1c 100644
--- a/RGB.NET.Core/Devices/IRGBDevice.cs
+++ b/RGB.NET.Core/Devices/IRGBDevice.cs
@@ -60,14 +60,14 @@ namespace RGB.NET.Core
///
/// The of the to get.
/// The with the specified or null if no is found.
- Led this[LedId ledId] { get; }
+ Led? this[LedId ledId] { get; }
///
/// Gets the at the given physical location.
///
/// The to get the location from.
/// The at the given or null if no location is found.
- Led this[Point location] { get; }
+ Led? this[Point location] { get; }
///
/// Gets a list of inside the given .
diff --git a/RGB.NET.Core/Leds/Led.cs b/RGB.NET.Core/Leds/Led.cs
index a7947a3..7613fb2 100644
--- a/RGB.NET.Core/Leds/Led.cs
+++ b/RGB.NET.Core/Leds/Led.cs
@@ -124,7 +124,7 @@ namespace RGB.NET.Core
///
/// Indicates whether the is about to change it's color.
///
- public bool IsDirty => RequestedColor.HasValue && (RequestedColor != InternalColor);
+ public bool IsDirty => RequestedColor.HasValue && (RequestedColor != Color);
private Color? _requestedColor;
///
@@ -152,36 +152,13 @@ namespace RGB.NET.Core
get => _color;
set
{
- if (!IsLocked)
- {
- if (RequestedColor.HasValue)
- RequestedColor = RequestedColor.Value + value;
- else
- RequestedColor = value;
- }
-
+ if (RequestedColor.HasValue)
+ RequestedColor = RequestedColor.Value + value;
+ else
+ RequestedColor = value;
}
}
- ///
- /// Gets or set the ignoring all workflows regarding locks and update-requests. />
- ///
- internal Color InternalColor
- {
- get => _color;
- set => SetProperty(ref _color, value);
- }
-
- private bool _isLocked;
- ///
- /// Gets or sets if the color of this LED can be changed.
- ///
- public bool IsLocked
- {
- get => _isLocked;
- set => SetProperty(ref _isLocked, value);
- }
-
///
/// Gets the URI of an image of the or null if there is no image.
///
@@ -287,7 +264,6 @@ namespace RGB.NET.Core
{
_color = Color.Transparent;
RequestedColor = null;
- IsLocked = false;
// ReSharper disable once ExplicitCallerInfoArgument
OnPropertyChanged(nameof(Color));
@@ -301,13 +277,13 @@ namespace RGB.NET.Core
/// Converts a to a .
///
/// The to convert.
- public static implicit operator Color(Led led) => led?.Color ?? Color.Transparent;
+ public static implicit operator Color(Led led) => led.Color;
///
/// Converts a to a .
///
/// The to convert.
- public static implicit operator Rectangle(Led led) => led?.LedRectangle ?? new Rectangle();
+ public static implicit operator Rectangle(Led led) => led.LedRectangle;
#endregion
}