diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 295a57d033a..275e4d03040 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -709,7 +709,7 @@ void CanvasItem::draw_circle(const Point2& p_pos, float p_radius, const Color& p } -void CanvasItem::draw_texture(const Ref& p_texture,const Point2& p_pos) { +void CanvasItem::draw_texture(const Ref& p_texture,const Point2& p_pos,const Color& p_modulate) { if (!drawing) { ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); @@ -718,7 +718,7 @@ void CanvasItem::draw_texture(const Ref& p_texture,const Point2& p_pos) ERR_FAIL_COND(p_texture.is_null()); - p_texture->draw(canvas_item,p_pos); + p_texture->draw(canvas_item,p_pos,p_modulate); } void CanvasItem::draw_texture_rect(const Ref& p_texture,const Rect2& p_rect, bool p_tile,const Color& p_modulate, bool p_transpose) { diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 667fedc9566..4c0386b953b 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -211,7 +211,7 @@ public: void draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width=1.0); void draw_rect(const Rect2& p_rect, const Color& p_color); void draw_circle(const Point2& p_pos, float p_radius, const Color& p_color); - void draw_texture(const Ref& p_texture,const Point2& p_pos); + void draw_texture(const Ref& p_texture, const Point2& p_pos, const Color &p_modulate=Color(1,1,1,1)); void draw_texture_rect(const Ref& p_texture, const Rect2& p_rect, bool p_tile=false,const Color& p_modulate=Color(1,1,1), bool p_transpose=false); void draw_texture_rect_region(const Ref& p_texture,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1), bool p_transpose=false); void draw_style_box(const Ref& p_style_box,const Rect2& p_rect); diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 47a55e07167..5f4215a1d50 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -74,6 +74,7 @@ Size2 Tabs::get_minimum_size() const { } } + ms.width=0; //should make this optional return ms; } @@ -85,6 +86,23 @@ void Tabs::_input_event(const InputEvent& p_event) { Point2 pos( p_event.mouse_motion.x, p_event.mouse_motion.y ); + hilite_arrow=-1; + if (buttons_visible) { + + Ref incr = get_icon("increment"); + Ref decr = get_icon("decrement"); + + int limit=get_size().width-incr->get_width()-decr->get_width(); + + if (pos.x>limit+decr->get_width()) { + hilite_arrow=1; + } else if (pos.x>limit) { + hilite_arrow=0; + } + } + + + int hover_buttons=-1; hover=-1; for(int i=0;i incr = get_icon("increment"); + Ref decr = get_icon("decrement"); + + int limit=get_size().width-incr->get_width()-decr->get_width(); + + if (pos.x>limit+decr->get_width()) { + if (missing_right) { + offset++; + update(); + } + return; + } else if (pos.x>limit) { + if (offset>0) { + offset--; + update(); + } + return; + } + } + + int found=-1; for(int i=0;i tex = tabs[i].icon; + if (tex.is_valid()) { + if (tabs[i].text!="") + mw+=get_constant("hseparation"); + + } + mw+=font->get_string_size(tabs[i].text).width; + if (current==i) + mw+=tab_fg->get_minimum_size().width; + else + mw+=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"); + + mw+=bms.width; + } + + if (tabs[i].close_button.is_valid()) { + Ref cb=tabs[i].close_button; + Size2 bms = cb->get_size();//+get_stylebox("button")->get_minimum_size(); + bms.width+=get_constant("hseparation"); + mw+=bms.width; + } + } + + } + + if (tab_align==ALIGN_CENTER) { w=(get_size().width-mw)/2; @@ -238,8 +320,19 @@ void Tabs::_notification(int p_what) { w=0; } + Ref incr = get_icon("increment"); + Ref decr = get_icon("decrement"); + Ref incr_hl = get_icon("increment_hilite"); + Ref decr_hl = get_icon("decrement_hilite"); + + int limit=get_size().width - incr->get_size().width - decr->get_size().width; + + missing_right=false; + for(int i=0;iget_string_size(s).width; lsize+=slen; + + Ref icon; if (tabs[i].icon.is_valid()) { icon = tabs[i].icon; @@ -319,6 +414,16 @@ void Tabs::_notification(int p_what) { } + if (w+lsize > limit) { + max_drawn_tab=i-1; + missing_right=true; + break; + } else { + max_drawn_tab=i; + } + + + Ref sb; int va; Color col; @@ -484,6 +589,25 @@ void Tabs::_notification(int p_what) { } + if (offset>0 || missing_right) { + + int vofs = (get_size().height-incr->get_size().height)/2; + + if (offset>0) + draw_texture(hilite_arrow==0?decr_hl:decr,Point2(limit,vofs)); + else + draw_texture(decr,Point2(limit,vofs),Color(1,1,1,0.5)); + + if (missing_right) + draw_texture(hilite_arrow==1?incr_hl:incr,Point2(limit+decr->get_size().width,vofs)); + else + draw_texture(incr,Point2(limit+decr->get_size().width,vofs),Color(1,1,1,0.5)); + + buttons_visible=true; + } else { + buttons_visible=false; + } + } break; } @@ -673,8 +797,11 @@ Tabs::Tabs() { tab_align=ALIGN_CENTER; rb_hover=-1; rb_pressing=false; + hilite_arrow=-1; cb_hover=-1; cb_pressing=false; cb_displaypolicy = SHOW_NEVER; // Default : no close button + offset=0; + max_drawn_tab=0; } diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h index 1a8352bc932..48fbed1f76e 100644 --- a/scene/gui/tabs.h +++ b/scene/gui/tabs.h @@ -65,6 +65,12 @@ private: Rect2 cb_rect; }; + + int offset; + int max_drawn_tab; + int hilite_arrow; + bool buttons_visible; + bool missing_right; Vector tabs; int current; Control *_get_tab(int idx) const; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 25407a5b845..33e1eb338e6 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -709,6 +709,10 @@ void make_default_theme() { t->set_stylebox("button_pressed","Tabs", make_stylebox( button_pressed_png,4,4,4,4) ); t->set_stylebox("button","Tabs", make_stylebox( button_normal_png,4,4,4,4) ); + t->set_icon("increment","Tabs",make_icon( scroll_button_right_png)); + t->set_icon("increment_hilite","Tabs",make_icon( scroll_button_right_hl_png)); + t->set_icon("decrement","Tabs",make_icon( scroll_button_left_png)); + t->set_icon("decrement_hilite","Tabs",make_icon( scroll_button_left_hl_png)); t->set_font("font","Tabs", default_font );