Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to add splash image to splash screen. #3119

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 68 additions & 5 deletions Source/Editor/Windows/SplashScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,27 @@ void SplashScreen::Show()
font->OnLoaded.Bind<SplashScreen, &SplashScreen::OnFontLoaded>(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<Texture>(*splashImagePath);
if (texture == nullptr)
{
LOG(Info, "Cannot load splash Texture at {0}", splashImagePath);
}
else
{
if (texture->IsLoaded())
OnTextureLoaded(texture);
else
texture->OnLoaded.Bind<SplashScreen, &SplashScreen::OnTextureLoaded>(this);
}

_window->Show();
}

Expand Down Expand Up @@ -246,8 +267,19 @@ void SplashScreen::OnDraw()
const float time = static_cast<float>((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 + 20 * s;
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
Expand Down Expand Up @@ -276,15 +308,27 @@ void SplashScreen::OnDraw()
for (int32 i = 0; i < 4 - static_cast<int32>(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 + 4 * 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
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);
Expand All @@ -307,3 +351,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<SplashScreen, &SplashScreen::OnTextureLoaded>(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);
}
3 changes: 3 additions & 0 deletions Source/Editor/Windows/SplashScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#pragma once

#include "Engine/Content/Assets/Texture.h"
#include "Engine/Core/Types/DateTime.h"
#include "Engine/Platform/Window.h"

Expand All @@ -18,6 +19,7 @@ class SplashScreen
Window* _window = nullptr;
Font* _titleFont = nullptr;
Font* _subtitleFont = nullptr;
Texture* _splashTexture = nullptr;
String _title;
DateTime _startTime;
String _infoText;
Expand Down Expand Up @@ -78,4 +80,5 @@ class SplashScreen
void OnDraw();
bool HasLoadedFonts() const;
void OnFontLoaded(Asset* asset);
void OnTextureLoaded(Asset* asset);
};