1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Add new scaling modes for splash screen

Removes the `fullsize` option which is superseded by `stretch_mode`.

Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
Samuel Pedrajas
2021-10-25 19:27:12 +02:00
committed by Rémi Verschelde
parent 4979d9fc7b
commit fcc9f5ce39
13 changed files with 167 additions and 60 deletions

View File

@@ -159,7 +159,7 @@ void RendererCompositorRD::finalize() {
RD::get_singleton()->free(blit.sampler);
}
void RendererCompositorRD::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {
void RendererCompositorRD::set_boot_image(const Ref<Image> &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter) {
RD::get_singleton()->prepare_screen_for_drawing();
RID texture = storage->texture_allocate();
@@ -182,22 +182,56 @@ void RendererCompositorRD::set_boot_image(const Ref<Image> &p_image, const Color
Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height());
Rect2 screenrect;
if (p_scale) {
if (window_size.width > window_size.height) {
//scale horizontally
screenrect.size.y = window_size.height;
screenrect.size.x = imgrect.size.x * window_size.height / imgrect.size.y;
screenrect.position.x = (window_size.width - screenrect.size.x) / 2;
} else {
//scale vertically
switch (p_stretch_mode) {
case RenderingServer::SPLASH_STRETCH_MODE_DISABLED: {
screenrect = imgrect;
screenrect.position += ((window_size - screenrect.size) / 2.0).floor();
} break;
case RenderingServer::SPLASH_STRETCH_MODE_KEEP: {
if (window_size.width > window_size.height) {
// Scale horizontally.
screenrect.size.y = window_size.height;
screenrect.size.x = imgrect.size.x * window_size.height / imgrect.size.y;
screenrect.position.x = (window_size.width - screenrect.size.x) / 2;
} else {
// Scale vertically.
screenrect.size.x = window_size.width;
screenrect.size.y = imgrect.size.y * window_size.width / imgrect.size.x;
screenrect.position.y = (window_size.height - screenrect.size.y) / 2;
}
} break;
case RenderingServer::SPLASH_STRETCH_MODE_KEEP_WIDTH: {
// Scale vertically.
screenrect.size.x = window_size.width;
screenrect.size.y = imgrect.size.y * window_size.width / imgrect.size.x;
screenrect.position.y = (window_size.height - screenrect.size.y) / 2;
}
} else {
screenrect = imgrect;
screenrect.position += ((window_size - screenrect.size) / 2.0).floor();
} break;
case RenderingServer::SPLASH_STRETCH_MODE_KEEP_HEIGHT: {
// Scale horizontally.
screenrect.size.y = window_size.height;
screenrect.size.x = imgrect.size.x * window_size.height / imgrect.size.y;
screenrect.position.x = (window_size.width - screenrect.size.x) / 2;
} break;
case RenderingServer::SPLASH_STRETCH_MODE_COVER: {
double window_aspect = (double)window_size.width / window_size.height;
double img_aspect = imgrect.size.x / imgrect.size.y;
if (window_aspect > img_aspect) {
// Scale vertically.
screenrect.size.x = window_size.width;
screenrect.size.y = imgrect.size.y * window_size.width / imgrect.size.x;
screenrect.position.y = (window_size.height - screenrect.size.y) / 2;
} else {
// Scale horizontally.
screenrect.size.y = window_size.height;
screenrect.size.x = imgrect.size.x * window_size.height / imgrect.size.y;
screenrect.position.x = (window_size.width - screenrect.size.x) / 2;
}
} break;
case RenderingServer::SPLASH_STRETCH_MODE_EXPAND: {
screenrect.size.x = window_size.width;
screenrect.size.y = window_size.height;
} break;
}
screenrect.position /= window_size;