Update the editor display scale based on the device's scaled density
This commit is contained in:
parent
10d9e47949
commit
8eabf77f54
|
@ -1365,7 +1365,7 @@ String EditorSettings::get_editor_layouts_config() const {
|
|||
}
|
||||
|
||||
float EditorSettings::get_auto_display_scale() const {
|
||||
#ifdef OSX_ENABLED
|
||||
#if defined(OSX_ENABLED) || defined(ANDROID_ENABLED)
|
||||
return DisplayServer::get_singleton()->screen_get_max_scale();
|
||||
#else
|
||||
const int screen = DisplayServer::get_singleton()->window_get_current_screen();
|
||||
|
|
|
@ -161,6 +161,13 @@ int DisplayServerAndroid::screen_get_dpi(int p_screen) const {
|
|||
return godot_io_java->get_screen_dpi();
|
||||
}
|
||||
|
||||
float DisplayServerAndroid::screen_get_scale(int p_screen) const {
|
||||
GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java();
|
||||
ERR_FAIL_COND_V(!godot_io_java, 1.0f);
|
||||
|
||||
return godot_io_java->get_scaled_density();
|
||||
}
|
||||
|
||||
float DisplayServerAndroid::screen_get_refresh_rate(int p_screen) const {
|
||||
GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java();
|
||||
if (!godot_io_java) {
|
||||
|
|
|
@ -106,6 +106,7 @@ public:
|
|||
virtual Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||
virtual Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||
virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||
virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||
virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||
virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||
|
||||
|
|
|
@ -107,4 +107,18 @@ public class GodotEditor extends FullScreenGodotApp {
|
|||
Intent newInstance = new Intent(this, targetClass).putExtra(COMMAND_LINE_PARAMS, args);
|
||||
startActivity(newInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRequestedOrientation(int requestedOrientation) {
|
||||
if (!overrideOrientationRequest()) {
|
||||
super.setRequestedOrientation(requestedOrientation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Godot Android Editor sets its own orientation via its AndroidManifest
|
||||
*/
|
||||
protected boolean overrideOrientationRequest() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,4 +34,7 @@ package org.godotengine.editor;
|
|||
* Drives the 'run project' window of the Godot Editor.
|
||||
*/
|
||||
public class GodotGame extends GodotEditor {
|
||||
protected boolean overrideOrientationRequest() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -222,10 +222,14 @@ public class GodotIO {
|
|||
}
|
||||
|
||||
public int getScreenDPI() {
|
||||
DisplayMetrics metrics = activity.getApplicationContext().getResources().getDisplayMetrics();
|
||||
DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
|
||||
return (int)(metrics.density * 160f);
|
||||
}
|
||||
|
||||
public float getScaledDensity() {
|
||||
return activity.getResources().getDisplayMetrics().scaledDensity;
|
||||
}
|
||||
|
||||
public double getScreenRefreshRate(double fallback) {
|
||||
Display display = activity.getWindowManager().getDefaultDisplay();
|
||||
if (display != null) {
|
||||
|
|
|
@ -54,6 +54,7 @@ GodotIOJavaWrapper::GodotIOJavaWrapper(JNIEnv *p_env, jobject p_godot_io_instanc
|
|||
_get_locale = p_env->GetMethodID(cls, "getLocale", "()Ljava/lang/String;");
|
||||
_get_model = p_env->GetMethodID(cls, "getModel", "()Ljava/lang/String;");
|
||||
_get_screen_DPI = p_env->GetMethodID(cls, "getScreenDPI", "()I");
|
||||
_get_scaled_density = p_env->GetMethodID(cls, "getScaledDensity", "()F");
|
||||
_get_screen_refresh_rate = p_env->GetMethodID(cls, "getScreenRefreshRate", "(D)D");
|
||||
_screen_get_usable_rect = p_env->GetMethodID(cls, "screenGetUsableRect", "()[I"),
|
||||
_get_unique_id = p_env->GetMethodID(cls, "getUniqueID", "()Ljava/lang/String;");
|
||||
|
@ -138,6 +139,16 @@ int GodotIOJavaWrapper::get_screen_dpi() {
|
|||
}
|
||||
}
|
||||
|
||||
float GodotIOJavaWrapper::get_scaled_density() {
|
||||
if (_get_scaled_density) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, 1.0f);
|
||||
return env->CallFloatMethod(godot_io_instance, _get_scaled_density);
|
||||
} else {
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
float GodotIOJavaWrapper::get_screen_refresh_rate(float fallback) {
|
||||
if (_get_screen_refresh_rate) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
|
|
|
@ -51,6 +51,7 @@ private:
|
|||
jmethodID _get_locale = 0;
|
||||
jmethodID _get_model = 0;
|
||||
jmethodID _get_screen_DPI = 0;
|
||||
jmethodID _get_scaled_density = 0;
|
||||
jmethodID _get_screen_refresh_rate = 0;
|
||||
jmethodID _screen_get_usable_rect = 0;
|
||||
jmethodID _get_unique_id = 0;
|
||||
|
@ -72,6 +73,7 @@ public:
|
|||
String get_locale();
|
||||
String get_model();
|
||||
int get_screen_dpi();
|
||||
float get_scaled_density();
|
||||
float get_screen_refresh_rate(float fallback);
|
||||
void screen_get_usable_rect(int (&p_rect_xywh)[4]);
|
||||
String get_unique_id();
|
||||
|
|
Loading…
Reference in New Issue