cleanup of Lua some related files

This commit is contained in:
adelikat 2017-05-19 11:05:21 -05:00
parent 31e68a38f9
commit f89bcf4bfa
9 changed files with 66 additions and 56 deletions

View File

@ -3,12 +3,12 @@ using System.Windows.Forms;
namespace BizHawk.Client.EmuHawk
{
class LuaButton : Button
internal class LuaButton : Button
{
private void DoLuaClick(object sender, EventArgs e)
{
LuaWinform parent = Parent as LuaWinform;
if (parent != null) parent.DoLuaEvent(Handle);
parent?.DoLuaEvent(Handle);
}
protected override void OnClick(EventArgs e)

View File

@ -9,7 +9,7 @@ namespace BizHawk.Client.EmuHawk
[Description("Represents a canvas object returned by the gui.createcanvas() method")]
public partial class LuaCanvas : Form
{
private Graphics graphics;
private readonly Graphics _graphics;
public LuaCanvas(int width, int height)
{
@ -17,7 +17,7 @@ namespace BizHawk.Client.EmuHawk
pictureBox.Width = width;
pictureBox.Height = height;
pictureBox.Image = new Bitmap(width, height);
graphics = Graphics.FromImage(pictureBox.Image);
_graphics = Graphics.FromImage(pictureBox.Image);
}
[LuaMethodAttributes("SetTitle", "Sets the canvas window title")]
@ -29,7 +29,7 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes("Clear", "Clears the canvas")]
public void Clear(Color color)
{
graphics.Clear(color);
_graphics.Clear(color);
}
[LuaMethodAttributes("Refresh", "Redraws the canvas")]
@ -46,11 +46,11 @@ namespace BizHawk.Client.EmuHawk
if (fill.HasValue)
{
var brush = new SolidBrush(fill.Value);
graphics.FillRectangle(brush, x, y, width, height);
_graphics.FillRectangle(brush, x, y, width, height);
}
var pen = new Pen(outline.HasValue ? outline.Value : Color.Black);
graphics.DrawRectangle(pen, x, y, width, height);
_graphics.DrawRectangle(pen, x, y, width, height);
}
[LuaMethodAttributes(
@ -88,8 +88,8 @@ namespace BizHawk.Client.EmuHawk
}
var font = new Font(family, fontsize ?? 12, fstyle, GraphicsUnit.Pixel);
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
graphics.DrawString(message, font, new SolidBrush(color ?? Color.White), x, y);
_graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
_graphics.DrawString(message, font, new SolidBrush(color ?? Color.White), x, y);
}
}
}

View File

@ -8,10 +8,7 @@ namespace BizHawk.Client.EmuHawk
private void DoLuaClick(object sender, EventArgs e)
{
var parent = Parent as LuaWinform;
if (parent != null)
{
parent.DoLuaEvent(Handle);
}
parent?.DoLuaEvent(Handle);
}
protected override void OnClick(EventArgs e)

View File

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

View File

@ -41,8 +41,8 @@ namespace BizHawk.Client.EmuHawk
private void LuaFunctionList_Load(object sender, EventArgs e)
{
FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs
.OrderBy(x => x.Library)
.ThenBy(x => x.Name)
.OrderBy(l => l.Library)
.ThenBy(l => l.Name)
.ToList();
UpdateList();
FilterBox.Focus();
@ -52,7 +52,6 @@ namespace BizHawk.Client.EmuHawk
private void FunctionView_QueryItemBkColor(int index, int column, ref Color color)
{
}
private void FunctionView_QueryItemText(int index, int column, out string text)
@ -148,7 +147,7 @@ namespace BizHawk.Client.EmuHawk
OrderColumn(e.Column);
}
public class Sorting
private class Sorting
{
private bool _desc;
private int _column = 1;

View File

@ -7,7 +7,7 @@ namespace BizHawk.Client.EmuHawk
{
public partial class LuaRegisteredFunctionsList : Form
{
public Point StartLocation = new Point(0, 0);
public Point StartLocation { get; set; } = new Point(0, 0);
public LuaRegisteredFunctionsList()
{
InitializeComponent();

View File

@ -1,28 +1,25 @@
using System;
using System.Globalization;
using System.Globalization;
using System.Windows.Forms;
using BizHawk.Common.StringExtensions;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
enum BoxType { All, Signed, Unsigned, Hex };
class LuaTextBox : TextBox
internal enum BoxType
{
All, Signed, Unsigned, Hex
}
internal class LuaTextBox : TextBox
{
private BoxType _boxType = BoxType.All;
public void SetType(BoxType type)
{
_boxType = type;
if (type != BoxType.All)
{
CharacterCasing = CharacterCasing.Upper;
}
else
{
CharacterCasing = CharacterCasing.Normal;
}
CharacterCasing = type != BoxType.All
? CharacterCasing.Upper
: CharacterCasing.Normal;
}
protected override void OnKeyPress(KeyPressEventArgs e)
@ -33,7 +30,6 @@ namespace BizHawk.Client.EmuHawk
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
switch (_boxType)
@ -76,7 +72,7 @@ namespace BizHawk.Client.EmuHawk
private void Increment()
{
string text = String.IsNullOrWhiteSpace(Text) ? "0" : Text;
string text = string.IsNullOrWhiteSpace(Text) ? "0" : Text;
switch (_boxType)
{
case BoxType.Hex:
@ -90,6 +86,7 @@ namespace BizHawk.Client.EmuHawk
{
Text = "0";
}
break;
case BoxType.Signed:
var sval = int.Parse(text);
@ -102,6 +99,7 @@ namespace BizHawk.Client.EmuHawk
{
Text = "0";
}
break;
case BoxType.Unsigned:
var uval = uint.Parse(text);
@ -114,13 +112,14 @@ namespace BizHawk.Client.EmuHawk
{
Text = "0";
}
break;
}
}
private void Decrement()
{
string text = String.IsNullOrWhiteSpace(Text) ? "0" : Text;
string text = string.IsNullOrWhiteSpace(Text) ? "0" : Text;
switch (_boxType)
{
case BoxType.Hex:
@ -130,6 +129,7 @@ namespace BizHawk.Client.EmuHawk
hval--;
Text = hval.ToString("X");
}
break;
case BoxType.Signed:
var sval = int.Parse(text);
@ -143,27 +143,40 @@ namespace BizHawk.Client.EmuHawk
uval--;
Text = uval.ToString();
}
break;
}
}
private void SpecificValueBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\b') return;
if (e.KeyChar == '\b')
{
return;
}
switch (_boxType)
{
case BoxType.Unsigned:
if (!e.KeyChar.IsUnsigned())
{
e.Handled = true;
}
break;
case BoxType.Signed:
if (!e.KeyChar.IsSigned())
{
e.Handled = true;
}
break;
case BoxType.Hex:
if (!e.KeyChar.IsHex())
{
e.Handled = true;
}
break;
}
}

View File

@ -1,47 +1,47 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using BizHawk.Client.Common;
using LuaInterface;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public partial class LuaWinform : Form
{
public List<LuaEvent> ControlEvents = new List<LuaEvent>();
public List<LuaEvent> ControlEvents { get; } = new List<LuaEvent>();
private string CurrentDirectory = Environment.CurrentDirectory;
Lua OwnerThread;
private readonly string _currentDirectory = Environment.CurrentDirectory;
private readonly Lua _ownerThread;
public LuaWinform(Lua ownerThread)
{
InitializeComponent();
OwnerThread = ownerThread;
_ownerThread = ownerThread;
StartPosition = FormStartPosition.CenterParent;
Closing += (o, e) => CloseThis();
}
private void LuaWinform_Load(object sender, EventArgs e)
{
}
public void CloseThis()
private void CloseThis()
{
GlobalWin.Tools.LuaConsole.LuaImp.WindowClosed(Handle);
}
public void DoLuaEvent(IntPtr handle)
{
LuaSandbox.Sandbox(OwnerThread, () =>
LuaSandbox.Sandbox(_ownerThread, () =>
{
Environment.CurrentDirectory = CurrentDirectory;
foreach (LuaEvent l_event in ControlEvents)
Environment.CurrentDirectory = _currentDirectory;
foreach (LuaEvent luaEvent in ControlEvents)
{
if (l_event.Control == handle)
if (luaEvent.Control == handle)
{
l_event.Event.Call();
luaEvent.Event.Call();
}
}
});
@ -49,15 +49,14 @@ namespace BizHawk.Client.EmuHawk
public class LuaEvent
{
public LuaFunction Event;
public IntPtr Control;
public LuaEvent() { }
public LuaEvent(IntPtr handle, LuaFunction lfunction)
{
Event = lfunction;
Control = handle;
}
public LuaFunction Event { get; }
public IntPtr Control { get; }
}
}
}

View File

@ -2,20 +2,21 @@
using System.Windows.Forms;
using System.Runtime.InteropServices;
class SyncTextBox : RichTextBox
internal class SyncTextBox : RichTextBox
{
public SyncTextBox()
{
this.Multiline = true;
this.ScrollBars = RichTextBoxScrollBars.Vertical;
}
public Control Buddy { get; set; }
private static bool scrolling; // In case buddy tries to scroll us
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
// Trap WM_VSCROLL message and pass to buddy
if ((m.Msg == 0x115 || m.Msg == 0x20a) && !scrolling && Buddy != null && Buddy.IsHandleCreated)
{
@ -24,6 +25,7 @@ class SyncTextBox : RichTextBox
scrolling = false;
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
}