HostInterface: Move OSD messages to base class
This commit is contained in:
parent
0a6b913536
commit
299ee05cd9
|
@ -7,6 +7,7 @@
|
||||||
#include "host_display.h"
|
#include "host_display.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <imgui.h>
|
||||||
Log_SetChannel(HostInterface);
|
Log_SetChannel(HostInterface);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -82,7 +83,6 @@ void HostInterface::ResetSystem()
|
||||||
AddOSDMessage("System reset.");
|
AddOSDMessage("System reset.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HostInterface::DestroySystem()
|
void HostInterface::DestroySystem()
|
||||||
{
|
{
|
||||||
m_system.reset();
|
m_system.reset();
|
||||||
|
@ -100,6 +100,63 @@ void HostInterface::ReportMessage(const char* message)
|
||||||
Log_InfoPrintf(message);
|
Log_InfoPrintf(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HostInterface::AddOSDMessage(const char* message, float duration /*= 2.0f*/)
|
||||||
|
{
|
||||||
|
OSDMessage msg;
|
||||||
|
msg.text = message;
|
||||||
|
msg.duration = duration;
|
||||||
|
|
||||||
|
std::unique_lock<std::mutex> lock(m_osd_messages_lock);
|
||||||
|
m_osd_messages.push_back(std::move(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
void HostInterface::DrawOSDMessages()
|
||||||
|
{
|
||||||
|
constexpr ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs |
|
||||||
|
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |
|
||||||
|
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoNav |
|
||||||
|
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing;
|
||||||
|
|
||||||
|
std::unique_lock<std::mutex> lock(m_osd_messages_lock);
|
||||||
|
const float scale = ImGui::GetIO().DisplayFramebufferScale.x;
|
||||||
|
|
||||||
|
auto iter = m_osd_messages.begin();
|
||||||
|
float position_x = 10.0f * scale;
|
||||||
|
float position_y = (10.0f + (m_settings.display_fullscreen ? 0.0f : 20.0f)) * scale;
|
||||||
|
u32 index = 0;
|
||||||
|
while (iter != m_osd_messages.end())
|
||||||
|
{
|
||||||
|
const OSDMessage& msg = *iter;
|
||||||
|
const double time = msg.time.GetTimeSeconds();
|
||||||
|
const float time_remaining = static_cast<float>(msg.duration - time);
|
||||||
|
if (time_remaining <= 0.0f)
|
||||||
|
{
|
||||||
|
iter = m_osd_messages.erase(iter);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float opacity = std::min(time_remaining, 1.0f);
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(position_x, position_y));
|
||||||
|
ImGui::SetNextWindowSize(ImVec2(0.0f, 0.0f));
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, opacity);
|
||||||
|
|
||||||
|
if (ImGui::Begin(SmallString::FromFormat("osd_%u", index++), nullptr, window_flags))
|
||||||
|
{
|
||||||
|
ImGui::TextUnformatted(msg.text.c_str());
|
||||||
|
position_y += ImGui::GetWindowSize().y + (4.0f * scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HostInterface::ClearImGuiFocus()
|
||||||
|
{
|
||||||
|
ImGui::SetWindowFocus(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<std::vector<u8>> HostInterface::GetBIOSImage(ConsoleRegion region)
|
std::optional<std::vector<u8>> HostInterface::GetBIOSImage(ConsoleRegion region)
|
||||||
{
|
{
|
||||||
// Try the other default filenames in the directory of the configured BIOS.
|
// Try the other default filenames in the directory of the configured BIOS.
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <deque>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class AudioStream;
|
class AudioStream;
|
||||||
|
@ -38,8 +41,8 @@ public:
|
||||||
virtual void ReportError(const char* message);
|
virtual void ReportError(const char* message);
|
||||||
virtual void ReportMessage(const char* message);
|
virtual void ReportMessage(const char* message);
|
||||||
|
|
||||||
// Adds OSD messages, duration is in seconds.
|
/// Adds OSD messages, duration is in seconds.
|
||||||
virtual void AddOSDMessage(const char* message, float duration = 2.0f) = 0;
|
void AddOSDMessage(const char* message, float duration = 2.0f);
|
||||||
|
|
||||||
/// Loads the BIOS image for the specified region.
|
/// Loads the BIOS image for the specified region.
|
||||||
virtual std::optional<std::vector<u8>> GetBIOSImage(ConsoleRegion region);
|
virtual std::optional<std::vector<u8>> GetBIOSImage(ConsoleRegion region);
|
||||||
|
@ -50,6 +53,13 @@ public:
|
||||||
protected:
|
protected:
|
||||||
using ThrottleClock = std::chrono::steady_clock;
|
using ThrottleClock = std::chrono::steady_clock;
|
||||||
|
|
||||||
|
struct OSDMessage
|
||||||
|
{
|
||||||
|
std::string text;
|
||||||
|
Timer time;
|
||||||
|
float duration;
|
||||||
|
};
|
||||||
|
|
||||||
/// Connects controllers. TODO: Clean this up later...
|
/// Connects controllers. TODO: Clean this up later...
|
||||||
virtual void ConnectControllers();
|
virtual void ConnectControllers();
|
||||||
|
|
||||||
|
@ -58,6 +68,9 @@ protected:
|
||||||
|
|
||||||
void UpdateSpeedLimiterState();
|
void UpdateSpeedLimiterState();
|
||||||
|
|
||||||
|
void DrawOSDMessages();
|
||||||
|
void ClearImGuiFocus();
|
||||||
|
|
||||||
void UpdatePerformanceCounters();
|
void UpdatePerformanceCounters();
|
||||||
void ResetPerformanceCounters();
|
void ResetPerformanceCounters();
|
||||||
|
|
||||||
|
@ -79,6 +92,9 @@ protected:
|
||||||
u32 m_last_global_tick_counter = 0;
|
u32 m_last_global_tick_counter = 0;
|
||||||
Timer m_fps_timer;
|
Timer m_fps_timer;
|
||||||
|
|
||||||
|
std::deque<OSDMessage> m_osd_messages;
|
||||||
|
std::mutex m_osd_messages_lock;
|
||||||
|
|
||||||
bool m_paused = false;
|
bool m_paused = false;
|
||||||
bool m_speed_limiter_temp_disabled = false;
|
bool m_speed_limiter_temp_disabled = false;
|
||||||
bool m_speed_limiter_enabled = false;
|
bool m_speed_limiter_enabled = false;
|
||||||
|
|
|
@ -608,11 +608,6 @@ void SDLHostInterface::HandleSDLKeyEvent(const SDL_Event* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLHostInterface::ClearImGuiFocus()
|
|
||||||
{
|
|
||||||
ImGui::SetWindowFocus(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDLHostInterface::DrawImGui()
|
void SDLHostInterface::DrawImGui()
|
||||||
{
|
{
|
||||||
DrawMainMenuBar();
|
DrawMainMenuBar();
|
||||||
|
@ -1274,58 +1269,6 @@ bool SDLHostInterface::DrawFileChooser(const char* label, std::string* path, con
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLHostInterface::AddOSDMessage(const char* message, float duration /*= 2.0f*/)
|
|
||||||
{
|
|
||||||
OSDMessage msg;
|
|
||||||
msg.text = message;
|
|
||||||
msg.duration = duration;
|
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(m_osd_messages_lock);
|
|
||||||
m_osd_messages.push_back(std::move(msg));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDLHostInterface::DrawOSDMessages()
|
|
||||||
{
|
|
||||||
constexpr ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs |
|
|
||||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |
|
|
||||||
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoNav |
|
|
||||||
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing;
|
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(m_osd_messages_lock);
|
|
||||||
const float scale = ImGui::GetIO().DisplayFramebufferScale.x;
|
|
||||||
|
|
||||||
auto iter = m_osd_messages.begin();
|
|
||||||
float position_x = 10.0f * scale;
|
|
||||||
float position_y = (10.0f + (m_settings.display_fullscreen ? 0.0f : 20.0f)) * scale;
|
|
||||||
u32 index = 0;
|
|
||||||
while (iter != m_osd_messages.end())
|
|
||||||
{
|
|
||||||
const OSDMessage& msg = *iter;
|
|
||||||
const double time = msg.time.GetTimeSeconds();
|
|
||||||
const float time_remaining = static_cast<float>(msg.duration - time);
|
|
||||||
if (time_remaining <= 0.0f)
|
|
||||||
{
|
|
||||||
iter = m_osd_messages.erase(iter);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float opacity = std::min(time_remaining, 1.0f);
|
|
||||||
ImGui::SetNextWindowPos(ImVec2(position_x, position_y));
|
|
||||||
ImGui::SetNextWindowSize(ImVec2(0.0f, 0.0f));
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, opacity);
|
|
||||||
|
|
||||||
if (ImGui::Begin(SmallString::FromFormat("osd_%u", index++), nullptr, window_flags))
|
|
||||||
{
|
|
||||||
ImGui::TextUnformatted(msg.text);
|
|
||||||
position_y += ImGui::GetWindowSize().y + (4.0f * scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::End();
|
|
||||||
ImGui::PopStyleVar();
|
|
||||||
++iter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDLHostInterface::DoPowerOff()
|
void SDLHostInterface::DoPowerOff()
|
||||||
{
|
{
|
||||||
Assert(m_system);
|
Assert(m_system);
|
||||||
|
|
|
@ -31,9 +31,6 @@ public:
|
||||||
void ReportError(const char* message) override;
|
void ReportError(const char* message) override;
|
||||||
void ReportMessage(const char* message) override;
|
void ReportMessage(const char* message) override;
|
||||||
|
|
||||||
// Adds OSD messages, duration is in seconds.
|
|
||||||
void AddOSDMessage(const char* message, float duration = 2.0f) override;
|
|
||||||
|
|
||||||
void Run();
|
void Run();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -43,13 +40,6 @@ private:
|
||||||
static constexpr u32 NUM_QUICK_SAVE_STATES = 10;
|
static constexpr u32 NUM_QUICK_SAVE_STATES = 10;
|
||||||
static constexpr char RESUME_SAVESTATE_FILENAME[] = "savestate_resume.bin";
|
static constexpr char RESUME_SAVESTATE_FILENAME[] = "savestate_resume.bin";
|
||||||
|
|
||||||
struct OSDMessage
|
|
||||||
{
|
|
||||||
String text;
|
|
||||||
Timer time;
|
|
||||||
float duration;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool HasSystem() const { return static_cast<bool>(m_system); }
|
bool HasSystem() const { return static_cast<bool>(m_system); }
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -91,7 +81,6 @@ private:
|
||||||
|
|
||||||
void HandleSDLEvent(const SDL_Event* event);
|
void HandleSDLEvent(const SDL_Event* event);
|
||||||
void HandleSDLKeyEvent(const SDL_Event* event);
|
void HandleSDLKeyEvent(const SDL_Event* event);
|
||||||
void ClearImGuiFocus();
|
|
||||||
|
|
||||||
void DrawMainMenuBar();
|
void DrawMainMenuBar();
|
||||||
void DrawQuickSettingsMenu();
|
void DrawQuickSettingsMenu();
|
||||||
|
@ -99,7 +88,6 @@ private:
|
||||||
void DrawPoweredOffWindow();
|
void DrawPoweredOffWindow();
|
||||||
void DrawSettingsWindow();
|
void DrawSettingsWindow();
|
||||||
void DrawAboutWindow();
|
void DrawAboutWindow();
|
||||||
void DrawOSDMessages();
|
|
||||||
void DrawDebugWindows();
|
void DrawDebugWindows();
|
||||||
bool DrawFileChooser(const char* label, std::string* path, const char* filter = nullptr);
|
bool DrawFileChooser(const char* label, std::string* path, const char* filter = nullptr);
|
||||||
|
|
||||||
|
@ -108,9 +96,6 @@ private:
|
||||||
|
|
||||||
std::string m_settings_filename;
|
std::string m_settings_filename;
|
||||||
|
|
||||||
std::deque<OSDMessage> m_osd_messages;
|
|
||||||
std::mutex m_osd_messages_lock;
|
|
||||||
|
|
||||||
std::map<int, SDL_GameController*> m_sdl_controllers;
|
std::map<int, SDL_GameController*> m_sdl_controllers;
|
||||||
|
|
||||||
std::shared_ptr<DigitalController> m_controller;
|
std::shared_ptr<DigitalController> m_controller;
|
||||||
|
|
Loading…
Reference in New Issue