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:
adelikat 2015-02-23 03:10:38 +00:00
parent aabd3f4526
commit b45d3820be
1 changed files with 49 additions and 21 deletions

View File

@ -21,6 +21,9 @@ namespace BizHawk.Client.EmuHawk
public GuiLuaLibrary(Lua lua, Action<string> logOutputCallback)
: base(lua, logOutputCallback) { }
private Color DefaultForeground = Color.White;
private Color? DefaultBackground = null;
public override string Name { get { return "gui"; } }
#region Gui API
@ -155,6 +158,24 @@ namespace BizHawk.Client.EmuHawk
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(
"drawBezier",
"Draws a Bezier curve using the table of coordinates provided in the given color"
@ -218,10 +239,12 @@ namespace BizHawk.Client.EmuHawk
y -= y2;
}
g.DrawRectangle(GetPen(line ?? Color.White), x, y, x2, y2);
if (background.HasValue)
g.DrawRectangle(GetPen(line ?? DefaultForeground), x, y, x2, y2);
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)
@ -236,17 +259,19 @@ 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, 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;
using (var g = GetGraphics())
{
try
{
g.DrawEllipse(GetPen(line ?? Color.White), x, y, width, height);
if (background.HasValue)
g.DrawEllipse(GetPen(line ?? DefaultForeground), x, y, width, height);
var bg = background ?? DefaultBackground;
if (bg.HasValue)
{
var brush = GetBrush(background.Value);
var brush = GetBrush(bg.Value);
g.FillEllipse(brush, x, y, width, height);
}
}
@ -323,7 +348,7 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.DisplayManager.NeedsToPaint = true;
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 startangle,
int sweepangle,
Color line,
Color? line = null,
Color? background = null)
{
GlobalWin.DisplayManager.NeedsToPaint = true;
using (var g = GetGraphics())
{
g.DrawPie(GetPen(line), x, y, width, height, startangle, sweepangle);
if (background.HasValue)
g.DrawPie(GetPen(line ?? DefaultForeground), x, y, width, height, startangle, sweepangle);
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);
}
}
@ -364,7 +390,7 @@ namespace BizHawk.Client.EmuHawk
{
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)
{
@ -377,7 +403,7 @@ namespace BizHawk.Client.EmuHawk
"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"
)]
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;
@ -393,10 +419,11 @@ namespace BizHawk.Client.EmuHawk
i++;
}
g.DrawPolygon(GetPen(line), pointsArr);
if (background.HasValue)
g.DrawPolygon(GetPen(line ?? DefaultForeground), pointsArr);
var bg = background ?? DefaultBackground;
if (bg.HasValue)
{
g.FillPolygon(GetBrush(background.Value), pointsArr);
g.FillPolygon(GetBrush(bg.Value), pointsArr);
}
}
catch (Exception)
@ -414,10 +441,11 @@ namespace BizHawk.Client.EmuHawk
{
using (var g = GetGraphics())
{
g.DrawRectangle(GetPen(line ?? Color.White), x, y, width, height);
if (background.HasValue)
g.DrawRectangle(GetPen(line ?? DefaultForeground), x, y, width, height);
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);
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)
{