1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Core - Removed Fody

UI projects will follow
Not interested in becoming a Patreon with their attitude and fixes edit & continue in the core
This commit is contained in:
SpoinkyNL 2020-06-20 22:34:39 +02:00
parent d47f347beb
commit f18edc4f36
14 changed files with 234 additions and 145 deletions

View File

@ -26,10 +26,6 @@
<PackageReference Include="Ben.Demystifier" Version="0.1.6" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="FastMember" Version="1.5.0" />
<PackageReference Include="Fody" Version="6.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="HidSharp" Version="2.1.0" />
<PackageReference Include="LiteDB" Version="5.0.8" />
<PackageReference Include="McMaster.NETCore.Plugins" Version="1.3.0" />
@ -37,7 +33,6 @@
<PackageReference Include="Ninject" Version="3.3.4" />
<PackageReference Include="Ninject.Extensions.ChildKernel" Version="3.3.0" />
<PackageReference Include="Ninject.Extensions.Conventions" Version="3.3.0" />
<PackageReference Include="PropertyChanged.Fody" Version="3.2.8" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Enrichers.Demystify" Version="1.0.0-dev-00019" />
<PackageReference Include="Serilog.Sinks.Debug" Version="1.0.1" />

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
</Weavers>

View File

@ -1,64 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EventInvokerNames" type="xs:string">
<xs:annotation>
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEquality" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressWarnings" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings from this weaver.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressOnPropertyNameChangedWarning" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings about mismatched On_PropertyName_Changed methods.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -45,15 +45,15 @@ namespace Artemis.Core.Models.Profile
// Load child folders
foreach (var childFolder in Profile.ProfileEntity.Folders.Where(f => f.ParentId == EntityId))
_children.Add(new Folder(profile, this, childFolder));
ChildrenList.Add(new Folder(profile, this, childFolder));
// Load child layers
foreach (var childLayer in Profile.ProfileEntity.Layers.Where(f => f.ParentId == EntityId))
_children.Add(new Layer(profile, this, childLayer));
ChildrenList.Add(new Layer(profile, this, childLayer));
// Ensure order integrity, should be unnecessary but no one is perfect specially me
_children = _children.OrderBy(c => c.Order).ToList();
for (var index = 0; index < _children.Count; index++)
_children[index].Order = index + 1;
ChildrenList = ChildrenList.OrderBy(c => c.Order).ToList();
for (var index = 0; index < ChildrenList.Count; index++)
ChildrenList[index].Order = index + 1;
}
internal FolderEntity FolderEntity { get; set; }

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core.Annotations;
using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
@ -23,9 +22,12 @@ namespace Artemis.Core.Models.Profile
/// </summary>
public sealed class Layer : EffectProfileElement
{
private LayerGeneralProperties _general;
private SKBitmap _layerBitmap;
private BaseLayerBrush _layerBrush;
private LayerShape _layerShape;
private List<ArtemisLed> _leds;
private SKBitmap _layerBitmap;
private LayerTransformProperties _transform;
internal Layer(Profile profile, ProfileElement parent, string name)
{
@ -84,22 +86,34 @@ namespace Artemis.Core.Models.Profile
get => _layerShape;
set
{
_layerShape = value;
SetAndNotify(ref _layerShape, value);
if (Path != null)
CalculateRenderProperties();
}
}
[PropertyGroupDescription(Name = "General", Description = "A collection of general properties")]
public LayerGeneralProperties General { get; set; }
public LayerGeneralProperties General
{
get => _general;
set => SetAndNotify(ref _general, value);
}
[PropertyGroupDescription(Name = "Transform", Description = "A collection of transformation properties")]
public LayerTransformProperties Transform { get; set; }
public LayerTransformProperties Transform
{
get => _transform;
set => SetAndNotify(ref _transform, value);
}
/// <summary>
/// The brush that will fill the <see cref="LayerShape" />.
/// </summary>
public BaseLayerBrush LayerBrush { get; internal set; }
public BaseLayerBrush LayerBrush
{
get => _layerBrush;
internal set => SetAndNotify(ref _layerBrush, value);
}
public override string ToString()
{
@ -239,11 +253,11 @@ namespace Artemis.Core.Models.Profile
return;
if (_layerBitmap == null)
_layerBitmap = new SKBitmap(new SKImageInfo((int)Path.Bounds.Width, (int)Path.Bounds.Height));
else if (_layerBitmap.Info.Width != (int)Path.Bounds.Width || _layerBitmap.Info.Height != (int)Path.Bounds.Height)
_layerBitmap = new SKBitmap(new SKImageInfo((int) Path.Bounds.Width, (int) Path.Bounds.Height));
else if (_layerBitmap.Info.Width != (int) Path.Bounds.Width || _layerBitmap.Info.Height != (int) Path.Bounds.Height)
{
_layerBitmap.Dispose();
_layerBitmap = new SKBitmap(new SKImageInfo((int)Path.Bounds.Width, (int)Path.Bounds.Height));
_layerBitmap = new SKBitmap(new SKImageInfo((int) Path.Bounds.Width, (int) Path.Bounds.Height));
}
using var layerPath = new SKPath(Path);
@ -255,9 +269,9 @@ namespace Artemis.Core.Models.Profile
Color = new SKColor(0, 0, 0, (byte) (Transform.Opacity.CurrentValue * 2.55f))
};
layerCanvas.Clear();
layerPath.Transform(SKMatrix.MakeTranslation(layerPath.Bounds.Left * -1, layerPath.Bounds.Top * -1));
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
baseLayerEffect.PreProcess(layerCanvas, _layerBitmap.Info, layerPath, layerPaint);
@ -278,7 +292,6 @@ namespace Artemis.Core.Models.Profile
targetLocation = Path.Bounds.Location - parentFolder.Path.Bounds.Location;
canvas.DrawBitmap(_layerBitmap, targetLocation, layerPaint);
}
private void SimpleRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint, SKPath layerPath)

View File

@ -11,6 +11,8 @@ namespace Artemis.Core.Models.Profile
{
public sealed class Profile : ProfileElement
{
private bool _isActivated;
internal Profile(PluginInfo pluginInfo, string name)
{
ProfileEntity = new ProfileEntity();
@ -38,7 +40,12 @@ namespace Artemis.Core.Models.Profile
}
public PluginInfo PluginInfo { get; }
public bool IsActivated { get; private set; }
public bool IsActivated
{
get => _isActivated;
private set => SetAndNotify(ref _isActivated, value);
}
internal ProfileEntity ProfileEntity { get; set; }
@ -78,14 +85,14 @@ namespace Artemis.Core.Models.Profile
{
Name = ProfileEntity.Name;
lock (_children)
lock (ChildrenList)
{
foreach (var folder in GetAllFolders())
folder.Deactivate();
foreach (var layer in GetAllLayers())
layer.Deactivate();
_children.Clear();
ChildrenList.Clear();
// Populate the profile starting at the root, the rest is populated recursively
var rootFolder = ProfileEntity.Folders.FirstOrDefault(f => f.ParentId == EntityId);
if (rootFolder == null)

View File

@ -9,36 +9,68 @@ namespace Artemis.Core.Models.Profile
{
public abstract class ProfileElement : PropertyChangedBase
{
protected List<ProfileElement> _children;
private bool _enabled;
private Guid _entityId;
private string _name;
private int _order;
private ProfileElement _parent;
private Profile _profile;
protected List<ProfileElement> ChildrenList;
protected ProfileElement()
{
_children = new List<ProfileElement>();
ChildrenList = new List<ProfileElement>();
}
public Guid EntityId { get; internal set; }
public Profile Profile { get; internal set; }
public ProfileElement Parent { get; internal set; }
public Guid EntityId
{
get => _entityId;
internal set => SetAndNotify(ref _entityId, value);
}
public Profile Profile
{
get => _profile;
internal set => SetAndNotify(ref _profile, value);
}
public ProfileElement Parent
{
get => _parent;
internal set => SetAndNotify(ref _parent, value);
}
/// <summary>
/// The element's children
/// </summary>
public ReadOnlyCollection<ProfileElement> Children => _children.AsReadOnly();
public ReadOnlyCollection<ProfileElement> Children => ChildrenList.AsReadOnly();
/// <summary>
/// The order in which this element appears in the update loop and editor
/// </summary>
public int Order { get; internal set; }
public int Order
{
get => _order;
internal set => SetAndNotify(ref _order, value);
}
/// <summary>
/// The name which appears in the editor
/// </summary>
public string Name { get; set; }
public string Name
{
get => _name;
set => SetAndNotify(ref _name, value);
}
/// <summary>
/// Gets or sets the enabled state, if not enabled the element is skipped in render and update
/// </summary>
public bool Enabled { get; set; }
public bool Enabled
{
get => _enabled;
set => SetAndNotify(ref _enabled, value);
}
/// <summary>
/// Updates the element
@ -86,29 +118,29 @@ namespace Artemis.Core.Models.Profile
/// <param name="order">The order where to place the child (1-based), defaults to the end of the collection</param>
public virtual void AddChild(ProfileElement child, int? order = null)
{
lock (_children)
lock (ChildrenList)
{
// Add to the end of the list
if (order == null)
{
_children.Add(child);
child.Order = _children.Count;
ChildrenList.Add(child);
child.Order = ChildrenList.Count;
}
// Shift everything after the given order
else
{
foreach (var profileElement in _children.Where(c => c.Order >= order).ToList())
foreach (var profileElement in ChildrenList.Where(c => c.Order >= order).ToList())
profileElement.Order++;
int targetIndex;
if (order == 0)
targetIndex = 0;
else if (order > _children.Count)
targetIndex = _children.Count;
else if (order > ChildrenList.Count)
targetIndex = ChildrenList.Count;
else
targetIndex = _children.FindIndex(c => c.Order == order + 1);
targetIndex = ChildrenList.FindIndex(c => c.Order == order + 1);
_children.Insert(targetIndex, child);
ChildrenList.Insert(targetIndex, child);
child.Order = order.Value;
}
@ -122,12 +154,12 @@ namespace Artemis.Core.Models.Profile
/// <param name="child">The profile element to remove</param>
public virtual void RemoveChild(ProfileElement child)
{
lock (_children)
lock (ChildrenList)
{
_children.Remove(child);
ChildrenList.Remove(child);
// Shift everything after the given order
foreach (var profileElement in _children.Where(c => c.Order > child.Order).ToList())
foreach (var profileElement in ChildrenList.Where(c => c.Order > child.Order).ToList())
profileElement.Order--;
child.Parent = null;

View File

@ -6,9 +6,8 @@ namespace Artemis.Core.Models.Profile
{
public abstract class PropertiesProfileElement : ProfileElement
{
internal abstract PropertiesEntity PropertiesEntity { get; }
private SKPath _path;
internal abstract PropertiesEntity PropertiesEntity { get; }
/// <summary>
/// Gets the path containing all the LEDs this entity is applied to, any rendering outside the entity Path is
@ -19,7 +18,7 @@ namespace Artemis.Core.Models.Profile
get => _path;
protected set
{
_path = value;
SetAndNotify(ref _path, value);
// I can't really be sure about the performance impact of calling Bounds often but
// SkiaSharp calls SkiaApi.sk_path_get_bounds (Handle, &rect); which sounds expensive
Bounds = value?.Bounds ?? SKRect.Empty;
@ -29,12 +28,17 @@ namespace Artemis.Core.Models.Profile
/// <summary>
/// The bounds of this entity
/// </summary>
public SKRect Bounds { get; private set; }
public SKRect Bounds
{
get => _bounds;
private set => SetAndNotify(ref _bounds, value);
}
#region Property group expansion
protected List<string> _expandedPropertyGroups;
private SKRect _bounds;
public bool IsPropertyGroupExpanded(LayerPropertyGroup layerPropertyGroup)
{
return _expandedPropertyGroups.Contains(layerPropertyGroup.Path);
@ -49,6 +53,5 @@ namespace Artemis.Core.Models.Profile
}
#endregion
}
}

View File

@ -12,6 +12,10 @@ namespace Artemis.Core.Models.Surface
{
public class ArtemisDevice : PropertyChangedBase
{
private SKRect _renderRectangle;
private SKPath _renderPath;
private ReadOnlyCollection<ArtemisLed> _leds;
internal ArtemisDevice(IRGBDevice rgbDevice, Plugin plugin, ArtemisSurface surface)
{
RgbDevice = rgbDevice;
@ -37,14 +41,28 @@ namespace Artemis.Core.Models.Surface
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
}
public SKRect RenderRectangle { get; private set; }
public SKPath RenderPath { get; private set; }
public SKRect RenderRectangle
{
get => _renderRectangle;
private set => SetAndNotify(ref _renderRectangle, value);
}
public SKPath RenderPath
{
get => _renderPath;
private set => SetAndNotify(ref _renderPath, value);
}
public IRGBDevice RgbDevice { get; }
public Plugin Plugin { get; }
public ArtemisSurface Surface { get; }
public DeviceEntity DeviceEntity { get; }
public ReadOnlyCollection<ArtemisLed> Leds { get; set; }
public ReadOnlyCollection<ArtemisLed> Leds
{
get => _leds;
set => SetAndNotify(ref _leds, value);
}
public double X
{

View File

@ -7,6 +7,9 @@ namespace Artemis.Core.Models.Surface
{
public class ArtemisLed : PropertyChangedBase
{
private SKRect _renderRectangle;
private SKRect _absoluteRenderRectangle;
public ArtemisLed(Led led, ArtemisDevice device)
{
RgbLed = led;
@ -18,9 +21,18 @@ namespace Artemis.Core.Models.Surface
public Led RgbLed { get; }
public ArtemisDevice Device { get; }
public SKRect RenderRectangle { get; private set; }
public SKRect AbsoluteRenderRectangle { get; private set; }
public SKRect RenderRectangle
{
get => _renderRectangle;
private set => SetAndNotify(ref _renderRectangle, value);
}
public SKRect AbsoluteRenderRectangle
{
get => _absoluteRenderRectangle;
private set => SetAndNotify(ref _absoluteRenderRectangle, value);
}
public void CalculateRenderRectangle()
{
RenderRectangle = SKRect.Create(

View File

@ -9,6 +9,11 @@ namespace Artemis.Core.Models.Surface
{
public class ArtemisSurface : PropertyChangedBase
{
private double _scale;
private string _name;
private bool _isActive;
private List<ArtemisDevice> _devices;
internal ArtemisSurface(RGBSurface rgbSurface, string name, double scale)
{
SurfaceEntity = new SurfaceEntity {DeviceEntities = new List<DeviceEntity>()};
@ -40,10 +45,30 @@ namespace Artemis.Core.Models.Surface
}
public RGBSurface RgbSurface { get; }
public double Scale { get; private set; }
public string Name { get; set; }
public bool IsActive { get; internal set; }
public List<ArtemisDevice> Devices { get; internal set; }
public double Scale
{
get => _scale;
private set => SetAndNotify(ref _scale, value);
}
public string Name
{
get => _name;
set => SetAndNotify(ref _name, value);
}
public bool IsActive
{
get => _isActive;
internal set => SetAndNotify(ref _isActive, value);
}
public List<ArtemisDevice> Devices
{
get => _devices;
internal set => SetAndNotify(ref _devices, value);
}
internal SurfaceEntity SurfaceEntity { get; set; }
internal Guid EntityId { get; set; }

View File

@ -13,28 +13,43 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
/// </summary>
public abstract class BaseLayerBrush : PropertyChangedBase, IDisposable
{
private LayerBrushType _brushType;
private LayerBrushDescriptor _descriptor;
private Layer _layer;
private bool _supportsTransformation = true;
/// <summary>
/// Gets the layer this brush is applied to
/// </summary>
public Layer Layer { get; internal set; }
public Layer Layer
{
get => _layer;
internal set => SetAndNotify(ref _layer, value);
}
/// <summary>
/// Gets the descriptor of this brush
/// </summary>
public LayerBrushDescriptor Descriptor { get; internal set; }
public LayerBrushDescriptor Descriptor
{
get => _descriptor;
internal set => SetAndNotify(ref _descriptor, value);
}
/// <summary>
/// Gets the type of layer brush
/// </summary>
public LayerBrushType BrushType
{
get => _brushType;
internal set => SetAndNotify(ref _brushType, value);
}
/// <summary>
/// Gets the plugin info that defined this brush
/// </summary>
public PluginInfo PluginInfo => Descriptor.LayerBrushProvider.PluginInfo;
/// <summary>
/// Gets the type of layer brush
/// </summary>
public LayerBrushType BrushType { get; internal set; }
/// <summary>
/// Gets a reference to the layer property group without knowing it's type
/// </summary>

View File

@ -12,41 +12,77 @@ namespace Artemis.Core.Plugins.LayerEffect.Abstract
/// </summary>
public abstract class BaseLayerEffect : PropertyChangedBase, IDisposable
{
private Guid _entityId;
private EffectProfileElement _profileElement;
private string _name;
private bool _enabled;
private bool _hasBeenRenamed;
private int _order;
private LayerEffectDescriptor _descriptor;
/// <summary>
/// Gets the unique ID of this effect
/// </summary>
public Guid EntityId { get; internal set; }
public Guid EntityId
{
get => _entityId;
internal set => SetAndNotify(ref _entityId, value);
}
/// <summary>
/// Gets the profile element (such as layer or folder) this effect is applied to
/// </summary>
public EffectProfileElement ProfileElement { get; internal set; }
public EffectProfileElement ProfileElement
{
get => _profileElement;
internal set => SetAndNotify(ref _profileElement, value);
}
/// <summary>
/// The name which appears in the editor
/// </summary>
public string Name { get; set; }
public string Name
{
get => _name;
set => SetAndNotify(ref _name, value);
}
/// <summary>
/// Gets or sets the enabled state, if not enabled the effect is skipped in render and update
/// </summary>
public bool Enabled { get; set; }
public bool Enabled
{
get => _enabled;
set => SetAndNotify(ref _enabled, value);
}
/// <summary>
/// Gets or sets whether the effect has been renamed by the user, if true consider refraining from changing the name
/// programatically
/// </summary>
public bool HasBeenRenamed { get; set; }
public bool HasBeenRenamed
{
get => _hasBeenRenamed;
set => SetAndNotify(ref _hasBeenRenamed, value);
}
/// <summary>
/// Gets the order in which this effect appears in the update loop and editor
/// </summary>
public int Order { get; set; }
public int Order
{
get => _order;
set => SetAndNotify(ref _order, value);
}
/// <summary>
/// Gets the descriptor of this effect
/// </summary>
public LayerEffectDescriptor Descriptor { get; internal set; }
public LayerEffectDescriptor Descriptor
{
get => _descriptor;
internal set => SetAndNotify(ref _descriptor, value);
}
/// <summary>
/// Gets the plugin info that defined this effect

View File

@ -67,9 +67,11 @@ namespace Artemis.Core.Services
_logger.Warning("Device provider {deviceProvider} has no devices", deviceProvider.GetType().Name);
return;
}
foreach (var surfaceDevice in deviceProvider.Devices)
{
_logger.Debug("Device provider {deviceProvider} added {deviceName}",
deviceProvider.GetType().Name, surfaceDevice.DeviceInfo?.DeviceName);
if (!_loadedDevices.Contains(surfaceDevice))
{
_loadedDevices.Add(surfaceDevice);