GlosSITarget: Add Splashscreen / Overlay background

pull/183/head
Peter Repukat 2 years ago
parent dd978ae80c
commit 6fcf50b408

@ -201,6 +201,7 @@
<ClInclude Include="..\deps\subhook\subhook.h" />
<ClInclude Include="AppLauncher.h" />
<ClInclude Include="DllInjector.h" />
<ClInclude Include="GlosSI_logo.h" />
<ClInclude Include="HidHide.h" />
<ClInclude Include="imconfig.h" />
<ClInclude Include="InputRedirector.h" />

@ -173,6 +173,9 @@
<ClInclude Include="ProcessPriority.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GlosSI_logo.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\deps\SFML\out\Debug\lib\Debug\sfml-system-d-2.dll" />

File diff suppressed because it is too large Load Diff

@ -19,9 +19,11 @@ limitations under the License.
#include <utility>
#include <locale>
#include <codecvt>
#include <regex>
#include "Roboto.h"
#include "Settings.h"
#include "GlosSI_logo.h"
#include "../version.hpp"
@ -42,7 +44,6 @@ Overlay::Overlay(
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.Fonts->Clear(); // clear fonts if you loaded some before (even if only default one was loaded)
auto fontconf = ImFontConfig{};
fontconf.FontDataOwnedByAtlas = false;
@ -66,9 +67,17 @@ Overlay::Overlay(
io.IniFilename = config_file_name_.data();
#endif
if (!logo_texture_.loadFromMemory(GLOSSI_LOGO.data(), GLOSSI_LOGO.size())) {
spdlog::trace("Failed to load logo texture");
}
if (logo_texture_.getSize().x > 0) {
logo_sprite_.setTexture(logo_texture_);
logo_sprite_.setScale(0.5f, 0.5f);
}
window.resetGLStates();
//Hack: Trick ImGui::SFML into thinking we already have focus (otherwise only notices after focus-lost)
// Hack: Trick ImGui::SFML into thinking we already have focus (otherwise only notices after focus-lost)
const sf::Event ev(sf::Event::GainedFocus);
ProcessEvent(ev);
@ -157,13 +166,26 @@ void Overlay::update()
{
ImGui::SFML::Update(window_, update_clock_.restart());
if (!enabled_ && !force_enable_ && time_since_start_clock_.getElapsedTime().asSeconds() < SPLASH_DURATION_S_) {
const auto millis = time_since_start_clock_.getElapsedTime().asMilliseconds();
const auto fade_millis = 1000;
const auto remain_millis = SPLASH_DURATION_S_ * 1000 - millis;
if (remain_millis <= fade_millis) {
showSplash(static_cast<float>(remain_millis) / static_cast<float>(fade_millis) * 128.f);
} else {
showSplash(128);
}
}
showLogs(0);
if (enabled_ || force_enable_) {
showSplash();
// Create a DockSpace node where any window can be docked
ImGui::SetNextWindowSize({ImGui::GetMainViewport()->Size.x * 0.6f, ImGui::GetMainViewport()->Size.y * 0.7f}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowPos({ImGui::GetMainViewport()->Size.x * 0.25f, 100 }, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowPos({ImGui::GetMainViewport()->Size.x * 0.25f, 100}, ImGuiCond_FirstUseEver);
ImGui::Begin("GlosSI Settings");
ImGui::Text("Version: %s", version::VERSION_STR);
if (Settings::settings_path_ != "") {
@ -176,14 +198,13 @@ void Overlay::update()
ImGui::DockSpace(dockspace_id);
window_.clear(sf::Color(0, 0, 0, 128)); // make window slightly dim screen with overlay
std::ranges::for_each(OVERLAY_ELEMS_, [this, &dockspace_id](const auto& elem) {
elem.second(window_.hasFocus(), dockspace_id);
});
ImGui::End();
// ImGui::ShowDemoWindow();
if (closeButton()) {
@ -239,13 +260,11 @@ void Overlay::showLogs(ImGuiID dockspace_id)
std::ranges::copy_if(LOG_MSGS_,
std::back_inserter(logs),
[&logs_contain_warn_or_worse](const auto& log) {
const auto res = (
log.time.time_since_epoch() + std::chrono::seconds(
LOG_RETENTION_TIME_) >
std::chrono::system_clock::now().time_since_epoch())
const auto res = (log.time.time_since_epoch() + std::chrono::seconds(
LOG_RETENTION_TIME_) >
std::chrono::system_clock::now().time_since_epoch())
#ifdef NDEBUG
&& (log.level > spdlog::level::debug)
&& (log.level > spdlog::level::debug)
#endif
;
if (res && log.level > spdlog::level::warn) {
@ -254,7 +273,7 @@ void Overlay::showLogs(ImGuiID dockspace_id)
return res;
});
}
if (logs.empty() || ( !enabled_ && !force_enable_ && !logs_contain_warn_or_worse && time_since_start_clock_.getElapsedTime().asSeconds() > HIDE_NORMAL_LOGS_AFTER_S))
if (logs.empty() || (!enabled_ && !force_enable_ && !logs_contain_warn_or_worse && time_since_start_clock_.getElapsedTime().asSeconds() > HIDE_NORMAL_LOGS_AFTER_S))
return;
ImGui::SetNextWindowSizeConstraints({150, 150}, {1000, window_.getSize().y - 250.f});
if (!enabled_) {
@ -263,7 +282,7 @@ void Overlay::showLogs(ImGuiID dockspace_id)
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoTitleBar);
}
else {
//ImGui::SetNextWindowDockID(dockspace_id, ImGuiCond_FirstUseEver);
// ImGui::SetNextWindowDockID(dockspace_id, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize({ImGui::GetMainViewport()->Size.x * 0.2f, ImGui::GetMainViewport()->Size.y * 0.7f}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowPos({ImGui::GetMainViewport()->Size.x * 0.05f, 100}, ImGuiCond_FirstUseEver);
log_expanded_ = ImGui::Begin("Log");
@ -340,3 +359,20 @@ bool Overlay::closeButton() const
ImGui::PopStyleVar();
return false;
}
void Overlay::showSplash(uint8_t alpha)
{
if (logo_texture_.getSize().x > 0) {
ImGui::SetNextWindowPos(
{ImGui::GetMainViewport()->Size.x * 0.5f - static_cast<float>(logo_texture_.getSize().x) * 0.5f * logo_sprite_.getScale().x,
ImGui::GetMainViewport()->Size.y * 0.5f - static_cast<float>(logo_texture_.getSize().y) * 0.5f * logo_sprite_.getScale().y});
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0});
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0f, 0.f, 0.f, 0.0f));
ImGui::Begin("##Splash", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar);
ImGui::Image(logo_sprite_, {255, 255, 255, alpha});
ImGui::End();
ImGui::PopStyleColor();
ImGui::PopStyleVar();
}
}

@ -50,10 +50,14 @@ class Overlay {
void showLogs(ImGuiID dockspace_id);
bool closeOverlayButton() const;
[[nodiscard]] bool closeButton() const;
void showSplash(uint8_t alpha = 128);
bool force_enable_ = false;
bool log_expanded_ = true;
sf::Clock time_since_start_clock_;
sf::Texture logo_texture_;
sf::Sprite logo_sprite_;
struct Log {
std::chrono::system_clock::time_point time;
spdlog::level::level_enum level;
@ -62,6 +66,7 @@ class Overlay {
static inline std::vector<Log> LOG_MSGS_;
static constexpr int LOG_RETENTION_TIME_ = 5;
static constexpr int HIDE_NORMAL_LOGS_AFTER_S = 20;
static constexpr int SPLASH_DURATION_S_ = 3;
static inline int overlay_element_id_ = 0;
static inline std::map<int, std::function<void(bool window_has_focus, ImGuiID dockspace_id)>> OVERLAY_ELEMS_;

Loading…
Cancel
Save