Merge pull request #71838 from m4gr3d/fix_godot_editor_cropping_3x

[3.x] Update the logic to calculate the screen scale on Android
This commit is contained in:
Rémi Verschelde 2023-01-23 22:28:32 +01:00
commit 5a7997c794
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 16 additions and 4 deletions

View File

@ -150,7 +150,6 @@ public class GodotIO {
} else {
selectedScaledDensity = 0.75f;
}
Log.d(TAG, "Selected scaled density: " + selectedScaledDensity);
return selectedScaledDensity;
}

View File

@ -55,6 +55,8 @@
#include "tts_android.h"
const char *OS_Android::ANDROID_EXEC_PATH = "apk";
static const int DEFAULT_WINDOW_WIDTH = 800;
static const int DEFAULT_WINDOW_HEIGHT = 600;
String _remove_symlink(const String &dir) {
// Workaround for Android 6.0+ using a symlink.
@ -530,7 +532,18 @@ int OS_Android::get_screen_dpi(int p_screen) const {
}
float OS_Android::get_screen_scale(int p_screen) const {
return godot_io_java->get_scaled_density();
float screen_scale = godot_io_java->get_scaled_density();
// Update the scale to avoid cropping.
Vector2 screen_size = get_window_size();
if (screen_size != Vector2()) {
float width_scale = screen_size.width / (float)DEFAULT_WINDOW_WIDTH;
float height_scale = screen_size.height / (float)DEFAULT_WINDOW_HEIGHT;
screen_scale = MIN(screen_scale, MIN(width_scale, height_scale));
}
print_line("Selected screen scale: " + rtos(screen_scale));
return screen_scale;
}
float OS_Android::get_screen_max_scale() const {
@ -679,8 +692,8 @@ bool OS_Android::_check_internal_feature_support(const String &p_feature) {
OS_Android::OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_godot_io_java, bool p_use_apk_expansion) {
use_apk_expansion = p_use_apk_expansion;
default_videomode.width = 800;
default_videomode.height = 600;
default_videomode.width = DEFAULT_WINDOW_WIDTH;
default_videomode.height = DEFAULT_WINDOW_HEIGHT;
default_videomode.fullscreen = true;
default_videomode.resizable = false;