Merge pull request #1180 from AntyMew/lua-polygon-pos

Lua: Add optional position parameters to `DrawPolygon`
This commit is contained in:
adelikat 2018-11-18 08:12:01 -06:00 committed by GitHub
commit ee9e21bcb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 13 deletions

View File

@ -1022,11 +1022,11 @@ namespace BizHawk.Client.EmuHawk
} }
} }
[LuaMethodExample("forms.drawPolygon( 334, { { 5, 10 }, { 10, 10 }, { 10, 20 }, { 5, 20 } }, 0x007F00FF, 0x7F7F7FFF );")] [LuaMethodExample("forms.drawPolygon( 334, { { 5, 10 }, { 10, 10 }, { 10, 20 }, { 5, 20 } }, 10, 30, 0x007F00FF, 0x7F7F7FFF );")]
[LuaMethod( [LuaMethod(
"drawPolygon", "drawPolygon",
"Draws a polygon using the table of coordinates specified in points. This should be a table of tables(each of size 2). Line is the color of the polygon. Background is the optional fill color")] "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(int componentHandle, LuaTable points, Color? line = null, Color? background = null) public void DrawPolygon(int componentHandle, LuaTable points, int? x = null, int? y = null, Color? line = null, Color? background = null)
{ {
try try
{ {
@ -1043,7 +1043,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (control is LuaPictureBox) if (control is LuaPictureBox)
{ {
(control as LuaPictureBox).DrawPolygon(points, line, background); (control as LuaPictureBox).DrawPolygon(points, x, y, line, background);
} }
} }
} }

View File

@ -448,9 +448,9 @@ namespace BizHawk.Client.EmuHawk
} }
} }
[LuaMethodExample("gui.drawPolygon( { { 5, 10 }, { 10, 10 }, { 10, 20 }, { 5, 20 } }, 0x007F00FF, 0x7F7F7FFF );")] [LuaMethodExample("gui.drawPolygon( { { 5, 10 }, { 10, 10 }, { 10, 20 }, { 5, 20 } }, 10, 30, 0x007F00FF, 0x7F7F7FFF );")]
[LuaMethod("drawPolygon", "Draws a polygon using the table of coordinates specified in points. This should be a table of tables(each of size 2). Line is the color of the polygon. Background is the optional fill color")] [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, Color? line = null, Color? background = null) public void DrawPolygon(LuaTable points, int? x = null, int? y = null, Color? line = null, Color? background = null)
{ {
using (var g = GetGraphics()) using (var g = GetGraphics())
{ {
@ -460,7 +460,7 @@ namespace BizHawk.Client.EmuHawk
var i = 0; var i = 0;
foreach (LuaTable point in points.Values) foreach (LuaTable point in points.Values)
{ {
pointsArr[i] = new Point(LuaInt(point[1]), LuaInt(point[2])); pointsArr[i] = new Point(LuaInt(point[1]) + x ?? 0, LuaInt(point[2]) + y ?? 0);
i++; i++;
} }

View File

@ -291,11 +291,11 @@ namespace BizHawk.Client.EmuHawk
[LuaMethod( [LuaMethod(
"drawPolygon", "drawPolygon",
"Draws a polygon using the table of coordinates specified in points. This should be a table of tables(each of size 2). Line is the color of the polygon. Background is the optional fill color")] "Draws a polygon using the table of coordinates specified in points. This should be a table of tables(each of size 2). Line is the color of the polygon. Background is the optional fill color")]
public void DrawPolygon(LuaTable points, Color? line = null, Color? background = null) public void DrawPolygon(LuaTable points, int? x = null, int? y = null, Color? line = null, Color? background = null)
{ {
try try
{ {
luaPictureBox.DrawPolygon(points, line, background); luaPictureBox.DrawPolygon(points, x, y, line, background);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -255,13 +255,13 @@ namespace BizHawk.Client.EmuHawk
boxBackground.DrawLine(GetPen(color ?? _defaultForeground), x, y, x + 0.1F, y); boxBackground.DrawLine(GetPen(color ?? _defaultForeground), x, y, x + 0.1F, y);
} }
public void DrawPolygon(LuaTable points, Color? line = null, Color? background = null) 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 pointsArr = new Point[points.Values.Count];
var i = 0; var i = 0;
foreach (LuaTable point in points.Values) foreach (LuaTable point in points.Values)
{ {
pointsArr[i] = new Point((int)(double)(point[1]), (int)(double)(point[2])); pointsArr[i] = new Point((int)(double)(point[1]) + x ?? 0, (int)(double)(point[2]) + y ?? 0);
i++; i++;
} }
@ -393,4 +393,4 @@ namespace BizHawk.Client.EmuHawk
base.OnClick(e); base.OnClick(e);
} }
} }
} }