diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/base_button.cpp | 7 | ||||
-rw-r--r-- | scene/gui/color_picker.cpp | 12 | ||||
-rw-r--r-- | scene/gui/color_picker.h | 1 | ||||
-rw-r--r-- | scene/gui/color_ramp_edit.cpp | 4 | ||||
-rw-r--r-- | scene/gui/control.cpp | 19 | ||||
-rw-r--r-- | scene/gui/control.h | 2 | ||||
-rw-r--r-- | scene/gui/grid_container.cpp | 1 | ||||
-rw-r--r-- | scene/gui/item_list.cpp | 16 | ||||
-rw-r--r-- | scene/gui/item_list.h | 1 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 49 | ||||
-rw-r--r-- | scene/gui/line_edit.h | 6 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 7 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 7 |
13 files changed, 115 insertions, 17 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index d7632b14b8..699062fee4 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -31,6 +31,7 @@ #include "print_string.h" #include "button_group.h" #include "scene/scene_string_names.h" +#include "scene/main/viewport.h" void BaseButton::_input_event(InputEvent p_event) { @@ -415,7 +416,11 @@ Ref<ShortCut> BaseButton:: get_shortcut() const { void BaseButton::_unhandled_input(InputEvent p_event) { - if (!is_disabled() && is_visible() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { + if (!is_disabled() && is_visible() && p_event.is_pressed() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { + + if (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)) + return; //ignore because of modal window + if (is_toggle_mode()) { set_pressed(!is_pressed()); emit_signal("toggled",is_pressed()); diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index d6bbdf2d21..06f8c27957 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -72,13 +72,16 @@ void ColorPicker::_notification(int p_what) { _update_color(); } - case NOTIFICATION_VISIBILITY_CHANGED: { - c_text->call_deferred("grab_focus"); - c_text->call_deferred("select"); - } break; + } } +void ColorPicker::set_focus_on_line_edit() { + + c_text->grab_focus(); + c_text->select(); +} + void ColorPicker::_update_controls() { if (edit_alpha) { @@ -628,6 +631,7 @@ void ColorPickerButton::pressed() { popup->set_pos(get_global_pos()-Size2(0,ms.height)); popup->set_size(ms); popup->popup(); + picker->set_focus_on_line_edit(); } diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index f5de982200..b9ef1f1e2f 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -107,6 +107,7 @@ public: void set_raw_mode(bool p_enabled); bool is_raw_mode() const; + void set_focus_on_line_edit(); ColorPicker(); }; diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp index 50e1ffbec9..b7347f00dc 100644 --- a/scene/gui/color_ramp_edit.cpp +++ b/scene/gui/color_ramp_edit.cpp @@ -271,7 +271,9 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) { void ColorRampEdit::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_TREE) { - picker->connect("color_changed",this,"_color_changed"); + if (!picker->is_connected("color_changed",this,"_color_changed")) { + picker->connect("color_changed",this,"_color_changed"); + } } if (p_what==NOTIFICATION_DRAW) { diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 2e28baa137..fc27c0d24f 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -49,14 +49,22 @@ Variant Control::edit_get_state() const { - return get_rect(); + Dictionary s; + s["rect"]=get_rect(); + s["rot"]=get_rotation(); + s["scale"]=get_scale(); + return s; } void Control::edit_set_state(const Variant& p_state) { - Rect2 state=p_state; + Dictionary s=p_state; + + Rect2 state=s["rect"]; set_pos(state.pos); set_size(state.size); + set_rotation(s["rot"]); + set_scale(s["scale"]); } void Control::set_custom_minimum_size(const Size2& p_custom) { @@ -754,6 +762,11 @@ bool Control::is_window_modal_on_top() const { return get_viewport()->_gui_is_modal_on_top(this); } +uint64_t Control::get_modal_frame() const { + + return data.modal_frame; +} + Size2 Control::get_minimum_size() const { @@ -1829,6 +1842,7 @@ void Control::show_modal(bool p_exclusive) { raise(); data.modal_exclusive=p_exclusive; data.MI=get_viewport()->_gui_show_modal(this); + data.modal_frame=OS::get_singleton()->get_frames_drawn(); } @@ -2539,6 +2553,7 @@ Control::Control() { data.parent_canvas_item=NULL; data.scale=Vector2(1,1); data.drag_owner=0; + data.modal_frame=0; for (int i=0;i<4;i++) { diff --git a/scene/gui/control.h b/scene/gui/control.h index 07a28de1ea..830ebd1620 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -132,6 +132,7 @@ private: ObjectID drag_owner; bool modal; bool modal_exclusive; + uint64_t modal_frame; //frame used to put something as modal Ref<Theme> theme; Control *theme_owner; String tooltip; @@ -249,6 +250,7 @@ public: Size2 get_custom_minimum_size() const; bool is_window_modal_on_top() const; + uint64_t get_modal_frame() const; //frame in which this was made modal Control *get_parent_control() const; diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index dde9768a6d..5e6622b3f8 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -156,6 +156,7 @@ void GridContainer::_notification(int p_what) { void GridContainer::set_columns(int p_columns) { + ERR_FAIL_COND(p_columns<1); columns=p_columns; queue_sort(); minimum_size_changed(); diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 5379836746..d63c483ef9 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -1245,6 +1245,19 @@ real_t ItemList::get_icon_scale() const { return icon_scale; } +Vector<int> ItemList::get_selected_items() { + Vector<int> selected; + for (int i = 0; i < items.size(); i++) { + if (items[i].selected) { + selected.push_back(i); + if (this->select_mode == SELECT_SINGLE) { + break; + } + } + } + return selected; +} + void ItemList::_bind_methods(){ ObjectTypeDB::bind_method(_MD("add_item","text","icon:Texture","selectable"),&ItemList::add_item,DEFVAL(Variant()),DEFVAL(true)); @@ -1277,6 +1290,7 @@ void ItemList::_bind_methods(){ ObjectTypeDB::bind_method(_MD("select","idx","single"),&ItemList::select,DEFVAL(true)); ObjectTypeDB::bind_method(_MD("unselect","idx"),&ItemList::unselect); ObjectTypeDB::bind_method(_MD("is_selected","idx"),&ItemList::is_selected); + ObjectTypeDB::bind_method(_MD("get_selected_items"),&ItemList::get_selected_items); ObjectTypeDB::bind_method(_MD("get_item_count"),&ItemList::get_item_count); ObjectTypeDB::bind_method(_MD("remove_item","idx"),&ItemList::remove_item); @@ -1330,8 +1344,6 @@ void ItemList::_bind_methods(){ ADD_SIGNAL( MethodInfo("item_activated",PropertyInfo(Variant::INT,"index"))); } - - ItemList::ItemList() { current=-1; diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index aa6dd64c50..e1902d1c1f 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -144,6 +144,7 @@ public: void select(int p_idx,bool p_single=true); void unselect(int p_idx); bool is_selected(int p_idx) const; + Vector<int> get_selected_items(); void set_current(int p_current); int get_current() const; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 579a6e2f0a..c025e4c706 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -108,7 +108,7 @@ void LineEdit::_input_event(InputEvent p_event) { selection.doubleclick=false; if (OS::get_singleton()->has_virtual_keyboard()) - OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect()); + OS::get_singleton()->show_virtual_keyboard(text,get_global_rect()); } update(); @@ -556,7 +556,9 @@ void LineEdit::_notification(int p_what) { cursor_set_blink_enabled(EDITOR_DEF("text_editor/caret_blink", false)); cursor_set_blink_speed(EDITOR_DEF("text_editor/caret_blink_speed", 0.65)); - EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed"); + if (!EditorSettings::get_singleton()->is_connected("settings_changed",this,"_editor_settings_changed")) { + EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed"); + } } } break; #endif @@ -634,14 +636,19 @@ void LineEdit::_notification(int p_what) { Color font_color_selected=get_color("font_color_selected"); Color cursor_color=get_color("cursor_color"); + const String& t = text.empty() ? placeholder : text; + // draw placeholder color + if(text.empty()) + font_color.a *= placeholder_alpha; + while(true) { //end of string, break! - if (char_ofs>=text.length()) + if (char_ofs>=t.length()) break; - CharType cchar=pass?'*':text[char_ofs]; - CharType next=pass?'*':text[char_ofs+1]; + CharType cchar=pass?'*':t[char_ofs]; + CharType next=pass?'*':t[char_ofs+1]; int char_width=font->get_char_size( cchar,next ).width; // end of widget, break! @@ -678,7 +685,7 @@ void LineEdit::_notification(int p_what) { } if (OS::get_singleton()->has_virtual_keyboard()) - OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect()); + OS::get_singleton()->show_virtual_keyboard(text,get_global_rect()); } break; case NOTIFICATION_FOCUS_EXIT: { @@ -938,6 +945,29 @@ String LineEdit::get_text() const { return text; } +void LineEdit::set_placeholder(String p_text) { + + placeholder = p_text; + update(); +} + +String LineEdit::get_placeholder() const { + + return placeholder; +} + + +void LineEdit::set_placeholder_alpha(float p_alpha) { + + placeholder_alpha = p_alpha; + update(); +} + +float LineEdit::get_placeholder_alpha() const { + + return placeholder_alpha; +} + void LineEdit::set_cursor_pos(int p_pos) { if (p_pos>(int)text.length()) @@ -1223,6 +1253,10 @@ void LineEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("select_all"),&LineEdit::select_all); ObjectTypeDB::bind_method(_MD("set_text","text"),&LineEdit::set_text); ObjectTypeDB::bind_method(_MD("get_text"),&LineEdit::get_text); + ObjectTypeDB::bind_method(_MD("set_placeholder","text"),&LineEdit::set_placeholder); + ObjectTypeDB::bind_method(_MD("get_placeholder"),&LineEdit::get_placeholder); + ObjectTypeDB::bind_method(_MD("set_placeholder_alpha","alpha"),&LineEdit::set_placeholder_alpha); + ObjectTypeDB::bind_method(_MD("get_placeholder_alpha"),&LineEdit::get_placeholder_alpha); ObjectTypeDB::bind_method(_MD("set_cursor_pos","pos"),&LineEdit::set_cursor_pos); ObjectTypeDB::bind_method(_MD("get_cursor_pos"),&LineEdit::get_cursor_pos); ObjectTypeDB::bind_method(_MD("cursor_set_blink_enabled", "enable"),&LineEdit::cursor_set_blink_enabled); @@ -1257,6 +1291,8 @@ void LineEdit::_bind_methods() { BIND_CONSTANT( MENU_MAX ); ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "text" ), _SCS("set_text"),_SCS("get_text") ); + ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "placeholder/text" ), _SCS("set_placeholder"),_SCS("get_placeholder") ); + ADD_PROPERTYNZ( PropertyInfo( Variant::REAL, "placeholder/alpha",PROPERTY_HINT_RANGE,"0,1,0.001" ), _SCS("set_placeholder_alpha"),_SCS("get_placeholder_alpha") ); ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), _SCS("set_align"), _SCS("get_align")); ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "max_length" ), _SCS("set_max_length"),_SCS("get_max_length") ); ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "editable" ), _SCS("set_editable"),_SCS("is_editable") ); @@ -1275,6 +1311,7 @@ LineEdit::LineEdit() { window_has_focus=true; max_length = 0; pass=false; + placeholder_alpha=0.6; selection_clear(); set_focus_mode( FOCUS_ALL ); diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index e4da0f0b87..112e4ad55e 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -67,6 +67,8 @@ private: String undo_text; String text; + String placeholder; + float placeholder_alpha; PopupMenu *menu; @@ -135,6 +137,10 @@ public: void delete_text(int p_from_column, int p_to_column); void set_text(String p_text); String get_text() const; + void set_placeholder(String p_text); + String get_placeholder() const; + void set_placeholder_alpha(float p_alpha); + float get_placeholder_alpha() const; void set_cursor_pos(int p_pos); int get_cursor_pos() const; void set_max_length(int p_max_length); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 6fd6137ac8..e106f0dfc6 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -852,6 +852,11 @@ void TextEdit::_notification(int p_what) { k++; } + // check for space between name and bracket + while (k < str.length() && (str[k] == '\t' || str[k] == ' ')) { + k++; + } + if (str[k] == '(') { in_function_name = true; } @@ -1973,6 +1978,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } } break; case KEY_TAB: { + if (k.mod.command) break; // avoid tab when command if (readonly) break; @@ -4541,6 +4547,7 @@ TextEdit::TextEdit() { scroll_past_end_of_file_enabled=false; auto_brace_completion_enabled=false; brace_matching_enabled=false; + highlight_all_occurrences=false; auto_indent=false; insert_mode = false; window_has_focus=true; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index f8516f8f5d..db14c15db8 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1355,6 +1355,8 @@ void Tree::select_single_item(TreeItem *p_selected,TreeItem *p_current,int p_col switched=true; } + bool emitted_row=false; + for (int i=0;i<columns.size();i++) { TreeItem::Cell &c=p_current->cells[i]; @@ -1373,7 +1375,10 @@ void Tree::select_single_item(TreeItem *p_selected,TreeItem *p_current,int p_col selected_item=p_selected; selected_col=0; selected_item=p_selected; - emit_signal("item_selected"); + if (!emitted_row) { + emit_signal("item_selected"); + emitted_row=true; + } //if (p_col==i) // p_current->selected_signal.call(p_col); } |