1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +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;
// 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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -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,

View File

@ -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;
}
}
}
}

View File

@ -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<LuaColor, double> gradientColors, double startX, double startY,
@ -23,27 +24,6 @@ namespace Artemis.Profiles.Lua.Brushes
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>
/// Gets or sets the Brush's GradientStops using a LUA table
/// </summary>
@ -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));
}
}
}

View File

@ -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<LuaColor, double> gradientColors, double centerX,
@ -23,27 +24,6 @@ namespace Artemis.Profiles.Lua.Brushes
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>
/// Gets or sets the Brush's GradientStops using a LUA table
/// </summary>
@ -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)

View File

@ -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);
}
/// <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; }
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); }
}
}
}

View File

@ -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