HostInterface: Most some imgui logic from SDL to core

This commit is contained in:
Connor McLaughlin 2020-01-02 19:14:06 +10:00
parent 9436ffc806
commit 9de0bf0aaf
4 changed files with 93 additions and 24 deletions

View file

@ -3,9 +3,15 @@
#include "YBaseLib/Log.h"
#include "YBaseLib/Timer.h"
#include "bios.h"
#include "cdrom.h"
#include "common/audio_stream.h"
#include "dma.h"
#include "gpu.h"
#include "host_display.h"
#include "mdec.h"
#include "spu.h"
#include "system.h"
#include "timers.h"
#include <imgui.h>
Log_SetChannel(HostInterface);
@ -98,6 +104,73 @@ void HostInterface::ReportMessage(const char* message)
Log_InfoPrintf(message);
}
void HostInterface::DrawFPSWindow()
{
const bool show_fps = true;
const bool show_vps = true;
const bool show_speed = true;
if (!(show_fps | show_vps | show_speed))
return;
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x - 175.0f, 0.0f), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(175.0f, 16.0f));
if (!ImGui::Begin("FPSWindow", nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMouseInputs |
ImGuiWindowFlags_NoBringToFrontOnFocus))
{
ImGui::End();
return;
}
bool first = true;
if (show_fps)
{
ImGui::Text("%.2f", m_fps);
first = false;
}
if (show_vps)
{
if (first)
{
first = false;
}
else
{
ImGui::SameLine();
ImGui::Text("/");
ImGui::SameLine();
}
ImGui::Text("%.2f", m_vps);
}
if (show_speed)
{
if (first)
{
first = false;
}
else
{
ImGui::SameLine();
ImGui::Text("/");
ImGui::SameLine();
}
const u32 rounded_speed = static_cast<u32>(std::round(m_speed));
if (m_speed < 90.0f)
ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.4f, 1.0f), "%u%%", rounded_speed);
else if (m_speed < 110.0f)
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.0f), "%u%%", rounded_speed);
else
ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f), "%u%%", rounded_speed);
}
ImGui::End();
}
void HostInterface::AddOSDMessage(const char* message, float duration /*= 2.0f*/)
{
OSDMessage msg;
@ -150,6 +223,22 @@ void HostInterface::DrawOSDMessages()
}
}
void HostInterface::DrawDebugWindows()
{
const Settings::DebugSettings& debug_settings = m_system->GetSettings().debugging;
if (debug_settings.show_gpu_state)
m_system->GetGPU()->DrawDebugStateWindow();
if (debug_settings.show_cdrom_state)
m_system->GetCDROM()->DrawDebugWindow();
if (debug_settings.show_timers_state)
m_system->GetTimers()->DrawDebugStateWindow();
if (debug_settings.show_spu_state)
m_system->GetSPU()->DrawDebugStateWindow();
if (debug_settings.show_mdec_state)
m_system->GetMDEC()->DrawDebugStateWindow();
}
void HostInterface::ClearImGuiFocus()
{
ImGui::SetWindowFocus(nullptr);

View file

@ -65,7 +65,9 @@ protected:
void UpdateSpeedLimiterState();
void DrawFPSWindow();
void DrawOSDMessages();
void DrawDebugWindows();
void ClearImGuiFocus();
void UpdatePerformanceCounters();

View file

@ -1,23 +1,18 @@
#include "sdl_host_interface.h"
#include "sdl_settings_interface.h"
#include "YBaseLib/AutoReleasePtr.h"
#include "YBaseLib/ByteStream.h"
#include "YBaseLib/Error.h"
#include "YBaseLib/Log.h"
#include "common/null_audio_stream.h"
#include "core/cdrom.h"
#include "core/dma.h"
#include "core/controller.h"
#include "core/gpu.h"
#include "core/host_display.h"
#include "core/mdec.h"
#include "core/memory_card.h"
#include "core/spu.h"
#include "core/system.h"
#include "core/timers.h"
#include "icon.h"
#include "imgui_styles.h"
#include "opengl_host_display.h"
#include "sdl_audio_stream.h"
#include "sdl_settings_interface.h"
#include <cinttypes>
#include <imgui.h>
#include <imgui_impl_sdl.h>
@ -1412,22 +1407,6 @@ void SDLHostInterface::DrawAboutWindow()
ImGui::EndPopup();
}
void SDLHostInterface::DrawDebugWindows()
{
const Settings::DebugSettings& debug_settings = m_system->GetSettings().debugging;
if (debug_settings.show_gpu_state)
m_system->GetGPU()->DrawDebugStateWindow();
if (debug_settings.show_cdrom_state)
m_system->GetCDROM()->DrawDebugWindow();
if (debug_settings.show_timers_state)
m_system->GetTimers()->DrawDebugStateWindow();
if (debug_settings.show_spu_state)
m_system->GetSPU()->DrawDebugStateWindow();
if (debug_settings.show_mdec_state)
m_system->GetMDEC()->DrawDebugStateWindow();
}
bool SDLHostInterface::DrawFileChooser(const char* label, std::string* path, const char* filter /* = nullptr */)
{
ImGui::SetNextItemWidth(ImGui::CalcItemWidth() - 50.0f);

View file

@ -124,7 +124,6 @@ private:
void DrawPoweredOffWindow();
void DrawSettingsWindow();
void DrawAboutWindow();
void DrawDebugWindows();
bool DrawFileChooser(const char* label, std::string* path, const char* filter = nullptr);
SDL_Window* m_window = nullptr;