mirror of
https://github.com/emu-russia/pureikyubu.git
synced 2024-06-01 19:17:33 -04:00
uisdl.cpp wip
This commit is contained in:
parent
b8ad5d6a0e
commit
64e9d315c7
161
src/uisdl.cpp
161
src/uisdl.cpp
|
@ -1,11 +1,15 @@
|
|||
// Portable UI based on SDL+imgui
|
||||
#include "pch.h"
|
||||
#ifdef _WINDOWS
|
||||
#include <SDL_syswm.h>
|
||||
#endif
|
||||
|
||||
static bool ui_active = false;
|
||||
static bool show_demo_window = true;
|
||||
static SDL_Window* window;
|
||||
static SDL_Renderer* renderer;
|
||||
static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||
static bool debugger_enabled_check = false;
|
||||
|
||||
static Json::Value* CmdUIError(std::vector<std::string>& args)
|
||||
{
|
||||
|
@ -49,10 +53,20 @@ static Json::Value* CmdGetRenderTarget(std::vector<std::string>& args)
|
|||
{
|
||||
// Return main window as RenderTarget
|
||||
|
||||
// For the first time, this is a hack to check
|
||||
#ifdef _WINDOWS
|
||||
SDL_SysWMinfo wmInfo;
|
||||
SDL_VERSION(&wmInfo.version);
|
||||
SDL_GetWindowWMInfo(window, &wmInfo);
|
||||
HWND hwnd = wmInfo.info.win.window;
|
||||
|
||||
Json::Value* value = new Json::Value();
|
||||
value->type = Json::ValueType::Int;
|
||||
value->value.AsInt = (uint64_t)hwnd;
|
||||
return value;
|
||||
#endif
|
||||
|
||||
// TODO
|
||||
//Json::Value* value = new Json::Value();
|
||||
//value->type = Json::ValueType::Int;
|
||||
//value->value.AsInt = (uint64_t)wnd.hMainWindow;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -64,10 +78,140 @@ static void UIReflector()
|
|||
JdiAddCmd("GetRenderTarget", CmdGetRenderTarget);
|
||||
}
|
||||
|
||||
// emulation stop in progress
|
||||
void OnMainWindowClosed()
|
||||
{
|
||||
//if (UI::g_perfMetrics != nullptr) {
|
||||
// delete UI::g_perfMetrics;
|
||||
// UI::g_perfMetrics = nullptr;
|
||||
//}
|
||||
|
||||
// set to Idle
|
||||
auto win_name = fmt::format("{:s} - {:s} ({:s})", APPNAME_A, Util::WstringToString(APPDESC), UI::Jdi->GetVersion());
|
||||
SDL_SetWindowTitle(window, win_name.c_str());
|
||||
}
|
||||
|
||||
static void ui_main_window()
|
||||
{
|
||||
static bool use_work_area = true;
|
||||
static ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar;
|
||||
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(use_work_area ? viewport->WorkPos : viewport->Pos);
|
||||
ImGui::SetNextWindowSize(use_work_area ? viewport->WorkSize : viewport->Size);
|
||||
|
||||
if (ImGui::Begin("main_window", nullptr, flags))
|
||||
{
|
||||
// Menu Bar
|
||||
if (ImGui::BeginMenuBar())
|
||||
{
|
||||
if (ImGui::BeginMenu("File"))
|
||||
{
|
||||
ImGui::MenuItem("Open", NULL);
|
||||
ImGui::MenuItem("Reopen", NULL);
|
||||
if (ImGui::MenuItem("Close", NULL)) { // Unload file (STOP)
|
||||
UI::Jdi->Stop();
|
||||
Thread::Sleep(100);
|
||||
UI::Jdi->Unload();
|
||||
OnMainWindowClosed();
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Run Bootrom", NULL)) { // Load bootrom
|
||||
UI::Jdi->LoadFile("Bootrom");
|
||||
//OnMainWindowOpened(L"Bootrom");
|
||||
if (Debug::debugger == nullptr)
|
||||
{
|
||||
UI::Jdi->Run();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug::debugger->SetDisasmCursor(0xfff0'0100);
|
||||
UI::Jdi->ExecuteCommand("echo \"Bootrom is started in Suspended state for debugging purposes. Press F5 to continue.\"");
|
||||
}
|
||||
}
|
||||
if (ImGui::BeginMenu("Swap Disk"))
|
||||
{
|
||||
ImGui::MenuItem("Open Cover", NULL);
|
||||
ImGui::MenuItem("Change DVD...", NULL);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::Separator();
|
||||
ImGui::MenuItem("Refresh View", NULL);
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Exit", NULL)) {
|
||||
ui_active = false;
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("Debug"))
|
||||
{
|
||||
if (ImGui::MenuItem("Debug Console", NULL, debugger_enabled_check)) { // Open/close system-wide debugger
|
||||
if (Debug::debugger == nullptr)
|
||||
{ // open
|
||||
debugger_enabled_check = true;
|
||||
Debug::debugger = new Debug::Debugger();
|
||||
UI::Jdi->SetConfigBool(USER_DOLDEBUG, true, USER_UI);
|
||||
//SetStatusText(STATUS_ENUM::Progress, L"Debugger opened");
|
||||
}
|
||||
else
|
||||
{ // close
|
||||
debugger_enabled_check = false;
|
||||
delete Debug::debugger;
|
||||
Debug::debugger = nullptr;
|
||||
UI::Jdi->SetConfigBool(USER_DOLDEBUG, false, USER_UI);
|
||||
//SetStatusText(STATUS_ENUM::Progress, L"Debugger closed");
|
||||
}
|
||||
}
|
||||
ImGui::MenuItem("Mount DolphinSDK as DVD...", NULL);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("Options"))
|
||||
{
|
||||
ImGui::MenuItem("Settings...", NULL);
|
||||
ImGui::MenuItem("View", NULL);
|
||||
ImGui::Separator();
|
||||
if (ImGui::BeginMenu("Controllers"))
|
||||
{
|
||||
ImGui::MenuItem("Port 1", NULL);
|
||||
ImGui::MenuItem("Port 2", NULL);
|
||||
ImGui::MenuItem("Port 3", NULL);
|
||||
ImGui::MenuItem("Port 4", NULL);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("Memcards"))
|
||||
{
|
||||
ImGui::MenuItem("Slot A", NULL);
|
||||
ImGui::MenuItem("Slot B", NULL);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("Help"))
|
||||
{
|
||||
ImGui::MenuItem("About...", NULL);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
static int ui_main()
|
||||
{
|
||||
EMUCtor();
|
||||
|
||||
// debugger enabled ?
|
||||
debugger_enabled_check = UI::Jdi->GetConfigBool(USER_DOLDEBUG, USER_UI);
|
||||
if (debugger_enabled_check)
|
||||
{
|
||||
Debug::debugger = new Debug::Debugger();
|
||||
}
|
||||
|
||||
// Create an interface for communicating with the emulator core
|
||||
UI::Jdi = new UI::JdiClient;
|
||||
|
||||
|
@ -84,13 +228,16 @@ static int ui_main()
|
|||
|
||||
// Create window with SDL_Renderer graphics context
|
||||
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
window = SDL_CreateWindow(APPNAME_A, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
|
||||
window = SDL_CreateWindow(APPNAME_A, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, window_flags);
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_SOFTWARE);
|
||||
if (renderer == nullptr) {
|
||||
SDL_Log("Error creating SDL_Renderer!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// simulate close operation, like we just stopped emu
|
||||
OnMainWindowClosed();
|
||||
|
||||
// Setup Dear ImGui context
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
|
@ -99,8 +246,8 @@ static int ui_main()
|
|||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsClassic();
|
||||
//ImGui::StyleColorsDark();
|
||||
//ImGui::StyleColorsClassic();
|
||||
ImGui::StyleColorsDark();
|
||||
//ImGui::StyleColorsLight();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
|
@ -129,7 +276,7 @@ static int ui_main()
|
|||
ImGui::NewFrame();
|
||||
|
||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||
//if (show_demo_window)
|
||||
ui_main_window();
|
||||
if (show_demo_window) {
|
||||
ImGui::ShowDemoWindow(&show_demo_window);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue