Skip to content

Commit b9e7e77

Browse files
committed
(REMOVE) Add example in CorePlugin
1 parent f2179bd commit b9e7e77

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

Dalamud.CorePlugin/PluginImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ public void Dispose()
5656
/// </summary>
5757
/// <param name="pluginInterface">Dalamud plugin interface.</param>
5858
/// <param name="log">Logging service.</param>
59-
public PluginImpl(DalamudPluginInterface pluginInterface, IPluginLog log)
59+
public PluginImpl(DalamudPluginInterface pluginInterface, IDataManager dataManager, ITextureProvider textureProvider, IPluginLog log)
6060
{
6161
try
6262
{
6363
// this.InitLoc();
6464
this.Interface = pluginInterface;
6565
this.pluginLog = log;
6666

67-
this.windowSystem.AddWindow(new PluginWindow());
67+
this.windowSystem.AddWindow(new PluginWindow(pluginInterface.UiBuilder, dataManager, textureProvider));
6868

6969
this.Interface.UiBuilder.Draw += this.OnDraw;
7070
this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi;

Dalamud.CorePlugin/PluginWindow.cs

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
using System;
2-
using System.Numerics;
3-
2+
using System.IO;
3+
using Dalamud.Interface;
4+
using Dalamud.Interface.Internal;
45
using Dalamud.Interface.Windowing;
6+
using Dalamud.Plugin.Services;
57
using ImGuiNET;
8+
using Lumina.Data.Files;
9+
using SharpDX;
10+
using SharpDX.Direct3D11;
11+
using Vector2 = System.Numerics.Vector2;
612

713
namespace Dalamud.CorePlugin
814
{
@@ -11,21 +17,59 @@ namespace Dalamud.CorePlugin
1117
/// </summary>
1218
internal class PluginWindow : Window, IDisposable
1319
{
20+
private readonly UiBuilder uiBuilder;
21+
private readonly ITextureProvider textureProvider;
22+
private readonly IDalamudTextureWrap tex;
23+
private readonly IntPtr callbackId;
24+
private readonly Device device;
25+
private readonly DeviceContext deviceContext;
26+
private readonly PixelShader pixelShader;
27+
private readonly SamplerState fontSampler;
28+
1429
/// <summary>
1530
/// Initializes a new instance of the <see cref="PluginWindow"/> class.
1631
/// </summary>
17-
public PluginWindow()
32+
public PluginWindow(UiBuilder uiBuilder, IDataManager dataManager, ITextureProvider textureProvider)
1833
: base("CorePlugin")
1934
{
35+
this.uiBuilder = uiBuilder;
36+
this.textureProvider = textureProvider;
2037
this.IsOpen = true;
2138

2239
this.Size = new Vector2(810, 520);
2340
this.SizeCondition = ImGuiCond.FirstUseEver;
41+
42+
this.tex = this.textureProvider.GetTexture(dataManager.GetFile<TexFile>("chara/monster/m0361/obj/body/b0001/texture/v01_m0361b0001_n.tex")!);
43+
this.callbackId = this.uiBuilder.AddImGuiDrawCmdUserCallback(this.DrawCmdUserCallback);
44+
this.device = CppObject.FromPointer<Device>(uiBuilder.DeviceNativePointer);
45+
this.deviceContext = CppObject.FromPointer<DeviceContext>(uiBuilder.DeviceContextNativePointer);
46+
this.pixelShader = new PixelShader(this.device, File.ReadAllBytes(@"Z:\test.fxc"));
47+
this.fontSampler = new SamplerState(this.device, new SamplerStateDescription
48+
{
49+
Filter = Filter.MinMagMipLinear,
50+
AddressU = TextureAddressMode.Wrap,
51+
AddressV = TextureAddressMode.Wrap,
52+
AddressW = TextureAddressMode.Wrap,
53+
MipLodBias = 0,
54+
ComparisonFunction = Comparison.Always,
55+
MinimumLod = 0,
56+
MaximumLod = 0,
57+
});
58+
}
59+
60+
private void DrawCmdUserCallback(ImDrawDataPtr drawData, ImDrawCmdPtr drawCmd)
61+
{
62+
this.deviceContext.PixelShader.Set(this.pixelShader);
63+
this.deviceContext.PixelShader.SetSampler(0, this.fontSampler);
2464
}
2565

2666
/// <inheritdoc/>
2767
public void Dispose()
2868
{
69+
this.uiBuilder.RemoveImGuiDrawCmdUserCallback(this.DrawCmdUserCallback);
70+
this.tex.Dispose();
71+
this.pixelShader.Dispose();
72+
this.fontSampler.Dispose();
2973
}
3074

3175
/// <inheritdoc/>
@@ -36,6 +80,15 @@ public override void OnOpen()
3680
/// <inheritdoc/>
3781
public override void Draw()
3882
{
83+
var drawList = ImGui.GetWindowDrawList();
84+
drawList.AddCallback(this.callbackId, nint.Zero);
85+
ImGui.Image(this.tex.ImGuiHandle, new(512, 512), new(1, 0), new(2, 1));
86+
ImGui.SameLine();
87+
ImGui.Image(this.tex.ImGuiHandle, new(512, 512), new(2, 0), new(3, 1));
88+
ImGui.Image(this.tex.ImGuiHandle, new(512, 512), new(3, 0), new(4, 1));
89+
ImGui.SameLine();
90+
ImGui.Image(this.tex.ImGuiHandle, new(512, 512), new(4, 0), new(5, 1));
91+
drawList.AddCallback(this.uiBuilder.ImGuiResetDrawCmdUserCallback, nint.Zero);
3992
}
4093
}
4194
}

0 commit comments

Comments
 (0)