Lua - gui library - make all colors optional parameters and use defaults if not provided (initially white foreground and transparent background). Add gui.defaultForeground(color) and gui.defaultBackground(color) to change those defaults
This commit is contained in:
parent
aabd3f4526
commit
b45d3820be
|
@ -21,6 +21,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public GuiLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
public GuiLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
||||||
: base(lua, logOutputCallback) { }
|
: base(lua, logOutputCallback) { }
|
||||||
|
|
||||||
|
private Color DefaultForeground = Color.White;
|
||||||
|
private Color? DefaultBackground = null;
|
||||||
|
|
||||||
public override string Name { get { return "gui"; } }
|
public override string Name { get { return "gui"; } }
|
||||||
|
|
||||||
#region Gui API
|
#region Gui API
|
||||||
|
@ -155,6 +158,24 @@ namespace BizHawk.Client.EmuHawk
|
||||||
GlobalWin.OSD.ClearGUIText();
|
GlobalWin.OSD.ClearGUIText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[LuaMethodAttributes(
|
||||||
|
"defaultForeground",
|
||||||
|
"Sets the default foreground color to use when using drawing methods, white by default"
|
||||||
|
)]
|
||||||
|
public void SetDefaultForegroundColor(Color color)
|
||||||
|
{
|
||||||
|
DefaultForeground = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
[LuaMethodAttributes(
|
||||||
|
"defaultBackground",
|
||||||
|
"Sets the default background color to use when using drawing methods, transparent by default"
|
||||||
|
)]
|
||||||
|
public void SetDefaultBackgroundColor(Color color)
|
||||||
|
{
|
||||||
|
DefaultBackground = color;
|
||||||
|
}
|
||||||
|
|
||||||
[LuaMethodAttributes(
|
[LuaMethodAttributes(
|
||||||
"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"
|
||||||
|
@ -218,10 +239,12 @@ namespace BizHawk.Client.EmuHawk
|
||||||
y -= y2;
|
y -= y2;
|
||||||
}
|
}
|
||||||
|
|
||||||
g.DrawRectangle(GetPen(line ?? Color.White), x, y, x2, y2);
|
g.DrawRectangle(GetPen(line ?? DefaultForeground), x, y, x2, y2);
|
||||||
if (background.HasValue)
|
|
||||||
|
var bg = background ?? DefaultBackground;
|
||||||
|
if (bg.HasValue)
|
||||||
{
|
{
|
||||||
g.FillRectangle(GetBrush(background.Value), x, y, x2, y2);
|
g.FillRectangle(GetBrush(bg.Value), x, y, x2, y2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -236,17 +259,19 @@ namespace BizHawk.Client.EmuHawk
|
||||||
"drawEllipse",
|
"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"
|
"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, Color? line, Color? background = null)
|
public void DrawEllipse(int x, int y, int width, int height, Color? line = null, Color? background = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
g.DrawEllipse(GetPen(line ?? Color.White), x, y, width, height);
|
g.DrawEllipse(GetPen(line ?? DefaultForeground), x, y, width, height);
|
||||||
if (background.HasValue)
|
|
||||||
|
var bg = background ?? DefaultBackground;
|
||||||
|
if (bg.HasValue)
|
||||||
{
|
{
|
||||||
var brush = GetBrush(background.Value);
|
var brush = GetBrush(bg.Value);
|
||||||
g.FillEllipse(brush, x, y, width, height);
|
g.FillEllipse(brush, x, y, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,7 +348,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
g.DrawLine(GetPen(color ?? Color.White), x1, y1, x2, y2);
|
g.DrawLine(GetPen(color ?? DefaultForeground), x1, y1, x2, y2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,16 +363,17 @@ namespace BizHawk.Client.EmuHawk
|
||||||
int height,
|
int height,
|
||||||
int startangle,
|
int startangle,
|
||||||
int sweepangle,
|
int sweepangle,
|
||||||
Color line,
|
Color? line = null,
|
||||||
Color? 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 ?? DefaultForeground), x, y, width, height, startangle, sweepangle);
|
||||||
if (background.HasValue)
|
var bg = background ?? DefaultBackground;
|
||||||
|
if (bg.HasValue)
|
||||||
{
|
{
|
||||||
var brush = GetBrush(background.Value);
|
var brush = GetBrush(bg.Value);
|
||||||
g.FillPie(brush, x, y, width, height, startangle, sweepangle);
|
g.FillPie(brush, x, y, width, height, startangle, sweepangle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -364,7 +390,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
g.DrawLine(GetPen(color ?? Color.White), x, y, x + 0.1F, y);
|
g.DrawLine(GetPen(color ?? DefaultForeground), x, y, x + 0.1F, y);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -377,7 +403,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, Color line, Color? background = null)
|
public void DrawPolygon(LuaTable points, Color? line = null, Color? background = null)
|
||||||
{
|
{
|
||||||
GlobalWin.DisplayManager.NeedsToPaint = true;
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
||||||
|
|
||||||
|
@ -393,10 +419,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
g.DrawPolygon(GetPen(line), pointsArr);
|
g.DrawPolygon(GetPen(line ?? DefaultForeground), pointsArr);
|
||||||
if (background.HasValue)
|
var bg = background ?? DefaultBackground;
|
||||||
|
if (bg.HasValue)
|
||||||
{
|
{
|
||||||
g.FillPolygon(GetBrush(background.Value), pointsArr);
|
g.FillPolygon(GetBrush(bg.Value), pointsArr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -414,10 +441,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
using (var g = GetGraphics())
|
using (var g = GetGraphics())
|
||||||
{
|
{
|
||||||
g.DrawRectangle(GetPen(line ?? Color.White), x, y, width, height);
|
g.DrawRectangle(GetPen(line ?? DefaultForeground), x, y, width, height);
|
||||||
if (background.HasValue)
|
var bg = background ?? DefaultBackground;
|
||||||
|
if (bg.HasValue)
|
||||||
{
|
{
|
||||||
g.FillRectangle(GetBrush(background.Value), x, y, width, height);
|
g.FillRectangle(GetBrush(bg.Value), x, y, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -487,7 +515,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.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
|
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
|
||||||
g.DrawString(message, font, GetBrush(color ?? Color.White), x, y);
|
g.DrawString(message, font, GetBrush(color ?? DefaultForeground), x, y);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue