Use NLuaTableHelper for more conversion to/from LuaTable
also fix indexing that I broke in c8e10120d
This commit is contained in:
parent
46504b4880
commit
b541fe5b40
|
@ -63,9 +63,10 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
var pointsArr = new Point[4];
|
||||
var i = 0;
|
||||
foreach (var point in _th.EnumerateValues<LuaTable>(points))
|
||||
foreach (var point in _th.EnumerateValues<LuaTable>(points)
|
||||
.Select(table => _th.EnumerateValues<double>(table).ToList()))
|
||||
{
|
||||
pointsArr[i] = new Point(LuaInt(point[1]), LuaInt(point[2]));
|
||||
pointsArr[i] = new Point(LuaInt(point[0]), LuaInt(point[1]));
|
||||
i++;
|
||||
if (i >= 4)
|
||||
{
|
||||
|
@ -124,14 +125,15 @@ namespace BizHawk.Client.Common
|
|||
[LuaMethod("drawPolygon", "Draws a polygon using the table of coordinates specified in points. This should be a table of tables(each of size 2). If x or y is passed, the polygon will be translated by the passed coordinate pair. Line is the color of the polygon. Background is the optional fill color")]
|
||||
public void DrawPolygon(LuaTable points, int? offsetX = null, int? offsetY = null, Color? line = null, Color? background = null)
|
||||
{
|
||||
var pointsList = _th.EnumerateValues<LuaTable>(points).ToList();
|
||||
var pointsList = _th.EnumerateValues<LuaTable>(points)
|
||||
.Select(table => _th.EnumerateValues<double>(table).ToList()).ToList();
|
||||
try
|
||||
{
|
||||
var pointsArr = new Point[pointsList.Count];
|
||||
var i = 0;
|
||||
foreach (var point in pointsList)
|
||||
{
|
||||
pointsArr[i] = new Point(LuaInt(point[1]) + (offsetX ?? 0), LuaInt(point[2]) + (offsetY ?? 0));
|
||||
pointsArr[i] = new Point(LuaInt(point[0]) + (offsetX ?? 0), LuaInt(point[1]) + (offsetY ?? 0));
|
||||
i++;
|
||||
}
|
||||
APIs.Gui.DrawPolygon(pointsArr, line, background);
|
||||
|
|
|
@ -422,7 +422,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return 0;
|
||||
}
|
||||
|
||||
var pictureBox = new LuaPictureBox();
|
||||
var pictureBox = new LuaPictureBox { TableHelper = _th };
|
||||
form.Controls.Add(pictureBox);
|
||||
|
||||
if (x.HasValue && y.HasValue)
|
||||
|
|
|
@ -15,10 +15,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
private readonly Action<string> LogOutputCallback;
|
||||
|
||||
public LuaCanvas(int width, int height, int? x, int? y, Action<string> logOutputCallback)
|
||||
public LuaCanvas(int width, int height, int? x, int? y, NLuaTableHelper tableHelper, Action<string> logOutputCallback)
|
||||
{
|
||||
LogOutputCallback = logOutputCallback;
|
||||
InitializeComponent();
|
||||
luaPictureBox.TableHelper = tableHelper;
|
||||
luaPictureBox.Image = Properties.Resources.LuaPictureBox;
|
||||
luaPictureBox.Width = width;
|
||||
luaPictureBox.Height = height;
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
using NLua;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
|
@ -14,6 +17,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
private readonly Dictionary<Color, SolidBrush> _solidBrushes = new Dictionary<Color, SolidBrush>();
|
||||
private readonly Dictionary<Color, Pen> _pens = new Dictionary<Color, Pen>();
|
||||
|
||||
internal NLuaTableHelper TableHelper { private get; set; }
|
||||
|
||||
private SolidBrush GetBrush(Color color)
|
||||
{
|
||||
if (!_solidBrushes.TryGetValue(color, out var b))
|
||||
|
@ -78,9 +83,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
var pointsArr = new Point[4];
|
||||
|
||||
var i = 0;
|
||||
foreach (LuaTable point in points.Values)
|
||||
foreach (var point in TableHelper.EnumerateValues<LuaTable>(points)
|
||||
.Select(table => TableHelper.EnumerateValues<double>(table).ToList()))
|
||||
{
|
||||
pointsArr[i] = new Point((int)(double)(point[1]), (int)(double)(point[2]));
|
||||
pointsArr[i] = new Point((int) point[0], (int) point[1]);
|
||||
i++;
|
||||
if (i >= 4)
|
||||
{
|
||||
|
@ -252,11 +258,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void DrawPolygon(LuaTable points, int? x = null, int? y = null, Color? line = null, Color? background = null)
|
||||
{
|
||||
var pointsArr = new Point[points.Values.Count];
|
||||
var pointsList = TableHelper.EnumerateValues<LuaTable>(points)
|
||||
.Select(table => TableHelper.EnumerateValues<double>(table).ToList()).ToList();
|
||||
var pointsArr = new Point[pointsList.Count];
|
||||
var i = 0;
|
||||
foreach (LuaTable point in points.Values)
|
||||
foreach (var point in pointsList)
|
||||
{
|
||||
pointsArr[i] = new Point((int)(double)(point[1]) + x ?? 0, (int)(double)(point[2]) + y ?? 0);
|
||||
pointsArr[i] = new Point((int) point[0] + x ?? 0, (int) point[1] + y ?? 0);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
guiLib.CreateLuaCanvasCallback = (width, height, x, y) =>
|
||||
{
|
||||
var canvas = new LuaCanvas(width, height, x, y, LogToLuaConsole);
|
||||
var canvas = new LuaCanvas(width, height, x, y, _th, LogToLuaConsole);
|
||||
canvas.Show();
|
||||
return _th.ObjectToTable(canvas);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue