diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-05-15 23:41:48 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-05-15 23:41:48 -0300 |
commit | a2c4c1708501e1eb223e34375c506c14d8fb4631 (patch) | |
tree | 12ab03db126e51d9e746f701f5e03d139ddef878 /scene/gui | |
parent | 8b47e26f59ddca57f95dfae5ce807d382957a97e (diff) |
Experimental Right Mouse Button menu for SceneTree
Will eventually replace the buttons of that dock, so please test it!
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/tree.cpp | 45 | ||||
-rw-r--r-- | scene/gui/tree.h | 4 |
2 files changed, 44 insertions, 5 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 6f5f7d82a6..9c70785408 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1563,7 +1563,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ col_width-=w+cache.button_margin; } - if (p_button==BUTTON_LEFT) { + if (p_button==BUTTON_LEFT || (p_button==BUTTON_RIGHT && allow_rmb_select)) { /* process selection */ if (p_doubleclick && (!c.editable || c.mode==TreeItem::CELL_MODE_CUSTOM || c.mode==TreeItem::CELL_MODE_ICON /*|| c.mode==TreeItem::CELL_MODE_CHECK*/)) { //it' s confusing for check @@ -1574,10 +1574,13 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ if (select_mode==SELECT_MULTI && p_mod.command && c.selectable) { - if (!c.selected) { + if (!c.selected || p_button==BUTTON_RIGHT) { p_item->select(col); emit_signal("multi_selected",p_item,col,true); + if (p_button==BUTTON_RIGHT) { + emit_signal("item_rmb_selected",get_local_mouse_pos()); + } //p_item->selected_signal.call(col); @@ -1597,15 +1600,25 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ bool inrange=false; select_single_item( p_item, root, col,selected_item,&inrange ); + if (p_button==BUTTON_RIGHT) { + emit_signal("item_rmb_selected",get_local_mouse_pos()); + } } else { int icount = _count_selected_items(root); - if (select_mode==SELECT_MULTI && icount>1) { + if (select_mode==SELECT_MULTI && icount>1 && p_button!=BUTTON_RIGHT) { single_select_defer=p_item; single_select_defer_column=col; } else { - select_single_item( p_item, root, col ); + + if (p_button!=BUTTON_RIGHT || !c.selected) { + select_single_item( p_item, root, col ); + } + + if (p_button==BUTTON_RIGHT) { + emit_signal("item_rmb_selected",get_local_mouse_pos()); + } } } @@ -2348,12 +2361,13 @@ void Tree::_input_event(InputEvent p_event) { } switch(b.button_index) { + case BUTTON_RIGHT: case BUTTON_LEFT: { Ref<StyleBox> bg = cache.bg; Point2 pos = Point2(b.x,b.y) - bg->get_offset(); cache.click_type=Cache::CLICK_NONE; - if (show_column_titles) { + if (show_column_titles && b.button_index==BUTTON_LEFT) { pos.y-=_get_title_button_height(); if (pos.y<0) { @@ -2390,6 +2404,9 @@ void Tree::_input_event(InputEvent p_event) { } + if (b.button_index==BUTTON_RIGHT) + break; + if (drag_touching) { set_fixed_process(false); drag_touching_deaccel=false; @@ -3465,6 +3482,17 @@ bool Tree::get_single_select_cell_editing_only_when_already_selected() const { return force_select_on_already_selected; } + +void Tree::set_allow_rmb_select(bool p_allow) { + + allow_rmb_select=p_allow; +} + +bool Tree::get_allow_rmb_select() const{ + + return allow_rmb_select; +} + void Tree::_bind_methods() { ObjectTypeDB::bind_method(_MD("_range_click_timeout"),&Tree::_range_click_timeout); @@ -3515,10 +3543,15 @@ void Tree::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_drop_mode_flags","flags"),&Tree::set_drop_mode_flags); ObjectTypeDB::bind_method(_MD("get_drop_mode_flags"),&Tree::get_drop_mode_flags); + ObjectTypeDB::bind_method(_MD("set_allow_rmb_select","allow"),&Tree::set_allow_rmb_select); + ObjectTypeDB::bind_method(_MD("get_allow_rmb_select"),&Tree::get_allow_rmb_select); + + ObjectTypeDB::bind_method(_MD("set_single_select_cell_editing_only_when_already_selected","enable"),&Tree::set_single_select_cell_editing_only_when_already_selected); ObjectTypeDB::bind_method(_MD("get_single_select_cell_editing_only_when_already_selected"),&Tree::get_single_select_cell_editing_only_when_already_selected); ADD_SIGNAL( MethodInfo("item_selected")); + ADD_SIGNAL( MethodInfo("item_rmb_selected",PropertyInfo(Variant::VECTOR2,"pos"))); ADD_SIGNAL( MethodInfo("cell_selected")); ADD_SIGNAL( MethodInfo("multi_selected",PropertyInfo(Variant::OBJECT,"item"),PropertyInfo(Variant::INT,"column"),PropertyInfo(Variant::BOOL,"selected")) ); ADD_SIGNAL( MethodInfo("item_edited")); @@ -3623,6 +3656,8 @@ Tree::Tree() { drop_mode_section=0; single_select_defer=NULL; force_select_on_already_selected=false; + + allow_rmb_select=false; } diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 4d0167ebb8..1dad26dffe 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -438,6 +438,7 @@ friend class TreeItem; bool drag_touching; bool drag_touching_deaccel; bool click_handled; + bool allow_rmb_select; bool force_select_on_already_selected; @@ -519,6 +520,9 @@ public: void set_single_select_cell_editing_only_when_already_selected(bool p_enable); bool get_single_select_cell_editing_only_when_already_selected() const; + void set_allow_rmb_select(bool p_allow); + bool get_allow_rmb_select() const; + void set_value_evaluator(ValueEvaluator *p_evaluator); Tree(); |