|
@@ -86,6 +86,46 @@ void register_dynamic_symbol(char *name, void *address) {
|
|
|
OS_IOS::dynamic_symbol_lookup_table[String(name)] = address;
|
|
|
}
|
|
|
|
|
|
+Rect2 fit_keep_aspect_centered(const Vector2 &p_container, const Vector2 &p_rect) {
|
|
|
+ real_t available_ratio = p_container.width / p_container.height;
|
|
|
+ real_t fit_ratio = p_rect.width / p_rect.height;
|
|
|
+ Rect2 result;
|
|
|
+ if (fit_ratio < available_ratio) {
|
|
|
+ // Fit height - we'll have horizontal gaps
|
|
|
+ result.size.height = p_container.height;
|
|
|
+ result.size.width = p_container.height * fit_ratio;
|
|
|
+ result.position.y = 0;
|
|
|
+ result.position.x = (p_container.width - result.size.width) * 0.5f;
|
|
|
+ } else {
|
|
|
+ // Fit width - we'll have vertical gaps
|
|
|
+ result.size.width = p_container.width;
|
|
|
+ result.size.height = p_container.width / fit_ratio;
|
|
|
+ result.position.x = 0;
|
|
|
+ result.position.y = (p_container.height - result.size.height) * 0.5f;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+Rect2 fit_keep_aspect_covered(const Vector2 &p_container, const Vector2 &p_rect) {
|
|
|
+ real_t available_ratio = p_container.width / p_container.height;
|
|
|
+ real_t fit_ratio = p_rect.width / p_rect.height;
|
|
|
+ Rect2 result;
|
|
|
+ if (fit_ratio < available_ratio) {
|
|
|
+ // Need to scale up to fit width, and crop height
|
|
|
+ result.size.width = p_container.width;
|
|
|
+ result.size.height = p_container.width / fit_ratio;
|
|
|
+ result.position.x = 0;
|
|
|
+ result.position.y = (p_container.height - result.size.height) * 0.5f;
|
|
|
+ } else {
|
|
|
+ // Need to scale up to fit height, and crop width
|
|
|
+ result.size.width = p_container.height * fit_ratio;
|
|
|
+ result.size.height = p_container.height;
|
|
|
+ result.position.x = (p_container.width - result.size.width) * 0.5f;
|
|
|
+ result.position.y = 0;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
OS_IOS *OS_IOS::get_singleton() {
|
|
|
return (OS_IOS *)OS::get_singleton();
|
|
|
}
|
|
@@ -660,4 +700,21 @@ void OS_IOS::on_exit_background() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+Rect2 OS_IOS::calculate_boot_screen_rect(const Size2 &p_window_size, const Size2 &p_imgrect_size) const {
|
|
|
+ String scalemodestr = GLOBAL_GET("ios/launch_screen_image_mode");
|
|
|
+
|
|
|
+ if (scalemodestr == "scaleAspectFit") {
|
|
|
+ return fit_keep_aspect_centered(p_window_size, p_imgrect_size);
|
|
|
+ } else if (scalemodestr == "scaleAspectFill") {
|
|
|
+ return fit_keep_aspect_covered(p_window_size, p_imgrect_size);
|
|
|
+ } else if (scalemodestr == "scaleToFill") {
|
|
|
+ return Rect2(Point2(), p_window_size);
|
|
|
+ } else if (scalemodestr == "center") {
|
|
|
+ return OS_Unix::calculate_boot_screen_rect(p_window_size, p_imgrect_size);
|
|
|
+ } else {
|
|
|
+ WARN_PRINT(vformat("Boot screen scale mode mismatch between iOS and Godot: %s not supported", scalemodestr));
|
|
|
+ return OS_Unix::calculate_boot_screen_rect(p_window_size, p_imgrect_size);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#endif // IOS_ENABLED
|