diff options
Diffstat (limited to 'scene/gui/tree.cpp')
| -rw-r--r-- | scene/gui/tree.cpp | 71 |
1 files changed, 41 insertions, 30 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 66ce117c9..05b1e8bce 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -482,7 +482,7 @@ void TreeItem::deselect(int p_column) { _cell_deselected(p_column); } -void TreeItem::add_button(int p_column,const Ref<Texture>& p_button,int p_id) { +void TreeItem::add_button(int p_column, const Ref<Texture>& p_button, int p_id, bool p_disabled) { ERR_FAIL_INDEX( p_column, cells.size() ); @@ -492,6 +492,7 @@ void TreeItem::add_button(int p_column,const Ref<Texture>& p_button,int p_id) { if (p_id<0) p_id=cells[p_column].buttons.size(); button.id=p_id; + button.disabled=p_disabled; cells[p_column].buttons.push_back(button); _changed_notify(p_column); } @@ -533,6 +534,15 @@ int TreeItem::get_button_by_id(int p_column,int p_id) const { return -1; } + +bool TreeItem::is_button_disabled(int p_column, int p_idx) const { + + ERR_FAIL_INDEX_V( p_column, cells.size(), false ); + ERR_FAIL_INDEX_V( p_idx, cells[p_column].buttons.size(), false ); + + return cells[p_column].buttons[p_idx].disabled; + +} void TreeItem::set_button(int p_column,int p_idx,const Ref<Texture>& p_button){ ERR_FAIL_COND( p_button.is_null() ); @@ -672,10 +682,11 @@ void TreeItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("clear_custom_bg_color","column"),&TreeItem::clear_custom_bg_color); ObjectTypeDB::bind_method(_MD("get_custom_bg_color","column"),&TreeItem::get_custom_bg_color); - ObjectTypeDB::bind_method(_MD("add_button","column","button:Texture","button_idx"),&TreeItem::add_button); + ObjectTypeDB::bind_method(_MD("add_button","column","button:Texture","button_idx","disabled"),&TreeItem::add_button,DEFVAL(-1),DEFVAL(false)); ObjectTypeDB::bind_method(_MD("get_button_count","column"),&TreeItem::get_button_count); ObjectTypeDB::bind_method(_MD("get_button:Texture","column","button_idx"),&TreeItem::get_button); ObjectTypeDB::bind_method(_MD("erase_button","column","button_idx"),&TreeItem::erase_button); + ObjectTypeDB::bind_method(_MD("is_button_disabled","column","button_idx"),&TreeItem::is_button_disabled); ObjectTypeDB::bind_method(_MD("set_tooltip","column","tooltip"),&TreeItem::set_tooltip); ObjectTypeDB::bind_method(_MD("get_tooltip","column"),&TreeItem::get_tooltip); @@ -1015,14 +1026,15 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& Point2i o = Point2i( ofs+w-s.width, p_pos.y )-cache.offset+p_draw_ofs; - if (cache.click_type==Cache::CLICK_BUTTON && cache.click_item==p_item && cache.click_column==i) { + if (cache.click_type==Cache::CLICK_BUTTON && cache.click_item==p_item && cache.click_column==i && !p_item->cells[i].buttons[j].disabled) { //being pressed cache.button_pressed->draw(get_canvas_item(),Rect2(o,s)); } o.y+=(label_h-s.height)/2; o+=cache.button_pressed->get_offset(); - b->draw(ci,o); + + b->draw(ci,o,p_item->cells[i].buttons[j].disabled?Color(1,1,1,0.5):Color(1,1,1,1)); w-=s.width+cache.button_margin; bw+=s.width+cache.button_margin; } @@ -1472,7 +1484,13 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ for(int j=c.buttons.size()-1;j>=0;j--) { Ref<Texture> b=c.buttons[j].texture; int w = b->get_size().width + cache.button_pressed->get_minimum_size().width; + if (x>col_width-w) { + if (c.buttons[j].disabled) { + pressed_button=-1; + cache.click_type=Cache::CLICK_NONE; + return -1; + } pressed_button=j; cache.click_type=Cache::CLICK_BUTTON; cache.click_index=j; @@ -1721,9 +1739,24 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ } +void Tree::_text_editor_modal_close() { + + if ( Input::get_singleton()->is_key_pressed(KEY_ESCAPE) || + Input::get_singleton()->is_key_pressed(KEY_ENTER) || + Input::get_singleton()->is_key_pressed(KEY_RETURN) ) { + + return; + } + + if (value_editor->has_point(value_editor->get_local_mouse_pos())) + return; + + text_editor_enter(text_editor->get_text()); +} + + void Tree::text_editor_enter(String p_text) { - text_changed=false; text_editor->hide(); value_editor->hide(); @@ -1762,22 +1795,6 @@ void Tree::text_editor_enter(String p_text) { } -void Tree::text_editor_changed(String p_text) { - - text_changed=true; -} - -void Tree::text_editor_hide() { - - if (!text_changed) - return; - - if (Input::get_singleton()->is_key_pressed(KEY_ESCAPE)) - return; - - text_editor_enter(text_editor->get_text()); -} - void Tree::value_editor_changed(double p_value) { if (updating_value_editor) { @@ -2319,7 +2336,7 @@ bool Tree::edit_selected() { return false; Rect2 rect; - rect.pos.y = get_item_offset(s) - v_scroll->get_val(); + rect.pos.y = get_item_offset(s) - get_scroll().y; for(int i=0;i<col;i++) { @@ -2367,8 +2384,6 @@ bool Tree::edit_selected() { } else if (c.mode==TreeItem::CELL_MODE_STRING || c.mode==TreeItem::CELL_MODE_RANGE) { - text_changed=false; - Point2i textedpos=get_global_pos() + rect.pos; text_editor->set_pos( textedpos ); text_editor->set_size( rect.size); @@ -3204,8 +3219,7 @@ void Tree::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&Tree::_input_event); ObjectTypeDB::bind_method(_MD("_popup_select"),&Tree::popup_select); ObjectTypeDB::bind_method(_MD("_text_editor_enter"),&Tree::text_editor_enter); - ObjectTypeDB::bind_method(_MD("_text_editor_changed"),&Tree::text_editor_changed); - ObjectTypeDB::bind_method(_MD("_text_editor_hide"),&Tree::text_editor_hide); + ObjectTypeDB::bind_method(_MD("_text_editor_modal_close"),&Tree::_text_editor_modal_close); ObjectTypeDB::bind_method(_MD("_value_editor_changed"),&Tree::value_editor_changed); ObjectTypeDB::bind_method(_MD("_scroll_moved"),&Tree::_scroll_moved); @@ -3304,8 +3318,7 @@ Tree::Tree() { h_scroll->connect("value_changed", this,"_scroll_moved"); v_scroll->connect("value_changed", this,"_scroll_moved"); text_editor->connect("text_entered", this,"_text_editor_enter"); - text_editor->connect("text_changed",this,"_text_editor_changed"); - text_editor->connect("hide",this,"_text_editor_hide"); + text_editor->connect("modal_close", this,"_text_editor_modal_close"); popup_menu->connect("item_pressed", this,"_popup_select"); value_editor->connect("value_changed", this,"_value_editor_changed"); @@ -3339,8 +3352,6 @@ Tree::Tree() { hide_folding=false; - text_changed=false; - } |
