-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNMF_ImGui.h
188 lines (156 loc) · 4.76 KB
/
NMF_ImGui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#pragma once
#ifndef NMF_VERSION
#include "NMF.h"
#endif
#ifdef NMF_USE_IMGUI
#include <functional>
#include <map>
#include <mutex>
#include <stdint.h>
#include <string>
// TODO: imconfig.h ?
#include "lib/imgui/imgui.h"
#if defined(NMF_IMGUI_DX9)
struct IDirect3D9;
struct IDirect3DDevice9;
#elif defined(NMF_IMGUI_DX10)
#error "Not implemented yet!"
#elif defined(NMF_IMGUI_DX11)
struct ID3D11Device;
struct ID3D11DeviceContext;
#elif defined(NMF_IMGUI_DX12)
#error "Not implemented yet!"
#else
#error "Invalid DX version!"
#endif
namespace NMF
{
enum class ImGuiDrawTarget : uint8_t
{
MainMenu,
General
};
struct ImGuiConsoleEntry
{
ImVec4 Color;
std::string Message;
};
using ConsoleSendFunction = std::function<void(const char*)>;
struct ImGuiConsole
{
ImGuiConsole()
: Id(nullptr)
, Name(nullptr)
, TextInput("")
, LastEntryCount(0)
, HistoryIndex(-1)
, IsShown(false)
, SendFunction()
, Entries()
, History()
, EntriesLock()
{
}
const char* Id;
const char* Name;
char TextInput[512];
size_t LastEntryCount;
int HistoryIndex;
bool IsShown;
ConsoleSendFunction SendFunction;
std::vector<ImGuiConsoleEntry> Entries;
std::vector<std::string> History;
std::mutex EntriesLock;
};
class NMF_EXPORT ImGuiManager final
{
public:
static void Setup(HINSTANCE hinstance, int nShowCmd);
static void Teardown();
static void Render();
static WndProcHandleResult WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static void ShowMenu(bool isShown);
static bool IsMenuShown();
static void EndScene();
static bool AddConsole(const char* id, const char* name, ConsoleSendFunction sendFunction);
static bool RemoveConsole(const char* id);
static bool AddMessage(const char* id, const std::string& message);
static bool AddMessage(const char* id, const std::string& message, const ImVec4& color);
#ifdef NMF_EXTERN_SET_GAME_FOCUS
static void SetCatchControl(bool isCatching);
static bool IsCatchingControl();
#endif
#if defined(NMF_IMGUI_DX9)
static void SetupD3D(HWND gameHWND, IDirect3D9* instance, IDirect3DDevice9* device);
#elif defined(NMF_IMGUI_DX10)
#error "Not implemented yet!"
#elif defined(NMF_IMGUI_DX11)
static void SetupD3D(HWND gameHWND, ID3D11Device* device, ID3D11DeviceContext* context);
#elif defined(NMF_IMGUI_DX12)
#error "Not implemented yet!"
#else
#error "Invalid DX version!"
#endif
private:
static void RecreateContext();
static void RenderConsole(ImGuiDrawTarget target, ImGuiConsole* console);
static void HandleCommand(ImGuiConsole* console);
static bool IsMenuOpen;
static HWND GameHWND;
static HINSTANCE GameHINSTANCE;
static int GamenShowCmd;
#ifdef NMF_EXTERN_SET_GAME_FOCUS
static bool IsControlCaught;
#endif
#pragma warning(disable: 4251)
static std::map<std::string, ImGuiConsole*> Consoles;
#pragma warning(default: 4251)
#ifdef NMF_IMGUI_POP_OUT
static LRESULT WINAPI ExternalWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static bool RegisterExternalWindow();
static bool CreateExternalWindow();
static bool ShowExternalWindow();
static bool HideExternalWindow();
static bool CreateExternalDevice();
static bool IsExternalWindow;
static HWND ExternalHWND;
static constexpr const TCHAR* ExternalWindowClassName = TEXT("NMF_class");
static constexpr const TCHAR* ExternalWindowName = TEXT("NMF");
#endif
#ifdef NMF_USE_LOGGING
static Logger Logger;
#endif
#ifdef NMF_IMGUI_DEMO
static bool IsImGUIDemoOpen;
#endif
#if defined(NMF_IMGUI_DX9)
static IDirect3DDevice9* GameDevice;
static IDirect3D9* GameInstance;
#ifdef NMF_IMGUI_POP_OUT
static IDirect3DDevice9* ExternalDevice;
#endif
#ifdef NMF_IMGUI_DX9_HOOK_VIRTUAL
static Hook* DeviceEndSceneHook;
static Hook* DeviceResetHook;
static HRESULT __stdcall DX9EndScene(void* device);
static HRESULT __stdcall DX9Reset(void* device, void* pParam);
#endif
#elif defined(NMF_IMGUI_DX11)
static ID3D11Device* GameDevice;
static ID3D11DeviceContext* GameDeviceContext;
#ifdef NMF_IMGUI_POP_OUT
static ID3D11Device* ExternalDevice;
#endif
#else
static void* ExternalDevice;
#endif
};
#ifdef NMF_USE_CONSOLE
#ifdef NMF_USE_EXT_LUA_CONSOLE
// wire the ext lua into the console
#else
// wire extern functions into the console
#endif
#endif
}
#endif