Selaa lähdekoodia

-work in progress implementation of NDEE's theme It's NOT DONE YET

Juan Linietsky 10 vuotta sitten
vanhempi
commit
d241b2ec1b

+ 51 - 38
scene/gui/tab_container.cpp

@@ -229,6 +229,18 @@ void TabContainer::_notification(int p_what) {
 
 			int w=0;
 			int idx=0;
+			Vector<int> offsets;
+			Vector<Control*> controls;
+			int from=0;
+			int limit=get_size().width;
+			if (popup) {
+				top_size.width-=menu->get_width();
+				limit-=menu->get_width();
+			}
+
+			bool notdone=false;
+			last_tab_cache=-1;
+
 			for(int i=0;i<get_child_count();i++) {
 
 				Control *c = get_child(i)->cast_to<Control>();
@@ -236,7 +248,20 @@ void TabContainer::_notification(int p_what) {
 					continue;
 				if (c->is_set_as_toplevel())
 					continue;
+				if (idx<tab_display_ofs) {
+					idx++;
+					from=idx;
+					continue;
+				}
 
+				if (w>=get_size().width) {
+					buttons_visible_cache=true;
+					notdone=true;
+					break;
+				}
+
+				offsets.push_back(w);
+				controls.push_back(c);
 
 				String s = c->has_meta("_tab_name")?String(XL_MESSAGE(String(c->get_meta("_tab_name")))):String(c->get_name());
 				w+=font->get_string_size(s).width;
@@ -257,55 +282,46 @@ void TabContainer::_notification(int p_what) {
 					w+=tab_bg->get_minimum_size().width;
 				}
 
-				idx++;
-			}
+				if (idx<tab_display_ofs) {
 
+				}
+				last_tab_cache=idx;
 
-			int ofs;
-			int limit=get_size().width;
-			if (popup) {
-				top_size.width-=menu->get_width();
-				limit-=menu->get_width();
+				idx++;
 			}
 
 
-			if (w<=limit) {
-				switch(align) {
+			int ofs;
 
-					case ALIGN_LEFT: ofs = side_margin; break;
-					case ALIGN_CENTER: ofs = (int(limit) - w)/2; break;
-					case ALIGN_RIGHT: ofs = int(limit) - w - side_margin; break;
-				};
+			switch(align) {
 
-				tab_display_ofs=0;
-				buttons_visible_cache=false;
-			} else {
+				case ALIGN_LEFT: ofs = side_margin; break;
+				case ALIGN_CENTER: ofs = (int(limit) - w)/2; break;
+				case ALIGN_RIGHT: ofs = int(limit) - w - side_margin; break;
+			};
 
-				ofs=0;
-				limit-=incr->get_width()+decr->get_width();
-				buttons_visible_cache=true;
-			}
+			tab_display_ofs=0;
 
 
 			tabs_ofs_cache=ofs;
-			last_tab_cache=-1;
 			idx=0;
-			bool notdone=false;
 
 
-			for(int i=0;i<get_child_count();i++) {
 
-				Control *c = get_child(i)->cast_to<Control>();
-				if (!c)
-					continue;
-				if (c->is_set_as_toplevel())
-					continue;
+			for(int i=0;i<controls.size();i++) {
 
-				if (idx<tab_display_ofs) {
-					idx++;
-					continue;
+				idx=i+from;
+				if (current>=from && current<from+controls.size()-1) {
+					//current is visible! draw it last.
+					if (i==controls.size()-1) {
+						idx=current;
+					} else if (idx>=current) {
+						idx+=1;
+					}
 				}
 
+				Control *c = controls[idx-from];
+
 				String s = c->has_meta("_tab_name")?String(c->get_meta("_tab_name")):String(c->get_name());
 				int w=font->get_string_size(s).width;
 				Ref<Texture> icon;
@@ -336,14 +352,12 @@ void TabContainer::_notification(int p_what) {
 					col=color_bg;
 				}
 
+				int lofs = ofs + offsets[idx-from];
 
 				Size2i sb_ms = sb->get_minimum_size();
-				Rect2 sb_rect = Rect2( ofs, 0, w+sb_ms.width, top_margin);
+				Rect2 sb_rect = Rect2( lofs, 0, w+sb_ms.width, top_margin);
+
 
-				if (sb_ms.width+w+ofs > limit) {
-					notdone=true;
-					break;
-				}
 				sb->draw(ci, sb_rect );
 
 				Point2i lpos = sb_rect.pos;
@@ -357,8 +371,7 @@ void TabContainer::_notification(int p_what) {
 				}
 
 				font->draw(ci, Point2i( lpos.x, sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-font->get_height())/2+font->get_ascent() ), s, col );
-				ofs+=sb_ms.x+w;
-				last_tab_cache=idx;
+				//ofs+=sb_ms.x+w;
 
 				/*
 				int sb_mw = sb->get_minimum_size().width;

BIN
scene/resources/default_theme/button_disabled.png


BIN
scene/resources/default_theme/button_hover.png


BIN
scene/resources/default_theme/button_normal.png


BIN
scene/resources/default_theme/button_pressed.png


+ 52 - 33
scene/resources/default_theme/default_theme.cpp

@@ -60,6 +60,16 @@ static Ref<StyleBoxTexture> make_stylebox(T p_src,float p_left, float p_top, flo
 	return style;
 }
 
+
+static Ref<StyleBoxTexture> sb_expand(Ref<StyleBoxTexture> p_sbox,float p_left, float p_top, float p_right, float p_botton) {
+
+	p_sbox->set_expand_margin_size(MARGIN_LEFT,p_left);
+	p_sbox->set_expand_margin_size(MARGIN_TOP,p_top);
+	p_sbox->set_expand_margin_size(MARGIN_RIGHT,p_right);
+	p_sbox->set_expand_margin_size(MARGIN_BOTTOM,p_botton);
+	return p_sbox;
+}
+
 template<class T>
 static Ref<Texture> make_icon(T p_src) {
 
@@ -195,18 +205,24 @@ void make_default_theme() {
 
 	Ref<StyleBoxTexture> focus = make_stylebox( focus_png,5,5,5,5);
 	for(int i=0;i<4;i++) {
-		focus->set_expand_margin_size(Margin(i),2);
+		focus->set_expand_margin_size(Margin(i),1);
 	}
 
 
 
 	// Button
 
-	t->set_stylebox("normal","Button", make_stylebox( button_normal_png,4,4,4,4,8,4,8,4) );
-	t->set_stylebox("pressed","Button", make_stylebox( button_pressed_png,4,4,4,4) );
-	t->set_stylebox("hover","Button", make_stylebox( button_hover_png,4,4,4,4) );
-	t->set_stylebox("disabled","Button", make_stylebox( button_disabled_png,4,4,4,4) );
-	t->set_stylebox("focus","Button", focus );
+	Ref<StyleBox> sb_button_normal = sb_expand( make_stylebox( button_normal_png,4,4,4,4,6,2,6,2),2,2,2,2);
+	Ref<StyleBox> sb_button_pressed = sb_expand( make_stylebox( button_pressed_png,4,4,4,4,6,2,6,2),2,2,2,2);
+	Ref<StyleBox> sb_button_hover = sb_expand( make_stylebox( button_hover_png,4,4,4,4,6,2,6,2),2,2,2,2);
+	Ref<StyleBox> sb_button_disabled = sb_expand( make_stylebox( button_disabled_png,4,4,4,4,6,2,6,2),2,2,2,2);
+	Ref<StyleBox> sb_button_focus = sb_expand( make_stylebox( button_focus_png,4,4,4,4,6,2,6,2),2,2,2,2);
+
+	t->set_stylebox("normal","Button", sb_button_normal);
+	t->set_stylebox("pressed","Button", sb_button_pressed);
+	t->set_stylebox("hover","Button", sb_button_hover);
+	t->set_stylebox("disabled","Button", sb_button_disabled);
+	t->set_stylebox("focus","Button", sb_button_focus);
 
 	t->set_font("font","Button", default_font );
 
@@ -221,11 +237,11 @@ void make_default_theme() {
 
 	// ColorPickerButton
 
-	t->set_stylebox("normal","ColorPickerButton", make_stylebox( button_normal_png,4,4,4,4) );
-	t->set_stylebox("pressed","ColorPickerButton", make_stylebox( button_pressed_png,4,4,4,4) );
-	t->set_stylebox("hover","ColorPickerButton", make_stylebox( button_hover_png,4,4,4,4) );
-	t->set_stylebox("disabled","ColorPickerButton", make_stylebox( button_disabled_png,4,4,4,4) );
-	t->set_stylebox("focus","ColorPickerButton", focus );
+	t->set_stylebox("normal","ColorPickerButton", sb_button_normal);
+	t->set_stylebox("pressed","ColorPickerButton", sb_button_pressed);
+	t->set_stylebox("hover","ColorPickerButton", sb_button_hover);
+	t->set_stylebox("disabled","ColorPickerButton", sb_button_disabled);
+	t->set_stylebox("focus","ColorPickerButton", sb_button_focus);
 
 	t->set_font("font","ColorPickerButton", default_font );
 
@@ -263,11 +279,17 @@ void make_default_theme() {
 
 	// OptionButton
 
-	t->set_stylebox("normal","OptionButton", make_stylebox( option_button_normal_png,5,5,21,5,8,4,8,4) );
-	t->set_stylebox("pressed","OptionButton", make_stylebox( option_button_pressed_png,5,5,21,5) );
-	t->set_stylebox("hover","OptionButton", make_stylebox( option_button_hover_png,5,5,21,5) );
-	t->set_stylebox("disabled","OptionButton", make_stylebox( option_button_disabled_png,5,5,21,5) );
-	t->set_stylebox("focus","OptionButton", focus );
+	Ref<StyleBox> sb_optbutton_normal = sb_expand( make_stylebox( option_button_normal_png,4,4,21,4,6,2,21,2),2,2,2,2);
+	Ref<StyleBox> sb_optbutton_pressed = sb_expand( make_stylebox( option_button_pressed_png,4,4,21,4,6,2,21,2),2,2,2,2);
+	Ref<StyleBox> sb_optbutton_hover = sb_expand( make_stylebox( option_button_hover_png,4,4,21,4,6,2,21,2),2,2,2,2);
+	Ref<StyleBox> sb_optbutton_disabled = sb_expand( make_stylebox( option_button_disabled_png,4,4,21,4,6,2,21,2),2,2,2,2);
+	Ref<StyleBox> sb_optbutton_focus = sb_expand( make_stylebox( button_focus_png,4,4,4,4,6,2,6,2),2,2,2,2);
+
+	t->set_stylebox("normal","OptionButton", sb_optbutton_normal );
+	t->set_stylebox("pressed","OptionButton", sb_optbutton_pressed );
+	t->set_stylebox("hover","OptionButton", sb_optbutton_hover );
+	t->set_stylebox("disabled","OptionButton", sb_optbutton_disabled );
+	t->set_stylebox("focus","OptionButton", sb_button_focus );
 
 	t->set_icon("arrow","OptionButton", make_icon( option_arrow_png ) );
 
@@ -285,9 +307,9 @@ void make_default_theme() {
 
 	// MenuButton
 
-	t->set_stylebox("normal","MenuButton", make_stylebox( button_normal_png,4,4,4,4,8,4,8,4) );
-	t->set_stylebox("pressed","MenuButton", make_stylebox( tool_button_pressed_png ,4,4,4,4) );
-	t->set_stylebox("hover","MenuButton", make_stylebox( button_normal_png,4,4,4,4) );
+	t->set_stylebox("normal","MenuButton", sb_button_normal );
+	t->set_stylebox("pressed","MenuButton", sb_button_pressed );
+	t->set_stylebox("hover","MenuButton", sb_button_pressed );
 	t->set_stylebox("disabled","MenuButton", make_empty_stylebox(0,0,0,0) );
 
 	t->set_font("font","MenuButton", default_font );
@@ -497,10 +519,10 @@ void make_default_theme() {
 
 	// WindowDialog
 
-	Ref<StyleBoxTexture> style_pp_win = make_stylebox( popup_window_png,6,28,6,7);
-	for(int i=0;i<4;i++)
+	Ref<StyleBoxTexture> style_pp_win = sb_expand(make_stylebox( popup_window_png,10,30,10,8),8,26,8,4);
+	/*for(int i=0;i<4;i++)
 		style_pp_win->set_expand_margin_size((Margin)i,3);
-	style_pp_win->set_expand_margin_size(MARGIN_TOP,26);
+	style_pp_win->set_expand_margin_size(MARGIN_TOP,26);*/
 
 	t->set_stylebox("panel","WindowDialog", style_pp_win );
 
@@ -520,7 +542,7 @@ void make_default_theme() {
 
 	// Popup
 
-	Ref<StyleBoxTexture> style_pp = make_stylebox( popup_bg_png,4,4,4,4,8,8,8,8);
+	Ref<StyleBoxTexture> style_pp =  sb_expand( make_stylebox( popup_bg_png,5,5,5,5,4,4,4,4),2,2,2,2);
 
 	Ref<StyleBoxTexture> selected = make_stylebox( selection_png,6,6,6,6);
 	for(int i=0;i<4;i++) {
@@ -644,16 +666,13 @@ void make_default_theme() {
 
 	// TabContainer
 
-	Ref<StyleBoxTexture> tc_sb = make_stylebox( tab_container_bg_png,4,4,4,4);
-	for(int i=0;i<4;i++) {
-		tc_sb->set_default_margin(Margin(i),4);
-		tc_sb->set_expand_margin_size(Margin(i),2);
-	}
+	Ref<StyleBoxTexture> tc_sb = sb_expand( make_stylebox( tab_container_bg_png,4,4,4,4,4,4,4,4),3,3,3,3);
+
 	tc_sb->set_expand_margin_size(MARGIN_TOP,2);
 	tc_sb->set_default_margin(MARGIN_TOP,8);
 
-	t->set_stylebox("tab_fg","TabContainer", make_stylebox( tab_current_png,4,4,4,4,16,4,16,4) );
-	t->set_stylebox("tab_bg","TabContainer", make_stylebox( tab_behind_png,4,4,4,4,16,6,16,4) );
+	t->set_stylebox("tab_fg","TabContainer", sb_expand( make_stylebox( tab_current_png,4,4,4,1,16,4,16,4),2,2,2,2) );
+	t->set_stylebox("tab_bg","TabContainer", sb_expand( make_stylebox( tab_behind_png,5,5,5,1,16,6,16,4),3,0,3,3) );
 	t->set_stylebox("panel","TabContainer", tc_sb );
 
 	t->set_icon("increment","TabContainer",make_icon( scroll_button_right_png));
@@ -678,9 +697,9 @@ void make_default_theme() {
 
 	// Tabs
 
-	t->set_stylebox("tab_fg","Tabs", make_stylebox( tab_current_png,4,4,4,4,16,4,16,4) );
-	t->set_stylebox("tab_bg","Tabs", make_stylebox( tab_behind_png,4,4,4,4,16,6,16,4) );
-	t->set_stylebox("panel","Tabs", make_stylebox( tab_container_bg_png,4,4,4,4) );
+	t->set_stylebox("tab_fg","Tabs", sb_expand( make_stylebox( tab_current_png,4,4,4,1,16,4,16,4),2,2,2,2) );
+	t->set_stylebox("tab_bg","Tabs", sb_expand( make_stylebox( tab_behind_png,5,5,5,1,16,6,16,4),3,3,3,3) );
+	t->set_stylebox("panel","Tabs",tc_sb );
 	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) );
 

BIN
scene/resources/default_theme/focus.png


BIN
scene/resources/default_theme/line_edit.png


BIN
scene/resources/default_theme/line_edit_disabled.png


BIN
scene/resources/default_theme/option_button_disabled.png


BIN
scene/resources/default_theme/option_button_hover.png


BIN
scene/resources/default_theme/option_button_normal.png


BIN
scene/resources/default_theme/option_button_pressed.png


BIN
scene/resources/default_theme/panel_bg.png


BIN
scene/resources/default_theme/popup_bg.png


BIN
scene/resources/default_theme/popup_window.png


BIN
scene/resources/default_theme/tab_behind.png


BIN
scene/resources/default_theme/tab_container_bg.png


BIN
scene/resources/default_theme/tab_current.png


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 1
scene/resources/default_theme/theme_data.h


BIN
scene/resources/default_theme/tree_bg.png


Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä