2012-07-10 19:04:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
2017-05-19 16:05:21 +00:00
|
|
|
|
|
2012-07-10 19:04:35 +00:00
|
|
|
|
using LuaInterface;
|
|
|
|
|
|
2017-05-19 16:05:21 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2012-07-10 19:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class LuaWinform : Form
|
|
|
|
|
{
|
2017-05-19 16:05:21 +00:00
|
|
|
|
public List<LuaEvent> ControlEvents { get; } = new List<LuaEvent>();
|
2012-07-10 19:04:35 +00:00
|
|
|
|
|
2017-05-19 16:05:21 +00:00
|
|
|
|
private readonly string _currentDirectory = Environment.CurrentDirectory;
|
|
|
|
|
private readonly Lua _ownerThread;
|
2016-02-01 01:54:48 +00:00
|
|
|
|
|
|
|
|
|
public LuaWinform(Lua ownerThread)
|
2012-07-10 19:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2017-05-19 16:05:21 +00:00
|
|
|
|
_ownerThread = ownerThread;
|
2014-05-22 01:03:18 +00:00
|
|
|
|
StartPosition = FormStartPosition.CenterParent;
|
2012-07-10 19:04:35 +00:00
|
|
|
|
Closing += (o, e) => CloseThis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LuaWinform_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 16:05:21 +00:00
|
|
|
|
private void CloseThis()
|
2012-07-10 19:04:35 +00:00
|
|
|
|
{
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.Tools.LuaConsole.LuaImp.WindowClosed(Handle);
|
2012-07-10 19:04:35 +00:00
|
|
|
|
}
|
2012-07-10 20:23:19 +00:00
|
|
|
|
|
|
|
|
|
public void DoLuaEvent(IntPtr handle)
|
|
|
|
|
{
|
2017-05-19 16:05:21 +00:00
|
|
|
|
LuaSandbox.Sandbox(_ownerThread, () =>
|
2012-07-10 20:23:19 +00:00
|
|
|
|
{
|
2017-05-19 16:05:21 +00:00
|
|
|
|
Environment.CurrentDirectory = _currentDirectory;
|
|
|
|
|
foreach (LuaEvent luaEvent in ControlEvents)
|
2012-07-10 20:23:19 +00:00
|
|
|
|
{
|
2017-05-19 16:05:21 +00:00
|
|
|
|
if (luaEvent.Control == handle)
|
2015-07-02 00:17:15 +00:00
|
|
|
|
{
|
2017-05-19 16:05:21 +00:00
|
|
|
|
luaEvent.Event.Call();
|
2015-07-02 00:17:15 +00:00
|
|
|
|
}
|
2012-07-10 20:23:19 +00:00
|
|
|
|
}
|
2015-07-02 00:17:15 +00:00
|
|
|
|
});
|
2012-07-10 20:23:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-17 15:55:13 +00:00
|
|
|
|
public class LuaEvent
|
2012-07-10 20:23:19 +00:00
|
|
|
|
{
|
2013-11-17 15:55:13 +00:00
|
|
|
|
public LuaEvent(IntPtr handle, LuaFunction lfunction)
|
2012-07-10 20:23:19 +00:00
|
|
|
|
{
|
|
|
|
|
Event = lfunction;
|
|
|
|
|
Control = handle;
|
|
|
|
|
}
|
2017-05-19 16:05:21 +00:00
|
|
|
|
|
|
|
|
|
public LuaFunction Event { get; }
|
|
|
|
|
public IntPtr Control { get; }
|
2012-07-10 20:23:19 +00:00
|
|
|
|
}
|
2012-07-10 19:04:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|