1
1
using System ;
2
- using System . Numerics ;
3
-
2
+ using System . IO ;
3
+ using Dalamud . Interface ;
4
+ using Dalamud . Interface . Internal ;
4
5
using Dalamud . Interface . Windowing ;
6
+ using Dalamud . Plugin . Services ;
5
7
using ImGuiNET ;
8
+ using Lumina . Data . Files ;
9
+ using SharpDX ;
10
+ using SharpDX . Direct3D11 ;
11
+ using Vector2 = System . Numerics . Vector2 ;
6
12
7
13
namespace Dalamud . CorePlugin
8
14
{
@@ -11,21 +17,59 @@ namespace Dalamud.CorePlugin
11
17
/// </summary>
12
18
internal class PluginWindow : Window , IDisposable
13
19
{
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
+
14
29
/// <summary>
15
30
/// Initializes a new instance of the <see cref="PluginWindow"/> class.
16
31
/// </summary>
17
- public PluginWindow ( )
32
+ public PluginWindow ( UiBuilder uiBuilder , IDataManager dataManager , ITextureProvider textureProvider )
18
33
: base ( "CorePlugin" )
19
34
{
35
+ this . uiBuilder = uiBuilder ;
36
+ this . textureProvider = textureProvider ;
20
37
this . IsOpen = true ;
21
38
22
39
this . Size = new Vector2 ( 810 , 520 ) ;
23
40
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 ) ;
24
64
}
25
65
26
66
/// <inheritdoc/>
27
67
public void Dispose ( )
28
68
{
69
+ this . uiBuilder . RemoveImGuiDrawCmdUserCallback ( this . DrawCmdUserCallback ) ;
70
+ this . tex . Dispose ( ) ;
71
+ this . pixelShader . Dispose ( ) ;
72
+ this . fontSampler . Dispose ( ) ;
29
73
}
30
74
31
75
/// <inheritdoc/>
@@ -36,6 +80,15 @@ public override void OnOpen()
36
80
/// <inheritdoc/>
37
81
public override void Draw ( )
38
82
{
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 ) ;
39
92
}
40
93
}
41
94
}
0 commit comments