Skip to content
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
3 changes: 3 additions & 0 deletions exporters/obj_exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ Error ObjExporter::_write_meshes_to_obj(const Vector<Ref<Mesh>> &p_meshes, const
String v_line = format_obj_line(force_single_precision, "v %.6f %.6f %.6f", v.x, v.y, v.z);
if (t.has_color) {
v_line += format_obj_line(force_single_precision, " %.6f %.6f %.6f", t.vc.r, t.vc.g, t.vc.b);
if (t.vc.a != 1.0f) {
v_line += format_obj_line(force_single_precision, " %.6f", t.vc.a);
}
}
f->store_line(v_line);
if (t.has_uv) {
Expand Down
4 changes: 2 additions & 2 deletions gui/find_replace_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ GDREFindReplaceBar::GDREFindReplaceBar() {
search_text->set_placeholder(TTRC("Find"));
search_text->set_tooltip_text(TTRC("Find"));
search_text->set_accessibility_name(TTRC("Find"));
search_text->set_custom_minimum_size(Size2(100 * GDRESettings::get_singleton()->get_auto_display_scale(), 0));
search_text->set_custom_minimum_size(Size2(100 * GDRESettings::get_auto_display_scale(), 0));
search_text->connect(SceneStringName(text_changed), callable_mp(this, &GDREFindReplaceBar::_search_text_changed));
search_text->connect(SceneStringName(text_submitted), callable_mp(this, &GDREFindReplaceBar::_search_text_submitted));

Expand Down Expand Up @@ -1077,7 +1077,7 @@ GDREFindReplaceBar::GDREFindReplaceBar() {
replace_text->set_placeholder(TTRC("Replace"));
replace_text->set_tooltip_text(TTRC("Replace"));
replace_text->set_accessibility_name(TTRC("Replace"));
replace_text->set_custom_minimum_size(Size2(100 * GDRESettings::get_singleton()->get_auto_display_scale(), 0));
replace_text->set_custom_minimum_size(Size2(100 * GDRESettings::get_auto_display_scale(), 0));
replace_text->connect(SceneStringName(text_submitted), callable_mp(this, &GDREFindReplaceBar::_replace_text_submitted));

Control *replace_text_spacer = memnew(Control);
Expand Down
8 changes: 6 additions & 2 deletions gui/gdre_progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include "gui/gdre_progress.h"

#include "gui/gdre_window.h"

#include "core/object/callable_mp.h"
#include "core/object/class_db.h"
#include "core/os/os.h"
Expand Down Expand Up @@ -62,7 +64,7 @@ void GDREBackgroundProgress::_add_task(const String &p_task, const String &p_lab
ec->set_v_size_flags(SIZE_EXPAND_FILL);
t.progress->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
ec->add_child(t.progress);
ec->set_custom_minimum_size(Size2(80, 5) * GDRESettings::get_singleton()->get_auto_display_scale());
ec->set_custom_minimum_size(Size2(80, 5) * GDRESettings::get_auto_display_scale());
t.hb->add_child(ec);

add_child(t.hb);
Expand Down Expand Up @@ -146,6 +148,8 @@ void GDREProgressDialog::_update_ui() {
void GDREProgressDialog::_notification(int p_what) {
if (p_what == NOTIFICATION_PROCESS) {
main_thread_update();
} else if (p_what == NOTIFICATION_READY) {
GDREWindow::set_window_autoscaling(this, get_min_size());
}
}

Expand Down Expand Up @@ -305,7 +309,7 @@ void GDREProgressDialog::_reparent_and_show() {
}

Size2 ms = main->get_combined_minimum_size();
ms.width = MAX(500 * GDRESettings::get_singleton()->get_auto_display_scale(), ms.width);
ms.width = MAX(500 * GDRESettings::get_auto_display_scale(), ms.width);

Ref<StyleBox> style = main->get_theme_stylebox(SceneStringName(panel), SNAME("PopupMenu"));
ms += style->get_minimum_size();
Expand Down
9 changes: 9 additions & 0 deletions gui/gdre_standalone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include "scene/gui/dialogs.h"
#include "scene/gui/rich_text_label.h"
#include "scene/main/node.h"
#include "scene/main/scene_tree.h"
#include "utility/gdre_logger.h"
#include "utility/gdre_settings.h"
#include "utility/gdre_version.gen.h"

GodotREEditorStandalone *GodotREEditorStandalone::singleton = nullptr;
Expand Down Expand Up @@ -155,6 +157,13 @@ void GodotREEditorStandalone::_notification(int p_notification) {
if (get_parent_window()) {
get_parent_window()->call_deferred("add_child", error_dialog);
get_parent_window()->call_deferred("add_child", confirmation_dialog);
if (!Engine::get_singleton()->is_editor_hint()) {
Window *main_window = get_parent_window();
Size2i min_size = Size2i(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
GDREWindow::set_window_autoscaling(main_window, min_size);
main_window->set_size(min_size * GDRESettings::get_auto_display_scale());
main_window->move_to_center();
}
}
}
if (p_notification == NOTIFICATION_PROCESS) {
Expand Down
89 changes: 89 additions & 0 deletions gui/gdre_window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "gdre_window.h"
#include "gui/gdre_progress.h"
#include "scene/main/node.h"
#include "scene/main/window.h"
#include "utility/gdre_settings.h"

#include "core/config/engine.h"
#include "core/object/class_db.h"

void GDREWindow::popup_box(Node *p_parent, Window *p_box, const String &p_message, const String &p_title, const Callable &p_confirm_callback, const Callable &p_cancel_callback, const String &p_ok_button_text, const String &p_cancel_button_text) {
Expand Down Expand Up @@ -45,6 +49,40 @@ void GDREWindow::popup_box(Node *p_parent, Window *p_box, const String &p_messag
p_box->popup_centered();
}

void GDREWindow::set_window_autoscaling(Window *p_window, Size2i p_min_size) {
ERR_FAIL_NULL(p_window);
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
float current_scale = p_window->get_content_scale_factor();
float auto_display_scale = GDRESettings::get_auto_display_scale();
if (auto_display_scale != 1.0 && auto_display_scale != current_scale) {
p_window->set_content_scale_factor(auto_display_scale);
}
bool no_min = p_min_size == Size2i();
float size_scale = auto_display_scale / current_scale;
Size2i new_min_size = Size2i(float(p_min_size.x) * size_scale, float(p_min_size.y) * size_scale);

if (!no_min && p_window->get_min_size() != new_min_size) {
p_window->set_min_size(new_min_size);
}

Size2i current_size = p_window->get_size();
Size2i new_size = no_min ? Size2i(float(current_size.x) * size_scale, float(current_size.y) * size_scale) : new_min_size;
if (no_min || current_size < new_size) {
p_window->set_size(new_size);
}
p_window->set_oversampling_override(auto_display_scale);
}

void GDREWindow::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
GDREWindow::set_window_autoscaling(this, get_min_size());
GDREWindow::set_window_autoscaling(confirmation_dialog, confirmation_dialog->get_min_size());
GDREWindow::set_window_autoscaling(error_dialog, error_dialog->get_min_size());
}
}

GDREWindow::GDREWindow() {
if (GDREProgressDialog::get_singleton()) {
GDREProgressDialog::get_singleton()->add_host_window(this);
Expand Down Expand Up @@ -93,6 +131,52 @@ void GDREAcceptDialogBase::popup_error_box(const String &p_message, const String
GDREWindow::popup_box(this, error_dialog, p_message, p_title, p_callback, p_callback);
}

void GDREAcceptDialogBase::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
GDREWindow::set_window_autoscaling(this, get_min_size());
GDREWindow::set_window_autoscaling(confirmation_dialog, confirmation_dialog->get_min_size());
GDREWindow::set_window_autoscaling(error_dialog, error_dialog->get_min_size());
}
}

GDREConfirmationDialogBase::GDREConfirmationDialogBase() {
if (GDREProgressDialog::get_singleton()) {
GDREProgressDialog::get_singleton()->add_host_window(this);
}
confirmation_dialog = memnew(ConfirmationDialog);
error_dialog = memnew(AcceptDialog);
add_child(confirmation_dialog);
add_child(error_dialog);
}

GDREConfirmationDialogBase::~GDREConfirmationDialogBase() {
if (GDREProgressDialog::get_singleton()) {
GDREProgressDialog::get_singleton()->remove_host_window(this);
}
}

void GDREConfirmationDialogBase::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
GDREWindow::set_window_autoscaling(this, get_min_size());
GDREWindow::set_window_autoscaling(confirmation_dialog, confirmation_dialog->get_min_size());
GDREWindow::set_window_autoscaling(error_dialog, error_dialog->get_min_size());
}
}

void GDREConfirmationDialogBase::popup_confirm_box(const String &p_message, const String &p_title, const Callable &p_confirm_callback, const Callable &p_cancel_callback, const String &p_ok_button_text, const String &p_cancel_button_text) {
GDREWindow::popup_box(this, confirmation_dialog, p_message, p_title, p_confirm_callback, p_cancel_callback, p_ok_button_text, p_cancel_button_text);
}

void GDREConfirmationDialogBase::popup_error_box(const String &p_message, const String &p_title, const Callable &p_callback) {
GDREWindow::popup_box(this, error_dialog, p_message, p_title, p_callback);
}

void GDREFileDialog::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
GDREWindow::set_window_autoscaling(this, get_min_size());
}
}

void GDREWindow::_bind_methods() {
ClassDB::bind_static_method(get_class_static(), D_METHOD("popup_box", "p_parent", "p_box", "p_message", "p_title", "p_confirm_callback", "p_cancel_callback", "p_ok_button_text", "p_cancel_button_text"), &GDREWindow::popup_box, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL("OK"), DEFVAL("Cancel"));
ClassDB::bind_method(D_METHOD("popup_confirm_box", "p_message", "p_title", "p_confirm_callback", "p_cancel_callback", "p_ok_button_text", "p_cancel_button_text"), &GDREWindow::popup_confirm_box, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL("OK"), DEFVAL("Cancel"));
Expand All @@ -103,3 +187,8 @@ void GDREAcceptDialogBase::_bind_methods() {
ClassDB::bind_method(D_METHOD("popup_confirm_box", "p_message", "p_title", "p_confirm_callback", "p_cancel_callback", "p_ok_button_text", "p_cancel_button_text"), &GDREAcceptDialogBase::popup_confirm_box, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL("OK"), DEFVAL("Cancel"));
ClassDB::bind_method(D_METHOD("popup_error_box", "p_message", "p_title", "p_callback"), &GDREAcceptDialogBase::popup_error_box, DEFVAL("Error"), DEFVAL(Callable()));
}

void GDREConfirmationDialogBase::_bind_methods() {
ClassDB::bind_method(D_METHOD("popup_confirm_box", "p_message", "p_title", "p_confirm_callback", "p_cancel_callback", "p_ok_button_text", "p_cancel_button_text"), &GDREConfirmationDialogBase::popup_confirm_box, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL("OK"), DEFVAL("Cancel"));
ClassDB::bind_method(D_METHOD("popup_error_box", "p_message", "p_title", "p_callback"), &GDREConfirmationDialogBase::popup_error_box, DEFVAL("Error"), DEFVAL(Callable()));
}
33 changes: 33 additions & 0 deletions gui/gdre_window.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include "scene/gui/dialogs.h"
#include "scene/gui/file_dialog.h"
#include "scene/main/scene_tree.h"
#include "scene/main/window.h"

class GDREWindow : public Window {
Expand All @@ -13,7 +15,10 @@ class GDREWindow : public Window {
protected:
static void _bind_methods();

void _notification(int p_what);

public:
static void set_window_autoscaling(Window *p_window, Size2i p_min_size);
static void popup_box(Node *p_parent, Window *p_box, const String &p_message, const String &p_title, const Callable &p_confirm_callback = {}, const Callable &p_cancel_callback = {}, const String &p_ok_button_text = "OK", const String &p_cancel_button_text = "Cancel");

void popup_confirm_box(const String &p_message, const String &p_title, const Callable &p_confirm_callback = Callable(), const Callable &p_cancel_callback = Callable(), const String &p_ok_button_text = "OK", const String &p_cancel_button_text = "Cancel");
Expand All @@ -31,10 +36,38 @@ class GDREAcceptDialogBase : public AcceptDialog {
protected:
static void _bind_methods();

void _notification(int p_what);

public:
void popup_confirm_box(const String &p_message, const String &p_title, const Callable &p_confirm_callback = Callable(), const Callable &p_cancel_callback = Callable(), const String &p_ok_button_text = "OK", const String &p_cancel_button_text = "Cancel");
void popup_error_box(const String &p_message, const String &p_title = "Error", const Callable &p_callback = Callable());

GDREAcceptDialogBase();
~GDREAcceptDialogBase();
};

class GDREConfirmationDialogBase : public ConfirmationDialog {
GDCLASS(GDREConfirmationDialogBase, ConfirmationDialog);

ConfirmationDialog *confirmation_dialog;
AcceptDialog *error_dialog;

protected:
static void _bind_methods();

void _notification(int p_what);

public:
void popup_confirm_box(const String &p_message, const String &p_title, const Callable &p_confirm_callback = Callable(), const Callable &p_cancel_callback = Callable(), const String &p_ok_button_text = "OK", const String &p_cancel_button_text = "Cancel");
void popup_error_box(const String &p_message, const String &p_title = "Error", const Callable &p_callback = Callable());

GDREConfirmationDialogBase();
~GDREConfirmationDialogBase();
};

class GDREFileDialog : public FileDialog {
GDCLASS(GDREFileDialog, FileDialog);

protected:
void _notification(int p_what);
};
21 changes: 6 additions & 15 deletions gui/gui_icons.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
#include "gui_icons.h"
#include "gui/gdre_icons.gen.h"
#include "scene/gui/control.h"
#include "scene/resources/dpi_texture.h"
#include "scene/resources/image_texture.h"
#include "scene/theme/theme_db.h"
#ifdef MODULE_SVG_ENABLED
#include "modules/svg/image_loader_svg.h"

#endif

// HashMap<float, HashMap<StringName, Ref<ImageTexture>>> GDREGuiIcons::icons;
// HashMap<float, HashMap<StringName, Ref<DPITexture>>> GDREGuiIcons::icons;
// bool GDREGuiIcons::initialized = false;
// BinaryMutex GDREGuiIcons::init_lock;

GDREGuiIcons *GDREGuiIcons::singleton = nullptr;
namespace {
static inline Ref<ImageTexture> generate_icon(int p_index, float scale) {
static inline Ref<DPITexture> generate_icon(int p_index, float scale) {
ERR_FAIL_INDEX_V(p_index, gdre_icons_count, nullptr);
Ref<Image> img = memnew(Image);

#ifdef MODULE_SVG_ENABLED
// Upsample icon generation only if the scale isn't an integer multiplier.
// Generating upsampled icons is slower, and the benefit is hardly visible
// with integer scales.
ImageLoaderSVG img_loader;
img_loader.create_image_from_string(img, gdre_icons_sources[p_index], scale, false, false);
#endif

return ImageTexture::create_from_image(img);
return DPITexture::create_from_string(gdre_icons_sources[p_index], scale);
}
} //namespace

Expand All @@ -39,11 +30,11 @@ int get_icon_index(const StringName &p_name) {
return -1;
}

Ref<ImageTexture> GDREGuiIcons::get_icon(const StringName &p_name, float scale) {
Ref<DPITexture> GDREGuiIcons::get_icon(const StringName &p_name, float scale) {
return singleton->_get_gdre_icon(p_name, scale);
}

Ref<ImageTexture> GDREGuiIcons::_get_gdre_icon(const StringName &p_name, float scale) {
Ref<DPITexture> GDREGuiIcons::_get_gdre_icon(const StringName &p_name, float scale) {
if (!initialized) {
init();
}
Expand Down
8 changes: 4 additions & 4 deletions gui/gui_icons.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#include "core/object/object.h"
#include "scene/resources/image_texture.h"
#include "scene/resources/dpi_texture.h"

class Control;
class GDREGuiIcons {
static GDREGuiIcons *singleton;

HashMap<float, HashMap<StringName, Ref<ImageTexture>>> icons;
HashMap<float, HashMap<StringName, Ref<DPITexture>>> icons;
bool initialized = false;
Mutex init_lock;

void init_for_scale(float scale);
void init();

Ref<ImageTexture> _get_gdre_icon(const StringName &p_name, float scale = 1.0);
Ref<DPITexture> _get_gdre_icon(const StringName &p_name, float scale = 1.0);

public:
static Ref<ImageTexture> get_icon(const StringName &p_name, float scale = 1.0);
static Ref<DPITexture> get_icon(const StringName &p_name, float scale = 1.0);
static void add_icons_to_theme(Control *p_theme);

static GDREGuiIcons *get_singleton();
Expand Down
2 changes: 1 addition & 1 deletion gui/mesh_previewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ MeshPreviewer::MeshPreviewer() {
mesh_instance = memnew(MeshInstance3D);
rotation->add_child(mesh_instance);

set_custom_minimum_size(Size2(1, 150) * GDRESettings::get_singleton()->get_auto_display_scale());
set_custom_minimum_size(Size2(1, 150) * GDRESettings::get_auto_display_scale());

HBoxContainer *hb = memnew(HBoxContainer);
add_child(hb);
Expand Down
2 changes: 1 addition & 1 deletion gui/scene_previewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void ScenePreviewer3D::setup_3d() {
rotation = memnew(Node3D);
viewport->add_child(rotation);

set_custom_minimum_size(Size2(1, 150) * GDRESettings::get_singleton()->get_auto_display_scale());
set_custom_minimum_size(Size2(1, 150) * GDRESettings::get_auto_display_scale());

HBoxContainer *hb = memnew(HBoxContainer);
add_child(hb);
Expand Down
8 changes: 8 additions & 0 deletions register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "gui/gdre_standalone.h"
#include "gui/texture_layered_previewer.h"
#include "modules/regex/regex.h"
#include "modules/register_module_types.h"
#include "utility/app_version_getter.h"
#include "utility/file_access_gdre.h"
#include "utility/file_access_patched_gdre.h"
Expand Down Expand Up @@ -456,6 +457,11 @@ void initialize_gdsdecomp_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
if (!Engine::get_singleton()->is_editor_hint()) {
float scale = GDRESettings::get_auto_display_scale();
ProjectSettings::get_singleton()->set_setting("display/window/stretch/scale", scale);
}

#ifdef TOOLS_ENABLED
ClassDB::register_class<PackDialog>();
ClassDB::register_class<NewPackDialog>();
Expand All @@ -466,6 +472,8 @@ void initialize_gdsdecomp_module(ModuleInitializationLevel p_level) {

ClassDB::register_class<GDREWindow>();
ClassDB::register_class<GDREAcceptDialogBase>();
ClassDB::register_class<GDREConfirmationDialogBase>();
ClassDB::register_class<GDREFileDialog>();

ClassDB::register_class<SemVer>();
ClassDB::register_class<GodotVer>();
Expand Down
2 changes: 1 addition & 1 deletion standalone/export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ application/copyright_localized={}
application/min_macos_version_x86_64="10.15"
application/min_macos_version_arm64="11.00"
application/export_angle=0
display/high_res=false
display/high_res=true
shader_baker/enabled=false
application/additional_plist_content=""
xcode/platform_build="14C18"
Expand Down
Loading
Loading