diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj
index 68945023b..6654080aa 100644
--- a/Artemis/Artemis/Artemis.csproj
+++ b/Artemis/Artemis/Artemis.csproj
@@ -414,7 +414,7 @@
-
+
diff --git a/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs b/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs
index ac6a96f0d..a4f65af0b 100644
--- a/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs
+++ b/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs
@@ -16,9 +16,9 @@ namespace Artemis.DeviceProviders.Logitech
@"SOFTWARE\Classes\Installer\Dependencies\{ca67548a-5ebe-413a-b50c-4b9ceb6d66c6}") == null)
{
CantEnableText = "Couldn't connect to your Logitech keyboard.\n" +
- "The Visual C++ 2012 Redistributable could not be found, which is required.\n" +
- "Please download it by going to the following URL:\n\n" +
- "https://www.microsoft.com/download/confirmation.aspx?id=30679";
+ "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 (link also in wiki):\n\n" +
+ "https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe";
return false;
}
diff --git a/Artemis/Artemis/Profiles/Lua/Brushes/ILuaBrush.cs b/Artemis/Artemis/Profiles/Lua/Brushes/ILuaBrush.cs
deleted file mode 100644
index 58b78b300..000000000
--- a/Artemis/Artemis/Profiles/Lua/Brushes/ILuaBrush.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System.Windows.Media;
-
-namespace Artemis.Profiles.Lua.Brushes
-{
- public interface ILuaBrush
- {
- Brush Brush { get; set; }
- }
-}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Lua/Brushes/LuaBrush.cs b/Artemis/Artemis/Profiles/Lua/Brushes/LuaBrush.cs
new file mode 100644
index 000000000..f8b5273db
--- /dev/null
+++ b/Artemis/Artemis/Profiles/Lua/Brushes/LuaBrush.cs
@@ -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; }
+ }
+}
\ 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 01c9819e3..3c934e165 100644
--- a/Artemis/Artemis/Profiles/Lua/Brushes/LuaLinearGradientBrush.cs
+++ b/Artemis/Artemis/Profiles/Lua/Brushes/LuaLinearGradientBrush.cs
@@ -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.Interop;
namespace Artemis.Profiles.Lua.Brushes
{
[MoonSharpUserData]
- public class LuaLinearGradientBrush : ILuaBrush
+ public class LuaLinearGradientBrush : LuaBrush
{
- // ReSharper disable once SuggestBaseTypeForParameter
+ private readonly Script _script;
+ private LinearGradientBrush _brush;
+
public LuaLinearGradientBrush(LinearGradientBrush 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
- var gradientStop = new GradientStop();
- var collection = new GradientStopCollection();
- Brush = new LinearGradientBrush();
+ _script = script;
+ SetupBrush(gradientColors, startX, startY, endX, endY);
}
- public Brush Brush { get; set; }
+ ///
+ /// The underlying brush
+ ///
+ [MoonSharpVisible(false)]
+ public new LinearGradientBrush Brush
+ {
+ get { return _brush; }
+ set
+ {
+ _brush = value;
+ _brush.Freeze();
+ }
+ }
+
+ ///
+ /// Gets or sets the Brush's GradientStops using a LUA table
+ ///
+ public Table Colors
+ {
+ get { return CreateGradientTable(); }
+ set
+ {
+ var updatedBrush = Brush.CloneCurrentValue();
+ updatedBrush.GradientStops = CreateGradientCollection(value);
+ Brush = updatedBrush;
+ }
+ }
+
+ ///
+ /// Configures the brush according to the provided values usable in LUA
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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));
+ }
+
+ ///
+ /// Maps a LUA table to a GradientStopsCollection
+ ///
+ ///
+ ///
+ 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;
+ }
+
+ ///
+ /// Maps the current brush's GradientStopsCollection to a LUA table
+ ///
+ ///
+ 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;
+ }
}
}
\ 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 4850362f5..7e692e73f 100644
--- a/Artemis/Artemis/Profiles/Lua/Brushes/LuaRadialGradientBrush.cs
+++ b/Artemis/Artemis/Profiles/Lua/Brushes/LuaRadialGradientBrush.cs
@@ -1,17 +1,34 @@
using System.Windows.Media;
using MoonSharp.Interpreter;
+using MoonSharp.Interpreter.Interop;
namespace Artemis.Profiles.Lua.Brushes
{
[MoonSharpUserData]
- public class LuaRadialGradientBrush : ILuaBrush
+ public class LuaRadialGradientBrush : LuaBrush
{
- // ReSharper disable once SuggestBaseTypeForParameter
+ private RadialGradientBrush _brush;
+
public LuaRadialGradientBrush(RadialGradientBrush 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(); }
+ }
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs b/Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs
index c9179fcc9..022859610 100644
--- a/Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs
+++ b/Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs
@@ -1,13 +1,15 @@
using System.Windows.Media;
+using Artemis.Utilities;
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
namespace Artemis.Profiles.Lua.Brushes
{
[MoonSharpUserData]
- public class LuaSolidColorBrush : ILuaBrush
+ public class LuaSolidColorBrush : LuaBrush
{
- // ReSharper disable once SuggestBaseTypeForParameter
+ private SolidColorBrush _brush;
+
public LuaSolidColorBrush(SolidColorBrush solidColorBrush)
{
Brush = solidColorBrush;
@@ -15,35 +17,30 @@ namespace Artemis.Profiles.Lua.Brushes
public LuaSolidColorBrush(string hexCode)
{
- SetupBrush(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); }
+ Brush = new SolidColorBrush(new Color().FromHex(hexCode));
}
+ ///
+ /// The underlying brush
+ ///
[MoonSharpVisible(false)]
- public Brush Brush { get; set; }
-
- private void SetupBrush(string hexCode)
+ public new SolidColorBrush Brush
{
- var convertFromString = ColorConverter.ConvertFromString(hexCode);
- if (convertFromString != null)
+ get { return _brush; }
+ set
{
- var col = (Color) convertFromString;
- Brush = new SolidColorBrush(col);
- Brush.Freeze();
- }
- else
- {
- Brush = null;
+ _brush = value;
+ _brush.Freeze();
}
}
+
+ ///
+ /// Gets or sets the brush's color using a hex notation
+ ///
+ public string Color
+ {
+ get { return Brush.Color.ToHex(); }
+ set { Brush = new SolidColorBrush(new Color().FromHex(value)); }
+ }
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Lua/LuaBrushWrapper.cs b/Artemis/Artemis/Profiles/Lua/LuaBrushWrapper.cs
index 032da035b..5dcdcba8c 100644
--- a/Artemis/Artemis/Profiles/Lua/LuaBrushWrapper.cs
+++ b/Artemis/Artemis/Profiles/Lua/LuaBrushWrapper.cs
@@ -1,4 +1,5 @@
-using Artemis.Profiles.Lua.Brushes;
+using System.Windows.Media;
+using Artemis.Profiles.Lua.Brushes;
using MoonSharp.Interpreter;
namespace Artemis.Profiles.Lua
@@ -6,17 +7,25 @@ namespace Artemis.Profiles.Lua
[MoonSharpUserData]
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);
}
diff --git a/Artemis/Artemis/Profiles/Lua/LuaDrawWrapper.cs b/Artemis/Artemis/Profiles/Lua/LuaDrawWrapper.cs
index a49d6c6c1..e7a6327e8 100644
--- a/Artemis/Artemis/Profiles/Lua/LuaDrawWrapper.cs
+++ b/Artemis/Artemis/Profiles/Lua/LuaDrawWrapper.cs
@@ -17,7 +17,7 @@ namespace Artemis.Profiles.Lua
_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);
_ctx.DrawEllipse(luaBrush.Brush, new Pen(), center, width, height);
diff --git a/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs b/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs
index a7a09aa4a..54a894599 100644
--- a/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs
+++ b/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs
@@ -17,7 +17,7 @@ namespace Artemis.Profiles.Lua
{
ProfileModel = profileModel;
LuaProfileWrapper = new LuaProfileWrapper(ProfileModel);
- LuaBrushWrapper = new LuaBrushWrapper();
+ LuaBrushWrapper = new LuaBrushWrapper(LuaScript);
SetupLuaScript();
}
diff --git a/Artemis/Artemis/Utilities/ColorHelpers.cs b/Artemis/Artemis/Utilities/ColorHelpers.cs
index a6adeaf35..812fac2bd 100644
--- a/Artemis/Artemis/Utilities/ColorHelpers.cs
+++ b/Artemis/Artemis/Utilities/ColorHelpers.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Windows.Media;
using Brush = System.Windows.Media.Brush;
using Color = System.Drawing.Color;
+using ColorConverter = System.Windows.Media.ColorConverter;
namespace Artemis.Utilities
{
@@ -47,6 +48,20 @@ namespace Artemis.Utilities
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)
{
int newRed = c.R;