From 0c645cbc78555e2b803d2ee50b47431082d10c7d Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 24 Dec 2024 12:12:59 -0600 Subject: [PATCH 1/4] Allow user to add splash image to splash screen. --- Source/Editor/Windows/SplashScreen.cpp | 67 ++++++++++++++++++++++++-- Source/Editor/Windows/SplashScreen.h | 3 ++ 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index 49257d281..2c8cd2e21 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -214,6 +214,27 @@ void SplashScreen::Show() font->OnLoaded.Bind(this); } + // Load Splash image + String splashImagePath = String::Format(TEXT("{0}/{1}"), Globals::ProjectContentFolder, TEXT("SplashImage/SplashImage.flax")); +#if PLATFORM_WIN32 + splashImagePath.Replace('/', '\\'); +#else + splashImagePath.Replace('\\', '/'); +#endif + + auto texture = Content::LoadAsync(*splashImagePath); + if (texture == nullptr) + { + LOG(Info, "Cannot load splash Texture at {0}", splashImagePath); + } + else + { + if (texture->IsLoaded()) + OnTextureLoaded(texture); + else + texture->OnLoaded.Bind(this); + } + _window->Show(); } @@ -246,8 +267,19 @@ void SplashScreen::OnDraw() const float time = static_cast((DateTime::NowUTC() - _startTime).GetTotalSeconds()); // Background - const float lightBarHeight = 112 * s; - Render2D::FillRectangle(Rectangle(0, 0, width, 150 * s), Color::FromRGB(0x1C1C1C)); + float lightBarHeight = 112 * s; + if (_splashTexture != nullptr) + { + if (_splashTexture->IsLoaded()) + { + lightBarHeight = height - lightBarHeight; + Render2D::DrawTexture(_splashTexture, Rectangle(0, 0, width, height)); + } + } + else + { + Render2D::FillRectangle(Rectangle(0, 0, width, 150 * s), Color::FromRGB(0x1C1C1C)); + } Render2D::FillRectangle(Rectangle(0, lightBarHeight, width, height), Color::FromRGB(0x0C0C0C)); // Animated border @@ -276,10 +308,18 @@ void SplashScreen::OnDraw() for (int32 i = 0; i < 4 - static_cast(time * 2.0f) % 4; i++) subtitle += TEXT(' '); } - layout.Bounds = Rectangle(width - 224 * s, lightBarHeight - 39 * s, 220 * s, 35 * s); + if (_splashTexture != nullptr) + { + layout.Bounds = Rectangle(width - 224 * s, lightBarHeight + 2 * s, 220 * s, 35 * s); + layout.VerticalAlignment = TextAlignment::Near; + } + else + { + layout.Bounds = Rectangle(width - 224 * s, lightBarHeight - 39 * s, 220 * s, 35 * s); + layout.VerticalAlignment = TextAlignment::Far; + } layout.Scale = 1.0f; layout.HorizontalAlignment = TextAlignment::Far; - layout.VerticalAlignment = TextAlignment::Far; Render2D::DrawText(_subtitleFont, subtitle, Color::FromRGB(0x8C8C8C), layout); // Additional info @@ -307,3 +347,22 @@ void SplashScreen::OnFontLoaded(Asset* asset) _titleFont = font->CreateFont(35 * s); _subtitleFont = font->CreateFont(9 * s); } + +void SplashScreen::OnTextureLoaded(Asset* asset) +{ + ASSERT(asset && asset->IsLoaded()); + auto texture = (Texture*)asset; + + texture->OnLoaded.Unbind(this); + _splashTexture = texture; + + // Resize window to be larger if texture is being used. + auto desktopSize = Platform::GetDesktopSize(); + auto xSize = (desktopSize.X / (600.0f * 3.0f)) * 600.0f; + auto ySize = (desktopSize.Y / (200.0f * 3.0f)) * 200.0f; + + _window->SetClientSize(Float2(xSize, ySize)); + _width = _window->GetSize().X; + _height = _window->GetSize().Y; + _window->SetPosition((Platform::GetDesktopSize() - _window->GetSize()) / 2.0f); +} diff --git a/Source/Editor/Windows/SplashScreen.h b/Source/Editor/Windows/SplashScreen.h index c8f59432e..6c840975e 100644 --- a/Source/Editor/Windows/SplashScreen.h +++ b/Source/Editor/Windows/SplashScreen.h @@ -2,6 +2,7 @@ #pragma once +#include "Engine/Content/Assets/Texture.h" #include "Engine/Core/Types/DateTime.h" #include "Engine/Platform/Window.h" @@ -18,6 +19,7 @@ private: Window* _window = nullptr; Font* _titleFont = nullptr; Font* _subtitleFont = nullptr; + Texture* _splashTexture = nullptr; String _title; DateTime _startTime; String _infoText; @@ -78,4 +80,5 @@ private: void OnDraw(); bool HasLoadedFonts() const; void OnFontLoaded(Asset* asset); + void OnTextureLoaded(Asset* asset); }; From 819c93f6fbd015cf237e1b14bc2193855302089d Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 24 Dec 2024 14:26:59 -0600 Subject: [PATCH 2/4] Increase margins. --- Source/Editor/Windows/SplashScreen.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index 2c8cd2e21..dc94da95c 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -272,7 +272,7 @@ void SplashScreen::OnDraw() { if (_splashTexture->IsLoaded()) { - lightBarHeight = height - lightBarHeight; + lightBarHeight = height - lightBarHeight + 20 * s; Render2D::DrawTexture(_splashTexture, Rectangle(0, 0, width, height)); } } @@ -310,7 +310,7 @@ void SplashScreen::OnDraw() } if (_splashTexture != nullptr) { - layout.Bounds = Rectangle(width - 224 * s, lightBarHeight + 2 * s, 220 * s, 35 * s); + layout.Bounds = Rectangle(width - 224 * s, lightBarHeight + 4 * s, 220 * s, 35 * s); layout.VerticalAlignment = TextAlignment::Near; } else @@ -324,7 +324,11 @@ void SplashScreen::OnDraw() // Additional info const float infoMargin = 6 * s; - layout.Bounds = Rectangle(infoMargin, lightBarHeight + infoMargin, width - (2 * infoMargin), height - lightBarHeight - (2 * infoMargin)); + if (_splashTexture != nullptr) + layout.Bounds = Rectangle(infoMargin + 4 * s, lightBarHeight + infoMargin, width - (2 * infoMargin), height - lightBarHeight - (2 * infoMargin)); + else + layout.Bounds = Rectangle(infoMargin, lightBarHeight + infoMargin, width - (2 * infoMargin), height - lightBarHeight - (2 * infoMargin)); + layout.HorizontalAlignment = TextAlignment::Near; layout.VerticalAlignment = TextAlignment::Center; Render2D::DrawText(_subtitleFont, _infoText, Color::FromRGB(0xFFFFFF) * 0.9f, layout); From 42d02a9e6368461df974f55aef134bffa99c63be Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 8 Feb 2025 18:49:04 -0600 Subject: [PATCH 3/4] Add small fade to bottom bar. --- Source/Editor/Windows/SplashScreen.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index dc94da95c..3a9e82cfe 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -274,13 +274,15 @@ void SplashScreen::OnDraw() { lightBarHeight = height - lightBarHeight + 20 * s; Render2D::DrawTexture(_splashTexture, Rectangle(0, 0, width, height)); + Color rectColor = Color::FromRGB(0x0C0C0C); + Render2D::FillRectangle(Rectangle(0, lightBarHeight, width, height - lightBarHeight),rectColor.AlphaMultiplied(0.85f), rectColor.AlphaMultiplied(0.85f), rectColor, rectColor); } } else { Render2D::FillRectangle(Rectangle(0, 0, width, 150 * s), Color::FromRGB(0x1C1C1C)); + Render2D::FillRectangle(Rectangle(0, lightBarHeight, width, height), Color::FromRGB(0x0C0C0C)); } - Render2D::FillRectangle(Rectangle(0, lightBarHeight, width, height), Color::FromRGB(0x0C0C0C)); // Animated border const float anim = Math::Sin(time * 4.0f) * 0.5f + 0.5f; From d6c75b3f8668c34748919c2c85d60573d902507d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 24 Aug 2025 13:37:48 +0200 Subject: [PATCH 4/4] Simplify code in #3119 --- Source/Editor/Windows/SplashScreen.cpp | 53 +++++++++----------------- Source/Editor/Windows/SplashScreen.h | 8 ++-- 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index 4707ffd6f..7e2889ca1 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -9,6 +9,7 @@ #include "Engine/Render2D/Font.h" #include "Engine/Render2D/TextLayoutOptions.h" #include "Engine/Render2D/Render2D.h" +#include "Engine/Platform/FileSystem.h" #include "Engine/Content/Content.h" #include "FlaxEngine.Gen.h" @@ -188,8 +189,7 @@ void SplashScreen::Show() // Setup _dpiScale = dpiScale; - _width = settings.Size.X; - _height = settings.Size.Y; + _size = settings.Size; _startTime = DateTime::NowUTC(); auto str = Globals::ProjectFolder; #if PLATFORM_WIN32 @@ -214,26 +214,11 @@ void SplashScreen::Show() font->OnLoaded.Bind(this); } - // Load Splash image - String splashImagePath = String::Format(TEXT("{0}/{1}"), Globals::ProjectContentFolder, TEXT("SplashImage/SplashImage.flax")); -#if PLATFORM_WIN32 - splashImagePath.Replace('/', '\\'); -#else - splashImagePath.Replace('\\', '/'); -#endif - - auto texture = Content::LoadAsync(*splashImagePath); - if (texture == nullptr) - { - LOG(Info, "Cannot load splash Texture at {0}", splashImagePath); - } - else - { - if (texture->IsLoaded()) - OnTextureLoaded(texture); - else - texture->OnLoaded.Bind(this); - } + // Load custom image + _splashTexture.Loaded.Bind(this); + String splashImagePath = Globals::ProjectContentFolder / TEXT("SplashImage.flax"); + if (FileSystem::FileExists(splashImagePath)) + _splashTexture = Content::LoadAsync(splashImagePath); _window->Show(); } @@ -248,6 +233,10 @@ void SplashScreen::Close() // Close window _window->Close(ClosingReason::CloseEvent); _window = nullptr; + + _titleFont = nullptr; + _subtitleFont = nullptr; + _splashTexture = nullptr; } void SplashScreen::OnShown() @@ -260,8 +249,8 @@ void SplashScreen::OnShown() void SplashScreen::OnDraw() { const float s = _dpiScale; - const float width = _width; - const float height = _height; + const float width = _size.X; + const float height = _size.Y; // Peek time const float time = static_cast((DateTime::NowUTC() - _startTime).GetTotalSeconds()); @@ -354,21 +343,13 @@ void SplashScreen::OnFontLoaded(Asset* asset) _subtitleFont = font->CreateFont(9 * s); } -void SplashScreen::OnTextureLoaded(Asset* asset) +void SplashScreen::OnSplashLoaded() { - ASSERT(asset && asset->IsLoaded()); - auto texture = (Texture*)asset; - - texture->OnLoaded.Unbind(this); - _splashTexture = texture; - - // Resize window to be larger if texture is being used. + // Resize window to be larger if texture is being used auto desktopSize = Platform::GetDesktopSize(); auto xSize = (desktopSize.X / (600.0f * 3.0f)) * 600.0f; auto ySize = (desktopSize.Y / (200.0f * 3.0f)) * 200.0f; - _window->SetClientSize(Float2(xSize, ySize)); - _width = _window->GetSize().X; - _height = _window->GetSize().Y; - _window->SetPosition((Platform::GetDesktopSize() - _window->GetSize()) / 2.0f); + _size = _window->GetSize(); + _window->SetPosition((desktopSize - _size) * 0.5f); } diff --git a/Source/Editor/Windows/SplashScreen.h b/Source/Editor/Windows/SplashScreen.h index c5b3d0e5a..6f8f17a7f 100644 --- a/Source/Editor/Windows/SplashScreen.h +++ b/Source/Editor/Windows/SplashScreen.h @@ -3,6 +3,7 @@ #pragma once #include "Engine/Content/Assets/Texture.h" +#include "Engine/Content/AssetReference.h" #include "Engine/Core/Types/DateTime.h" #include "Engine/Platform/Window.h" @@ -19,11 +20,12 @@ private: Window* _window = nullptr; Font* _titleFont = nullptr; Font* _subtitleFont = nullptr; - Texture* _splashTexture = nullptr; + AssetReference _splashTexture; String _title; DateTime _startTime; String _infoText; - float _dpiScale, _width, _height; + float _dpiScale; + Float2 _size; StringView _quote; public: @@ -80,5 +82,5 @@ private: void OnDraw(); bool HasLoadedFonts() const; void OnFontLoaded(Asset* asset); - void OnTextureLoaded(Asset* asset); + void OnSplashLoaded(); };