diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/item_list.cpp | 60 | ||||
-rw-r--r-- | scene/gui/item_list.h | 9 | ||||
-rw-r--r-- | scene/gui/tabs.cpp | 48 | ||||
-rw-r--r-- | scene/gui/tabs.h | 16 | ||||
-rw-r--r-- | scene/gui/tree.h | 2 |
5 files changed, 128 insertions, 7 deletions
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 2fd4d810de..c29f6625d3 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -11,6 +11,7 @@ void ItemList::add_item(const String& p_item,const Ref<Texture>& p_texture,bool item.selectable=p_selectable; item.selected=false; item.disabled=false; + item.custom_bg=Color(0,0,0,0); items.push_back(item); update(); @@ -26,6 +27,7 @@ void ItemList::add_icon_item(const Ref<Texture>& p_item,bool p_selectable){ item.selectable=p_selectable; item.selected=false; item.disabled=false; + item.custom_bg=Color(0,0,0,0); items.push_back(item); update(); @@ -85,6 +87,23 @@ Ref<Texture> ItemList::get_item_icon(int p_idx) const{ } +void ItemList::set_item_custom_bg_color(int p_idx,const Color& p_custom_bg_color) { + + ERR_FAIL_INDEX(p_idx,items.size()); + + items[p_idx].custom_bg=p_custom_bg_color; + +} + +Color ItemList::get_item_custom_bg_color(int p_idx) const { + + ERR_FAIL_INDEX_V(p_idx,items.size(),Color()); + + return items[p_idx].custom_bg; + +} + + void ItemList::set_item_tag_icon(int p_idx,const Ref<Texture>& p_tag_icon){ @@ -635,6 +654,7 @@ void ItemList::_notification(int p_what) { Ref<Font> font = get_font("font"); Color guide_color = get_color("guide_color"); Color font_color = get_color("font_color"); + Color font_color_selected = get_color("font_color_selected"); int font_height = font->get_height(); Vector<int> line_size_cache; Vector<int> line_limit_cache; @@ -781,6 +801,11 @@ void ItemList::_notification(int p_what) { if (current_columns==1) { rcache.size.width = width-rcache.pos.x; } + if (items[i].custom_bg.a>0.001) { + Rect2 r=rcache; + r.pos+=base_ofs; + draw_rect(r,items[i].custom_bg); + } if (items[i].selected) { Rect2 r=rcache; r.pos+=base_ofs; @@ -864,7 +889,7 @@ void ItemList::_notification(int p_what) { if (line>=max_text_lines) break; } - ofs+=font->draw_char(get_canvas_item(),text_ofs+Vector2(ofs+(max_len-line_size_cache[line])/2,line*(font_height+line_separation)).floor(),items[i].text[j],items[i].text[j+1],font_color); + ofs+=font->draw_char(get_canvas_item(),text_ofs+Vector2(ofs+(max_len-line_size_cache[line])/2,line*(font_height+line_separation)).floor(),items[i].text[j],items[i].text[j+1],items[i].selected?font_color_selected:font_color); } //special multiline mode @@ -884,7 +909,7 @@ void ItemList::_notification(int p_what) { text_ofs+=base_ofs; text_ofs+=items[i].rect_cache.pos; - draw_string(font,text_ofs,items[i].text,font_color,max_len+1); + draw_string(font,text_ofs,items[i].text,items[i].selected?font_color_selected:font_color,max_len+1); } @@ -954,6 +979,30 @@ String ItemList::get_tooltip(const Point2& p_pos) const { } +void ItemList::sort_items_by_text() { + items.sort(); + update(); + if (select_mode==SELECT_SINGLE) { + for(int i=0;i<items.size();i++) { + if (items[i].selected) { + select(i); + return; + } + } + } +} + +int ItemList::find_metadata(const Variant& p_metadata) const { + + for(int i=0;i<items.size();i++) { + if (items[i].metadata==p_metadata) { + return i; + } + } + + return -1; + +} void ItemList::_bind_methods(){ @@ -972,6 +1021,12 @@ void ItemList::_bind_methods(){ ObjectTypeDB::bind_method(_MD("set_item_disabled","idx","disabled"),&ItemList::set_item_disabled); ObjectTypeDB::bind_method(_MD("is_item_disabled","idx"),&ItemList::is_item_disabled); + ObjectTypeDB::bind_method(_MD("set_item_metadata","idx","metadata"),&ItemList::set_item_metadata); + ObjectTypeDB::bind_method(_MD("get_item_metadata","idx"),&ItemList::get_item_metadata); + + ObjectTypeDB::bind_method(_MD("set_item_custom_bg_color","idx","custom_bg_color"),&ItemList::set_item_custom_bg_color); + ObjectTypeDB::bind_method(_MD("get_item_custom_bg_color","idx"),&ItemList::get_item_custom_bg_color); + ObjectTypeDB::bind_method(_MD("set_item_tooltip","idx","tooltip"),&ItemList::set_item_tooltip); ObjectTypeDB::bind_method(_MD("get_item_tooltip","idx"),&ItemList::get_item_tooltip); @@ -983,6 +1038,7 @@ void ItemList::_bind_methods(){ ObjectTypeDB::bind_method(_MD("remove_item","idx"),&ItemList::remove_item); ObjectTypeDB::bind_method(_MD("clear"),&ItemList::clear); + ObjectTypeDB::bind_method(_MD("sort_items_by_text"),&ItemList::clear); ObjectTypeDB::bind_method(_MD("set_fixed_column_width","width"),&ItemList::set_fixed_column_width); ObjectTypeDB::bind_method(_MD("get_fixed_column_width"),&ItemList::get_fixed_column_width); diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index 6bbb416970..237079c428 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -29,8 +29,12 @@ private: bool disabled; Variant metadata; String tooltip; + Color custom_bg; + Rect2 rect_cache; + + bool operator<(const Item& p_another) const { return text<p_another.text; } }; int current; @@ -85,6 +89,9 @@ public: void set_item_tooltip(int p_idx,const String& p_tooltip); String get_item_tooltip(int p_idx) const; + void set_item_custom_bg_color(int p_idx,const Color& p_custom_bg_color); + Color get_item_custom_bg_color(int p_idx) const; + void select(int p_idx,bool p_single=true); void unselect(int p_idx); bool is_selected(int p_idx) const; @@ -118,6 +125,8 @@ public: void ensure_current_is_visible(); + void sort_items_by_text(); + int find_metadata(const Variant& p_metadata) const; virtual String get_tooltip(const Point2& p_pos) const; diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 37369a7e6c..40a6e20c37 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -77,8 +77,8 @@ void Tabs::_input_event(const InputEvent& p_event) { for(int i=0;i<tabs.size();i++) { int ofs=tabs[i].ofs_cache; - - if (pos.x < ofs) { + int size = tabs[i].ofs_cache; + if (pos.x >=tabs[i].ofs_cache && pos.x<tabs[i].ofs_cache+tabs[i].size_cache) { found=i; break; @@ -89,6 +89,7 @@ void Tabs::_input_event(const InputEvent& p_event) { if (found!=-1) { set_current_tab(found); + emit_signal("tab_changed",found); } } @@ -117,8 +118,22 @@ void Tabs::_notification(int p_what) { int w=0; + int mw = get_minimum_size().width; + + if (tab_align==ALIGN_CENTER) { + w=(get_size().width-mw)/2; + } else if (tab_align==ALIGN_RIGHT) { + w=get_size().width-mw; + + } + + if (w<0) { + w=0; + } + for(int i=0;i<tabs.size();i++) { + tabs[i].ofs_cache=w; String s = tabs[i].text; int lsize=0; @@ -171,7 +186,7 @@ void Tabs::_notification(int p_what) { w+=slen+sb->get_margin(MARGIN_RIGHT); - tabs[i].ofs_cache=w; + tabs[i].size_cache=w-tabs[i].ofs_cache; } @@ -195,7 +210,7 @@ void Tabs::set_current_tab(int p_current) { current=p_current; _change_notify("current_tab"); - emit_signal("tab_changed",current); + //emit_signal("tab_changed",current); update(); } @@ -249,6 +264,12 @@ void Tabs::add_tab(const String& p_str,const Ref<Texture>& p_icon) { } +void Tabs::clear_tabs() { + tabs.clear(); + current=0; + update(); +} + void Tabs::remove_tab(int p_idx) { ERR_FAIL_INDEX(p_idx,tabs.size()); @@ -263,8 +284,19 @@ void Tabs::remove_tab(int p_idx) { if (current>=tabs.size()) current=tabs.size()-1; - emit_signal("tab_changed",current); + //emit_signal("tab_changed",current); + +} + +void Tabs::set_tab_align(TabAlign p_align) { + + tab_align=p_align; + update(); +} + +Tabs::TabAlign Tabs::get_tab_align() const { + return tab_align; } @@ -280,15 +312,21 @@ void Tabs::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_tab_icon:Texture","tab_idx"),&Tabs::get_tab_icon); ObjectTypeDB::bind_method(_MD("remove_tab","tab_idx"),&Tabs::remove_tab); ObjectTypeDB::bind_method(_MD("add_tab","title","icon:Texture"),&Tabs::add_tab); + ObjectTypeDB::bind_method(_MD("set_tab_align","align"),&Tabs::set_tab_align); + ObjectTypeDB::bind_method(_MD("get_tab_align"),&Tabs::get_tab_align); ADD_SIGNAL(MethodInfo("tab_changed",PropertyInfo(Variant::INT,"tab"))); ADD_PROPERTY( PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE,"-1,4096,1",PROPERTY_USAGE_EDITOR), _SCS("set_current_tab"), _SCS("get_current_tab") ); + BIND_CONSTANT( ALIGN_LEFT ); + BIND_CONSTANT( ALIGN_CENTER ); + BIND_CONSTANT( ALIGN_RIGHT ); } Tabs::Tabs() { current=0; + tab_align=ALIGN_CENTER; } diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h index 4a969928ff..8d4d0123f8 100644 --- a/scene/gui/tabs.h +++ b/scene/gui/tabs.h @@ -34,6 +34,14 @@ class Tabs : public Control { OBJ_TYPE( Tabs, Control ); +public: + + enum TabAlign { + + ALIGN_LEFT, + ALIGN_CENTER, + ALIGN_RIGHT + }; private: @@ -42,12 +50,14 @@ private: String text; Ref<Texture> icon; int ofs_cache; + int size_cache; }; Vector<Tab> tabs; int current; Control *_get_tab(int idx) const; int _get_top_margin() const; + TabAlign tab_align; protected: @@ -65,16 +75,22 @@ public: void set_tab_icon(int p_tab,const Ref<Texture>& p_icon); Ref<Texture> get_tab_icon(int p_tab) const; + void set_tab_align(TabAlign p_align); + TabAlign get_tab_align() const; + int get_tab_count() const; void set_current_tab(int p_current); int get_current_tab() const; void remove_tab(int p_idx); + void clear_tabs(); + Size2 get_minimum_size() const; Tabs(); }; +VARIANT_ENUM_CAST(Tabs::TabAlign); #endif // TABS_H diff --git a/scene/gui/tree.h b/scene/gui/tree.h index f03827f542..8ddddd0630 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -454,6 +454,8 @@ public: void set_cursor_can_exit_tree(bool p_enable); bool can_cursor_exit_tree() const; + VScrollBar *get_vscroll_bar() { return v_scroll; } + Tree(); ~Tree(); |