HostInterface: Move OSD messages to base class

This commit is contained in:
Connor McLaughlin
2019-12-01 21:33:56 +10:00
parent 0a6b913536
commit 299ee05cd9
4 changed files with 76 additions and 75 deletions

View File

@@ -608,11 +608,6 @@ void SDLHostInterface::HandleSDLKeyEvent(const SDL_Event* event)
}
}
void SDLHostInterface::ClearImGuiFocus()
{
ImGui::SetWindowFocus(nullptr);
}
void SDLHostInterface::DrawImGui()
{
DrawMainMenuBar();
@@ -1274,58 +1269,6 @@ bool SDLHostInterface::DrawFileChooser(const char* label, std::string* path, con
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()
{
Assert(m_system);

View File

@@ -31,9 +31,6 @@ public:
void ReportError(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();
protected:
@@ -43,13 +40,6 @@ private:
static constexpr u32 NUM_QUICK_SAVE_STATES = 10;
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); }
#ifdef WIN32
@@ -91,7 +81,6 @@ private:
void HandleSDLEvent(const SDL_Event* event);
void HandleSDLKeyEvent(const SDL_Event* event);
void ClearImGuiFocus();
void DrawMainMenuBar();
void DrawQuickSettingsMenu();
@@ -99,7 +88,6 @@ private:
void DrawPoweredOffWindow();
void DrawSettingsWindow();
void DrawAboutWindow();
void DrawOSDMessages();
void DrawDebugWindows();
bool DrawFileChooser(const char* label, std::string* path, const char* filter = nullptr);
@@ -108,9 +96,6 @@ private:
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::shared_ptr<DigitalController> m_controller;