EditorSettings: Factor code to compute auto display scale
Also fixes typo introduced in https://github.com/godotengine/godot/pull/48597/files#r652636544.
This commit is contained in:
parent
badad53438
commit
f862f9a056
@ -5689,36 +5689,10 @@ EditorNode::EditorNode() {
|
|||||||
int display_scale = EditorSettings::get_singleton()->get("interface/editor/display_scale");
|
int display_scale = EditorSettings::get_singleton()->get("interface/editor/display_scale");
|
||||||
|
|
||||||
switch (display_scale) {
|
switch (display_scale) {
|
||||||
case 0: {
|
case 0:
|
||||||
// Try applying a suitable display scale automatically.
|
// Try applying a suitable display scale automatically.
|
||||||
// The code below is adapted in `editor/editor_settings.cpp` and `editor/project_manager.cpp`.
|
editor_set_scale(EditorSettings::get_singleton()->get_auto_display_scale());
|
||||||
// Make sure to update those when modifying the code below.
|
break;
|
||||||
#ifdef OSX_ENABLED
|
|
||||||
editor_set_scale(DisplayServer::get_singleton()->screen_get_max_scale());
|
|
||||||
#else
|
|
||||||
const int screen = DisplayServer::get_singleton()->window_get_current_screen();
|
|
||||||
// Use the smallest dimension to use a correct display scale on portait displays.
|
|
||||||
const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y);
|
|
||||||
float scale;
|
|
||||||
if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) {
|
|
||||||
// hiDPI display.
|
|
||||||
scale = 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.
|
|
||||||
scale = 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.
|
|
||||||
scale = 0.75;
|
|
||||||
} else {
|
|
||||||
scale = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
editor_set_scale(scale);
|
|
||||||
#endif
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
editor_set_scale(0.75);
|
editor_set_scale(0.75);
|
||||||
break;
|
break;
|
||||||
|
@ -373,30 +373,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
|
|||||||
// Editor
|
// Editor
|
||||||
_initial_set("interface/editor/display_scale", 0);
|
_initial_set("interface/editor/display_scale", 0);
|
||||||
// Display what the Auto display scale setting effectively corresponds to.
|
// 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`.
|
float scale = get_auto_display_scale();
|
||||||
// Make sure to update those when modifying the code below.
|
|
||||||
#ifdef OSX_ENABLED
|
|
||||||
float scale = DisplayServer::get_singleton()->screen_get_max_scale();
|
|
||||||
#else
|
|
||||||
const int screen = DisplayServer::get_singleton()->window_get_current_screen();
|
|
||||||
// Use the smallest dimension to use a correct display scale on portait displays.
|
|
||||||
const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y);
|
|
||||||
float scale;
|
|
||||||
if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) {
|
|
||||||
// hiDPI display.
|
|
||||||
scale = 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.
|
|
||||||
scale = 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.
|
|
||||||
scale = 0.75;
|
|
||||||
} else {
|
|
||||||
scale = 1.0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
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);
|
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);
|
_initial_set("interface/editor/custom_display_scale", 1.0f);
|
||||||
hints["interface/editor/custom_display_scale"] = PropertyInfo(Variant::FLOAT, "interface/editor/custom_display_scale", PROPERTY_HINT_RANGE, "0.5,3,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
|
hints["interface/editor/custom_display_scale"] = PropertyInfo(Variant::FLOAT, "interface/editor/custom_display_scale", PROPERTY_HINT_RANGE, "0.5,3,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
|
||||||
@ -1447,6 +1424,29 @@ String EditorSettings::get_editor_layouts_config() const {
|
|||||||
return EditorPaths::get_singleton()->get_config_dir().plus_file("editor_layouts.cfg");
|
return EditorPaths::get_singleton()->get_config_dir().plus_file("editor_layouts.cfg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float EditorSettings::get_auto_display_scale() const {
|
||||||
|
#ifdef OSX_ENABLED
|
||||||
|
return DisplayServer::get_singleton()->screen_get_max_scale();
|
||||||
|
#else
|
||||||
|
const int screen = DisplayServer::get_singleton()->window_get_current_screen();
|
||||||
|
// Use the smallest dimension to use a correct display scale on portait displays.
|
||||||
|
const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y);
|
||||||
|
if (DisplayServer::get_singleton()->screen_get_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
|
// Shortcuts
|
||||||
|
|
||||||
void EditorSettings::add_shortcut(const String &p_name, Ref<Shortcut> &p_shortcut) {
|
void EditorSettings::add_shortcut(const String &p_name, Ref<Shortcut> &p_shortcut) {
|
||||||
|
@ -174,6 +174,7 @@ public:
|
|||||||
|
|
||||||
Vector<String> get_script_templates(const String &p_extension, const String &p_custom_path = String());
|
Vector<String> get_script_templates(const String &p_extension, const String &p_custom_path = String());
|
||||||
String get_editor_layouts_config() const;
|
String get_editor_layouts_config() const;
|
||||||
|
float get_auto_display_scale() const;
|
||||||
|
|
||||||
void add_shortcut(const String &p_name, Ref<Shortcut> &p_shortcut);
|
void add_shortcut(const String &p_name, Ref<Shortcut> &p_shortcut);
|
||||||
bool is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const;
|
bool is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const;
|
||||||
|
@ -2400,36 +2400,10 @@ ProjectManager::ProjectManager() {
|
|||||||
int display_scale = EditorSettings::get_singleton()->get("interface/editor/display_scale");
|
int display_scale = EditorSettings::get_singleton()->get("interface/editor/display_scale");
|
||||||
|
|
||||||
switch (display_scale) {
|
switch (display_scale) {
|
||||||
case 0: {
|
case 0:
|
||||||
// Try applying a suitable display scale automatically.
|
// Try applying a suitable display scale automatically.
|
||||||
// The code below is adapted in `editor/editor_settings.cpp` and `editor/editor_node.cpp`.
|
editor_set_scale(EditorSettings::get_singleton()->get_auto_display_scale());
|
||||||
// Make sure to update those when modifying the code below.
|
break;
|
||||||
#ifdef OSX_ENABLED
|
|
||||||
editor_set_scale(DisplayServer::get_singleton()->screen_get_max_scale());
|
|
||||||
#else
|
|
||||||
const int screen = DisplayServer::get_singleton()->window_get_current_screen();
|
|
||||||
// Use the smallest dimension to use a correct display scale on portait displays.
|
|
||||||
const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y);
|
|
||||||
float scale;
|
|
||||||
if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) {
|
|
||||||
// hiDPI display.
|
|
||||||
scale = 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.
|
|
||||||
scale = 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.
|
|
||||||
scale = 0.75;
|
|
||||||
} else {
|
|
||||||
scale = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
editor_set_scale(scale);
|
|
||||||
#endif
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
editor_set_scale(0.75);
|
editor_set_scale(0.75);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user