diff --git a/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs index 587597f7f..56cd8958d 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs @@ -35,7 +35,7 @@ namespace Artemis.Profiles.Layers.Animations const int scale = 4; // Set up variables for this frame - var rect = props.Contain + var rect = applied.Contain ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); diff --git a/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs index 7417d36b9..ee7c0a131 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs @@ -35,7 +35,7 @@ namespace Artemis.Profiles.Layers.Animations const int scale = 4; // Set up variables for this frame - var rect = props.Contain + var rect = applied.Contain ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs index 74b56819c..23b176656 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs @@ -28,7 +28,7 @@ namespace Artemis.Profiles.Layers.Animations const int scale = 4; // Set up variables for this frame - var rect = props.Contain + var rect = applied.Contain ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs index f77fbcaf4..7394deee4 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs @@ -28,7 +28,7 @@ namespace Artemis.Profiles.Layers.Animations const int scale = 4; // Set up variables for this frame - var rect = props.Contain + var rect = applied.Contain ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs index 89229b254..83352d26c 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs @@ -28,7 +28,7 @@ namespace Artemis.Profiles.Layers.Animations const int scale = 4; // Set up variables for this frame - var rect = props.Contain + var rect = applied.Contain ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs index fc5ab53c6..651fb88b2 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs @@ -28,7 +28,7 @@ namespace Artemis.Profiles.Layers.Animations const int scale = 4; // Set up variables for this frame - var rect = props.Contain + var rect = applied.Contain ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); diff --git a/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs b/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs index 01f2db9b8..dfbf75ac8 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs @@ -67,6 +67,8 @@ namespace Artemis.Profiles.Layers.Types.KeyPress layerModel.Properties.Y = 0; layerModel.Properties.Contain = true; + layerModel.AppliedProperties = new KeyPressPropertiesModel(layerModel.Properties); + _layerModel = layerModel; if (isPreview) diff --git a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs index 7a570c644..d5e90cbed 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs @@ -44,7 +44,7 @@ namespace Artemis.Profiles.Layers.Types.Keyboard } // Otherwise draw the rectangle with its layer.AppliedProperties dimensions and brush - var rect = layer.Properties.Contain + var rect = layer.AppliedProperties.Contain ? new Rect(layer.AppliedProperties.X*4, layer.AppliedProperties.Y*4, layer.AppliedProperties.Width*4, diff --git a/Artemis/Artemis/Profiles/Lua/Brushes/LuaBrush.cs b/Artemis/Artemis/Profiles/Lua/Brushes/LuaBrush.cs index 21a31f891..497f9616b 100644 --- a/Artemis/Artemis/Profiles/Lua/Brushes/LuaBrush.cs +++ b/Artemis/Artemis/Profiles/Lua/Brushes/LuaBrush.cs @@ -7,7 +7,17 @@ namespace Artemis.Profiles.Lua.Brushes [MoonSharpUserData] public abstract class LuaBrush { + private Brush _brush; + [MoonSharpVisible(false)] - public virtual Brush Brush { get; set; } + public Brush Brush + { + get { return _brush; } + set + { + value.Freeze(); + _brush = value; + } + } } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Lua/Brushes/LuaLinearGradientBrush.cs b/Artemis/Artemis/Profiles/Lua/Brushes/LuaLinearGradientBrush.cs index 0ea3ad65a..2f62d030a 100644 --- a/Artemis/Artemis/Profiles/Lua/Brushes/LuaLinearGradientBrush.cs +++ b/Artemis/Artemis/Profiles/Lua/Brushes/LuaLinearGradientBrush.cs @@ -1,20 +1,21 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Media; using MoonSharp.Interpreter; -using MoonSharp.Interpreter.Interop; namespace Artemis.Profiles.Lua.Brushes { [MoonSharpUserData] public class LuaLinearGradientBrush : LuaBrush { - private LinearGradientBrush _brush; - - public LuaLinearGradientBrush(LinearGradientBrush brush) + public LuaLinearGradientBrush(Brush brush) { - LinearGradientBrush = brush; + if (!(brush is LinearGradientBrush)) + throw new ArgumentException("Brush type must be LinearGradientBrush"); + + Brush = brush; } public LuaLinearGradientBrush(Dictionary gradientColors, double startX, double startY, @@ -23,27 +24,6 @@ namespace Artemis.Profiles.Lua.Brushes SetupBrush(gradientColors, startX, startY, endX, endY); } - /// - /// The underlying brush - /// - [MoonSharpVisible(false)] - public LinearGradientBrush LinearGradientBrush - { - get { return _brush; } - set - { - _brush = value; - _brush.Freeze(); - Brush = _brush; - } - } - - public override Brush Brush - { - get { return LinearGradientBrush; } - set { LinearGradientBrush = (LinearGradientBrush) value; } - } - /// /// Gets or sets the Brush's GradientStops using a LUA table /// @@ -51,15 +31,16 @@ namespace Artemis.Profiles.Lua.Brushes { get { - return LinearGradientBrush.GradientStops.ToDictionary(gs => new LuaColor(gs.Color), gs => gs.Offset); + return ((LinearGradientBrush) Brush).GradientStops.ToDictionary(gs => new LuaColor(gs.Color), + gs => gs.Offset); } set { - var updatedBrush = LinearGradientBrush.CloneCurrentValue(); - updatedBrush.GradientStops = new GradientStopCollection(value - .Select(gc => new GradientStop(gc.Key.Color, gc.Value))); + var updatedBrush = ((LinearGradientBrush) Brush).CloneCurrentValue(); + updatedBrush.GradientStops = + new GradientStopCollection(value.Select(gc => new GradientStop(gc.Key.Color, gc.Value))); - LinearGradientBrush = updatedBrush; + Brush = updatedBrush; } } @@ -77,7 +58,7 @@ namespace Artemis.Profiles.Lua.Brushes var collection = new GradientStopCollection(gradientColors .Select(gc => new GradientStop(gc.Key.Color, gc.Value))); - LinearGradientBrush = new LinearGradientBrush(collection, new Point(startX, startY), new Point(endX, endY)); + Brush = new LinearGradientBrush(collection, new Point(startX, startY), new Point(endX, endY)); } } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Lua/Brushes/LuaRadialGradientBrush.cs b/Artemis/Artemis/Profiles/Lua/Brushes/LuaRadialGradientBrush.cs index 2c34abeea..d1300784a 100644 --- a/Artemis/Artemis/Profiles/Lua/Brushes/LuaRadialGradientBrush.cs +++ b/Artemis/Artemis/Profiles/Lua/Brushes/LuaRadialGradientBrush.cs @@ -1,20 +1,21 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Media; using MoonSharp.Interpreter; -using MoonSharp.Interpreter.Interop; namespace Artemis.Profiles.Lua.Brushes { [MoonSharpUserData] public class LuaRadialGradientBrush : LuaBrush { - private RadialGradientBrush _brush; - - public LuaRadialGradientBrush(RadialGradientBrush brush) + public LuaRadialGradientBrush(Brush brush) { - RadialGradientBrush = brush; + if (!(brush is RadialGradientBrush)) + throw new ArgumentException("Brush type must be RadialGradientBrush"); + + Brush = brush; } public LuaRadialGradientBrush(Dictionary gradientColors, double centerX, @@ -23,27 +24,6 @@ namespace Artemis.Profiles.Lua.Brushes SetupBrush(gradientColors, centerX, centerY, originX, originY); } - /// - /// The underlying brush - /// - [MoonSharpVisible(false)] - public RadialGradientBrush RadialGradientBrush - { - get { return _brush; } - set - { - _brush = value; - _brush.Freeze(); - Brush = _brush; - } - } - - public override Brush Brush - { - get { return RadialGradientBrush; } - set { RadialGradientBrush = (RadialGradientBrush) value; } - } - /// /// Gets or sets the Brush's GradientStops using a LUA table /// @@ -51,15 +31,16 @@ namespace Artemis.Profiles.Lua.Brushes { get { - return RadialGradientBrush.GradientStops.ToDictionary(gs => new LuaColor(gs.Color), gs => gs.Offset); + return ((RadialGradientBrush) Brush).GradientStops.ToDictionary(gs => new LuaColor(gs.Color), + gs => gs.Offset); } set { - var updatedBrush = RadialGradientBrush.CloneCurrentValue(); - updatedBrush.GradientStops = new GradientStopCollection(value - .Select(gc => new GradientStop(gc.Key.Color, gc.Value))); + var updatedBrush = ((RadialGradientBrush) Brush).CloneCurrentValue(); + updatedBrush.GradientStops = + new GradientStopCollection(value.Select(gc => new GradientStop(gc.Key.Color, gc.Value))); - RadialGradientBrush = updatedBrush; + Brush = updatedBrush; } } @@ -77,7 +58,7 @@ namespace Artemis.Profiles.Lua.Brushes var collection = new GradientStopCollection(gradientColors .Select(gc => new GradientStop(gc.Key.Color, gc.Value))); - RadialGradientBrush = new RadialGradientBrush(collection) + Brush = new RadialGradientBrush(collection) { Center = new Point(centerX, centerY), GradientOrigin = new Point(originX, originY) diff --git a/Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs b/Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs index a6f4f18c2..ed4163cf1 100644 --- a/Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs +++ b/Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs @@ -1,49 +1,29 @@ -using System.Windows.Media; +using System; +using System.Windows.Media; using MoonSharp.Interpreter; -using MoonSharp.Interpreter.Interop; namespace Artemis.Profiles.Lua.Brushes { [MoonSharpUserData] public class LuaSolidColorBrush : LuaBrush { - private SolidColorBrush _brush; - - public LuaSolidColorBrush(SolidColorBrush brush) + public LuaSolidColorBrush(Brush brush) { - SolidColorBrush = brush; + if (!(brush is SolidColorBrush)) + throw new ArgumentException("Brush type must be SolidColorBrush"); + + Brush = brush; } public LuaSolidColorBrush(LuaColor luaColor) { - SolidColorBrush = new SolidColorBrush(luaColor.Color); - } - - /// - /// The underlying brush - /// - [MoonSharpVisible(false)] - public SolidColorBrush SolidColorBrush - { - get { return _brush; } - set - { - _brush = value; - _brush.Freeze(); - Brush = _brush; - } - } - - public override Brush Brush - { - get { return SolidColorBrush; } - set { SolidColorBrush = (SolidColorBrush)value; } + Brush = new SolidColorBrush(luaColor.Color); } public LuaColor Color { - get { return new LuaColor(SolidColorBrush.Color); } - set { SolidColorBrush = new SolidColorBrush(value.Color); } + get { return new LuaColor(((SolidColorBrush) Brush).Color); } + set { Brush = new SolidColorBrush(value.Color); } } } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Lua/LuaLayerWrapper.cs b/Artemis/Artemis/Profiles/Lua/LuaLayerWrapper.cs index e777f9a3d..0ac4cd5af 100644 --- a/Artemis/Artemis/Profiles/Lua/LuaLayerWrapper.cs +++ b/Artemis/Artemis/Profiles/Lua/LuaLayerWrapper.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Windows.Media; +using Artemis.Modules.Effects.ProfilePreview; using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Lua.Brushes; using MoonSharp.Interpreter; @@ -18,6 +19,9 @@ namespace Artemis.Profiles.Lua public LuaLayerWrapper(LayerModel layerModel) { _layerModel = layerModel; + + // Triger an update to fill up the AppliedProperties + _layerModel.Update(new ProfilePreviewDataModel(), true, false); } #region Child methods @@ -63,67 +67,67 @@ namespace Artemis.Profiles.Lua public double X { - get { return _layerModel.Properties.X; } - set { _layerModel.Properties.X = value; } + get { return _layerModel.AppliedProperties.X; } + set { _layerModel.AppliedProperties.X = value; } } public double Y { - get { return _layerModel.Properties.Y; } - set { _layerModel.Properties.Y = value; } + get { return _layerModel.AppliedProperties.Y; } + set { _layerModel.AppliedProperties.Y = value; } } public double Width { - get { return _layerModel.Properties.Width; } - set { _layerModel.Properties.Width = value; } + get { return _layerModel.AppliedProperties.Width; } + set { _layerModel.AppliedProperties.Width = value; } } public double Height { - get { return _layerModel.Properties.Height; } - set { _layerModel.Properties.Height = value; } + get { return _layerModel.AppliedProperties.Height; } + set { _layerModel.AppliedProperties.Height = value; } } public bool Contain { - get { return _layerModel.Properties.Contain; } - set { _layerModel.Properties.Contain = value; } + get { return _layerModel.AppliedProperties.Contain; } + set { _layerModel.AppliedProperties.Contain = value; } } public double Opacity { - get { return _layerModel.Properties.Opacity; } - set { _layerModel.Properties.Opacity = value; } + get { return _layerModel.AppliedProperties.Opacity; } + set { _layerModel.AppliedProperties.Opacity = value; } } public double AnimationSpeed { - get { return _layerModel.Properties.AnimationSpeed; } - set { _layerModel.Properties.AnimationSpeed = value; } + get { return _layerModel.AppliedProperties.AnimationSpeed; } + set { _layerModel.AppliedProperties.AnimationSpeed = value; } } public double AnimationProgress { - get { return _layerModel.Properties.AnimationProgress; } - set { _layerModel.Properties.AnimationProgress = value; } + get { return _layerModel.AppliedProperties.AnimationProgress; } + set { _layerModel.AppliedProperties.AnimationProgress = value; } } - public string BrushType => _layerModel.Properties.Brush?.GetType().Name; + public string BrushType => _layerModel.AppliedProperties.Brush?.GetType().Name; public LuaBrush Brush { get { - if (_layerModel.Properties.Brush is SolidColorBrush) - return new LuaSolidColorBrush((SolidColorBrush) _layerModel.Properties.Brush); - if (_layerModel.Properties.Brush is LinearGradientBrush) - return new LuaLinearGradientBrush((LinearGradientBrush) _layerModel.Properties.Brush); - if (_layerModel.Properties.Brush is RadialGradientBrush) - return new LuaRadialGradientBrush((RadialGradientBrush) _layerModel.Properties.Brush); + if (_layerModel.AppliedProperties.Brush is SolidColorBrush) + return new LuaSolidColorBrush(_layerModel.AppliedProperties.Brush); + if (_layerModel.AppliedProperties.Brush is LinearGradientBrush) + return new LuaLinearGradientBrush(_layerModel.AppliedProperties.Brush); + if (_layerModel.AppliedProperties.Brush is RadialGradientBrush) + return new LuaRadialGradientBrush(_layerModel.AppliedProperties.Brush); return null; } - set { _layerModel.Properties.Brush = value.Brush; } + set { _layerModel.AppliedProperties.Brush = value.Brush; } } #endregion