tastudio/lua - add onqueryitembg event to the lua library, this is called during each cell's background color drawing callback, and gives the opportunity for lua to override the color.

This commit is contained in:
adelikat 2015-07-01 19:01:29 -04:00
parent a0f3931257
commit f847e905d2
3 changed files with 73 additions and 0 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Drawing;
using System.Linq;
using LuaInterface;
@ -63,5 +64,30 @@ namespace BizHawk.Client.Common
{
return (uint)(double)luaArg;
}
protected static Color? ToColor(object color)
{
if (color == null)
{
return null;
}
double tryNum = double.NaN;
var result = double.TryParse(color.ToString(), out tryNum);
if (result)
{
var stringResult = ((int)tryNum).ToString();
return ColorTranslator.FromHtml(stringResult);
}
if (!string.IsNullOrWhiteSpace(color.ToString()))
{
return Color.FromName(color.ToString());
}
return null;
}
}
}

View File

@ -125,5 +125,28 @@ namespace BizHawk.Client.EmuHawk
return false;
}
[LuaMethodAttributes(
"onqueryitembg",
"called during the background draw event of the tastudio listview"
)]
public void OnQueryItemBg(LuaFunction luaf)
{
if (Engaged())
{
Tastudio.QueryItemBgColorCallback = (int index, string name) =>
{
var result = luaf.Call(index, name);
if (result != null)
{
var color = ToColor(result[0]);
return color;
}
return null;
};
}
}
}
}

View File

@ -95,8 +95,32 @@ namespace BizHawk.Client.EmuHawk
}
}
#region Event callbacks
public Func<int, string, Color?> QueryItemBgColorCallback { get; set; }
public Color? GetColorOverride(int index, InputRoll.RollColumn column)
{
if (QueryItemBgColorCallback != null)
{
return QueryItemBgColorCallback(index, column.Name);
}
return null;
}
#endregion
private void TasView_QueryItemBkColor(int index, InputRoll.RollColumn column, ref Color color)
{
var overrideColor = GetColorOverride(index, column);
if (overrideColor.HasValue)
{
color = overrideColor.Value;
return;
}
string columnName = column.Name;
if (columnName == MarkerColumnName)