Lua - Finish strongly typing the Color params in the gui library, Lua Functions List - cleanup display of Color params and some other things
This commit is contained in:
parent
58b5163715
commit
5d79072a38
|
@ -86,7 +86,9 @@ namespace BizHawk.Client.Common
|
||||||
.Replace(" ", string.Empty)
|
.Replace(" ", string.Empty)
|
||||||
.Replace(".", string.Empty)
|
.Replace(".", string.Empty)
|
||||||
.Replace("LuaInterface", string.Empty)
|
.Replace("LuaInterface", string.Empty)
|
||||||
|
.Replace("Object[]", "object[] ")
|
||||||
.Replace("Object", "object ")
|
.Replace("Object", "object ")
|
||||||
|
.Replace("Boolean[]", "bool[] ")
|
||||||
.Replace("Boolean", "bool ")
|
.Replace("Boolean", "bool ")
|
||||||
.Replace("String", "string ")
|
.Replace("String", "string ")
|
||||||
.Replace("LuaTable", "table ")
|
.Replace("LuaTable", "table ")
|
||||||
|
@ -102,7 +104,9 @@ namespace BizHawk.Client.Common
|
||||||
.Replace("UInt32", "uint ")
|
.Replace("UInt32", "uint ")
|
||||||
.Replace("UInt64", "ulong ")
|
.Replace("UInt64", "ulong ")
|
||||||
.Replace("Double", "double ")
|
.Replace("Double", "double ")
|
||||||
.Replace("Uint", "uint ");
|
.Replace("Uint", "uint ")
|
||||||
|
.Replace("Nullable`1[DrawingColor]", "Color? ")
|
||||||
|
.Replace("DrawingColor", "Color ");
|
||||||
|
|
||||||
list.Append(param);
|
list.Append(param);
|
||||||
if (i < Parameters.Count - 1)
|
if (i < Parameters.Count - 1)
|
||||||
|
|
|
@ -68,44 +68,25 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private DisplaySurface _luaSurface;
|
private DisplaySurface _luaSurface;
|
||||||
|
|
||||||
// TODO: obsolete this method and strongly type all colors
|
private SolidBrush GetBrush(Color color)
|
||||||
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));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Color.FromName(color.ToString().ToLower());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private SolidBrush GetBrush(object color)
|
|
||||||
{
|
|
||||||
var c = GetColor(color);
|
|
||||||
SolidBrush b;
|
SolidBrush b;
|
||||||
if (!_solidBrushes.TryGetValue(c, out b))
|
if (!_solidBrushes.TryGetValue(color, out b))
|
||||||
{
|
{
|
||||||
b = new SolidBrush(c);
|
b = new SolidBrush(color);
|
||||||
_solidBrushes[c] = b;
|
_solidBrushes[color] = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pen GetPen(object color)
|
private Pen GetPen(Color color)
|
||||||
{
|
{
|
||||||
var c = GetColor(color);
|
|
||||||
Pen p;
|
Pen p;
|
||||||
if (!_pens.TryGetValue(c, out p))
|
if (!_pens.TryGetValue(color, out p))
|
||||||
{
|
{
|
||||||
p = new Pen(c);
|
p = new Pen(color);
|
||||||
_pens[c] = p;
|
_pens[color] = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
@ -161,7 +142,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
"drawBezier",
|
"drawBezier",
|
||||||
"Draws a Bezier curve using the table of coordinates provided in the given color"
|
"Draws a Bezier curve using the table of coordinates provided in the given color"
|
||||||
)]
|
)]
|
||||||
public void DrawBezier(LuaTable points, object color)
|
public void DrawBezier(LuaTable points, Color color)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
|
@ -194,7 +175,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
"drawBox",
|
"drawBox",
|
||||||
"Draws a rectangle on screen from x1/y1 to x2/y2. Same as drawRectangle except it receives two points intead of a point and width/height"
|
"Draws a rectangle on screen from x1/y1 to x2/y2. Same as drawRectangle except it receives two points intead of a point and width/height"
|
||||||
)]
|
)]
|
||||||
public void DrawBox(int x, int y, int x2, int y2, object line = null, object background = null)
|
public void DrawBox(int x, int y, int x2, int y2, Color? line = null, Color? background = null)
|
||||||
{
|
{
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
|
@ -220,10 +201,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
y -= y2;
|
y -= y2;
|
||||||
}
|
}
|
||||||
|
|
||||||
g.DrawRectangle(GetPen(line ?? "white"), x, y, x2, y2);
|
g.DrawRectangle(GetPen(line ?? Color.White), x, y, x2, y2);
|
||||||
if (background != null)
|
if (background.HasValue)
|
||||||
{
|
{
|
||||||
g.FillRectangle(GetBrush(background), x, y, x2, y2);
|
g.FillRectangle(GetBrush(background.Value), x, y, x2, y2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -246,9 +227,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
g.DrawEllipse(GetPen(line ?? Color.White), x, y, width, height);
|
g.DrawEllipse(GetPen(line ?? Color.White), x, y, width, height);
|
||||||
if (background != null)
|
if (background.HasValue)
|
||||||
{
|
{
|
||||||
var brush = GetBrush(background);
|
var brush = GetBrush(background.Value);
|
||||||
g.FillEllipse(brush, x, y, width, height);
|
g.FillEllipse(brush, x, y, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,12 +289,12 @@ namespace BizHawk.Client.EmuHawk
|
||||||
"drawLine",
|
"drawLine",
|
||||||
"Draws a line from the first coordinate pair to the 2nd. Color is optional (if not specified it will be drawn black)"
|
"Draws a line from the first coordinate pair to the 2nd. Color is optional (if not specified it will be drawn black)"
|
||||||
)]
|
)]
|
||||||
public void DrawLine(int x1, int y1, int x2, int y2, object color = null)
|
public void DrawLine(int x1, int y1, int x2, int y2, Color? color = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
g.DrawLine(GetPen(color ?? "white"), x1, y1, x2, y2);
|
g.DrawLine(GetPen(color ?? Color.White), x1, y1, x2, y2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,16 +309,16 @@ namespace BizHawk.Client.EmuHawk
|
||||||
int height,
|
int height,
|
||||||
int startangle,
|
int startangle,
|
||||||
int sweepangle,
|
int sweepangle,
|
||||||
object line,
|
Color line,
|
||||||
object background = null)
|
Color? background = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
g.DrawPie(GetPen(line), x, y, width, height, startangle, sweepangle);
|
g.DrawPie(GetPen(line), x, y, width, height, startangle, sweepangle);
|
||||||
if (background != null)
|
if (background.HasValue)
|
||||||
{
|
{
|
||||||
var brush = GetBrush(background);
|
var brush = GetBrush(background.Value);
|
||||||
g.FillPie(brush, x, y, width, height, startangle, sweepangle);
|
g.FillPie(brush, x, y, width, height, startangle, sweepangle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -347,14 +328,14 @@ namespace BizHawk.Client.EmuHawk
|
||||||
"drawPixel",
|
"drawPixel",
|
||||||
"Draws a single pixel at the given coordinates in the given color. Color is optional (if not specified it will be drawn black)"
|
"Draws a single pixel at the given coordinates in the given color. Color is optional (if not specified it will be drawn black)"
|
||||||
)]
|
)]
|
||||||
public void DrawPixel(int x, int y, object color = null)
|
public void DrawPixel(int x, int y, Color? color = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
g.DrawLine(GetPen(color ?? "white"), x, y, x + 0.1F, y);
|
g.DrawLine(GetPen(color ?? Color.White), x, y, x + 0.1F, y);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -367,7 +348,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
"drawPolygon",
|
"drawPolygon",
|
||||||
"Draws a polygon using the table of coordinates specified in points. Line is the color of the polygon. Background is the optional fill color"
|
"Draws a polygon using the table of coordinates specified in points. Line is the color of the polygon. Background is the optional fill color"
|
||||||
)]
|
)]
|
||||||
public void DrawPolygon(LuaTable points, object line, object background = null)
|
public void DrawPolygon(LuaTable points, Color line, Color? background = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
|
|
||||||
|
@ -384,9 +365,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
g.DrawPolygon(GetPen(line), pointsArr);
|
g.DrawPolygon(GetPen(line), pointsArr);
|
||||||
if (background != null)
|
if (background.HasValue)
|
||||||
{
|
{
|
||||||
g.FillPolygon(GetBrush(background), pointsArr);
|
g.FillPolygon(GetBrush(background.Value), pointsArr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -400,14 +381,14 @@ namespace BizHawk.Client.EmuHawk
|
||||||
"drawRectangle",
|
"drawRectangle",
|
||||||
"Draws a rectangle at the given coordinate and the given width and height. Line is the color of the box. Background is the optional fill color"
|
"Draws a rectangle at the given coordinate and the given width and height. Line is the color of the box. Background is the optional fill color"
|
||||||
)]
|
)]
|
||||||
public void DrawRectangle(int x, int y, int width, int height, object line, object background = null)
|
public void DrawRectangle(int x, int y, int width, int height, Color? line = null, Color? background = null)
|
||||||
{
|
{
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
g.DrawRectangle(GetPen(line ?? "white"), x, y, width, height);
|
g.DrawRectangle(GetPen(line ?? Color.White), x, y, width, height);
|
||||||
if (background != null)
|
if (background.HasValue)
|
||||||
{
|
{
|
||||||
g.FillRectangle(GetBrush(background), x, y, width, height);
|
g.FillRectangle(GetBrush(background.Value), x, y, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,7 +401,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
string message,
|
string message,
|
||||||
object color = null,
|
Color? color = null,
|
||||||
int? fontsize = null,
|
int? fontsize = null,
|
||||||
string fontfamily = null,
|
string fontfamily = null,
|
||||||
string fontstyle = null)
|
string fontstyle = null)
|
||||||
|
@ -436,7 +417,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
string message,
|
string message,
|
||||||
object color = null,
|
Color? color = null,
|
||||||
int? fontsize = null,
|
int? fontsize = null,
|
||||||
string fontfamily = null,
|
string fontfamily = null,
|
||||||
string fontstyle = null)
|
string fontstyle = null)
|
||||||
|
@ -476,7 +457,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
var font = new Font(family, fontsize ?? 12, fstyle, GraphicsUnit.Pixel);
|
var font = new Font(family, fontsize ?? 12, fstyle, GraphicsUnit.Pixel);
|
||||||
g.DrawString(message, font, GetBrush(color ?? "white"), x, y);
|
g.DrawString(message, font, GetBrush(color ?? Color.White), x, y);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -493,8 +474,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
string message,
|
string message,
|
||||||
object background = null,
|
Color? background = null,
|
||||||
object forecolor = null,
|
Color? forecolor = null,
|
||||||
string anchor = null)
|
string anchor = null)
|
||||||
{
|
{
|
||||||
var a = 0;
|
var a = 0;
|
||||||
|
@ -527,7 +508,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
y -= Global.Emulator.CoreComm.ScreenLogicalOffsetY;
|
y -= Global.Emulator.CoreComm.ScreenLogicalOffsetY;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalWin.OSD.AddGUIText(message, x, y, GetColor(background ?? "black"), GetColor(forecolor ?? "white"), a);
|
GlobalWin.OSD.AddGUIText(message, x, y, background ?? Color.Black, forecolor ?? Color.White, a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue