Profiles - Dispose WIP

This commit is contained in:
SpoinkyNL committed 2020-08-09 22:34:45 +02:00
1 parent c2034c5de7
commit ce353fd84f
26 files changed
+246 -105

No files matched your search

+13 -1
View File
@@ -172,7 +172,7 @@ namespace Artemis.Core.Models.Profile
profileElement.Render(deltaTime, folderCanvas, _folderBitmap.Info);
folderCanvas.Restore();
}
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
baseLayerEffect.PostProcess(canvas, canvasInfo, folderPath, folderPaint);
canvas.DrawBitmap(_folderBitmap, targetLocation, folderPaint);
@@ -229,6 +229,18 @@ namespace Artemis.Core.Models.Profile
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()
{
+23 -9
View File
@@ -141,6 +141,20 @@ namespace Artemis.Core.Models.Profile
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
internal override void ApplyToEntity()
@@ -328,9 +342,9 @@ namespace Artemis.Core.Models.Profile
if (!LayerBrush.SupportsTransformation)
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);
else if (General.FillType.CurrentValue == LayerFillType.Clip)
else if (General.ResizeMode.CurrentValue == LayerResizeMode.Clip)
ClipRender(layerCanvas, _layerBitmap.Info, layerPaint, layerPath);
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
@@ -340,7 +354,7 @@ namespace Artemis.Core.Models.Profile
if (Parent is Folder parentFolder)
targetLocation = Path.Bounds.Location - parentFolder.Path.Bounds.Location;
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 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.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));
}
else
@@ -497,7 +511,7 @@ namespace Artemis.Core.Models.Profile
var reversedXScale = 1f / (sizeProperty.Width / 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.MakeScale(reversedXScale, reversedYScale, anchorPosition.X, anchorPosition.Y));
@@ -530,7 +544,7 @@ namespace Artemis.Core.Models.Profile
var reversedXScale = 1f / (sizeProperty.Width / 100f);
var reversedYScale = 1f / (sizeProperty.Height / 100f);
if (General.FillType == LayerFillType.Stretch)
if (General.ResizeMode == LayerResizeMode.Normal)
{
canvas.Translate(x * -1, y * -1);
canvas.Scale(reversedXScale, reversedYScale, anchorPosition.X, anchorPosition.Y);
@@ -666,9 +680,9 @@ namespace Artemis.Core.Models.Profile
Rectangle
}
public enum LayerFillType
public enum LayerResizeMode
{
Stretch,
Normal,
Clip
}
}
@@ -9,8 +9,8 @@ namespace Artemis.Core.Models.Profile
[PropertyDescription(Name = "Shape type", Description = "The type of shape to draw in this layer")]
public EnumLayerProperty<LayerShapeType> ShapeType { get; set; }
[PropertyDescription(Name = "Fill type", Description = "How to make the shape adjust to scale changes")]
public EnumLayerProperty<LayerFillType> FillType { get; set; }
[PropertyDescription(Name = "Resize mode", Description = "How to make the shape adjust to scale changes")]
public EnumLayerProperty<LayerResizeMode> ResizeMode { get; set; }
[PropertyDescription(Name = "Blend mode", Description = "How to blend this layer into the resulting image")]
public EnumLayerProperty<SKBlendMode> BlendMode { get; set; }
@@ -21,11 +21,11 @@ namespace Artemis.Core.Models.Profile
protected override void PopulateDefaults()
{
ShapeType.DefaultValue = LayerShapeType.Rectangle;
FillType.DefaultValue = LayerFillType.Stretch;
ResizeMode.DefaultValue = LayerResizeMode.Normal;
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
{
public abstract class LayerPropertyGroup
public abstract class LayerPropertyGroup : IDisposable
{
private readonly List<BaseLayerProperty> _layerProperties;
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>
/// A list of all layer properties in this group
/// </summary>
@@ -112,17 +107,26 @@ namespace Artemis.Core.Models.Profile
return _allLayerProperties;
}
public void Dispose()
{
DisableProperties();
}
/// <summary>
/// Called before properties are fully initialized to allow you to populate
/// <see cref="LayerProperty{T}.DefaultValue" /> on the properties you want
/// Called before property group is activated to allow you to populate <see cref="LayerProperty{T}.DefaultValue" /> on
/// the properties you want
/// </summary>
protected abstract void PopulateDefaults();
/// <summary>
/// Called when all layer properties in this property group have been initialized, you may access all properties on the
/// group here
/// Called when the property group is deactivated
/// </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()
{
@@ -195,7 +199,7 @@ namespace Artemis.Core.Models.Profile
foreach (var layerProperty in _layerProperties.Where(p => !p.IsLoadedFromStorage))
layerProperty.ApplyDefaultValue();
OnPropertiesInitialized();
EnableProperties();
PropertiesInitialized = true;
OnPropertyGroupInitialized();
}
@@ -27,7 +27,7 @@ namespace Artemis.Core.Models.Profile
Opacity.DefaultValue = 100;
}
protected override void OnPropertiesInitialized()
protected override void EnableProperties()
{
}
}
+19 -8
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Exceptions;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
@@ -13,12 +14,12 @@ namespace Artemis.Core.Models.Profile
{
private bool _isActivated;
internal Profile(PluginInfo pluginInfo, string name)
internal Profile(ProfileModule module, string name)
{
ProfileEntity = new ProfileEntity();
EntityId = Guid.NewGuid();
PluginInfo = pluginInfo;
Module = module;
Name = name;
UndoStack = new Stack<string>();
RedoStack = new Stack<string>();
@@ -27,19 +28,19 @@ namespace Artemis.Core.Models.Profile
ApplyToEntity();
}
internal Profile(PluginInfo pluginInfo, ProfileEntity profileEntity)
internal Profile(ProfileModule module, ProfileEntity profileEntity)
{
ProfileEntity = profileEntity;
EntityId = profileEntity.Id;
PluginInfo = pluginInfo;
Module = module;
UndoStack = new Stack<string>();
RedoStack = new Stack<string>();
ApplyToProfile();
}
public PluginInfo PluginInfo { get; }
public ProfileModule Module { get; }
public bool IsActivated
{
@@ -104,13 +105,23 @@ namespace Artemis.Core.Models.Profile
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()
{
ProfileEntity.Id = EntityId;
ProfileEntity.PluginGuid = PluginInfo.Guid;
ProfileEntity.PluginGuid = Module.PluginInfo.Guid;
ProfileEntity.Name = Name;
ProfileEntity.IsActive = IsActivated;
@@ -144,7 +155,7 @@ namespace Artemis.Core.Models.Profile
if (!IsActivated)
return;
foreach (var folder in GetAllFolders())
foreach (var folder in GetAllFolders())
folder.Deactivate();
foreach (var layer in GetAllLayers())
layer.Deactivate();
@@ -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
{
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 Guid _entityId;
private string _name;