mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-08-25 11:46:27 +00:00
Fix merge of OnScreenDisplay.cpp which I messed up
I accidentally discarded the changes made in upstream. Also fixing the include order while I'm at it.
This commit is contained in:
parent
fb1798791f
commit
f13d09516f
1 changed files with 30 additions and 14 deletions
|
@ -2,7 +2,10 @@
|
|||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "VideoCommon/OnScreenDisplay.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
@ -12,12 +15,11 @@
|
|||
|
||||
#include "AudioCommon/AudioCommon.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Timer.h"
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Common/Timer.h"
|
||||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Slippi/SlippiPlayback.h"
|
||||
#include "VideoCommon/OnScreenDisplay.h"
|
||||
|
||||
#ifdef IS_PLAYBACK
|
||||
#ifndef IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
@ -39,6 +41,9 @@ constexpr float LEFT_MARGIN = 10.0f; // Pixels to the left of OSD messages.
|
|||
constexpr float TOP_MARGIN = 10.0f; // Pixels above the first OSD message.
|
||||
constexpr float WINDOW_PADDING = 4.0f; // Pixels between subsequent OSD messages.
|
||||
|
||||
static std::atomic<int> s_obscured_pixels_left = 0;
|
||||
static std::atomic<int> s_obscured_pixels_top = 0;
|
||||
|
||||
struct Message
|
||||
{
|
||||
Message() = default;
|
||||
|
@ -53,12 +58,12 @@ struct Message
|
|||
static std::multimap<MessageType, Message> s_messages;
|
||||
static std::mutex s_messages_mutex;
|
||||
|
||||
static ImVec4 RGBAToImVec4(const u32 rgba)
|
||||
static ImVec4 ARGBToImVec4(const u32 argb)
|
||||
{
|
||||
return ImVec4(static_cast<float>((rgba >> 16) & 0xFF) / 255.0f,
|
||||
static_cast<float>((rgba >> 8) & 0xFF) / 255.0f,
|
||||
static_cast<float>((rgba >> 0) & 0xFF) / 255.0f,
|
||||
static_cast<float>((rgba >> 24) & 0xFF) / 255.0f);
|
||||
return ImVec4(static_cast<float>((argb >> 16) & 0xFF) / 255.0f,
|
||||
static_cast<float>((argb >> 8) & 0xFF) / 255.0f,
|
||||
static_cast<float>((argb >> 0) & 0xFF) / 255.0f,
|
||||
static_cast<float>((argb >> 24) & 0xFF) / 255.0f);
|
||||
}
|
||||
|
||||
static float DrawMessage(int index, const Message& msg, const ImVec2& position, int time_left)
|
||||
|
@ -83,7 +88,7 @@ static float DrawMessage(int index, const Message& msg, const ImVec2& position,
|
|||
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing))
|
||||
{
|
||||
// Use %s in case message contains %.
|
||||
ImGui::TextColored(RGBAToImVec4(msg.color), "%s", msg.text.c_str());
|
||||
ImGui::TextColored(ARGBToImVec4(msg.color), "%s", msg.text.c_str());
|
||||
window_height =
|
||||
ImGui::GetWindowSize().y + (WINDOW_PADDING * ImGui::GetIO().DisplayFramebufferScale.y);
|
||||
}
|
||||
|
@ -94,26 +99,27 @@ static float DrawMessage(int index, const Message& msg, const ImVec2& position,
|
|||
return window_height;
|
||||
}
|
||||
|
||||
void AddTypedMessage(MessageType type, std::string message, u32 ms, u32 rgba)
|
||||
void AddTypedMessage(MessageType type, std::string message, u32 ms, u32 argb)
|
||||
{
|
||||
std::lock_guard lock{s_messages_mutex};
|
||||
s_messages.erase(type);
|
||||
s_messages.emplace(type, Message(std::move(message), Common::Timer::GetTimeMs() + ms, rgba));
|
||||
s_messages.emplace(type, Message(std::move(message), Common::Timer::GetTimeMs() + ms, argb));
|
||||
}
|
||||
|
||||
void AddMessage(std::string message, u32 ms, u32 rgba)
|
||||
void AddMessage(std::string message, u32 ms, u32 argb)
|
||||
{
|
||||
std::lock_guard lock{s_messages_mutex};
|
||||
s_messages.emplace(MessageType::Typeless,
|
||||
Message(std::move(message), Common::Timer::GetTimeMs() + ms, rgba));
|
||||
Message(std::move(message), Common::Timer::GetTimeMs() + ms, argb));
|
||||
}
|
||||
|
||||
void DrawMessages()
|
||||
{
|
||||
const bool draw_messages = Config::Get(Config::MAIN_OSD_MESSAGES);
|
||||
const u32 now = Common::Timer::GetTimeMs();
|
||||
const float current_x = LEFT_MARGIN * ImGui::GetIO().DisplayFramebufferScale.x;
|
||||
float current_y = TOP_MARGIN * ImGui::GetIO().DisplayFramebufferScale.y;
|
||||
const float current_x =
|
||||
LEFT_MARGIN * ImGui::GetIO().DisplayFramebufferScale.x + s_obscured_pixels_left;
|
||||
float current_y = TOP_MARGIN * ImGui::GetIO().DisplayFramebufferScale.y + s_obscured_pixels_top;
|
||||
int index = 0;
|
||||
|
||||
std::lock_guard lock{s_messages_mutex};
|
||||
|
@ -144,6 +150,16 @@ void ClearMessages()
|
|||
s_messages.clear();
|
||||
}
|
||||
|
||||
void SetObscuredPixelsLeft(int width)
|
||||
{
|
||||
s_obscured_pixels_left = width;
|
||||
}
|
||||
|
||||
void SetObscuredPixelsTop(int height)
|
||||
{
|
||||
s_obscured_pixels_top = height;
|
||||
}
|
||||
|
||||
#ifdef IS_PLAYBACK
|
||||
static float height = 1080.0f;
|
||||
static float scaled_height = height;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue