1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-01 02:03:32 +00:00

LUA layer interaction fixes

This commit is contained in:
SpoinkyNL 2016-11-04 22:36:15 +01:00
parent 3bb15f70c3
commit adc5bb9adf
13 changed files with 86 additions and 128 deletions

View File

@ -35,7 +35,7 @@ namespace Artemis.Profiles.Layers.Animations
const int scale = 4; const int scale = 4;
// Set up variables for this frame // 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(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); : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale);

View File

@ -35,7 +35,7 @@ namespace Artemis.Profiles.Layers.Animations
const int scale = 4; const int scale = 4;
// Set up variables for this frame // 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(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); : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale);

View File

@ -28,7 +28,7 @@ namespace Artemis.Profiles.Layers.Animations
const int scale = 4; const int scale = 4;
// Set up variables for this frame // 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(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); : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale);

View File

@ -28,7 +28,7 @@ namespace Artemis.Profiles.Layers.Animations
const int scale = 4; const int scale = 4;
// Set up variables for this frame // 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(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); : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale);

View File

@ -28,7 +28,7 @@ namespace Artemis.Profiles.Layers.Animations
const int scale = 4; const int scale = 4;
// Set up variables for this frame // 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(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); : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale);

View File

@ -28,7 +28,7 @@ namespace Artemis.Profiles.Layers.Animations
const int scale = 4; const int scale = 4;
// Set up variables for this frame // 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(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); : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale);

View File

@ -67,6 +67,8 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
layerModel.Properties.Y = 0; layerModel.Properties.Y = 0;
layerModel.Properties.Contain = true; layerModel.Properties.Contain = true;
layerModel.AppliedProperties = new KeyPressPropertiesModel(layerModel.Properties);
_layerModel = layerModel; _layerModel = layerModel;
if (isPreview) if (isPreview)

View File

@ -44,7 +44,7 @@ namespace Artemis.Profiles.Layers.Types.Keyboard
} }
// Otherwise draw the rectangle with its layer.AppliedProperties dimensions and brush // 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, ? new Rect(layer.AppliedProperties.X*4,
layer.AppliedProperties.Y*4, layer.AppliedProperties.Y*4,
layer.AppliedProperties.Width*4, layer.AppliedProperties.Width*4,

View File

@ -7,7 +7,17 @@ namespace Artemis.Profiles.Lua.Brushes
[MoonSharpUserData] [MoonSharpUserData]
public abstract class LuaBrush public abstract class LuaBrush
{ {
private Brush _brush;
[MoonSharpVisible(false)] [MoonSharpVisible(false)]
public virtual Brush Brush { get; set; } public Brush Brush
{
get { return _brush; }
set
{
value.Freeze();
_brush = value;
}
}
} }
} }

View File

@ -1,20 +1,21 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using MoonSharp.Interpreter; using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
namespace Artemis.Profiles.Lua.Brushes namespace Artemis.Profiles.Lua.Brushes
{ {
[MoonSharpUserData] [MoonSharpUserData]
public class LuaLinearGradientBrush : LuaBrush public class LuaLinearGradientBrush : LuaBrush
{ {
private LinearGradientBrush _brush; public LuaLinearGradientBrush(Brush brush)
public LuaLinearGradientBrush(LinearGradientBrush brush)
{ {
LinearGradientBrush = brush; if (!(brush is LinearGradientBrush))
throw new ArgumentException("Brush type must be LinearGradientBrush");
Brush = brush;
} }
public LuaLinearGradientBrush(Dictionary<LuaColor, double> gradientColors, double startX, double startY, public LuaLinearGradientBrush(Dictionary<LuaColor, double> gradientColors, double startX, double startY,
@ -23,27 +24,6 @@ namespace Artemis.Profiles.Lua.Brushes
SetupBrush(gradientColors, startX, startY, endX, endY); SetupBrush(gradientColors, startX, startY, endX, endY);
} }
/// <summary>
/// The underlying brush
/// </summary>
[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; }
}
/// <summary> /// <summary>
/// Gets or sets the Brush's GradientStops using a LUA table /// Gets or sets the Brush's GradientStops using a LUA table
/// </summary> /// </summary>
@ -51,15 +31,16 @@ namespace Artemis.Profiles.Lua.Brushes
{ {
get 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 set
{ {
var updatedBrush = LinearGradientBrush.CloneCurrentValue(); var updatedBrush = ((LinearGradientBrush) Brush).CloneCurrentValue();
updatedBrush.GradientStops = new GradientStopCollection(value updatedBrush.GradientStops =
.Select(gc => new GradientStop(gc.Key.Color, gc.Value))); 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 var collection = new GradientStopCollection(gradientColors
.Select(gc => new GradientStop(gc.Key.Color, gc.Value))); .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));
} }
} }
} }

View File

@ -1,20 +1,21 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using MoonSharp.Interpreter; using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
namespace Artemis.Profiles.Lua.Brushes namespace Artemis.Profiles.Lua.Brushes
{ {
[MoonSharpUserData] [MoonSharpUserData]
public class LuaRadialGradientBrush : LuaBrush public class LuaRadialGradientBrush : LuaBrush
{ {
private RadialGradientBrush _brush; public LuaRadialGradientBrush(Brush brush)
public LuaRadialGradientBrush(RadialGradientBrush brush)
{ {
RadialGradientBrush = brush; if (!(brush is RadialGradientBrush))
throw new ArgumentException("Brush type must be RadialGradientBrush");
Brush = brush;
} }
public LuaRadialGradientBrush(Dictionary<LuaColor, double> gradientColors, double centerX, public LuaRadialGradientBrush(Dictionary<LuaColor, double> gradientColors, double centerX,
@ -23,27 +24,6 @@ namespace Artemis.Profiles.Lua.Brushes
SetupBrush(gradientColors, centerX, centerY, originX, originY); SetupBrush(gradientColors, centerX, centerY, originX, originY);
} }
/// <summary>
/// The underlying brush
/// </summary>
[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; }
}
/// <summary> /// <summary>
/// Gets or sets the Brush's GradientStops using a LUA table /// Gets or sets the Brush's GradientStops using a LUA table
/// </summary> /// </summary>
@ -51,15 +31,16 @@ namespace Artemis.Profiles.Lua.Brushes
{ {
get 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 set
{ {
var updatedBrush = RadialGradientBrush.CloneCurrentValue(); var updatedBrush = ((RadialGradientBrush) Brush).CloneCurrentValue();
updatedBrush.GradientStops = new GradientStopCollection(value updatedBrush.GradientStops =
.Select(gc => new GradientStop(gc.Key.Color, gc.Value))); 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 var collection = new GradientStopCollection(gradientColors
.Select(gc => new GradientStop(gc.Key.Color, gc.Value))); .Select(gc => new GradientStop(gc.Key.Color, gc.Value)));
RadialGradientBrush = new RadialGradientBrush(collection) Brush = new RadialGradientBrush(collection)
{ {
Center = new Point(centerX, centerY), Center = new Point(centerX, centerY),
GradientOrigin = new Point(originX, originY) GradientOrigin = new Point(originX, originY)

View File

@ -1,49 +1,29 @@
using System.Windows.Media; using System;
using System.Windows.Media;
using MoonSharp.Interpreter; using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
namespace Artemis.Profiles.Lua.Brushes namespace Artemis.Profiles.Lua.Brushes
{ {
[MoonSharpUserData] [MoonSharpUserData]
public class LuaSolidColorBrush : LuaBrush public class LuaSolidColorBrush : LuaBrush
{ {
private SolidColorBrush _brush; public LuaSolidColorBrush(Brush brush)
public LuaSolidColorBrush(SolidColorBrush brush)
{ {
SolidColorBrush = brush; if (!(brush is SolidColorBrush))
throw new ArgumentException("Brush type must be SolidColorBrush");
Brush = brush;
} }
public LuaSolidColorBrush(LuaColor luaColor) public LuaSolidColorBrush(LuaColor luaColor)
{ {
SolidColorBrush = new SolidColorBrush(luaColor.Color); Brush = new SolidColorBrush(luaColor.Color);
}
/// <summary>
/// The underlying brush
/// </summary>
[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; }
} }
public LuaColor Color public LuaColor Color
{ {
get { return new LuaColor(SolidColorBrush.Color); } get { return new LuaColor(((SolidColorBrush) Brush).Color); }
set { SolidColorBrush = new SolidColorBrush(value.Color); } set { Brush = new SolidColorBrush(value.Color); }
} }
} }
} }

View File

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows.Media; using System.Windows.Media;
using Artemis.Modules.Effects.ProfilePreview;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.Profiles.Lua.Brushes; using Artemis.Profiles.Lua.Brushes;
using MoonSharp.Interpreter; using MoonSharp.Interpreter;
@ -18,6 +19,9 @@ namespace Artemis.Profiles.Lua
public LuaLayerWrapper(LayerModel layerModel) public LuaLayerWrapper(LayerModel layerModel)
{ {
_layerModel = layerModel; _layerModel = layerModel;
// Triger an update to fill up the AppliedProperties
_layerModel.Update(new ProfilePreviewDataModel(), true, false);
} }
#region Child methods #region Child methods
@ -63,67 +67,67 @@ namespace Artemis.Profiles.Lua
public double X public double X
{ {
get { return _layerModel.Properties.X; } get { return _layerModel.AppliedProperties.X; }
set { _layerModel.Properties.X = value; } set { _layerModel.AppliedProperties.X = value; }
} }
public double Y public double Y
{ {
get { return _layerModel.Properties.Y; } get { return _layerModel.AppliedProperties.Y; }
set { _layerModel.Properties.Y = value; } set { _layerModel.AppliedProperties.Y = value; }
} }
public double Width public double Width
{ {
get { return _layerModel.Properties.Width; } get { return _layerModel.AppliedProperties.Width; }
set { _layerModel.Properties.Width = value; } set { _layerModel.AppliedProperties.Width = value; }
} }
public double Height public double Height
{ {
get { return _layerModel.Properties.Height; } get { return _layerModel.AppliedProperties.Height; }
set { _layerModel.Properties.Height = value; } set { _layerModel.AppliedProperties.Height = value; }
} }
public bool Contain public bool Contain
{ {
get { return _layerModel.Properties.Contain; } get { return _layerModel.AppliedProperties.Contain; }
set { _layerModel.Properties.Contain = value; } set { _layerModel.AppliedProperties.Contain = value; }
} }
public double Opacity public double Opacity
{ {
get { return _layerModel.Properties.Opacity; } get { return _layerModel.AppliedProperties.Opacity; }
set { _layerModel.Properties.Opacity = value; } set { _layerModel.AppliedProperties.Opacity = value; }
} }
public double AnimationSpeed public double AnimationSpeed
{ {
get { return _layerModel.Properties.AnimationSpeed; } get { return _layerModel.AppliedProperties.AnimationSpeed; }
set { _layerModel.Properties.AnimationSpeed = value; } set { _layerModel.AppliedProperties.AnimationSpeed = value; }
} }
public double AnimationProgress public double AnimationProgress
{ {
get { return _layerModel.Properties.AnimationProgress; } get { return _layerModel.AppliedProperties.AnimationProgress; }
set { _layerModel.Properties.AnimationProgress = value; } set { _layerModel.AppliedProperties.AnimationProgress = value; }
} }
public string BrushType => _layerModel.Properties.Brush?.GetType().Name; public string BrushType => _layerModel.AppliedProperties.Brush?.GetType().Name;
public LuaBrush Brush public LuaBrush Brush
{ {
get get
{ {
if (_layerModel.Properties.Brush is SolidColorBrush) if (_layerModel.AppliedProperties.Brush is SolidColorBrush)
return new LuaSolidColorBrush((SolidColorBrush) _layerModel.Properties.Brush); return new LuaSolidColorBrush(_layerModel.AppliedProperties.Brush);
if (_layerModel.Properties.Brush is LinearGradientBrush) if (_layerModel.AppliedProperties.Brush is LinearGradientBrush)
return new LuaLinearGradientBrush((LinearGradientBrush) _layerModel.Properties.Brush); return new LuaLinearGradientBrush(_layerModel.AppliedProperties.Brush);
if (_layerModel.Properties.Brush is RadialGradientBrush) if (_layerModel.AppliedProperties.Brush is RadialGradientBrush)
return new LuaRadialGradientBrush((RadialGradientBrush) _layerModel.Properties.Brush); return new LuaRadialGradientBrush(_layerModel.AppliedProperties.Brush);
return null; return null;
} }
set { _layerModel.Properties.Brush = value.Brush; } set { _layerModel.AppliedProperties.Brush = value.Brush; }
} }
#endregion #endregion