Skip to content

Commit

Permalink
(REMOVE) Add example in CorePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Soreepeong committed Nov 11, 2023
1 parent 1ca89e4 commit c0837cb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Dalamud.CorePlugin/PluginImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public void Dispose()
/// </summary>
/// <param name="pluginInterface">Dalamud plugin interface.</param>
/// <param name="log">Logging service.</param>
public PluginImpl(DalamudPluginInterface pluginInterface, IPluginLog log)
public PluginImpl(DalamudPluginInterface pluginInterface, IDataManager dataManager, ITextureProvider textureProvider, IPluginLog log)
{
try
{
// this.InitLoc();
this.Interface = pluginInterface;
this.pluginLog = log;

this.windowSystem.AddWindow(new PluginWindow());
this.windowSystem.AddWindow(new PluginWindow(pluginInterface.UiBuilder, dataManager, textureProvider));

this.Interface.UiBuilder.Draw += this.OnDraw;
this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi;
Expand Down
59 changes: 56 additions & 3 deletions Dalamud.CorePlugin/PluginWindow.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
using System;
using System.Numerics;

using System.IO;
using Dalamud.Interface;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services;
using ImGuiNET;
using Lumina.Data.Files;
using SharpDX;
using SharpDX.Direct3D11;
using Vector2 = System.Numerics.Vector2;

namespace Dalamud.CorePlugin
{
Expand All @@ -11,21 +17,59 @@ namespace Dalamud.CorePlugin
/// </summary>
internal class PluginWindow : Window, IDisposable
{
private readonly UiBuilder uiBuilder;
private readonly ITextureProvider textureProvider;
private readonly IDalamudTextureWrap tex;
private readonly IntPtr callbackId;
private readonly Device device;
private readonly DeviceContext deviceContext;
private readonly PixelShader pixelShader;
private readonly SamplerState fontSampler;

/// <summary>
/// Initializes a new instance of the <see cref="PluginWindow"/> class.
/// </summary>
public PluginWindow()
public PluginWindow(UiBuilder uiBuilder, IDataManager dataManager, ITextureProvider textureProvider)
: base("CorePlugin")
{
this.uiBuilder = uiBuilder;
this.textureProvider = textureProvider;
this.IsOpen = true;

this.Size = new Vector2(810, 520);
this.SizeCondition = ImGuiCond.FirstUseEver;

this.tex = this.textureProvider.GetTexture(dataManager.GetFile<TexFile>("chara/monster/m0361/obj/body/b0001/texture/v01_m0361b0001_n.tex")!);
this.callbackId = this.uiBuilder.AddImGuiDrawCmdUserCallback(this.DrawCmdUserCallback);
this.device = CppObject.FromPointer<Device>(uiBuilder.DeviceNativePointer);
this.deviceContext = CppObject.FromPointer<DeviceContext>(uiBuilder.DeviceContextNativePointer);
this.pixelShader = new PixelShader(this.device, File.ReadAllBytes(@"Z:\test.fxc"));
this.fontSampler = new SamplerState(this.device, new SamplerStateDescription
{
Filter = Filter.MinMagMipLinear,
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
MipLodBias = 0,
ComparisonFunction = Comparison.Always,
MinimumLod = 0,
MaximumLod = 0,
});
}

private void DrawCmdUserCallback(ImDrawDataPtr drawData, ImDrawCmdPtr drawCmd)
{
this.deviceContext.PixelShader.Set(this.pixelShader);
this.deviceContext.PixelShader.SetSampler(0, this.fontSampler);
}

/// <inheritdoc/>
public void Dispose()
{
this.uiBuilder.RemoveImGuiDrawCmdUserCallback(this.DrawCmdUserCallback);
this.tex.Dispose();
this.pixelShader.Dispose();
this.fontSampler.Dispose();
}

/// <inheritdoc/>
Expand All @@ -36,6 +80,15 @@ public override void OnOpen()
/// <inheritdoc/>
public override void Draw()
{
var drawList = ImGui.GetWindowDrawList();
drawList.AddCallback(this.callbackId, nint.Zero);
ImGui.Image(this.tex.ImGuiHandle, new(512, 512), new(1, 0), new(2, 1));
ImGui.SameLine();
ImGui.Image(this.tex.ImGuiHandle, new(512, 512), new(2, 0), new(3, 1));
ImGui.Image(this.tex.ImGuiHandle, new(512, 512), new(3, 0), new(4, 1));
ImGui.SameLine();
ImGui.Image(this.tex.ImGuiHandle, new(512, 512), new(4, 0), new(5, 1));
drawList.AddCallback(this.uiBuilder.ImGuiResetDrawCmdUserCallback, nint.Zero);
}
}
}

0 comments on commit c0837cb

Please sign in to comment.