Lua - more documentation and more strong typing of parameters, more fixups to display of parameter types in the Lua functions list

This commit is contained in:
adelikat 2014-01-27 03:16:05 +00:00
parent be49f6fa33
commit 7417ea7b8f
7 changed files with 242 additions and 281 deletions

View File

@ -93,9 +93,9 @@ namespace BizHawk.Client.Common
"set",
"Sets the bit 'pos' in 'num'"
)]
public static uint Set(object num, object pos)
public static uint Set(int num, int pos)
{
return (uint)(LuaInt(num) | 1 << LuaInt(pos));
return (uint)(num | 1 << pos);
}
[LuaMethodAttributes(

View File

@ -9,9 +9,9 @@ namespace BizHawk.Client.Common
"hex",
"Converts the number to a string representation of the hexadecimal value of the given number"
)]
public static string Hex(object num)
public static string Hex(long num)
{
var hex = String.Format("{0:X}", LuaLong(num));
var hex = String.Format("{0:X}", num);
if (hex.Length == 1)
{
hex = "0" + hex;
@ -24,9 +24,9 @@ namespace BizHawk.Client.Common
"binary",
"Converts the number to a string representation of the binary value of the given number"
)]
public static string Binary(object num)
public static string Binary(long num)
{
var binary = Convert.ToString(LuaLong(num), 2);
var binary = Convert.ToString(num, 2);
binary = binary.TrimStart('0');
return binary;
}
@ -35,9 +35,9 @@ namespace BizHawk.Client.Common
"octal",
"Converts the number to a string representation of the octal value of the given number"
)]
public static string Octal(object num)
public static string Octal(long num)
{
var octal = Convert.ToString(LuaLong(num), 8);
var octal = Convert.ToString(num, 8);
if (octal.Length == 1)
{
octal = "0" + octal;

View File

@ -83,16 +83,33 @@ namespace BizHawk.Client.Common
list.Append('(');
for (var i = 0; i < Parameters.Count; i++)
{
if (Parameters[i].Contains("Nullable"))
{
int x = 0;
}
var param =
Parameters[i].Replace("System", String.Empty)
.Replace("Object", String.Empty)
.Replace(" ", String.Empty)
.Replace(".", String.Empty)
.Replace("LuaInterface", String.Empty)
.Replace("Object", "object ")
.Replace("Boolean", "bool ")
.Replace("String", "string ")
.Replace("LuaTable", "table ")
.Replace("LuaFunction", "func ");
.Replace("LuaFunction", "func ")
.Replace("Nullable`1[Int32]", "int? ")
.Replace("Nullable`1[UInt32]", "uint? ")
.Replace("Byte", "byte ")
.Replace("Int16", "short ")
.Replace("Int32", "int ")
.Replace("Int64", "long ")
.Replace("Ushort", "ushort ")
.Replace("Ulong", "ulong ")
.Replace("UInt32", "uint ")
.Replace("UInt64", "ulong ")
.Replace("Double", "double ")
.Replace("Uint", "uint ");
list.Append(param);
if (i < Parameters.Count - 1)

View File

@ -42,16 +42,6 @@ namespace BizHawk.Client.Common
return (uint)(double)luaArg;
}
protected static long LuaLong(object luaArg)
{
return (long)(double)luaArg;
}
protected static ulong LuaULong(object luaArg)
{
return (ulong)(double)luaArg;
}
/// <summary>
/// LuaInterface requires the exact match of parameter count, except optional parameters.
/// So, if you want to support variable arguments, declare them as optional and pass

View File

@ -37,7 +37,7 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"log",
"Outputs the given string to the output box on the Lua Console dialog. Note: Can accept a LuaTable"
"Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable"
)]
public static void Log(object output)
{

View File

@ -30,59 +30,36 @@ namespace BizHawk.Client.EmuHawk
}
}
private LuaWinform GetForm(object formHandle)
private LuaWinform GetForm(int formHandle)
{
var ptr = new IntPtr(LuaInt(formHandle));
var ptr = new IntPtr(formHandle);
return _luaForms.FirstOrDefault(form => form.Handle == ptr);
}
private static void SetLocation(Control control, object x, object y)
private static void SetLocation(Control control, int x, int y)
{
try
{
if (x != null && y != null)
{
control.Location = new Point(LuaInt(x), LuaInt(y));
}
}
catch (Exception ex)
{
ConsoleLuaLibrary.Log(ex.Message);
}
control.Location = new Point(x, y);
}
private static void SetSize(Control control, object width, object height)
private static void SetSize(Control control, int width, int height)
{
try
{
if (width != null && height != null)
{
control.Size = new Size(LuaInt(width), LuaInt(height));
}
}
catch (Exception ex)
{
ConsoleLuaLibrary.Log(ex.Message);
}
control.Size = new Size(width, height);
}
private static void SetText(Control control, object caption)
private static void SetText(Control control, string caption)
{
if (caption != null)
{
control.Text = caption.ToString();
}
control.Text = caption ?? string.Empty;
}
#endregion
[LuaMethodAttributes(
"addclick",
"TODO"
"adds the given lua function as a click event to the given control"
)]
public void AddClick(object handle, LuaFunction clickEvent)
public void AddClick(int handle, LuaFunction clickEvent)
{
var ptr = new IntPtr(LuaInt(handle));
var ptr = new IntPtr(handle);
foreach (var form in _luaForms)
{
foreach (Control control in form.Controls)
@ -97,16 +74,16 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"button",
"TODO"
"Creates a button control on the given form. The caption property will be the text value on the button. clickEvent is the name of a Lua function that will be invoked when the button is clicked. x, and y are the optional location parameters for the position of the button within the given form. The function returns the handle of the created button. Width and Height are optional, if not specified they will be a default size"
)]
public int Button(
object formHandle,
object caption,
int formHandle,
string caption,
LuaFunction clickEvent,
object x = null,
object y = null,
object width = null,
object height = null)
int? x = null,
int? y = null,
int? width = null,
int? height = null)
{
var form = GetForm(formHandle);
if (form == null)
@ -119,17 +96,24 @@ namespace BizHawk.Client.EmuHawk
form.Controls.Add(button);
form.ControlEvents.Add(new LuaWinform.LuaEvent(button.Handle, clickEvent));
SetLocation(button, x, y);
SetSize(button, width, height);
if (x.HasValue && y.HasValue)
{
SetLocation(button, x.Value, y.Value);
}
if (width.HasValue && height.HasValue)
{
SetSize(button, width.Value, height.Value);
}
return (int)button.Handle;
}
[LuaMethodAttributes(
"checkbox",
"TODO"
"Creates a checkbox control on the given form. The caption property will be the text of the checkbox. x and y are the optional location parameters for the position of the checkbox within the form"
)]
public int Checkbox(object formHandle, string caption, object x = null, object y = null)
public int Checkbox(int formHandle, string caption, int? x = null, int? y = null)
{
var form = GetForm(formHandle);
if (form == null)
@ -140,18 +124,22 @@ namespace BizHawk.Client.EmuHawk
var checkbox = new LuaCheckbox();
form.Controls.Add(checkbox);
SetText(checkbox, caption);
SetLocation(checkbox, x, y);
if (x.HasValue && y.HasValue)
{
SetLocation(checkbox, x.Value, y.Value);
}
return (int)checkbox.Handle;
}
[LuaMethodAttributes(
"clearclicks",
"TODO"
"Removes all click events from the given widget at the specified handle"
)]
public void ClearClicks(object handle)
public void ClearClicks(int handle)
{
var ptr = new IntPtr(LuaInt(handle));
var ptr = new IntPtr(handle);
foreach (var form in _luaForms)
{
foreach (Control control in form.Controls)
@ -170,11 +158,11 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"destroy",
"TODO"
"Closes and removes a Lua created form with the specified handle. If a dialog was found and removed true is returned, else false"
)]
public bool Destroy(object handle)
public bool Destroy(int handle)
{
var ptr = new IntPtr(LuaInt(handle));
var ptr = new IntPtr(handle);
foreach (var form in _luaForms)
{
if (form.Handle == ptr)
@ -190,7 +178,7 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"destroyall",
"TODO"
"Closes and removes all Lua created dialogs"
)]
public void DestroyAll()
{
@ -203,15 +191,15 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"dropdown",
"TODO"
"Creates a dropdown (with a ComboBoxStyle of DropDownList) control on the given form. Dropdown items are passed via a lua table. Only the values will be pulled for the dropdown items, the keys are irrelevant. Items will be sorted alphabetically. x and y are the optional location parameters, and width and height are the optional size parameters."
)]
public int Dropdown(
object formHandle,
int formHandle,
LuaTable items,
object x = null,
object y = null,
object width = null,
object height = null)
int? x = null,
int? y = null,
int? width = null,
int? height = null)
{
var form = GetForm(formHandle);
if (form == null)
@ -224,25 +212,34 @@ namespace BizHawk.Client.EmuHawk
var dropdown = new LuaDropDown(dropdownItems);
form.Controls.Add(dropdown);
SetLocation(dropdown, x, y);
SetSize(dropdown, width, height);
if (x.HasValue && y.HasValue)
{
SetLocation(dropdown, x.Value, y.Value);
}
if (width.HasValue && height.HasValue)
{
SetSize(dropdown, width.Value, height.Value);
}
return (int)dropdown.Handle;
}
[LuaMethodAttributes(
"getproperty",
"TODO"
"returns a string representation of the value of a property of the widget at the given handle"
)]
public string GetProperty(object handle, object property)
public string GetProperty(int handle, string property)
{
try
{
var ptr = new IntPtr(LuaInt(handle));
var ptr = new IntPtr(handle);
foreach (var form in _luaForms)
{
if (form.Handle == ptr)
{
return form.GetType().GetProperty(property.ToString()).GetValue(form, null).ToString();
return form.GetType().GetProperty(property).GetValue(form, null).ToString();
}
else
{
@ -250,7 +247,7 @@ namespace BizHawk.Client.EmuHawk
{
if (control.Handle == ptr)
{
return control.GetType().GetProperty(property.ToString()).GetValue(control, null).ToString();
return control.GetType().GetProperty(property).GetValue(control, null).ToString();
}
}
}
@ -266,13 +263,13 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"gettext",
"TODO"
"Returns the text property of a given form or control"
)]
public string GetText(object handle)
public string GetText(int handle)
{
try
{
var ptr = new IntPtr(LuaInt(handle));
var ptr = new IntPtr(handle);
foreach (var form in _luaForms)
{
if (form.Handle == ptr)
@ -308,57 +305,50 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"ischecked",
"TODO"
"Returns the given checkbox's checked property"
)]
public bool IsChecked(object handle)
public bool IsChecked(int handle)
{
try
var ptr = new IntPtr(handle);
foreach (var form in _luaForms)
{
var ptr = new IntPtr(LuaInt(handle));
foreach (var form in _luaForms)
if (form.Handle == ptr)
{
if (form.Handle == ptr)
return false;
}
else
{
foreach (Control control in form.Controls)
{
return false;
}
else
{
foreach (Control control in form.Controls)
if (control.Handle == ptr)
{
if (control.Handle == ptr)
if (control is LuaCheckbox)
{
if (control is LuaCheckbox)
{
return (control as LuaCheckbox).Checked;
}
else
{
return false;
}
return (control as LuaCheckbox).Checked;
}
else
{
return false;
}
}
}
}
}
catch (Exception ex)
{
ConsoleLuaLibrary.Log(ex.Message);
}
return false;
}
[LuaMethodAttributes(
"label",
"TODO"
"Creates a label control on the given form. The caption property is the text of the label. x, and y are the optional location parameters for the position of the label within the given form. The function returns the handle of the created label. Width and Height are optional, if not specified they will be a default size."
)]
public int Label(
object formHandle,
object caption,
object x = null,
object y = null,
object width = null,
object height = null)
int formHandle,
string caption,
int? x = null,
int? y = null,
int? width = null,
int? height = null)
{
var form = GetForm(formHandle);
if (form == null)
@ -369,21 +359,29 @@ namespace BizHawk.Client.EmuHawk
var label = new Label();
SetText(label, caption);
form.Controls.Add(label);
SetLocation(label, x, y);
SetSize(label, width, height);
if (x.HasValue && y.HasValue)
{
SetLocation(label, x.Value, y.Value);
}
if (width.HasValue && height.HasValue)
{
SetSize(label, width.Value, height.Value);
}
return (int)label.Handle;
}
[LuaMethodAttributes(
"newform",
"TODO"
"creates a new default dialog, if both width and height are specified it will create a dialog of the specified size. If title is specified it will be the caption of the dialog, else the dialog caption will be 'Lua Dialog'. The function will return an int representing the handle of the dialog created."
)]
public int NewForm(object width = null, object height = null, string title = null)
public int NewForm(int? width = null, int? height = null, string title = null)
{
var form = new LuaWinform();
_luaForms.Add(form);
if (width != null && height != null)
if (width.HasValue && height.HasValue)
{
form.Size = new Size(LuaInt(width), LuaInt(height));
}
@ -395,7 +393,7 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"openfile",
"TODO"
"Creates a standard openfile dialog with optional parameters for the filename, directory, and filter. The return value is the directory that the user picked. If they chose to cancel, it will return an empty string"
)]
public string OpenFile(string fileName = null, string initialDirectory = null, string filter = "All files (*.*)|*.*")
{
@ -429,11 +427,11 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"setlocation",
"TODO"
"Sets the location of a control or form by passing in the handle of the created object"
)]
public void SetLocation(object handle, object x, object y)
public void SetLocation(int handle, int x, int y)
{
var ptr = new IntPtr(LuaInt(handle));
var ptr = new IntPtr(handle);
foreach (var form in _luaForms)
{
if (form.Handle == ptr)
@ -455,16 +453,19 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"setproperty",
"TODO"
"Attempts to set the given property of the widget with the given value. Note: not all properties will be able to be represented for the control to accept"
)]
public void SetProperty(object handle, object property, object value)
public void SetProperty(int handle, string property, object value)
{
var ptr = new IntPtr(LuaInt(handle));
var ptr = new IntPtr(handle);
foreach (var form in _luaForms)
{
if (form.Handle == ptr)
{
form.GetType().GetProperty(property.ToString()).SetValue(form, Convert.ChangeType(value, form.GetType().GetProperty(property.ToString()).PropertyType), null);
form
.GetType()
.GetProperty(property)
.SetValue(form, Convert.ChangeType(value, form.GetType().GetProperty(property).PropertyType), null);
}
else
{
@ -472,7 +473,10 @@ namespace BizHawk.Client.EmuHawk
{
if (control.Handle == ptr)
{
control.GetType().GetProperty(property.ToString()).SetValue(control, Convert.ChangeType(value, form.GetType().GetProperty(property.ToString()).PropertyType), null);
control
.GetType()
.GetProperty(property)
.SetValue(control, Convert.ChangeType(value, form.GetType().GetProperty(property).PropertyType), null);
}
}
}
@ -483,9 +487,9 @@ namespace BizHawk.Client.EmuHawk
"setsize",
"TODO"
)]
public void SetSize(object handle, object width, object height)
public void SetSize(int handle, int width, int height)
{
var ptr = new IntPtr(LuaInt(handle));
var ptr = new IntPtr(handle);
foreach (var form in _luaForms)
{
if (form.Handle == ptr)
@ -507,11 +511,11 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"settext",
"TODO"
"Sets the text property of a control or form by passing in the handle of the created object"
)]
public void Settext(object handle, object caption)
public void Settext(int handle, string caption)
{
var ptr = new IntPtr(LuaInt(handle));
var ptr = new IntPtr(handle);
foreach (var form in _luaForms)
{
if (form.Handle == ptr)
@ -533,16 +537,16 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"textbox",
"TODO"
"Creates a textbox control on the given form. The caption property will be the initial value of the textbox (default is empty). Width and Height are option, if not specified they will be a default size of 100, 20. Type is an optional property to restrict the textbox input. The available options are HEX, SIGNED, and UNSIGNED. Passing it null or any other value will set it to no restriction. x, and y are the optional location parameters for the position of the textbox within the given form. The function returns the handle of the created textbox. If true, the multiline will enable the standard winform multi-line property. If true, the fixedWidth options will create a fixed width font"
)]
public int Textbox(
object formHandle,
object caption = null,
object width = null,
object height = null,
object boxtype = null,
object x = null,
object y = null,
int formHandle,
string caption = null,
int? width = null,
int? height = null,
string boxtype = null,
int? x = null,
int? y = null,
bool multiline = false,
bool fixedWidth = false)
{
@ -560,12 +564,20 @@ namespace BizHawk.Client.EmuHawk
textbox.Multiline = multiline;
SetText(textbox, caption);
SetLocation(textbox, x, y);
SetSize(textbox, width, height);
if (x.HasValue && y.HasValue)
{
SetLocation(textbox, x.Value, y.Value);
}
if (width.HasValue && height.HasValue)
{
SetSize(textbox, width.Value, height.Value);
}
if (boxtype != null)
{
switch (boxtype.ToString().ToUpper())
switch (boxtype.ToUpper())
{
case "HEX":
case "HEXADECIMAL":

View File

@ -134,8 +134,8 @@ namespace BizHawk.Client.EmuHawk
}
private static void DoGuiText(
object x,
object y,
int x,
int y,
string message,
bool alert,
object background = null,
@ -155,8 +155,6 @@ namespace BizHawk.Client.EmuHawk
}
}
var dx = LuaInt(x);
var dy = LuaInt(y);
var a = 0;
if (anchor != null)
@ -188,22 +186,22 @@ namespace BizHawk.Client.EmuHawk
}
else
{
dx -= Global.Emulator.CoreComm.ScreenLogicalOffsetX;
dy -= Global.Emulator.CoreComm.ScreenLogicalOffsetY;
x -= Global.Emulator.CoreComm.ScreenLogicalOffsetX;
y -= Global.Emulator.CoreComm.ScreenLogicalOffsetY;
}
// blah hacks
dx *= EmuHawkLuaLibrary.GetWindowSize();
dy *= EmuHawkLuaLibrary.GetWindowSize();
x *= EmuHawkLuaLibrary.GetWindowSize();
y *= EmuHawkLuaLibrary.GetWindowSize();
GlobalWin.OSD.AddGUIText(message, dx, dy, alert, GetColor(background), GetColor(forecolor), a);
GlobalWin.OSD.AddGUIText(message, x, y, alert, GetColor(background), GetColor(forecolor), a);
}
#endregion
[LuaMethodAttributes(
"addmessage",
"TODO"
"Adds a message to the OSD's message area"
)]
public void AddMessage(object luaStr)
{
@ -212,16 +210,16 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"alert",
"TODO"
"Functions the same as gui.text() but shows the message in the alert font"
)]
public void Alert(object x, object y, string message, object anchor = null)
public void Alert(int x, int y, string message, object anchor = null)
{
DoGuiText(x, y, message, true, null, null, anchor); // TODO: refactor DoGuiText to take luaStr as string and refactor
}
[LuaMethodAttributes(
"clearGraphics",
"TODO"
"clears all lua drawn graphics from the screen"
)]
public void ClearGraphics()
{
@ -240,7 +238,7 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"drawBezier",
"TODO"
"Draws a Bezier curve using the table of coordinates provided in the given color"
)]
public void DrawBezier(LuaTable points, object color)
{
@ -273,43 +271,38 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"drawBox",
"TODO"
"Draws a rectangle on screen from x1/y1 to x2/y2. Same as drawRectangle except it receives two points intead of a point and width/height"
)]
public void DrawBox(object x, object y, object x2, object y2, object line = null, object background = null)
public void DrawBox(int x, int y, int x2, int y2, object line = null, object background = null)
{
using (var g = GetGraphics())
{
try
{
var intX = LuaInt(x);
var intY = LuaInt(y);
var intWidth = LuaInt(x2);
var intHeight = LuaInt(y2);
if (intX < intWidth)
if (x < x2)
{
intWidth = Math.Abs(intX - intWidth);
x2 = Math.Abs(x - x2);
}
else
{
intWidth = intX - intWidth;
intX -= intWidth;
x2 = x - x2;
x -= x2;
}
if (intY < intHeight)
if (y < y2)
{
intHeight = Math.Abs(intY - intHeight);
y2 = Math.Abs(y - y2);
}
else
{
intHeight = intY - intHeight;
intY -= intHeight;
y2 = y - y2;
y -= y2;
}
g.DrawRectangle(GetPen(line ?? "white"), intX, intY, intWidth, intHeight);
g.DrawRectangle(GetPen(line ?? "white"), x, y, x2, y2);
if (background != null)
{
g.FillRectangle(GetBrush(background), intX, intY, intWidth, intHeight);
g.FillRectangle(GetBrush(background), x, y, x2, y2);
}
}
catch (Exception)
@ -322,20 +315,20 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"drawEllipse",
"TODO"
"Draws an ellipse at the given coordinates and the given width and height. Line is the color of the ellipse. Background is the optional fill color"
)]
public void DrawEllipse(object x, object y, object width, object height, object line, object background = null)
public void DrawEllipse(int x, int y, int width, int 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"), x, y, width, height);
if (background != null)
{
var brush = GetBrush(background);
g.FillEllipse(brush, LuaInt(x), LuaInt(y), LuaInt(width), LuaInt(height));
g.FillEllipse(brush, x, y, width, height);
}
}
catch (Exception)
@ -348,9 +341,9 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"drawIcon",
"TODO"
"draws an Icon (.ico) file from the given path at the given coordinate. width and height are optional. If specified, it will resize the image accordingly"
)]
public void DrawIcon(string path, object x, object y, object width = null, object height = null)
public void DrawIcon(string path, int x, int y, int? width = null, int? height = null)
{
GlobalWin.DisplayManager.NeedsToPaint = true;
using (var g = GetGraphics())
@ -358,16 +351,16 @@ namespace BizHawk.Client.EmuHawk
try
{
Icon icon;
if (width != null && height != null)
if (width.HasValue && height.HasValue)
{
icon = new Icon(path, LuaInt(width), LuaInt(height));
icon = new Icon(path, width.Value, height.Value);
}
else
{
icon = new Icon(path);
}
g.DrawIcon(icon, LuaInt(x), LuaInt(y));
g.DrawIcon(icon, x, y);
}
catch (Exception)
{
@ -378,102 +371,69 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"drawImage",
"TODO"
"draws an image file from the given path at the given coordinate. width and height are optional. If specified, it will resize the image accordingly"
)]
public void DrawImage(string path, object x, object y, object width = null, object height = null)
public void DrawImage(string path, int x, int y, int? width = null, int? height = null)
{
GlobalWin.DisplayManager.NeedsToPaint = true;
using (var g = GetGraphics())
{
try
{
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), LuaInt(width), LuaInt(height));
}
catch (Exception)
{
return;
}
var img = Image.FromFile(path);
g.DrawImage(img, x, y, width ?? img.Width, height ?? img.Height);
}
}
[LuaMethodAttributes(
"drawLine",
"TODO"
"Draws a line from the first coordinate pair to the 2nd. Color is optional (if not specified it will be drawn black)"
)]
public void DrawLine(object x1, object y1, object x2, object y2, object color = null)
public void DrawLine(int x1, int y1, int x2, int y2, object color = null)
{
GlobalWin.DisplayManager.NeedsToPaint = true;
using (var g = GetGraphics())
{
try
{
g.DrawLine(GetPen(color ?? "white"), LuaInt(x1), LuaInt(y1), LuaInt(x2), LuaInt(y2));
}
catch (Exception)
{
return;
}
g.DrawLine(GetPen(color ?? "white"), x1, y1, x2, y2);
}
}
[LuaMethodAttributes(
"drawPie",
"TODO"
"draws a Pie shape at the given coordinates and the given width and height"
)]
public void DrawPie(
object x,
object y,
object width,
object height,
object startangle,
object sweepangle,
int x,
int y,
int width,
int height,
int startangle,
int sweepangle,
object line,
object background = null)
{
GlobalWin.DisplayManager.NeedsToPaint = true;
using (var g = GetGraphics())
{
try
g.DrawPie(GetPen(line), x, y, width, height, startangle, sweepangle);
if (background != null)
{
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));
}
}
catch (Exception)
{
// need to stop the script from here
return;
var brush = GetBrush(background);
g.FillPie(brush, x, y, width, height, startangle, sweepangle);
}
}
}
[LuaMethodAttributes(
"drawPixel",
"TODO"
"Draws a single pixel at the given coordinates in the given color. Color is optional (if not specified it will be drawn black)"
)]
public void DrawPixel(object x, object y, object color = null)
public void DrawPixel(int x, int y, object color = null)
{
GlobalWin.DisplayManager.NeedsToPaint = true;
using (var g = GetGraphics())
{
try
{
g.DrawLine(GetPen(color ?? "white"), LuaInt(x), LuaInt(y), LuaInt(x) + 0.1F, LuaInt(y));
g.DrawLine(GetPen(color ?? "white"), x, y, x + 0.1F, y);
}
catch (Exception)
{
@ -484,7 +444,7 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"drawPolygon",
"TODO"
"Draws a polygon using the table of coordinates specified in points. Line is the color of the polygon. Background is the optional fill color"
)]
public void DrawPolygon(LuaTable points, object line, object background = null)
{
@ -517,42 +477,30 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"drawRectangle",
"TODO"
"Draws a rectangle at the given coordinate and the given width and height. Line is the color of the box. Background is the optional fill color"
)]
public void DrawRectangle(object x, object y, object width, object height, object line, object background = null)
public void DrawRectangle(int x, int y, int width, int height, object line, object background = null)
{
using (var g = GetGraphics())
{
try
g.DrawRectangle(GetPen(line ?? "white"), x, y, width, height);
if (background != null)
{
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), intX, intY, intWidth, intHeight);
}
}
catch (Exception)
{
// need to stop the script from here
return;
g.FillRectangle(GetBrush(background), x, y, width, height);
}
}
}
[LuaMethodAttributes(
"drawString",
"TODO"
"Alias of gui.drawText()"
)]
public void DrawString(
object x,
object y,
int x,
int y,
string message,
object color = null,
object fontsize = null,
int? fontsize = null,
string fontfamily = null,
string fontstyle = null)
{
@ -561,14 +509,14 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"drawText",
"TODO"
"Draws the given message in the emulator screen space (like all draw functions) at the given x,y coordinates and the given color. The default color is white. A fontfamily can be specified and is monospace generic if none is specified (font family options are the same as the .NET FontFamily class. The fontsize default is 12. The default font style. Font style options are regular, bold, italic, strikethrough, underline"
)]
public void DrawText(
object x,
object y,
int x,
int y,
string message,
object color = null,
object fontsize = null,
int? fontsize = null,
string fontfamily = null,
string fontstyle = null)
{
@ -577,12 +525,6 @@ namespace BizHawk.Client.EmuHawk
{
try
{
var fsize = 12;
if (fontsize != null)
{
fsize = LuaInt(fontsize);
}
var family = FontFamily.GenericMonospace;
if (fontfamily != null)
{
@ -612,7 +554,7 @@ namespace BizHawk.Client.EmuHawk
}
}
var font = new Font(family, fsize, fstyle, GraphicsUnit.Pixel);
var font = new Font(family, fontsize ?? 12, fstyle, GraphicsUnit.Pixel);
g.DrawString(message, font, GetBrush(color ?? "white"), LuaInt(x), LuaInt(y));
}
catch (Exception)
@ -624,11 +566,11 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"text",
"TODO"
"Displays the given text on the screen at the given coordinates. Optional Foreground and background colors. The optional anchor flag anchors the text to one of the four corners. Anchor flag parameters: topleft, topright, bottomleft, bottomright"
)]
public void Text(
object x,
object y,
int x,
int y,
string message,
object background = null,
object forecolor = null,