Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | // Copyright (c) FIRST and other WPILib contributors. |
| 2 | // Open Source Software; you can modify and/or share it under the terms of |
| 3 | // the WPILib BSD license file in the root directory of this project. |
| 4 | |
| 5 | #include <memory> |
| 6 | |
| 7 | #include <GLFW/glfw3.h> |
| 8 | #include <fmt/format.h> |
| 9 | #include <imgui.h> |
| 10 | #include <ntcore_cpp.h> |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 11 | #include <wpi/StringExtras.h> |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 12 | #include <wpigui.h> |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 13 | #include <wpigui_openurl.h> |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 14 | |
| 15 | #include "glass/Context.h" |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 16 | #include "glass/MainMenuBar.h" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 17 | #include "glass/Model.h" |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 18 | #include "glass/Storage.h" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 19 | #include "glass/View.h" |
| 20 | #include "glass/networktables/NetworkTables.h" |
| 21 | #include "glass/networktables/NetworkTablesProvider.h" |
| 22 | #include "glass/networktables/NetworkTablesSettings.h" |
| 23 | #include "glass/other/Log.h" |
| 24 | #include "glass/other/Plot.h" |
| 25 | |
| 26 | namespace gui = wpi::gui; |
| 27 | |
| 28 | const char* GetWPILibVersion(); |
| 29 | |
| 30 | namespace glass { |
| 31 | std::string_view GetResource_glass_16_png(); |
| 32 | std::string_view GetResource_glass_32_png(); |
| 33 | std::string_view GetResource_glass_48_png(); |
| 34 | std::string_view GetResource_glass_64_png(); |
| 35 | std::string_view GetResource_glass_128_png(); |
| 36 | std::string_view GetResource_glass_256_png(); |
| 37 | std::string_view GetResource_glass_512_png(); |
| 38 | } // namespace glass |
| 39 | |
| 40 | static std::unique_ptr<glass::PlotProvider> gPlotProvider; |
| 41 | static std::unique_ptr<glass::NetworkTablesProvider> gNtProvider; |
| 42 | |
| 43 | static std::unique_ptr<glass::NetworkTablesModel> gNetworkTablesModel; |
| 44 | static std::unique_ptr<glass::NetworkTablesSettings> gNetworkTablesSettings; |
| 45 | static glass::LogData gNetworkTablesLog; |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 46 | static std::unique_ptr<glass::Window> gNetworkTablesWindow; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 47 | static std::unique_ptr<glass::Window> gNetworkTablesInfoWindow; |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 48 | static std::unique_ptr<glass::Window> gNetworkTablesSettingsWindow; |
| 49 | static std::unique_ptr<glass::Window> gNetworkTablesLogWindow; |
| 50 | |
| 51 | static glass::MainMenuBar gMainMenu; |
| 52 | static bool gAbout = false; |
| 53 | static bool gSetEnterKey = false; |
| 54 | static bool gKeyEdit = false; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 55 | static int* gEnterKey; |
| 56 | static void (*gPrevKeyCallback)(GLFWwindow*, int, int, int, int); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 57 | static bool gNetworkTablesDebugLog = false; |
| 58 | static unsigned int gPrevMode = NT_NET_MODE_NONE; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 59 | |
| 60 | static void RemapEnterKeyCallback(GLFWwindow* window, int key, int scancode, |
| 61 | int action, int mods) { |
| 62 | if (action == GLFW_PRESS || action == GLFW_RELEASE) { |
| 63 | if (gKeyEdit) { |
| 64 | *gEnterKey = key; |
| 65 | gKeyEdit = false; |
| 66 | } else if (*gEnterKey == key) { |
| 67 | key = GLFW_KEY_ENTER; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if (gPrevKeyCallback) { |
| 72 | gPrevKeyCallback(window, key, scancode, action, mods); |
| 73 | } |
| 74 | } |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 75 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 76 | /** |
| 77 | * Generates the proper title bar title based on current instance state and |
| 78 | * event. |
| 79 | */ |
| 80 | static std::string MakeTitle(NT_Inst inst, nt::Event event) { |
| 81 | auto mode = nt::GetNetworkMode(inst); |
| 82 | if (mode & NT_NET_MODE_SERVER) { |
| 83 | auto numClients = nt::GetConnections(inst).size(); |
| 84 | return fmt::format("Glass - {} Client{} Connected", numClients, |
| 85 | (numClients == 1 ? "" : "s")); |
| 86 | } else if (mode & NT_NET_MODE_CLIENT3 || mode & NT_NET_MODE_CLIENT4) { |
| 87 | if (event.Is(NT_EVENT_CONNECTED)) { |
| 88 | return fmt::format("Glass - Connected ({})", |
| 89 | event.GetConnectionInfo()->remote_ip); |
| 90 | } |
| 91 | } |
| 92 | return "Glass - DISCONNECTED"; |
| 93 | } |
| 94 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 95 | static void NtInitialize() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 96 | auto inst = nt::GetDefaultInstance(); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 97 | auto poller = nt::CreateListenerPoller(inst); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 98 | nt::AddPolledListener(poller, inst, NT_EVENT_CONNECTION | NT_EVENT_IMMEDIATE); |
| 99 | nt::AddPolledLogger(poller, 0, 100); |
| 100 | gui::AddEarlyExecute([inst, poller] { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 101 | auto win = gui::GetSystemWindow(); |
| 102 | if (!win) { |
| 103 | return; |
| 104 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 105 | bool updateTitle = false; |
| 106 | nt::Event connectionEvent; |
| 107 | if (nt::GetNetworkMode(inst) != gPrevMode) { |
| 108 | gPrevMode = nt::GetNetworkMode(inst); |
| 109 | updateTitle = true; |
| 110 | } |
| 111 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 112 | for (auto&& event : nt::ReadListenerQueue(poller)) { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 113 | if (event.Is(NT_EVENT_CONNECTION)) { |
| 114 | updateTitle = true; |
| 115 | connectionEvent = event; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 116 | } else if (auto msg = event.GetLogMessage()) { |
| 117 | const char* level = ""; |
| 118 | if (msg->level >= NT_LOG_CRITICAL) { |
| 119 | level = "CRITICAL: "; |
| 120 | } else if (msg->level >= NT_LOG_ERROR) { |
| 121 | level = "ERROR: "; |
| 122 | } else if (msg->level >= NT_LOG_WARNING) { |
| 123 | level = "WARNING: "; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 124 | } else if (msg->level < NT_LOG_INFO && !gNetworkTablesDebugLog) { |
| 125 | continue; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 126 | } |
| 127 | gNetworkTablesLog.Append(fmt::format( |
| 128 | "{}{} ({}:{})\n", level, msg->message, msg->filename, msg->line)); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 131 | |
| 132 | if (updateTitle) { |
| 133 | glfwSetWindowTitle(win, MakeTitle(inst, connectionEvent).c_str()); |
| 134 | } |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 135 | }); |
| 136 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 137 | gNetworkTablesLogWindow = std::make_unique<glass::Window>( |
| 138 | glass::GetStorageRoot().GetChild("NetworkTables Log"), |
| 139 | "NetworkTables Log", glass::Window::kHide); |
| 140 | gNetworkTablesLogWindow->SetView( |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 141 | std::make_unique<glass::LogView>(&gNetworkTablesLog)); |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 142 | gNetworkTablesLogWindow->SetDefaultPos(250, 615); |
| 143 | gNetworkTablesLogWindow->SetDefaultSize(600, 130); |
| 144 | gNetworkTablesLogWindow->DisableRenamePopup(); |
| 145 | gui::AddLateExecute([] { gNetworkTablesLogWindow->Display(); }); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 146 | |
| 147 | // NetworkTables table window |
| 148 | gNetworkTablesModel = std::make_unique<glass::NetworkTablesModel>(); |
| 149 | gui::AddEarlyExecute([] { gNetworkTablesModel->Update(); }); |
| 150 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 151 | gNetworkTablesWindow = std::make_unique<glass::Window>( |
| 152 | glass::GetStorageRoot().GetChild("NetworkTables View"), "NetworkTables"); |
| 153 | gNetworkTablesWindow->SetView( |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 154 | std::make_unique<glass::NetworkTablesView>(gNetworkTablesModel.get())); |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 155 | gNetworkTablesWindow->SetDefaultPos(250, 277); |
| 156 | gNetworkTablesWindow->SetDefaultSize(750, 185); |
| 157 | gNetworkTablesWindow->DisableRenamePopup(); |
| 158 | gui::AddLateExecute([] { gNetworkTablesWindow->Display(); }); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 159 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 160 | // NetworkTables info window |
| 161 | gNetworkTablesInfoWindow = std::make_unique<glass::Window>( |
| 162 | glass::GetStorageRoot().GetChild("NetworkTables Info"), |
| 163 | "NetworkTables Info"); |
| 164 | gNetworkTablesInfoWindow->SetView(glass::MakeFunctionView( |
| 165 | [&] { glass::DisplayNetworkTablesInfo(gNetworkTablesModel.get()); })); |
| 166 | gNetworkTablesInfoWindow->SetDefaultPos(250, 130); |
| 167 | gNetworkTablesInfoWindow->SetDefaultSize(750, 145); |
| 168 | gNetworkTablesInfoWindow->SetDefaultVisibility(glass::Window::kHide); |
| 169 | gNetworkTablesInfoWindow->DisableRenamePopup(); |
| 170 | gui::AddLateExecute([] { gNetworkTablesInfoWindow->Display(); }); |
| 171 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 172 | // NetworkTables settings window |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 173 | gNetworkTablesSettings = std::make_unique<glass::NetworkTablesSettings>( |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 174 | "glass", glass::GetStorageRoot().GetChild("NetworkTables Settings")); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 175 | gui::AddEarlyExecute([] { gNetworkTablesSettings->Update(); }); |
| 176 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 177 | gNetworkTablesSettingsWindow = std::make_unique<glass::Window>( |
| 178 | glass::GetStorageRoot().GetChild("NetworkTables Settings"), |
| 179 | "NetworkTables Settings"); |
| 180 | gNetworkTablesSettingsWindow->SetView( |
| 181 | glass::MakeFunctionView([] { gNetworkTablesSettings->Display(); })); |
| 182 | gNetworkTablesSettingsWindow->SetDefaultPos(30, 30); |
| 183 | gNetworkTablesSettingsWindow->SetFlags(ImGuiWindowFlags_AlwaysAutoResize); |
| 184 | gNetworkTablesSettingsWindow->DisableRenamePopup(); |
| 185 | gui::AddLateExecute([] { gNetworkTablesSettingsWindow->Display(); }); |
| 186 | |
| 187 | gui::AddWindowScaler([](float scale) { |
| 188 | // scale default window positions |
| 189 | gNetworkTablesLogWindow->ScaleDefault(scale); |
| 190 | gNetworkTablesWindow->ScaleDefault(scale); |
| 191 | gNetworkTablesSettingsWindow->ScaleDefault(scale); |
| 192 | }); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | #ifdef _WIN32 |
| 196 | int __stdcall WinMain(void* hInstance, void* hPrevInstance, char* pCmdLine, |
| 197 | int nCmdShow) { |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 198 | int argc = __argc; |
| 199 | char** argv = __argv; |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 200 | #else |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 201 | int main(int argc, char** argv) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 202 | #endif |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 203 | std::string_view saveDir; |
| 204 | if (argc == 2) { |
| 205 | saveDir = argv[1]; |
| 206 | } |
| 207 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 208 | gui::CreateContext(); |
| 209 | glass::CreateContext(); |
| 210 | |
| 211 | gui::AddIcon(glass::GetResource_glass_16_png()); |
| 212 | gui::AddIcon(glass::GetResource_glass_32_png()); |
| 213 | gui::AddIcon(glass::GetResource_glass_48_png()); |
| 214 | gui::AddIcon(glass::GetResource_glass_64_png()); |
| 215 | gui::AddIcon(glass::GetResource_glass_128_png()); |
| 216 | gui::AddIcon(glass::GetResource_glass_256_png()); |
| 217 | gui::AddIcon(glass::GetResource_glass_512_png()); |
| 218 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 219 | gui::AddEarlyExecute( |
| 220 | [] { ImGui::DockSpaceOverViewport(ImGui::GetMainViewport()); }); |
| 221 | |
| 222 | gui::AddInit([] { ImGui::GetIO().ConfigDockingWithShift = true; }); |
| 223 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 224 | gPlotProvider = std::make_unique<glass::PlotProvider>( |
| 225 | glass::GetStorageRoot().GetChild("Plots")); |
| 226 | gNtProvider = std::make_unique<glass::NetworkTablesProvider>( |
| 227 | glass::GetStorageRoot().GetChild("NetworkTables")); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 228 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 229 | glass::SetStorageName("glass"); |
| 230 | glass::SetStorageDir(saveDir.empty() ? gui::GetPlatformSaveFileDir() |
| 231 | : saveDir); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 232 | gPlotProvider->GlobalInit(); |
| 233 | gui::AddInit([] { glass::ResetTime(); }); |
| 234 | gNtProvider->GlobalInit(); |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 235 | NtInitialize(); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 236 | |
| 237 | glass::AddStandardNetworkTablesViews(*gNtProvider); |
| 238 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 239 | gui::AddLateExecute([] { gMainMenu.Display(); }); |
| 240 | |
| 241 | gMainMenu.AddMainMenu([] { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 242 | if (ImGui::BeginMenu("View")) { |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 243 | if (ImGui::MenuItem("Set Enter Key")) { |
| 244 | gSetEnterKey = true; |
| 245 | } |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 246 | if (ImGui::MenuItem("Reset Time")) { |
| 247 | glass::ResetTime(); |
| 248 | } |
| 249 | ImGui::EndMenu(); |
| 250 | } |
| 251 | if (ImGui::BeginMenu("NetworkTables")) { |
| 252 | if (gNetworkTablesSettingsWindow) { |
| 253 | gNetworkTablesSettingsWindow->DisplayMenuItem("NetworkTables Settings"); |
| 254 | } |
| 255 | if (gNetworkTablesWindow) { |
| 256 | gNetworkTablesWindow->DisplayMenuItem("NetworkTables View"); |
| 257 | } |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 258 | if (gNetworkTablesInfoWindow) { |
| 259 | gNetworkTablesInfoWindow->DisplayMenuItem("NetworkTables Info"); |
| 260 | } |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 261 | if (gNetworkTablesLogWindow) { |
| 262 | gNetworkTablesLogWindow->DisplayMenuItem("NetworkTables Log"); |
| 263 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 264 | ImGui::MenuItem("NetworkTables Debug Logging", nullptr, |
| 265 | &gNetworkTablesDebugLog); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 266 | ImGui::Separator(); |
| 267 | gNtProvider->DisplayMenu(); |
| 268 | ImGui::EndMenu(); |
| 269 | } |
| 270 | if (ImGui::BeginMenu("Plot")) { |
| 271 | bool paused = gPlotProvider->IsPaused(); |
| 272 | if (ImGui::MenuItem("Pause All Plots", nullptr, &paused)) { |
| 273 | gPlotProvider->SetPaused(paused); |
| 274 | } |
| 275 | ImGui::Separator(); |
| 276 | gPlotProvider->DisplayMenu(); |
| 277 | ImGui::EndMenu(); |
| 278 | } |
| 279 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 280 | if (ImGui::BeginMenu("Info")) { |
| 281 | if (ImGui::MenuItem("About")) { |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 282 | gAbout = true; |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 283 | } |
| 284 | ImGui::EndMenu(); |
| 285 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 286 | |
| 287 | if (ImGui::BeginMenu("Docs")) { |
| 288 | if (ImGui::MenuItem("Online documentation")) { |
| 289 | wpi::gui::OpenURL( |
| 290 | "https://docs.wpilib.org/en/stable/docs/software/dashboards/" |
| 291 | "glass/"); |
| 292 | } |
| 293 | ImGui::EndMenu(); |
| 294 | } |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 295 | }); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 296 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 297 | gui::AddLateExecute([] { |
| 298 | if (gAbout) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 299 | ImGui::OpenPopup("About"); |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 300 | gAbout = false; |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 301 | } |
| 302 | if (ImGui::BeginPopupModal("About")) { |
| 303 | ImGui::Text("Glass: A different kind of dashboard"); |
| 304 | ImGui::Separator(); |
| 305 | ImGui::Text("v%s", GetWPILibVersion()); |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 306 | ImGui::Separator(); |
| 307 | ImGui::Text("Save location: %s", glass::GetStorageDir().c_str()); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 308 | ImGui::Text("%.3f ms/frame (%.1f FPS)", |
| 309 | 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 310 | if (ImGui::Button("Close")) { |
| 311 | ImGui::CloseCurrentPopup(); |
| 312 | } |
| 313 | ImGui::EndPopup(); |
| 314 | } |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 315 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 316 | if (gSetEnterKey) { |
| 317 | ImGui::OpenPopup("Set Enter Key"); |
| 318 | gSetEnterKey = false; |
| 319 | } |
| 320 | if (ImGui::BeginPopupModal("Set Enter Key")) { |
| 321 | ImGui::Text("Set the key to use to mean 'Enter'"); |
| 322 | ImGui::Text("This is useful to edit values without the DS disabling"); |
| 323 | ImGui::Separator(); |
| 324 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 325 | ImGui::Text("Key:"); |
| 326 | ImGui::SameLine(); |
| 327 | char editLabel[40]; |
| 328 | char nameBuf[32]; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 329 | const char* name = glfwGetKeyName(*gEnterKey, 0); |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 330 | if (!name) { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 331 | wpi::format_to_n_c_str(nameBuf, sizeof(nameBuf), "{}", *gEnterKey); |
| 332 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 333 | name = nameBuf; |
| 334 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 335 | wpi::format_to_n_c_str(editLabel, sizeof(editLabel), "{}###edit", |
| 336 | gKeyEdit ? "(press key)" : name); |
| 337 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 338 | if (ImGui::SmallButton(editLabel)) { |
| 339 | gKeyEdit = true; |
| 340 | } |
| 341 | ImGui::SameLine(); |
| 342 | if (ImGui::SmallButton("Reset")) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 343 | *gEnterKey = GLFW_KEY_ENTER; |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | if (ImGui::Button("Close")) { |
| 347 | ImGui::CloseCurrentPopup(); |
| 348 | gKeyEdit = false; |
| 349 | } |
| 350 | ImGui::EndPopup(); |
| 351 | } |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 352 | }); |
| 353 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 354 | gui::Initialize("Glass - DISCONNECTED", 1024, 768, |
| 355 | ImGuiConfigFlags_DockingEnable); |
| 356 | gEnterKey = &glass::GetStorageRoot().GetInt("enterKey", GLFW_KEY_ENTER); |
| 357 | if (auto win = gui::GetSystemWindow()) { |
| 358 | gPrevKeyCallback = glfwSetKeyCallback(win, RemapEnterKeyCallback); |
| 359 | } |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 360 | gui::Main(); |
| 361 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 362 | gNetworkTablesSettingsWindow.reset(); |
| 363 | gNetworkTablesLogWindow.reset(); |
| 364 | gNetworkTablesWindow.reset(); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 365 | gNetworkTablesModel.reset(); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 366 | gNtProvider.reset(); |
| 367 | gPlotProvider.reset(); |
| 368 | |
| 369 | glass::DestroyContext(); |
| 370 | gui::DestroyContext(); |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 371 | |
| 372 | return 0; |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 373 | } |