Frontend: Add about window

This commit is contained in:
Connor McLaughlin 2019-10-20 21:18:11 +10:00
parent d389fcaa13
commit cac09bcedc
2 changed files with 105 additions and 40 deletions

View file

@ -428,8 +428,10 @@ void SDLInterface::Render()
{ {
DrawImGui(); DrawImGui();
if (m_system)
m_system->GetGPU()->ResetGraphicsAPIState(); m_system->GetGPU()->ResetGraphicsAPIState();
glDisable(GL_SCISSOR_TEST);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -446,28 +448,11 @@ void SDLInterface::Render()
ImGui::NewFrame(); ImGui::NewFrame();
GL::Program::ResetLastProgram(); GL::Program::ResetLastProgram();
if (m_system)
m_system->GetGPU()->RestoreGraphicsAPIState(); m_system->GetGPU()->RestoreGraphicsAPIState();
} }
void SDLInterface::RenderPoweredOff()
{
DrawPoweredOffWindow();
ImGui::Render();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(m_window);
ImGui_ImplSDL2_NewFrame(m_window);
ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame();
}
static std::tuple<int, int, int, int> CalculateDrawRect(int window_width, int window_height, float display_ratio) static std::tuple<int, int, int, int> CalculateDrawRect(int window_width, int window_height, float display_ratio)
{ {
const float window_ratio = float(window_width) / float(window_height); const float window_ratio = float(window_width) / float(window_height);
@ -520,7 +505,13 @@ void SDLInterface::DrawImGui()
{ {
DrawMainMenuBar(); DrawMainMenuBar();
if (m_system)
m_system->DrawDebugWindows(); m_system->DrawDebugWindows();
else
DrawPoweredOffWindow();
if (m_about_window_open)
DrawAboutWindow();
DrawOSDMessages(); DrawOSDMessages();
@ -534,10 +525,15 @@ void SDLInterface::DrawMainMenuBar()
if (ImGui::BeginMenu("System")) if (ImGui::BeginMenu("System"))
{ {
if (ImGui::MenuItem("Reset")) const bool system_enabled = static_cast<bool>(m_system);
if (ImGui::MenuItem("Reset", nullptr, false, system_enabled))
DoReset(); DoReset();
ImGui::Separator(); ImGui::MenuItem("Change Disc", nullptr, false, system_enabled);
if (ImGui::MenuItem("Power Off", nullptr, false, system_enabled))
DoPowerOff();
#if 0 #if 0
if (ImGui::MenuItem("Enable Speed Limiter", nullptr, IsSpeedLimiterEnabled())) if (ImGui::MenuItem("Enable Speed Limiter", nullptr, IsSpeedLimiterEnabled()))
@ -546,6 +542,13 @@ void SDLInterface::DrawMainMenuBar()
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem("Start Disc"))
DoStartDisc();
if (ImGui::MenuItem("Start BIOS"))
DoStartBIOS();
ImGui::Separator();
if (ImGui::BeginMenu("Load State")) if (ImGui::BeginMenu("Load State"))
{ {
for (u32 i = 1; i <= 8; i++) for (u32 i = 1; i <= 8; i++)
@ -566,6 +569,8 @@ void SDLInterface::DrawMainMenuBar()
ImGui::EndMenu(); ImGui::EndMenu();
} }
ImGui::Separator();
if (ImGui::MenuItem("Exit")) if (ImGui::MenuItem("Exit"))
m_running = false; m_running = false;
@ -604,6 +609,8 @@ void SDLInterface::DrawMainMenuBar()
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (m_system)
{
if (ImGui::BeginMenu("Debug")) if (ImGui::BeginMenu("Debug"))
{ {
m_system->DrawDebugMenus(); m_system->DrawDebugMenus();
@ -625,6 +632,23 @@ void SDLInterface::DrawMainMenuBar()
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - 80.0f); ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - 80.0f);
ImGui::Text("VPS: %.2f", m_vps); ImGui::Text("VPS: %.2f", m_vps);
}
if (ImGui::BeginMenu("Help"))
{
if (ImGui::MenuItem("GitHub Repository"))
{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Add URL Opener", "https://github.com/stenzek/duckstation",
m_window);
}
ImGui::Separator();
if (ImGui::MenuItem("About"))
m_about_window_open = true;
ImGui::EndMenu();
}
ImGui::EndMainMenuBar(); ImGui::EndMainMenuBar();
} }
@ -695,6 +719,35 @@ void SDLInterface::DrawPoweredOffWindow()
ImGui::End(); ImGui::End();
} }
void SDLInterface::DrawAboutWindow()
{
ImGui::SetNextWindowPosCenter(ImGuiCond_FirstUseEver);
if (!ImGui::Begin("About DuckStation", &m_about_window_open))
{
ImGui::End();
return;
}
ImGui::Text("DuckStation");
ImGui::NewLine();
ImGui::Text("Authors:");
ImGui::Text(" Connor McLaughlin <stenzek@gmail.com>");
ImGui::NewLine();
ImGui::Text("Uses Dear ImGui (https://github.com/ocornut/imgui)");
ImGui::Text("Uses libcue (https://github.com/lipnitsk/libcue)");
ImGui::Text("Uses stb_image_write (https://github.com/nothings/stb)");
ImGui::NewLine();
ImGui::Text("Duck icon by icons8 (https://icons8.com/icon/74847/platforms.undefined.short-title)");
ImGui::NewLine();
ImGui::SetCursorPosX((ImGui::GetWindowSize().x - 60.0f) / 2.0f);
if (ImGui::Button("Close", ImVec2(60.0f, 20.0f)))
m_about_window_open = false;
ImGui::End();
}
void SDLInterface::AddOSDMessage(const char* message, float duration /*= 2.0f*/) void SDLInterface::AddOSDMessage(const char* message, float duration /*= 2.0f*/)
{ {
OSDMessage msg; OSDMessage msg;
@ -768,6 +821,15 @@ void SDLInterface::DoReset()
AddOSDMessage("System reset."); AddOSDMessage("System reset.");
} }
void SDLInterface::DoPowerOff()
{
Assert(m_system);
m_system.reset();
m_display_texture = nullptr;
AddOSDMessage("System powered off.");
}
void SDLInterface::DoResume() {} void SDLInterface::DoResume() {}
void SDLInterface::DoStartDisc() void SDLInterface::DoStartDisc()
@ -865,7 +927,7 @@ void SDLInterface::Run()
} }
else else
{ {
RenderPoweredOff(); Render();
} }
} }
} }

View file

@ -54,6 +54,7 @@ private:
bool IsWindowFullscreen() const; bool IsWindowFullscreen() const;
void DrawImGui(); void DrawImGui();
void DoReset(); void DoReset();
void DoPowerOff();
void DoResume(); void DoResume();
void DoStartDisc(); void DoStartDisc();
void DoStartBIOS(); void DoStartBIOS();
@ -63,10 +64,10 @@ private:
bool HandleSDLEvent(const SDL_Event* event); bool HandleSDLEvent(const SDL_Event* event);
bool PassEventToImGui(const SDL_Event* event); bool PassEventToImGui(const SDL_Event* event);
void Render(); void Render();
void RenderPoweredOff();
void RenderDisplay(); void RenderDisplay();
void DrawMainMenuBar(); void DrawMainMenuBar();
void DrawPoweredOffWindow(); void DrawPoweredOffWindow();
void DrawAboutWindow();
void DrawOSDMessages(); void DrawOSDMessages();
SDL_Window* m_window = nullptr; SDL_Window* m_window = nullptr;
@ -99,4 +100,6 @@ private:
u32 m_last_internal_frame_number = 0; u32 m_last_internal_frame_number = 0;
u32 m_last_global_tick_counter = 0; u32 m_last_global_tick_counter = 0;
Timer m_fps_timer; Timer m_fps_timer;
bool m_about_window_open = false;
}; };