mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +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
|
||||
{
|
||||
get => _size;
|
||||
protected set
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _size, value))
|
||||
UpdateActualData();
|
||||
@ -106,10 +106,10 @@ namespace RGB.NET.Core
|
||||
#region Indexer
|
||||
|
||||
/// <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 />
|
||||
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 />
|
||||
IEnumerable<Led> IRGBDevice.this[Rectangle referenceRect, double minOverlayPercentage]
|
||||
@ -164,15 +164,6 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
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>
|
||||
/// Initializes the <see cref="Led"/> with the specified id.
|
||||
/// </summary>
|
||||
@ -180,66 +171,24 @@ namespace RGB.NET.Core
|
||||
/// <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>
|
||||
/// <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;
|
||||
|
||||
Led led = new Led(this, ledId, location, size, CreateLedCustomData(ledId));
|
||||
Led led = new(this, ledId, location, size, customData);
|
||||
LedMapping.Add(ledId, led);
|
||||
return led;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
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;
|
||||
}
|
||||
|
||||
/// <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
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -60,14 +60,14 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <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>
|
||||
Led this[LedId ledId] { get; }
|
||||
Led? this[LedId ledId] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Led" /> at the given physical location.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
Led this[Point location] { get; }
|
||||
Led? this[Point location] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="Led" /> inside the given <see cref="Rectangle"/>.
|
||||
|
||||
@ -124,7 +124,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Indicates whether the <see cref="Led" /> is about to change it's color.
|
||||
/// </summary>
|
||||
public bool IsDirty => RequestedColor.HasValue && (RequestedColor != InternalColor);
|
||||
public bool IsDirty => RequestedColor.HasValue && (RequestedColor != Color);
|
||||
|
||||
private Color? _requestedColor;
|
||||
/// <summary>
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Gets the URI of an image of the <see cref="Led"/> or null if there is no image.
|
||||
/// </summary>
|
||||
@ -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 <see cref="Led" /> to a <see cref="Core.Color" />.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// 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.LedRectangle;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user