From 0d9ced7d83ceb534f8e11fe1445ddb73dba893cf Mon Sep 17 00:00:00 2001 From: Callie LeFave Date: Mon, 16 Apr 2018 16:15:37 -0400 Subject: [PATCH 1/3] Lua: Add optional position parameters to `DrawPolygon` --- .../tools/Lua/Libraries/EmuLuaLibrary.Forms.cs | 8 ++++---- .../tools/Lua/Libraries/EmuLuaLibrary.Gui.cs | 8 ++++---- BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs | 4 ++-- BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs index 2fe833b845..1148a56d54 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs @@ -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( "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")] - public void DrawPolygon(int componentHandle, LuaTable points, Color? line = null, Color? background = null) + "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, int x = 0, int y = 0, Color? line = null, Color? background = null) { try { @@ -1043,7 +1043,7 @@ namespace BizHawk.Client.EmuHawk { if (control is LuaPictureBox) { - (control as LuaPictureBox).DrawPolygon(points, line, background); + (control as LuaPictureBox).DrawPolygon(points, line, x, y, background); } } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs index 105ac74ee9..6f328d2c75 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs @@ -448,9 +448,9 @@ namespace BizHawk.Client.EmuHawk } } - [LuaMethodExample("gui.drawPolygon( { { 5, 10 }, { 10, 10 }, { 10, 20 }, { 5, 20 } }, 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")] - public void DrawPolygon(LuaTable points, Color? line = null, Color? background = null) + [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). 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 x = 0, int y = 0, Color? line = null, Color? background = null) { using (var g = GetGraphics()) { @@ -460,7 +460,7 @@ namespace BizHawk.Client.EmuHawk var i = 0; foreach (LuaTable point in points.Values) { - pointsArr[i] = new Point(LuaInt(point[1]), LuaInt(point[2])); + pointsArr[i] = new Point(LuaInt(point[1]) + x, LuaInt(point[2]) + y); i++; } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs index b0d900a8e4..2b0156cc84 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs @@ -291,11 +291,11 @@ namespace BizHawk.Client.EmuHawk [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")] - public void DrawPolygon(LuaTable points, Color? line = null, Color? background = null) + public void DrawPolygon(LuaTable points, int x = 0, int y = 0, Color? line = null, Color? background = null) { try { - luaPictureBox.DrawPolygon(points, line, background); + luaPictureBox.DrawPolygon(points, line, x, y, background); } catch (Exception ex) { diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs index ff3db73575..4f2d33a780 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs @@ -255,13 +255,13 @@ namespace BizHawk.Client.EmuHawk 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 = 0, int y = 0, Color? line = null, Color? background = null) { var pointsArr = new Point[points.Values.Count]; var i = 0; 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, (int)(double)(point[2]) + y); i++; } @@ -393,4 +393,4 @@ namespace BizHawk.Client.EmuHawk base.OnClick(e); } } -} \ No newline at end of file +} From a10d0ec6cca9c35d8b7e860578f49863fc12b085 Mon Sep 17 00:00:00 2001 From: Callie LeFave Date: Mon, 16 Apr 2018 16:44:18 -0400 Subject: [PATCH 2/3] Fix CI build --- .../tools/Lua/Libraries/EmuLuaLibrary.Forms.cs | 2 +- .../tools/Lua/Libraries/EmuLuaLibrary.Gui.cs | 4 ++-- BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs | 2 +- BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs index 1148a56d54..16e6789fc9 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs @@ -1026,7 +1026,7 @@ namespace BizHawk.Client.EmuHawk [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(int componentHandle, LuaTable points, int x = 0, int y = 0, 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 { diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs index 6f328d2c75..adf906bf22 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs @@ -450,7 +450,7 @@ namespace BizHawk.Client.EmuHawk [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). 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 x = 0, int y = 0, 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()) { @@ -460,7 +460,7 @@ namespace BizHawk.Client.EmuHawk var i = 0; foreach (LuaTable point in points.Values) { - pointsArr[i] = new Point(LuaInt(point[1]) + x, LuaInt(point[2]) + y); + pointsArr[i] = new Point(LuaInt(point[1]) + x ?? 0, LuaInt(point[2]) + y ?? 0); i++; } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs index 2b0156cc84..6d98658c93 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs @@ -291,7 +291,7 @@ namespace BizHawk.Client.EmuHawk [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")] - public void DrawPolygon(LuaTable points, int x = 0, int y = 0, Color? line = null, Color? background = null) + public void DrawPolygon(LuaTable points, int? x = null, int? y = null, Color? line = null, Color? background = null) { try { diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs index 4f2d33a780..5d10dd1481 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs @@ -255,13 +255,13 @@ namespace BizHawk.Client.EmuHawk boxBackground.DrawLine(GetPen(color ?? _defaultForeground), x, y, x + 0.1F, y); } - public void DrawPolygon(LuaTable points, int x = 0, int y = 0, 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 i = 0; foreach (LuaTable point in points.Values) { - pointsArr[i] = new Point((int)(double)(point[1]) + x, (int)(double)(point[2]) + y); + pointsArr[i] = new Point((int)(double)(point[1]) + x ?? 0, (int)(double)(point[2]) + y ?? 0); i++; } From be2085ecfb43470ca9783962f7b388f627c3bbf2 Mon Sep 17 00:00:00 2001 From: Callie LeFave Date: Mon, 16 Apr 2018 16:56:56 -0400 Subject: [PATCH 3/3] ._. --- .../tools/Lua/Libraries/EmuLuaLibrary.Forms.cs | 2 +- BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs index 16e6789fc9..3b94fbf40d 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs @@ -1043,7 +1043,7 @@ namespace BizHawk.Client.EmuHawk { if (control is LuaPictureBox) { - (control as LuaPictureBox).DrawPolygon(points, line, x, y, background); + (control as LuaPictureBox).DrawPolygon(points, x, y, line, background); } } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs index 6d98658c93..58efd9554a 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs @@ -295,7 +295,7 @@ namespace BizHawk.Client.EmuHawk { try { - luaPictureBox.DrawPolygon(points, line, x, y, background); + luaPictureBox.DrawPolygon(points, x, y, line, background); } catch (Exception ex) {