added loading screen background image scaling modes
This commit is contained in:
@@ -84,26 +84,52 @@ namespace wi
|
||||
const float canvas_aspect = GetLogicalWidth() / GetLogicalHeight();
|
||||
const float image_aspect = float(desc.width) / float(desc.height);
|
||||
|
||||
if (canvas_aspect > image_aspect)
|
||||
switch (background_mode)
|
||||
{
|
||||
// display aspect is wider than image:
|
||||
fx.siz.x = GetLogicalWidth() / canvas_aspect * image_aspect;
|
||||
fx.siz.y = GetLogicalHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
// image aspect is wider or equal to display
|
||||
fx.siz.x = GetLogicalWidth();
|
||||
fx.siz.y = GetLogicalHeight() * canvas_aspect / image_aspect;
|
||||
default:
|
||||
case wi::LoadingScreen::BackgroundMode::Fill:
|
||||
if (canvas_aspect > image_aspect)
|
||||
{
|
||||
// display aspect is wider than image:
|
||||
fx.siz.x = GetLogicalWidth();
|
||||
fx.siz.y = GetLogicalHeight() / image_aspect * canvas_aspect;
|
||||
}
|
||||
else
|
||||
{
|
||||
// image aspect is wider or equal to display
|
||||
fx.siz.x = GetLogicalWidth() / canvas_aspect * image_aspect;
|
||||
fx.siz.y = GetLogicalHeight();
|
||||
}
|
||||
fx.pos = XMFLOAT3(GetLogicalWidth() * 0.5f, GetLogicalHeight() * 0.5f, 0);
|
||||
fx.pivot = XMFLOAT2(0.5f, 0.5f);
|
||||
break;
|
||||
case wi::LoadingScreen::BackgroundMode::Fit:
|
||||
if (canvas_aspect > image_aspect)
|
||||
{
|
||||
// display aspect is wider than image:
|
||||
fx.siz.x = GetLogicalWidth() / canvas_aspect * image_aspect;
|
||||
fx.siz.y = GetLogicalHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
// image aspect is wider or equal to display
|
||||
fx.siz.x = GetLogicalWidth();
|
||||
fx.siz.y = GetLogicalHeight() * canvas_aspect / image_aspect;
|
||||
}
|
||||
fx.pos = XMFLOAT3(GetLogicalWidth() * 0.5f, GetLogicalHeight() * 0.5f, 0);
|
||||
fx.pivot = XMFLOAT2(0.5f, 0.5f);
|
||||
break;
|
||||
case wi::LoadingScreen::BackgroundMode::Stretch:
|
||||
fx.enableFullScreen();
|
||||
break;
|
||||
}
|
||||
|
||||
fx.pos = XMFLOAT3(GetLogicalWidth() * 0.5f, GetLogicalHeight() * 0.5f, 0);
|
||||
fx.pivot = XMFLOAT2(0.5f, 0.5f);
|
||||
fx.blendFlag = wi::enums::BLENDMODE_ALPHA;
|
||||
if (colorspace != ColorSpace::SRGB)
|
||||
{
|
||||
fx.enableLinearOutputMapping(hdr_scaling);
|
||||
}
|
||||
|
||||
wi::image::Draw(&tex, fx, cmd);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,13 @@ namespace wi
|
||||
public:
|
||||
wi::Resource backgroundTexture;
|
||||
|
||||
enum class BackgroundMode
|
||||
{
|
||||
Fill, // fill the whole screen, will cut off parts of the image if aspects don't match
|
||||
Fit, // fit the image completely inside the screen, will result in black bars on screen if aspects don't match
|
||||
Stretch // fill the whole screen, and stretch the image if needed
|
||||
} background_mode = BackgroundMode::Fill;
|
||||
|
||||
//Add a loading task which should be executed
|
||||
void addLoadingFunction(std::function<void(wi::jobsystem::JobArgs)> loadingFunction);
|
||||
//Helper for loading a whole renderable component
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace wi::lua
|
||||
lunamethod(LoadingScreen_BindLua, GetProgress),
|
||||
lunamethod(LoadingScreen_BindLua, SetBackgroundTexture),
|
||||
lunamethod(LoadingScreen_BindLua, GetBackgroundTexture),
|
||||
lunamethod(LoadingScreen_BindLua, SetBackgroundMode),
|
||||
lunamethod(LoadingScreen_BindLua, GetBackgroundMode),
|
||||
{ NULL, NULL }
|
||||
};
|
||||
Luna<LoadingScreen_BindLua>::PropertyType LoadingScreen_BindLua::properties[] = {
|
||||
@@ -271,6 +273,34 @@ namespace wi::lua
|
||||
Luna<Texture_BindLua>::push(L, loading->backgroundTexture);
|
||||
return 1;
|
||||
}
|
||||
int LoadingScreen_BindLua::SetBackgroundMode(lua_State* L)
|
||||
{
|
||||
LoadingScreen* loading = dynamic_cast<LoadingScreen*>(component);
|
||||
if (loading == nullptr)
|
||||
{
|
||||
wi::lua::SError(L, "SetBackgroundMode(int mode): loading screen is not valid!");
|
||||
return 0;
|
||||
}
|
||||
int argc = wi::lua::SGetArgCount(L);
|
||||
if (argc < 1)
|
||||
{
|
||||
wi::lua::SError(L, "SetBackgroundMode(int mode): not enough arguments!");
|
||||
return 0;
|
||||
}
|
||||
loading->background_mode = (LoadingScreen::BackgroundMode)wi::lua::SGetInt(L, 1);
|
||||
return 0;
|
||||
}
|
||||
int LoadingScreen_BindLua::GetBackgroundMode(lua_State* L)
|
||||
{
|
||||
LoadingScreen* loading = dynamic_cast<LoadingScreen*>(component);
|
||||
if (loading == nullptr)
|
||||
{
|
||||
wi::lua::SError(L, "GetBackgroundMode(): loading screen is not valid!");
|
||||
return 0;
|
||||
}
|
||||
wi::lua::SSetInt(L, (int)loading->background_mode);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void LoadingScreen_BindLua::Bind()
|
||||
{
|
||||
@@ -279,6 +309,14 @@ namespace wi::lua
|
||||
{
|
||||
initialized = true;
|
||||
Luna<LoadingScreen_BindLua>::Register(wi::lua::GetLuaState());
|
||||
|
||||
wi::lua::RunText(R"(
|
||||
BackgroundMode = {
|
||||
Fill = 0,
|
||||
Fit = 1,
|
||||
Stretch = 2
|
||||
}
|
||||
)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace wi::lua
|
||||
int GetProgress(lua_State* L);
|
||||
int SetBackgroundTexture(lua_State* L);
|
||||
int GetBackgroundTexture(lua_State* L);
|
||||
int SetBackgroundMode(lua_State* L);
|
||||
int GetBackgroundMode(lua_State* L);
|
||||
|
||||
static void Bind();
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace wi::version
|
||||
// minor features, major updates, breaking compatibility changes
|
||||
const int minor = 71;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 462;
|
||||
const int revision = 463;
|
||||
|
||||
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user