desktop code refactoring

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2025-04-10 23:31:16 +02:00
parent b3bf03999b
commit 5b82cd8189
22 changed files with 163 additions and 158 deletions

View File

@@ -1,81 +1,80 @@
#include "debug/DebugOverlay.h"
#include <imgui_impl_sdlrenderer3.h>
#include "Common.h"
#include "Version.h"
#include "imgui.h"
#include "imgui_impl_sdl3.h"
#include <imgui_impl_sdlrenderer3.h>
#include "Common.h"
#include "ui/Matrix.h"
#include "Version.h"
namespace DebugOverlay {
void init(const AppContext *context) {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO &io{ImGui::GetIO()};
void init(const AppContext* context) {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io{ImGui::GetIO()};
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
ImGui::StyleColorsDark();
ImGui::StyleColorsDark();
ImGui_ImplSDL3_InitForSDLRenderer(context->window(), context->renderer());
ImGui_ImplSDLRenderer3_Init(context->renderer());
}
ImGui_ImplSDL3_InitForSDLRenderer(context->window(), context->renderer());
ImGui_ImplSDLRenderer3_Init(context->renderer());
}
void update(AppContext *context, const SDL_Event *event) {
ImGui_ImplSDL3_ProcessEvent(event);
void update(AppContext* context, const SDL_Event* event) {
ImGui_ImplSDL3_ProcessEvent(event);
if (show_led_matrix) {
if (context->matrix_window() == nullptr) {
const auto win = createWindow("LED Matrix", 32 * 50, 8 * 50);
SDL_SetWindowFocusable(win->window(), false);
SDL_SetRenderVSync(win->renderer(), SDL_RENDERER_VSYNC_ADAPTIVE);
SDL_SetWindowPosition(win->window(), 0, 0);
SDL_ShowWindow(win->window());
if(show_led_matrix) {
if(context->matrix_window() == nullptr) {
const auto win = createWindow("LED Matrix", 32 * 50, 8 * 50);
SDL_SetWindowFocusable(win->window(), false);
SDL_SetRenderVSync(win->renderer(), SDL_RENDERER_VSYNC_ADAPTIVE);
SDL_SetWindowPosition(win->window(), 0, 0);
SDL_ShowWindow(win->window());
context->setMatrix(new Matrix(win));
}
} else {
if (context->matrix_window() != nullptr) {
SDL_DestroyWindow(context->matrix_window());
context->setMatrix(nullptr);
}
context->setMatrix(new Matrix(win));
}
}
} else {
if(context->matrix_window() != nullptr) {
SDL_DestroyWindow(context->matrix_window());
void render(const AppContext *context) {
ImGui_ImplSDLRenderer3_NewFrame();
ImGui_ImplSDL3_NewFrame();
ImGui::NewFrame();
if (show_debug_window && ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("Config")) {
ImGui::Checkbox("Show LED Matrix", &show_led_matrix);
ImGui::Checkbox("Show Unhandled Events", &show_unhandled_events);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Help")) {
ImGui::Text("FPS: %.2f", ImGui::GetIO().Framerate);
ImGui::SeparatorText("App Info");
ImGui::Text("Project: %s", MY_PROJECT);
ImGui::Text("Version: %s", MY_VERSION);
ImGui::Text("ImGui Version: %s", ImGui::GetVersion());
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
context->setMatrix(nullptr);
}
// Rendering
ImGui::Render();
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), context->renderer());
}
void cleanup() {
ImGui_ImplSDLRenderer3_Shutdown();
ImGui_ImplSDL3_Shutdown();
ImGui::DestroyContext();
}
}
void render(const AppContext* context) {
ImGui_ImplSDLRenderer3_NewFrame();
ImGui_ImplSDL3_NewFrame();
ImGui::NewFrame();
if(show_debug_window && ImGui::BeginMainMenuBar()) {
if(ImGui::BeginMenu("Config")) {
ImGui::Checkbox("Show LED Matrix", &show_led_matrix);
ImGui::Checkbox("Show Unhandled Events", &show_unhandled_events);
ImGui::EndMenu();
}
if(ImGui::BeginMenu("Help")) {
ImGui::Text("FPS: %.2f", ImGui::GetIO().Framerate);
ImGui::SeparatorText("App Info");
ImGui::Text("Project: %s", MY_PROJECT);
ImGui::Text("Version: %s", MY_VERSION);
ImGui::Text("ImGui Version: %s", ImGui::GetVersion());
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
// Rendering
ImGui::Render();
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), context->renderer());
}
void cleanup() {
ImGui_ImplSDLRenderer3_Shutdown();
ImGui_ImplSDL3_Shutdown();
ImGui::DestroyContext();
}
} // namespace DebugOverlay