diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-05-23 23:24:17 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-05-23 23:24:32 -0300 |
commit | e843e74d39bbed3657c611c50bdceade979cf031 (patch) | |
tree | e8acdfe69f08b4a43edec55ff89c231b6ce4fd36 | |
parent | 472ab44768240bc8415778af125ab605b8f334fd (diff) |
General docks clean up
-Moved path box above in fs dock
-Remove up/down button and added reordering with DND of favorites
-Changed zoom icon to be centered vertically
-Made filter for files always visible
-Added some options to TextureFrame for better alignment/stretching
-rw-r--r-- | scene/gui/texture_frame.cpp | 46 | ||||
-rw-r--r-- | scene/gui/texture_frame.h | 15 | ||||
-rw-r--r-- | tools/editor/scene_tree_dock.cpp | 1 | ||||
-rw-r--r-- | tools/editor/scenes_dock.cpp | 266 | ||||
-rw-r--r-- | tools/editor/scenes_dock.h | 7 |
5 files changed, 183 insertions, 152 deletions
diff --git a/scene/gui/texture_frame.cpp b/scene/gui/texture_frame.cpp index 73fecf591a..2fe8735fda 100644 --- a/scene/gui/texture_frame.cpp +++ b/scene/gui/texture_frame.cpp @@ -37,9 +37,31 @@ void TextureFrame::_notification(int p_what) { return; - Size2 s=expand?get_size():texture->get_size(); + RID ci = get_canvas_item(); - draw_texture_rect(texture,Rect2(Point2(),s),false,modulate); + + switch(stretch_mode) { + case STRETCH_SCALE_ON_EXPAND: { + Size2 s=expand?get_size():texture->get_size(); + draw_texture_rect(texture,Rect2(Point2(),s),false,modulate); + } break; + case STRETCH_SCALE: { + draw_texture_rect(texture,Rect2(Point2(),get_size()),false,modulate); + } break; + case STRETCH_TILE: { + draw_texture_rect(texture,Rect2(Point2(),get_size()),true,modulate); + } break; + case STRETCH_KEEP: { + draw_texture_rect(texture,Rect2(Point2(),texture->get_size()),false,modulate); + + } break; + case STRETCH_KEEP_CENTERED: { + + Vector2 ofs = (get_size() - texture->get_size())/2; + draw_texture_rect(texture,Rect2(ofs,texture->get_size()),false,modulate); + } break; + } + /* Vector<Point2> points; @@ -76,11 +98,19 @@ void TextureFrame::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_modulate"), & TextureFrame::get_modulate ); ObjectTypeDB::bind_method(_MD("set_expand","enable"), & TextureFrame::set_expand ); ObjectTypeDB::bind_method(_MD("has_expand"), & TextureFrame::has_expand ); + ObjectTypeDB::bind_method(_MD("set_stretch_mode","stretch_mode"), & TextureFrame::set_stretch_mode ); + ObjectTypeDB::bind_method(_MD("get_stretch_mode"), & TextureFrame::get_stretch_mode ); ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture"),_SCS("get_texture") ); ADD_PROPERTYNO( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate") ); ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "expand" ), _SCS("set_expand"),_SCS("has_expand") ); + ADD_PROPERTYNO( PropertyInfo( Variant::INT, "stretch_mode",PROPERTY_HINT_ENUM,"Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered"), _SCS("set_stretch_mode"),_SCS("get_stretch_mode") ); + BIND_CONSTANT( STRETCH_SCALE_ON_EXPAND ); + BIND_CONSTANT( STRETCH_SCALE ); + BIND_CONSTANT( STRETCH_TILE ); + BIND_CONSTANT( STRETCH_KEEP ); + BIND_CONSTANT( STRETCH_KEEP_CENTERED ); } @@ -121,12 +151,24 @@ bool TextureFrame::has_expand() const { return expand; } +void TextureFrame::set_stretch_mode(StretchMode p_mode) { + + stretch_mode=p_mode; + update(); +} + +TextureFrame::StretchMode TextureFrame::get_stretch_mode() const { + + return stretch_mode; +} + TextureFrame::TextureFrame() { expand=false; modulate=Color(1,1,1,1); set_ignore_mouse(true); + stretch_mode=STRETCH_SCALE_ON_EXPAND; } diff --git a/scene/gui/texture_frame.h b/scene/gui/texture_frame.h index e1f0de92df..a4acf588ea 100644 --- a/scene/gui/texture_frame.h +++ b/scene/gui/texture_frame.h @@ -36,10 +36,19 @@ class TextureFrame : public Control { OBJ_TYPE(TextureFrame,Control); - +public: + enum StretchMode { + STRETCH_SCALE_ON_EXPAND, //default, for backwards compatibility + STRETCH_SCALE, + STRETCH_TILE, + STRETCH_KEEP, + STRETCH_KEEP_CENTERED, + }; +private: bool expand; Color modulate; Ref<Texture> texture; + StretchMode stretch_mode; protected: void _notification(int p_what); @@ -57,9 +66,13 @@ public: void set_expand(bool p_expand); bool has_expand() const; + void set_stretch_mode(StretchMode p_mode); + StretchMode get_stretch_mode() const; + TextureFrame(); ~TextureFrame(); }; +VARIANT_ENUM_CAST( TextureFrame::StretchMode ); #endif // TEXTURE_FRAME_H diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index 803ae59466..517162b81e 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -1787,6 +1787,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec filter_hbc->add_child(filter); filter_icon = memnew( TextureFrame ); filter_hbc->add_child(filter_icon); + filter_icon->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED); filter->connect("text_changed",this,"_filter_changed"); diff --git a/tools/editor/scenes_dock.cpp b/tools/editor/scenes_dock.cpp index ec2f7e293c..fc0bcfe7b9 100644 --- a/tools/editor/scenes_dock.cpp +++ b/tools/editor/scenes_dock.cpp @@ -190,8 +190,6 @@ void ScenesDock::_notification(int p_what) { button_reload->set_icon( get_icon("Reload","EditorIcons")); button_favorite->set_icon( get_icon("Favorites","EditorIcons")); - button_fav_up->set_icon( get_icon("MoveUp","EditorIcons")); - button_fav_down->set_icon( get_icon("MoveDown","EditorIcons")); //button_instance->set_icon( get_icon("Add","EditorIcons")); //button_open->set_icon( get_icon("Folder","EditorIcons")); button_back->set_icon( get_icon("Filesystem","EditorIcons")); @@ -201,7 +199,7 @@ void ScenesDock::_notification(int p_what) { files->connect("item_activated",this,"_select_file"); button_hist_next->connect("pressed",this,"_fw_history"); button_hist_prev->connect("pressed",this,"_bw_history"); - search_button->set_icon( get_icon("Zoom","EditorIcons")); + search_icon->set_texture( get_icon("Zoom","EditorIcons")); button_hist_next->set_icon( get_icon("Forward","EditorIcons")); button_hist_prev->set_icon( get_icon("Back","EditorIcons")); @@ -228,10 +226,16 @@ void ScenesDock::_notification(int p_what) { case NOTIFICATION_DRAG_BEGIN: { Dictionary dd = get_viewport()->gui_get_drag_data(); - if (tree->is_visible() && dd.has("type") && ( - (String(dd["type"])=="files") || (String(dd["type"])=="files_and_dirs") || (String(dd["type"])=="resource"))) { - tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM); + if (tree->is_visible() && dd.has("type") ) { + if ( (String(dd["type"])=="files") || (String(dd["type"])=="files_and_dirs") || (String(dd["type"])=="resource")) { + tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM); + } + if ( (String(dd["type"])=="favorite") ) { + tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); + } } + + } break; case NOTIFICATION_DRAG_END: { @@ -272,11 +276,7 @@ void ScenesDock::_dir_selected() { if (ti->get_parent() && ti->get_parent()->get_parent()==tree->get_root() && !ti->get_parent()->get_prev()) { //a favorite!!! - button_fav_up->set_disabled(!ti->get_prev()); - button_fav_down->set_disabled(!ti->get_next()); } else { - button_fav_up->set_disabled(true); - button_fav_down->set_disabled(true); } @@ -287,83 +287,6 @@ void ScenesDock::_dir_selected() { } -void ScenesDock::_fav_up_pressed() { - - TreeItem *sel = tree->get_selected(); - if (!sel) - return ; - - if (!sel->get_prev()) - return; - - String sw = sel->get_prev()->get_metadata(0); - String txt = sel->get_metadata(0); - - Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs(); - - int a_idx=favorited.find(sw); - int b_idx=favorited.find(txt); - - if (a_idx==-1 || b_idx==-1) - return; - SWAP(favorited[a_idx],favorited[b_idx]); - - EditorSettings::get_singleton()->set_favorite_dirs(favorited); - - _update_tree(); - - if (!tree->get_root() || !tree->get_root()->get_children() || !tree->get_root()->get_children()->get_children()) - return; - sel = tree->get_root()->get_children()->get_children(); - while(sel) { - - String t = sel->get_metadata(0); - if (t==txt) { - sel->select(0); - return; - } - sel=sel->get_next(); - } -} - -void ScenesDock::_fav_down_pressed() { - - TreeItem *sel = tree->get_selected(); - if (!sel) - return ; - - if (!sel->get_next()) - return; - - String sw = sel->get_next()->get_metadata(0); - String txt = sel->get_metadata(0); - - Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs(); - - int a_idx=favorited.find(sw); - int b_idx=favorited.find(txt); - - if (a_idx==-1 || b_idx==-1) - return; - SWAP(favorited[a_idx],favorited[b_idx]); - - EditorSettings::get_singleton()->set_favorite_dirs(favorited); - - _update_tree(); - - if (!tree->get_root() || !tree->get_root()->get_children() || !tree->get_root()->get_children()->get_children()) - return; - sel = tree->get_root()->get_children()->get_children(); - while(sel) { - - String t = sel->get_metadata(0); - if (t==txt) { - sel->select(0); - return; - } - sel=sel->get_next(); - } -} void ScenesDock::_favorites_pressed() { @@ -499,7 +422,7 @@ void ScenesDock::_update_files(bool p_keep_selection) { Ref<Texture> file_thumbnail; bool use_thumbnails=!display_mode->is_pressed(); - bool use_folders = !search_box->is_visible() && split_mode; + bool use_folders = search_box->get_text().length()==0 && split_mode; if (use_thumbnails) { //thumbnails @@ -579,7 +502,7 @@ void ScenesDock::_update_files(bool p_keep_selection) { List<FileInfo> filelist; - if (search_box->is_visible()) { + if (search_box->get_text().length()) { if (search_box->get_text().length()>1) { _search(EditorFileSystem::get_singleton()->get_filesystem(),&filelist,128); @@ -653,8 +576,6 @@ void ScenesDock::_go_to_tree() { tree->grab_focus(); tree->ensure_cursor_is_visible(); button_favorite->show(); - button_fav_up->show(); - button_fav_down->show(); //button_open->hide(); //file_options->hide(); } @@ -680,8 +601,6 @@ void ScenesDock::_fs_changed() { if (!tree->is_hidden()) { button_favorite->show(); - button_fav_up->show(); - button_fav_down->show(); _update_tree(); } @@ -1100,8 +1019,6 @@ void ScenesDock::_open_pressed(){ tree->hide(); file_list_vb->show(); button_favorite->hide(); - button_fav_up->hide(); - button_fav_down->hide(); } //file_options->show(); @@ -1114,26 +1031,6 @@ void ScenesDock::_open_pressed(){ } -void ScenesDock::_search_toggled(){ - - if (search_button->is_pressed()) { - //search_box->clear(); - search_box->select_all(); - search_box->show(); - current_path->hide(); - search_box->grab_focus(); - - _update_files(false); - } else { - - //search_box->clear(); - search_box->hide(); - current_path->show(); - - _update_files(false); - - } -} void ScenesDock::_search_changed(const String& p_text) { @@ -1180,7 +1077,14 @@ Variant ScenesDock::get_drag_data_fw(const Point2& p_point,Control* p_from) { path=path+"/"; Vector<String> paths; paths.push_back(path); - return EditorNode::get_singleton()->drag_files(paths,p_from); + Dictionary d = EditorNode::get_singleton()->drag_files(paths,p_from); + + if (selected->get_parent() && tree->get_root()->get_children()==selected->get_parent()) { + //a favorite.. treat as such + d["type"]="favorite"; + } + + return d; } @@ -1239,6 +1143,30 @@ bool ScenesDock::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Co Dictionary drag_data = p_data; + if (drag_data.has("type") && String(drag_data["type"])=="favorite") { + + //moving favorite around + TreeItem *ti = tree->get_item_at_pos(p_point); + if (!ti) + return false; + + int what = tree->get_drop_section_at_pos(p_point); + + if (ti==tree->get_root()->get_children()) { + return (what==1); //the parent, first fav + } + if (ti->get_parent() && tree->get_root()->get_children()==ti->get_parent()) { + return true; // a favorite + } + + if (ti==tree->get_root()->get_children()->get_next()) { + return (what==-1); //the tree, last fav + } + + return false; + + } + if (drag_data.has("type") && String(drag_data["type"])=="resource") { return true; @@ -1283,6 +1211,69 @@ void ScenesDock::drop_data_fw(const Point2& p_point,const Variant& p_data,Contro return; Dictionary drag_data = p_data; + if (drag_data.has("type") && String(drag_data["type"])=="favorite") { + + //moving favorite around + TreeItem *ti = tree->get_item_at_pos(p_point); + if (!ti) + return; + + Vector<String> files = drag_data["files"]; + + ERR_FAIL_COND(files.size()!=1); + + String swap = files[0]; + if (swap!="res://" && swap.ends_with("/")) { + swap=swap.substr(0,swap.length()-1); + } + + int what = tree->get_drop_section_at_pos(p_point); + + TreeItem *swap_item=NULL; + + if (ti==tree->get_root()->get_children()) { + swap_item=tree->get_root()->get_children()->get_children(); + + } else if (ti->get_parent() && tree->get_root()->get_children()==ti->get_parent()) { + if (what==-1) { + swap_item=ti; + } else { + swap_item=ti->get_next(); + } + } + + String swap_with; + + if (swap_item) { + swap_with=swap_item->get_metadata(0); + if (swap_with!="res://" && swap_with.ends_with("/")) { + swap_with=swap_with.substr(0,swap_with.length()-1); + } + } + + if (swap==swap_with) + return; + + Vector<String> dirs = EditorSettings::get_singleton()->get_favorite_dirs(); + + ERR_FAIL_COND(dirs.find(swap)==-1); + ERR_FAIL_COND(swap_with!=String() && dirs.find(swap_with)==-1); + + dirs.erase(swap); + + if (swap_with==String()) { + dirs.push_back(swap); + } else { + int idx = dirs.find(swap_with); + dirs.insert(idx,swap); + } + + EditorSettings::get_singleton()->set_favorite_dirs(dirs); + _update_tree(); + return; + + } + if (drag_data.has("type") && String(drag_data["type"])=="resource") { Ref<Resource> res = drag_data["resource"]; @@ -1449,12 +1440,10 @@ void ScenesDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_bw_history"), &ScenesDock::_bw_history); ObjectTypeDB::bind_method(_MD("_fs_changed"), &ScenesDock::_fs_changed); ObjectTypeDB::bind_method(_MD("_dir_selected"), &ScenesDock::_dir_selected); - ObjectTypeDB::bind_method(_MD("_fav_up_pressed"), &ScenesDock::_fav_up_pressed); - ObjectTypeDB::bind_method(_MD("_fav_down_pressed"), &ScenesDock::_fav_down_pressed); ObjectTypeDB::bind_method(_MD("_file_option"), &ScenesDock::_file_option); ObjectTypeDB::bind_method(_MD("_move_operation"), &ScenesDock::_move_operation); ObjectTypeDB::bind_method(_MD("_rename_operation"), &ScenesDock::_rename_operation); - ObjectTypeDB::bind_method(_MD("_search_toggled"), &ScenesDock::_search_toggled); + ObjectTypeDB::bind_method(_MD("_search_changed"), &ScenesDock::_search_changed); ObjectTypeDB::bind_method(_MD("get_drag_data_fw"), &ScenesDock::get_drag_data_fw); @@ -1487,28 +1476,21 @@ ScenesDock::ScenesDock(EditorNode *p_editor) { button_hist_next->set_focus_mode(FOCUS_NONE); button_hist_next->set_tooltip(TTR("Next Directory")); + current_path=memnew( LineEdit ); + current_path->set_h_size_flags(SIZE_EXPAND_FILL); + toolbar_hbc->add_child(current_path); + + button_reload = memnew( Button ); button_reload->set_flat(true); button_reload->connect("pressed",this,"_rescan"); toolbar_hbc->add_child(button_reload); button_reload->set_focus_mode(FOCUS_NONE); button_reload->set_tooltip(TTR("Re-Scan Filesystem")); + button_reload->hide(); - toolbar_hbc->add_spacer(); - - button_fav_up = memnew( ToolButton ); - button_fav_up->set_flat(true); - toolbar_hbc->add_child(button_fav_up); - button_fav_up->set_disabled(true); - button_fav_up->connect("pressed",this,"_fav_up_pressed"); - button_fav_up->set_tooltip(TTR("Move Favorite Up")); + //toolbar_hbc->add_spacer(); - button_fav_down = memnew( ToolButton ); - button_fav_down->set_flat(true); - toolbar_hbc->add_child(button_fav_down); - button_fav_down->set_disabled(true); - button_fav_down->connect("pressed",this,"_fav_down_pressed"); - button_fav_down->set_tooltip(TTR("Move Favorite Down")); button_favorite = memnew( Button ); button_favorite->set_flat(true); @@ -1518,8 +1500,10 @@ ScenesDock::ScenesDock(EditorNode *p_editor) { button_favorite->set_tooltip(TTR("Toggle folder status as Favorite")); button_favorite->set_focus_mode(FOCUS_NONE); - button_fav_up->set_focus_mode(FOCUS_NONE); - button_fav_down->set_focus_mode(FOCUS_NONE); + + Control *spacer = memnew( Control); + + /* button_open = memnew( Button ); @@ -1577,20 +1561,15 @@ ScenesDock::ScenesDock(EditorNode *p_editor) { button_back = memnew( ToolButton ); path_hb->add_child(button_back); button_back->hide(); - current_path=memnew( LineEdit ); - current_path->set_h_size_flags(SIZE_EXPAND_FILL); - path_hb->add_child(current_path); search_box = memnew( LineEdit ); search_box->set_h_size_flags(SIZE_EXPAND_FILL); path_hb->add_child(search_box); - search_box->hide(); search_box->connect("text_changed",this,"_search_changed"); - search_button = memnew( ToolButton ); - path_hb->add_child(search_button); - search_button->set_toggle_mode(true ); - search_button->connect("pressed",this,"_search_toggled"); + search_icon = memnew( TextureFrame ); + search_icon->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED); + path_hb->add_child(search_icon); display_mode = memnew( ToolButton ); path_hb->add_child(display_mode); @@ -1641,6 +1620,7 @@ ScenesDock::ScenesDock(EditorNode *p_editor) { path="res://"; + add_constant_override("separation",3); } ScenesDock::~ScenesDock() { diff --git a/tools/editor/scenes_dock.h b/tools/editor/scenes_dock.h index 42c1374be1..1d6d03374a 100644 --- a/tools/editor/scenes_dock.h +++ b/tools/editor/scenes_dock.h @@ -77,15 +77,13 @@ class ScenesDock : public VBoxContainer { Button *button_reload; Button *button_favorite; - Button *button_fav_up; - Button *button_fav_down; Button *button_back; Button *display_mode; Button *button_hist_next; Button *button_hist_prev; LineEdit *current_path; LineEdit *search_box; - Button *search_button; + TextureFrame *search_icon; HBoxContainer *path_hb; bool split_mode; @@ -137,8 +135,6 @@ class ScenesDock : public VBoxContainer { void _push_to_history(); - void _fav_up_pressed(); - void _fav_down_pressed(); void _dir_selected(); void _update_tree(); void _rescan(); @@ -147,7 +143,6 @@ class ScenesDock : public VBoxContainer { void _favorites_pressed(); void _open_pressed(); - void _search_toggled(); void _search_changed(const String& p_text); |