From d50ebbb441cd6e1d2227d26cc168e76c7bff2b62 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 24 Jul 2015 14:18:02 -0300 Subject: -added icons for root node types on tabs --- scene/gui/tabs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scene/gui') diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 40a6e20c37..9c59547cba 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -142,7 +142,7 @@ void Tabs::_notification(int p_what) { Ref icon; if (tabs[i].icon.is_valid()) { - Ref icon = tabs[i].icon; + icon = tabs[i].icon; if (icon.is_valid()) { lsize+=icon->get_width(); if (s!="") -- cgit v1.2.3 From 07c99e11f5939699fefa10fab0b898ddc9246f85 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 26 Jul 2015 10:44:10 -0300 Subject: QOL, script buttons in scene tabs --- scene/gui/tabs.cpp | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++- scene/gui/tabs.h | 7 ++++ 2 files changed, 118 insertions(+), 2 deletions(-) (limited to 'scene/gui') diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 9c59547cba..a849d3ae72 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -56,7 +56,14 @@ Size2 Tabs::get_minimum_size() const { else ms.width+=tab_bg->get_minimum_size().width; + if (tabs[i].right_button.is_valid()) { + Ref rb=tabs[i].right_button; + Size2 bms = rb->get_size()+get_stylebox("button")->get_minimum_size(); + bms.width+=get_constant("hseparation"); + ms.width+=bms.width; + ms.height=MAX(bms.height+tab_bg->get_minimum_size().height,ms.height); + } } return ms; @@ -66,6 +73,39 @@ Size2 Tabs::get_minimum_size() const { void Tabs::_input_event(const InputEvent& p_event) { + if (p_event.type==InputEvent::MOUSE_MOTION) { + + Point2 pos( p_event.mouse_motion.x, p_event.mouse_motion.y ); + + int hover=-1; + for(int i=0;i=tabs[i].ofs_cache && pos.x style = get_stylebox("button"); + Ref rb=tabs[i].right_button; + + lsize+=get_constant("hseparation"); + lsize+=style->get_margin(MARGIN_LEFT); + lsize+=rb->get_width(); + lsize+=style->get_margin(MARGIN_RIGHT); + + } Ref sb; int va; @@ -184,7 +243,37 @@ void Tabs::_notification(int p_what) { font->draw(ci, Point2i( w, sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-font->get_height())/2+font->get_ascent() ), s, col ); - w+=slen+sb->get_margin(MARGIN_RIGHT); + w+=slen; + + if (tabs[i].right_button.is_valid()) { + Ref style = get_stylebox("button"); + Ref rb=tabs[i].right_button; + + w+=get_constant("hseparation"); + + Rect2 rb_rect; + rb_rect.size=style->get_minimum_size()+rb->get_size(); + rb_rect.pos.x=w; + rb_rect.pos.y=sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-(rb_rect.size.y))/2; + + if (rb_hover==i) { + if (rb_pressing) + get_stylebox("button_pressed")->draw(ci,rb_rect); + else + style->draw(ci,rb_rect); + } + + w+=style->get_margin(MARGIN_LEFT); + + rb->draw(ci,Point2i( w,rb_rect.pos.y+style->get_margin(MARGIN_TOP) )); + w+=rb->get_width(); + w+=style->get_margin(MARGIN_RIGHT); + tabs[i].rb_rect=rb_rect; + + + } + + w+=sb->get_margin(MARGIN_RIGHT); tabs[i].size_cache=w-tabs[i].ofs_cache; @@ -252,6 +341,23 @@ Ref Tabs::get_tab_icon(int p_tab) const{ } + + +void Tabs::set_tab_right_button(int p_tab,const Ref& p_right_button){ + + ERR_FAIL_INDEX(p_tab,tabs.size()); + tabs[p_tab].right_button=p_right_button; + update(); + minimum_size_changed(); + +} +Ref Tabs::get_tab_right_button(int p_tab) const{ + + ERR_FAIL_INDEX_V(p_tab,tabs.size(),Ref()); + return tabs[p_tab].right_button; + +} + void Tabs::add_tab(const String& p_str,const Ref& p_icon) { Tab t; @@ -316,6 +422,7 @@ void Tabs::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_tab_align"),&Tabs::get_tab_align); ADD_SIGNAL(MethodInfo("tab_changed",PropertyInfo(Variant::INT,"tab"))); + ADD_SIGNAL(MethodInfo("right_button_pressed",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") ); @@ -328,5 +435,7 @@ Tabs::Tabs() { current=0; tab_align=ALIGN_CENTER; + rb_hover=-1; + rb_pressing=false; } diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h index 8d4d0123f8..5cb0d9e916 100644 --- a/scene/gui/tabs.h +++ b/scene/gui/tabs.h @@ -51,6 +51,8 @@ private: Ref icon; int ofs_cache; int size_cache; + Ref right_button; + Rect2 rb_rect; }; Vector tabs; @@ -58,6 +60,8 @@ private: Control *_get_tab(int idx) const; int _get_top_margin() const; TabAlign tab_align; + int rb_hover; + bool rb_pressing; protected: @@ -75,6 +79,9 @@ public: void set_tab_icon(int p_tab,const Ref& p_icon); Ref get_tab_icon(int p_tab) const; + void set_tab_right_button(int p_tab,const Ref& p_right_button); + Ref get_tab_right_button(int p_tab) const; + void set_tab_align(TabAlign p_align); TabAlign get_tab_align() const; -- cgit v1.2.3