some cleanup in some lua files

This commit is contained in:
adelikat 2019-11-30 11:28:56 -06:00
parent d2ff9b6ff0
commit 7b23c5aee8
5 changed files with 82 additions and 99 deletions

View File

@ -5,15 +5,9 @@ namespace BizHawk.Client.EmuHawk
{ {
internal class LuaButton : Button internal class LuaButton : Button
{ {
private void DoLuaClick(object sender, EventArgs e)
{
LuaWinform parent = Parent as LuaWinform;
parent?.DoLuaEvent(Handle);
}
protected override void OnClick(EventArgs e) protected override void OnClick(EventArgs e)
{ {
DoLuaClick(this, e); (Parent as LuaWinform)?.DoLuaEvent(Handle);
base.OnClick(e); base.OnClick(e);
} }
} }

View File

@ -1,3 +1,4 @@
using System;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
@ -5,16 +6,13 @@ using System.IO;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using NLua; using NLua;
using System;
using System.Collections.Generic;
// ReSharper disable UnusedMember.Global
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
[Description("Represents a canvas object returned by the gui.createcanvas() method")] [Description("Represents a canvas object returned by the gui.createcanvas() method")]
public partial class LuaCanvas : Form public partial class LuaCanvas : Form
{ {
//public List<LuaEvent> ControlEvents { get; } = new List<LuaEvent>();
public LuaCanvas(int width, int height, int? x = null, int? y = null) public LuaCanvas(int width, int height, int? x = null, int? y = null)
{ {
InitializeComponent(); InitializeComponent();
@ -24,7 +22,7 @@ namespace BizHawk.Client.EmuHawk
if (x.HasValue) if (x.HasValue)
{ {
StartPosition = System.Windows.Forms.FormStartPosition.Manual; StartPosition = FormStartPosition.Manual;
Left = (int)x; Left = (int)x;
if (y.HasValue) if (y.HasValue)
{ {
@ -50,9 +48,9 @@ namespace BizHawk.Client.EmuHawk
"Sets the location of the canvas window")] "Sets the location of the canvas window")]
public void SetLocation(int x, int y) public void SetLocation(int x, int y)
{ {
StartPosition = System.Windows.Forms.FormStartPosition.Manual; StartPosition = FormStartPosition.Manual;
Left = (int)x; Left = x;
Top = (int)y; Top = y;
} }
[LuaMethodExample( [LuaMethodExample(
@ -99,7 +97,7 @@ namespace BizHawk.Client.EmuHawk
"LuaCanvas.setDefaultTextBackground( 0x000000FF );")] "LuaCanvas.setDefaultTextBackground( 0x000000FF );")]
[LuaMethod( [LuaMethod(
"setDefaultTextBackground", "setDefaultTextBackground",
"Sets the default backgroiund color to use in text drawing methods, half-transparent black by default")] "Sets the default background color to use in text drawing methods, half-transparent black by default")]
public void SetDefaultTextBackground(Color color) public void SetDefaultTextBackground(Color color)
{ {
luaPictureBox.SetDefaultTextBackground(color); luaPictureBox.SetDefaultTextBackground(color);
@ -119,7 +117,6 @@ namespace BizHawk.Client.EmuHawk
catch (Exception ex) catch (Exception ex)
{ {
ConsoleLuaLibrary.Log(ex.Message); ConsoleLuaLibrary.Log(ex.Message);
return;
} }
} }
@ -137,7 +134,6 @@ namespace BizHawk.Client.EmuHawk
catch (Exception ex) catch (Exception ex)
{ {
ConsoleLuaLibrary.Log(ex.Message); ConsoleLuaLibrary.Log(ex.Message);
return;
} }
} }
@ -155,7 +151,6 @@ namespace BizHawk.Client.EmuHawk
catch (Exception ex) catch (Exception ex)
{ {
ConsoleLuaLibrary.Log(ex.Message); ConsoleLuaLibrary.Log(ex.Message);
return;
} }
} }
@ -173,7 +168,6 @@ namespace BizHawk.Client.EmuHawk
catch (Exception ex) catch (Exception ex)
{ {
ConsoleLuaLibrary.Log(ex.Message); ConsoleLuaLibrary.Log(ex.Message);
return;
} }
} }
@ -208,7 +202,7 @@ namespace BizHawk.Client.EmuHawk
[LuaMethod( [LuaMethod(
"drawImageRegion", "drawImageRegion",
"draws a given region of an image file from the given path at the given coordinate, and optionally with the given size")] "draws a given region of an image file from the given path at the given coordinate, and optionally with the given size")]
public void DrawImageRegion(string path, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int? dest_width = null, int? dest_height = null) public void DrawImageRegion(string path, int sourceX, int sourceY, int sourceWidth, int sourceHeight, int destX, int destY, int? destWidth = null, int? destHeight = null)
{ {
if (!File.Exists(path)) if (!File.Exists(path))
{ {
@ -216,7 +210,7 @@ namespace BizHawk.Client.EmuHawk
return; return;
} }
luaPictureBox.DrawImageRegion(path, source_x, source_y, source_width, source_height, dest_x, dest_y, dest_width, dest_height); luaPictureBox.DrawImageRegion(path, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight);
} }
[LuaMethodExample( [LuaMethodExample(
@ -245,9 +239,9 @@ namespace BizHawk.Client.EmuHawk
"drawArc", "drawArc",
"draws a Arc shape at the given coordinates and the given width and height" "draws a Arc shape at the given coordinates and the given width and height"
)] )]
public void DrawArc(int x, int y, int width, int height, int startangle, int sweepangle, Color? line = null) public void DrawArc(int x, int y, int width, int height, int startAngle, int sweepAngle, Color? line = null)
{ {
luaPictureBox.DrawArc(x, y, width, height, startangle, sweepangle, line); luaPictureBox.DrawArc(x, y, width, height, startAngle, sweepAngle, line);
} }
[LuaMethodExample( [LuaMethodExample(
@ -260,12 +254,12 @@ namespace BizHawk.Client.EmuHawk
int y, int y,
int width, int width,
int height, int height,
int startangle, int startAngle,
int sweepangle, int sweepAngle,
Color? line = null, Color? line = null,
Color? background = null) Color? background = null)
{ {
luaPictureBox.DrawPie(x, y, width, height, startangle, sweepangle, line, background); luaPictureBox.DrawPie(x, y, width, height, startAngle, sweepAngle, line, background);
} }
[LuaMethodExample( [LuaMethodExample(
@ -282,7 +276,6 @@ namespace BizHawk.Client.EmuHawk
catch (Exception ex) catch (Exception ex)
{ {
ConsoleLuaLibrary.Log(ex.Message); ConsoleLuaLibrary.Log(ex.Message);
return;
} }
} }
@ -300,7 +293,6 @@ namespace BizHawk.Client.EmuHawk
catch (Exception ex) catch (Exception ex)
{ {
ConsoleLuaLibrary.Log(ex.Message); ConsoleLuaLibrary.Log(ex.Message);
return;
} }
} }
@ -324,15 +316,15 @@ namespace BizHawk.Client.EmuHawk
int x, int x,
int y, int y,
string message, string message,
Color? forecolor = null, Color? foreColor = null,
Color? backcolor = null, Color? backColor = null,
int? fontsize = null, int? fontSize = null,
string fontfamily = null, string fontFamily = null,
string fontstyle = null, string fontStyle = null,
string horizalign = null, string horizontalAlign = null,
string vertalign = null) string verticalAlign = null)
{ {
luaPictureBox.DrawText(x, y, message, forecolor, backcolor, fontsize, fontfamily, fontstyle, horizalign, vertalign); luaPictureBox.DrawText(x, y, message, foreColor, backColor, fontSize, fontFamily, fontStyle, horizontalAlign, verticalAlign);
} }
[LuaMethodExample( [LuaMethodExample(
@ -344,15 +336,15 @@ namespace BizHawk.Client.EmuHawk
int x, int x,
int y, int y,
string message, string message,
Color? forecolor = null, Color? foreColor = null,
Color? backcolor = null, Color? backColor = null,
int? fontsize = null, int? fontSize = null,
string fontfamily = null, string fontFamily = null,
string fontstyle = null, string fontStyle = null,
string horizalign = null, string horizontalAlign = null,
string vertalign = null) string verticalAlign = null)
{ {
luaPictureBox.DrawText(x, y, message, forecolor, backcolor, fontsize, fontfamily, fontstyle, horizalign, vertalign); luaPictureBox.DrawText(x, y, message, foreColor, backColor, fontSize, fontFamily, fontStyle, horizontalAlign, verticalAlign);
} }

View File

@ -6,14 +6,14 @@ namespace BizHawk.Client.EmuHawk
{ {
public class LuaDropDown : ComboBox public class LuaDropDown : ComboBox
{ {
public LuaDropDown(List<string> items) public LuaDropDown(ICollection<string> items)
{ {
Items.AddRange(items.Cast<object>().ToArray()); Items.AddRange(items.Cast<object>().ToArray());
SelectedIndex = 0; SelectedIndex = 0;
DropDownStyle = ComboBoxStyle.DropDownList; DropDownStyle = ComboBoxStyle.DropDownList;
} }
public void SetItems(List<string> items) public void SetItems(ICollection<string> items)
{ {
Items.Clear(); Items.Clear();
Items.AddRange(items.Cast<object>().ToArray()); Items.AddRange(items.Cast<object>().ToArray());

View File

@ -12,21 +12,20 @@ namespace BizHawk.Client.EmuHawk
{ {
private readonly Sorting _columnSort = new Sorting(); private readonly Sorting _columnSort = new Sorting();
private List<LibraryFunction> FunctionList = new List<LibraryFunction>(); private List<LibraryFunction> _functionList = new List<LibraryFunction>();
private List<LibraryFunction> _filteredList = new List<LibraryFunction>(); private List<LibraryFunction> _filteredList = new List<LibraryFunction>();
private void GenerateFilteredList() private void GenerateFilteredList()
{ {
if (!string.IsNullOrWhiteSpace(FilterBox.Text)) if (!string.IsNullOrWhiteSpace(FilterBox.Text))
{ {
_filteredList = FunctionList _filteredList = _functionList
.Where(f => $"{f.Library}.{f.Name}".ToLowerInvariant().Contains(FilterBox.Text.ToLowerInvariant())) .Where(f => $"{f.Library}.{f.Name}".ToLowerInvariant().Contains(FilterBox.Text.ToLowerInvariant()))
.ToList(); .ToList();
} }
else else
{ {
_filteredList = FunctionList.ToList(); _filteredList = _functionList.ToList();
} }
} }
@ -38,7 +37,7 @@ namespace BizHawk.Client.EmuHawk
private void LuaFunctionList_Load(object sender, EventArgs e) private void LuaFunctionList_Load(object sender, EventArgs e)
{ {
FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs _functionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs
.OrderBy(l => l.Library) .OrderBy(l => l.Library)
.ThenBy(l => l.Name) .ThenBy(l => l.Name)
.ToList(); .ToList();
@ -66,19 +65,19 @@ namespace BizHawk.Client.EmuHawk
switch (column) switch (column)
{ {
case 0: // Return case 0: // Return
FunctionList = FunctionList.OrderByDescending(x => x.ReturnType).ToList(); _functionList = _functionList.OrderByDescending(x => x.ReturnType).ToList();
break; break;
case 1: // Library case 1: // Library
FunctionList = FunctionList.OrderByDescending(x => x.Library).ToList(); _functionList = _functionList.OrderByDescending(x => x.Library).ToList();
break; break;
case 2: // Name case 2: // Name
FunctionList = FunctionList.OrderByDescending(x => x.Name).ToList(); _functionList = _functionList.OrderByDescending(x => x.Name).ToList();
break; break;
case 3: // Parameters case 3: // Parameters
FunctionList = FunctionList.OrderByDescending(x => x.ParameterList).ToList(); _functionList = _functionList.OrderByDescending(x => x.ParameterList).ToList();
break; break;
case 4: // Description case 4: // Description
FunctionList = FunctionList.OrderByDescending(x => x.Description).ToList(); _functionList = _functionList.OrderByDescending(x => x.Description).ToList();
break; break;
} }
} }
@ -87,19 +86,19 @@ namespace BizHawk.Client.EmuHawk
switch (column) switch (column)
{ {
case 0: // Return case 0: // Return
FunctionList = FunctionList.OrderBy(x => x.ReturnType).ToList(); _functionList = _functionList.OrderBy(x => x.ReturnType).ToList();
break; break;
case 1: // Library case 1: // Library
FunctionList = FunctionList.OrderBy(x => x.Library).ToList(); _functionList = _functionList.OrderBy(x => x.Library).ToList();
break; break;
case 2: // Name case 2: // Name
FunctionList = FunctionList.OrderBy(x => x.Name).ToList(); _functionList = _functionList.OrderBy(x => x.Name).ToList();
break; break;
case 3: // Parameters case 3: // Parameters
FunctionList = FunctionList.OrderBy(x => x.ParameterList).ToList(); _functionList = _functionList.OrderBy(x => x.ParameterList).ToList();
break; break;
case 4: // Description case 4: // Description
FunctionList = FunctionList.OrderBy(x => x.Description).ToList(); _functionList = _functionList.OrderBy(x => x.Description).ToList();
break; break;
} }
} }

View File

@ -17,8 +17,7 @@ namespace BizHawk.Client.EmuHawk
private SolidBrush GetBrush(Color color) private SolidBrush GetBrush(Color color)
{ {
SolidBrush b; if (!_solidBrushes.TryGetValue(color, out var b))
if (!_solidBrushes.TryGetValue(color, out b))
{ {
b = new SolidBrush(color); b = new SolidBrush(color);
_solidBrushes[color] = b; _solidBrushes[color] = b;
@ -29,8 +28,7 @@ namespace BizHawk.Client.EmuHawk
private Pen GetPen(Color color) private Pen GetPen(Color color)
{ {
Pen p; if (!_pens.TryGetValue(color, out var p))
if (!_pens.TryGetValue(color, out p))
{ {
p = new Pen(color); p = new Pen(color);
_pens[color] = p; _pens[color] = p;
@ -190,7 +188,7 @@ namespace BizHawk.Client.EmuHawk
_imageCache.Clear(); _imageCache.Clear();
} }
public void DrawImageRegion(string path, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int? dest_width = null, int? dest_height = null) public void DrawImageRegion(string path, int sourceX, int sourceY, int sourceWidth, int sourceHeight, int destX, int destY, int? destWidth = null, int? destHeight = null)
{ {
Image img; Image img;
if (_imageCache.ContainsKey(path)) if (_imageCache.ContainsKey(path))
@ -203,10 +201,10 @@ namespace BizHawk.Client.EmuHawk
_imageCache.Add(path, img); _imageCache.Add(path, img);
} }
var destRect = new Rectangle(dest_x, dest_y, dest_width ?? source_width, dest_height ?? source_height); var destRect = new Rectangle(destX, destY, destWidth ?? sourceWidth, destHeight ?? sourceHeight);
var boxBackground = Graphics.FromImage(Image); var boxBackground = Graphics.FromImage(Image);
boxBackground.DrawImage(img, destRect, source_x, source_y, source_width, source_height, GraphicsUnit.Pixel); boxBackground.DrawImage(img, destRect, sourceX, sourceY, sourceWidth, sourceHeight, GraphicsUnit.Pixel);
} }
public void DrawLine(int x1, int y1, int x2, int y2, Color? color = null) public void DrawLine(int x1, int y1, int x2, int y2, Color? color = null)
@ -221,10 +219,10 @@ namespace BizHawk.Client.EmuHawk
DrawLine(x, y + size, x, y - size, color); DrawLine(x, y + size, x, y - size, color);
} }
public void DrawArc(int x, int y, int width, int height, int startangle, int sweepangle, Color? line = null) public void DrawArc(int x, int y, int width, int height, int startAngle, int sweepAngle, Color? line = null)
{ {
var boxBackground = Graphics.FromImage(Image); var boxBackground = Graphics.FromImage(Image);
boxBackground.DrawArc(GetPen(line ?? _defaultForeground), x, y, width, height, startangle, sweepangle); boxBackground.DrawArc(GetPen(line ?? _defaultForeground), x, y, width, height, startAngle, sweepAngle);
} }
public void DrawPie( public void DrawPie(
@ -232,8 +230,8 @@ namespace BizHawk.Client.EmuHawk
int y, int y,
int width, int width,
int height, int height,
int startangle, int startAngle,
int sweepangle, int sweepAngle,
Color? line = null, Color? line = null,
Color? background = null) Color? background = null)
{ {
@ -242,11 +240,11 @@ namespace BizHawk.Client.EmuHawk
if (bg.HasValue) if (bg.HasValue)
{ {
var brush = GetBrush(bg.Value); var brush = GetBrush(bg.Value);
boxBackground.FillPie(brush, x, y, width, height, startangle, sweepangle); boxBackground.FillPie(brush, x, y, width, height, startAngle, sweepAngle);
boxBackground = Graphics.FromImage(Image); boxBackground = Graphics.FromImage(Image);
} }
boxBackground.DrawPie(GetPen(line ?? _defaultForeground), x + 1, y + 1, width - 1, height - 1, startangle, sweepangle); boxBackground.DrawPie(GetPen(line ?? _defaultForeground), x + 1, y + 1, width - 1, height - 1, startAngle, sweepAngle);
} }
public void DrawPixel(int x, int y, Color? color = null) public void DrawPixel(int x, int y, Color? color = null)
@ -292,52 +290,52 @@ namespace BizHawk.Client.EmuHawk
int x, int x,
int y, int y,
string message, string message,
Color? forecolor = null, Color? foreColor = null,
Color? backcolor = null, Color? backColor = null,
int? fontsize = null, int? fontSize = null,
string fontfamily = null, string fontFamily = null,
string fontstyle = null, string fontStyle = null,
string horizalign = null, string horizAlign = null,
string vertalign = null) string vertAlign = null)
{ {
var family = FontFamily.GenericMonospace; var family = FontFamily.GenericMonospace;
if (fontfamily != null) if (fontFamily != null)
{ {
family = new FontFamily(fontfamily); family = new FontFamily(fontFamily);
} }
var fstyle = FontStyle.Regular; var fStyle = FontStyle.Regular;
if (fontstyle != null) if (fontStyle != null)
{ {
switch (fontstyle.ToLower()) switch (fontStyle.ToLower())
{ {
default: default:
case "regular": case "regular":
break; break;
case "bold": case "bold":
fstyle = FontStyle.Bold; fStyle = FontStyle.Bold;
break; break;
case "italic": case "italic":
fstyle = FontStyle.Italic; fStyle = FontStyle.Italic;
break; break;
case "strikethrough": case "strikethrough":
fstyle = FontStyle.Strikeout; fStyle = FontStyle.Strikeout;
break; break;
case "underline": case "underline":
fstyle = FontStyle.Underline; fStyle = FontStyle.Underline;
break; break;
} }
} }
var f = new StringFormat(StringFormat.GenericDefault); var f = new StringFormat(StringFormat.GenericDefault);
var font = new Font(family, fontsize ?? 12, fstyle, GraphicsUnit.Pixel); var font = new Font(family, fontSize ?? 12, fStyle, GraphicsUnit.Pixel);
var boxBackground = Graphics.FromImage(Image); var boxBackground = Graphics.FromImage(Image);
Size sizeOfText = boxBackground.MeasureString(message, font, 0, f).ToSize(); Size sizeOfText = boxBackground.MeasureString(message, font, 0, f).ToSize();
if (horizalign != null) if (horizAlign != null)
{ {
switch (horizalign.ToLower()) switch (horizAlign.ToLower())
{ {
default: default:
case "left": case "left":
@ -352,9 +350,9 @@ namespace BizHawk.Client.EmuHawk
} }
} }
if (vertalign != null) if (vertAlign != null)
{ {
switch (vertalign.ToLower()) switch (vertAlign.ToLower())
{ {
default: default:
case "top": case "top":
@ -370,15 +368,15 @@ namespace BizHawk.Client.EmuHawk
} }
Rectangle rect = new Rectangle(new Point(x, y), sizeOfText); Rectangle rect = new Rectangle(new Point(x, y), sizeOfText);
boxBackground = Graphics.FromImage(Image); boxBackground = Graphics.FromImage(Image);
boxBackground.FillRectangle(GetBrush(backcolor ?? _defaultTextBackground.Value), rect); boxBackground.FillRectangle(GetBrush(backColor ?? _defaultTextBackground.Value), rect);
boxBackground = Graphics.FromImage(Image); boxBackground = Graphics.FromImage(Image);
boxBackground.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; boxBackground.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
boxBackground.DrawString(message, font, new SolidBrush(forecolor ?? Color.Black), x, y); boxBackground.DrawString(message, font, new SolidBrush(foreColor ?? Color.Black), x, y);
} }
public Point GetMouse() public Point GetMouse()
{ {
var p = PointToClient(Control.MousePosition); var p = PointToClient(MousePosition);
return p; return p;
} }