mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-01 02:03:32 +00:00
Profiles - Dispose WIP
This commit is contained in:
parent
1f70c65651
commit
c0bdd8cf26
@ -172,7 +172,7 @@ namespace Artemis.Core.Models.Profile
|
|||||||
profileElement.Render(deltaTime, folderCanvas, _folderBitmap.Info);
|
profileElement.Render(deltaTime, folderCanvas, _folderBitmap.Info);
|
||||||
folderCanvas.Restore();
|
folderCanvas.Restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
|
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
|
||||||
baseLayerEffect.PostProcess(canvas, canvasInfo, folderPath, folderPaint);
|
baseLayerEffect.PostProcess(canvas, canvasInfo, folderPath, folderPaint);
|
||||||
canvas.DrawBitmap(_folderBitmap, targetLocation, folderPaint);
|
canvas.DrawBitmap(_folderBitmap, targetLocation, folderPaint);
|
||||||
@ -229,6 +229,18 @@ namespace Artemis.Core.Models.Profile
|
|||||||
OnRenderPropertiesUpdated();
|
OnRenderPropertiesUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (!disposing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_folderBitmap?.Dispose();
|
||||||
|
foreach (var baseLayerEffect in LayerEffects)
|
||||||
|
baseLayerEffect.Dispose();
|
||||||
|
foreach (var profileElement in Children)
|
||||||
|
profileElement.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
internal override void ApplyToEntity()
|
internal override void ApplyToEntity()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -141,6 +141,20 @@ namespace Artemis.Core.Models.Profile
|
|||||||
return keyframes;
|
return keyframes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (!disposing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_general?.Dispose();
|
||||||
|
_layerBitmap?.Dispose();
|
||||||
|
_layerBrush?.Dispose();
|
||||||
|
_transform?.Dispose();
|
||||||
|
|
||||||
|
foreach (var baseLayerEffect in LayerEffects)
|
||||||
|
baseLayerEffect.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
#region Storage
|
#region Storage
|
||||||
|
|
||||||
internal override void ApplyToEntity()
|
internal override void ApplyToEntity()
|
||||||
@ -328,9 +342,9 @@ namespace Artemis.Core.Models.Profile
|
|||||||
|
|
||||||
if (!LayerBrush.SupportsTransformation)
|
if (!LayerBrush.SupportsTransformation)
|
||||||
SimpleRender(layerCanvas, _layerBitmap.Info, layerPaint, layerPath);
|
SimpleRender(layerCanvas, _layerBitmap.Info, layerPaint, layerPath);
|
||||||
else if (General.FillType.CurrentValue == LayerFillType.Stretch)
|
else if (General.ResizeMode.CurrentValue == LayerResizeMode.Normal)
|
||||||
StretchRender(layerCanvas, _layerBitmap.Info, layerPaint, layerPath);
|
StretchRender(layerCanvas, _layerBitmap.Info, layerPaint, layerPath);
|
||||||
else if (General.FillType.CurrentValue == LayerFillType.Clip)
|
else if (General.ResizeMode.CurrentValue == LayerResizeMode.Clip)
|
||||||
ClipRender(layerCanvas, _layerBitmap.Info, layerPaint, layerPath);
|
ClipRender(layerCanvas, _layerBitmap.Info, layerPaint, layerPath);
|
||||||
|
|
||||||
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
|
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
|
||||||
@ -340,7 +354,7 @@ namespace Artemis.Core.Models.Profile
|
|||||||
if (Parent is Folder parentFolder)
|
if (Parent is Folder parentFolder)
|
||||||
targetLocation = Path.Bounds.Location - parentFolder.Path.Bounds.Location;
|
targetLocation = Path.Bounds.Location - parentFolder.Path.Bounds.Location;
|
||||||
|
|
||||||
|
|
||||||
canvas.DrawBitmap(_layerBitmap, targetLocation, layerPaint);
|
canvas.DrawBitmap(_layerBitmap, targetLocation, layerPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,10 +479,10 @@ namespace Artemis.Core.Models.Profile
|
|||||||
var x = anchorPosition.X - (zeroBased ? Bounds.MidX - Bounds.Left : Bounds.MidX) - anchorProperty.X * Bounds.Width;
|
var x = anchorPosition.X - (zeroBased ? Bounds.MidX - Bounds.Left : Bounds.MidX) - anchorProperty.X * Bounds.Width;
|
||||||
var y = anchorPosition.Y - (zeroBased ? Bounds.MidY - Bounds.Top : Bounds.MidY) - anchorProperty.Y * Bounds.Height;
|
var y = anchorPosition.Y - (zeroBased ? Bounds.MidY - Bounds.Top : Bounds.MidY) - anchorProperty.Y * Bounds.Height;
|
||||||
|
|
||||||
if (General.FillType == LayerFillType.Stretch)
|
if (General.ResizeMode == LayerResizeMode.Normal)
|
||||||
{
|
{
|
||||||
path.Transform(SKMatrix.MakeTranslation(x, y));
|
path.Transform(SKMatrix.MakeTranslation(x, y));
|
||||||
path.Transform(SKMatrix.MakeScale((sizeProperty.Width / 100f), (sizeProperty.Height / 100f), anchorPosition.X, anchorPosition.Y));
|
path.Transform(SKMatrix.MakeScale(sizeProperty.Width / 100f, sizeProperty.Height / 100f, anchorPosition.X, anchorPosition.Y));
|
||||||
path.Transform(SKMatrix.MakeRotationDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y));
|
path.Transform(SKMatrix.MakeRotationDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -497,7 +511,7 @@ namespace Artemis.Core.Models.Profile
|
|||||||
var reversedXScale = 1f / (sizeProperty.Width / 100f);
|
var reversedXScale = 1f / (sizeProperty.Width / 100f);
|
||||||
var reversedYScale = 1f / (sizeProperty.Height / 100f);
|
var reversedYScale = 1f / (sizeProperty.Height / 100f);
|
||||||
|
|
||||||
if (General.FillType == LayerFillType.Stretch)
|
if (General.ResizeMode == LayerResizeMode.Normal)
|
||||||
{
|
{
|
||||||
path.Transform(SKMatrix.MakeRotationDegrees(rotationProperty * -1, anchorPosition.X, anchorPosition.Y));
|
path.Transform(SKMatrix.MakeRotationDegrees(rotationProperty * -1, anchorPosition.X, anchorPosition.Y));
|
||||||
path.Transform(SKMatrix.MakeScale(reversedXScale, reversedYScale, anchorPosition.X, anchorPosition.Y));
|
path.Transform(SKMatrix.MakeScale(reversedXScale, reversedYScale, anchorPosition.X, anchorPosition.Y));
|
||||||
@ -530,7 +544,7 @@ namespace Artemis.Core.Models.Profile
|
|||||||
var reversedXScale = 1f / (sizeProperty.Width / 100f);
|
var reversedXScale = 1f / (sizeProperty.Width / 100f);
|
||||||
var reversedYScale = 1f / (sizeProperty.Height / 100f);
|
var reversedYScale = 1f / (sizeProperty.Height / 100f);
|
||||||
|
|
||||||
if (General.FillType == LayerFillType.Stretch)
|
if (General.ResizeMode == LayerResizeMode.Normal)
|
||||||
{
|
{
|
||||||
canvas.Translate(x * -1, y * -1);
|
canvas.Translate(x * -1, y * -1);
|
||||||
canvas.Scale(reversedXScale, reversedYScale, anchorPosition.X, anchorPosition.Y);
|
canvas.Scale(reversedXScale, reversedYScale, anchorPosition.X, anchorPosition.Y);
|
||||||
@ -666,9 +680,9 @@ namespace Artemis.Core.Models.Profile
|
|||||||
Rectangle
|
Rectangle
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum LayerFillType
|
public enum LayerResizeMode
|
||||||
{
|
{
|
||||||
Stretch,
|
Normal,
|
||||||
Clip
|
Clip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9,8 +9,8 @@ namespace Artemis.Core.Models.Profile
|
|||||||
[PropertyDescription(Name = "Shape type", Description = "The type of shape to draw in this layer")]
|
[PropertyDescription(Name = "Shape type", Description = "The type of shape to draw in this layer")]
|
||||||
public EnumLayerProperty<LayerShapeType> ShapeType { get; set; }
|
public EnumLayerProperty<LayerShapeType> ShapeType { get; set; }
|
||||||
|
|
||||||
[PropertyDescription(Name = "Fill type", Description = "How to make the shape adjust to scale changes")]
|
[PropertyDescription(Name = "Resize mode", Description = "How to make the shape adjust to scale changes")]
|
||||||
public EnumLayerProperty<LayerFillType> FillType { get; set; }
|
public EnumLayerProperty<LayerResizeMode> ResizeMode { get; set; }
|
||||||
|
|
||||||
[PropertyDescription(Name = "Blend mode", Description = "How to blend this layer into the resulting image")]
|
[PropertyDescription(Name = "Blend mode", Description = "How to blend this layer into the resulting image")]
|
||||||
public EnumLayerProperty<SKBlendMode> BlendMode { get; set; }
|
public EnumLayerProperty<SKBlendMode> BlendMode { get; set; }
|
||||||
@ -21,11 +21,11 @@ namespace Artemis.Core.Models.Profile
|
|||||||
protected override void PopulateDefaults()
|
protected override void PopulateDefaults()
|
||||||
{
|
{
|
||||||
ShapeType.DefaultValue = LayerShapeType.Rectangle;
|
ShapeType.DefaultValue = LayerShapeType.Rectangle;
|
||||||
FillType.DefaultValue = LayerFillType.Stretch;
|
ResizeMode.DefaultValue = LayerResizeMode.Normal;
|
||||||
BlendMode.DefaultValue = SKBlendMode.SrcOver;
|
BlendMode.DefaultValue = SKBlendMode.SrcOver;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ using Artemis.Storage.Entities.Profile;
|
|||||||
|
|
||||||
namespace Artemis.Core.Models.Profile
|
namespace Artemis.Core.Models.Profile
|
||||||
{
|
{
|
||||||
public abstract class LayerPropertyGroup
|
public abstract class LayerPropertyGroup : IDisposable
|
||||||
{
|
{
|
||||||
private readonly List<BaseLayerProperty> _layerProperties;
|
private readonly List<BaseLayerProperty> _layerProperties;
|
||||||
private readonly List<LayerPropertyGroup> _layerPropertyGroups;
|
private readonly List<LayerPropertyGroup> _layerPropertyGroups;
|
||||||
@ -78,11 +78,6 @@ namespace Artemis.Core.Models.Profile
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets whether the group is expanded in the UI
|
|
||||||
/// </summary>
|
|
||||||
public bool IsExpanded { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A list of all layer properties in this group
|
/// A list of all layer properties in this group
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -112,17 +107,26 @@ namespace Artemis.Core.Models.Profile
|
|||||||
return _allLayerProperties;
|
return _allLayerProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
DisableProperties();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called before properties are fully initialized to allow you to populate
|
/// Called before property group is activated to allow you to populate <see cref="LayerProperty{T}.DefaultValue" /> on
|
||||||
/// <see cref="LayerProperty{T}.DefaultValue" /> on the properties you want
|
/// the properties you want
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract void PopulateDefaults();
|
protected abstract void PopulateDefaults();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when all layer properties in this property group have been initialized, you may access all properties on the
|
/// Called when the property group is deactivated
|
||||||
/// group here
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract void OnPropertiesInitialized();
|
protected abstract void EnableProperties();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the property group is deactivated (either the profile unloaded or the related brush/effect was removed)
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void DisableProperties();
|
||||||
|
|
||||||
protected virtual void OnPropertyGroupInitialized()
|
protected virtual void OnPropertyGroupInitialized()
|
||||||
{
|
{
|
||||||
@ -195,7 +199,7 @@ namespace Artemis.Core.Models.Profile
|
|||||||
foreach (var layerProperty in _layerProperties.Where(p => !p.IsLoadedFromStorage))
|
foreach (var layerProperty in _layerProperties.Where(p => !p.IsLoadedFromStorage))
|
||||||
layerProperty.ApplyDefaultValue();
|
layerProperty.ApplyDefaultValue();
|
||||||
|
|
||||||
OnPropertiesInitialized();
|
EnableProperties();
|
||||||
PropertiesInitialized = true;
|
PropertiesInitialized = true;
|
||||||
OnPropertyGroupInitialized();
|
OnPropertyGroupInitialized();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ namespace Artemis.Core.Models.Profile
|
|||||||
Opacity.DefaultValue = 100;
|
Opacity.DefaultValue = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Artemis.Core.Exceptions;
|
using Artemis.Core.Exceptions;
|
||||||
using Artemis.Core.Models.Surface;
|
using Artemis.Core.Models.Surface;
|
||||||
|
using Artemis.Core.Plugins.Abstract;
|
||||||
using Artemis.Core.Plugins.Models;
|
using Artemis.Core.Plugins.Models;
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
@ -13,12 +14,12 @@ namespace Artemis.Core.Models.Profile
|
|||||||
{
|
{
|
||||||
private bool _isActivated;
|
private bool _isActivated;
|
||||||
|
|
||||||
internal Profile(PluginInfo pluginInfo, string name)
|
internal Profile(ProfileModule module, string name)
|
||||||
{
|
{
|
||||||
ProfileEntity = new ProfileEntity();
|
ProfileEntity = new ProfileEntity();
|
||||||
EntityId = Guid.NewGuid();
|
EntityId = Guid.NewGuid();
|
||||||
|
|
||||||
PluginInfo = pluginInfo;
|
Module = module;
|
||||||
Name = name;
|
Name = name;
|
||||||
UndoStack = new Stack<string>();
|
UndoStack = new Stack<string>();
|
||||||
RedoStack = new Stack<string>();
|
RedoStack = new Stack<string>();
|
||||||
@ -27,19 +28,19 @@ namespace Artemis.Core.Models.Profile
|
|||||||
ApplyToEntity();
|
ApplyToEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Profile(PluginInfo pluginInfo, ProfileEntity profileEntity)
|
internal Profile(ProfileModule module, ProfileEntity profileEntity)
|
||||||
{
|
{
|
||||||
ProfileEntity = profileEntity;
|
ProfileEntity = profileEntity;
|
||||||
EntityId = profileEntity.Id;
|
EntityId = profileEntity.Id;
|
||||||
|
|
||||||
PluginInfo = pluginInfo;
|
Module = module;
|
||||||
UndoStack = new Stack<string>();
|
UndoStack = new Stack<string>();
|
||||||
RedoStack = new Stack<string>();
|
RedoStack = new Stack<string>();
|
||||||
|
|
||||||
ApplyToProfile();
|
ApplyToProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginInfo PluginInfo { get; }
|
public ProfileModule Module { get; }
|
||||||
|
|
||||||
public bool IsActivated
|
public bool IsActivated
|
||||||
{
|
{
|
||||||
@ -104,13 +105,23 @@ namespace Artemis.Core.Models.Profile
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"[Profile] {nameof(Name)}: {Name}, {nameof(IsActivated)}: {IsActivated}, {nameof(PluginInfo)}: {PluginInfo}";
|
return $"[Profile] {nameof(Name)}: {Name}, {nameof(IsActivated)}: {IsActivated}, {nameof(Module)}: {Module}";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (!disposing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Deactivate();
|
||||||
|
foreach (var profileElement in Children)
|
||||||
|
profileElement.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void ApplyToEntity()
|
internal override void ApplyToEntity()
|
||||||
{
|
{
|
||||||
ProfileEntity.Id = EntityId;
|
ProfileEntity.Id = EntityId;
|
||||||
ProfileEntity.PluginGuid = PluginInfo.Guid;
|
ProfileEntity.PluginGuid = Module.PluginInfo.Guid;
|
||||||
ProfileEntity.Name = Name;
|
ProfileEntity.Name = Name;
|
||||||
ProfileEntity.IsActive = IsActivated;
|
ProfileEntity.IsActive = IsActivated;
|
||||||
|
|
||||||
@ -144,7 +155,7 @@ namespace Artemis.Core.Models.Profile
|
|||||||
if (!IsActivated)
|
if (!IsActivated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var folder in GetAllFolders())
|
foreach (var folder in GetAllFolders())
|
||||||
folder.Deactivate();
|
folder.Deactivate();
|
||||||
foreach (var layer in GetAllLayers())
|
foreach (var layer in GetAllLayers())
|
||||||
layer.Deactivate();
|
layer.Deactivate();
|
||||||
|
|||||||
24
src/Artemis.Core/Models/Profile/ProfileDescriptor.cs
Normal file
24
src/Artemis.Core/Models/Profile/ProfileDescriptor.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using Artemis.Core.Plugins.Abstract;
|
||||||
|
using Artemis.Storage.Entities.Profile;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Models.Profile
|
||||||
|
{
|
||||||
|
public class ProfileDescriptor
|
||||||
|
{
|
||||||
|
internal ProfileDescriptor(ProfileModule profileModule, ProfileEntity profileEntity)
|
||||||
|
{
|
||||||
|
ProfileModule = profileModule;
|
||||||
|
ProfileEntity = profileEntity;
|
||||||
|
|
||||||
|
Id = profileEntity.Id;
|
||||||
|
Name = profileEntity.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Guid Id { get; }
|
||||||
|
public ProfileModule ProfileModule { get; }
|
||||||
|
public string Name { get; }
|
||||||
|
|
||||||
|
internal ProfileEntity ProfileEntity { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,8 +7,21 @@ using Stylet;
|
|||||||
|
|
||||||
namespace Artemis.Core.Models.Profile
|
namespace Artemis.Core.Models.Profile
|
||||||
{
|
{
|
||||||
public abstract class ProfileElement : PropertyChangedBase
|
public abstract class ProfileElement : PropertyChangedBase, IDisposable
|
||||||
{
|
{
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
private bool _enabled;
|
private bool _enabled;
|
||||||
private Guid _entityId;
|
private Guid _entityId;
|
||||||
private string _name;
|
private string _name;
|
||||||
|
|||||||
@ -131,14 +131,14 @@ namespace Artemis.Core.Plugins.Abstract
|
|||||||
|
|
||||||
internal void ChangeActiveProfile(Profile profile, ArtemisSurface surface)
|
internal void ChangeActiveProfile(Profile profile, ArtemisSurface surface)
|
||||||
{
|
{
|
||||||
if (profile != null && profile.PluginInfo != PluginInfo)
|
if (profile != null && profile.Module != this)
|
||||||
throw new ArtemisCoreException($"Cannot activate a profile of plugin {profile.PluginInfo} on a module of plugin {PluginInfo}.");
|
throw new ArtemisCoreException($"Cannot activate a profile of module {profile.Module} on a module of plugin {PluginInfo}.");
|
||||||
lock (this)
|
lock (this)
|
||||||
{
|
{
|
||||||
if (profile == ActiveProfile)
|
if (profile == ActiveProfile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ActiveProfile?.Deactivate();
|
ActiveProfile?.Dispose();
|
||||||
|
|
||||||
ActiveProfile = profile;
|
ActiveProfile = profile;
|
||||||
ActiveProfile?.Activate(surface);
|
ActiveProfile?.Activate(surface);
|
||||||
|
|||||||
@ -80,8 +80,9 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
DisableLayerBrush();
|
DisableLayerBrush();
|
||||||
|
BaseProperties.Dispose();
|
||||||
|
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
|
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -106,6 +106,7 @@ namespace Artemis.Core.Plugins.LayerEffect.Abstract
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
DisableLayerEffect();
|
DisableLayerEffect();
|
||||||
|
BaseProperties.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -90,7 +90,7 @@ namespace Artemis.Core.Services
|
|||||||
else
|
else
|
||||||
_logger.Information("Initialized without an active surface entity");
|
_logger.Information("Initialized without an active surface entity");
|
||||||
|
|
||||||
_profileService.ActivateDefaultProfiles();
|
_profileService.ActivateLastActiveProfiles();
|
||||||
|
|
||||||
OnInitialized();
|
OnInitialized();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,19 +7,50 @@ namespace Artemis.Core.Services.Storage.Interfaces
|
|||||||
{
|
{
|
||||||
public interface IProfileService : IArtemisService
|
public interface IProfileService : IArtemisService
|
||||||
{
|
{
|
||||||
void ActivateDefaultProfiles();
|
/// <summary>
|
||||||
Profile CreateProfile(ProfileModule module, string name);
|
/// Activates the last profile for each module
|
||||||
List<Profile> GetProfiles(ProfileModule module);
|
/// </summary>
|
||||||
Profile GetActiveProfile(ProfileModule module);
|
void ActivateLastActiveProfiles();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new profile for the given module and returns a descriptor pointing to it
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="module">The profile module to create the profile for</param>
|
||||||
|
/// <param name="name">The name of the new profile</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
ProfileDescriptor CreateProfile(ProfileModule module, string name);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a descriptor for each profile stored for the given <see cref="ProfileModule" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="module">The module to return profile descriptors for</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<ProfileDescriptor> GetProfiles(ProfileModule module);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the profile to persistent storage
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="profile"></param>
|
||||||
|
/// <param name="includeChildren"></param>
|
||||||
void UpdateProfile(Profile profile, bool includeChildren);
|
void UpdateProfile(Profile profile, bool includeChildren);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disposes and permanently deletes the provided profile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="profile">The profile to delete</param>
|
||||||
void DeleteProfile(Profile profile);
|
void DeleteProfile(Profile profile);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Activates the profile for the given <see cref="ProfileModule" /> with the currently active surface
|
/// Activates the profile described in the given <see cref="ProfileDescriptor" /> with the currently active surface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="module">The module to activate the profile for</param>
|
/// <param name="profileDescriptor">The descriptor describing the profile to activate</param>
|
||||||
/// <param name="profile">The profile to activate</param>
|
Profile ActivateProfile(ProfileDescriptor profileDescriptor);
|
||||||
void ActivateProfile(ProfileModule module, Profile profile);
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clears the active profile on the given <see cref="ProfileModule" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="module">The profile module to deactivate the active profile on</param>
|
||||||
|
void ClearActiveProfile(ProfileModule module);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to restore the profile to the state it had before the last <see cref="UpdateProfile" /> call.
|
/// Attempts to restore the profile to the state it had before the last <see cref="UpdateProfile" /> call.
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Artemis.Core.Events;
|
using Artemis.Core.Events;
|
||||||
using Artemis.Core.Models.Profile;
|
using Artemis.Core.Models.Profile;
|
||||||
@ -41,70 +42,58 @@ namespace Artemis.Core.Services.Storage
|
|||||||
|
|
||||||
public JsonSerializerSettings MementoSettings { get; set; } = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All};
|
public JsonSerializerSettings MementoSettings { get; set; } = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All};
|
||||||
|
|
||||||
public void ActivateDefaultProfiles()
|
public void ActivateLastActiveProfiles()
|
||||||
{
|
{
|
||||||
foreach (var profileModule in _pluginService.GetPluginsOfType<ProfileModule>())
|
foreach (var profileModule in _pluginService.GetPluginsOfType<ProfileModule>())
|
||||||
{
|
{
|
||||||
var activeProfile = GetActiveProfile(profileModule);
|
var activeProfile = GetLastActiveProfile(profileModule);
|
||||||
ActivateProfile(profileModule, activeProfile);
|
ActivateProfile(activeProfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Profile> GetProfiles(ProfileModule module)
|
public List<ProfileDescriptor> GetProfiles(ProfileModule module)
|
||||||
{
|
{
|
||||||
var profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
var profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||||
var profiles = new List<Profile>();
|
return profileEntities.Select(e => new ProfileDescriptor(module, e)).ToList();
|
||||||
foreach (var profileEntity in profileEntities)
|
|
||||||
{
|
|
||||||
// If the profile entity matches the module's currently active profile, use that instead
|
|
||||||
if (module.ActiveProfile != null && module.ActiveProfile.EntityId == profileEntity.Id)
|
|
||||||
profiles.Add(module.ActiveProfile);
|
|
||||||
else
|
|
||||||
profiles.Add(new Profile(module.PluginInfo, profileEntity));
|
|
||||||
}
|
|
||||||
|
|
||||||
return profiles;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profile GetActiveProfile(ProfileModule module)
|
public ProfileDescriptor GetLastActiveProfile(ProfileModule module)
|
||||||
{
|
{
|
||||||
if (module.ActiveProfile != null)
|
|
||||||
return module.ActiveProfile;
|
|
||||||
|
|
||||||
var moduleProfiles = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
var moduleProfiles = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||||
var profileEntity = moduleProfiles.FirstOrDefault(p => p.IsActive) ?? moduleProfiles.FirstOrDefault();
|
var profileEntity = moduleProfiles.FirstOrDefault(p => p.IsActive) ?? moduleProfiles.FirstOrDefault();
|
||||||
if (profileEntity == null)
|
return profileEntity == null ? null : new ProfileDescriptor(module, profileEntity);
|
||||||
return null;
|
|
||||||
|
|
||||||
return new Profile(module.PluginInfo, profileEntity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profile CreateProfile(ProfileModule module, string name)
|
public ProfileDescriptor CreateProfile(ProfileModule module, string name)
|
||||||
{
|
{
|
||||||
var profile = new Profile(module.PluginInfo, name);
|
var profileEntity = new ProfileEntity {Id = Guid.NewGuid(), Name = name, PluginGuid = module.PluginInfo.Guid};
|
||||||
_profileRepository.Add(profile.ProfileEntity);
|
return new ProfileDescriptor(module, profileEntity);
|
||||||
|
}
|
||||||
|
|
||||||
if (_surfaceService.ActiveSurface != null)
|
public Profile ActivateProfile(ProfileDescriptor profileDescriptor)
|
||||||
profile.PopulateLeds(_surfaceService.ActiveSurface);
|
{
|
||||||
|
if (profileDescriptor.ProfileModule.ActiveProfile.EntityId == profileDescriptor.Id)
|
||||||
|
return profileDescriptor.ProfileModule.ActiveProfile;
|
||||||
|
|
||||||
|
var profile = new Profile(profileDescriptor.ProfileModule, profileDescriptor.ProfileEntity);
|
||||||
|
InitializeLayerProperties(profile);
|
||||||
|
InstantiateLayers(profile);
|
||||||
|
InstantiateFolders(profile);
|
||||||
|
|
||||||
|
profileDescriptor.ProfileModule.ChangeActiveProfile(profile, _surfaceService.ActiveSurface);
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearActiveProfile(ProfileModule module)
|
||||||
public void ActivateProfile(ProfileModule module, Profile profile)
|
|
||||||
{
|
{
|
||||||
module.ChangeActiveProfile(profile, _surfaceService.ActiveSurface);
|
module.ChangeActiveProfile(null, _surfaceService.ActiveSurface);
|
||||||
if (profile != null)
|
|
||||||
{
|
|
||||||
InitializeLayerProperties(profile);
|
|
||||||
InstantiateLayers(profile);
|
|
||||||
InstantiateFolders(profile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteProfile(Profile profile)
|
public void DeleteProfile(Profile profile)
|
||||||
{
|
{
|
||||||
_logger.Debug("Removing profile " + profile);
|
_logger.Debug("Removing profile " + profile);
|
||||||
|
|
||||||
|
|
||||||
_profileRepository.Remove(profile.ProfileEntity);
|
_profileRepository.Remove(profile.ProfileEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -284,7 +284,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
|||||||
var hideRenderRelatedProperties = SelectedLayer?.LayerBrush != null && !SelectedLayer.LayerBrush.SupportsTransformation;
|
var hideRenderRelatedProperties = SelectedLayer?.LayerBrush != null && !SelectedLayer.LayerBrush.SupportsTransformation;
|
||||||
|
|
||||||
SelectedLayer.General.ShapeType.IsHidden = hideRenderRelatedProperties;
|
SelectedLayer.General.ShapeType.IsHidden = hideRenderRelatedProperties;
|
||||||
SelectedLayer.General.FillType.IsHidden = hideRenderRelatedProperties;
|
SelectedLayer.General.ResizeMode.IsHidden = hideRenderRelatedProperties;
|
||||||
SelectedLayer.General.BlendMode.IsHidden = hideRenderRelatedProperties;
|
SelectedLayer.General.BlendMode.IsHidden = hideRenderRelatedProperties;
|
||||||
SelectedLayer.Transform.IsHidden = hideRenderRelatedProperties;
|
SelectedLayer.Transform.IsHidden = hideRenderRelatedProperties;
|
||||||
|
|
||||||
|
|||||||
@ -48,7 +48,7 @@ namespace Artemis.Plugins.LayerBrushes.Color
|
|||||||
|
|
||||||
public override void Render(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
|
public override void Render(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
|
||||||
{
|
{
|
||||||
if (Layer.General.FillType.CurrentValue == LayerFillType.Clip)
|
if (Layer.General.ResizeMode.CurrentValue == LayerResizeMode.Clip)
|
||||||
{
|
{
|
||||||
var layerBounds = new SKRect(0, 0, Layer.Bounds.Width, Layer.Bounds.Height);
|
var layerBounds = new SKRect(0, 0, Layer.Bounds.Width, Layer.Bounds.Height);
|
||||||
if (layerBounds != _shaderBounds)
|
if (layerBounds != _shaderBounds)
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using Artemis.Core.Events;
|
||||||
using Artemis.Core.Models.Profile;
|
using Artemis.Core.Models.Profile;
|
||||||
using Artemis.Core.Models.Profile.Colors;
|
using Artemis.Core.Models.Profile.Colors;
|
||||||
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
|
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
|
||||||
@ -24,9 +25,13 @@ namespace Artemis.Plugins.LayerBrushes.Color
|
|||||||
[PropertyDescription(DisableKeyframes = true, Description = "How many times to repeat the colors in the selected gradient", MinInputValue = 0, MaxInputValue = 10)]
|
[PropertyDescription(DisableKeyframes = true, Description = "How many times to repeat the colors in the selected gradient", MinInputValue = 0, MaxInputValue = 10)]
|
||||||
public IntLayerProperty GradientRepeat { get; set; }
|
public IntLayerProperty GradientRepeat { get; set; }
|
||||||
|
|
||||||
|
#region Linear greadient properties
|
||||||
|
|
||||||
[PropertyDescription(Name = "Rotation", Description = "Change the rotation of the linear gradient without affecting the rotation of the shape", InputAffix = "°")]
|
[PropertyDescription(Name = "Rotation", Description = "Change the rotation of the linear gradient without affecting the rotation of the shape", InputAffix = "°")]
|
||||||
public FloatLayerProperty LinearGradientRotation { get; set; }
|
public FloatLayerProperty LinearGradientRotation { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
protected override void PopulateDefaults()
|
protected override void PopulateDefaults()
|
||||||
{
|
{
|
||||||
GradientType.DefaultValue = LayerBrushes.Color.GradientType.Solid;
|
GradientType.DefaultValue = LayerBrushes.Color.GradientType.Solid;
|
||||||
@ -35,26 +40,53 @@ namespace Artemis.Plugins.LayerBrushes.Color
|
|||||||
GradientRepeat.DefaultValue = 0;
|
GradientRepeat.DefaultValue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
GradientType.BaseValueChanged += (sender, args) => UpdateVisibility();
|
GradientType.BaseValueChanged += OnBaseValueChanged;
|
||||||
if (ProfileElement is Layer layer)
|
if (ProfileElement is Layer layer)
|
||||||
layer.General.FillType.BaseValueChanged += (sender, args) => UpdateVisibility();
|
layer.General.ResizeMode.BaseValueChanged += OnBaseValueChanged;
|
||||||
|
|
||||||
UpdateVisibility();
|
UpdateVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void DisableProperties()
|
||||||
|
{
|
||||||
|
GradientType.BaseValueChanged -= OnBaseValueChanged;
|
||||||
|
if (ProfileElement is Layer layer)
|
||||||
|
layer.General.ResizeMode.BaseValueChanged -= OnBaseValueChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBaseValueChanged(object sender, LayerPropertyEventArgs e)
|
||||||
|
{
|
||||||
|
UpdateVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateVisibility()
|
private void UpdateVisibility()
|
||||||
{
|
{
|
||||||
|
var normalRender = false;
|
||||||
|
if (ProfileElement is Layer layer)
|
||||||
|
normalRender = layer.General.ResizeMode.CurrentValue == LayerResizeMode.Normal;
|
||||||
|
|
||||||
Color.IsHidden = GradientType.BaseValue != LayerBrushes.Color.GradientType.Solid;
|
Color.IsHidden = GradientType.BaseValue != LayerBrushes.Color.GradientType.Solid;
|
||||||
Gradient.IsHidden = GradientType.BaseValue == LayerBrushes.Color.GradientType.Solid;
|
Gradient.IsHidden = GradientType.BaseValue == LayerBrushes.Color.GradientType.Solid;
|
||||||
GradientRepeat.IsHidden = GradientType.BaseValue == LayerBrushes.Color.GradientType.Solid;
|
GradientRepeat.IsHidden = GradientType.BaseValue == LayerBrushes.Color.GradientType.Solid;
|
||||||
|
|
||||||
if (ProfileElement is Layer layer)
|
RadialGradientCenterOffset.IsHidden = GradientType.BaseValue != LayerBrushes.Color.GradientType.RadialGradient;
|
||||||
GradientTileMode.IsHidden = layer.General.FillType.CurrentValue != LayerFillType.Clip;
|
RadialGradientResizeMode.IsHidden = GradientType.BaseValue != LayerBrushes.Color.GradientType.RadialGradient;
|
||||||
else
|
|
||||||
GradientTileMode.IsHidden = true;
|
GradientTileMode.IsHidden = normalRender;
|
||||||
|
RadialGradientResizeMode.IsHidden = !normalRender || GradientType.BaseValue != LayerBrushes.Color.GradientType.RadialGradient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Radial gradient properties
|
||||||
|
|
||||||
|
[PropertyDescription(Name = "Center offset", Description = "Change the position of the gradient by offsetting it from the center of the layer", InputAffix = "%")]
|
||||||
|
public SKPointLayerProperty RadialGradientCenterOffset { get; set; }
|
||||||
|
|
||||||
|
[PropertyDescription(Name = "Resize mode", Description = "How to make the gradient adjust to scale changes")]
|
||||||
|
public EnumLayerProperty<RadialGradientResizeMode> RadialGradientResizeMode { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum GradientType
|
public enum GradientType
|
||||||
@ -71,4 +103,13 @@ namespace Artemis.Plugins.LayerBrushes.Color
|
|||||||
[Description("Sweep Gradient")]
|
[Description("Sweep Gradient")]
|
||||||
SweepGradient
|
SweepGradient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum RadialGradientResizeMode
|
||||||
|
{
|
||||||
|
[Description("Stretch or shrink")]
|
||||||
|
Stretch,
|
||||||
|
|
||||||
|
[Description("Maintain a circle")]
|
||||||
|
MaintainCircle
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@ namespace Artemis.Plugins.LayerBrushes.ColorRgbNet
|
|||||||
TestProperty.DefaultValue = "I was empty before!";
|
TestProperty.DefaultValue = "I was empty before!";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
|||||||
AnimationSpeed.DefaultValue = 25f;
|
AnimationSpeed.DefaultValue = 25f;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
ColorType.BaseValueChanged += (sender, args) => UpdateVisibility();
|
ColorType.BaseValueChanged += (sender, args) => UpdateVisibility();
|
||||||
UpdateVisibility();
|
UpdateVisibility();
|
||||||
|
|||||||
@ -14,7 +14,7 @@ namespace Artemis.Plugins.LayerEffects.Filter
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ namespace Artemis.Plugins.LayerEffects.Filter
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
ColorMatrix.IsHidden = true;
|
ColorMatrix.IsHidden = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ namespace Artemis.Plugins.LayerEffects.Filter
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ namespace Artemis.Plugins.LayerEffects.Filter
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ namespace Artemis.Plugins.LayerEffects.Filter
|
|||||||
GlowColor.DefaultValue = new SKColor(255, 255, 255);
|
GlowColor.DefaultValue = new SKColor(255, 255, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ namespace Artemis.Plugins.LayerEffects.Filter
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ namespace Artemis.Plugins.LayerEffects.Filter
|
|||||||
Opacity.DefaultValue = 100f;
|
Opacity.DefaultValue = 100f;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertiesInitialized()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user