mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
LUA Brush expansions
This commit is contained in:
parent
c7c3614f3b
commit
2bd21bfc0e
@ -414,7 +414,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Profiles\Layers\Types\Mousemat\MousematPropertiesViewModel.cs" />
|
<Compile Include="Profiles\Layers\Types\Mousemat\MousematPropertiesViewModel.cs" />
|
||||||
<Compile Include="Profiles\Layers\Types\Mousemat\MousematType.cs" />
|
<Compile Include="Profiles\Layers\Types\Mousemat\MousematType.cs" />
|
||||||
<Compile Include="Profiles\Lua\Brushes\ILuaBrush.cs" />
|
<Compile Include="Profiles\Lua\Brushes\LuaBrush.cs" />
|
||||||
<Compile Include="Profiles\Lua\Brushes\LuaLinearGradientBrush.cs" />
|
<Compile Include="Profiles\Lua\Brushes\LuaLinearGradientBrush.cs" />
|
||||||
<Compile Include="Profiles\Lua\Brushes\LuaRadialGradientBrush.cs" />
|
<Compile Include="Profiles\Lua\Brushes\LuaRadialGradientBrush.cs" />
|
||||||
<Compile Include="Profiles\Lua\LuaBrushWrapper.cs" />
|
<Compile Include="Profiles\Lua\LuaBrushWrapper.cs" />
|
||||||
|
|||||||
@ -16,9 +16,9 @@ namespace Artemis.DeviceProviders.Logitech
|
|||||||
@"SOFTWARE\Classes\Installer\Dependencies\{ca67548a-5ebe-413a-b50c-4b9ceb6d66c6}") == null)
|
@"SOFTWARE\Classes\Installer\Dependencies\{ca67548a-5ebe-413a-b50c-4b9ceb6d66c6}") == null)
|
||||||
{
|
{
|
||||||
CantEnableText = "Couldn't connect to your Logitech keyboard.\n" +
|
CantEnableText = "Couldn't connect to your Logitech keyboard.\n" +
|
||||||
"The Visual C++ 2012 Redistributable could not be found, which is required.\n" +
|
"The Visual C++ 2012 Redistributable v11.0.61030.0 could not be found, which is required.\n" +
|
||||||
"Please download it by going to the following URL:\n\n" +
|
"Please download it by going to the following URL (link also in wiki):\n\n" +
|
||||||
"https://www.microsoft.com/download/confirmation.aspx?id=30679";
|
"https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe";
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +0,0 @@
|
|||||||
using System.Windows.Media;
|
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua.Brushes
|
|
||||||
{
|
|
||||||
public interface ILuaBrush
|
|
||||||
{
|
|
||||||
Brush Brush { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
13
Artemis/Artemis/Profiles/Lua/Brushes/LuaBrush.cs
Normal file
13
Artemis/Artemis/Profiles/Lua/Brushes/LuaBrush.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System.Windows.Media;
|
||||||
|
using MoonSharp.Interpreter;
|
||||||
|
using MoonSharp.Interpreter.Interop;
|
||||||
|
|
||||||
|
namespace Artemis.Profiles.Lua.Brushes
|
||||||
|
{
|
||||||
|
[MoonSharpUserData]
|
||||||
|
public abstract class LuaBrush
|
||||||
|
{
|
||||||
|
[MoonSharpVisible(false)]
|
||||||
|
public Brush Brush { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,25 +1,105 @@
|
|||||||
using System.Windows.Media;
|
using System.Linq;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using Artemis.Utilities;
|
||||||
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 : ILuaBrush
|
public class LuaLinearGradientBrush : LuaBrush
|
||||||
{
|
{
|
||||||
// ReSharper disable once SuggestBaseTypeForParameter
|
private readonly Script _script;
|
||||||
|
private LinearGradientBrush _brush;
|
||||||
|
|
||||||
public LuaLinearGradientBrush(LinearGradientBrush linearGradientBrush)
|
public LuaLinearGradientBrush(LinearGradientBrush linearGradientBrush)
|
||||||
{
|
{
|
||||||
Brush = linearGradientBrush;
|
Brush = linearGradientBrush;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupBrush()
|
public LuaLinearGradientBrush(Script script, Table gradientColors, double startX = 0.5, double startY = 0.0,
|
||||||
|
double endX = 0.5, double endY = 1.0)
|
||||||
{
|
{
|
||||||
// TODO: Convert array of hex code and offset to gradient stop collection
|
_script = script;
|
||||||
var gradientStop = new GradientStop();
|
SetupBrush(gradientColors, startX, startY, endX, endY);
|
||||||
var collection = new GradientStopCollection();
|
|
||||||
Brush = new LinearGradientBrush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Brush Brush { get; set; }
|
/// <summary>
|
||||||
|
/// The underlying brush
|
||||||
|
/// </summary>
|
||||||
|
[MoonSharpVisible(false)]
|
||||||
|
public new LinearGradientBrush Brush
|
||||||
|
{
|
||||||
|
get { return _brush; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_brush = value;
|
||||||
|
_brush.Freeze();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the Brush's GradientStops using a LUA table
|
||||||
|
/// </summary>
|
||||||
|
public Table Colors
|
||||||
|
{
|
||||||
|
get { return CreateGradientTable(); }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
var updatedBrush = Brush.CloneCurrentValue();
|
||||||
|
updatedBrush.GradientStops = CreateGradientCollection(value);
|
||||||
|
Brush = updatedBrush;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures the brush according to the provided values usable in LUA
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gradientColors"></param>
|
||||||
|
/// <param name="startX"></param>
|
||||||
|
/// <param name="startY"></param>
|
||||||
|
/// <param name="endX"></param>
|
||||||
|
/// <param name="endY"></param>
|
||||||
|
private void SetupBrush(Table gradientColors, double startX, double startY, double endX, double endY)
|
||||||
|
{
|
||||||
|
var collection = CreateGradientCollection(gradientColors);
|
||||||
|
Brush = new LinearGradientBrush(collection, new Point(startX, startY), new Point(endX, endY));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maps a LUA table to a GradientStopsCollection
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gradientColors"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private GradientStopCollection CreateGradientCollection(Table gradientColors)
|
||||||
|
{
|
||||||
|
var collection = new GradientStopCollection();
|
||||||
|
foreach (var gradientColor in gradientColors.Values)
|
||||||
|
{
|
||||||
|
var pair = gradientColor.Table.Values.ToList();
|
||||||
|
var hexCode = pair[0].String;
|
||||||
|
var position = pair[1].Number;
|
||||||
|
collection.Add(new GradientStop(new Color().FromHex(hexCode), position));
|
||||||
|
}
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maps the current brush's GradientStopsCollection to a LUA table
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private Table CreateGradientTable()
|
||||||
|
{
|
||||||
|
var table = new Table(_script);
|
||||||
|
foreach (var gradientStop in Brush.GradientStops)
|
||||||
|
{
|
||||||
|
var inner = new Table(_script);
|
||||||
|
inner.Append(DynValue.NewString(gradientStop.Color.ToHex()));
|
||||||
|
inner.Append(DynValue.NewNumber(gradientStop.Offset));
|
||||||
|
table.Append(DynValue.NewTable(inner));
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,17 +1,34 @@
|
|||||||
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 : ILuaBrush
|
public class LuaRadialGradientBrush : LuaBrush
|
||||||
{
|
{
|
||||||
// ReSharper disable once SuggestBaseTypeForParameter
|
private RadialGradientBrush _brush;
|
||||||
|
|
||||||
public LuaRadialGradientBrush(RadialGradientBrush radialGradientBrush)
|
public LuaRadialGradientBrush(RadialGradientBrush radialGradientBrush)
|
||||||
{
|
{
|
||||||
Brush = radialGradientBrush;
|
Brush = radialGradientBrush;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Brush Brush { get; set; }
|
[MoonSharpVisible(false)]
|
||||||
|
public new RadialGradientBrush Brush
|
||||||
|
{
|
||||||
|
get { return _brush; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_brush = value;
|
||||||
|
_brush.Freeze();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Table Colors
|
||||||
|
{
|
||||||
|
get { throw new System.NotImplementedException(); }
|
||||||
|
set { throw new System.NotImplementedException(); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,13 +1,15 @@
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using Artemis.Utilities;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
using MoonSharp.Interpreter.Interop;
|
using MoonSharp.Interpreter.Interop;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua.Brushes
|
namespace Artemis.Profiles.Lua.Brushes
|
||||||
{
|
{
|
||||||
[MoonSharpUserData]
|
[MoonSharpUserData]
|
||||||
public class LuaSolidColorBrush : ILuaBrush
|
public class LuaSolidColorBrush : LuaBrush
|
||||||
{
|
{
|
||||||
// ReSharper disable once SuggestBaseTypeForParameter
|
private SolidColorBrush _brush;
|
||||||
|
|
||||||
public LuaSolidColorBrush(SolidColorBrush solidColorBrush)
|
public LuaSolidColorBrush(SolidColorBrush solidColorBrush)
|
||||||
{
|
{
|
||||||
Brush = solidColorBrush;
|
Brush = solidColorBrush;
|
||||||
@ -15,35 +17,30 @@ namespace Artemis.Profiles.Lua.Brushes
|
|||||||
|
|
||||||
public LuaSolidColorBrush(string hexCode)
|
public LuaSolidColorBrush(string hexCode)
|
||||||
{
|
{
|
||||||
SetupBrush(hexCode);
|
Brush = new SolidColorBrush(new Color().FromHex(hexCode));
|
||||||
}
|
|
||||||
|
|
||||||
public string HexCode
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var c = ((SolidColorBrush) Brush).Color;
|
|
||||||
return "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
|
|
||||||
}
|
|
||||||
set { SetupBrush(value); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The underlying brush
|
||||||
|
/// </summary>
|
||||||
[MoonSharpVisible(false)]
|
[MoonSharpVisible(false)]
|
||||||
public Brush Brush { get; set; }
|
public new SolidColorBrush Brush
|
||||||
|
|
||||||
private void SetupBrush(string hexCode)
|
|
||||||
{
|
{
|
||||||
var convertFromString = ColorConverter.ConvertFromString(hexCode);
|
get { return _brush; }
|
||||||
if (convertFromString != null)
|
set
|
||||||
{
|
{
|
||||||
var col = (Color) convertFromString;
|
_brush = value;
|
||||||
Brush = new SolidColorBrush(col);
|
_brush.Freeze();
|
||||||
Brush.Freeze();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Brush = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the brush's color using a hex notation
|
||||||
|
/// </summary>
|
||||||
|
public string Color
|
||||||
|
{
|
||||||
|
get { return Brush.Color.ToHex(); }
|
||||||
|
set { Brush = new SolidColorBrush(new Color().FromHex(value)); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using Artemis.Profiles.Lua.Brushes;
|
using System.Windows.Media;
|
||||||
|
using Artemis.Profiles.Lua.Brushes;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua
|
namespace Artemis.Profiles.Lua
|
||||||
@ -6,17 +7,25 @@ namespace Artemis.Profiles.Lua
|
|||||||
[MoonSharpUserData]
|
[MoonSharpUserData]
|
||||||
public class LuaBrushWrapper
|
public class LuaBrushWrapper
|
||||||
{
|
{
|
||||||
public static LuaSolidColorBrush GetSolidColorBrush(string hexCode)
|
private readonly Script _script;
|
||||||
|
|
||||||
|
public LuaBrushWrapper(Script script)
|
||||||
{
|
{
|
||||||
return new LuaSolidColorBrush(hexCode);
|
_script = script;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LuaSolidColorBrush GetLinearGradientBrush(string hexCode)
|
public LuaRadialGradientBrush GetSolidColorBrush(string hexCode)
|
||||||
{
|
{
|
||||||
return new LuaSolidColorBrush(hexCode);
|
return new LuaRadialGradientBrush(new RadialGradientBrush());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LuaSolidColorBrush GetRadialGradientBrush(string hexCode)
|
public LuaLinearGradientBrush GetLinearGradientBrush(Table gradientColors,
|
||||||
|
double startX = 0.5, double startY = 0.0, double endX = 0.5, double endY = 1.0)
|
||||||
|
{
|
||||||
|
return new LuaLinearGradientBrush(_script, gradientColors, startX, startY, endX, endY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LuaSolidColorBrush GetRadialGradientBrush(string hexCode)
|
||||||
{
|
{
|
||||||
return new LuaSolidColorBrush(hexCode);
|
return new LuaSolidColorBrush(hexCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ namespace Artemis.Profiles.Lua
|
|||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawCircle(ILuaBrush luaBrush, double x, double y, double height, double width)
|
public void DrawCircle(LuaBrush luaBrush, double x, double y, double height, double width)
|
||||||
{
|
{
|
||||||
var center = new Point(x + width/2, y + height/2);
|
var center = new Point(x + width/2, y + height/2);
|
||||||
_ctx.DrawEllipse(luaBrush.Brush, new Pen(), center, width, height);
|
_ctx.DrawEllipse(luaBrush.Brush, new Pen(), center, width, height);
|
||||||
|
|||||||
@ -17,7 +17,7 @@ namespace Artemis.Profiles.Lua
|
|||||||
{
|
{
|
||||||
ProfileModel = profileModel;
|
ProfileModel = profileModel;
|
||||||
LuaProfileWrapper = new LuaProfileWrapper(ProfileModel);
|
LuaProfileWrapper = new LuaProfileWrapper(ProfileModel);
|
||||||
LuaBrushWrapper = new LuaBrushWrapper();
|
LuaBrushWrapper = new LuaBrushWrapper(LuaScript);
|
||||||
SetupLuaScript();
|
SetupLuaScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Brush = System.Windows.Media.Brush;
|
using Brush = System.Windows.Media.Brush;
|
||||||
using Color = System.Drawing.Color;
|
using Color = System.Drawing.Color;
|
||||||
|
using ColorConverter = System.Windows.Media.ColorConverter;
|
||||||
|
|
||||||
namespace Artemis.Utilities
|
namespace Artemis.Utilities
|
||||||
{
|
{
|
||||||
@ -47,6 +48,20 @@ namespace Artemis.Utilities
|
|||||||
return returnColor;
|
return returnColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static System.Windows.Media.Color FromHex(this System.Windows.Media.Color c, string hex)
|
||||||
|
{
|
||||||
|
var convertFromString = ColorConverter.ConvertFromString(hex);
|
||||||
|
if (convertFromString != null)
|
||||||
|
return (System.Windows.Media.Color) convertFromString;
|
||||||
|
|
||||||
|
throw new ArgumentException("Invalid hex color code");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ToHex(this System.Windows.Media.Color c)
|
||||||
|
{
|
||||||
|
return "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
|
||||||
|
}
|
||||||
|
|
||||||
public static Color ShiftColor(Color c, int shiftAmount)
|
public static Color ShiftColor(Color c, int shiftAmount)
|
||||||
{
|
{
|
||||||
int newRed = c.R;
|
int newRed = c.R;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user