DCS EFM ImGui (FmGui)  v1.2
Source only library for using ImGui with the DCS: World EFM API.
Fm.cpp
1 
2 // Some code above...
3 // Include imgui.h
4 #include <imgui.h>
5 
6 // Include implot.h if it is enabled in FmGui.hpp:
7 #if defined FMGUI_ENABLE_IMPLOT
8 #include <implot.h>
9 #endif
10 // Include FmGui.hpp
11 #include "FmGui.hpp"
12 
13 // Some code...
14 
15 // The user's ImGuiRoutine function:
16 static void FmGuiRoutine(void)
17 {
18  /*
19  * Set up your ImGui widgets here. Refer to the ImGui documentation and
20  * examples for creating widgets.
21  */
22  ImGui::ShowDemoWindow();
23  // ImGui::ShowAboutWindow();
24  // ImGui::ShowUserGuide();
25  ImGui::Begin("Hello, world!");
26  ImGui::Text("Here, have some text.");
27  ImGui::End();
28  /*
29  * Use ImPlot extension if it is enabled.
30  */
31 #if defined FMGUI_ENABLE_IMPLOT
32  ImPlot::ShowDemoWindow();
33 #endif
34 }
35 
36 // The user's ImGuiInputRoutine function (optional):
37 static void FmGuiInputRoutine(UINT uMsg, WPARAM wParam, LPARAM lParam)
38 {
39  /*
40  * Handle input. See the links below for Win32 input handling.
41  * https://docs.microsoft.com/en-us/windows/win32/inputdev/keyboard-input
42  * https://docs.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input
43  * https://docs.microsoft.com/en-us/windows/win32/inputdev/using-keyboard-input
44  */
45  if (uMsg == WM_KEYDOWN)
46  {
47  if (wParam == 'W')
48  {
49  std::printf("W key pressed!\n");
50  }
51  }
52 }
53 
54 // Some code...
55 /*
56  * NOTE: This function may not be exported from your DLL if you are using the ED
57  * EFM API template that is bundled with the game's install. You will need to add
58  * an exported declaration to the extern "C" block of the ED_FM_TEMPLATE_API.h header
59  * (or your project's equivalent):
60  *
61  * // The ED_FM_TEMPLATE_API preproccessor definition may have a different name
62  * // It is equivalent to: __declspec(dllexport)
63  * ED_FM_TEMPLATE_API void ed_fm_set_plugin_data_install_path(const char *path);
64  * // For ed_fm_release as well:
65  * ED_FM_TEMPLATE_API void ed_fm_release(void);
66  */
67 void ed_fm_set_plugin_data_install_path(const char *path)
68 {
69  /*
70  * You may wish to use the preprocessor to only enable FmGui when your project
71  * is in DEBUG configuration. This can be done with the #ifdef _DEBUG and
72  * a closing #endif in most projects using MSVC. For a more standard abiding
73  * solution you may use #ifndef NDEBUG and a closing #endif.
74  */
75 // #ifdef _DEBUG
76  /*
77  * Optional configuration. For more information and default values see the
78  * FmGuiConfig struct in FmGui.hpp.
79  */
80  FmGui::Config config;
81  /*
82  * This following line is known to cause crashes on the second mission's
83  * quit:
84  * fmGuiConfig.imGuiIniFileName = std::string(path) + "/bin/imgui.ini";
85  */
86  config.style = FmGui::Style::kCLASSIC; // FmGuiStyle::kDARK
87 
88  // Start the FmGui and associated hook.
89  // You can ommit the config arugment entirely: FmGui::StartupHook() is valid.
90  if (!FmGui::StartupHook(config))
91  {
92  std::fprintf(stderr, "FmGui::StartupHook failed!\n");
93  }
94  else
95  {
96  // Print the addresses of the D3D11 context:
97  std::printf("%s\n", FmGui::AddressDump().c_str());
98  // Set the pointers to your ImGui and ImGui Input routine functions:
99  FmGui::SetRoutinePtr(FmGuiRoutine);
100  FmGui::SetInputRoutinePtr(FmGuiInputRoutine);
101  // Set the widget visibility to ON:
103  }
104  /*
105  * The closing #endif for use if you want FmGui to only be enabled for DEBUG
106  * builds.
107  */
108 // #endif
109 }
110 
111 // Some code...
112 
113 void ed_fm_release(void)
114 {
115  // Finally close the FmGui and associated hook.
116  if (!FmGui::ShutdownHook())
117  {
118  std::fprintf(stderr, "FmGui::ShutdownHook failed...\n");
119  }
120 }
121 
122 // Some code...
123 
124 /*
125  * The following is some additional ideas for using FmGui in your flight model/systems code:
126  * - If you use classes to abstract your code you can make an interface class
127  * that your flight model & systems classes can implement as seen below:
128  *
129  * class IFmGuiable
130  * {
131  * public:
132  * virtual ~IFmGuiable(void) = default;
133  * virtual constexpr const char *VFmGuiWidgetName(void) = 0;
134  * virtual void VFmGuiRoutine(void) = 0;
135  * };
136  *
137  * // Here is an example systems class that implements this interface.
138  * class FuelSystem : public IFmGuiable
139  * {
140  * public:
141  * FuelSystem(void) = default;
142  *
143  * constexpr const char *VFmGuiWidgetName(void) override
144  * {
145  * return "Fuel System";
146  * }
147  *
148  * void VFmGuiRoutine(void) override
149  * {
150  * ImGui::Begin("FuelSystem ImGui Window");
151  * ImGui::Text("Total Volume = %.2f", this->totalVolume);
152  * ImGui::Text("Total Capacity = %.2f", this->totalCapacity);
153  * ImGui::End();
154  * }
155  * private:
156  * double totalVolume = 1000.0;
157  * double totalCapacity = 1000.0;
158  * };
159  *
160  * // Now in your ImGuiRoutine you can perform a call to this virtual function
161  * // your systems class:
162  *
163  * std::unique_ptr<FuelSystem> pFuelSystem = std::make_unique<FuelSystem>();
164  *
165  * static void FmGuiRoutine(void)
166  * {
167  * // Call the Gui routine for this particular object.
168  * if (ImGui::CollapsingHeader(pFuelSystem->VFmGuiWidgetName())
169  * {
170  * pFuelSystem->VFmGuiRoutine();
171  * }
172  * }
173  */
bool StartupHook(const Config &config=Config())
Definition: FmGui.cpp:376
std::string AddressDump(void)
Definition: FmGui.cpp:142
void SetRoutinePtr(RoutinePtr pRoutine)
Definition: FmGui.cpp:127
void SetInputRoutinePtr(InputRoutinePtr pInputRoutine)
Definition: FmGui.cpp:132
bool SetWidgetVisibility(bool bEnabled)
Definition: FmGui.cpp:360
bool ShutdownHook(void)
Definition: FmGui.cpp:595
FmGui configuration data.
Definition: FmGui.hpp:76
Style style
Definition: FmGui.hpp:82