Merge branch 'Tryibion-splash-image'
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include "Engine/Render2D/Font.h"
|
#include "Engine/Render2D/Font.h"
|
||||||
#include "Engine/Render2D/TextLayoutOptions.h"
|
#include "Engine/Render2D/TextLayoutOptions.h"
|
||||||
#include "Engine/Render2D/Render2D.h"
|
#include "Engine/Render2D/Render2D.h"
|
||||||
|
#include "Engine/Platform/FileSystem.h"
|
||||||
#include "Engine/Content/Content.h"
|
#include "Engine/Content/Content.h"
|
||||||
#include "FlaxEngine.Gen.h"
|
#include "FlaxEngine.Gen.h"
|
||||||
|
|
||||||
@@ -188,8 +189,7 @@ void SplashScreen::Show()
|
|||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
_dpiScale = dpiScale;
|
_dpiScale = dpiScale;
|
||||||
_width = settings.Size.X;
|
_size = settings.Size;
|
||||||
_height = settings.Size.Y;
|
|
||||||
_startTime = DateTime::NowUTC();
|
_startTime = DateTime::NowUTC();
|
||||||
auto str = Globals::ProjectFolder;
|
auto str = Globals::ProjectFolder;
|
||||||
#if PLATFORM_WIN32
|
#if PLATFORM_WIN32
|
||||||
@@ -214,6 +214,12 @@ void SplashScreen::Show()
|
|||||||
font->OnLoaded.Bind<SplashScreen, &SplashScreen::OnFontLoaded>(this);
|
font->OnLoaded.Bind<SplashScreen, &SplashScreen::OnFontLoaded>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load custom image
|
||||||
|
_splashTexture.Loaded.Bind<SplashScreen, &SplashScreen::OnSplashLoaded>(this);
|
||||||
|
String splashImagePath = Globals::ProjectContentFolder / TEXT("SplashImage.flax");
|
||||||
|
if (FileSystem::FileExists(splashImagePath))
|
||||||
|
_splashTexture = Content::LoadAsync<Texture>(splashImagePath);
|
||||||
|
|
||||||
_window->Show();
|
_window->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,6 +233,10 @@ void SplashScreen::Close()
|
|||||||
// Close window
|
// Close window
|
||||||
_window->Close(ClosingReason::CloseEvent);
|
_window->Close(ClosingReason::CloseEvent);
|
||||||
_window = nullptr;
|
_window = nullptr;
|
||||||
|
|
||||||
|
_titleFont = nullptr;
|
||||||
|
_subtitleFont = nullptr;
|
||||||
|
_splashTexture = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplashScreen::OnShown()
|
void SplashScreen::OnShown()
|
||||||
@@ -239,16 +249,29 @@ void SplashScreen::OnShown()
|
|||||||
void SplashScreen::OnDraw()
|
void SplashScreen::OnDraw()
|
||||||
{
|
{
|
||||||
const float s = _dpiScale;
|
const float s = _dpiScale;
|
||||||
const float width = _width;
|
const float width = _size.X;
|
||||||
const float height = _height;
|
const float height = _size.Y;
|
||||||
|
|
||||||
// Peek time
|
// Peek time
|
||||||
const float time = static_cast<float>((DateTime::NowUTC() - _startTime).GetTotalSeconds());
|
const float time = static_cast<float>((DateTime::NowUTC() - _startTime).GetTotalSeconds());
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
const float lightBarHeight = 112 * s;
|
float lightBarHeight = 112 * s;
|
||||||
Render2D::FillRectangle(Rectangle(0, 0, width, 150 * s), Color::FromRGB(0x1C1C1C));
|
if (_splashTexture != nullptr)
|
||||||
Render2D::FillRectangle(Rectangle(0, lightBarHeight, width, height), Color::FromRGB(0x0C0C0C));
|
{
|
||||||
|
if (_splashTexture->IsLoaded())
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
// Animated border
|
// Animated border
|
||||||
const float anim = Math::Sin(time * 4.0f) * 0.5f + 0.5f;
|
const float anim = Math::Sin(time * 4.0f) * 0.5f + 0.5f;
|
||||||
@@ -276,15 +299,27 @@ void SplashScreen::OnDraw()
|
|||||||
for (int32 i = 0; i < 4 - static_cast<int32>(time * 2.0f) % 4; i++)
|
for (int32 i = 0; i < 4 - static_cast<int32>(time * 2.0f) % 4; i++)
|
||||||
subtitle += TEXT(' ');
|
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.Scale = 1.0f;
|
||||||
layout.HorizontalAlignment = TextAlignment::Far;
|
layout.HorizontalAlignment = TextAlignment::Far;
|
||||||
layout.VerticalAlignment = TextAlignment::Far;
|
|
||||||
Render2D::DrawText(_subtitleFont, subtitle, Color::FromRGB(0x8C8C8C), layout);
|
Render2D::DrawText(_subtitleFont, subtitle, Color::FromRGB(0x8C8C8C), layout);
|
||||||
|
|
||||||
// Additional info
|
// Additional info
|
||||||
const float infoMargin = 6 * s;
|
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.HorizontalAlignment = TextAlignment::Near;
|
||||||
layout.VerticalAlignment = TextAlignment::Center;
|
layout.VerticalAlignment = TextAlignment::Center;
|
||||||
Render2D::DrawText(_subtitleFont, _infoText, Color::FromRGB(0xFFFFFF) * 0.9f, layout);
|
Render2D::DrawText(_subtitleFont, _infoText, Color::FromRGB(0xFFFFFF) * 0.9f, layout);
|
||||||
@@ -307,3 +342,14 @@ void SplashScreen::OnFontLoaded(Asset* asset)
|
|||||||
_titleFont = font->CreateFont(35 * s);
|
_titleFont = font->CreateFont(35 * s);
|
||||||
_subtitleFont = font->CreateFont(9 * s);
|
_subtitleFont = font->CreateFont(9 * s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SplashScreen::OnSplashLoaded()
|
||||||
|
{
|
||||||
|
// 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));
|
||||||
|
_size = _window->GetSize();
|
||||||
|
_window->SetPosition((desktopSize - _size) * 0.5f);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Engine/Content/Assets/Texture.h"
|
||||||
|
#include "Engine/Content/AssetReference.h"
|
||||||
#include "Engine/Core/Types/DateTime.h"
|
#include "Engine/Core/Types/DateTime.h"
|
||||||
#include "Engine/Platform/Window.h"
|
#include "Engine/Platform/Window.h"
|
||||||
|
|
||||||
@@ -18,10 +20,12 @@ private:
|
|||||||
Window* _window = nullptr;
|
Window* _window = nullptr;
|
||||||
Font* _titleFont = nullptr;
|
Font* _titleFont = nullptr;
|
||||||
Font* _subtitleFont = nullptr;
|
Font* _subtitleFont = nullptr;
|
||||||
|
AssetReference<Texture> _splashTexture;
|
||||||
String _title;
|
String _title;
|
||||||
DateTime _startTime;
|
DateTime _startTime;
|
||||||
String _infoText;
|
String _infoText;
|
||||||
float _dpiScale, _width, _height;
|
float _dpiScale;
|
||||||
|
Float2 _size;
|
||||||
StringView _quote;
|
StringView _quote;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -78,4 +82,5 @@ private:
|
|||||||
void OnDraw();
|
void OnDraw();
|
||||||
bool HasLoadedFonts() const;
|
bool HasLoadedFonts() const;
|
||||||
void OnFontLoaded(Asset* asset);
|
void OnFontLoaded(Asset* asset);
|
||||||
|
void OnSplashLoaded();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user