move the gui library to its own function (all libraries are separate objects now!), add lua function: gui.clearGraphics()
This commit is contained in:
parent
4bb60ec8c9
commit
ae34ccce0a
|
@ -8,14 +8,95 @@ using BizHawk.Client.Common;
|
||||||
|
|
||||||
namespace BizHawk.MultiClient
|
namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
public partial class EmuLuaLibrary
|
public class GuiLuaLibrary : LuaLibraryBase
|
||||||
{
|
{
|
||||||
#region Gui Library Helpers
|
public override string Name { get { return "gui"; } }
|
||||||
|
public override string[] Functions
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
"addmessage",
|
||||||
|
"alert",
|
||||||
|
"clearGraphics",
|
||||||
|
"cleartext",
|
||||||
|
"drawBezier",
|
||||||
|
"drawBox",
|
||||||
|
"drawEllipse",
|
||||||
|
"drawIcon",
|
||||||
|
"drawImage",
|
||||||
|
"drawLine",
|
||||||
|
"drawPie",
|
||||||
|
"drawPixel",
|
||||||
|
"drawPolygon",
|
||||||
|
"drawRectangle",
|
||||||
|
"drawString",
|
||||||
|
"drawText",
|
||||||
|
"text",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Gui API
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
foreach (var brush in SolidBrushes.Values) brush.Dispose();
|
||||||
|
foreach (var brush in Pens.Values) brush.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SurfaceIsNull
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return luaSurface == null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// sets the current drawing context to a new surface.
|
||||||
|
/// you COULD pass these back to lua to use as a target in rendering jobs, instead of setting it as current here.
|
||||||
|
/// could be more powerful.
|
||||||
|
/// performance test may reveal that repeatedly calling GetGraphics could be slow.
|
||||||
|
/// we may want to make a class here in LuaImplementation that wraps a DisplaySurface and a Graphics which would be created once
|
||||||
|
/// </summary>
|
||||||
|
public void DrawNew()
|
||||||
|
{
|
||||||
|
luaSurface = GlobalWinF.DisplayManager.GetLuaSurfaceNative();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawNewEmu()
|
||||||
|
{
|
||||||
|
luaSurface = GlobalWinF.DisplayManager.GetLuaEmuSurfaceEmu();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// finishes the current drawing and submits it to the display manager (at native [host] resolution pre-osd)
|
||||||
|
/// you would probably want some way to specify which surface to set it to, when there are other surfaces.
|
||||||
|
/// most notably, the client output [emulated] resolution
|
||||||
|
/// </summary>
|
||||||
|
public void DrawFinish()
|
||||||
|
{
|
||||||
|
GlobalWinF.DisplayManager.SetLuaSurfaceNativePreOSD(luaSurface);
|
||||||
|
luaSurface = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawFinishEmu()
|
||||||
|
{
|
||||||
|
GlobalWinF.DisplayManager.SetLuaSurfaceEmu(luaSurface);
|
||||||
|
luaSurface = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Helpers
|
||||||
|
|
||||||
|
private DisplaySurface luaSurface;
|
||||||
private readonly Dictionary<Color, SolidBrush> SolidBrushes = new Dictionary<Color, SolidBrush>();
|
private readonly Dictionary<Color, SolidBrush> SolidBrushes = new Dictionary<Color, SolidBrush>();
|
||||||
private readonly Dictionary<Color, Pen> Pens = new Dictionary<Color, Pen>();
|
private readonly Dictionary<Color, Pen> Pens = new Dictionary<Color, Pen>();
|
||||||
|
|
||||||
public Color GetColor(object color)
|
private static Color GetColor(object color)
|
||||||
{
|
{
|
||||||
if (color is double)
|
if (color is double)
|
||||||
{
|
{
|
||||||
|
@ -27,7 +108,7 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SolidBrush GetBrush(object color)
|
private SolidBrush GetBrush(object color)
|
||||||
{
|
{
|
||||||
Color c = GetColor(color);
|
Color c = GetColor(color);
|
||||||
SolidBrush b;
|
SolidBrush b;
|
||||||
|
@ -39,7 +120,7 @@ namespace BizHawk.MultiClient
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pen GetPen(object color)
|
private Pen GetPen(object color)
|
||||||
{
|
{
|
||||||
Color c = GetColor(color);
|
Color c = GetColor(color);
|
||||||
Pen p;
|
Pen p;
|
||||||
|
@ -51,47 +132,7 @@ namespace BizHawk.MultiClient
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_clearGraphics()
|
private Graphics GetGraphics()
|
||||||
{
|
|
||||||
GlobalWinF.DisplayManager.NeedsToPaint = true;
|
|
||||||
luaSurface.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// sets the current drawing context to a new surface.
|
|
||||||
/// you COULD pass these back to lua to use as a target in rendering jobs, instead of setting it as current here.
|
|
||||||
/// could be more powerful.
|
|
||||||
/// performance test may reveal that repeatedly calling GetGraphics could be slow.
|
|
||||||
/// we may want to make a class here in LuaImplementation that wraps a DisplaySurface and a Graphics which would be created once
|
|
||||||
/// </summary>
|
|
||||||
public void gui_drawNew()
|
|
||||||
{
|
|
||||||
luaSurface = GlobalWinF.DisplayManager.GetLuaSurfaceNative();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void gui_drawNewEmu()
|
|
||||||
{
|
|
||||||
luaSurface = GlobalWinF.DisplayManager.GetLuaEmuSurfaceEmu();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// finishes the current drawing and submits it to the display manager (at native [host] resolution pre-osd)
|
|
||||||
/// you would probably want some way to specify which surface to set it to, when there are other surfaces.
|
|
||||||
/// most notably, the client output [emulated] resolution
|
|
||||||
/// </summary>
|
|
||||||
public void gui_drawFinish()
|
|
||||||
{
|
|
||||||
GlobalWinF.DisplayManager.SetLuaSurfaceNativePreOSD(luaSurface);
|
|
||||||
luaSurface = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void gui_drawFinishEmu()
|
|
||||||
{
|
|
||||||
GlobalWinF.DisplayManager.SetLuaSurfaceEmu(luaSurface);
|
|
||||||
luaSurface = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Graphics GetGraphics()
|
|
||||||
{
|
{
|
||||||
var g = luaSurface.GetGraphics();
|
var g = luaSurface.GetGraphics();
|
||||||
int tx = Global.Emulator.CoreComm.ScreenLogicalOffsetX;
|
int tx = Global.Emulator.CoreComm.ScreenLogicalOffsetX;
|
||||||
|
@ -105,9 +146,7 @@ namespace BizHawk.MultiClient
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DisplaySurface luaSurface;
|
private void DoGuiText(object luaX, object luaY, object luaStr, bool alert, object background = null,
|
||||||
|
|
||||||
private void do_gui_text(object luaX, object luaY, object luaStr, bool alert, object background = null,
|
|
||||||
object forecolor = null, object anchor = null)
|
object forecolor = null, object anchor = null)
|
||||||
{
|
{
|
||||||
if (!alert)
|
if (!alert)
|
||||||
|
@ -160,10 +199,16 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
public void gui_alert(object luaX, object luaY, object luaStr, object anchor = null)
|
public void gui_alert(object luaX, object luaY, object luaStr, object anchor = null)
|
||||||
{
|
{
|
||||||
do_gui_text(luaX, luaY, luaStr, true, null, null, anchor);
|
DoGuiText(luaX, luaY, luaStr, true, null, null, anchor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gui_cleartext()
|
public void gui_clearGraphics()
|
||||||
|
{
|
||||||
|
GlobalWinF.DisplayManager.NeedsToPaint = true;
|
||||||
|
luaSurface.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void gui_cleartext()
|
||||||
{
|
{
|
||||||
GlobalWinF.OSD.ClearGUIText();
|
GlobalWinF.OSD.ClearGUIText();
|
||||||
}
|
}
|
||||||
|
@ -421,10 +466,8 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void gui_drawString(object X, object Y, object message, object color = null, object fontsize = null, object fontfamily = null, object fontstyle = null)
|
public void gui_drawString(object X, object Y, object message, object color = null, object fontsize = null, object fontfamily = null, object fontstyle = null)
|
||||||
{
|
{
|
||||||
GlobalWinF.DisplayManager.NeedsToPaint = true;
|
|
||||||
gui_drawText(X, Y, message, color, fontsize, fontfamily, fontstyle);
|
gui_drawText(X, Y, message, color, fontsize, fontfamily, fontstyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +527,7 @@ namespace BizHawk.MultiClient
|
||||||
public void gui_text(object luaX, object luaY, object luaStr, object background = null, object forecolor = null,
|
public void gui_text(object luaX, object luaY, object luaStr, object background = null, object forecolor = null,
|
||||||
object anchor = null)
|
object anchor = null)
|
||||||
{
|
{
|
||||||
do_gui_text(luaX, luaY, luaStr, false, background, forecolor, anchor);
|
DoGuiText(luaX, luaY, luaStr, false, background, forecolor, anchor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,21 @@ namespace BizHawk.MultiClient
|
||||||
private Lua currThread;
|
private Lua currThread;
|
||||||
private FormsLuaLibrary _formsLibrary = new FormsLuaLibrary();
|
private FormsLuaLibrary _formsLibrary = new FormsLuaLibrary();
|
||||||
private EventLuaLibrary _eventLibrary = new EventLuaLibrary();
|
private EventLuaLibrary _eventLibrary = new EventLuaLibrary();
|
||||||
|
private GuiLuaLibrary _guiLibrary = new GuiLuaLibrary();
|
||||||
|
|
||||||
public LuaDocumentation Docs = new LuaDocumentation();
|
public LuaDocumentation Docs = new LuaDocumentation();
|
||||||
public bool IsRunning;
|
public bool IsRunning;
|
||||||
public EventWaitHandle LuaWait;
|
public EventWaitHandle LuaWait;
|
||||||
public bool FrameAdvanceRequested;
|
public bool FrameAdvanceRequested;
|
||||||
|
|
||||||
|
public GuiLuaLibrary GuiLibrary
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _guiLibrary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void WindowClosed(IntPtr handle)
|
public void WindowClosed(IntPtr handle)
|
||||||
{
|
{
|
||||||
_formsLibrary.WindowClosed(handle);
|
_formsLibrary.WindowClosed(handle);
|
||||||
|
@ -60,32 +69,9 @@ namespace BizHawk.MultiClient
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
_lua = new Lua();
|
_lua = new Lua();
|
||||||
foreach (var brush in SolidBrushes.Values) brush.Dispose();
|
_guiLibrary.Dispose();
|
||||||
foreach (var brush in Pens.Values) brush.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Register Library Functions
|
|
||||||
|
|
||||||
public static string[] GuiFunctions = new[]
|
|
||||||
{
|
|
||||||
"addmessage",
|
|
||||||
"alert",
|
|
||||||
"cleartext",
|
|
||||||
"drawBezier",
|
|
||||||
"drawBox",
|
|
||||||
"drawEllipse",
|
|
||||||
"drawIcon",
|
|
||||||
"drawImage",
|
|
||||||
"drawLine",
|
|
||||||
"drawPie",
|
|
||||||
"drawPixel",
|
|
||||||
"drawPolygon",
|
|
||||||
"drawRectangle",
|
|
||||||
"drawString",
|
|
||||||
"drawText",
|
|
||||||
"text",
|
|
||||||
};
|
|
||||||
|
|
||||||
public void LuaRegister(Lua lua)
|
public void LuaRegister(Lua lua)
|
||||||
{
|
{
|
||||||
lua.RegisterFunction("print", this, GetType().GetMethod("print"));
|
lua.RegisterFunction("print", this, GetType().GetMethod("print"));
|
||||||
|
@ -101,6 +87,7 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
_eventLibrary.LuaRegister(lua, Docs);
|
_eventLibrary.LuaRegister(lua, Docs);
|
||||||
_formsLibrary.LuaRegister(lua, Docs);
|
_formsLibrary.LuaRegister(lua, Docs);
|
||||||
|
_guiLibrary.LuaRegister(lua, Docs);
|
||||||
new InputLuaLibrary(_lua).LuaRegister(lua, Docs);
|
new InputLuaLibrary(_lua).LuaRegister(lua, Docs);
|
||||||
new JoypadLuaLibrary(_lua).LuaRegister(lua, Docs);
|
new JoypadLuaLibrary(_lua).LuaRegister(lua, Docs);
|
||||||
new MemoryLuaLibrary().LuaRegister(lua, Docs);
|
new MemoryLuaLibrary().LuaRegister(lua, Docs);
|
||||||
|
@ -110,20 +97,9 @@ namespace BizHawk.MultiClient
|
||||||
new SavestateLuaLibrary().LuaRegister(lua, Docs);
|
new SavestateLuaLibrary().LuaRegister(lua, Docs);
|
||||||
new SNESLuaLibrary().LuaRegister(lua, Docs);
|
new SNESLuaLibrary().LuaRegister(lua, Docs);
|
||||||
|
|
||||||
lua.NewTable("gui");
|
|
||||||
foreach (string t in GuiFunctions)
|
|
||||||
{
|
|
||||||
lua.RegisterFunction("gui." + t, this, GetType().GetMethod("gui_" + t));
|
|
||||||
Docs.Add("gui", t, GetType().GetMethod("gui_" + t));
|
|
||||||
}
|
|
||||||
|
|
||||||
Docs.Sort();
|
Docs.Sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Library Helpers
|
|
||||||
|
|
||||||
public Lua SpawnCoroutine(string File)
|
public Lua SpawnCoroutine(string File)
|
||||||
{
|
{
|
||||||
var t = _lua.NewThread();
|
var t = _lua.NewThread();
|
||||||
|
@ -175,7 +151,5 @@ namespace BizHawk.MultiClient
|
||||||
GlobalWinF.DisplayManager.NeedsToPaint = true;
|
GlobalWinF.DisplayManager.NeedsToPaint = true;
|
||||||
currThread.Yield(0);
|
currThread.Yield(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,7 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
string func = Name + "." + methodName;
|
string func = Name + "." + methodName;
|
||||||
var method = GetType().GetMethod(Name + "_" + methodName);
|
var method = GetType().GetMethod(Name + "_" + methodName);
|
||||||
|
lua.RegisterFunction(func, this, method);
|
||||||
lua.RegisterFunction(
|
|
||||||
Name + "." + methodName,
|
|
||||||
this,
|
|
||||||
GetType().GetMethod(Name + "_" + methodName)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (docs != null)
|
if (docs != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -800,9 +800,9 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
if (luaList != null && luaList.Count > 0)
|
if (luaList != null && luaList.Count > 0)
|
||||||
{
|
{
|
||||||
if (LuaImp.luaSurface == null)
|
if (LuaImp.GuiLibrary.SurfaceIsNull)
|
||||||
{
|
{
|
||||||
LuaImp.gui_drawNewEmu();
|
LuaImp.GuiLibrary.DrawNewEmu();
|
||||||
}
|
}
|
||||||
foreach (var lf in luaList)
|
foreach (var lf in luaList)
|
||||||
{
|
{
|
||||||
|
@ -853,24 +853,21 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
if (luaList != null && luaList.Count > 0)
|
if (luaList != null && luaList.Count > 0)
|
||||||
{
|
{
|
||||||
if (LuaImp.luaSurface == null)
|
if (LuaImp.GuiLibrary.SurfaceIsNull)
|
||||||
LuaImp.gui_drawNewEmu();
|
{
|
||||||
|
LuaImp.GuiLibrary.DrawNewEmu();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EndLuaDrawing()
|
public void EndLuaDrawing()
|
||||||
{
|
{
|
||||||
if (luaList != null && luaList.Count > 0)
|
if (luaList != null && luaList.Any())
|
||||||
{
|
{
|
||||||
LuaImp.gui_drawFinishEmu();
|
LuaImp.GuiLibrary.DrawFinishEmu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsRunning()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool WaitOne(int timeout)
|
public bool WaitOne(int timeout)
|
||||||
{
|
{
|
||||||
if (!IsHandleCreated || IsDisposed)
|
if (!IsHandleCreated || IsDisposed)
|
||||||
|
|
Loading…
Reference in New Issue