Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Update the logic to calculate the screen scale on Android #71838

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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