Skip to content

Commit

Permalink
Merge pull request #71838 from m4gr3d/fix_godot_editor_cropping_3x
Browse files Browse the repository at this point in the history
[3.x] Update the logic to calculate the screen scale on Android
  • Loading branch information
akien-mga committed Jan 23, 2023
2 parents 627d688 + 48aedb2 commit 5a7997c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public float getScaledDensity() {
} else {
selectedScaledDensity = 0.75f;
}
Log.d(TAG, "Selected scaled density: " + selectedScaledDensity);
return selectedScaledDensity;
}

Expand Down
19 changes: 16 additions & 3 deletions platform/android/os_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 5a7997c

Please sign in to comment.