Created 2 functions, GetPen and GetBrush. They will recieve an object variable to return a Pen/Brush of said color, this was made to clean the code of the draw functions.
This commit is contained in:
parent
b1d62ed574
commit
cf9606eb49
|
@ -6,6 +6,7 @@ using System.Text;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using LuaInterface;
|
using LuaInterface;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using System.Drawing;
|
||||||
using BizHawk.MultiClient.tools;
|
using BizHawk.MultiClient.tools;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
|
@ -168,6 +169,34 @@ namespace BizHawk.MultiClient
|
||||||
return Convert.ToUInt32((double)lua_arg);
|
return Convert.ToUInt32((double)lua_arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Pen GetPen(object color)
|
||||||
|
{
|
||||||
|
System.Drawing.Pen myPen;
|
||||||
|
if (color.GetType() == typeof(Double))
|
||||||
|
{
|
||||||
|
myPen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myPen = new System.Drawing.Pen(System.Drawing.Color.FromName(color.ToString().ToLower()));
|
||||||
|
}
|
||||||
|
return myPen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SolidBrush GetBrush(object color)
|
||||||
|
{
|
||||||
|
System.Drawing.SolidBrush myBrush;
|
||||||
|
if (color.GetType() == typeof(Double))
|
||||||
|
{
|
||||||
|
myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromName(color.ToString().ToLower()));
|
||||||
|
}
|
||||||
|
return myBrush;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LuaInterface requires the exact match of parameter count,
|
* LuaInterface requires the exact match of parameter count,
|
||||||
* except optional parameters. So, if you want to support
|
* except optional parameters. So, if you want to support
|
||||||
|
@ -472,28 +501,10 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
System.Drawing.Pen myPen;
|
g.DrawRectangle(GetPen(line), LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height));
|
||||||
if(line.GetType() == typeof(Double))
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(int.Parse(long.Parse(line.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromName(line.ToString().ToLower()));
|
|
||||||
}
|
|
||||||
g.DrawRectangle(myPen, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height));
|
|
||||||
if (background != null)
|
if (background != null)
|
||||||
{
|
{
|
||||||
System.Drawing.SolidBrush myBrush;
|
g.FillRectangle(GetBrush(background), LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height));
|
||||||
if (background.GetType() == typeof(Double))
|
|
||||||
{
|
|
||||||
myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(int.Parse(long.Parse(background.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromName(background.ToString().ToLower()));
|
|
||||||
}
|
|
||||||
g.FillRectangle(myBrush, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -510,18 +521,9 @@ namespace BizHawk.MultiClient
|
||||||
using (var g = luaSurface.GetGraphics())
|
using (var g = luaSurface.GetGraphics())
|
||||||
{
|
{
|
||||||
float x = LuaInt(X) + 0.1F;
|
float x = LuaInt(X) + 0.1F;
|
||||||
System.Drawing.Pen myPen;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (color.GetType() == typeof(Double))
|
g.DrawLine(GetPen(color), LuaInt(X), LuaInt(Y), x, LuaInt(Y));
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromName(color.ToString().ToLower()));
|
|
||||||
}
|
|
||||||
g.DrawLine(myPen, LuaInt(X), LuaInt(Y), x, LuaInt(Y));
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -535,19 +537,9 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
System.Drawing.Pen myPen;
|
if (color == null)
|
||||||
if (color == null)
|
color = "black";
|
||||||
color = "black";
|
g.DrawLine(GetPen(color), LuaInt(x1), LuaInt(y1), LuaInt(x2), LuaInt(y2));
|
||||||
|
|
||||||
if (color.GetType() == typeof(Double))
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromName(color.ToString().ToLower()));
|
|
||||||
}
|
|
||||||
g.DrawLine(myPen, LuaInt(x1), LuaInt(y1), LuaInt(x2), LuaInt(y2));
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -562,28 +554,10 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
System.Drawing.Pen myPen;
|
g.DrawEllipse(GetPen(line), LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height));
|
||||||
if (line.GetType() == typeof(Double))
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(int.Parse(long.Parse(line.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromName(line.ToString().ToLower()));
|
|
||||||
}
|
|
||||||
g.DrawEllipse(myPen, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height));
|
|
||||||
if (background != null)
|
if (background != null)
|
||||||
{
|
{
|
||||||
System.Drawing.SolidBrush myBrush;
|
g.FillEllipse(GetBrush(background), LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height));
|
||||||
if (background.GetType() == typeof(Double))
|
|
||||||
{
|
|
||||||
myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(int.Parse(long.Parse(background.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromName(background.ToString().ToLower()));
|
|
||||||
}
|
|
||||||
g.FillEllipse(myBrush, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -609,28 +583,11 @@ namespace BizHawk.MultiClient
|
||||||
Points[i] = new System.Drawing.Point(LuaInt(point[1]), LuaInt(point[2]));
|
Points[i] = new System.Drawing.Point(LuaInt(point[1]), LuaInt(point[2]));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
System.Drawing.Pen myPen;
|
|
||||||
if (line.GetType() == typeof(Double))
|
g.DrawPolygon(GetPen(line), Points);
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(int.Parse(long.Parse(line.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromName(line.ToString().ToLower()));
|
|
||||||
}
|
|
||||||
g.DrawPolygon(myPen, Points);
|
|
||||||
if (background != null)
|
if (background != null)
|
||||||
{
|
{
|
||||||
System.Drawing.SolidBrush myBrush;
|
g.FillPolygon(GetBrush(background), Points);
|
||||||
if (background.GetType() == typeof(Double))
|
|
||||||
{
|
|
||||||
myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(int.Parse(long.Parse(background.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromName(background.ToString().ToLower()));
|
|
||||||
}
|
|
||||||
g.FillPolygon(myBrush, Points);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -655,16 +612,7 @@ namespace BizHawk.MultiClient
|
||||||
if (i >= 4)
|
if (i >= 4)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
System.Drawing.Pen myPen;
|
g.DrawBezier(GetPen(color), Points[0], Points[1], Points[2], Points[3]);
|
||||||
if (color.GetType() == typeof(Double))
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromName(color.ToString().ToLower()));
|
|
||||||
}
|
|
||||||
g.DrawBezier(myPen, Points[0], Points[1], Points[2], Points[3]);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -679,28 +627,10 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
System.Drawing.Pen myPen;
|
g.DrawPie(GetPen(line), LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle));
|
||||||
if (line.GetType() == typeof(Double))
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(int.Parse(long.Parse(line.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myPen = new System.Drawing.Pen(System.Drawing.Color.FromName(line.ToString().ToLower()));
|
|
||||||
}
|
|
||||||
g.DrawPie(myPen, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle));
|
|
||||||
if (background != null)
|
if (background != null)
|
||||||
{
|
{
|
||||||
System.Drawing.SolidBrush myBrush;
|
g.FillPie(GetBrush(background), LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle));
|
||||||
if (background.GetType() == typeof(Double))
|
|
||||||
{
|
|
||||||
myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(int.Parse(long.Parse(background.ToString()).ToString("X"), System.Globalization.NumberStyles.HexNumber)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromName(background.ToString().ToLower()));
|
|
||||||
}
|
|
||||||
g.FillPie(myBrush, LuaInt(X), LuaInt(Y), LuaInt(width), LuaInt(height), LuaInt(startangle), LuaInt(sweepangle));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue