Core - Added XML comments to all remaining public members/methods

Core - Refactored a lot of code for nullable reference types
This commit is contained in:
Robert committed 2020-11-16 20:16:06 +01:00
1 parent 61fc96742d
commit a3cd32f6c4
107 files changed
+1150 -649

No files matched your search

@@ -1,22 +1,26 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core.DeviceProviders;
using Artemis.Storage.Entities.Surface;
using RGB.NET.Core;
using SkiaSharp;
namespace Artemis.Core
{
/// <summary>
/// Represents an RGB device usable by Artemis, provided by a <see cref="DeviceProviders.DeviceProvider" />
/// </summary>
public class ArtemisDevice : CorePropertyChanged
{
private ReadOnlyCollection<ArtemisLed> _leds;
private SKPath _renderPath;
private SKRect _renderRectangle;
internal ArtemisDevice(IRGBDevice rgbDevice, PluginFeature pluginFeature, ArtemisSurface surface)
internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider, ArtemisSurface surface)
{
RgbDevice = rgbDevice;
PluginFeature = pluginFeature;
DeviceProvider = deviceProvider;
Surface = surface;
DeviceEntity = new DeviceEntity();
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
@@ -29,38 +33,60 @@ namespace Artemis.Core
CalculateRenderProperties();
}
internal ArtemisDevice(IRGBDevice rgbDevice, PluginFeature pluginFeature, ArtemisSurface surface, DeviceEntity deviceEntity)
internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider, ArtemisSurface surface, DeviceEntity deviceEntity)
{
RgbDevice = rgbDevice;
PluginFeature = pluginFeature;
DeviceProvider = deviceProvider;
Surface = surface;
DeviceEntity = deviceEntity;
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
}
/// <summary>
/// Gets the rectangle covering the device, sized to match the render scale
/// </summary>
public SKRect RenderRectangle
{
get => _renderRectangle;
private set => SetAndNotify(ref _renderRectangle, value);
}
/// <summary>
/// Gets the path surrounding the device, sized to match the render scale
/// </summary>
public SKPath RenderPath
{
get => _renderPath;
private set => SetAndNotify(ref _renderPath, value);
}
/// <summary>
/// Gets the RGB.NET device backing this Artemis device
/// </summary>
public IRGBDevice RgbDevice { get; }
public PluginFeature PluginFeature { get; }
public ArtemisSurface Surface { get; }
public DeviceEntity DeviceEntity { get; }
/// <summary>
/// Gets the device provider that provided this device
/// </summary>
public DeviceProvider DeviceProvider { get; }
/// <summary>
/// Gets the surface containing this device
/// </summary>
public ArtemisSurface Surface { get; }
/// <summary>
/// Gets a read only collection containing the LEDs of this device
/// </summary>
public ReadOnlyCollection<ArtemisLed> Leds
{
get => _leds;
set => SetAndNotify(ref _leds, value);
private set => SetAndNotify(ref _leds, value);
}
/// <summary>
/// Gets or sets the X-position of the device
/// </summary>
public double X
{
get => DeviceEntity.X;
@@ -71,6 +97,9 @@ namespace Artemis.Core
}
}
/// <summary>
/// Gets or sets the Y-position of the device
/// </summary>
public double Y
{
get => DeviceEntity.Y;
@@ -81,6 +110,9 @@ namespace Artemis.Core
}
}
/// <summary>
/// Gets or sets the rotation of the device
/// </summary>
public double Rotation
{
get => DeviceEntity.Rotation;
@@ -91,6 +123,9 @@ namespace Artemis.Core
}
}
/// <summary>
/// Gets or sets the scale of the device
/// </summary>
public double Scale
{
get => DeviceEntity.Scale;
@@ -101,6 +136,9 @@ namespace Artemis.Core
}
}
/// <summary>
/// Gets or sets the Z-index of the device
/// </summary>
public int ZIndex
{
get => DeviceEntity.ZIndex;
@@ -111,13 +149,22 @@ namespace Artemis.Core
}
}
internal DeviceEntity DeviceEntity { get; }
/// <inheritdoc />
public override string ToString()
{
return $"[{RgbDevice.DeviceInfo.DeviceType}] {RgbDevice.DeviceInfo.DeviceName} - {X}.{Y}.{ZIndex}";
}
public event EventHandler DeviceUpdated;
/// <summary>
/// Occurs when the underlying RGB.NET device was updated
/// </summary>
public event EventHandler? DeviceUpdated;
/// <summary>
/// Invokes the <see cref="DeviceUpdated" /> event
/// </summary>
protected virtual void OnDeviceUpdated()
{
DeviceUpdated?.Invoke(this, EventArgs.Empty);
+19 -3
View File
@@ -3,35 +3,51 @@ using SkiaSharp;
namespace Artemis.Core
{
/// <summary>
/// Represents an RGB LED contained in an <see cref="ArtemisDevice" />
/// </summary>
public class ArtemisLed : CorePropertyChanged
{
private SKRect _absoluteRenderRectangle;
private SKRect _renderRectangle;
public ArtemisLed(Led led, ArtemisDevice device)
internal ArtemisLed(Led led, ArtemisDevice device)
{
RgbLed = led;
Device = device;
CalculateRenderRectangle();
}
public int LedIndex => Device.Leds.IndexOf(this);
/// <summary>
/// Gets the RGB.NET LED backing this Artemis LED
/// </summary>
public Led RgbLed { get; }
/// <summary>
/// Gets the device that contains this LED
/// </summary>
public ArtemisDevice Device { get; }
/// <summary>
/// Gets the rectangle covering the LED, sized to match the render scale and positioned relative to the
/// <see cref="Device" />
/// </summary>
public SKRect RenderRectangle
{
get => _renderRectangle;
private set => SetAndNotify(ref _renderRectangle, value);
}
/// <summary>
/// Gets the rectangle covering the LED, sized to match the render scale
/// </summary>
public SKRect AbsoluteRenderRectangle
{
get => _absoluteRenderRectangle;
private set => SetAndNotify(ref _absoluteRenderRectangle, value);
}
public void CalculateRenderRectangle()
internal void CalculateRenderRectangle()
{
RenderRectangle = SKRect.Create(
(RgbLed.LedRectangle.Location.X * Device.Surface.Scale).RoundToInt(),
@@ -6,6 +6,9 @@ using RGB.NET.Core;
namespace Artemis.Core
{
/// <summary>
/// Represents a surface of a specific scale, containing all the available <see cref="ArtemisDevice" />s
/// </summary>
public class ArtemisSurface : CorePropertyChanged
{
private List<ArtemisDevice> _devices;
@@ -17,14 +20,14 @@ namespace Artemis.Core
{
SurfaceEntity = new SurfaceEntity {DeviceEntities = new List<DeviceEntity>()};
EntityId = Guid.NewGuid();
Name = name;
Scale = scale;
RgbSurface = rgbSurface;
IsActive = false;
_name = name;
_scale = scale;
_isActive = false;
// Devices are not populated here but as they are detected
Devices = new List<ArtemisDevice>();
_devices = new List<ArtemisDevice>();
ApplyToEntity();
}
@@ -33,36 +36,51 @@ namespace Artemis.Core
{
SurfaceEntity = surfaceEntity;
EntityId = surfaceEntity.Id;
RgbSurface = rgbSurface;
Scale = scale;
Name = surfaceEntity.Name;
IsActive = surfaceEntity.IsActive;
_scale = scale;
_name = surfaceEntity.Name;
_isActive = surfaceEntity.IsActive;
// Devices are not populated here but as they are detected
Devices = new List<ArtemisDevice>();
_devices = new List<ArtemisDevice>();
}
/// <summary>
/// Gets the RGB.NET surface backing this Artemis surface
/// </summary>
public RGBSurface RgbSurface { get; }
/// <summary>
/// Gets the scale at which this surface is rendered
/// </summary>
public double Scale
{
get => _scale;
private set => SetAndNotify(ref _scale, value);
}
/// <summary>
/// Gets the name of the surface
/// </summary>
public string Name
{
get => _name;
set => SetAndNotify(ref _name, value);
}
/// <summary>
/// Gets a boolean indicating whether this surface is the currently active surface
/// </summary>
public bool IsActive
{
get => _isActive;
internal set => SetAndNotify(ref _isActive, value);
}
/// <summary>
/// Gets a list of devices this surface contains
/// </summary>
public List<ArtemisDevice> Devices
{
get => _devices;
@@ -72,6 +90,10 @@ namespace Artemis.Core
internal SurfaceEntity SurfaceEntity { get; set; }
internal Guid EntityId { get; set; }
/// <summary>
/// Updates the scale of the surface
/// </summary>
/// <param name="value"></param>
public void UpdateScale(double value)
{
Scale = value;
@@ -89,16 +111,20 @@ namespace Artemis.Core
// Add missing device entities, don't remove old ones in case they come back later
foreach (DeviceEntity deviceEntity in Devices.Select(d => d.DeviceEntity).ToList())
{
if (!SurfaceEntity.DeviceEntities.Contains(deviceEntity))
SurfaceEntity.DeviceEntities.Add(deviceEntity);
}
}
#region Events
public event EventHandler<EventArgs> ScaleChanged;
/// <summary>
/// Occurs when the scale of the surface is changed
/// </summary>
public event EventHandler<EventArgs>? ScaleChanged;
/// <summary>
/// Invokes the <see cref="ScaleChanged" /> event
/// </summary>
protected virtual void OnScaleChanged()
{
ScaleChanged?.Invoke(this, EventArgs.Empty);