Simplify draw delegate handling

This commit is contained in:
meli 2020-01-12 08:16:12 -08:00
parent 07c5fe013c
commit 92b7482e87
2 changed files with 17 additions and 13 deletions

View file

@ -85,7 +85,7 @@ namespace Dalamud {
this.WinSock2 = new WinSockHandlers(); this.WinSock2 = new WinSockHandlers();
this.InterfaceManager = new InterfaceManager(this.sigScanner); this.InterfaceManager = new InterfaceManager(this.sigScanner);
this.InterfaceManager.ReadyToDraw += (sender, args) => this.InterfaceManager.OnBuildUi += BuildDalamudUi; this.InterfaceManager.OnDraw += BuildDalamudUi;
this.InterfaceManager.Enable(); this.InterfaceManager.Enable();
try { try {

View file

@ -37,13 +37,7 @@ namespace Dalamud.Interface
/// <summary> /// <summary>
/// This event gets called when ImGUI is ready to draw your UI. /// This event gets called when ImGUI is ready to draw your UI.
/// </summary> /// </summary>
public event RawDX11Scene.BuildUIDelegate OnBuildUi public event RawDX11Scene.BuildUIDelegate OnDraw;
{
add => this.scene.OnBuildUI += value;
remove => this.scene.OnBuildUI -= value;
}
public EventHandler ReadyToDraw;
public InterfaceManager(SigScanner scanner) public InterfaceManager(SigScanner scanner)
{ {
@ -83,8 +77,7 @@ namespace Dalamud.Interface
if (this.scene == null) if (this.scene == null)
{ {
this.scene = new RawDX11Scene(swapChain); this.scene = new RawDX11Scene(swapChain);
this.scene.OnBuildUI += HandleMouseUI; this.scene.OnBuildUI += Display;
this.ReadyToDraw?.Invoke(this, null);
} }
this.scene.Render(); this.scene.Render();
@ -92,14 +85,25 @@ namespace Dalamud.Interface
return this.presentHook.Original(swapChain, syncInterval, presentFlags); return this.presentHook.Original(swapChain, syncInterval, presentFlags);
} }
private void HandleMouseUI() private void Display()
{ {
// this is more or less part of what reshade/etc do to avoid having to manually // this is more or less part of what reshade/etc do to avoid having to manually
// set the cursor inside the ui // set the cursor inside the ui
// This effectively means that when the ui is hovered, there will be 2 cursors - // This will just tell ImGui to draw its own software cursor instead of using the hardware cursor
// the normal one from the game, and the one for ImGui // The scene internally will handle hiding and showing the hardware (game) cursor
// If the player has the game software cursor enabled, we can't really do anything about that and
// they will see both cursors.
// Doing this here because it's somewhat application-specific behavior // Doing this here because it's somewhat application-specific behavior
ImGui.GetIO().MouseDrawCursor = ImGui.GetIO().WantCaptureMouse; ImGui.GetIO().MouseDrawCursor = ImGui.GetIO().WantCaptureMouse;
// invoke all our external ui handlers, giving each a custom id to prevent name collisions
// because ImGui control names are globally shared
foreach (var del in this.OnDraw?.GetInvocationList())
{
//ImGui.PushID(someId);
del.DynamicInvoke();
//ImGui.PopID();
}
} }
} }
} }