Skip to content

Commit 4ed6e65

Browse files
committed
add serial interface, UI theming
1 parent 9de9c6f commit 4ed6e65

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

UI/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
77
// - Introduction, links and more at the top of imgui.cpp
88

9+
// Modified by RobertJN64 to add plot support and split render into its own file
10+
911
#include "imgui.h"
12+
#include "implot.h"
1013
#include "imgui_impl_win32.h"
1114
#include "imgui_impl_dx11.h"
1215
#include <d3d11.h>
@@ -28,7 +31,7 @@ void CleanupRenderTarget();
2831
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
2932

3033
// Forward declaration of render loop (in ui.cpp)
31-
void render_loop(ImGuiIO io);
34+
void render_loop();
3235

3336
// Main code
3437
int main(int, char **) {
@@ -39,7 +42,7 @@ int main(int, char **) {
3942
// Create application window
4043
WNDCLASSEXW wc = {sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"ImGui Example", nullptr};
4144
::RegisterClassExW(&wc);
42-
HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"Dear ImGui DirectX11 Example", WS_OVERLAPPEDWINDOW, 100, 100, (int)(1280 * main_scale), (int)(800 * main_scale), nullptr, nullptr, wc.hInstance, nullptr);
45+
HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"PSP Active Controls DAQ v0.1", WS_OVERLAPPEDWINDOW, 100, 100, (int)(1280 * main_scale), (int)(800 * main_scale), nullptr, nullptr, wc.hInstance, nullptr);
4346

4447
// Initialize Direct3D
4548
if (!CreateDeviceD3D(hwnd)) {
@@ -55,6 +58,7 @@ int main(int, char **) {
5558
// Setup Dear ImGui context
5659
IMGUI_CHECKVERSION();
5760
ImGui::CreateContext();
61+
ImPlot::CreateContext();
5862
ImGuiIO &io = ImGui::GetIO();
5963
(void)io;
6064
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
@@ -69,6 +73,11 @@ int main(int, char **) {
6973
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
7074
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
7175

76+
ImPlotStyle &plotStyle = ImPlot::GetStyle();
77+
plotStyle.PlotBorderSize = 1.0f; // thickness of border
78+
plotStyle.Colors[ImPlotCol_FrameBg] = ImVec4(0.1f, 0.1f, 0.1f, 1.0f); // Plot background
79+
plotStyle.Colors[ImPlotCol_PlotBorder] = ImVec4(205 / 255.0, 159 / 255.0, 38 / 255.0, 1.0f); // Plot border
80+
7281
// Setup Platform/Renderer backends
7382
ImGui_ImplWin32_Init(hwnd);
7483
ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext);
@@ -128,7 +137,7 @@ int main(int, char **) {
128137
ImGui_ImplDX11_NewFrame();
129138
ImGui_ImplWin32_NewFrame();
130139
ImGui::NewFrame();
131-
render_loop(io);
140+
render_loop();
132141

133142
// Rendering
134143
ImGui::Render();
@@ -146,6 +155,7 @@ int main(int, char **) {
146155
// Cleanup
147156
ImGui_ImplDX11_Shutdown();
148157
ImGui_ImplWin32_Shutdown();
158+
ImPlot::DestroyContext();
149159
ImGui::DestroyContext();
150160

151161
CleanupDeviceD3D();

UI/ui.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ void control_panel() {
8787
}
8888
ImGui::EndTable();
8989
}
90+
91+
ImGui::Dummy(ImVec2(0, 100)); // Add vertical spacing
92+
93+
static char inputBuffer[128] = ""; // buffer for text input
94+
ImGui::InputTextWithHint("##serial_input", "enter serial command", inputBuffer, IM_ARRAYSIZE(inputBuffer));
95+
ImGui::SameLine();
96+
if (daq_button("Send", ImVec2(-1, 0), IM_COL32(33, 112, 69, 255))) {
97+
// Do something with inputBuffer
98+
printf("You entered: %s\n", inputBuffer);
99+
inputBuffer[0] = '\0';
100+
}
101+
102+
static char outputBuffer[128] = ">help\nping\npong"; // buffer for text input
103+
ImGui::InputTextMultiline("##serial_output", outputBuffer, IM_ARRAYSIZE(outputBuffer));
90104
}
91105

92106
void plot_panel() {

0 commit comments

Comments
 (0)