summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Koopa <raykoopa@users.noreply.github.com>2017-03-02 22:43:56 +0100
committerRay Koopa <raykoopa@users.noreply.github.com>2017-03-03 18:45:53 +0100
commit7623fd10bf10086f0b2b90bc6ceaa7e32279e645 (patch)
tree04c17c3b996e8b5f8a564aaa0a9eb5129a3aad84
parent74eace2b14b337e23d0dc552f3bc3e60f1710f65 (diff)
Make Editor, Export and Project settings dialogs resizable and store their bounds
-rw-r--r--scene/gui/dialogs.cpp28
-rw-r--r--scene/gui/dialogs.h2
-rw-r--r--scene/gui/popup.cpp10
-rw-r--r--scene/gui/popup.h4
-rw-r--r--tools/editor/project_export.cpp23
-rw-r--r--tools/editor/project_settings.cpp57
-rw-r--r--tools/editor/settings_config_dialog.cpp23
7 files changed, 105 insertions, 42 deletions
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index e889d1acd3..6d06f8c59c 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -36,6 +36,34 @@ void WindowDialog::_post_popup() {
drag_type = DRAG_NONE; // just in case
}
+void WindowDialog::_fix_size() {
+
+ // Perhaps this should be called when the viewport resizes aswell or windows go out of bounds...
+
+ // Ensure the whole window is visible.
+ Point2i pos = get_global_pos();
+ Size2i size = get_size();
+ Size2i viewport_size = get_viewport_rect().size;
+
+ // Windows require additional padding to keep the window chrome visible.
+ Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog");
+ float top = panel->get_margin(MARGIN_TOP);
+ float left = panel->get_margin(MARGIN_LEFT);
+ float bottom = panel->get_margin(MARGIN_BOTTOM);
+ float right = panel->get_margin(MARGIN_RIGHT);
+
+ pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right));
+ pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom));
+ set_global_pos(pos);
+
+ // Also resize the window to fit if a resize should be possible at all.
+ if (resizable) {
+ size.x = MIN(size.x, viewport_size.x - left - right);
+ size.y = MIN(size.y, viewport_size.y - top - bottom);
+ set_size(size);
+ }
+}
+
bool WindowDialog::has_point(const Point2& p_point) const {
Rect2 r(Point2(), get_size());
diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h
index 845ac69cd5..dd75b76c8e 100644
--- a/scene/gui/dialogs.h
+++ b/scene/gui/dialogs.h
@@ -66,7 +66,7 @@ class WindowDialog : public Popup {
protected:
virtual void _post_popup();
-
+ virtual void _fix_size();
virtual void _close_pressed() {}
virtual bool has_point(const Point2& p_point) const;
void _notification(int p_what);
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 60ecd775f7..1f0daa99ba 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -226,12 +226,16 @@ void Popup::popup_centered_ratio(float p_screen_ratio) {
}
-void Popup::popup() {
+void Popup::popup(const Rect2& bounds) {
emit_signal("about_to_show");
show_modal(exclusive);
-
+ // Fit the popup into the optionally provided bounds.
+ if (!bounds.has_no_area()) {
+ set_pos(bounds.pos);
+ set_size(bounds.size);
+ }
_fix_size();
Control *focusable = find_next_valid_focus();
@@ -260,7 +264,7 @@ void Popup::_bind_methods() {
ClassDB::bind_method(D_METHOD("popup_centered","size"),&Popup::popup_centered,DEFVAL(Size2()));
ClassDB::bind_method(D_METHOD("popup_centered_ratio","ratio"),&Popup::popup_centered_ratio,DEFVAL(0.75));
ClassDB::bind_method(D_METHOD("popup_centered_minsize","minsize"),&Popup::popup_centered_minsize,DEFVAL(Size2()));
- ClassDB::bind_method(D_METHOD("popup"),&Popup::popup);
+ ClassDB::bind_method(D_METHOD("popup","bounds"),&Popup::popup,DEFVAL(Rect2()));
ClassDB::bind_method(D_METHOD("set_exclusive","enable"),&Popup::set_exclusive);
ClassDB::bind_method(D_METHOD("is_exclusive"),&Popup::is_exclusive);
ADD_SIGNAL( MethodInfo("about_to_show") );
diff --git a/scene/gui/popup.h b/scene/gui/popup.h
index 17ae4a938a..4e4c8b0292 100644
--- a/scene/gui/popup.h
+++ b/scene/gui/popup.h
@@ -47,7 +47,7 @@ protected:
void _gui_input(InputEvent p_event);
void _notification(int p_what);
- void _fix_size();
+ virtual void _fix_size();
static void _bind_methods();
public:
@@ -63,7 +63,7 @@ public:
void popup_centered(const Size2& p_size=Size2());
void popup_centered_minsize(const Size2& p_minsize=Size2());
void set_as_minsize();
- virtual void popup();
+ virtual void popup(const Rect2& p_bounds=Rect2());
virtual String get_configuration_warning() const;
diff --git a/tools/editor/project_export.cpp b/tools/editor/project_export.cpp
index f6593a4895..fc6d8793d8 100644
--- a/tools/editor/project_export.cpp
+++ b/tools/editor/project_export.cpp
@@ -46,10 +46,14 @@
void ProjectExportDialog::_notification(int p_what) {
- if (p_what==NOTIFICATION_READY) {
- delete_preset->set_icon(get_icon("Del","EditorIcons"));
- connect("confirmed",this,"_export_pck_zip");
-
+ switch (p_what) {
+ case NOTIFICATION_READY: {
+ delete_preset->set_icon(get_icon("Del","EditorIcons"));
+ connect("confirmed",this,"_export_pck_zip");
+ } break;
+ case NOTIFICATION_POPUP_HIDE: {
+ EditorSettings::get_singleton()->set("interface/dialogs/export_bounds", get_rect());
+ } break;
}
}
@@ -66,7 +70,13 @@ void ProjectExportDialog::popup_export() {
}
_update_presets();
- popup_centered_ratio();
+
+ // Restore valid window bounds or pop up at default size.
+ if (EditorSettings::get_singleton()->has("interface/dialogs/export_bounds")) {
+ popup(EditorSettings::get_singleton()->get("interface/dialogs/export_bounds"));
+ } else {
+ popup_centered_ratio();
+ }
}
void ProjectExportDialog::_add_preset(int p_platform) {
@@ -664,6 +674,9 @@ void ProjectExportDialog::_bind_methods() {
}
ProjectExportDialog::ProjectExportDialog() {
+ set_title(TTR("Export"));
+ set_resizable(true);
+
HBoxContainer *hbox = memnew( HBoxContainer );
add_child(hbox);
diff --git a/tools/editor/project_settings.cpp b/tools/editor/project_settings.cpp
index ed3c59cc4a..15019b8ca8 100644
--- a/tools/editor/project_settings.cpp
+++ b/tools/editor/project_settings.cpp
@@ -73,34 +73,38 @@ static const char* _axis_names[JOY_AXIS_MAX*2] = {
void ProjectSettings::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_TREE) {
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ globals_editor->edit(GlobalConfig::get_singleton());
- globals_editor->edit(GlobalConfig::get_singleton());
+ search_button->set_icon(get_icon("Zoom","EditorIcons"));
+ clear_button->set_icon(get_icon("Close","EditorIcons"));
- search_button->set_icon(get_icon("Zoom","EditorIcons"));
- clear_button->set_icon(get_icon("Close","EditorIcons"));
+ translation_list->connect("button_pressed",this,"_translation_delete");
+ _update_actions();
+ popup_add->add_icon_item(get_icon("Keyboard","EditorIcons"),TTR("Key "),InputEvent::KEY);//"Key " - because the word 'key' has already been used as a key animation
+ popup_add->add_icon_item(get_icon("JoyButton","EditorIcons"),TTR("Joy Button"),InputEvent::JOYPAD_BUTTON);
+ popup_add->add_icon_item(get_icon("JoyAxis","EditorIcons"),TTR("Joy Axis"),InputEvent::JOYPAD_MOTION);
+ popup_add->add_icon_item(get_icon("Mouse","EditorIcons"),TTR("Mouse Button"),InputEvent::MOUSE_BUTTON);
- translation_list->connect("button_pressed",this,"_translation_delete");
- _update_actions();
- popup_add->add_icon_item(get_icon("Keyboard","EditorIcons"),TTR("Key "),InputEvent::KEY);//"Key " - because the word 'key' has already been used as a key animation
- popup_add->add_icon_item(get_icon("JoyButton","EditorIcons"),TTR("Joy Button"),InputEvent::JOYPAD_BUTTON);
- popup_add->add_icon_item(get_icon("JoyAxis","EditorIcons"),TTR("Joy Axis"),InputEvent::JOYPAD_MOTION);
- popup_add->add_icon_item(get_icon("Mouse","EditorIcons"),TTR("Mouse Button"),InputEvent::MOUSE_BUTTON);
+ List<String> tfn;
+ ResourceLoader::get_recognized_extensions_for_type("Translation",&tfn);
+ for (List<String>::Element *E=tfn.front();E;E=E->next()) {
- List<String> tfn;
- ResourceLoader::get_recognized_extensions_for_type("Translation",&tfn);
- for (List<String>::Element *E=tfn.front();E;E=E->next()) {
-
- translation_file_open->add_filter("*."+E->get());
- }
+ translation_file_open->add_filter("*."+E->get());
+ }
- List<String> rfn;
- ResourceLoader::get_recognized_extensions_for_type("Resource",&rfn);
- for (List<String>::Element *E=rfn.front();E;E=E->next()) {
+ List<String> rfn;
+ ResourceLoader::get_recognized_extensions_for_type("Resource",&rfn);
+ for (List<String>::Element *E=rfn.front();E;E=E->next()) {
- translation_res_file_open->add_filter("*."+E->get());
- translation_res_option_file_open->add_filter("*."+E->get());
- }
+ translation_res_file_open->add_filter("*."+E->get());
+ translation_res_option_file_open->add_filter("*."+E->get());
+ }
+ } break;
+ case NOTIFICATION_POPUP_HIDE: {
+ EditorSettings::get_singleton()->set("interface/dialogs/project_settings_bounds", get_rect());
+ } break;
}
}
@@ -579,8 +583,12 @@ void ProjectSettings::_update_actions() {
void ProjectSettings::popup_project_settings() {
- //popup_centered(Size2(500,400));
- popup_centered_ratio();
+ // Restore valid window bounds or pop up at default size.
+ if (EditorSettings::get_singleton()->has("interface/dialogs/project_settings_bounds")) {
+ popup(EditorSettings::get_singleton()->get("interface/dialogs/project_settings_bounds"));
+ } else {
+ popup_centered_ratio();
+ }
globals_editor->update_category_list();
_update_translations();
autoload_settings->update_autoload();
@@ -1224,6 +1232,7 @@ ProjectSettings::ProjectSettings(EditorData *p_data) {
singleton=this;
set_title(TTR("Project Settings (godot.cfg)"));
+ set_resizable(true);
undo_redo=&p_data->get_undo_redo();
data=p_data;
diff --git a/tools/editor/settings_config_dialog.cpp b/tools/editor/settings_config_dialog.cpp
index 6a62e035ec..7d8d6ffcec 100644
--- a/tools/editor/settings_config_dialog.cpp
+++ b/tools/editor/settings_config_dialog.cpp
@@ -93,10 +93,14 @@ void EditorSettingsDialog::popup_edit_settings() {
search_box->grab_focus();
_update_shortcuts();
- popup_centered_ratio(0.7);
-}
-
+ // Restore valid window bounds or pop up at default size.
+ if (EditorSettings::get_singleton()->has("interface/dialogs/editor_settings_bounds")) {
+ popup(EditorSettings::get_singleton()->get("interface/dialogs/editor_settings_bounds"));
+ } else {
+ popup_centered_ratio(0.7);
+ }
+}
void EditorSettingsDialog::_clear_search_box() {
@@ -121,10 +125,14 @@ void EditorSettingsDialog::_filter_shortcuts(const String& p_filter) {
void EditorSettingsDialog::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_TREE) {
-
- clear_button->set_icon(get_icon("Close","EditorIcons"));
- shortcut_clear_button->set_icon(get_icon("Close","EditorIcons"));
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ clear_button->set_icon(get_icon("Close", "EditorIcons"));
+ shortcut_clear_button->set_icon(get_icon("Close", "EditorIcons"));
+ } break;
+ case NOTIFICATION_POPUP_HIDE: {
+ EditorSettings::get_singleton()->set("interface/dialogs/editor_settings_bounds", get_rect());
+ } break;
}
}
@@ -305,6 +313,7 @@ void EditorSettingsDialog::_bind_methods() {
EditorSettingsDialog::EditorSettingsDialog() {
set_title(TTR("Editor Settings"));
+ set_resizable(true);
tabs = memnew( TabContainer );
add_child(tabs);