mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +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);
|
||||
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()
|
||||
{
|
||||
|
||||
@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
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
|
||||
{
|
||||
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;
|
||||
|
||||
@ -131,14 +131,14 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
|
||||
internal void ChangeActiveProfile(Profile profile, ArtemisSurface surface)
|
||||
{
|
||||
if (profile != null && profile.PluginInfo != PluginInfo)
|
||||
throw new ArtemisCoreException($"Cannot activate a profile of plugin {profile.PluginInfo} on a module of plugin {PluginInfo}.");
|
||||
if (profile != null && profile.Module != this)
|
||||
throw new ArtemisCoreException($"Cannot activate a profile of module {profile.Module} on a module of plugin {PluginInfo}.");
|
||||
lock (this)
|
||||
{
|
||||
if (profile == ActiveProfile)
|
||||
return;
|
||||
|
||||
ActiveProfile?.Deactivate();
|
||||
ActiveProfile?.Dispose();
|
||||
|
||||
ActiveProfile = profile;
|
||||
ActiveProfile?.Activate(surface);
|
||||
|
||||
@ -80,8 +80,9 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
|
||||
public void Dispose()
|
||||
{
|
||||
DisableLayerBrush();
|
||||
BaseProperties.Dispose();
|
||||
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
|
||||
@ -106,6 +106,7 @@ namespace Artemis.Core.Plugins.LayerEffect.Abstract
|
||||
public void Dispose()
|
||||
{
|
||||
DisableLayerEffect();
|
||||
BaseProperties.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -90,7 +90,7 @@ namespace Artemis.Core.Services
|
||||
else
|
||||
_logger.Information("Initialized without an active surface entity");
|
||||
|
||||
_profileService.ActivateDefaultProfiles();
|
||||
_profileService.ActivateLastActiveProfiles();
|
||||
|
||||
OnInitialized();
|
||||
}
|
||||
|
||||
@ -7,19 +7,50 @@ namespace Artemis.Core.Services.Storage.Interfaces
|
||||
{
|
||||
public interface IProfileService : IArtemisService
|
||||
{
|
||||
void ActivateDefaultProfiles();
|
||||
Profile CreateProfile(ProfileModule module, string name);
|
||||
List<Profile> GetProfiles(ProfileModule module);
|
||||
Profile GetActiveProfile(ProfileModule module);
|
||||
/// <summary>
|
||||
/// Activates the last profile for each module
|
||||
/// </summary>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Disposes and permanently deletes the provided profile
|
||||
/// </summary>
|
||||
/// <param name="profile">The profile to delete</param>
|
||||
void DeleteProfile(Profile profile);
|
||||
|
||||
/// <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>
|
||||
/// <param name="module">The module to activate the profile for</param>
|
||||
/// <param name="profile">The profile to activate</param>
|
||||
void ActivateProfile(ProfileModule module, Profile profile);
|
||||
/// <param name="profileDescriptor">The descriptor describing the profile to activate</param>
|
||||
Profile ActivateProfile(ProfileDescriptor profileDescriptor);
|
||||
|
||||
/// <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>
|
||||
/// 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 Artemis.Core.Events;
|
||||
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 void ActivateDefaultProfiles()
|
||||
public void ActivateLastActiveProfiles()
|
||||
{
|
||||
foreach (var profileModule in _pluginService.GetPluginsOfType<ProfileModule>())
|
||||
{
|
||||
var activeProfile = GetActiveProfile(profileModule);
|
||||
ActivateProfile(profileModule, activeProfile);
|
||||
var activeProfile = GetLastActiveProfile(profileModule);
|
||||
ActivateProfile(activeProfile);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Profile> GetProfiles(ProfileModule module)
|
||||
public List<ProfileDescriptor> GetProfiles(ProfileModule module)
|
||||
{
|
||||
var profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||
var profiles = new List<Profile>();
|
||||
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;
|
||||
return profileEntities.Select(e => new ProfileDescriptor(module, e)).ToList();
|
||||
}
|
||||
|
||||
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 profileEntity = moduleProfiles.FirstOrDefault(p => p.IsActive) ?? moduleProfiles.FirstOrDefault();
|
||||
if (profileEntity == null)
|
||||
return null;
|
||||
|
||||
return new Profile(module.PluginInfo, profileEntity);
|
||||
return profileEntity == null ? null : new ProfileDescriptor(module, profileEntity);
|
||||
}
|
||||
|
||||
public Profile CreateProfile(ProfileModule module, string name)
|
||||
public ProfileDescriptor CreateProfile(ProfileModule module, string name)
|
||||
{
|
||||
var profile = new Profile(module.PluginInfo, name);
|
||||
_profileRepository.Add(profile.ProfileEntity);
|
||||
var profileEntity = new ProfileEntity {Id = Guid.NewGuid(), Name = name, PluginGuid = module.PluginInfo.Guid};
|
||||
return new ProfileDescriptor(module, profileEntity);
|
||||
}
|
||||
|
||||
if (_surfaceService.ActiveSurface != null)
|
||||
profile.PopulateLeds(_surfaceService.ActiveSurface);
|
||||
public Profile ActivateProfile(ProfileDescriptor profileDescriptor)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
public void ActivateProfile(ProfileModule module, Profile profile)
|
||||
public void ClearActiveProfile(ProfileModule module)
|
||||
{
|
||||
module.ChangeActiveProfile(profile, _surfaceService.ActiveSurface);
|
||||
if (profile != null)
|
||||
{
|
||||
InitializeLayerProperties(profile);
|
||||
InstantiateLayers(profile);
|
||||
InstantiateFolders(profile);
|
||||
}
|
||||
module.ChangeActiveProfile(null, _surfaceService.ActiveSurface);
|
||||
}
|
||||
|
||||
public void DeleteProfile(Profile profile)
|
||||
{
|
||||
_logger.Debug("Removing profile " + profile);
|
||||
|
||||
|
||||
_profileRepository.Remove(profile.ProfileEntity);
|
||||
}
|
||||
|
||||
|
||||
@ -284,7 +284,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
var hideRenderRelatedProperties = SelectedLayer?.LayerBrush != null && !SelectedLayer.LayerBrush.SupportsTransformation;
|
||||
|
||||
SelectedLayer.General.ShapeType.IsHidden = hideRenderRelatedProperties;
|
||||
SelectedLayer.General.FillType.IsHidden = hideRenderRelatedProperties;
|
||||
SelectedLayer.General.ResizeMode.IsHidden = hideRenderRelatedProperties;
|
||||
SelectedLayer.General.BlendMode.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)
|
||||
{
|
||||
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);
|
||||
if (layerBounds != _shaderBounds)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.Colors;
|
||||
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)]
|
||||
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 = "°")]
|
||||
public FloatLayerProperty LinearGradientRotation { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
protected override void PopulateDefaults()
|
||||
{
|
||||
GradientType.DefaultValue = LayerBrushes.Color.GradientType.Solid;
|
||||
@ -35,26 +40,53 @@ namespace Artemis.Plugins.LayerBrushes.Color
|
||||
GradientRepeat.DefaultValue = 0;
|
||||
}
|
||||
|
||||
protected override void OnPropertiesInitialized()
|
||||
protected override void EnableProperties()
|
||||
{
|
||||
GradientType.BaseValueChanged += (sender, args) => UpdateVisibility();
|
||||
GradientType.BaseValueChanged += OnBaseValueChanged;
|
||||
if (ProfileElement is Layer layer)
|
||||
layer.General.FillType.BaseValueChanged += (sender, args) => UpdateVisibility();
|
||||
layer.General.ResizeMode.BaseValueChanged += OnBaseValueChanged;
|
||||
|
||||
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()
|
||||
{
|
||||
var normalRender = false;
|
||||
if (ProfileElement is Layer layer)
|
||||
normalRender = layer.General.ResizeMode.CurrentValue == LayerResizeMode.Normal;
|
||||
|
||||
Color.IsHidden = GradientType.BaseValue != LayerBrushes.Color.GradientType.Solid;
|
||||
Gradient.IsHidden = GradientType.BaseValue == LayerBrushes.Color.GradientType.Solid;
|
||||
GradientRepeat.IsHidden = GradientType.BaseValue == LayerBrushes.Color.GradientType.Solid;
|
||||
|
||||
if (ProfileElement is Layer layer)
|
||||
GradientTileMode.IsHidden = layer.General.FillType.CurrentValue != LayerFillType.Clip;
|
||||
else
|
||||
GradientTileMode.IsHidden = true;
|
||||
RadialGradientCenterOffset.IsHidden = GradientType.BaseValue != LayerBrushes.Color.GradientType.RadialGradient;
|
||||
RadialGradientResizeMode.IsHidden = GradientType.BaseValue != LayerBrushes.Color.GradientType.RadialGradient;
|
||||
|
||||
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
|
||||
@ -71,4 +103,13 @@ namespace Artemis.Plugins.LayerBrushes.Color
|
||||
[Description("Sweep Gradient")]
|
||||
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!";
|
||||
}
|
||||
|
||||
protected override void OnPropertiesInitialized()
|
||||
protected override void EnableProperties()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
AnimationSpeed.DefaultValue = 25f;
|
||||
}
|
||||
|
||||
protected override void OnPropertiesInitialized()
|
||||
protected override void EnableProperties()
|
||||
{
|
||||
ColorType.BaseValueChanged += (sender, args) => 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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
protected override void OnPropertiesInitialized()
|
||||
protected override void EnableProperties()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user