Lua - finish up refactoring remaining lua libraries
This commit is contained in:
parent
bce8320b85
commit
5f9757d7d0
|
@ -4,9 +4,9 @@ using BizHawk.Client.Common;
|
||||||
|
|
||||||
namespace BizHawk.Client.EmuHawk
|
namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
public class MultiClientLuaLibrary : LuaLibraryBase
|
public class EmuHawkLuaLibrary : LuaLibraryBase
|
||||||
{
|
{
|
||||||
private Dictionary<int, string> _filterMappings = new Dictionary<int,string>
|
private readonly Dictionary<int, string> _filterMappings = new Dictionary<int, string>
|
||||||
{
|
{
|
||||||
{ 0, "None" },
|
{ 0, "None" },
|
||||||
{ 1, "x2SAI" },
|
{ 1, "x2SAI" },
|
||||||
|
@ -15,13 +15,13 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{ 4, "Scanlines" },
|
{ 4, "Scanlines" },
|
||||||
};
|
};
|
||||||
|
|
||||||
public MultiClientLuaLibrary(Action<string> logOutputCallback)
|
public EmuHawkLuaLibrary(Action<string> logOutputCallback)
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
LogOutputCallback = logOutputCallback;
|
LogOutputCallback = logOutputCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiClientLuaLibrary() : base() { }
|
public EmuHawkLuaLibrary() { }
|
||||||
|
|
||||||
public override string Name { get { return "client"; } }
|
public override string Name { get { return "client"; } }
|
||||||
public override string[] Functions
|
public override string[] Functions
|
||||||
|
@ -68,42 +68,59 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action<string> LogOutputCallback = null;
|
public Action<string> LogOutputCallback { get; set; }
|
||||||
|
|
||||||
public void client_clearautohold()
|
private void Log(string message)
|
||||||
|
{
|
||||||
|
if (LogOutputCallback != null)
|
||||||
|
{
|
||||||
|
LogOutputCallback(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[LuaMethodAttributes(
|
||||||
|
"clearautohold",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void ClearAutohold()
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.ClearHolds();
|
GlobalWin.MainForm.ClearHolds();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_closerom()
|
[LuaMethodAttributes(
|
||||||
|
"closerom",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void CloseRom()
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.CloseRom();
|
GlobalWin.MainForm.CloseRom();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_enablerewind(object boolean)
|
[LuaMethodAttributes(
|
||||||
|
"enablerewind",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void EnableRewind(bool enabled)
|
||||||
{
|
{
|
||||||
string temp = boolean.ToString();
|
if (enabled)
|
||||||
if (!String.IsNullOrWhiteSpace(temp))
|
|
||||||
{
|
|
||||||
if (temp == "0" || temp.ToLower() == "false")
|
|
||||||
{
|
|
||||||
Global.Rewinder.RewindActive = false;
|
|
||||||
GlobalWin.OSD.AddMessage("Rewind suspended");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
Global.Rewinder.RewindActive = true;
|
Global.Rewinder.RewindActive = true;
|
||||||
GlobalWin.OSD.AddMessage("Rewind enabled");
|
GlobalWin.OSD.AddMessage("Rewind enabled");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Global.Rewinder.RewindActive = false;
|
||||||
|
GlobalWin.OSD.AddMessage("Rewind suspended");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void client_frameskip(object num_frames)
|
[LuaMethodAttributes(
|
||||||
|
"frameskip",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void FrameSkip(object numFrames)
|
||||||
{
|
{
|
||||||
try
|
var frames = LuaInt(numFrames);
|
||||||
{
|
|
||||||
string temp = num_frames.ToString();
|
|
||||||
int frames = Convert.ToInt32(temp);
|
|
||||||
if (frames > 0)
|
if (frames > 0)
|
||||||
{
|
{
|
||||||
Global.Config.FrameSkip = frames;
|
Global.Config.FrameSkip = frames;
|
||||||
|
@ -111,101 +128,168 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ConsoleLuaLibrary.console_log("Invalid frame skip value");
|
ConsoleLuaLibrary.Log("Invalid frame skip value");
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
ConsoleLuaLibrary.console_log("Invalid frame skip value");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string client_getdisplayfilter()
|
[LuaMethodAttributes(
|
||||||
|
"getdisplayfilter",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public string GetDisplayFilter()
|
||||||
{
|
{
|
||||||
return _filterMappings[Global.Config.TargetDisplayFilter];
|
return _filterMappings[Global.Config.TargetDisplayFilter];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int client_gettargetscanlineintensity()
|
[LuaMethodAttributes(
|
||||||
|
"gettargetscanlineintensity",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static int GetTargetScanlineIntensity()
|
||||||
{
|
{
|
||||||
return Global.Config.TargetScanlineFilterIntensity;
|
return Global.Config.TargetScanlineFilterIntensity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int client_getwindowsize()
|
[LuaMethodAttributes(
|
||||||
|
"getwindowsize",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static int GetWindowSize()
|
||||||
{
|
{
|
||||||
return Global.Config.TargetZoomFactor;
|
return Global.Config.TargetZoomFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool client_ispaused()
|
[LuaMethodAttributes(
|
||||||
|
"ispaused",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static bool IsPaused()
|
||||||
{
|
{
|
||||||
return GlobalWin.MainForm.EmulatorPaused;
|
return GlobalWin.MainForm.EmulatorPaused;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_opencheats()
|
[LuaMethodAttributes(
|
||||||
|
"opencheats",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void OpenCheats()
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.Load<Cheats>();
|
GlobalWin.Tools.Load<Cheats>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_openhexeditor()
|
[LuaMethodAttributes(
|
||||||
|
"openhexeditor",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void OpenHexEditor()
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.Load<HexEditor>();
|
GlobalWin.Tools.Load<HexEditor>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_openramwatch()
|
[LuaMethodAttributes(
|
||||||
|
"openramwatch",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void OpenRamWatch()
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.LoadRamWatch(true);
|
GlobalWin.Tools.LoadRamWatch(loadDialog: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_openramsearch()
|
[LuaMethodAttributes(
|
||||||
|
"openramsearch",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void OpenRamSearch()
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.Load<RamSearch>();
|
GlobalWin.Tools.Load<RamSearch>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_openrom(object lua_input)
|
[LuaMethodAttributes(
|
||||||
|
"openrom",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void OpenRom(string path)
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.LoadRom(lua_input.ToString());
|
GlobalWin.MainForm.LoadRom(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_opentasstudio()
|
[LuaMethodAttributes(
|
||||||
|
"opentasstudio",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void OpenTasStudio()
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.Load<TAStudio>();
|
GlobalWin.Tools.Load<TAStudio>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_opentoolbox()
|
[LuaMethodAttributes(
|
||||||
|
"opentoolbox",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void OpenToolBox()
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.Load<ToolBox>();
|
GlobalWin.Tools.Load<ToolBox>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_opentracelogger()
|
[LuaMethodAttributes(
|
||||||
|
"opentracelogger",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void OpenTraceLogger()
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.LoadTraceLogger();
|
GlobalWin.Tools.LoadTraceLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_paint()
|
[LuaMethodAttributes(
|
||||||
|
"paint",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void Paint()
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_pause()
|
[LuaMethodAttributes(
|
||||||
|
"pause",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void Pause()
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.PauseEmulator();
|
GlobalWin.MainForm.PauseEmulator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_pause_av()
|
[LuaMethodAttributes(
|
||||||
|
"pause_av",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void PauseAv()
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.PauseAVI = true;
|
GlobalWin.MainForm.PauseAVI = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_reboot_core()
|
[LuaMethodAttributes(
|
||||||
|
"reboot_core",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void RebootCore()
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.RebootCore();
|
GlobalWin.MainForm.RebootCore();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int client_screenheight()
|
[LuaMethodAttributes(
|
||||||
|
"screenheight",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static int ScreenHeight()
|
||||||
{
|
{
|
||||||
return GlobalWin.RenderPanel.NativeSize.Height;
|
return GlobalWin.RenderPanel.NativeSize.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_screenshot(object path = null)
|
[LuaMethodAttributes(
|
||||||
|
"screenshot",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void Screenshot(string path = null)
|
||||||
{
|
{
|
||||||
if (path == null)
|
if (path == null)
|
||||||
{
|
{
|
||||||
|
@ -213,16 +297,24 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.TakeScreenshot(path.ToString());
|
GlobalWin.MainForm.TakeScreenshot(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_screenshottoclipboard()
|
[LuaMethodAttributes(
|
||||||
|
"screenshottoclipboard",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void ScreenshotToClipboard()
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.TakeScreenshotToClipboard();
|
GlobalWin.MainForm.TakeScreenshotToClipboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void client_setdisplayfilter(string filter)
|
[LuaMethodAttributes(
|
||||||
|
"setdisplayfilter",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void SetDisplayFilter(string filter)
|
||||||
{
|
{
|
||||||
foreach (var kvp in _filterMappings)
|
foreach (var kvp in _filterMappings)
|
||||||
{
|
{
|
||||||
|
@ -234,88 +326,110 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_settargetscanlineintensity(int val)
|
[LuaMethodAttributes(
|
||||||
|
"settargetscanlineintensity",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void SetTargetScanlineIntensity(object val)
|
||||||
{
|
{
|
||||||
Global.Config.TargetScanlineFilterIntensity = val;
|
Global.Config.TargetScanlineFilterIntensity = LuaInt(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_setscreenshotosd(bool value)
|
[LuaMethodAttributes(
|
||||||
|
"setscreenshotosd",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void SetScreenshotOSD(bool value)
|
||||||
{
|
{
|
||||||
Global.Config.Screenshot_CaptureOSD = value;
|
Global.Config.Screenshot_CaptureOSD = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int client_screenwidth()
|
[LuaMethodAttributes(
|
||||||
|
"screenwidth",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static int ScreenWidth()
|
||||||
{
|
{
|
||||||
return GlobalWin.RenderPanel.NativeSize.Width;
|
return GlobalWin.RenderPanel.NativeSize.Width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void client_setwindowsize(object window_size)
|
[LuaMethodAttributes(
|
||||||
|
"setwindowsize",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void SetWindowSize(object size)
|
||||||
{
|
{
|
||||||
try
|
var s = LuaInt(size);
|
||||||
|
if (s == 1 || s == 2 || s == 3 || s == 4 || s == 5 || s == 10)
|
||||||
{
|
{
|
||||||
string temp = window_size.ToString();
|
Global.Config.TargetZoomFactor = s;
|
||||||
int size = Convert.ToInt32(temp);
|
|
||||||
if (size == 1 || size == 2 || size == 3 || size == 4 || size == 5 || size == 10)
|
|
||||||
{
|
|
||||||
Global.Config.TargetZoomFactor = size;
|
|
||||||
GlobalWin.MainForm.FrameBufferResized();
|
GlobalWin.MainForm.FrameBufferResized();
|
||||||
GlobalWin.OSD.AddMessage("Window size set to " + size.ToString() + "x");
|
GlobalWin.OSD.AddMessage("Window size set to " + s + "x");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (LogOutputCallback != null)
|
Log("Invalid window size");
|
||||||
{
|
|
||||||
LogOutputCallback("Invalid window size");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
LogOutputCallback("Invalid window size");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void client_speedmode(object percent)
|
[LuaMethodAttributes(
|
||||||
|
"speedmode",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void SpeedMode(object percent)
|
||||||
{
|
{
|
||||||
try
|
var speed = LuaInt(percent);
|
||||||
{
|
if (speed > 0 && speed < 6400)
|
||||||
int speed = Convert.ToInt32(percent.ToString());
|
|
||||||
if (speed > 0 && speed < 1600) // arbituarily capping it at 1600%
|
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.ClickSpeedItem(speed);
|
GlobalWin.MainForm.ClickSpeedItem(speed);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ConsoleLuaLibrary.console_log("Invalid speed value");
|
Log("Invalid speed value");
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
ConsoleLuaLibrary.console_log("Invalid speed value");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_togglepause()
|
[LuaMethodAttributes(
|
||||||
|
"togglepause",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void TogglePause()
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.TogglePause();
|
GlobalWin.MainForm.TogglePause();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_unpause()
|
[LuaMethodAttributes(
|
||||||
|
"unpause",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void Unpause()
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.UnpauseEmulator();
|
GlobalWin.MainForm.UnpauseEmulator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void client_unpause_av()
|
[LuaMethodAttributes(
|
||||||
|
"unpause_av",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void UnpauseAv()
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.PauseAVI = false;
|
GlobalWin.MainForm.PauseAVI = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int client_xpos()
|
[LuaMethodAttributes(
|
||||||
|
"xpos",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static int Xpos()
|
||||||
{
|
{
|
||||||
return GlobalWin.MainForm.DesktopLocation.X;
|
return GlobalWin.MainForm.DesktopLocation.X;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int client_ypos()
|
[LuaMethodAttributes(
|
||||||
|
"ypos",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static int Ypos()
|
||||||
{
|
{
|
||||||
return GlobalWin.MainForm.DesktopLocation.Y;
|
return GlobalWin.MainForm.DesktopLocation.Y;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using LuaInterface;
|
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
|
using LuaInterface;
|
||||||
|
|
||||||
namespace BizHawk.Client.EmuHawk
|
namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
|
@ -19,58 +19,66 @@ namespace BizHawk.Client.EmuHawk
|
||||||
"clear",
|
"clear",
|
||||||
"getluafunctionslist",
|
"getluafunctionslist",
|
||||||
"log",
|
"log",
|
||||||
"output",
|
"output"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void console_clear()
|
[LuaMethodAttributes(
|
||||||
|
"clear",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void Clear()
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.LuaConsole.ClearOutputWindow();
|
GlobalWin.Tools.LuaConsole.ClearOutputWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string console_getluafunctionslist()
|
[LuaMethodAttributes(
|
||||||
|
"getluafunctionslist",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static string GetLuaFunctionsList()
|
||||||
{
|
{
|
||||||
StringBuilder list = new StringBuilder();
|
var list = new StringBuilder();
|
||||||
foreach (var function in GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList)
|
foreach (var function in GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList)
|
||||||
{
|
{
|
||||||
list.AppendLine(function.Name);
|
list.AppendLine(function.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return list.ToString();
|
return list.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void console_log(object lua_input)
|
[LuaMethodAttributes(
|
||||||
|
"log",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void Log(object output)
|
||||||
{
|
{
|
||||||
console_output(lua_input);
|
if (output == null)
|
||||||
}
|
|
||||||
|
|
||||||
public static void console_output(object lua_input)
|
|
||||||
{
|
|
||||||
if (lua_input == null)
|
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.LuaConsole.WriteToOutputWindow("NULL");
|
GlobalWin.Tools.LuaConsole.WriteToOutputWindow("NULL");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (lua_input is LuaTable)
|
if (output is LuaTable)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
var lti = (lua_input as LuaTable);
|
var lti = output as LuaTable;
|
||||||
|
|
||||||
List<string> Keys = (from object key in lti.Keys select key.ToString()).ToList();
|
var keys = (from object key in lti.Keys select key.ToString()).ToList();
|
||||||
List<string> Values = (from object value in lti.Values select value.ToString()).ToList();
|
var values = (from object value in lti.Values select value.ToString()).ToList();
|
||||||
|
|
||||||
List<KeyValuePair<string, string>> KVPs = new List<KeyValuePair<string, string>>();
|
var kvps = new List<KeyValuePair<string, string>>();
|
||||||
for (int i = 0; i < Keys.Count; i++)
|
for (var i = 0; i < keys.Count; i++)
|
||||||
{
|
{
|
||||||
if (i < Values.Count)
|
if (i < values.Count)
|
||||||
{
|
{
|
||||||
KeyValuePair<string, string> kvp = new KeyValuePair<string, string>(Keys[i], Values[i]);
|
kvps.Add(new KeyValuePair<string, string>(keys[i], values[i]));
|
||||||
KVPs.Add(kvp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KVPs = KVPs.OrderBy(x => x.Key).ToList();
|
|
||||||
foreach (var kvp in KVPs)
|
kvps = kvps.OrderBy(x => x.Key).ToList();
|
||||||
|
foreach (var kvp in kvps)
|
||||||
{
|
{
|
||||||
sb
|
sb
|
||||||
.Append("\"")
|
.Append("\"")
|
||||||
|
@ -85,7 +93,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.LuaConsole.WriteToOutputWindow(lua_input.ToString());
|
GlobalWin.Tools.LuaConsole.WriteToOutputWindow(output.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,14 @@ using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using LuaInterface;
|
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
|
using LuaInterface;
|
||||||
|
|
||||||
namespace BizHawk.Client.EmuHawk
|
namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
public class FormsLuaLibrary : LuaLibraryBase
|
public class FormsLuaLibrary : LuaLibraryBase
|
||||||
{
|
{
|
||||||
|
// TODO: replace references to ConsoleLuaLibrary.Log with a callback that is passed in
|
||||||
public override string Name { get { return "forms"; } }
|
public override string Name { get { return "forms"; } }
|
||||||
public override string[] Functions
|
public override string[] Functions
|
||||||
{
|
{
|
||||||
|
@ -46,7 +47,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public void WindowClosed(IntPtr handle)
|
public void WindowClosed(IntPtr handle)
|
||||||
{
|
{
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
if (form.Handle == handle)
|
if (form.Handle == handle)
|
||||||
{
|
{
|
||||||
|
@ -58,35 +59,41 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private LuaWinform GetForm(object formHandle)
|
private LuaWinform GetForm(object formHandle)
|
||||||
{
|
{
|
||||||
IntPtr ptr = new IntPtr(LuaInt(formHandle));
|
var ptr = new IntPtr(LuaInt(formHandle));
|
||||||
return _luaForms.FirstOrDefault(form => form.Handle == ptr);
|
return _luaForms.FirstOrDefault(form => form.Handle == ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetLocation(Control control, object X, object Y)
|
private static void SetLocation(Control control, object x, object y)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (X != null && Y != null)
|
if (x != null && y != null)
|
||||||
{
|
{
|
||||||
control.Location = new Point(LuaInt(X), LuaInt(Y));
|
control.Location = new Point(LuaInt(x), LuaInt(y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { /*Do nothing*/ }
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ConsoleLuaLibrary.Log(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetSize(Control control, object Width, object Height)
|
private static void SetSize(Control control, object width, object height)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Width != null && Height != null)
|
if (width != null && height != null)
|
||||||
{
|
{
|
||||||
control.Size = new Size(LuaInt(Width), LuaInt(Height));
|
control.Size = new Size(LuaInt(width), LuaInt(height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { /*Do nothing*/ }
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ConsoleLuaLibrary.Log(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetText(Control control, object caption)
|
private static void SetText(Control control, object caption)
|
||||||
{
|
{
|
||||||
if (caption != null)
|
if (caption != null)
|
||||||
{
|
{
|
||||||
|
@ -96,80 +103,106 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public void forms_addclick(object handle, LuaFunction lua_event)
|
[LuaMethodAttributes(
|
||||||
|
"addclick",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void AddClick(object handle, LuaFunction clickEvent)
|
||||||
{
|
{
|
||||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
var ptr = new IntPtr(LuaInt(handle));
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
foreach (Control control in form.Controls)
|
foreach (Control control in form.Controls)
|
||||||
{
|
{
|
||||||
if (control.Handle == ptr)
|
if (control.Handle == ptr)
|
||||||
{
|
{
|
||||||
form.ControlEvents.Add(new LuaWinform.LuaEvent(control.Handle, lua_event));
|
form.ControlEvents.Add(new LuaWinform.LuaEvent(control.Handle, clickEvent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int forms_button(object form_handle, object caption, LuaFunction lua_event, object X = null, object Y = null, object width = null, object height = null)
|
[LuaMethodAttributes(
|
||||||
|
"button",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public int Button(
|
||||||
|
object formHandle,
|
||||||
|
object caption,
|
||||||
|
LuaFunction clickEvent,
|
||||||
|
object x = null,
|
||||||
|
object y = null,
|
||||||
|
object width = null,
|
||||||
|
object height = null)
|
||||||
{
|
{
|
||||||
LuaWinform form = GetForm(form_handle);
|
var form = GetForm(formHandle);
|
||||||
if (form == null)
|
if (form == null)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaButton button = new LuaButton();
|
var button = new LuaButton();
|
||||||
SetText(button, caption);
|
SetText(button, caption);
|
||||||
form.Controls.Add(button);
|
form.Controls.Add(button);
|
||||||
form.ControlEvents.Add(new LuaWinform.LuaEvent(button.Handle, lua_event));
|
form.ControlEvents.Add(new LuaWinform.LuaEvent(button.Handle, clickEvent));
|
||||||
|
|
||||||
SetLocation(button, X, Y);
|
SetLocation(button, x, y);
|
||||||
SetSize(button, width, height);
|
SetSize(button, width, height);
|
||||||
|
|
||||||
return (int)button.Handle;
|
return (int)button.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int forms_checkbox(object form_handle, string caption, object X = null, object Y = null)
|
[LuaMethodAttributes(
|
||||||
|
"checkbox",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public int Checkbox(object formHandle, string caption, object x = null, object y = null)
|
||||||
{
|
{
|
||||||
LuaWinform form = GetForm(form_handle);
|
var form = GetForm(formHandle);
|
||||||
if (form == null)
|
if (form == null)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaCheckbox checkbox = new LuaCheckbox();
|
var checkbox = new LuaCheckbox();
|
||||||
form.Controls.Add(checkbox);
|
form.Controls.Add(checkbox);
|
||||||
SetText(checkbox, caption);
|
SetText(checkbox, caption);
|
||||||
SetLocation(checkbox, X, Y);
|
SetLocation(checkbox, x, y);
|
||||||
|
|
||||||
|
|
||||||
return (int)checkbox.Handle;
|
return (int)checkbox.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forms_clearclicks(object handle)
|
[LuaMethodAttributes(
|
||||||
|
"clearclicks",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void ClearClicks(object handle)
|
||||||
{
|
{
|
||||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
var ptr = new IntPtr(LuaInt(handle));
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
foreach (Control control in form.Controls)
|
foreach (Control control in form.Controls)
|
||||||
{
|
{
|
||||||
if (control.Handle == ptr)
|
if (control.Handle == ptr)
|
||||||
{
|
{
|
||||||
List<LuaWinform.LuaEvent> lua_events = form.ControlEvents.Where(x => x.Control == ptr).ToList();
|
var luaEvents = form.ControlEvents.Where(x => x.Control == ptr).ToList();
|
||||||
foreach (LuaWinform.LuaEvent levent in lua_events)
|
foreach (var luaEvent in luaEvents)
|
||||||
{
|
{
|
||||||
form.ControlEvents.Remove(levent);
|
form.ControlEvents.Remove(luaEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool forms_destroy(object handle)
|
[LuaMethodAttributes(
|
||||||
|
"destroy",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public bool Destroy(object handle)
|
||||||
{
|
{
|
||||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
var ptr = new IntPtr(LuaInt(handle));
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
if (form.Handle == ptr)
|
if (form.Handle == ptr)
|
||||||
{
|
{
|
||||||
|
@ -178,42 +211,61 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forms_destroyall()
|
[LuaMethodAttributes(
|
||||||
|
"destroyall",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DestroyAll()
|
||||||
{
|
{
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
form.Close();
|
form.Close();
|
||||||
_luaForms.Remove(form);
|
_luaForms.Remove(form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int forms_dropdown(object form_handle, LuaTable items, object X = null, object Y = null, object width = null, object height = null)
|
[LuaMethodAttributes(
|
||||||
|
"dropdown",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public int Dropdown(
|
||||||
|
object formHandle,
|
||||||
|
LuaTable items,
|
||||||
|
object x = null,
|
||||||
|
object y = null,
|
||||||
|
object width = null,
|
||||||
|
object height = null)
|
||||||
{
|
{
|
||||||
LuaWinform form = GetForm(form_handle);
|
var form = GetForm(formHandle);
|
||||||
if (form == null)
|
if (form == null)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> dropdownItems = items.Values.Cast<string>().ToList();
|
var dropdownItems = items.Values.Cast<string>().ToList();
|
||||||
dropdownItems.Sort();
|
dropdownItems.Sort();
|
||||||
|
|
||||||
LuaDropDown dropdown = new LuaDropDown(dropdownItems);
|
var dropdown = new LuaDropDown(dropdownItems);
|
||||||
form.Controls.Add(dropdown);
|
form.Controls.Add(dropdown);
|
||||||
SetLocation(dropdown, X, Y);
|
SetLocation(dropdown, x, y);
|
||||||
SetSize(dropdown, width, height);
|
SetSize(dropdown, width, height);
|
||||||
return (int)dropdown.Handle;
|
return (int)dropdown.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string forms_getproperty(object handle, object property)
|
[LuaMethodAttributes(
|
||||||
|
"getproperty",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public string GetProperty(object handle, object property)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
var ptr = new IntPtr(LuaInt(handle));
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
if (form.Handle == ptr)
|
if (form.Handle == ptr)
|
||||||
{
|
{
|
||||||
|
@ -233,18 +285,22 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ConsoleLuaLibrary.console_output(ex.Message);
|
ConsoleLuaLibrary.Log(ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string forms_gettext(object handle)
|
[LuaMethodAttributes(
|
||||||
|
"gettext",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public string GetText(object handle)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
var ptr = new IntPtr(LuaInt(handle));
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
if (form.Handle == ptr)
|
if (form.Handle == ptr)
|
||||||
{
|
{
|
||||||
|
@ -271,18 +327,22 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ConsoleLuaLibrary.console_output(ex.Message);
|
ConsoleLuaLibrary.Log(ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool forms_ischecked(object handle)
|
[LuaMethodAttributes(
|
||||||
|
"ischecked",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public bool IsChecked(object handle)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
var ptr = new IntPtr(LuaInt(handle));
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
if (form.Handle == ptr)
|
if (form.Handle == ptr)
|
||||||
{
|
{
|
||||||
|
@ -309,62 +369,79 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ConsoleLuaLibrary.console_output(ex.Message);
|
ConsoleLuaLibrary.Log(ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int forms_label(object form_handle, object caption, object X = null, object Y = null, object width = null, object height = null)
|
[LuaMethodAttributes(
|
||||||
|
"label",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public int Label(
|
||||||
|
object formHandle,
|
||||||
|
object caption,
|
||||||
|
object x = null,
|
||||||
|
object y = null,
|
||||||
|
object width = null,
|
||||||
|
object height = null)
|
||||||
{
|
{
|
||||||
LuaWinform form = GetForm(form_handle);
|
var form = GetForm(formHandle);
|
||||||
if (form == null)
|
if (form == null)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Label label = new Label();
|
var label = new Label();
|
||||||
SetText(label, caption);
|
SetText(label, caption);
|
||||||
form.Controls.Add(label);
|
form.Controls.Add(label);
|
||||||
SetLocation(label, X, Y);
|
SetLocation(label, x, y);
|
||||||
SetSize(label, width, height);
|
SetSize(label, width, height);
|
||||||
|
|
||||||
return (int)label.Handle;
|
return (int)label.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int forms_newform(object Width = null, object Height = null, object title = null)
|
[LuaMethodAttributes(
|
||||||
|
"newform",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public int NewForm(object width = null, object height = null, string title = null)
|
||||||
{
|
{
|
||||||
|
var form = new LuaWinform();
|
||||||
LuaWinform theForm = new LuaWinform();
|
_luaForms.Add(form);
|
||||||
_luaForms.Add(theForm);
|
if (width != null && height != null)
|
||||||
if (Width != null && Height != null)
|
|
||||||
{
|
{
|
||||||
theForm.Size = new Size(LuaInt(Width), LuaInt(Height));
|
form.Size = new Size(LuaInt(width), LuaInt(height));
|
||||||
}
|
}
|
||||||
|
|
||||||
theForm.Text = (string)title;
|
form.Text = title;
|
||||||
theForm.Show();
|
form.Show();
|
||||||
return (int)theForm.Handle;
|
return (int)form.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string forms_openfile(string FileName = null, string InitialDirectory = null, string Filter = "All files (*.*)|*.*")
|
[LuaMethodAttributes(
|
||||||
|
"openfile",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public string OpenFile(string fileName = null, string initialDirectory = null, string filter = "All files (*.*)|*.*")
|
||||||
{
|
{
|
||||||
// filterext format ex: "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
|
// filterext format ex: "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
|
||||||
OpenFileDialog openFileDialog1 = new OpenFileDialog();
|
var openFileDialog1 = new OpenFileDialog();
|
||||||
if (InitialDirectory != null)
|
if (initialDirectory != null)
|
||||||
{
|
{
|
||||||
openFileDialog1.InitialDirectory = InitialDirectory;
|
openFileDialog1.InitialDirectory = initialDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FileName != null)
|
if (fileName != null)
|
||||||
{
|
{
|
||||||
openFileDialog1.FileName = FileName;
|
openFileDialog1.FileName = fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Filter != null)
|
if (filter != null)
|
||||||
{
|
{
|
||||||
openFileDialog1.AddExtension = true;
|
openFileDialog1.AddExtension = true;
|
||||||
openFileDialog1.Filter = Filter;
|
openFileDialog1.Filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
||||||
|
@ -377,14 +454,18 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forms_setlocation(object handle, object X, object Y)
|
[LuaMethodAttributes(
|
||||||
|
"setlocation",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void SetLocation(object handle, object x, object y)
|
||||||
{
|
{
|
||||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
var ptr = new IntPtr(LuaInt(handle));
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
if (form.Handle == ptr)
|
if (form.Handle == ptr)
|
||||||
{
|
{
|
||||||
SetLocation(form, X, Y);
|
SetLocation(form, x, y);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -392,17 +473,21 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
if (control.Handle == ptr)
|
if (control.Handle == ptr)
|
||||||
{
|
{
|
||||||
SetLocation(control, X, Y);
|
SetLocation(control, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forms_setproperty(object handle, object property, object value)
|
[LuaMethodAttributes(
|
||||||
|
"setproperty",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void SetProperty(object handle, object property, object value)
|
||||||
{
|
{
|
||||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
var ptr = new IntPtr(LuaInt(handle));
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
if (form.Handle == ptr)
|
if (form.Handle == ptr)
|
||||||
{
|
{
|
||||||
|
@ -421,14 +506,18 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forms_setsize(object handle, object Width, object Height)
|
[LuaMethodAttributes(
|
||||||
|
"setsize",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void SetSize(object handle, object width, object height)
|
||||||
{
|
{
|
||||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
var ptr = new IntPtr(LuaInt(handle));
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
if (form.Handle == ptr)
|
if (form.Handle == ptr)
|
||||||
{
|
{
|
||||||
SetSize(form, Width, Height);
|
SetSize(form, width, height);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -436,17 +525,21 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
if (control.Handle == ptr)
|
if (control.Handle == ptr)
|
||||||
{
|
{
|
||||||
SetSize(control, Width, Height);
|
SetSize(control, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forms_settext(object handle, object caption)
|
[LuaMethodAttributes(
|
||||||
|
"settext",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void Settext(object handle, object caption)
|
||||||
{
|
{
|
||||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
var ptr = new IntPtr(LuaInt(handle));
|
||||||
foreach (LuaWinform form in _luaForms)
|
foreach (var form in _luaForms)
|
||||||
{
|
{
|
||||||
if (form.Handle == ptr)
|
if (form.Handle == ptr)
|
||||||
{
|
{
|
||||||
|
@ -465,15 +558,28 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int forms_textbox(object form_handle, object caption = null, object width = null, object height = null, object boxtype = null, object X = null, object Y = null, bool multiline = false, bool fixedWidth = false)
|
[LuaMethodAttributes(
|
||||||
|
"textbox",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public int Textbox(
|
||||||
|
object formHandle,
|
||||||
|
object caption = null,
|
||||||
|
object width = null,
|
||||||
|
object height = null,
|
||||||
|
object boxtype = null,
|
||||||
|
object x = null,
|
||||||
|
object y = null,
|
||||||
|
bool multiline = false,
|
||||||
|
bool fixedWidth = false)
|
||||||
{
|
{
|
||||||
LuaWinform form = GetForm(form_handle);
|
var form = GetForm(formHandle);
|
||||||
if (form == null)
|
if (form == null)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaTextBox textbox = new LuaTextBox();
|
var textbox = new LuaTextBox();
|
||||||
if (fixedWidth)
|
if (fixedWidth)
|
||||||
{
|
{
|
||||||
textbox.Font = new Font("Courier New", 8);
|
textbox.Font = new Font("Courier New", 8);
|
||||||
|
@ -481,7 +587,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
textbox.Multiline = multiline;
|
textbox.Multiline = multiline;
|
||||||
SetText(textbox, caption);
|
SetText(textbox, caption);
|
||||||
SetLocation(textbox, X, Y);
|
SetLocation(textbox, x, y);
|
||||||
SetSize(textbox, width, height);
|
SetSize(textbox, width, height);
|
||||||
|
|
||||||
if (boxtype != null)
|
if (boxtype != null)
|
||||||
|
@ -504,6 +610,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
form.Controls.Add(textbox);
|
form.Controls.Add(textbox);
|
||||||
return (int)textbox.Handle;
|
return (int)textbox.Handle;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
using LuaInterface;
|
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
|
using LuaInterface;
|
||||||
|
|
||||||
namespace BizHawk.Client.EmuHawk
|
namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
"drawRectangle",
|
"drawRectangle",
|
||||||
"drawString",
|
"drawString",
|
||||||
"drawText",
|
"drawText",
|
||||||
"text",
|
"text"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,15 +42,22 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
foreach (var brush in SolidBrushes.Values) brush.Dispose();
|
foreach (var brush in _solidBrushes.Values)
|
||||||
foreach (var brush in Pens.Values) brush.Dispose();
|
{
|
||||||
|
brush.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var brush in _pens.Values)
|
||||||
|
{
|
||||||
|
brush.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SurfaceIsNull
|
public bool SurfaceIsNull
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return luaSurface == null;
|
return _luaSurface == null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,12 +70,12 @@ namespace BizHawk.Client.EmuHawk
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DrawNew()
|
public void DrawNew()
|
||||||
{
|
{
|
||||||
luaSurface = GlobalWin.DisplayManager.GetLuaSurfaceNative();
|
_luaSurface = GlobalWin.DisplayManager.GetLuaSurfaceNative();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawNewEmu()
|
public void DrawNewEmu()
|
||||||
{
|
{
|
||||||
luaSurface = GlobalWin.DisplayManager.GetLuaEmuSurfaceEmu();
|
_luaSurface = GlobalWin.DisplayManager.GetLuaEmuSurfaceEmu();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -78,23 +85,25 @@ namespace BizHawk.Client.EmuHawk
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DrawFinish()
|
public void DrawFinish()
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.SetLuaSurfaceNativePreOSD(luaSurface);
|
GlobalWin.DisplayManager.SetLuaSurfaceNativePreOSD(_luaSurface);
|
||||||
luaSurface = null;
|
_luaSurface = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawFinishEmu()
|
public void DrawFinishEmu()
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.SetLuaSurfaceEmu(luaSurface);
|
GlobalWin.DisplayManager.SetLuaSurfaceEmu(_luaSurface);
|
||||||
luaSurface = null;
|
_luaSurface = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Helpers
|
#region Helpers
|
||||||
|
|
||||||
private DisplaySurface luaSurface;
|
private readonly Dictionary<Color, SolidBrush> _solidBrushes = new Dictionary<Color, SolidBrush>();
|
||||||
private readonly Dictionary<Color, SolidBrush> SolidBrushes = new Dictionary<Color, SolidBrush>();
|
private readonly Dictionary<Color, Pen> _pens = new Dictionary<Color, Pen>();
|
||||||
private readonly Dictionary<Color, Pen> Pens = new Dictionary<Color, Pen>();
|
private readonly Bitmap _nullGraphicsBitmap = new Bitmap(1, 1);
|
||||||
|
|
||||||
|
private DisplaySurface _luaSurface;
|
||||||
|
|
||||||
private static Color GetColor(object color)
|
private static Color GetColor(object color)
|
||||||
{
|
{
|
||||||
|
@ -110,73 +119,94 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private SolidBrush GetBrush(object color)
|
private SolidBrush GetBrush(object color)
|
||||||
{
|
{
|
||||||
Color c = GetColor(color);
|
var c = GetColor(color);
|
||||||
SolidBrush b;
|
SolidBrush b;
|
||||||
if (!SolidBrushes.TryGetValue(c, out b))
|
if (!_solidBrushes.TryGetValue(c, out b))
|
||||||
{
|
{
|
||||||
b = new SolidBrush(c);
|
b = new SolidBrush(c);
|
||||||
SolidBrushes[c] = b;
|
_solidBrushes[c] = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pen GetPen(object color)
|
private Pen GetPen(object color)
|
||||||
{
|
{
|
||||||
Color c = GetColor(color);
|
var c = GetColor(color);
|
||||||
Pen p;
|
Pen p;
|
||||||
if (!Pens.TryGetValue(c, out p))
|
if (!_pens.TryGetValue(c, out p))
|
||||||
{
|
{
|
||||||
p = new Pen(c);
|
p = new Pen(c);
|
||||||
Pens[c] = p;
|
_pens[c] = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap nullGraphicsBitmap = new Bitmap(1, 1);
|
|
||||||
private Graphics GetGraphics()
|
private Graphics GetGraphics()
|
||||||
{
|
{
|
||||||
Graphics g;
|
var g = _luaSurface == null ? Graphics.FromImage(_nullGraphicsBitmap) : _luaSurface.GetGraphics();
|
||||||
if (luaSurface == null)
|
|
||||||
g = Graphics.FromImage(nullGraphicsBitmap);
|
var tx = Global.Emulator.CoreComm.ScreenLogicalOffsetX;
|
||||||
else g = luaSurface.GetGraphics();
|
var ty = Global.Emulator.CoreComm.ScreenLogicalOffsetY;
|
||||||
int tx = Global.Emulator.CoreComm.ScreenLogicalOffsetX;
|
|
||||||
int ty = Global.Emulator.CoreComm.ScreenLogicalOffsetY;
|
|
||||||
if (tx != 0 || ty != 0)
|
if (tx != 0 || ty != 0)
|
||||||
{
|
{
|
||||||
var transform = g.Transform;
|
var transform = g.Transform;
|
||||||
transform.Translate(-tx, -ty);
|
transform.Translate(-tx, -ty);
|
||||||
g.Transform = transform;
|
g.Transform = transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoGuiText(object luaX, object luaY, object luaStr, bool alert, object background = null,
|
private static void DoGuiText(
|
||||||
object forecolor = null, object anchor = null)
|
object x,
|
||||||
|
object y,
|
||||||
|
string message,
|
||||||
|
bool alert,
|
||||||
|
object background = null,
|
||||||
|
object forecolor = null,
|
||||||
|
object anchor = null)
|
||||||
{
|
{
|
||||||
if (!alert)
|
if (!alert)
|
||||||
{
|
{
|
||||||
if (forecolor == null)
|
if (forecolor == null)
|
||||||
|
{
|
||||||
forecolor = "white";
|
forecolor = "white";
|
||||||
|
}
|
||||||
|
|
||||||
if (background == null)
|
if (background == null)
|
||||||
|
{
|
||||||
background = "black";
|
background = "black";
|
||||||
}
|
}
|
||||||
int dx = LuaInt(luaX);
|
}
|
||||||
int dy = LuaInt(luaY);
|
|
||||||
int a = 0;
|
var dx = LuaInt(x);
|
||||||
|
var dy = LuaInt(y);
|
||||||
|
var a = 0;
|
||||||
|
|
||||||
if (anchor != null)
|
if (anchor != null)
|
||||||
{
|
{
|
||||||
int x;
|
int dummy;
|
||||||
if (int.TryParse(anchor.ToString(), out x) == false)
|
if (int.TryParse(anchor.ToString(), out dummy) == false)
|
||||||
{
|
{
|
||||||
if (anchor.ToString().ToLower() == "topleft")
|
if (anchor.ToString().ToLower() == "topleft")
|
||||||
|
{
|
||||||
a = 0;
|
a = 0;
|
||||||
|
}
|
||||||
else if (anchor.ToString().ToLower() == "topright")
|
else if (anchor.ToString().ToLower() == "topright")
|
||||||
|
{
|
||||||
a = 1;
|
a = 1;
|
||||||
|
}
|
||||||
else if (anchor.ToString().ToLower() == "bottomleft")
|
else if (anchor.ToString().ToLower() == "bottomleft")
|
||||||
|
{
|
||||||
a = 2;
|
a = 2;
|
||||||
|
}
|
||||||
else if (anchor.ToString().ToLower() == "bottomright")
|
else if (anchor.ToString().ToLower() == "bottomright")
|
||||||
|
{
|
||||||
a = 3;
|
a = 3;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
a = LuaInt(anchor);
|
a = LuaInt(anchor);
|
||||||
|
@ -187,54 +217,78 @@ namespace BizHawk.Client.EmuHawk
|
||||||
dx -= Global.Emulator.CoreComm.ScreenLogicalOffsetX;
|
dx -= Global.Emulator.CoreComm.ScreenLogicalOffsetX;
|
||||||
dy -= Global.Emulator.CoreComm.ScreenLogicalOffsetY;
|
dy -= Global.Emulator.CoreComm.ScreenLogicalOffsetY;
|
||||||
}
|
}
|
||||||
// blah hacks
|
|
||||||
dx *= MultiClientLuaLibrary.client_getwindowsize();
|
|
||||||
dy *= MultiClientLuaLibrary.client_getwindowsize();
|
|
||||||
|
|
||||||
GlobalWin.OSD.AddGUIText(luaStr.ToString(), dx, dy, alert, GetColor(background), GetColor(forecolor), a);
|
// blah hacks
|
||||||
|
dx *= EmuHawkLuaLibrary.GetWindowSize();
|
||||||
|
dy *= EmuHawkLuaLibrary.GetWindowSize();
|
||||||
|
|
||||||
|
GlobalWin.OSD.AddGUIText(message, dx, dy, alert, GetColor(background), GetColor(forecolor), a);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public void gui_addmessage(object luaStr)
|
[LuaMethodAttributes(
|
||||||
|
"addmessage",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void AddMessage(object luaStr)
|
||||||
{
|
{
|
||||||
GlobalWin.OSD.AddMessage(luaStr.ToString());
|
GlobalWin.OSD.AddMessage(luaStr.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_alert(object luaX, object luaY, object luaStr, object anchor = null)
|
[LuaMethodAttributes(
|
||||||
|
"alert",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void Alert(object x, object y, string message, object anchor = null)
|
||||||
{
|
{
|
||||||
DoGuiText(luaX, luaY, luaStr, true, null, null, anchor);
|
DoGuiText(x, y, message, true, null, null, anchor); // TODO: refactor DoGuiText to take luaStr as string and refactor
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_clearGraphics()
|
[LuaMethodAttributes(
|
||||||
|
"clearGraphics",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void ClearGraphics()
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
luaSurface.Clear();
|
_luaSurface.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void gui_cleartext()
|
[LuaMethodAttributes(
|
||||||
|
"cleartext",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public static void ClearText()
|
||||||
{
|
{
|
||||||
GlobalWin.OSD.ClearGUIText();
|
GlobalWin.OSD.ClearGUIText();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_drawBezier(LuaTable points, object color)
|
[LuaMethodAttributes(
|
||||||
|
"drawBezier",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawBezier(LuaTable points, object color)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Point[] Points = new Point[4];
|
var pointsArr = new Point[4];
|
||||||
int i = 0;
|
|
||||||
|
var i = 0;
|
||||||
foreach (LuaTable point in points.Values)
|
foreach (LuaTable point in points.Values)
|
||||||
{
|
{
|
||||||
Points[i] = new Point(LuaInt(point[1]), LuaInt(point[2]));
|
pointsArr[i] = new Point(LuaInt(point[1]), LuaInt(point[2]));
|
||||||
i++;
|
i++;
|
||||||
if (i >= 4)
|
if (i >= 4)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g.DrawBezier(GetPen(color), Points[0], Points[1], Points[2], Points[3]);
|
g.DrawBezier(GetPen(color), pointsArr[0], pointsArr[1], pointsArr[2], pointsArr[3]);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -243,41 +297,45 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_drawBox(object X, object Y, object X2, object Y2, object line = null, object background = null)
|
[LuaMethodAttributes(
|
||||||
|
"drawBox",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawBox(object x, object y, object x2, object y2, object line = null, object background = null)
|
||||||
{
|
{
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int int_x = LuaInt(X);
|
var intX = LuaInt(x);
|
||||||
int int_y = LuaInt(Y);
|
var intY = LuaInt(y);
|
||||||
int int_width = LuaInt(X2);
|
var intWidth = LuaInt(x2);
|
||||||
int int_height = LuaInt(Y2);
|
var intHeight = LuaInt(y2);
|
||||||
|
|
||||||
if (int_x < int_width)
|
if (intX < intWidth)
|
||||||
{
|
{
|
||||||
int_width = Math.Abs(int_x - int_width);
|
intWidth = Math.Abs(intX - intWidth);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int_width = int_x - int_width;
|
intWidth = intX - intWidth;
|
||||||
int_x -= int_width;
|
intX -= intWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (int_y < int_height)
|
if (intY < intHeight)
|
||||||
{
|
{
|
||||||
int_height = Math.Abs(int_y - int_height);
|
intHeight = Math.Abs(intY - intHeight);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int_height = int_y - int_height;
|
intHeight = intY - intHeight;
|
||||||
int_y -= int_height;
|
intY -= intHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
g.DrawRectangle(GetPen(line ?? "white"), int_x, int_y, int_width, int_height);
|
g.DrawRectangle(GetPen(line ?? "white"), intX, intY, intWidth, intHeight);
|
||||||
if (background != null)
|
if (background != null)
|
||||||
{
|
{
|
||||||
g.FillRectangle(GetBrush(background), int_x, int_y, int_width, int_height);
|
g.FillRectangle(GetBrush(background), intX, intY, intWidth, intHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -288,18 +346,22 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_drawEllipse(object X, object Y, object width, object height, object line, object background = null)
|
[LuaMethodAttributes(
|
||||||
|
"drawEllipse",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawEllipse(object x, object y, object width, object height, object line, object background = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
g.DrawEllipse(GetPen(line ?? "white"), LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height));
|
g.DrawEllipse(GetPen(line ?? "white"), LuaInt(x), LuaInt(y), LuaInt(width), LuaInt(height));
|
||||||
if (background != null)
|
if (background != null)
|
||||||
{
|
{
|
||||||
var brush = GetBrush(background);
|
var brush = GetBrush(background);
|
||||||
g.FillEllipse(brush, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height));
|
g.FillEllipse(brush, LuaInt(x), LuaInt(y), LuaInt(width), LuaInt(height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -310,7 +372,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_drawIcon(object Path, object x, object y, object width = null, object height = null)
|
[LuaMethodAttributes(
|
||||||
|
"drawIcon",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawIcon(string path, object x, object y, object width = null, object height = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
|
@ -320,11 +386,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Icon icon;
|
Icon icon;
|
||||||
if (width != null && height != null)
|
if (width != null && height != null)
|
||||||
{
|
{
|
||||||
icon = new Icon(Path.ToString(), LuaInt(width), LuaInt(height));
|
icon = new Icon(path, LuaInt(width), LuaInt(height));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
icon = new Icon(Path.ToString());
|
icon = new Icon(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
g.DrawIcon(icon, LuaInt(x), LuaInt(y));
|
g.DrawIcon(icon, LuaInt(x), LuaInt(y));
|
||||||
|
@ -336,21 +402,30 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_drawImage(object Path, object x, object y, object width = null, object height = null)
|
[LuaMethodAttributes(
|
||||||
|
"drawImage",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawImage(string path, object x, object y, object width = null, object height = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Image img = Image.FromFile(Path.ToString());
|
var img = Image.FromFile(path);
|
||||||
|
|
||||||
if (width == null || width.GetType() != typeof(int))
|
if (width == null || width.GetType() != typeof(int))
|
||||||
|
{
|
||||||
width = img.Width.ToString();
|
width = img.Width.ToString();
|
||||||
if (height == null || height.GetType() != typeof(int))
|
}
|
||||||
height = img.Height.ToString();
|
|
||||||
|
|
||||||
g.DrawImage(img, LuaInt(x), LuaInt(y), int.Parse(width.ToString()), int.Parse(height.ToString()));
|
if (height == null || height.GetType() != typeof(int))
|
||||||
|
{
|
||||||
|
height = img.Height.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
g.DrawImage(img, LuaInt(x), LuaInt(y), LuaInt(width), LuaInt(height));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -359,7 +434,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_drawLine(object x1, object y1, object x2, object y2, object color = null)
|
[LuaMethodAttributes(
|
||||||
|
"drawLine",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawLine(object x1, object y1, object x2, object y2, object color = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
|
@ -375,19 +454,30 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_drawPie(object X, object Y, object width, object height, object startangle, object sweepangle,
|
[LuaMethodAttributes(
|
||||||
object line, object background = null)
|
"drawPie",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawPie(
|
||||||
|
object x,
|
||||||
|
object y,
|
||||||
|
object width,
|
||||||
|
object height,
|
||||||
|
object startangle,
|
||||||
|
object sweepangle,
|
||||||
|
object line,
|
||||||
|
object background = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
g.DrawPie(GetPen(line), LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle));
|
g.DrawPie(GetPen(line), LuaInt(x), LuaInt(y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle));
|
||||||
if (background != null)
|
if (background != null)
|
||||||
{
|
{
|
||||||
var brush = GetBrush(background);
|
var brush = GetBrush(background);
|
||||||
g.FillPie(brush, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle));
|
g.FillPie(brush, LuaInt(x), LuaInt(y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -398,16 +488,18 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[LuaMethodAttributes(
|
||||||
public void gui_drawPixel(object X, object Y, object color = null)
|
"drawPixel",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawPixel(object x, object y, object color = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
float x = LuaInt(X) + 0.1F;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
g.DrawLine(GetPen(color ?? "white"), LuaInt(X), LuaInt(Y), x, LuaInt(Y));
|
g.DrawLine(GetPen(color ?? "white"), LuaInt(x), LuaInt(y), LuaInt(x) + 0.1F, LuaInt(y));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -416,27 +508,30 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_drawPolygon(LuaTable points, object line, object background = null)
|
[LuaMethodAttributes(
|
||||||
|
"drawPolygon",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawPolygon(LuaTable points, object line, object background = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
//this is a test
|
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Point[] Points = new Point[points.Values.Count];
|
var pointsArr = new Point[points.Values.Count];
|
||||||
int i = 0;
|
var i = 0;
|
||||||
foreach (LuaTable point in points.Values)
|
foreach (LuaTable point in points.Values)
|
||||||
{
|
{
|
||||||
Points[i] = new Point(LuaInt(point[1]), LuaInt(point[2]));
|
pointsArr[i] = new Point(LuaInt(point[1]), LuaInt(point[2]));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
g.DrawPolygon(GetPen(line), Points);
|
g.DrawPolygon(GetPen(line), pointsArr);
|
||||||
if (background != null)
|
if (background != null)
|
||||||
{
|
{
|
||||||
var brush = GetBrush(background);
|
g.FillPolygon(GetBrush(background), pointsArr);
|
||||||
g.FillPolygon(brush, Points);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -446,20 +541,24 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_drawRectangle(object X, object Y, object width, object height, object line, object background = null)
|
[LuaMethodAttributes(
|
||||||
|
"drawRectangle",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawRectangle(object x, object y, object width, object height, object line, object background = null)
|
||||||
{
|
{
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int int_x = LuaInt(X);
|
var intX = LuaInt(x);
|
||||||
int int_y = LuaInt(Y);
|
var intY = LuaInt(y);
|
||||||
int int_width = LuaInt(width);
|
var intWidth = LuaInt(width);
|
||||||
int int_height = LuaInt(height);
|
var intHeight = LuaInt(height);
|
||||||
g.DrawRectangle(GetPen(line ?? "white"), int_x, int_y, int_width, int_height);
|
g.DrawRectangle(GetPen(line ?? "white"), intX, intY, intWidth, intHeight);
|
||||||
if (background != null)
|
if (background != null)
|
||||||
{
|
{
|
||||||
g.FillRectangle(GetBrush(background), int_x, int_y, int_width, int_height);
|
g.FillRectangle(GetBrush(background), intX, intY, intWidth, intHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -470,35 +569,56 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_drawString(object X, object Y, object message, object color = null, object fontsize = null, object fontfamily = null, object fontstyle = null)
|
[LuaMethodAttributes(
|
||||||
|
"drawString",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawString(
|
||||||
|
object x,
|
||||||
|
object y,
|
||||||
|
string message,
|
||||||
|
object color = null,
|
||||||
|
object fontsize = null,
|
||||||
|
string fontfamily = null,
|
||||||
|
string fontstyle = null)
|
||||||
{
|
{
|
||||||
gui_drawText(X, Y, message, color, fontsize, fontfamily, fontstyle);
|
DrawText(x, y, message, color, fontsize, fontfamily, fontstyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_drawText(object X, object Y, object message, object color = null, object fontsize = null, object fontfamily = null, object fontstyle = null)
|
[LuaMethodAttributes(
|
||||||
|
"drawText",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void DrawText(
|
||||||
|
object x,
|
||||||
|
object y,
|
||||||
|
string message,
|
||||||
|
object color = null,
|
||||||
|
object fontsize = null,
|
||||||
|
string fontfamily = null,
|
||||||
|
string fontstyle = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int fsize = 12;
|
var fsize = 12;
|
||||||
if (fontsize != null)
|
if (fontsize != null)
|
||||||
{
|
{
|
||||||
fsize = LuaInt(fontsize);
|
fsize = LuaInt(fontsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
FontFamily family = FontFamily.GenericMonospace;
|
var family = FontFamily.GenericMonospace;
|
||||||
if (fontfamily != null)
|
if (fontfamily != null)
|
||||||
{
|
{
|
||||||
family = new FontFamily(fontfamily.ToString());
|
family = new FontFamily(fontfamily);
|
||||||
}
|
}
|
||||||
|
|
||||||
FontStyle fstyle = FontStyle.Regular;
|
var fstyle = FontStyle.Regular;
|
||||||
if (fontstyle != null)
|
if (fontstyle != null)
|
||||||
{
|
{
|
||||||
string tmp = fontstyle.ToString().ToLower();
|
switch (fontstyle.ToLower())
|
||||||
switch (tmp)
|
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case "regular":
|
case "regular":
|
||||||
|
@ -518,8 +638,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Font font = new Font(family, fsize, fstyle, GraphicsUnit.Pixel);
|
var font = new Font(family, fsize, fstyle, GraphicsUnit.Pixel);
|
||||||
g.DrawString(message.ToString(), font, GetBrush(color ?? "white"), LuaInt(X), LuaInt(Y));
|
g.DrawString(message, font, GetBrush(color ?? "white"), LuaInt(x), LuaInt(y));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -528,10 +648,19 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_text(object luaX, object luaY, object luaStr, object background = null, object forecolor = null,
|
[LuaMethodAttributes(
|
||||||
|
"text",
|
||||||
|
"TODO"
|
||||||
|
)]
|
||||||
|
public void Text(
|
||||||
|
object x,
|
||||||
|
object y,
|
||||||
|
string message,
|
||||||
|
object background = null,
|
||||||
|
object forecolor = null,
|
||||||
object anchor = null)
|
object anchor = null)
|
||||||
{
|
{
|
||||||
DoGuiText(luaX, luaY, luaStr, false, background, forecolor, anchor);
|
DoGuiText(x, y, message, false, background, forecolor, anchor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public class EmuLuaLibrary
|
public class EmuLuaLibrary
|
||||||
{
|
{
|
||||||
private readonly FormsLuaLibrary _formsLibrary = new FormsLuaLibrary();
|
private readonly FormsLuaLibrary _formsLibrary = new FormsLuaLibrary();
|
||||||
private readonly EventLuaLibrary _eventLibrary = new EventLuaLibrary(ConsoleLuaLibrary.console_log);
|
private readonly EventLuaLibrary _eventLibrary = new EventLuaLibrary(ConsoleLuaLibrary.Log);
|
||||||
private readonly GuiLuaLibrary _guiLibrary = new GuiLuaLibrary();
|
private readonly GuiLuaLibrary _guiLibrary = new GuiLuaLibrary();
|
||||||
private readonly LuaConsole _caller;
|
private readonly LuaConsole _caller;
|
||||||
|
|
||||||
|
@ -81,8 +81,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
lua.RegisterFunction("print", this, GetType().GetMethod("Print"));
|
lua.RegisterFunction("print", this, GetType().GetMethod("Print"));
|
||||||
|
|
||||||
new BitLuaLibrary().LuaRegisterNew(lua, Docs);
|
new BitLuaLibrary().LuaRegisterNew(lua, Docs);
|
||||||
new MultiClientLuaLibrary(ConsoleLuaLibrary.console_log).LuaRegister(lua, Docs);
|
new EmuHawkLuaLibrary(ConsoleLuaLibrary.Log).LuaRegisterNew(lua, Docs);
|
||||||
new ConsoleLuaLibrary().LuaRegister(lua, Docs);
|
new ConsoleLuaLibrary().LuaRegisterNew(lua, Docs);
|
||||||
|
|
||||||
new EmulatorLuaLibrary(
|
new EmulatorLuaLibrary(
|
||||||
_lua,
|
_lua,
|
||||||
|
@ -91,8 +91,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
).LuaRegisterNew(lua, Docs);
|
).LuaRegisterNew(lua, Docs);
|
||||||
|
|
||||||
_eventLibrary.LuaRegisterNew(lua, Docs);
|
_eventLibrary.LuaRegisterNew(lua, Docs);
|
||||||
_formsLibrary.LuaRegister(lua, Docs);
|
_formsLibrary.LuaRegisterNew(lua, Docs);
|
||||||
_guiLibrary.LuaRegister(lua, Docs);
|
_guiLibrary.LuaRegisterNew(lua, Docs);
|
||||||
new InputLuaLibrary(_lua).LuaRegisterNew(lua, Docs);
|
new InputLuaLibrary(_lua).LuaRegisterNew(lua, Docs);
|
||||||
new JoypadLuaLibrary(_lua).LuaRegisterNew(lua, Docs);
|
new JoypadLuaLibrary(_lua).LuaRegisterNew(lua, Docs);
|
||||||
new MemoryLuaLibrary().LuaRegisterNew(lua, Docs);
|
new MemoryLuaLibrary().LuaRegisterNew(lua, Docs);
|
||||||
|
|
Loading…
Reference in New Issue