diff options
Diffstat (limited to 'scene/gui')
| -rw-r--r-- | scene/gui/color_picker.cpp | 77 | ||||
| -rw-r--r-- | scene/gui/color_picker.h | 9 | ||||
| -rw-r--r-- | scene/gui/control.cpp | 4 | ||||
| -rw-r--r-- | scene/gui/line_edit.cpp | 9 | ||||
| -rw-r--r-- | scene/gui/tabs.cpp | 1 | ||||
| -rw-r--r-- | scene/gui/tree.cpp | 30 | ||||
| -rw-r--r-- | scene/gui/tree.h | 6 |
7 files changed, 111 insertions, 25 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 8685ec1c99..7b553543b6 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -64,7 +64,18 @@ void ColorPicker::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { btn_pick->set_icon(get_icon("screen_picker", "ColorPicker")); + update_material(uv_material, color); + update_material(w_material, color); + + uv_edit->get_child(0)->cast_to<Control>()->update(); + w_edit->get_child(0)->cast_to<Control>()->update(); + _update_color(); } + + case NOTIFICATION_VISIBILITY_CHANGED: { + c_text->call_deferred("grab_focus"); + c_text->call_deferred("select"); + } break; } } @@ -88,8 +99,13 @@ void ColorPicker::set_color(const Color& p_color) { h=color.get_h(); s=color.get_s(); v=color.get_v(); + + if (!is_inside_tree()) + return; + update_material(uv_material, color); update_material(w_material, color); + uv_edit->get_child(0)->cast_to<Control>()->update(); w_edit->get_child(0)->cast_to<Control>()->update(); _update_color(); @@ -100,6 +116,10 @@ void ColorPicker::set_edit_alpha(bool p_show) { edit_alpha=p_show; _update_controls(); + + if (!is_inside_tree()) + return; + _update_color(); sample->update(); } @@ -122,7 +142,7 @@ void ColorPicker::_value_changed(double) { update_material(uv_material,color); update_material(w_material,color); - html->set_text(color.to_html(edit_alpha && color.a<1)); + c_text->set_text(color.to_html(edit_alpha && color.a<1)); sample->update(); @@ -136,6 +156,10 @@ void ColorPicker::_html_entered(const String& p_html) { return; color = Color::html(p_html); + + if (!is_inside_tree()) + return; + _update_color(); emit_signal("color_changed",color); } @@ -153,7 +177,16 @@ void ColorPicker::_update_color() { scroll[i]->set_val(color.components[i]*255); } - html->set_text(color.to_html(edit_alpha && color.a<1)); + if (text_is_constructor) { + String t = "Color("+String::num(color.r)+","+String::num(color.g)+","+String::num(color.b); + if (edit_alpha && color.a<1) + t+=(","+String::num(color.a)+")") ; + else + t+=")"; + c_text->set_text(t); + } else { + c_text->set_text(color.to_html(edit_alpha && color.a<1)); + } sample->update(); updating=false; @@ -173,6 +206,21 @@ void ColorPicker::_update_presets() preset->set_texture(t); } +void ColorPicker::_text_type_toggled() +{ + if (!get_tree()->is_editor_hint()) + return; + text_is_constructor = !text_is_constructor; + if (text_is_constructor) { + text_type->set_text(""); + text_type->set_icon(get_icon("Script", "EditorIcons")); + } else { + text_type->set_text("#"); + text_type->set_icon(NULL); + } + _update_color(); +} + Color ColorPicker::get_color() const { return color; @@ -199,6 +247,9 @@ void ColorPicker::set_raw_mode(bool p_enabled) { if (btn_mode->is_pressed()!=p_enabled) btn_mode->set_pressed(p_enabled); + if (!is_inside_tree()) + return; + _update_controls(); _update_color(); } @@ -364,6 +415,7 @@ void ColorPicker::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_preset"), &ColorPicker::add_preset); ObjectTypeDB::bind_method(_MD("_value_changed"),&ColorPicker::_value_changed); ObjectTypeDB::bind_method(_MD("_html_entered"),&ColorPicker::_html_entered); + ObjectTypeDB::bind_method(_MD("_text_type_toggled"),&ColorPicker::_text_type_toggled); ObjectTypeDB::bind_method(_MD("_add_preset_pressed"), &ColorPicker::_add_preset_pressed); ObjectTypeDB::bind_method(_MD("_screen_pick_pressed"), &ColorPicker::_screen_pick_pressed); ObjectTypeDB::bind_method(_MD("_sample_draw"),&ColorPicker::_sample_draw); @@ -381,6 +433,7 @@ ColorPicker::ColorPicker() : updating=true; edit_alpha=true; + text_is_constructor = false; raw_mode_enabled=false; changing_color=false; screen=NULL; @@ -490,18 +543,20 @@ ColorPicker::ColorPicker() : btn_mode->connect("toggled", this, "set_raw_mode"); hhb->add_child(btn_mode); vbr->add_child(hhb); - html_num = memnew( Label ); - hhb->add_child(html_num); + text_type = memnew( Button ); + text_type->set_flat(true); + text_type->connect("pressed", this, "_text_type_toggled"); + hhb->add_child(text_type); - html = memnew( LineEdit ); - hhb->add_child(html); - html->connect("text_entered",this,"_html_entered"); - html_num->set_text("#"); - html->set_h_size_flags(SIZE_EXPAND_FILL); + c_text = memnew( LineEdit ); + hhb->add_child(c_text); + c_text->connect("text_entered",this,"_html_entered"); + text_type->set_text("#"); + c_text->set_h_size_flags(SIZE_EXPAND_FILL); _update_controls(); - _update_color(); + //_update_color(); updating=false; uv_material.instance(); @@ -564,6 +619,8 @@ void ColorPickerButton::pressed() { popup->set_pos(get_global_pos()-Size2(0,ms.height)); popup->set_size(ms); popup->popup(); + + } void ColorPickerButton::_notification(int p_what) { diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index c6c7fe537d..35f4ae7a99 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -62,10 +62,11 @@ private: HSlider *scroll[4]; SpinBox *values[4]; Label *labels[4]; - Label *html_num; - LineEdit *html; + Button *text_type; + LineEdit *c_text; bool edit_alpha; Size2i ms; + bool text_is_constructor; Color color; bool raw_mode_enabled; @@ -78,6 +79,7 @@ private: void _update_controls(); void _update_color(); void _update_presets(); + void _text_type_toggled(); void _sample_draw(); void _hsv_draw(int p_wich,Control *c); @@ -87,6 +89,9 @@ private: void _screen_input(const InputEvent& p_input); void _add_preset_pressed(); void _screen_pick_pressed(); + +friend class ColorPicker; + protected: void _notification(int); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 71a0f50240..c319e306e0 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1597,7 +1597,9 @@ bool Control::has_focus() const { void Control::grab_focus() { - ERR_FAIL_COND(!is_inside_tree()); + if (!is_inside_tree()){ + ERR_FAIL_COND(!is_inside_tree()); + } if (data.focus_mode==FOCUS_NONE) return; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index fdced3f62f..2a62ab30fc 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -80,8 +80,8 @@ void LineEdit::_input_event(InputEvent p_event) { selection.creating=false; selection.doubleclick=false; - // notify to show soft keyboard - notification(NOTIFICATION_FOCUS_ENTER); + if (OS::get_singleton()->has_virtual_keyboard()) + OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect()); } update(); @@ -230,8 +230,9 @@ void LineEdit::_input_event(InputEvent p_event) { case KEY_RETURN: { emit_signal( "text_entered",text ); - // notify to hide soft keyboard - notification(NOTIFICATION_FOCUS_EXIT); + if (OS::get_singleton()->has_virtual_keyboard()) + OS::get_singleton()->hide_virtual_keyboard(); + return; } break; diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index ecce71bdbd..c3e75842c3 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -633,7 +633,6 @@ int Tabs::get_tab_width(int p_idx) const { x+=tab_bg->get_minimum_size().width; if (tabs[p_idx].right_button.is_valid()) { - print_line("has right"); Ref<Texture> rb=tabs[p_idx].right_button; Size2 bms = rb->get_size();//+get_stylebox("button")->get_minimum_size(); bms.width+=get_constant("hseparation"); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index e81c08dbea..05b1e8bcea 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; @@ -1730,6 +1748,8 @@ void Tree::_text_editor_modal_close() { return; } + if (value_editor->has_point(value_editor->get_local_mouse_pos())) + return; text_editor_enter(text_editor->get_text()); } @@ -2316,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++) { diff --git a/scene/gui/tree.h b/scene/gui/tree.h index e4d349978c..e5c95b4d66 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -86,8 +86,9 @@ friend class Tree; struct Button { int id; + bool disabled; Ref<Texture> texture; - Button() { id=0; } + Button() { id=0; disabled=false; } }; Vector< Button > buttons; @@ -172,12 +173,13 @@ public: void set_icon_max_width(int p_column,int p_max); int get_icon_max_width(int p_column) const; - void add_button(int p_column,const Ref<Texture>& p_button,int p_id=-1); + void add_button(int p_column,const Ref<Texture>& p_button,int p_id=-1,bool p_disabled=false); int get_button_count(int p_column) const; Ref<Texture> get_button(int p_column,int p_idx) const; int get_button_id(int p_column,int p_idx) const; void erase_button(int p_column,int p_idx); int get_button_by_id(int p_column,int p_id) const; + bool is_button_disabled(int p_column,int p_idx) const; void set_button(int p_column,int p_idx,const Ref<Texture>& p_button); /* range works for mode number or mode combo */ |