Lua Interface - support Strongly typing System.Drawing.Color, and strongly type the color parameters of gui.drawEllipse()
This commit is contained in:
parent
83ada011e8
commit
58b5163715
|
@ -68,8 +68,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private DisplaySurface _luaSurface;
|
||||
|
||||
// TODO: obsolete this method and strongly type all colors
|
||||
private static Color GetColor(object color)
|
||||
{
|
||||
if (color is Color)
|
||||
{
|
||||
return (Color)color;
|
||||
}
|
||||
if (color is double)
|
||||
{
|
||||
return Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"), NumberStyles.HexNumber));
|
||||
|
@ -233,14 +238,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
"drawEllipse",
|
||||
"Draws an ellipse at the given coordinates and the given width and height. Line is the color of the ellipse. Background is the optional fill color"
|
||||
)]
|
||||
public void DrawEllipse(int x, int y, int width, int height, object line, object background = null)
|
||||
public void DrawEllipse(int x, int y, int width, int height, Color? line, Color? background = null)
|
||||
{
|
||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
try
|
||||
{
|
||||
g.DrawEllipse(GetPen(line ?? "white"), x, y, width, height);
|
||||
g.DrawEllipse(GetPen(line ?? Color.White), x, y, width, height);
|
||||
if (background != null)
|
||||
{
|
||||
var brush = GetBrush(background);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
using Lua511;
|
||||
|
||||
|
@ -40,7 +41,7 @@ namespace LuaInterface
|
|||
extractValues.Add(typeof(LuaFunction).TypeHandle.Value.ToInt64(), new ExtractValue(getAsFunction));
|
||||
extractValues.Add(typeof(LuaTable).TypeHandle.Value.ToInt64(), new ExtractValue(getAsTable));
|
||||
extractValues.Add(typeof(LuaUserData).TypeHandle.Value.ToInt64(), new ExtractValue(getAsUserdata));
|
||||
|
||||
extractValues.Add(typeof(Color).TypeHandle.Value.ToInt64(), new ExtractValue(getAsColor));
|
||||
extractNetObject = new ExtractValue(getAsNetObject);
|
||||
}
|
||||
|
||||
|
@ -108,7 +109,11 @@ namespace LuaInterface
|
|||
if (LuaDLL.lua_isboolean(luaState, stackPos))
|
||||
return extractValues[runtimeHandleValue];
|
||||
}
|
||||
else if (paramType == typeof(string) || paramType == typeof (char []))
|
||||
else if (paramType == typeof(Color))
|
||||
{
|
||||
return extractValues[runtimeHandleValue];
|
||||
}
|
||||
else if (paramType == typeof(string) || paramType == typeof(char[]))
|
||||
{
|
||||
if (LuaDLL.lua_isstring(luaState, stackPos))
|
||||
return extractValues[runtimeHandleValue];
|
||||
|
@ -252,6 +257,29 @@ namespace LuaInterface
|
|||
if(retVal=="" && !LuaDLL.lua_isstring(luaState,stackPos)) return null;
|
||||
return retVal;
|
||||
}
|
||||
private object getAsColor(IntPtr luaState, int stackPos)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (LuaDLL.lua_isnumber(luaState, stackPos))
|
||||
{
|
||||
Color retVal = Color.FromArgb((int)LuaDLL.lua_tonumber(luaState, stackPos));
|
||||
return retVal;
|
||||
}
|
||||
else if (LuaDLL.lua_isstring(luaState, stackPos))
|
||||
{
|
||||
|
||||
Color retVal = Color.FromName(LuaDLL.lua_tostring(luaState, stackPos));
|
||||
return retVal;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private object getAsTable(IntPtr luaState,int stackPos)
|
||||
{
|
||||
return translator.getTable(luaState,stackPos);
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue