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 committed 2020-06-20 22:35:09 +02:00
1 parent d47f347beb
commit f18edc4f36
14 files changed
+234 -145

No files matched your search

+5 -5
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; }
+25 -12
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)
+10 -3
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)
@@ -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;
@@ -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
}
}
@@ -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
{
+15 -3
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(
@@ -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; }