BizHawk/BizHawk.Client.EmuHawk/tools/Lua/LuaWinform.cs

63 lines
1.3 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Windows.Forms;
2017-05-19 16:05:21 +00:00
using LuaInterface;
2017-05-19 16:05:21 +00:00
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public partial class LuaWinform : Form
{
2017-05-19 16:05:21 +00:00
public List<LuaEvent> ControlEvents { get; } = new List<LuaEvent>();
2017-05-19 16:05:21 +00:00
private readonly string _currentDirectory = Environment.CurrentDirectory;
private readonly Lua _ownerThread;
public LuaWinform(Lua ownerThread)
{
InitializeComponent();
2017-05-19 16:05:21 +00:00
_ownerThread = ownerThread;
StartPosition = FormStartPosition.CenterParent;
Closing += (o, e) => CloseThis();
}
private void LuaWinform_Load(object sender, EventArgs e)
{
}
2017-05-19 16:05:21 +00:00
private void CloseThis()
{
GlobalWin.Tools.LuaConsole.LuaImp.WindowClosed(Handle);
}
public void DoLuaEvent(IntPtr handle)
{
2017-05-19 16:05:21 +00:00
LuaSandbox.Sandbox(_ownerThread, () =>
{
2017-05-19 16:05:21 +00:00
Environment.CurrentDirectory = _currentDirectory;
foreach (LuaEvent luaEvent in ControlEvents)
{
2017-05-19 16:05:21 +00:00
if (luaEvent.Control == handle)
{
2017-05-19 16:05:21 +00:00
luaEvent.Event.Call();
}
}
});
}
public class LuaEvent
{
public LuaEvent(IntPtr handle, LuaFunction lfunction)
{
Event = lfunction;
Control = handle;
}
2017-05-19 16:05:21 +00:00
public LuaFunction Event { get; }
public IntPtr Control { get; }
}
}
}