mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-01 10:13:30 +00:00
WIP on LUA wrappers refactor
This commit is contained in:
parent
876e1d81d7
commit
f1714c1262
@ -512,13 +512,15 @@
|
|||||||
<Compile Include="Profiles\Lua\Events\LuaDeviceDrawingEventArgs.cs" />
|
<Compile Include="Profiles\Lua\Events\LuaDeviceDrawingEventArgs.cs" />
|
||||||
<Compile Include="Profiles\Lua\Events\LuaDeviceUpdatingEventArgs.cs" />
|
<Compile Include="Profiles\Lua\Events\LuaDeviceUpdatingEventArgs.cs" />
|
||||||
<Compile Include="Profiles\Lua\Brushes\LuaBrushWrapper.cs" />
|
<Compile Include="Profiles\Lua\Brushes\LuaBrushWrapper.cs" />
|
||||||
<Compile Include="Profiles\Lua\LuaDrawWrapper.cs" />
|
<Compile Include="Profiles\Lua\Modules\ILuaModule.cs" />
|
||||||
<Compile Include="Profiles\Lua\Events\LuaEventsWrapper.cs" />
|
<Compile Include="Profiles\Lua\Events\LuaEventsWrapper.cs" />
|
||||||
<Compile Include="Profiles\Lua\LuaKeyboardWrapper.cs" />
|
<Compile Include="Profiles\Lua\LuaKeyboardWrapper.cs" />
|
||||||
<Compile Include="Profiles\Lua\LuaLayerWrapper.cs" />
|
<Compile Include="Profiles\Lua\LuaLayerWrapper.cs" />
|
||||||
<Compile Include="Profiles\Lua\LuaProfileWrapper.cs" />
|
<Compile Include="Profiles\Lua\LuaProfileWrapper.cs" />
|
||||||
<Compile Include="Profiles\Lua\Brushes\LuaSolidColorBrush.cs" />
|
<Compile Include="Profiles\Lua\Brushes\LuaSolidColorBrush.cs" />
|
||||||
<Compile Include="Profiles\Lua\LuaWrapper.cs" />
|
<Compile Include="Profiles\Lua\LuaWrapper.cs" />
|
||||||
|
<Compile Include="Profiles\Lua\Modules\LuaDrawModule.cs" />
|
||||||
|
<Compile Include="Profiles\Lua\Modules\LuaKeyboardModule.cs" />
|
||||||
<Compile Include="Profiles\ProfileModel.cs" />
|
<Compile Include="Profiles\ProfileModel.cs" />
|
||||||
<Compile Include="Profiles\Layers\Models\SimplePropertiesModel.cs" />
|
<Compile Include="Profiles\Layers\Models\SimplePropertiesModel.cs" />
|
||||||
<Compile Include="Profiles\Layers\Types\Keyboard\KeyboardPropertiesModel.cs" />
|
<Compile Include="Profiles\Layers\Types\Keyboard\KeyboardPropertiesModel.cs" />
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Artemis.Models.Interfaces;
|
using Artemis.Models.Interfaces;
|
||||||
|
using Artemis.Profiles.Lua.Modules;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua.Events
|
namespace Artemis.Profiles.Lua.Events
|
||||||
@ -7,7 +8,7 @@ namespace Artemis.Profiles.Lua.Events
|
|||||||
[MoonSharpUserData]
|
[MoonSharpUserData]
|
||||||
public class LuaDeviceDrawingEventArgs : EventArgs
|
public class LuaDeviceDrawingEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public LuaDeviceDrawingEventArgs(string deviceType, IDataModel dataModel, bool preview, LuaDrawWrapper luaDrawWrapper)
|
public LuaDeviceDrawingEventArgs(string deviceType, IDataModel dataModel, bool preview, LuaDrawModule luaDrawWrapper)
|
||||||
{
|
{
|
||||||
DeviceType = deviceType;
|
DeviceType = deviceType;
|
||||||
DataModel = dataModel;
|
DataModel = dataModel;
|
||||||
@ -18,6 +19,6 @@ namespace Artemis.Profiles.Lua.Events
|
|||||||
public string DeviceType { get; set; }
|
public string DeviceType { get; set; }
|
||||||
public IDataModel DataModel { get; }
|
public IDataModel DataModel { get; }
|
||||||
public bool Preview { get; }
|
public bool Preview { get; }
|
||||||
public LuaDrawWrapper Drawing { get; set; }
|
public LuaDrawModule Drawing { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,6 +2,7 @@
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Artemis.Models.Interfaces;
|
using Artemis.Models.Interfaces;
|
||||||
|
using Artemis.Profiles.Lua.Modules;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ namespace Artemis.Profiles.Lua.Events
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
LuaInvoke(profileModel, () => OnDeviceDrawing(new LuaProfileWrapper(profileModel),
|
LuaInvoke(profileModel, () => OnDeviceDrawing(new LuaProfileWrapper(profileModel),
|
||||||
new LuaDeviceDrawingEventArgs(deviceType, dataModel, preview, new LuaDrawWrapper(c))));
|
new LuaDeviceDrawingEventArgs(deviceType, dataModel, preview, new LuaDrawModule(c))));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -42,5 +42,10 @@ namespace Artemis.Profiles.Lua
|
|||||||
{
|
{
|
||||||
SendKeys.SendWait(keys);
|
SendKeys.SendWait(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void GetKeyPosition(Keys key)
|
||||||
|
{
|
||||||
|
_keyboardProvider.GetKeyPosition(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,15 +78,6 @@ namespace Artemis.Profiles.Lua
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Private lua functions
|
|
||||||
|
|
||||||
private static void LuaPrint(string s)
|
|
||||||
{
|
|
||||||
Logger.Debug("[{0}-LUA]: {1}", ProfileModel?.Name, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public static void Clear()
|
public static void Clear()
|
||||||
{
|
{
|
||||||
lock (LuaScript)
|
lock (LuaScript)
|
||||||
@ -137,6 +128,15 @@ namespace Artemis.Profiles.Lua
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Private lua functions
|
||||||
|
|
||||||
|
private static void LuaPrint(string s)
|
||||||
|
{
|
||||||
|
Logger.Debug("[{0}-LUA]: {1}", ProfileModel?.Name, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Editor
|
#region Editor
|
||||||
|
|
||||||
public static void OpenEditor()
|
public static void OpenEditor()
|
||||||
|
|||||||
10
Artemis/Artemis/Profiles/Lua/Modules/ILuaModule.cs
Normal file
10
Artemis/Artemis/Profiles/Lua/Modules/ILuaModule.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Artemis.Profiles.Lua.Modules
|
||||||
|
{
|
||||||
|
public interface ILuaModule : IDisposable
|
||||||
|
{
|
||||||
|
bool AlwaysPresent { get; }
|
||||||
|
string ModuleName { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,26 +1,31 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing.Text;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
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.Modules
|
||||||
{
|
{
|
||||||
[MoonSharpUserData]
|
[MoonSharpUserData]
|
||||||
public class LuaDrawWrapper
|
public class LuaDrawModule : ILuaModule
|
||||||
{
|
{
|
||||||
private readonly DrawingContext _ctx;
|
private readonly DrawingContext _ctx;
|
||||||
private FontFamily _font;
|
private readonly FontFamily _font;
|
||||||
|
|
||||||
public LuaDrawWrapper(DrawingContext ctx)
|
public LuaDrawModule(DrawingContext ctx)
|
||||||
{
|
{
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_font = new FontFamily(new Uri("pack://application:,,,/"), "./resources/#Silkscreen");
|
_font = new FontFamily(new Uri("pack://application:,,,/"), "./resources/#Silkscreen");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool AlwaysPresent => false;
|
||||||
|
public string ModuleName => null;
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawEllipse(LuaBrush luaBrush, double x, double y, double height, double width)
|
public void DrawEllipse(LuaBrush luaBrush, double x, double y, double height, double width)
|
||||||
{
|
{
|
||||||
x *= 4;
|
x *= 4;
|
||||||
55
Artemis/Artemis/Profiles/Lua/Modules/LuaKeyboardModule.cs
Normal file
55
Artemis/Artemis/Profiles/Lua/Modules/LuaKeyboardModule.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Artemis.DeviceProviders;
|
||||||
|
using MoonSharp.Interpreter.Interop;
|
||||||
|
|
||||||
|
namespace Artemis.Profiles.Lua.Modules
|
||||||
|
{
|
||||||
|
public class LuaKeyboardModule : ILuaModule
|
||||||
|
{
|
||||||
|
public bool AlwaysPresent => true;
|
||||||
|
public string ModuleName => "Keyboard";
|
||||||
|
|
||||||
|
private readonly KeyboardProvider _keyboardProvider;
|
||||||
|
|
||||||
|
public LuaKeyboardModule(KeyboardProvider keyboardProvider)
|
||||||
|
{
|
||||||
|
_keyboardProvider = keyboardProvider;
|
||||||
|
|
||||||
|
KeyboardHook.KeyDownCallback += KeyboardHookOnKeyDownCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name => _keyboardProvider.Name;
|
||||||
|
public string Slug => _keyboardProvider.Slug;
|
||||||
|
public int Width => _keyboardProvider.Width;
|
||||||
|
public int Height => _keyboardProvider.Height;
|
||||||
|
|
||||||
|
[MoonSharpVisible(false)]
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
KeyboardHook.KeyDownCallback -= KeyboardHookOnKeyDownCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void KeyboardHookOnKeyDownCallback(KeyEventArgs e)
|
||||||
|
{
|
||||||
|
var keyMatch = _keyboardProvider.GetKeyPosition(e.KeyCode);
|
||||||
|
if (keyMatch != null)
|
||||||
|
LuaWrapper.LuaEventsWrapper.InvokeKeyPressed(LuaWrapper.ProfileModel, this, keyMatch.Value.KeyCode,
|
||||||
|
keyMatch.Value.X, keyMatch.Value.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PressKeys(string keys)
|
||||||
|
{
|
||||||
|
SendKeys.SendWait(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GetKeyPosition(Keys key)
|
||||||
|
{
|
||||||
|
_keyboardProvider.GetKeyPosition(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user