forms library made into its own object

This commit is contained in:
adelikat 2013-10-31 16:45:08 +00:00
parent 21a21ac7b7
commit 092b87e267
2 changed files with 53 additions and 63 deletions

View File

@ -8,8 +8,34 @@ using LuaInterface;
namespace BizHawk.MultiClient
{
public partial class EmuLuaLibrary
public partial class FormsLuaLibrary : LuaLibraryBase
{
public override string Name { get { return "forms"; } }
public override string[] Functions
{
get
{
return new[]
{
"addclick",
"button",
"clearclicks",
"destroy",
"destroyall",
"getproperty",
"gettext",
"label",
"newform",
"openfile",
"setlocation",
"setproperty",
"setsize",
"settext",
"textbox",
};
}
}
#region Forms Library Helpers
private readonly List<LuaWinform> LuaForms = new List<LuaWinform>();
@ -38,15 +64,10 @@ namespace BizHawk.MultiClient
{
if (X != null && Y != null)
{
int x = LuaCommon.LuaInt(X);
int y = LuaCommon.LuaInt(Y);
control.Location = new Point(x, y);
control.Location = new Point(LuaInt(X), LuaInt(Y));
}
}
catch
{
//Do nothing
}
catch { /*Do nothing*/ }
}
private void SetSize(Control control, object Width, object Height)
@ -55,15 +76,10 @@ namespace BizHawk.MultiClient
{
if (Width != null && Height != null)
{
int width = LuaCommon.LuaInt(Width);
int height = LuaCommon.LuaInt(Height);
control.Size = new Size(width, height);
control.Size = new Size(LuaInt(Width), LuaInt(Height));
}
}
catch
{
//Do nothing
}
catch { /*Do nothing*/ }
}
private void SetText(Control control, object caption)
@ -104,11 +120,8 @@ namespace BizHawk.MultiClient
form.Controls.Add(button);
form.Control_Events.Add(new LuaWinform.Lua_Event(button.Handle, lua_event));
if (X != null && Y != null)
SetLocation(button, X, Y);
if (width != null & height != null)
SetSize(button, width, height);
SetLocation(button, X, Y);
SetSize(button, width, height);
return (int)button.Handle;
}
@ -229,11 +242,8 @@ namespace BizHawk.MultiClient
Label label = new Label();
SetText(label, caption);
form.Controls.Add(label);
if (X != null && Y != null)
SetLocation(label, X, Y);
if (width != null & height != null)
SetSize(label, width, height);
SetLocation(label, X, Y);
SetSize(label, width, height);
return (int)label.Handle;
}
@ -248,11 +258,7 @@ namespace BizHawk.MultiClient
theForm.Size = new Size(LuaCommon.LuaInt(Width), LuaCommon.LuaInt(Height));
}
if (title != null)
{
theForm.Text = title.ToString();
}
theForm.Text = (string)title;
theForm.Show();
return (int)theForm.Handle;
}
@ -265,19 +271,26 @@ namespace BizHawk.MultiClient
{
openFileDialog1.InitialDirectory = InitialDirectory;
}
if (FileName != null)
{
openFileDialog1.FileName = FileName;
}
if (Filter != null)
{
openFileDialog1.AddExtension = true;
openFileDialog1.Filter = Filter;
}
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
return openFileDialog1.FileName;
}
else
return "";
{
return String.Empty;
}
}
public void forms_setlocation(object handle, object X, object Y)
@ -378,12 +391,8 @@ namespace BizHawk.MultiClient
LuaTextBox textbox = new LuaTextBox();
SetText(textbox, caption);
if (X != null && Y != null)
SetLocation(textbox, X, Y);
if (width != null & height != null)
SetSize(textbox, width, height);
SetLocation(textbox, X, Y);
SetSize(textbox, width, height);
if (boxtype != null)
{

View File

@ -9,12 +9,18 @@ namespace BizHawk.MultiClient
private Lua _lua = new Lua();
private readonly LuaConsole _caller;
private Lua currThread;
private FormsLuaLibrary _formsLibrary = new FormsLuaLibrary();
public LuaDocumentation Docs = new LuaDocumentation();
public bool IsRunning;
public EventWaitHandle LuaWait;
public bool FrameAdvanceRequested;
public void WindowClosed(IntPtr handle)
{
_formsLibrary.WindowClosed(handle);
}
public EmuLuaLibrary(LuaConsole passed)
{
LuaWait = new AutoResetEvent(false);
@ -87,25 +93,6 @@ namespace BizHawk.MultiClient
"unregisterbyname",
};
public static string[] FormsFunctions = new[]
{
"addclick",
"button",
"clearclicks",
"destroy",
"destroyall",
"getproperty",
"gettext",
"label",
"newform",
"openfile",
"setlocation",
"setproperty",
"setsize",
"settext",
"textbox",
};
public void LuaRegister(Lua lua)
{
lua.RegisterFunction("print", this, GetType().GetMethod("print"));
@ -113,6 +100,7 @@ namespace BizHawk.MultiClient
new BitLuaLibrary().LuaRegister(lua, Docs);
new MultiClientLuaLibrary(ConsoleLuaLibrary.console_log).LuaRegister(lua, Docs);
new ConsoleLuaLibrary().LuaRegister(lua, Docs);
_formsLibrary.LuaRegister(lua, Docs);
new InputLuaLibrary(_lua).LuaRegister(lua, Docs);
new JoypadLuaLibrary(_lua).LuaRegister(lua, Docs);
new MemoryLuaLibrary().LuaRegister(lua, Docs);
@ -136,13 +124,6 @@ namespace BizHawk.MultiClient
Docs.Add("emu", t, GetType().GetMethod("emu_" + t));
}
lua.NewTable("forms");
foreach (string t in FormsFunctions)
{
lua.RegisterFunction("forms." + t, this, GetType().GetMethod("forms_" + t));
Docs.Add("forms", t, GetType().GetMethod("forms_" + t));
}
lua.NewTable("event");
foreach (string t in EventFunctions)
{