mirror of
https://github.com/pound-emu/pound.git
synced 2025-12-12 10:37:00 +00:00
feat(gui): Extract and modularize GUI system from main.cpp
- Create modular GUI architecture with base Panel class - Implement GUIManager to handle window lifecycle and panel management - Add Window wrapper class for SDL3/OpenGL context management - Create specialized panels: - ConsolePanel: Colored log output with timestamps - CPUPanel: CPU debugging with tabs for registers, memory, and disassembly - PerformancePanel: Real-time FPS and frame time monitoring - Apply modern dark theme with purple accents - Add comprehensive menu bar (File, Emulation, View, Tools, Help) - Update CMakeLists.txt to include new gui/ directory structure - Refactor main.cpp to use the new GUI system - Cutom theme on switch colors
This commit is contained in:
parent
22418185f8
commit
2bb666a088
15 changed files with 1099 additions and 121 deletions
169
core/main.cpp
169
core/main.cpp
|
|
@ -1,68 +1,20 @@
|
|||
// Copyright 2025 Pound Emulator Project. All rights reserved.
|
||||
|
||||
#include <thread>
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_sdl3.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
|
||||
#include "Base/Logging/Backend.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
|
||||
#include "ARM/cpu.h"
|
||||
#include "Base/Config.h"
|
||||
#include "ARM/cpu.h"
|
||||
#include "JIT/jit.h"
|
||||
|
||||
SDL_Window* Window{};
|
||||
SDL_GLContext gl_context{};
|
||||
SDL_Event windowEvent;
|
||||
|
||||
void initSDL3() {
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||
LOG_ERROR(Render, "Error while creating SDL3 Context!");
|
||||
}
|
||||
|
||||
SDL_PropertiesID props = SDL_CreateProperties();
|
||||
SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, "Pound Emulator");
|
||||
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, SDL_WINDOWPOS_CENTERED);
|
||||
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, SDL_WINDOWPOS_CENTERED);
|
||||
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, Config::windowWidth());
|
||||
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, Config::windowHeight());
|
||||
// For a new Vulkan support, don't forget to change 'SDL_WINDOW_OPENGL' by 'SDL_WINDOW_VULKAN'.
|
||||
SDL_SetNumberProperty(props, "flags", SDL_WINDOW_OPENGL);
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_RESIZABLE_BOOLEAN, true);
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, true);
|
||||
Window = SDL_CreateWindowWithProperties(props);
|
||||
SDL_DestroyProperties(props);
|
||||
|
||||
SDL_SetWindowMinimumSize(Window, 640, 480);
|
||||
|
||||
gl_context = SDL_GL_CreateContext(Window);
|
||||
if (!gl_context) {
|
||||
LOG_ERROR(Render, "Failed to create OpenGL context: {}", SDL_GetError());
|
||||
}
|
||||
|
||||
SDL_GL_MakeCurrent(Window, gl_context);
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
|
||||
ImGui::CreateContext();
|
||||
ImGui::StyleColorsDark();
|
||||
ImGui_ImplSDL3_InitForOpenGL(Window, gl_context);
|
||||
ImGui_ImplOpenGL3_Init("#version 330");
|
||||
|
||||
}
|
||||
|
||||
void deinitializeSDL3() {
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
SDL_DestroyWindow(Window);
|
||||
SDL_Quit();
|
||||
}
|
||||
#include "gui/GUIManager.h"
|
||||
#include "gui/panels/ConsolePanel.h"
|
||||
#include "gui/panels/CPUPanel.h"
|
||||
#include "gui/panels/PerformancePanel.h"
|
||||
|
||||
// CPU test function
|
||||
void cpuTest() {
|
||||
CPU cpu;
|
||||
cpu.pc = 0;
|
||||
|
|
@ -90,73 +42,48 @@ int main() {
|
|||
const auto config_dir = Base::FS::GetUserPath(Base::FS::PathType::BinaryDir);
|
||||
Config::Load(config_dir / "config.toml");
|
||||
|
||||
initSDL3();
|
||||
|
||||
bool rendering = true;
|
||||
bool show_popup = false; // Flag to control popup visibility
|
||||
|
||||
while (rendering) {
|
||||
// Process events.
|
||||
while (SDL_PollEvent(&windowEvent)) {
|
||||
ImGui_ImplSDL3_ProcessEvent(&windowEvent);
|
||||
|
||||
switch (windowEvent.type) {
|
||||
case SDL_EVENT_QUIT:
|
||||
rendering = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(50.0f, 50.0f), ImVec2(FLT_MAX, FLT_MAX));
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::Begin("Pound Emulator");
|
||||
|
||||
if (ImGui::Button("Run CPU Test")) {
|
||||
cpuTest();
|
||||
show_popup = true; // Trigger the popup after running the test
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
|
||||
// Popup logic
|
||||
if (show_popup) {
|
||||
ImGui::OpenPopup("CPU Test Info");
|
||||
}
|
||||
|
||||
// Define the modal popup
|
||||
if (ImGui::BeginPopupModal("CPU Test Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::Text("The CPU test has ran in the terminal.\nKeep in mind that Pound is still in pre-alpha state.");
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::Button("OK", ImVec2(120, 0))) {
|
||||
show_popup = false; // Close the popup
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::Render();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||
|
||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
SDL_GL_SwapWindow(Window);
|
||||
// Create GUI manager
|
||||
auto gui_manager = std::make_unique<Pound::GUI::GUIManager>();
|
||||
|
||||
// Initialize GUI
|
||||
if (!gui_manager->Initialize("Pound Emulator", Config::windowWidth(), Config::windowHeight())) {
|
||||
LOG_ERROR(Render, "Failed to initialize GUI");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create and add panels
|
||||
auto console_panel = std::make_shared<Pound::GUI::ConsolePanel>();
|
||||
auto cpu_panel = std::make_shared<Pound::GUI::CPUPanel>();
|
||||
auto performance_panel = std::make_shared<Pound::GUI::PerformancePanel>();
|
||||
|
||||
gui_manager->AddPanel(console_panel);
|
||||
gui_manager->AddPanel(cpu_panel);
|
||||
gui_manager->AddPanel(performance_panel);
|
||||
|
||||
// Set up callbacks
|
||||
auto cpu_test_callback = [console_panel]() {
|
||||
console_panel->AddLog("[INFO] Running CPU test...");
|
||||
cpuTest();
|
||||
console_panel->AddLog("[INFO] CPU test completed. Check terminal for details.");
|
||||
};
|
||||
|
||||
gui_manager->SetCPUTestCallback(cpu_test_callback);
|
||||
cpu_panel->SetCPUTestCallback(cpu_test_callback);
|
||||
|
||||
// Add initial console message
|
||||
console_panel->AddLog("[INFO] Pound Emulator started");
|
||||
console_panel->AddLog("[INFO] Version: Pre-Alpha");
|
||||
|
||||
// Main loop
|
||||
while (gui_manager->IsRunning()) {
|
||||
gui_manager->RunFrame();
|
||||
|
||||
// Small delay to prevent excessive CPU usage
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
}
|
||||
|
||||
deinitializeSDL3();
|
||||
// Cleanup
|
||||
gui_manager->Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue