diff --git a/src/Artemis.Core/Models/Profile/Folder.cs b/src/Artemis.Core/Models/Profile/Folder.cs index 6513c3d67..53e25ccf8 100644 --- a/src/Artemis.Core/Models/Profile/Folder.cs +++ b/src/Artemis.Core/Models/Profile/Folder.cs @@ -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() { diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index 6f93f36c7..0aa341779 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -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 } } \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/LayerGeneralProperties.cs b/src/Artemis.Core/Models/Profile/LayerGeneralProperties.cs index e0a2b46d4..8b1a11b2f 100644 --- a/src/Artemis.Core/Models/Profile/LayerGeneralProperties.cs +++ b/src/Artemis.Core/Models/Profile/LayerGeneralProperties.cs @@ -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 ShapeType { get; set; } - [PropertyDescription(Name = "Fill type", Description = "How to make the shape adjust to scale changes")] - public EnumLayerProperty FillType { get; set; } + [PropertyDescription(Name = "Resize mode", Description = "How to make the shape adjust to scale changes")] + public EnumLayerProperty ResizeMode { get; set; } [PropertyDescription(Name = "Blend mode", Description = "How to blend this layer into the resulting image")] public EnumLayerProperty 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() { } } diff --git a/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs b/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs index 04a1d56b6..009e46301 100644 --- a/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs +++ b/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs @@ -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 _layerProperties; private readonly List _layerPropertyGroups; @@ -78,11 +78,6 @@ namespace Artemis.Core.Models.Profile } } - /// - /// Gets or sets whether the group is expanded in the UI - /// - public bool IsExpanded { get; set; } - /// /// A list of all layer properties in this group /// @@ -112,17 +107,26 @@ namespace Artemis.Core.Models.Profile return _allLayerProperties; } + public void Dispose() + { + DisableProperties(); + } + /// - /// Called before properties are fully initialized to allow you to populate - /// on the properties you want + /// Called before property group is activated to allow you to populate on + /// the properties you want /// protected abstract void PopulateDefaults(); /// - /// 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 /// - protected abstract void OnPropertiesInitialized(); + protected abstract void EnableProperties(); + + /// + /// Called when the property group is deactivated (either the profile unloaded or the related brush/effect was removed) + /// + 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(); } diff --git a/src/Artemis.Core/Models/Profile/LayerTransformProperties.cs b/src/Artemis.Core/Models/Profile/LayerTransformProperties.cs index 81b35a838..141d8cfa0 100644 --- a/src/Artemis.Core/Models/Profile/LayerTransformProperties.cs +++ b/src/Artemis.Core/Models/Profile/LayerTransformProperties.cs @@ -27,7 +27,7 @@ namespace Artemis.Core.Models.Profile Opacity.DefaultValue = 100; } - protected override void OnPropertiesInitialized() + protected override void EnableProperties() { } } diff --git a/src/Artemis.Core/Models/Profile/Profile.cs b/src/Artemis.Core/Models/Profile/Profile.cs index df31ed9e2..2394fd43c 100644 --- a/src/Artemis.Core/Models/Profile/Profile.cs +++ b/src/Artemis.Core/Models/Profile/Profile.cs @@ -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(); RedoStack = new Stack(); @@ -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(); RedoStack = new Stack(); 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(); diff --git a/src/Artemis.Core/Models/Profile/ProfileDescriptor.cs b/src/Artemis.Core/Models/Profile/ProfileDescriptor.cs new file mode 100644 index 000000000..5dead225a --- /dev/null +++ b/src/Artemis.Core/Models/Profile/ProfileDescriptor.cs @@ -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; } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/ProfileElement.cs b/src/Artemis.Core/Models/Profile/ProfileElement.cs index 79588e4ae..a54fa5dc4 100644 --- a/src/Artemis.Core/Models/Profile/ProfileElement.cs +++ b/src/Artemis.Core/Models/Profile/ProfileElement.cs @@ -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; diff --git a/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs b/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs index 76dd755fb..f2a2d952a 100644 --- a/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs +++ b/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs @@ -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); diff --git a/src/Artemis.Core/Plugins/LayerBrush/Abstract/BaseLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/Abstract/BaseLayerBrush.cs index fbfa4ba5a..38bbd2c13 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/Abstract/BaseLayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/Abstract/BaseLayerBrush.cs @@ -80,8 +80,9 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract public void Dispose() { DisableLayerBrush(); + BaseProperties.Dispose(); + Dispose(true); - GC.SuppressFinalize(this); } diff --git a/src/Artemis.Core/Plugins/LayerEffect/Abstract/BaseLayerEffect.cs b/src/Artemis.Core/Plugins/LayerEffect/Abstract/BaseLayerEffect.cs index 212eb9368..6913defa4 100644 --- a/src/Artemis.Core/Plugins/LayerEffect/Abstract/BaseLayerEffect.cs +++ b/src/Artemis.Core/Plugins/LayerEffect/Abstract/BaseLayerEffect.cs @@ -106,6 +106,7 @@ namespace Artemis.Core.Plugins.LayerEffect.Abstract public void Dispose() { DisableLayerEffect(); + BaseProperties.Dispose(); } /// diff --git a/src/Artemis.Core/Services/CoreService.cs b/src/Artemis.Core/Services/CoreService.cs index 3f7d154f1..1cf8fd5b8 100644 --- a/src/Artemis.Core/Services/CoreService.cs +++ b/src/Artemis.Core/Services/CoreService.cs @@ -90,7 +90,7 @@ namespace Artemis.Core.Services else _logger.Information("Initialized without an active surface entity"); - _profileService.ActivateDefaultProfiles(); + _profileService.ActivateLastActiveProfiles(); OnInitialized(); } diff --git a/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs b/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs index 9fe885d6b..ed087426c 100644 --- a/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs +++ b/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs @@ -7,19 +7,50 @@ namespace Artemis.Core.Services.Storage.Interfaces { public interface IProfileService : IArtemisService { - void ActivateDefaultProfiles(); - Profile CreateProfile(ProfileModule module, string name); - List GetProfiles(ProfileModule module); - Profile GetActiveProfile(ProfileModule module); + /// + /// Activates the last profile for each module + /// + void ActivateLastActiveProfiles(); + + /// + /// Creates a new profile for the given module and returns a descriptor pointing to it + /// + /// The profile module to create the profile for + /// The name of the new profile + /// + ProfileDescriptor CreateProfile(ProfileModule module, string name); + + /// + /// Gets a descriptor for each profile stored for the given + /// + /// The module to return profile descriptors for + /// + List GetProfiles(ProfileModule module); + + /// + /// Writes the profile to persistent storage + /// + /// + /// void UpdateProfile(Profile profile, bool includeChildren); + + /// + /// Disposes and permanently deletes the provided profile + /// + /// The profile to delete void DeleteProfile(Profile profile); /// - /// Activates the profile for the given with the currently active surface + /// Activates the profile described in the given with the currently active surface /// - /// The module to activate the profile for - /// The profile to activate - void ActivateProfile(ProfileModule module, Profile profile); + /// The descriptor describing the profile to activate + Profile ActivateProfile(ProfileDescriptor profileDescriptor); + + /// + /// Clears the active profile on the given + /// + /// The profile module to deactivate the active profile on + void ClearActiveProfile(ProfileModule module); /// /// Attempts to restore the profile to the state it had before the last call. diff --git a/src/Artemis.Core/Services/Storage/ProfileService.cs b/src/Artemis.Core/Services/Storage/ProfileService.cs index d970852c7..e71830e3e 100644 --- a/src/Artemis.Core/Services/Storage/ProfileService.cs +++ b/src/Artemis.Core/Services/Storage/ProfileService.cs @@ -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()) { - var activeProfile = GetActiveProfile(profileModule); - ActivateProfile(profileModule, activeProfile); + var activeProfile = GetLastActiveProfile(profileModule); + ActivateProfile(activeProfile); } } - public List GetProfiles(ProfileModule module) + public List GetProfiles(ProfileModule module) { var profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid); - var profiles = new List(); - 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); } diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs index 5f3e2e1f0..4f9f1d7f3 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs @@ -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; diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs index dae9006e0..a764e95ad 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs @@ -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) diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProperties.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProperties.cs index 83739ce06..ed547ad51 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProperties.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProperties.cs @@ -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 { 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 + } } \ No newline at end of file diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProperties.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProperties.cs index ab0a7dcc2..df78485bc 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProperties.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProperties.cs @@ -20,7 +20,7 @@ namespace Artemis.Plugins.LayerBrushes.ColorRgbNet TestProperty.DefaultValue = "I was empty before!"; } - protected override void OnPropertiesInitialized() + protected override void EnableProperties() { } } diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProperties.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProperties.cs index 17fe7255e..0fceec8a8 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProperties.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProperties.cs @@ -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(); diff --git a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/BlurEffectProperties.cs b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/BlurEffectProperties.cs index 5f9f54986..33d190e23 100644 --- a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/BlurEffectProperties.cs +++ b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/BlurEffectProperties.cs @@ -14,7 +14,7 @@ namespace Artemis.Plugins.LayerEffects.Filter { } - protected override void OnPropertiesInitialized() + protected override void EnableProperties() { } diff --git a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ColorMatrixEffectProperties.cs b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ColorMatrixEffectProperties.cs index bedcfd5fa..43b70f133 100644 --- a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ColorMatrixEffectProperties.cs +++ b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ColorMatrixEffectProperties.cs @@ -21,7 +21,7 @@ namespace Artemis.Plugins.LayerEffects.Filter }; } - protected override void OnPropertiesInitialized() + protected override void EnableProperties() { ColorMatrix.IsHidden = true; } diff --git a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/DilateEffectProperties.cs b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/DilateEffectProperties.cs index 3049f2867..9bdbbdde9 100644 --- a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/DilateEffectProperties.cs +++ b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/DilateEffectProperties.cs @@ -13,7 +13,7 @@ namespace Artemis.Plugins.LayerEffects.Filter { } - protected override void OnPropertiesInitialized() + protected override void EnableProperties() { } } diff --git a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ErodeEffectProperties.cs b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ErodeEffectProperties.cs index 7ac09e4a7..45191c6e8 100644 --- a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ErodeEffectProperties.cs +++ b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/ErodeEffectProperties.cs @@ -13,7 +13,7 @@ namespace Artemis.Plugins.LayerEffects.Filter { } - protected override void OnPropertiesInitialized() + protected override void EnableProperties() { } } diff --git a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/GlowEffectProperties.cs b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/GlowEffectProperties.cs index 5aace96bd..368c6f090 100644 --- a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/GlowEffectProperties.cs +++ b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/GlowEffectProperties.cs @@ -22,7 +22,7 @@ namespace Artemis.Plugins.LayerEffects.Filter GlowColor.DefaultValue = new SKColor(255, 255, 255); } - protected override void OnPropertiesInitialized() + protected override void EnableProperties() { } } diff --git a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/GrayScaleEffectProperties.cs b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/GrayScaleEffectProperties.cs index a9bace0b3..f37d6337d 100644 --- a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/GrayScaleEffectProperties.cs +++ b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/GrayScaleEffectProperties.cs @@ -13,7 +13,7 @@ namespace Artemis.Plugins.LayerEffects.Filter { } - protected override void OnPropertiesInitialized() + protected override void EnableProperties() { } } diff --git a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/OpacityEffect.cs b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/OpacityEffect.cs index 5ef4210fa..b1acfaf3a 100644 --- a/src/Plugins/Artemis.Plugins.LayerEffects.Filter/OpacityEffect.cs +++ b/src/Plugins/Artemis.Plugins.LayerEffects.Filter/OpacityEffect.cs @@ -40,7 +40,7 @@ namespace Artemis.Plugins.LayerEffects.Filter Opacity.DefaultValue = 100f; } - protected override void OnPropertiesInitialized() + protected override void EnableProperties() { } }