-
Notifications
You must be signed in to change notification settings - Fork 4
/
Fm.cpp
151 lines (139 loc) · 4.01 KB
/
Fm.cpp
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
// Some code above...
// Include FmGui.hpp
#include "FmGui.hpp"
// Include imgui.h
#include <imgui.h>
// Include implot.h if it is enabled in FmGui.hpp
#if defined FMGUI_ENABLE_IMPLOT
#include <implot.h>
#endif
// Some code...
// The user's ImGuiRoutine function:
static void
FmGuiRoutine(void)
{
/*
* Set up your ImGui widgets here. Refer to the ImGui documentation and
* examples for creating widgets.
*/
ImGui::ShowDemoWindow();
// ImGui::ShowAboutWindow();
// ImGui::ShowUserGuide();
ImGui::Begin("Hello, world!");
ImGui::Text("Here, have some text.");
ImGui::End();
/*
* Use ImPlot extension if it is enabled.
*/
#if defined FMGUI_ENABLE_IMPLOT
ImPlot::ShowDemoWindow();
#endif
}
// The user's ImGuiInputRoutine function:
static void
FmGuiInputRoutine(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
/*
* Handle input. See the links below for Win32 input handling.
* https://docs.microsoft.com/en-us/windows/win32/inputdev/keyboard-input
* https://docs.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input
* https://docs.microsoft.com/en-us/windows/win32/inputdev/using-keyboard-input
*/
if (uMsg == WM_KEYDOWN) {
if (wParam == 'W') {
std::printf("W key pressed!\n");
}
}
}
// Some code...
void
ed_fm_set_plugin_data_install_path(const char *path)
{
/*
* You may wish to use the preprocessor to only enable FmGui when your project
* is in DEBUG configuration. This can be done with the #ifdef _DEBUG and
* a closing #endif in most projects using MSVC. For a more standard abiding
* solution you may use #ifndef NDEBUG and a closing #endif.
*/
// #ifdef _DEBUG
/*
* Optional configuration. For more information and default values see the
* FmGuiConfig struct in FmGui.hpp.
*/
FmGuiConfig fmGuiConfig;
/*
* This following line is known to cause crashes on the second mission's
* quit:
* fmGuiConfig.imGuiIniFileName = std::string(path) + "/bin/imgui.ini";
*/
fmGuiConfig.imGuiStyle = FmGuiStyle::CLASSIC; // FmGuiStyle::DARK
// Start the FmGui and associated hook.
// You can ommit the fmGuiConfig arugment entirely: FmGui::StartupHook() is valid.
if (!FmGui::StartupHook(fmGuiConfig)) {
std::fprintf(stderr, "FmGui::StartupHook failed!\n");
}
else {
// Print the addresses of the D3D11 context.
std::printf("%s\n", FmGui::AddressDump().c_str());
// Set the pointers to your ImGui and ImGui Input routine functions.
FmGui::SetImGuiRoutinePtr(FmGuiRoutine);
FmGui::SetImGuiInputRoutinePtr(FmGuiInputRoutine);
// Set the widget visibility to ON.
FmGui::SetWidgetVisibility(true);
}
/*
* The closing #endif for use if you want FmGui to only be enabled for DEBUG
* builds.
*/
// #endif
}
// Some code...
void
ed_fm_release(void)
{
// Finally close the FmGui and associated hook.
if (!FmGui::ShutdownHook()) {
std::fprintf(stderr, "FmGui::ShutdownHook failed...\n");
}
}
// Some code...
/*
* The following is some additional ideas for using FmGui in your systems code:
* - If you use classes to abstract your code you can make an interface class
* that your systems can inherit as seen below:
*
* class IFmGuiable
* {
* public:
* virtual void VFmGui(void) = 0;
* };
*
* // Here is an example systems class that inherits from this interface.
* class FuelSystem : public IFmGuiable
* {
* public:
* FuelSystem(void) = default;
*
* void VFmGui(void) override
* {
* ImGui::Begin("FuelSystem ImGui Window");
* ImGui::Text("Total Volume = %.2f", this->totalVolume);
* ImGui::Text("Total Capacity = %.2f", this->totalCapacity);
* ImGui::End();
* }
* private:
* double totalVolume = 1000.0;
* double totalCapacity = 1000.0;
* };
*
* // Now in your ImGuiRoutine you can perform a call to this virtual function
* // your systems class:
*
* std::unique_ptr<FuelSystem> pFuelSystem = std::make_unique<FuelSystem>();
*
* static void FmGuiRoutine(void)
* {
* // Call the Gui routine for this particular object.
* pFuelSystem->VFmGui();
* }
*/