Merge pull request #63 from JosJuice/fix-osd-merge

Fix merge of OnScreenDisplay.cpp which I messed up
This commit is contained in:
David Liu 2020-12-02 18:31:37 -05:00 committed by GitHub
commit fdea0f3cc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,10 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "VideoCommon/OnScreenDisplay.h"
#include <algorithm> #include <algorithm>
#include <atomic>
#include <map> #include <map>
#include <mutex> #include <mutex>
#include <string> #include <string>
@ -12,12 +15,11 @@
#include "AudioCommon/AudioCommon.h" #include "AudioCommon/AudioCommon.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Timer.h"
#include "Common/Config/Config.h" #include "Common/Config/Config.h"
#include "Common/Timer.h"
#include "Core/Config/MainSettings.h" #include "Core/Config/MainSettings.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Slippi/SlippiPlayback.h" #include "Core/Slippi/SlippiPlayback.h"
#include "VideoCommon/OnScreenDisplay.h"
#ifdef IS_PLAYBACK #ifdef IS_PLAYBACK
#ifndef IMGUI_DEFINE_MATH_OPERATORS #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 TOP_MARGIN = 10.0f; // Pixels above the first OSD message.
constexpr float WINDOW_PADDING = 4.0f; // Pixels between subsequent OSD messages. 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 struct Message
{ {
Message() = default; Message() = default;
@ -53,12 +58,12 @@ struct Message
static std::multimap<MessageType, Message> s_messages; static std::multimap<MessageType, Message> s_messages;
static std::mutex s_messages_mutex; 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, return ImVec4(static_cast<float>((argb >> 16) & 0xFF) / 255.0f,
static_cast<float>((rgba >> 8) & 0xFF) / 255.0f, static_cast<float>((argb >> 8) & 0xFF) / 255.0f,
static_cast<float>((rgba >> 0) & 0xFF) / 255.0f, static_cast<float>((argb >> 0) & 0xFF) / 255.0f,
static_cast<float>((rgba >> 24) & 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) 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)) ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing))
{ {
// Use %s in case message contains %. // 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 = window_height =
ImGui::GetWindowSize().y + (WINDOW_PADDING * ImGui::GetIO().DisplayFramebufferScale.y); 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; 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}; std::lock_guard lock{s_messages_mutex};
s_messages.erase(type); 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}; std::lock_guard lock{s_messages_mutex};
s_messages.emplace(MessageType::Typeless, 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() void DrawMessages()
{ {
const bool draw_messages = Config::Get(Config::MAIN_OSD_MESSAGES); const bool draw_messages = Config::Get(Config::MAIN_OSD_MESSAGES);
const u32 now = Common::Timer::GetTimeMs(); const u32 now = Common::Timer::GetTimeMs();
const float current_x = LEFT_MARGIN * ImGui::GetIO().DisplayFramebufferScale.x; const float current_x =
float current_y = TOP_MARGIN * ImGui::GetIO().DisplayFramebufferScale.y; 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; int index = 0;
std::lock_guard lock{s_messages_mutex}; std::lock_guard lock{s_messages_mutex};
@ -144,6 +150,16 @@ void ClearMessages()
s_messages.clear(); s_messages.clear();
} }
void SetObscuredPixelsLeft(int width)
{
s_obscured_pixels_left = width;
}
void SetObscuredPixelsTop(int height)
{
s_obscured_pixels_top = height;
}
#ifdef IS_PLAYBACK #ifdef IS_PLAYBACK
static float height = 1080.0f; static float height = 1080.0f;
static float scaled_height = height; static float scaled_height = height;