Make Editor, Export and Project settings dialogs resizable and store their bounds
This commit is contained in:
parent
74eace2b14
commit
7623fd10bf
7 changed files with 105 additions and 42 deletions
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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") );
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -93,11 +93,15 @@ 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() {
|
||||
|
||||
if (search_box->get_text()=="")
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue