GUI: implement custom title format

New option "Window Title Format" in Misc.
Backward compatible with FPS disabler.
Make rpcs3:::get_branch() return string_view.
This commit is contained in:
Nekotekina 2020-02-12 23:52:11 +03:00
parent 606693a9f7
commit 0d7aa5e310
8 changed files with 142 additions and 54 deletions

View file

@ -13,8 +13,6 @@
#include <QMessageBox>
#include <string>
#include "rpcs3_version.h"
#include "png.h"
#ifdef _WIN32
@ -35,32 +33,12 @@ LOG_CHANNEL(screenshot);
constexpr auto qstr = QString::fromStdString;
gs_frame::gs_frame(const QString& title, const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings)
: QWindow(), m_windowTitle(title), m_gui_settings(gui_settings)
gs_frame::gs_frame(const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings)
: QWindow(), m_gui_settings(gui_settings)
{
m_disable_mouse = gui_settings->GetValue(gui::gs_disableMouse).toBool();
// Get version by substringing VersionNumber-buildnumber-commithash to get just the part before the dash
std::string version = rpcs3::get_version().to_string();
version = version.substr(0 , version.find_last_of('-'));
// Add branch and commit hash to version on frame unless it's master.
if ((rpcs3::get_branch().compare("master") != 0) && (rpcs3::get_branch().compare("HEAD") != 0))
{
version = version + "-" + rpcs3::get_version().to_string().substr((rpcs3::get_version().to_string().find_last_of('-') + 1), 8) + "-" + rpcs3::get_branch();
}
m_windowTitle += qstr(" | " + version);
if (!Emu.GetTitle().empty())
{
m_windowTitle += qstr(" | " + Emu.GetTitle());
}
if (!Emu.GetTitleID().empty())
{
m_windowTitle += qstr(" [" + Emu.GetTitleID() + ']');
}
m_window_title = qstr(Emu.FormatTitle(0));
if (!appIcon.isNull())
{
@ -76,7 +54,7 @@ gs_frame::gs_frame(const QString& title, const QRect& geometry, const QIcon& app
setMinimumWidth(160);
setMinimumHeight(90);
setGeometry(geometry);
setTitle(m_windowTitle);
setTitle(m_window_title);
setVisibility(Hidden);
create();
@ -291,31 +269,22 @@ void gs_frame::flip(draw_context_t, bool /*skip_frame*/)
{
static Timer fps_t;
if (!m_show_fps_in_title && !g_cfg.misc.show_fps_in_title)
{
return;
}
++m_frames;
if (fps_t.GetElapsedTimeInSec() >= 0.5)
{
QString fps_title;
QString new_title = qstr(Emu.FormatTitle(m_frames / fps_t.GetElapsedTimeInSec()));
if ((m_show_fps_in_title = g_cfg.misc.show_fps_in_title.get()))
if (new_title != m_window_title)
{
fps_title = qstr(fmt::format("FPS: %.2f", m_frames / fps_t.GetElapsedTimeInSec()));
m_window_title = new_title;
if (!m_windowTitle.isEmpty())
Emu.CallAfter([this, title = std::move(new_title)]()
{
fps_title += " | ";
}
setTitle(title);
});
}
fps_title += m_windowTitle;
Emu.CallAfter([this, title = std::move(fps_title)]() { setTitle(title); });
m_frames = 0;
fps_t.Start();
}