From dd2fc60abc651e0b8c736fc9133c449eefbbb7cd Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sun, 9 May 2021 23:33:45 +0200 Subject: [PATCH] Handle portrait mode monitors in the automatic editor scale detection Using the smallest dimension of the width and height makes it possible to support both landscape and portrait monitors. (cherry picked from commit 728fa3ff71361f527e0bf18c46cf9152ec5a3d6d) EditorSettings: Factor code to compute auto display scale Also fixes typo introduced in https://github.com/godotengine/godot/pull/48597/files#r652636544. (cherry picked from commit f862f9a056d9d6eca392a04011838bdae660ab36) --- editor/editor_node.cpp | 30 +++---------------------- editor/editor_settings.cpp | 46 ++++++++++++++++++++------------------ editor/editor_settings.h | 1 + editor/project_manager.cpp | 30 +++---------------------- 4 files changed, 31 insertions(+), 76 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 43958690306..9980ae912e4 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5701,34 +5701,10 @@ EditorNode::EditorNode() { int display_scale = EditorSettings::get_singleton()->get("interface/editor/display_scale"); switch (display_scale) { - case 0: { + case 0: // Try applying a suitable display scale automatically. - // The code below is adapted in `editor/editor_settings.cpp` and `editor/project_manager.cpp`. - // Make sure to update those when modifying the code below. -#ifdef OSX_ENABLED - editor_set_scale(OS::get_singleton()->get_screen_max_scale()); -#else - const int screen = OS::get_singleton()->get_current_screen(); - float scale; - if (OS::get_singleton()->get_screen_dpi(screen) >= 192 && OS::get_singleton()->get_screen_size(screen).y >= 1400) { - // hiDPI display. - scale = 2.0; - } else if (OS::get_singleton()->get_screen_size(screen).y >= 1700) { - // Likely a hiDPI display, but we aren't certain due to the returned DPI. - // Use an intermediate scale to handle this situation. - scale = 1.5; - } else if (OS::get_singleton()->get_screen_size(screen).y <= 800) { - // Small loDPI display. Use a smaller display scale so that editor elements fit more easily. - // Icons won't look great, but this is better than having editor elements overflow from its window. - scale = 0.75; - } else { - scale = 1.0; - } - - editor_set_scale(scale); -#endif - } break; - + editor_set_scale(EditorSettings::get_singleton()->get_auto_display_scale()); + break; case 1: editor_set_scale(0.75); break; diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index d6b800ab6ba..d9471ed1ada 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -309,28 +309,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { // Editor _initial_set("interface/editor/display_scale", 0); // Display what the Auto display scale setting effectively corresponds to. - // The code below is adapted in `editor/editor_node.cpp` and `editor/project_manager.cpp`. - // Make sure to update those when modifying the code below. -#ifdef OSX_ENABLED - float scale = OS::get_singleton()->get_screen_max_scale(); -#else - const int screen = OS::get_singleton()->get_current_screen(); - float scale; - if (OS::get_singleton()->get_screen_dpi(screen) >= 192 && OS::get_singleton()->get_screen_size(screen).y >= 1400) { - // hiDPI display. - scale = 2.0; - } else if (OS::get_singleton()->get_screen_size(screen).y >= 1700) { - // Likely a hiDPI display, but we aren't certain due to the returned DPI. - // Use an intermediate scale to handle this situation. - scale = 1.5; - } else if (OS::get_singleton()->get_screen_size(screen).y <= 800) { - // Small loDPI display. Use a smaller display scale so that editor elements fit more easily. - // Icons won't look great, but this is better than having editor elements overflow from its window. - scale = 0.75; - } else { - scale = 1.0; - } -#endif + float scale = get_auto_display_scale(); hints["interface/editor/display_scale"] = PropertyInfo(Variant::INT, "interface/editor/display_scale", PROPERTY_HINT_ENUM, vformat("Auto (%d%%),75%%,100%%,125%%,150%%,175%%,200%%,Custom", Math::round(scale * 100)), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); _initial_set("interface/editor/custom_display_scale", 1.0f); hints["interface/editor/custom_display_scale"] = PropertyInfo(Variant::REAL, "interface/editor/custom_display_scale", PROPERTY_HINT_RANGE, "0.5,3,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); @@ -1482,6 +1461,29 @@ String EditorSettings::get_editor_layouts_config() const { return get_settings_dir().plus_file("editor_layouts.cfg"); } +float EditorSettings::get_auto_display_scale() const { +#ifdef OSX_ENABLED + return OS::get_singleton()->get_screen_max_scale(); +#else + const int screen = OS::get_singleton()->get_current_screen(); + // Use the smallest dimension to use a correct display scale on portait displays. + const int smallest_dimension = MIN(OS::get_singleton()->get_screen_size(screen).x, OS::get_singleton()->get_screen_size(screen).y); + if (OS::get_singleton()->get_screen_dpi(screen) >= 192 && smallest_dimension >= 1400) { + // hiDPI display. + return 2.0; + } else if (smallest_dimension >= 1700) { + // Likely a hiDPI display, but we aren't certain due to the returned DPI. + // Use an intermediate scale to handle this situation. + return 1.5; + } else if (smallest_dimension <= 800) { + // Small loDPI display. Use a smaller display scale so that editor elements fit more easily. + // Icons won't look great, but this is better than having editor elements overflow from its window. + return 0.75; + } + return 1.0; +#endif +} + // Shortcuts void EditorSettings::add_shortcut(const String &p_name, Ref &p_shortcut) { diff --git a/editor/editor_settings.h b/editor/editor_settings.h index 0eb55e23500..fc74146aa57 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -189,6 +189,7 @@ public: Vector get_script_templates(const String &p_extension, const String &p_custom_path = String()); String get_editor_layouts_config() const; + float get_auto_display_scale() const; void add_shortcut(const String &p_name, Ref &p_shortcut); bool is_shortcut(const String &p_name, const Ref &p_event) const; diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 1ef5eb588f8..69337993122 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -2363,34 +2363,10 @@ ProjectManager::ProjectManager() { float custom_display_scale = EditorSettings::get_singleton()->get("interface/editor/custom_display_scale"); switch (display_scale) { - case 0: { + case 0: // Try applying a suitable display scale automatically. - // The code below is adapted in `editor/editor_settings.cpp` and `editor/editor_node.cpp`. - // Make sure to update those when modifying the code below. -#ifdef OSX_ENABLED - editor_set_scale(OS::get_singleton()->get_screen_max_scale()); -#else - const int screen = OS::get_singleton()->get_current_screen(); - float scale; - if (OS::get_singleton()->get_screen_dpi(screen) >= 192 && OS::get_singleton()->get_screen_size(screen).y >= 1400) { - // hiDPI display. - scale = 2.0; - } else if (OS::get_singleton()->get_screen_size(screen).y >= 1700) { - // Likely a hiDPI display, but we aren't certain due to the returned DPI. - // Use an intermediate scale to handle this situation. - scale = 1.5; - } else if (OS::get_singleton()->get_screen_size(screen).y <= 800) { - // Small loDPI display. Use a smaller display scale so that editor elements fit more easily. - // Icons won't look great, but this is better than having editor elements overflow from its window. - scale = 0.75; - } else { - scale = 1.0; - } - - editor_set_scale(scale); -#endif - } break; - + editor_set_scale(EditorSettings::get_singleton()->get_auto_display_scale()); + break; case 1: editor_set_scale(0.75); break;