1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Final LUA brush implemented

This commit is contained in:
Robert Beekman 2016-10-27 21:53:18 +02:00
parent 2bd21bfc0e
commit f797bc470a
3 changed files with 58 additions and 17 deletions

View File

@ -13,13 +13,14 @@ namespace Artemis.Profiles.Lua.Brushes
private readonly Script _script; private readonly Script _script;
private LinearGradientBrush _brush; private LinearGradientBrush _brush;
public LuaLinearGradientBrush(LinearGradientBrush linearGradientBrush) public LuaLinearGradientBrush(Script script, LinearGradientBrush linearGradientBrush)
{ {
_script = script;
Brush = linearGradientBrush; Brush = linearGradientBrush;
} }
public LuaLinearGradientBrush(Script script, Table gradientColors, double startX = 0.5, double startY = 0.0, public LuaLinearGradientBrush(Script script, Table gradientColors,
double endX = 0.5, double endY = 1.0) double startX, double startY, double endX, double endY)
{ {
_script = script; _script = script;
SetupBrush(gradientColors, startX, startY, endX, endY); SetupBrush(gradientColors, startX, startY, endX, endY);
@ -44,7 +45,7 @@ namespace Artemis.Profiles.Lua.Brushes
/// </summary> /// </summary>
public Table Colors public Table Colors
{ {
get { return CreateGradientTable(); } get { return CreateGradientTable(_script, Brush.GradientStops); }
set set
{ {
var updatedBrush = Brush.CloneCurrentValue(); var updatedBrush = Brush.CloneCurrentValue();
@ -72,7 +73,7 @@ namespace Artemis.Profiles.Lua.Brushes
/// </summary> /// </summary>
/// <param name="gradientColors"></param> /// <param name="gradientColors"></param>
/// <returns></returns> /// <returns></returns>
private GradientStopCollection CreateGradientCollection(Table gradientColors) public static GradientStopCollection CreateGradientCollection(Table gradientColors)
{ {
var collection = new GradientStopCollection(); var collection = new GradientStopCollection();
foreach (var gradientColor in gradientColors.Values) foreach (var gradientColor in gradientColors.Values)
@ -89,12 +90,12 @@ namespace Artemis.Profiles.Lua.Brushes
/// Maps the current brush's GradientStopsCollection to a LUA table /// Maps the current brush's GradientStopsCollection to a LUA table
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private Table CreateGradientTable() public static Table CreateGradientTable(Script script, GradientStopCollection gradientStops)
{ {
var table = new Table(_script); var table = new Table(script);
foreach (var gradientStop in Brush.GradientStops) foreach (var gradientStop in gradientStops)
{ {
var inner = new Table(_script); var inner = new Table(script);
inner.Append(DynValue.NewString(gradientStop.Color.ToHex())); inner.Append(DynValue.NewString(gradientStop.Color.ToHex()));
inner.Append(DynValue.NewNumber(gradientStop.Offset)); inner.Append(DynValue.NewNumber(gradientStop.Offset));
table.Append(DynValue.NewTable(inner)); table.Append(DynValue.NewTable(inner));

View File

@ -1,4 +1,5 @@
using System.Windows.Media; using System.Windows;
using System.Windows.Media;
using MoonSharp.Interpreter; using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop; using MoonSharp.Interpreter.Interop;
@ -7,13 +8,25 @@ namespace Artemis.Profiles.Lua.Brushes
[MoonSharpUserData] [MoonSharpUserData]
public class LuaRadialGradientBrush : LuaBrush public class LuaRadialGradientBrush : LuaBrush
{ {
private readonly Script _script;
private RadialGradientBrush _brush; private RadialGradientBrush _brush;
public LuaRadialGradientBrush(RadialGradientBrush radialGradientBrush) public LuaRadialGradientBrush(Script script, RadialGradientBrush radialGradientBrush)
{ {
_script = script;
Brush = radialGradientBrush; Brush = radialGradientBrush;
} }
public LuaRadialGradientBrush(Script script, Table gradientColors,
double centerX, double centerY, double originX, double originY)
{
_script = script;
SetupBrush(gradientColors, centerX, centerY, originX, originY);
}
/// <summary>
/// The underlying brush
/// </summary>
[MoonSharpVisible(false)] [MoonSharpVisible(false)]
public new RadialGradientBrush Brush public new RadialGradientBrush Brush
{ {
@ -25,10 +38,36 @@ namespace Artemis.Profiles.Lua.Brushes
} }
} }
/// <summary>
/// Gets or sets the Brush's GradientStops using a LUA table
/// </summary>
public Table Colors public Table Colors
{ {
get { throw new System.NotImplementedException(); } get { return LuaLinearGradientBrush.CreateGradientTable(_script, Brush.GradientStops); }
set { throw new System.NotImplementedException(); } set
{
var updatedBrush = Brush.CloneCurrentValue();
updatedBrush.GradientStops = LuaLinearGradientBrush.CreateGradientCollection(value);
Brush = updatedBrush;
}
}
/// <summary>
/// Configures the brush according to the provided values usable in LUA
/// </summary>
/// <param name="gradientColors"></param>
/// <param name="centerX"></param>
/// <param name="centerY"></param>
/// <param name="originX"></param>
/// <param name="originY"></param>
private void SetupBrush(Table gradientColors, double centerX, double centerY, double originX, double originY)
{
var collection = LuaLinearGradientBrush.CreateGradientCollection(gradientColors);
Brush = new RadialGradientBrush(collection)
{
Center = new Point(centerX, centerY),
GradientOrigin = new Point(originX, originY)
};
} }
} }
} }

View File

@ -1,5 +1,4 @@
using System.Windows.Media; using Artemis.Profiles.Lua.Brushes;
using Artemis.Profiles.Lua.Brushes;
using MoonSharp.Interpreter; using MoonSharp.Interpreter;
namespace Artemis.Profiles.Lua namespace Artemis.Profiles.Lua
@ -14,9 +13,11 @@ namespace Artemis.Profiles.Lua
_script = script; _script = script;
} }
public LuaRadialGradientBrush GetSolidColorBrush(string hexCode) // TODO: Check default values
public LuaRadialGradientBrush GetSolidColorBrush(Table gradientColors,
double centerX = 0.5, double centerY = 0.5, double originX = 0.5, double originY = 0.5)
{ {
return new LuaRadialGradientBrush(new RadialGradientBrush()); return new LuaRadialGradientBrush(_script, gradientColors, centerX, centerY, originX, originY);
} }
public LuaLinearGradientBrush GetLinearGradientBrush(Table gradientColors, public LuaLinearGradientBrush GetLinearGradientBrush(Table gradientColors,