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
|
||||
{
|
||||
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" },
|
||||
{ 1, "x2SAI" },
|
||||
|
@ -15,20 +15,20 @@ namespace BizHawk.Client.EmuHawk
|
|||
{ 4, "Scanlines" },
|
||||
};
|
||||
|
||||
public MultiClientLuaLibrary(Action<string> logOutputCallback)
|
||||
public EmuHawkLuaLibrary(Action<string> logOutputCallback)
|
||||
: this()
|
||||
{
|
||||
LogOutputCallback = logOutputCallback;
|
||||
}
|
||||
|
||||
public MultiClientLuaLibrary() : base() { }
|
||||
public EmuHawkLuaLibrary() { }
|
||||
|
||||
public override string Name { get { return "client"; } }
|
||||
public override string[] Functions
|
||||
{
|
||||
get
|
||||
{
|
||||
return new []
|
||||
return new[]
|
||||
{
|
||||
"clearautohold",
|
||||
"closerom",
|
||||
|
@ -68,144 +68,228 @@ 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();
|
||||
}
|
||||
|
||||
public static void client_closerom()
|
||||
[LuaMethodAttributes(
|
||||
"closerom",
|
||||
"TODO"
|
||||
)]
|
||||
public static void 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 (!String.IsNullOrWhiteSpace(temp))
|
||||
if (enabled)
|
||||
{
|
||||
if (temp == "0" || temp.ToLower() == "false")
|
||||
{
|
||||
Global.Rewinder.RewindActive = false;
|
||||
GlobalWin.OSD.AddMessage("Rewind suspended");
|
||||
}
|
||||
else
|
||||
{
|
||||
Global.Rewinder.RewindActive = true;
|
||||
GlobalWin.OSD.AddMessage("Rewind enabled");
|
||||
}
|
||||
Global.Rewinder.RewindActive = true;
|
||||
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);
|
||||
if (frames > 0)
|
||||
{
|
||||
string temp = num_frames.ToString();
|
||||
int frames = Convert.ToInt32(temp);
|
||||
if (frames > 0)
|
||||
{
|
||||
Global.Config.FrameSkip = frames;
|
||||
GlobalWin.MainForm.FrameSkipMessage();
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLuaLibrary.console_log("Invalid frame skip value");
|
||||
}
|
||||
Global.Config.FrameSkip = frames;
|
||||
GlobalWin.MainForm.FrameSkipMessage();
|
||||
}
|
||||
catch
|
||||
else
|
||||
{
|
||||
ConsoleLuaLibrary.console_log("Invalid frame skip value");
|
||||
ConsoleLuaLibrary.Log("Invalid frame skip value");
|
||||
}
|
||||
}
|
||||
|
||||
public string client_getdisplayfilter()
|
||||
[LuaMethodAttributes(
|
||||
"getdisplayfilter",
|
||||
"TODO"
|
||||
)]
|
||||
public string GetDisplayFilter()
|
||||
{
|
||||
return _filterMappings[Global.Config.TargetDisplayFilter];
|
||||
}
|
||||
|
||||
public static int client_gettargetscanlineintensity()
|
||||
[LuaMethodAttributes(
|
||||
"gettargetscanlineintensity",
|
||||
"TODO"
|
||||
)]
|
||||
public static int GetTargetScanlineIntensity()
|
||||
{
|
||||
return Global.Config.TargetScanlineFilterIntensity;
|
||||
}
|
||||
|
||||
public static int client_getwindowsize()
|
||||
[LuaMethodAttributes(
|
||||
"getwindowsize",
|
||||
"TODO"
|
||||
)]
|
||||
public static int GetWindowSize()
|
||||
{
|
||||
return Global.Config.TargetZoomFactor;
|
||||
}
|
||||
|
||||
public static bool client_ispaused()
|
||||
[LuaMethodAttributes(
|
||||
"ispaused",
|
||||
"TODO"
|
||||
)]
|
||||
public static bool IsPaused()
|
||||
{
|
||||
return GlobalWin.MainForm.EmulatorPaused;
|
||||
}
|
||||
|
||||
public static void client_opencheats()
|
||||
[LuaMethodAttributes(
|
||||
"opencheats",
|
||||
"TODO"
|
||||
)]
|
||||
public static void OpenCheats()
|
||||
{
|
||||
GlobalWin.Tools.Load<Cheats>();
|
||||
}
|
||||
|
||||
public static void client_openhexeditor()
|
||||
[LuaMethodAttributes(
|
||||
"openhexeditor",
|
||||
"TODO"
|
||||
)]
|
||||
public static void OpenHexEditor()
|
||||
{
|
||||
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>();
|
||||
}
|
||||
|
||||
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>();
|
||||
}
|
||||
|
||||
public static void client_opentoolbox()
|
||||
[LuaMethodAttributes(
|
||||
"opentoolbox",
|
||||
"TODO"
|
||||
)]
|
||||
public static void OpenToolBox()
|
||||
{
|
||||
GlobalWin.Tools.Load<ToolBox>();
|
||||
}
|
||||
|
||||
public static void client_opentracelogger()
|
||||
[LuaMethodAttributes(
|
||||
"opentracelogger",
|
||||
"TODO"
|
||||
)]
|
||||
public static void OpenTraceLogger()
|
||||
{
|
||||
GlobalWin.Tools.LoadTraceLogger();
|
||||
}
|
||||
|
||||
public static void client_paint()
|
||||
[LuaMethodAttributes(
|
||||
"paint",
|
||||
"TODO"
|
||||
)]
|
||||
public static void Paint()
|
||||
{
|
||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||
}
|
||||
|
||||
public static void client_pause()
|
||||
[LuaMethodAttributes(
|
||||
"pause",
|
||||
"TODO"
|
||||
)]
|
||||
public static void Pause()
|
||||
{
|
||||
GlobalWin.MainForm.PauseEmulator();
|
||||
}
|
||||
|
||||
public static void client_pause_av()
|
||||
[LuaMethodAttributes(
|
||||
"pause_av",
|
||||
"TODO"
|
||||
)]
|
||||
public static void PauseAv()
|
||||
{
|
||||
GlobalWin.MainForm.PauseAVI = true;
|
||||
}
|
||||
|
||||
public static void client_reboot_core()
|
||||
[LuaMethodAttributes(
|
||||
"reboot_core",
|
||||
"TODO"
|
||||
)]
|
||||
public static void RebootCore()
|
||||
{
|
||||
GlobalWin.MainForm.RebootCore();
|
||||
}
|
||||
|
||||
public static int client_screenheight()
|
||||
[LuaMethodAttributes(
|
||||
"screenheight",
|
||||
"TODO"
|
||||
)]
|
||||
public static int ScreenHeight()
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -213,16 +297,24 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
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();
|
||||
}
|
||||
|
||||
public void client_setdisplayfilter(string filter)
|
||||
[LuaMethodAttributes(
|
||||
"setdisplayfilter",
|
||||
"TODO"
|
||||
)]
|
||||
public void SetDisplayFilter(string filter)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
public static int client_screenwidth()
|
||||
[LuaMethodAttributes(
|
||||
"screenwidth",
|
||||
"TODO"
|
||||
)]
|
||||
public static int ScreenWidth()
|
||||
{
|
||||
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();
|
||||
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.OSD.AddMessage("Window size set to " + size.ToString() + "x");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LogOutputCallback != null)
|
||||
{
|
||||
LogOutputCallback("Invalid window size");
|
||||
}
|
||||
}
|
||||
Global.Config.TargetZoomFactor = s;
|
||||
GlobalWin.MainForm.FrameBufferResized();
|
||||
GlobalWin.OSD.AddMessage("Window size set to " + s + "x");
|
||||
}
|
||||
catch
|
||||
else
|
||||
{
|
||||
LogOutputCallback("Invalid window size");
|
||||
Log("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);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLuaLibrary.console_log("Invalid speed value");
|
||||
}
|
||||
GlobalWin.MainForm.ClickSpeedItem(speed);
|
||||
}
|
||||
catch
|
||||
else
|
||||
{
|
||||
ConsoleLuaLibrary.console_log("Invalid speed value");
|
||||
Log("Invalid speed value");
|
||||
}
|
||||
}
|
||||
|
||||
public static void client_togglepause()
|
||||
[LuaMethodAttributes(
|
||||
"togglepause",
|
||||
"TODO"
|
||||
)]
|
||||
public static void TogglePause()
|
||||
{
|
||||
GlobalWin.MainForm.TogglePause();
|
||||
}
|
||||
|
||||
public static void client_unpause()
|
||||
[LuaMethodAttributes(
|
||||
"unpause",
|
||||
"TODO"
|
||||
)]
|
||||
public static void Unpause()
|
||||
{
|
||||
GlobalWin.MainForm.UnpauseEmulator();
|
||||
}
|
||||
|
||||
public static void client_unpause_av()
|
||||
[LuaMethodAttributes(
|
||||
"unpause_av",
|
||||
"TODO"
|
||||
)]
|
||||
public static void UnpauseAv()
|
||||
{
|
||||
GlobalWin.MainForm.PauseAVI = false;
|
||||
}
|
||||
|
||||
public static int client_xpos()
|
||||
[LuaMethodAttributes(
|
||||
"xpos",
|
||||
"TODO"
|
||||
)]
|
||||
public static int Xpos()
|
||||
{
|
||||
return GlobalWin.MainForm.DesktopLocation.X;
|
||||
}
|
||||
|
||||
public static int client_ypos()
|
||||
[LuaMethodAttributes(
|
||||
"ypos",
|
||||
"TODO"
|
||||
)]
|
||||
public static int Ypos()
|
||||
{
|
||||
return GlobalWin.MainForm.DesktopLocation.Y;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using LuaInterface;
|
||||
using BizHawk.Client.Common;
|
||||
using LuaInterface;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -19,58 +19,66 @@ namespace BizHawk.Client.EmuHawk
|
|||
"clear",
|
||||
"getluafunctionslist",
|
||||
"log",
|
||||
"output",
|
||||
"output"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static void console_clear()
|
||||
[LuaMethodAttributes(
|
||||
"clear",
|
||||
"TODO"
|
||||
)]
|
||||
public static void Clear()
|
||||
{
|
||||
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)
|
||||
{
|
||||
list.AppendLine(function.Name);
|
||||
}
|
||||
|
||||
return list.ToString();
|
||||
}
|
||||
|
||||
public static void console_log(object lua_input)
|
||||
[LuaMethodAttributes(
|
||||
"log",
|
||||
"TODO"
|
||||
)]
|
||||
public static void Log(object output)
|
||||
{
|
||||
console_output(lua_input);
|
||||
}
|
||||
|
||||
public static void console_output(object lua_input)
|
||||
{
|
||||
if (lua_input == null)
|
||||
if (output == null)
|
||||
{
|
||||
GlobalWin.Tools.LuaConsole.WriteToOutputWindow("NULL");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lua_input is LuaTable)
|
||||
if (output is LuaTable)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var lti = (lua_input as LuaTable);
|
||||
var sb = new StringBuilder();
|
||||
var lti = output as LuaTable;
|
||||
|
||||
List<string> 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 keys = (from object key in lti.Keys select key.ToString()).ToList();
|
||||
var values = (from object value in lti.Values select value.ToString()).ToList();
|
||||
|
||||
List<KeyValuePair<string, string>> KVPs = new List<KeyValuePair<string, string>>();
|
||||
for (int i = 0; i < Keys.Count; i++)
|
||||
var kvps = new List<KeyValuePair<string, string>>();
|
||||
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(kvp);
|
||||
kvps.Add(new KeyValuePair<string, string>(keys[i], values[i]));
|
||||
}
|
||||
}
|
||||
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
|
||||
.Append("\"")
|
||||
|
@ -85,7 +93,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
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.Windows.Forms;
|
||||
|
||||
using LuaInterface;
|
||||
using BizHawk.Client.Common;
|
||||
using LuaInterface;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
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[] Functions
|
||||
{
|
||||
|
@ -46,7 +47,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void WindowClosed(IntPtr handle)
|
||||
{
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
if (form.Handle == handle)
|
||||
{
|
||||
|
@ -58,35 +59,41 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private LuaWinform GetForm(object formHandle)
|
||||
{
|
||||
IntPtr ptr = new IntPtr(LuaInt(formHandle));
|
||||
var ptr = new IntPtr(LuaInt(formHandle));
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -96,80 +103,106 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
#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));
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
var ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
foreach (Control control in form.Controls)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
LuaButton button = new LuaButton();
|
||||
var button = new LuaButton();
|
||||
SetText(button, caption);
|
||||
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);
|
||||
|
||||
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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
LuaCheckbox checkbox = new LuaCheckbox();
|
||||
var checkbox = new LuaCheckbox();
|
||||
form.Controls.Add(checkbox);
|
||||
SetText(checkbox, caption);
|
||||
SetLocation(checkbox, X, Y);
|
||||
|
||||
SetLocation(checkbox, x, y);
|
||||
|
||||
return (int)checkbox.Handle;
|
||||
}
|
||||
|
||||
public void forms_clearclicks(object handle)
|
||||
[LuaMethodAttributes(
|
||||
"clearclicks",
|
||||
"TODO"
|
||||
)]
|
||||
public void ClearClicks(object handle)
|
||||
{
|
||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
var ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
foreach (Control control in form.Controls)
|
||||
{
|
||||
if (control.Handle == ptr)
|
||||
{
|
||||
List<LuaWinform.LuaEvent> lua_events = form.ControlEvents.Where(x => x.Control == ptr).ToList();
|
||||
foreach (LuaWinform.LuaEvent levent in lua_events)
|
||||
var luaEvents = form.ControlEvents.Where(x => x.Control == ptr).ToList();
|
||||
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));
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
var ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
if (form.Handle == ptr)
|
||||
{
|
||||
|
@ -178,42 +211,61 @@ namespace BizHawk.Client.EmuHawk
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void forms_destroyall()
|
||||
[LuaMethodAttributes(
|
||||
"destroyall",
|
||||
"TODO"
|
||||
)]
|
||||
public void DestroyAll()
|
||||
{
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
form.Close();
|
||||
_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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<string> dropdownItems = items.Values.Cast<string>().ToList();
|
||||
var dropdownItems = items.Values.Cast<string>().ToList();
|
||||
dropdownItems.Sort();
|
||||
|
||||
LuaDropDown dropdown = new LuaDropDown(dropdownItems);
|
||||
var dropdown = new LuaDropDown(dropdownItems);
|
||||
form.Controls.Add(dropdown);
|
||||
SetLocation(dropdown, X, Y);
|
||||
SetLocation(dropdown, x, y);
|
||||
SetSize(dropdown, width, height);
|
||||
return (int)dropdown.Handle;
|
||||
}
|
||||
|
||||
public string forms_getproperty(object handle, object property)
|
||||
[LuaMethodAttributes(
|
||||
"getproperty",
|
||||
"TODO"
|
||||
)]
|
||||
public string GetProperty(object handle, object property)
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
var ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
if (form.Handle == ptr)
|
||||
{
|
||||
|
@ -233,18 +285,22 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleLuaLibrary.console_output(ex.Message);
|
||||
ConsoleLuaLibrary.Log(ex.Message);
|
||||
}
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
public string forms_gettext(object handle)
|
||||
[LuaMethodAttributes(
|
||||
"gettext",
|
||||
"TODO"
|
||||
)]
|
||||
public string GetText(object handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
var ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
if (form.Handle == ptr)
|
||||
{
|
||||
|
@ -271,18 +327,22 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleLuaLibrary.console_output(ex.Message);
|
||||
ConsoleLuaLibrary.Log(ex.Message);
|
||||
}
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
public bool forms_ischecked(object handle)
|
||||
[LuaMethodAttributes(
|
||||
"ischecked",
|
||||
"TODO"
|
||||
)]
|
||||
public bool IsChecked(object handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
var ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
if (form.Handle == ptr)
|
||||
{
|
||||
|
@ -309,62 +369,79 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleLuaLibrary.console_output(ex.Message);
|
||||
ConsoleLuaLibrary.Log(ex.Message);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Label label = new Label();
|
||||
var label = new Label();
|
||||
SetText(label, caption);
|
||||
form.Controls.Add(label);
|
||||
SetLocation(label, X, Y);
|
||||
SetLocation(label, x, y);
|
||||
SetSize(label, width, height);
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
LuaWinform theForm = new LuaWinform();
|
||||
_luaForms.Add(theForm);
|
||||
if (Width != null && Height != null)
|
||||
var form = new LuaWinform();
|
||||
_luaForms.Add(form);
|
||||
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;
|
||||
theForm.Show();
|
||||
return (int)theForm.Handle;
|
||||
form.Text = title;
|
||||
form.Show();
|
||||
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 (*.*)|*.*"
|
||||
OpenFileDialog openFileDialog1 = new OpenFileDialog();
|
||||
if (InitialDirectory != null)
|
||||
var openFileDialog1 = new OpenFileDialog();
|
||||
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.Filter = Filter;
|
||||
openFileDialog1.Filter = filter;
|
||||
}
|
||||
|
||||
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));
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
var ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
if (form.Handle == ptr)
|
||||
{
|
||||
SetLocation(form, X, Y);
|
||||
SetLocation(form, x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -392,17 +473,21 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
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));
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
var ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
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));
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
var ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
if (form.Handle == ptr)
|
||||
{
|
||||
SetSize(form, Width, Height);
|
||||
SetSize(form, width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -436,17 +525,21 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
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));
|
||||
foreach (LuaWinform form in _luaForms)
|
||||
var ptr = new IntPtr(LuaInt(handle));
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
LuaTextBox textbox = new LuaTextBox();
|
||||
var textbox = new LuaTextBox();
|
||||
if (fixedWidth)
|
||||
{
|
||||
textbox.Font = new Font("Courier New", 8);
|
||||
|
@ -481,7 +587,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
textbox.Multiline = multiline;
|
||||
SetText(textbox, caption);
|
||||
SetLocation(textbox, X, Y);
|
||||
SetLocation(textbox, x, y);
|
||||
SetSize(textbox, width, height);
|
||||
|
||||
if (boxtype != null)
|
||||
|
@ -504,6 +610,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
form.Controls.Add(textbox);
|
||||
return (int)textbox.Handle;
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ using System.Collections.Generic;
|
|||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
|
||||
using LuaInterface;
|
||||
using BizHawk.Client.Common;
|
||||
using LuaInterface;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
"drawRectangle",
|
||||
"drawString",
|
||||
"drawText",
|
||||
"text",
|
||||
"text"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -42,15 +42,22 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var brush in SolidBrushes.Values) brush.Dispose();
|
||||
foreach (var brush in Pens.Values) brush.Dispose();
|
||||
foreach (var brush in _solidBrushes.Values)
|
||||
{
|
||||
brush.Dispose();
|
||||
}
|
||||
|
||||
foreach (var brush in _pens.Values)
|
||||
{
|
||||
brush.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public bool SurfaceIsNull
|
||||
{
|
||||
get
|
||||
{
|
||||
return luaSurface == null;
|
||||
return _luaSurface == null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,12 +70,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// </summary>
|
||||
public void DrawNew()
|
||||
{
|
||||
luaSurface = GlobalWin.DisplayManager.GetLuaSurfaceNative();
|
||||
_luaSurface = GlobalWin.DisplayManager.GetLuaSurfaceNative();
|
||||
}
|
||||
|
||||
public void DrawNewEmu()
|
||||
{
|
||||
luaSurface = GlobalWin.DisplayManager.GetLuaEmuSurfaceEmu();
|
||||
_luaSurface = GlobalWin.DisplayManager.GetLuaEmuSurfaceEmu();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -78,23 +85,25 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// </summary>
|
||||
public void DrawFinish()
|
||||
{
|
||||
GlobalWin.DisplayManager.SetLuaSurfaceNativePreOSD(luaSurface);
|
||||
luaSurface = null;
|
||||
GlobalWin.DisplayManager.SetLuaSurfaceNativePreOSD(_luaSurface);
|
||||
_luaSurface = null;
|
||||
}
|
||||
|
||||
public void DrawFinishEmu()
|
||||
{
|
||||
GlobalWin.DisplayManager.SetLuaSurfaceEmu(luaSurface);
|
||||
luaSurface = null;
|
||||
GlobalWin.DisplayManager.SetLuaSurfaceEmu(_luaSurface);
|
||||
_luaSurface = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
private DisplaySurface luaSurface;
|
||||
private readonly Dictionary<Color, SolidBrush> SolidBrushes = new Dictionary<Color, SolidBrush>();
|
||||
private readonly Dictionary<Color, Pen> Pens = new Dictionary<Color, Pen>();
|
||||
private readonly Dictionary<Color, SolidBrush> _solidBrushes = new Dictionary<Color, SolidBrush>();
|
||||
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)
|
||||
{
|
||||
|
@ -110,72 +119,93 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private SolidBrush GetBrush(object color)
|
||||
{
|
||||
Color c = GetColor(color);
|
||||
var c = GetColor(color);
|
||||
SolidBrush b;
|
||||
if (!SolidBrushes.TryGetValue(c, out b))
|
||||
if (!_solidBrushes.TryGetValue(c, out b))
|
||||
{
|
||||
b = new SolidBrush(c);
|
||||
SolidBrushes[c] = b;
|
||||
_solidBrushes[c] = b;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
private Pen GetPen(object color)
|
||||
{
|
||||
Color c = GetColor(color);
|
||||
var c = GetColor(color);
|
||||
Pen p;
|
||||
if (!Pens.TryGetValue(c, out p))
|
||||
if (!_pens.TryGetValue(c, out p))
|
||||
{
|
||||
p = new Pen(c);
|
||||
Pens[c] = p;
|
||||
_pens[c] = p;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
Bitmap nullGraphicsBitmap = new Bitmap(1, 1);
|
||||
private Graphics GetGraphics()
|
||||
{
|
||||
Graphics g;
|
||||
if (luaSurface == null)
|
||||
g = Graphics.FromImage(nullGraphicsBitmap);
|
||||
else g = luaSurface.GetGraphics();
|
||||
int tx = Global.Emulator.CoreComm.ScreenLogicalOffsetX;
|
||||
int ty = Global.Emulator.CoreComm.ScreenLogicalOffsetY;
|
||||
var g = _luaSurface == null ? Graphics.FromImage(_nullGraphicsBitmap) : _luaSurface.GetGraphics();
|
||||
|
||||
var tx = Global.Emulator.CoreComm.ScreenLogicalOffsetX;
|
||||
var ty = Global.Emulator.CoreComm.ScreenLogicalOffsetY;
|
||||
if (tx != 0 || ty != 0)
|
||||
{
|
||||
var transform = g.Transform;
|
||||
transform.Translate(-tx, -ty);
|
||||
g.Transform = transform;
|
||||
}
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
private void DoGuiText(object luaX, object luaY, object luaStr, bool alert, object background = null,
|
||||
object forecolor = null, object anchor = null)
|
||||
private static void DoGuiText(
|
||||
object x,
|
||||
object y,
|
||||
string message,
|
||||
bool alert,
|
||||
object background = null,
|
||||
object forecolor = null,
|
||||
object anchor = null)
|
||||
{
|
||||
if (!alert)
|
||||
{
|
||||
if (forecolor == null)
|
||||
{
|
||||
forecolor = "white";
|
||||
}
|
||||
|
||||
if (background == null)
|
||||
{
|
||||
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)
|
||||
{
|
||||
int x;
|
||||
if (int.TryParse(anchor.ToString(), out x) == false)
|
||||
int dummy;
|
||||
if (int.TryParse(anchor.ToString(), out dummy) == false)
|
||||
{
|
||||
if (anchor.ToString().ToLower() == "topleft")
|
||||
{
|
||||
a = 0;
|
||||
}
|
||||
else if (anchor.ToString().ToLower() == "topright")
|
||||
{
|
||||
a = 1;
|
||||
}
|
||||
else if (anchor.ToString().ToLower() == "bottomleft")
|
||||
{
|
||||
a = 2;
|
||||
}
|
||||
else if (anchor.ToString().ToLower() == "bottomright")
|
||||
{
|
||||
a = 3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -187,54 +217,78 @@ namespace BizHawk.Client.EmuHawk
|
|||
dx -= Global.Emulator.CoreComm.ScreenLogicalOffsetX;
|
||||
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
|
||||
|
||||
public void gui_addmessage(object luaStr)
|
||||
[LuaMethodAttributes(
|
||||
"addmessage",
|
||||
"TODO"
|
||||
)]
|
||||
public void AddMessage(object luaStr)
|
||||
{
|
||||
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;
|
||||
luaSurface.Clear();
|
||||
_luaSurface.Clear();
|
||||
}
|
||||
|
||||
public static void gui_cleartext()
|
||||
[LuaMethodAttributes(
|
||||
"cleartext",
|
||||
"TODO"
|
||||
)]
|
||||
public static void ClearText()
|
||||
{
|
||||
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;
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
try
|
||||
{
|
||||
Point[] Points = new Point[4];
|
||||
int i = 0;
|
||||
var pointsArr = new Point[4];
|
||||
|
||||
var i = 0;
|
||||
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++;
|
||||
if (i >= 4)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -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())
|
||||
{
|
||||
try
|
||||
{
|
||||
int int_x = LuaInt(X);
|
||||
int int_y = LuaInt(Y);
|
||||
int int_width = LuaInt(X2);
|
||||
int int_height = LuaInt(Y2);
|
||||
var intX = LuaInt(x);
|
||||
var intY = LuaInt(y);
|
||||
var intWidth = LuaInt(x2);
|
||||
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
|
||||
{
|
||||
int_width = int_x - int_width;
|
||||
int_x -= int_width;
|
||||
intWidth = intX - intWidth;
|
||||
intX -= intWidth;
|
||||
}
|
||||
|
||||
if (int_y < int_height)
|
||||
if (intY < intHeight)
|
||||
{
|
||||
int_height = Math.Abs(int_y - int_height);
|
||||
intHeight = Math.Abs(intY - intHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
int_height = int_y - int_height;
|
||||
int_y -= int_height;
|
||||
intHeight = intY - intHeight;
|
||||
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)
|
||||
{
|
||||
g.FillRectangle(GetBrush(background), int_x, int_y, int_width, int_height);
|
||||
g.FillRectangle(GetBrush(background), intX, intY, intWidth, intHeight);
|
||||
}
|
||||
}
|
||||
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;
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
@ -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;
|
||||
using (var g = GetGraphics())
|
||||
|
@ -320,11 +386,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
Icon icon;
|
||||
if (width != null && height != null)
|
||||
{
|
||||
icon = new Icon(Path.ToString(), LuaInt(width), LuaInt(height));
|
||||
icon = new Icon(path, LuaInt(width), LuaInt(height));
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = new Icon(Path.ToString());
|
||||
icon = new Icon(path);
|
||||
}
|
||||
|
||||
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;
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
try
|
||||
{
|
||||
Image img = Image.FromFile(Path.ToString());
|
||||
var img = Image.FromFile(path);
|
||||
|
||||
if (width == null || width.GetType() != typeof(int))
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -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;
|
||||
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,
|
||||
object line, object background = null)
|
||||
[LuaMethodAttributes(
|
||||
"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;
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
@ -398,16 +488,18 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void gui_drawPixel(object X, object Y, object color = null)
|
||||
[LuaMethodAttributes(
|
||||
"drawPixel",
|
||||
"TODO"
|
||||
)]
|
||||
public void DrawPixel(object x, object y, object color = null)
|
||||
{
|
||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
float x = LuaInt(X) + 0.1F;
|
||||
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)
|
||||
{
|
||||
|
@ -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;
|
||||
//this is a test
|
||||
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
try
|
||||
{
|
||||
Point[] Points = new Point[points.Values.Count];
|
||||
int i = 0;
|
||||
var pointsArr = new Point[points.Values.Count];
|
||||
var i = 0;
|
||||
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++;
|
||||
}
|
||||
|
||||
g.DrawPolygon(GetPen(line), Points);
|
||||
g.DrawPolygon(GetPen(line), pointsArr);
|
||||
if (background != null)
|
||||
{
|
||||
var brush = GetBrush(background);
|
||||
g.FillPolygon(brush, Points);
|
||||
g.FillPolygon(GetBrush(background), pointsArr);
|
||||
}
|
||||
}
|
||||
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())
|
||||
{
|
||||
try
|
||||
{
|
||||
int int_x = LuaInt(X);
|
||||
int int_y = LuaInt(Y);
|
||||
int int_width = LuaInt(width);
|
||||
int int_height = LuaInt(height);
|
||||
g.DrawRectangle(GetPen(line ?? "white"), int_x, int_y, int_width, int_height);
|
||||
var intX = LuaInt(x);
|
||||
var intY = LuaInt(y);
|
||||
var intWidth = LuaInt(width);
|
||||
var intHeight = LuaInt(height);
|
||||
g.DrawRectangle(GetPen(line ?? "white"), intX, intY, intWidth, intHeight);
|
||||
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)
|
||||
|
@ -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;
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
try
|
||||
{
|
||||
int fsize = 12;
|
||||
var fsize = 12;
|
||||
if (fontsize != null)
|
||||
{
|
||||
fsize = LuaInt(fontsize);
|
||||
}
|
||||
|
||||
FontFamily family = FontFamily.GenericMonospace;
|
||||
var family = FontFamily.GenericMonospace;
|
||||
if (fontfamily != null)
|
||||
{
|
||||
family = new FontFamily(fontfamily.ToString());
|
||||
family = new FontFamily(fontfamily);
|
||||
}
|
||||
|
||||
FontStyle fstyle = FontStyle.Regular;
|
||||
var fstyle = FontStyle.Regular;
|
||||
if (fontstyle != null)
|
||||
{
|
||||
string tmp = fontstyle.ToString().ToLower();
|
||||
switch (tmp)
|
||||
switch (fontstyle.ToLower())
|
||||
{
|
||||
default:
|
||||
case "regular":
|
||||
|
@ -518,8 +638,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
Font font = new Font(family, fsize, fstyle, GraphicsUnit.Pixel);
|
||||
g.DrawString(message.ToString(), font, GetBrush(color ?? "white"), LuaInt(X), LuaInt(Y));
|
||||
var font = new Font(family, fsize, fstyle, GraphicsUnit.Pixel);
|
||||
g.DrawString(message, font, GetBrush(color ?? "white"), LuaInt(x), LuaInt(y));
|
||||
}
|
||||
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,
|
||||
object anchor = null)
|
||||
[LuaMethodAttributes(
|
||||
"text",
|
||||
"TODO"
|
||||
)]
|
||||
public void Text(
|
||||
object x,
|
||||
object y,
|
||||
string message,
|
||||
object background = null,
|
||||
object forecolor = 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
|
||||
{
|
||||
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 LuaConsole _caller;
|
||||
|
||||
|
@ -81,8 +81,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
lua.RegisterFunction("print", this, GetType().GetMethod("Print"));
|
||||
|
||||
new BitLuaLibrary().LuaRegisterNew(lua, Docs);
|
||||
new MultiClientLuaLibrary(ConsoleLuaLibrary.console_log).LuaRegister(lua, Docs);
|
||||
new ConsoleLuaLibrary().LuaRegister(lua, Docs);
|
||||
new EmuHawkLuaLibrary(ConsoleLuaLibrary.Log).LuaRegisterNew(lua, Docs);
|
||||
new ConsoleLuaLibrary().LuaRegisterNew(lua, Docs);
|
||||
|
||||
new EmulatorLuaLibrary(
|
||||
_lua,
|
||||
|
@ -91,8 +91,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
).LuaRegisterNew(lua, Docs);
|
||||
|
||||
_eventLibrary.LuaRegisterNew(lua, Docs);
|
||||
_formsLibrary.LuaRegister(lua, Docs);
|
||||
_guiLibrary.LuaRegister(lua, Docs);
|
||||
_formsLibrary.LuaRegisterNew(lua, Docs);
|
||||
_guiLibrary.LuaRegisterNew(lua, Docs);
|
||||
new InputLuaLibrary(_lua).LuaRegisterNew(lua, Docs);
|
||||
new JoypadLuaLibrary(_lua).LuaRegisterNew(lua, Docs);
|
||||
new MemoryLuaLibrary().LuaRegisterNew(lua, Docs);
|
||||
|
|
Loading…
Reference in New Issue