summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-12-14 10:24:28 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-12-14 10:24:28 -0300
commit83e0e97214a4fad635e5992bbbbd413642d76436 (patch)
tree6ed60e21e525a2f771b521da2876011e5e9fe858
parent1312df7fdcf9fceff63cf82bf97d6101c2c52215 (diff)
-implement arrows on tabs, when too many tabs are present, fixes #2806
-rw-r--r--scene/2d/canvas_item.cpp4
-rw-r--r--scene/2d/canvas_item.h2
-rw-r--r--scene/gui/tabs.cpp129
-rw-r--r--scene/gui/tabs.h6
-rw-r--r--scene/resources/default_theme/default_theme.cpp4
5 files changed, 141 insertions, 4 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index 295a57d033..275e4d0304 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<Texture>& p_texture,const Point2& p_pos) {
+void CanvasItem::draw_texture(const Ref<Texture>& 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<Texture>& 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<Texture>& 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 667fedc956..4c0386b953 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<Texture>& p_texture,const Point2& p_pos);
+ void draw_texture(const Ref<Texture>& p_texture, const Point2& p_pos, const Color &p_modulate=Color(1,1,1,1));
void draw_texture_rect(const Ref<Texture>& 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<Texture>& 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<StyleBox>& p_style_box,const Rect2& p_rect);
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 47a55e0716..5f4215a1d5 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<Texture> incr = get_icon("increment");
+ Ref<Texture> 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<tabs.size();i++) {
@@ -163,9 +181,34 @@ void Tabs::_input_event(const InputEvent& p_event) {
// clicks
Point2 pos( p_event.mouse_button.x, p_event.mouse_button.y );
+ if (buttons_visible) {
+
+ Ref<Texture> incr = get_icon("increment");
+ Ref<Texture> 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<tabs.size();i++) {
+ if (i<offset)
+ continue;
if (tabs[i].rb_rect.has_point(pos)) {
rb_pressing=true;
update();
@@ -225,7 +268,46 @@ void Tabs::_notification(int p_what) {
int w=0;
- int mw = get_minimum_size().width;
+ int mw = 0;
+
+ {
+
+
+ // h+=MIN( get_constant("label_valign_fg"), get_constant("label_valign_bg") );
+
+ for(int i=0;i<tabs.size();i++) {
+
+ Ref<Texture> 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<Texture> 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<Texture> 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<Texture> incr = get_icon("increment");
+ Ref<Texture> decr = get_icon("decrement");
+ Ref<Texture> incr_hl = get_icon("increment_hilite");
+ Ref<Texture> 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;i<tabs.size();i++) {
+ if (i<offset)
+ continue;
tabs[i].ofs_cache=w;
String s = tabs[i].text;
@@ -247,6 +340,8 @@ void Tabs::_notification(int p_what) {
int slen=font->get_string_size(s).width;
lsize+=slen;
+
+
Ref<Texture> 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<StyleBox> 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 1a8352bc93..48fbed1f76 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<Tab> 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 25407a5b84..33e1eb338e 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 );