From 97c85e238c2ba6986a4f83a6cabe738ddb8ffe13 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Wed, 3 Jun 2020 19:22:08 +0200 Subject: [PATCH] Layer brushes - Render now always originates from 0,0 RGB.NET brushes - GetBrush is no called after properties are initialized Profile editor - Fixed inputs not responding to updates from the visualization tools when keyframes are disabled --- src/Artemis.Core/Models/Profile/Layer.cs | 16 +++++++--------- .../Plugins/LayerBrush/LayerBrush.cs | 5 +++++ .../Plugins/LayerBrush/RgbNetLayerBrush.cs | 2 +- .../PropertyInput/PropertyInputViewModel.cs | 3 +++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index 55f18200f..b5706b9e3 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -207,12 +207,12 @@ namespace Artemis.Core.Models.Profile if (LayerBrush?.BaseProperties == null || !LayerBrush.BaseProperties.PropertiesInitialized) return; + // TODO: Remove, this is slow and stupid + // For now, reset all keyframe engines after the last keyframe was hit + // This is a placeholder method of repeating the animation until repeat modes are implemented var properties = new List(General.GetAllLayerProperties().Where(p => p.BaseKeyframes.Any())); properties.AddRange(Transform.GetAllLayerProperties().Where(p => p.BaseKeyframes.Any())); properties.AddRange(LayerBrush.BaseProperties.GetAllLayerProperties().Where(p => p.BaseKeyframes.Any())); - - // For now, reset all keyframe engines after the last keyframe was hit - // This is a placeholder method of repeating the animation until repeat modes are implemented var timeLineEnd = properties.Any() ? properties.Max(p => p.BaseKeyframes.Max(k => k.Position)) : TimeSpan.MaxValue; if (properties.Any(p => p.TimelineProgress >= timeLineEnd)) { @@ -240,8 +240,12 @@ namespace Artemis.Core.Models.Profile /// public override void Render(double deltaTime, SKCanvas canvas, SKImageInfo canvasInfo) { + // Ensure the layer is ready if (Path == null || LayerShape?.Path == null || !General.PropertiesInitialized || !Transform.PropertiesInitialized) return; + // Ensure the brush is ready + if (LayerBrush?.BaseProperties?.PropertiesInitialized == false || LayerBrush?.BrushType != LayerBrushType.Regular) + return; canvas.Save(); canvas.ClipPath(Path); @@ -269,9 +273,6 @@ namespace Artemis.Core.Models.Profile private void StretchRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint) { - if (LayerBrush == null || !LayerBrush.BaseProperties.PropertiesInitialized || LayerBrush.BrushType != LayerBrushType.Regular) - return; - // Apply transformations var sizeProperty = Transform.Scale.CurrentValue; var rotationProperty = Transform.Rotation.CurrentValue; @@ -293,9 +294,6 @@ namespace Artemis.Core.Models.Profile private void ClipRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint) { - if (LayerBrush == null || !LayerBrush.BaseProperties.PropertiesInitialized || LayerBrush.BrushType != LayerBrushType.Regular) - return; - // Apply transformations var sizeProperty = Transform.Scale.CurrentValue; var rotationProperty = Transform.Rotation.CurrentValue; diff --git a/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs index a466492ff..c2285a09a 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs @@ -26,6 +26,11 @@ namespace Artemis.Core.Plugins.LayerBrush internal override void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint) { + // Move the canvas to the top-left of the render path + canvas.Translate(path.Bounds.Left, path.Bounds.Top); + // Pass the render path to the layer brush positioned at 0,0 + path.Transform(SKMatrix.MakeTranslation(path.Bounds.Left * -1, path.Bounds.Top * -1)); + Render(canvas, canvasInfo, path, paint); } diff --git a/src/Artemis.Core/Plugins/LayerBrush/RgbNetLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/RgbNetLayerBrush.cs index 3cbf70fe3..48c01a6f7 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/RgbNetLayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/RgbNetLayerBrush.cs @@ -17,7 +17,6 @@ namespace Artemis.Core.Plugins.LayerBrush Layer = layer; Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated; - UpdateLedGroup(); } /// @@ -59,6 +58,7 @@ namespace Artemis.Core.Plugins.LayerBrush internal override void Initialize(ILayerService layerService) { InitializeProperties(layerService); + UpdateLedGroup(); } // Not used in this brush type diff --git a/src/Artemis.UI.Shared/PropertyInput/PropertyInputViewModel.cs b/src/Artemis.UI.Shared/PropertyInput/PropertyInputViewModel.cs index 36f3ba376..fb08cfe80 100644 --- a/src/Artemis.UI.Shared/PropertyInput/PropertyInputViewModel.cs +++ b/src/Artemis.UI.Shared/PropertyInput/PropertyInputViewModel.cs @@ -14,6 +14,7 @@ namespace Artemis.UI.Shared.PropertyInput LayerProperty = layerProperty; ProfileEditorService = profileEditorService; LayerProperty.Updated += LayerPropertyOnUpdated; + LayerProperty.BaseValueChanged += LayerPropertyOnUpdated; UpdateInputValue(); } @@ -22,6 +23,7 @@ namespace Artemis.UI.Shared.PropertyInput LayerProperty = layerProperty; ProfileEditorService = profileEditorService; LayerProperty.Updated += LayerPropertyOnUpdated; + LayerProperty.BaseValueChanged += LayerPropertyOnUpdated; UpdateInputValue(); } @@ -43,6 +45,7 @@ namespace Artemis.UI.Shared.PropertyInput public virtual void Dispose() { LayerProperty.Updated -= LayerPropertyOnUpdated; + LayerProperty.BaseValueChanged -= LayerPropertyOnUpdated; } protected virtual void OnInputValueApplied()