From 7b23c5aee89b03086056a679c5c3813064daaf1c Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 30 Nov 2019 11:28:56 -0600 Subject: [PATCH] some cleanup in some lua files --- BizHawk.Client.EmuHawk/tools/Lua/LuaButton.cs | 8 +-- BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs | 68 ++++++++---------- .../tools/Lua/LuaDropDown.cs | 4 +- .../tools/Lua/LuaFunctionsForm.cs | 29 ++++---- .../tools/Lua/LuaPictureBox.cs | 72 +++++++++---------- 5 files changed, 82 insertions(+), 99 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaButton.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaButton.cs index eab3a6accc..fd1f578b93 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaButton.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaButton.cs @@ -5,15 +5,9 @@ namespace BizHawk.Client.EmuHawk { 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) { - DoLuaClick(this, e); + (Parent as LuaWinform)?.DoLuaEvent(Handle); base.OnClick(e); } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs index b3d0f5f424..38c0e7c4cf 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs @@ -1,3 +1,4 @@ +using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; @@ -5,16 +6,13 @@ using System.IO; using BizHawk.Client.Common; using NLua; -using System; -using System.Collections.Generic; +// ReSharper disable UnusedMember.Global namespace BizHawk.Client.EmuHawk { [Description("Represents a canvas object returned by the gui.createcanvas() method")] public partial class LuaCanvas : Form { - //public List ControlEvents { get; } = new List(); - public LuaCanvas(int width, int height, int? x = null, int? y = null) { InitializeComponent(); @@ -24,7 +22,7 @@ namespace BizHawk.Client.EmuHawk if (x.HasValue) { - StartPosition = System.Windows.Forms.FormStartPosition.Manual; + StartPosition = FormStartPosition.Manual; Left = (int)x; if (y.HasValue) { @@ -50,9 +48,9 @@ namespace BizHawk.Client.EmuHawk "Sets the location of the canvas window")] public void SetLocation(int x, int y) { - StartPosition = System.Windows.Forms.FormStartPosition.Manual; - Left = (int)x; - Top = (int)y; + StartPosition = FormStartPosition.Manual; + Left = x; + Top = y; } [LuaMethodExample( @@ -99,7 +97,7 @@ namespace BizHawk.Client.EmuHawk "LuaCanvas.setDefaultTextBackground( 0x000000FF );")] [LuaMethod( "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) { luaPictureBox.SetDefaultTextBackground(color); @@ -119,7 +117,6 @@ namespace BizHawk.Client.EmuHawk catch (Exception ex) { ConsoleLuaLibrary.Log(ex.Message); - return; } } @@ -137,7 +134,6 @@ namespace BizHawk.Client.EmuHawk catch (Exception ex) { ConsoleLuaLibrary.Log(ex.Message); - return; } } @@ -155,7 +151,6 @@ namespace BizHawk.Client.EmuHawk catch (Exception ex) { ConsoleLuaLibrary.Log(ex.Message); - return; } } @@ -173,7 +168,6 @@ namespace BizHawk.Client.EmuHawk catch (Exception ex) { ConsoleLuaLibrary.Log(ex.Message); - return; } } @@ -208,7 +202,7 @@ namespace BizHawk.Client.EmuHawk [LuaMethod( "drawImageRegion", "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)) { @@ -216,7 +210,7 @@ namespace BizHawk.Client.EmuHawk 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( @@ -245,9 +239,9 @@ namespace BizHawk.Client.EmuHawk "drawArc", "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( @@ -260,12 +254,12 @@ namespace BizHawk.Client.EmuHawk int y, int width, int height, - int startangle, - int sweepangle, + int startAngle, + int sweepAngle, Color? line = 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( @@ -282,7 +276,6 @@ namespace BizHawk.Client.EmuHawk catch (Exception ex) { ConsoleLuaLibrary.Log(ex.Message); - return; } } @@ -300,7 +293,6 @@ namespace BizHawk.Client.EmuHawk catch (Exception ex) { ConsoleLuaLibrary.Log(ex.Message); - return; } } @@ -324,15 +316,15 @@ namespace BizHawk.Client.EmuHawk int x, int y, string message, - Color? forecolor = null, - Color? backcolor = null, - int? fontsize = null, - string fontfamily = null, - string fontstyle = null, - string horizalign = null, - string vertalign = null) + Color? foreColor = null, + Color? backColor = null, + int? fontSize = null, + string fontFamily = null, + string fontStyle = null, + string horizontalAlign = 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( @@ -344,15 +336,15 @@ namespace BizHawk.Client.EmuHawk int x, int y, string message, - Color? forecolor = null, - Color? backcolor = null, - int? fontsize = null, - string fontfamily = null, - string fontstyle = null, - string horizalign = null, - string vertalign = null) + Color? foreColor = null, + Color? backColor = null, + int? fontSize = null, + string fontFamily = null, + string fontStyle = null, + string horizontalAlign = 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); } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaDropDown.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaDropDown.cs index d74f41429f..98e3ae72b8 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaDropDown.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaDropDown.cs @@ -6,14 +6,14 @@ namespace BizHawk.Client.EmuHawk { public class LuaDropDown : ComboBox { - public LuaDropDown(List items) + public LuaDropDown(ICollection items) { Items.AddRange(items.Cast().ToArray()); SelectedIndex = 0; DropDownStyle = ComboBoxStyle.DropDownList; } - public void SetItems(List items) + public void SetItems(ICollection items) { Items.Clear(); Items.AddRange(items.Cast().ToArray()); diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs index a815c21846..c30ec46136 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs @@ -12,21 +12,20 @@ namespace BizHawk.Client.EmuHawk { private readonly Sorting _columnSort = new Sorting(); - private List FunctionList = new List(); - + private List _functionList = new List(); private List _filteredList = new List(); private void GenerateFilteredList() { if (!string.IsNullOrWhiteSpace(FilterBox.Text)) { - _filteredList = FunctionList + _filteredList = _functionList .Where(f => $"{f.Library}.{f.Name}".ToLowerInvariant().Contains(FilterBox.Text.ToLowerInvariant())) .ToList(); } else { - _filteredList = FunctionList.ToList(); + _filteredList = _functionList.ToList(); } } @@ -38,7 +37,7 @@ namespace BizHawk.Client.EmuHawk private void LuaFunctionList_Load(object sender, EventArgs e) { - FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs + _functionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs .OrderBy(l => l.Library) .ThenBy(l => l.Name) .ToList(); @@ -66,19 +65,19 @@ namespace BizHawk.Client.EmuHawk switch (column) { case 0: // Return - FunctionList = FunctionList.OrderByDescending(x => x.ReturnType).ToList(); + _functionList = _functionList.OrderByDescending(x => x.ReturnType).ToList(); break; case 1: // Library - FunctionList = FunctionList.OrderByDescending(x => x.Library).ToList(); + _functionList = _functionList.OrderByDescending(x => x.Library).ToList(); break; case 2: // Name - FunctionList = FunctionList.OrderByDescending(x => x.Name).ToList(); + _functionList = _functionList.OrderByDescending(x => x.Name).ToList(); break; case 3: // Parameters - FunctionList = FunctionList.OrderByDescending(x => x.ParameterList).ToList(); + _functionList = _functionList.OrderByDescending(x => x.ParameterList).ToList(); break; case 4: // Description - FunctionList = FunctionList.OrderByDescending(x => x.Description).ToList(); + _functionList = _functionList.OrderByDescending(x => x.Description).ToList(); break; } } @@ -87,19 +86,19 @@ namespace BizHawk.Client.EmuHawk switch (column) { case 0: // Return - FunctionList = FunctionList.OrderBy(x => x.ReturnType).ToList(); + _functionList = _functionList.OrderBy(x => x.ReturnType).ToList(); break; case 1: // Library - FunctionList = FunctionList.OrderBy(x => x.Library).ToList(); + _functionList = _functionList.OrderBy(x => x.Library).ToList(); break; case 2: // Name - FunctionList = FunctionList.OrderBy(x => x.Name).ToList(); + _functionList = _functionList.OrderBy(x => x.Name).ToList(); break; case 3: // Parameters - FunctionList = FunctionList.OrderBy(x => x.ParameterList).ToList(); + _functionList = _functionList.OrderBy(x => x.ParameterList).ToList(); break; case 4: // Description - FunctionList = FunctionList.OrderBy(x => x.Description).ToList(); + _functionList = _functionList.OrderBy(x => x.Description).ToList(); break; } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs index be641ceccb..fcb85b0fa9 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs @@ -17,8 +17,7 @@ namespace BizHawk.Client.EmuHawk private SolidBrush GetBrush(Color color) { - SolidBrush b; - if (!_solidBrushes.TryGetValue(color, out b)) + if (!_solidBrushes.TryGetValue(color, out var b)) { b = new SolidBrush(color); _solidBrushes[color] = b; @@ -29,8 +28,7 @@ namespace BizHawk.Client.EmuHawk private Pen GetPen(Color color) { - Pen p; - if (!_pens.TryGetValue(color, out p)) + if (!_pens.TryGetValue(color, out var p)) { p = new Pen(color); _pens[color] = p; @@ -190,7 +188,7 @@ namespace BizHawk.Client.EmuHawk _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; if (_imageCache.ContainsKey(path)) @@ -203,10 +201,10 @@ namespace BizHawk.Client.EmuHawk _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); - 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) @@ -221,10 +219,10 @@ namespace BizHawk.Client.EmuHawk 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); - 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( @@ -232,8 +230,8 @@ namespace BizHawk.Client.EmuHawk int y, int width, int height, - int startangle, - int sweepangle, + int startAngle, + int sweepAngle, Color? line = null, Color? background = null) { @@ -242,11 +240,11 @@ namespace BizHawk.Client.EmuHawk if (bg.HasValue) { 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.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) @@ -292,52 +290,52 @@ namespace BizHawk.Client.EmuHawk int x, int y, string message, - Color? forecolor = null, - Color? backcolor = null, - int? fontsize = null, - string fontfamily = null, - string fontstyle = null, - string horizalign = null, - string vertalign = null) + Color? foreColor = null, + Color? backColor = null, + int? fontSize = null, + string fontFamily = null, + string fontStyle = null, + string horizAlign = null, + string vertAlign = null) { var family = FontFamily.GenericMonospace; - if (fontfamily != null) + if (fontFamily != null) { - family = new FontFamily(fontfamily); + family = new FontFamily(fontFamily); } - var fstyle = FontStyle.Regular; - if (fontstyle != null) + var fStyle = FontStyle.Regular; + if (fontStyle != null) { - switch (fontstyle.ToLower()) + switch (fontStyle.ToLower()) { default: case "regular": break; case "bold": - fstyle = FontStyle.Bold; + fStyle = FontStyle.Bold; break; case "italic": - fstyle = FontStyle.Italic; + fStyle = FontStyle.Italic; break; case "strikethrough": - fstyle = FontStyle.Strikeout; + fStyle = FontStyle.Strikeout; break; case "underline": - fstyle = FontStyle.Underline; + fStyle = FontStyle.Underline; break; } } 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); Size sizeOfText = boxBackground.MeasureString(message, font, 0, f).ToSize(); - if (horizalign != null) + if (horizAlign != null) { - switch (horizalign.ToLower()) + switch (horizAlign.ToLower()) { default: case "left": @@ -352,9 +350,9 @@ namespace BizHawk.Client.EmuHawk } } - if (vertalign != null) + if (vertAlign != null) { - switch (vertalign.ToLower()) + switch (vertAlign.ToLower()) { default: case "top": @@ -370,15 +368,15 @@ namespace BizHawk.Client.EmuHawk } Rectangle rect = new Rectangle(new Point(x, y), sizeOfText); boxBackground = Graphics.FromImage(Image); - boxBackground.FillRectangle(GetBrush(backcolor ?? _defaultTextBackground.Value), rect); + boxBackground.FillRectangle(GetBrush(backColor ?? _defaultTextBackground.Value), rect); boxBackground = Graphics.FromImage(Image); 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() { - var p = PointToClient(Control.MousePosition); + var p = PointToClient(MousePosition); return p; }