default_theme.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*************************************************/
  2. /* default_theme.cpp */
  3. /*************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /*************************************************/
  7. /* Source code within this file is: */
  8. /* (c) 2007-2010 Juan Linietsky, Ariel Manzur */
  9. /* All Rights Reserved. */
  10. /*************************************************/
  11. #include "default_theme.h"
  12. #include "scene/resources/theme.h"
  13. #include "theme_data.h"
  14. #include "os/os.h"
  15. #include "normal_font.inc"
  16. #include "bold_font.inc"
  17. #include "mono_font.inc"
  18. #include "font_normal.inc"
  19. #include "font_source.inc"
  20. #include "font_large.inc"
  21. typedef Map<const void*,Ref<ImageTexture> > TexCacheMap;
  22. static TexCacheMap *tex_cache;
  23. template<class T>
  24. static Ref<StyleBoxTexture> make_stylebox(T p_src,float p_left, float p_top, float p_right, float p_botton,float p_margin_left=-1, float p_margin_top=-1, float p_margin_right=-1, float p_margin_botton=-1, bool p_draw_center=true) {
  25. Ref<ImageTexture> texture;
  26. if (tex_cache->has(p_src)) {
  27. texture=(*tex_cache)[p_src];
  28. } else {
  29. texture = Ref<ImageTexture>( memnew( ImageTexture ) );
  30. texture->create_from_image( Image(p_src),ImageTexture::FLAG_FILTER );
  31. (*tex_cache)[p_src]=texture;
  32. }
  33. Ref<StyleBoxTexture> style( memnew( StyleBoxTexture ) );
  34. style->set_texture(texture);
  35. style->set_margin_size( MARGIN_LEFT, p_left );
  36. style->set_margin_size( MARGIN_RIGHT, p_right );
  37. style->set_margin_size( MARGIN_BOTTOM, p_botton );
  38. style->set_margin_size( MARGIN_TOP, p_top );
  39. style->set_default_margin( MARGIN_LEFT, p_margin_left );
  40. style->set_default_margin( MARGIN_RIGHT, p_margin_right );
  41. style->set_default_margin( MARGIN_BOTTOM, p_margin_botton );
  42. style->set_default_margin( MARGIN_TOP, p_margin_top );
  43. style->set_draw_center(p_draw_center);
  44. return style;
  45. }
  46. template<class T>
  47. static Ref<Texture> make_icon(T p_src) {
  48. Ref<ImageTexture> texture( memnew( ImageTexture ) );
  49. texture->create_from_image( Image(p_src) );
  50. return texture;
  51. }
  52. static Ref<Font> make_font(int p_height,int p_ascent, int p_valign, int p_charcount, const int *p_chars,const Ref<Texture> &p_texture) {
  53. Ref<Font> font( memnew( Font ) );
  54. font->add_texture( p_texture );
  55. for (int i=0;i<p_charcount;i++) {
  56. const int *c = &p_chars[i*8];
  57. int chr=c[0];
  58. Rect2 frect;
  59. frect.pos.x=c[1];
  60. frect.pos.y=c[2];
  61. frect.size.x=c[3];
  62. frect.size.y=c[4];
  63. Point2 align( c[5], c[6]+p_valign);
  64. int advance=c[7];
  65. font->add_char( chr, 0, frect, align,advance );
  66. }
  67. font->set_height( p_height );
  68. font->set_ascent( p_ascent );
  69. return font;
  70. }
  71. static Ref<Font> make_font2(int p_height,int p_ascent, int p_charcount, const int *p_char_rects,int p_kerning_count,const int *p_kernings,int p_w, int p_h, const unsigned char *p_img) {
  72. Ref<Font> font( memnew( Font ) );
  73. DVector<uint8_t> img;
  74. img.resize(p_w*p_h*2);
  75. {
  76. DVector<uint8_t>::Write w = img.write();
  77. for(int i=0;i<(p_w*p_h*2);i++) {
  78. w[i]=p_img[i];
  79. }
  80. }
  81. Image image(p_w,p_h,0,Image::FORMAT_GRAYSCALE_ALPHA,img);
  82. Ref<ImageTexture> tex = memnew( ImageTexture );
  83. tex->create_from_image(image);
  84. font->add_texture( tex );
  85. for (int i=0;i<p_charcount;i++) {
  86. const int *c = &p_char_rects[i*8];
  87. int chr=c[0];
  88. Rect2 frect;
  89. frect.pos.x=c[1];
  90. frect.pos.y=c[2];
  91. frect.size.x=c[3];
  92. frect.size.y=c[4];
  93. Point2 align( c[6], c[5]);
  94. int advance=c[7];
  95. font->add_char( chr, 0, frect, align,advance );
  96. }
  97. for(int i=0;i<p_kerning_count;i++) {
  98. font->add_kerning_pair(p_kernings[i*3+0],p_kernings[i*3+1],p_kernings[i*3+2]);
  99. }
  100. font->set_height( p_height );
  101. font->set_ascent( p_ascent );
  102. return font;
  103. }
  104. static Ref<StyleBox> make_empty_stylebox(float p_margin_left=-1, float p_margin_top=-1, float p_margin_right=-1, float p_margin_botton=-1) {
  105. Ref<StyleBox> style( memnew( StyleBoxEmpty) );
  106. style->set_default_margin( MARGIN_LEFT, p_margin_left );
  107. style->set_default_margin( MARGIN_RIGHT, p_margin_right );
  108. style->set_default_margin( MARGIN_BOTTOM, p_margin_botton );
  109. style->set_default_margin( MARGIN_TOP, p_margin_top );
  110. return style;
  111. }
  112. #ifndef DEFAULT_THEME_DISABLED
  113. void make_default_theme() {
  114. tex_cache = memnew( TexCacheMap );
  115. uint32_t last=OS::get_singleton()->get_ticks_msec();
  116. Ref<Theme> t( memnew( Theme ) );
  117. //Ref<Font> default_font = make_font(_bi_font_normal_height,_bi_font_normal_ascent,_bi_font_normal_valign,_bi_font_normal_charcount,_bi_font_normal_characters,make_icon(font_normal_png));
  118. Ref<Font> default_font=make_font2(_builtin_normal_font_height,_builtin_normal_font_ascent,_builtin_normal_font_charcount,&_builtin_normal_font_charrects[0][0],_builtin_normal_font_kerning_pair_count,&_builtin_normal_font_kerning_pairs[0][0],_builtin_normal_font_img_width,_builtin_normal_font_img_height,_builtin_normal_font_img_data);
  119. Ref<Font> source_font=make_font2(_builtin_source_font_height,_builtin_source_font_ascent,_builtin_source_font_charcount,&_builtin_source_font_charrects[0][0],_builtin_source_font_kerning_pair_count,&_builtin_source_font_kerning_pairs[0][0],_builtin_source_font_img_width,_builtin_source_font_img_height,_builtin_source_font_img_data);
  120. Ref<Font> large_font=make_font2(_builtin_large_font_height,_builtin_large_font_ascent,_builtin_large_font_charcount,&_builtin_large_font_charrects[0][0],_builtin_large_font_kerning_pair_count,&_builtin_large_font_kerning_pairs[0][0],_builtin_large_font_img_width,_builtin_large_font_img_height,_builtin_large_font_img_data);
  121. t->set_stylebox("panel","Panel", make_stylebox( panel_bg_png,0,0,0,0) );
  122. Color control_font_color = Color::html("cfc9d5");
  123. Color control_font_color_low = Color::html("bab4c1");
  124. Color control_font_color_hover = Color::html("ffffff");
  125. Color control_font_color_disabled = Color(0.9,0.9,0.9,0.6);
  126. Color control_font_color_pressed = Color::html("bfb9c5");
  127. Color font_color_selection = Color::html("715e7d");
  128. Ref<Texture> empty_icon = memnew( ImageTexture );
  129. t->set_stylebox("normal","Button", make_stylebox( button_normal_png,5,5,5,5,8,3,8,4) );
  130. t->set_stylebox("pressed","Button", make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3) );
  131. t->set_stylebox("hover","Button", make_stylebox( button_hover_png,5,5,5,5,3,0,3,0) );
  132. t->set_stylebox("disabled","Button", make_stylebox( button_disabled_png,5,5,5,5,3,3,3,3) );
  133. Ref<StyleBoxTexture> focus = make_stylebox( focus_png,6,6,6,6,3,3,3,3);
  134. for(int i=0;i<4;i++) {
  135. focus->set_expand_margin_size(Margin(i),2);
  136. }
  137. t->set_stylebox("focus","Button", focus );
  138. t->set_font("font","Button", default_font );
  139. t->set_color("font_color","Button", control_font_color );
  140. t->set_color("font_color_pressed","Button", control_font_color_pressed );
  141. t->set_color("font_color_hover","Button", control_font_color_hover );
  142. t->set_color("font_color_disabled","Button", control_font_color_disabled );
  143. t->set_constant("hseparation","Button", 2 );
  144. t->set_stylebox("normal","ColorPickerButton", make_stylebox( button_normal_png,7,7,7,7,8,3,8,3) );
  145. t->set_stylebox("pressed","ColorPickerButton", make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3) );
  146. t->set_stylebox("hover","ColorPickerButton", make_stylebox( button_hover_png,4,4,4,4,3,3,3,3) );
  147. t->set_stylebox("disabled","ColorPickerButton", make_stylebox( button_disabled_png,4,4,4,4,3,3,3,3) );
  148. t->set_stylebox("focus","ColorPickerButton", make_stylebox( focus_png,5,5,5,5,3,3,3,3) );
  149. t->set_font("font","ColorPickerButton", default_font );
  150. t->set_color("font_color","ColorPickerButton", Color(1,1,1,1) );
  151. t->set_color("font_color_pressed","ColorPickerButton", Color(0.8,0.8,0.8,1) );
  152. t->set_color("font_color_hover","ColorPickerButton", Color(1,1,1,1) );
  153. t->set_color("font_color_disabled","ColorPickerButton", Color(0.9,0.9,0.9,0.6) );
  154. t->set_constant("hseparation","ColorPickerButton", 2 );
  155. t->set_stylebox("normal","ToolButton", make_empty_stylebox(5,3,5,3) );
  156. t->set_stylebox("pressed","ToolButton", make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3) );
  157. t->set_stylebox("hover","ToolButton", make_stylebox( button_normal_png,5,5,5,5,3,3,3,3) );
  158. //t->set_stylebox("disabled","ToolButton", make_stylebox( button_disabled_png,5,5,5,5,3,3,3,3) );
  159. t->set_stylebox("disabled","ToolButton", make_empty_stylebox(3,3,3,3) );
  160. t->set_stylebox("focus","ToolButton", make_stylebox( focus_png,5,5,5,5,3,3,3,3) );
  161. t->set_font("font","ToolButton", default_font );
  162. t->set_color("font_color","ToolButton", control_font_color );
  163. t->set_color("font_color_pressed","ToolButton", control_font_color_pressed );
  164. t->set_color("font_color_hover","ToolButton", control_font_color_hover );
  165. t->set_color("font_color_disabled","ToolButton", Color(0.9,0.95,1,0.6) );
  166. t->set_constant("hseparation","ToolButton", 2 );
  167. t->set_stylebox("normal","OptionButton", make_stylebox( option_button_normal_png,4,4,20,5,8,3,20,4) );
  168. t->set_stylebox("pressed","OptionButton", make_stylebox( option_button_pressed_png,4,4,20,5,3,3,3,3) );
  169. t->set_stylebox("hover","OptionButton", make_stylebox( option_button_hover_png,4,4,20,5,3,3,3,3) );
  170. t->set_stylebox("disabled","OptionButton", make_stylebox( option_button_disabled_png,4,4,20,5,3,3,3,3) );
  171. t->set_stylebox("focus","OptionButton", focus );
  172. t->set_constant("arrow_margin","OptionButton", 1 );
  173. t->set_icon("arrow","OptionButton", make_icon( option_arrow_png ) );
  174. t->set_font("font","OptionButton", default_font );
  175. t->set_color("font_color","OptionButton", control_font_color );
  176. t->set_color("font_color_pressed","OptionButton", control_font_color_pressed );
  177. t->set_color("font_color_hover","OptionButton", control_font_color_hover );
  178. t->set_color("font_color_disabled","OptionButton", control_font_color_disabled );
  179. t->set_constant("hseparation","OptionButton", 2 );
  180. t->set_stylebox("normal","MenuButton", make_stylebox( button_normal_png,6,6,6,6,3,3,3,3) );
  181. t->set_stylebox("pressed","MenuButton", make_stylebox( tool_button_pressed_png ,6,6,6,6,3,3,3,3) );
  182. t->set_stylebox("hover","MenuButton", make_stylebox( button_normal_png,6,6,6,6,3,3,3,3) );
  183. t->set_stylebox("disabled","MenuButton", make_empty_stylebox(0,0,0,0) );
  184. t->set_font("font","MenuButton", default_font );
  185. t->set_color("font_color","MenuButton", control_font_color );
  186. t->set_color("font_color_pressed","MenuButton", control_font_color_pressed );
  187. t->set_color("font_color_hover","MenuButton", control_font_color_hover );
  188. t->set_color("font_color_disabled","MenuButton", Color(1,1,1,0.3) );
  189. t->set_stylebox("focus","OptionButton", Ref<StyleBox>( memnew( StyleBoxEmpty )) );
  190. t->set_constant("hseparation","MenuButton", 2 );
  191. Ref<StyleBox> cb_empty = memnew( StyleBoxEmpty );
  192. cb_empty->set_default_margin(MARGIN_RIGHT,70);
  193. cb_empty->set_default_margin(MARGIN_TOP,4);
  194. cb_empty->set_default_margin(MARGIN_BOTTOM,4);
  195. t->set_stylebox("normal","CheckButton", cb_empty );
  196. t->set_stylebox("pressed","CheckButton", cb_empty );
  197. t->set_stylebox("disabled","CheckButton", cb_empty );
  198. t->set_stylebox("hover","CheckButton", cb_empty );
  199. //t->set_stylebox("hover","CheckButton", make_stylebox( button_hover_png,5,5,5,5,3,3,3,3) );
  200. t->set_font("font","CheckButton", default_font );
  201. t->set_color("font_color","CheckButton", control_font_color );
  202. t->set_color("font_color_pressed","CheckButton", control_font_color_pressed );
  203. t->set_color("font_color_hover","CheckButton", control_font_color_hover );
  204. t->set_color("font_color_disabled","CheckButton", control_font_color_disabled );
  205. t->set_icon("on","CheckButton", make_icon(toggle_on_png) );
  206. t->set_icon("off","CheckButton", make_icon(toggle_off_png));
  207. t->set_stylebox("focus","CheckButton", focus );
  208. t->set_constant("hseparation","CheckButton",4);
  209. t->set_constant("check_vadjust","CheckButton",0);
  210. t->set_font("font","Label", default_font );
  211. t->set_color("font_color","Label", Color(1,1,1) );
  212. t->set_color("font_color_shadow","Label", Color(0,0,0,0) );
  213. t->set_constant("shadow_offset_x","Label", 1 );
  214. t->set_constant("shadow_offset_y","Label", 1 );
  215. t->set_constant("shadow_as_outline","Label", 0 );
  216. t->set_stylebox("normal","LineEdit", make_stylebox( line_edit_png,4,4,4,4,3,4,3,4) );
  217. t->set_stylebox("focus","LineEdit", focus );
  218. t->set_stylebox("read_only","LineEdit", make_stylebox( line_edit_disabled_png,6,6,6,6,4,4,4,4) );
  219. Image n(line_edit_png);
  220. Image nf(line_edit_focus_png);
  221. t->set_font("font","LineEdit", default_font );
  222. t->set_color("font_color","LineEdit", control_font_color );
  223. t->set_color("font_color_selected","LineEdit", Color(0,0,0) );
  224. t->set_color("cursor_color","LineEdit", control_font_color_hover );
  225. t->set_color("selection_color","LineEdit", font_color_selection );
  226. t->set_constant("minimum_spaces","LineEdit", 8 );
  227. t->set_stylebox("bg","ProgressBar", make_stylebox( progress_bar_png,5,5,5,5,0,0,0,0) );
  228. t->set_stylebox("fg","ProgressBar", make_stylebox( progress_fill_png,5,5,5,5,2,2,2,2) );
  229. t->set_font("font","ProgressBar", default_font );
  230. t->set_color("font_color","ProgressBar", control_font_color );
  231. t->set_color("font_color_shadow","ProgressBar", Color(0,0,0) );
  232. t->set_icon("tab","TextEdit", make_icon( tab_png) );
  233. t->set_stylebox("normal","TextEdit", make_stylebox( tree_bg_png,12,12,12,12,3,3,3,3) );
  234. t->set_stylebox("focus","TextEdit", focus );
  235. t->set_stylebox("completion","TextEdit", make_stylebox( tree_bg_png,4,4,4,5,3,3,3,3) );
  236. t->set_constant("completion_lines","TextEdit", 7 );
  237. t->set_constant("completion_max_width","TextEdit", 50 );
  238. t->set_constant("completion_scroll_width","TextEdit", 3 );
  239. t->set_color("completion_scroll_color","TextEdit", control_font_color_pressed );
  240. t->set_color("completion_existing","TextEdit", control_font_color );
  241. //t->set_font("font","TextEdit", mono_font );
  242. t->set_font("font","TextEdit", default_font );
  243. t->set_color("font_color","TextEdit", control_font_color );
  244. t->set_color("font_color_selected","TextEdit", Color(0,0,0) );
  245. t->set_color("selection_color","TextEdit", font_color_selection );
  246. t->set_color("mark_color","TextEdit", Color(1.0,0.4,0.4,0.4) );
  247. t->set_color("breakpoint_color","TextEdit", Color(0.8,0.8,0.4,0.4) );
  248. t->set_color("current_line_color","TextEdit", Color(0.3,0.5,0.8,0.15) );
  249. t->set_color("cursor_color","TextEdit", control_font_color );
  250. t->set_color("symbol_color","TextEdit", control_font_color_hover );
  251. t->set_constant("line_spacing","TextEdit",1 );
  252. t->set_stylebox("scroll","HScrollBar", make_stylebox( hscroll_bg_png,3,3,3,3,0,0,0,0) );
  253. t->set_stylebox("scroll_focus","HScrollBar", make_stylebox( hscroll_bg_png,3,3,3,3,0,0,0,0) );
  254. t->set_stylebox("grabber","HScrollBar", make_stylebox( hscroll_grabber_png,3,3,3,3,2,2,2,2) );
  255. t->set_stylebox("grabber_hilite","HScrollBar", make_stylebox( hscroll_grabber_hl_png,3,3,3,3,2,2,2,2) );
  256. t->set_icon("increment","HScrollBar",empty_icon);
  257. t->set_icon("increment_hilite","HScrollBar",empty_icon);
  258. t->set_icon("decrement","HScrollBar",empty_icon);
  259. t->set_icon("decrement_hilite","HScrollBar",empty_icon);
  260. t->set_stylebox("scroll","VScrollBar", make_stylebox( vscroll_bg_png,3,3,3,3,0,0,0,0) );
  261. t->set_stylebox("scroll_focus","VScrollBar", make_stylebox( vscroll_bg_png,3,3,3,3,0,0,0,0) );
  262. t->set_stylebox("grabber","VScrollBar", make_stylebox( vscroll_grabber_png,3,3,3,3,2,2,2,2) );
  263. t->set_stylebox("grabber_hilite","VScrollBar", make_stylebox( vscroll_grabber_hl_png,3,3,3,3,2,2,2,2) );
  264. t->set_icon("increment","VScrollBar",empty_icon);
  265. t->set_icon("increment_hilite","VScrollBar",empty_icon);
  266. t->set_icon("decrement","VScrollBar",empty_icon);
  267. t->set_icon("decrement_hilite","VScrollBar",empty_icon);
  268. t->set_stylebox("slider","HSlider", make_stylebox( hslider_bg_png,5,5,5,5,1,1,1,1) );
  269. t->set_stylebox("focus","HSlider", make_stylebox( focus_png,3,3,3,3,1,1,1,1) );
  270. //t->set_stylebox("slider_focus","HSlider", make_stylebox( hslider_bg_focus_png,6,6,6,6,2,2,2,2) );
  271. t->set_icon("grabber","HSlider", make_icon( hslider_grabber_png ) );
  272. t->set_icon("grabber_hilite","HSlider", make_icon( hslider_grabber_hl_png ) );
  273. t->set_icon("tick","HSlider", make_icon( hslider_tick_png ) );
  274. t->set_stylebox("grabber_hilite","HSlider", make_stylebox( hslider_grabber_hl_png,6,6,6,6,2,2,2,2) );
  275. t->set_stylebox("slider","VSlider", make_stylebox( vslider_bg_png,5,5,5,5,1,1,1,1) );
  276. t->set_stylebox("focus","HSlider", make_stylebox( focus_png,3,3,3,3,1,1,1,1) );
  277. //t->set_stylebox("slider_focus","VSlider", make_stylebox( vslider_bg_focus_png,6,6,6,6,2,2,2,2) );
  278. t->set_icon("grabber","VSlider", make_icon( vslider_grabber_png) );
  279. t->set_icon("grabber_hilite","VSlider", make_icon( vslider_grabber_hl_png ) );
  280. t->set_icon("tick","VSlider", make_icon( vslider_tick_png ) );
  281. t->set_stylebox("grabber_hilite","VSlider", make_stylebox( vslider_grabber_hl_png,6,6,6,6,2,2,2,2) );
  282. t->set_icon("updown","SpinBox",make_icon(spinbox_updown_png));
  283. Ref<StyleBoxTexture> style_pp_win = make_stylebox( popup_window_png,6,28,6,7,8,8,8,8);
  284. for(int i=0;i<4;i++)
  285. style_pp_win->set_expand_margin_size((Margin)i,3);
  286. style_pp_win->set_expand_margin_size(MARGIN_TOP,26);
  287. t->set_stylebox("panel","WindowDialog", style_pp_win );
  288. t->set_constant("titlebar_height","WindowDialog", 18 );
  289. t->set_constant("title_height","WindowDialog", 20 );
  290. t->set_font("title_font","WindowDialog", large_font );
  291. t->set_color("title_color","WindowDialog", Color(0,0,0) );
  292. t->set_icon("close","WindowDialog", make_icon( close_png ) );
  293. t->set_icon("close_hilite","WindowDialog", make_icon( close_hl_png ) );
  294. t->set_constant("close_h_ofs","WindowDialog", 22 );
  295. t->set_constant("close_v_ofs","WindowDialog", 20 );
  296. Ref<StyleBoxTexture> style_pp = make_stylebox( popup_bg_png,6,19,6,7,8,8,8,8);
  297. style_pp->set_expand_margin_size(MARGIN_LEFT,2);
  298. style_pp->set_expand_margin_size(MARGIN_TOP,3);
  299. style_pp->set_expand_margin_size(MARGIN_RIGHT,2);
  300. style_pp->set_expand_margin_size(MARGIN_BOTTOM,3);
  301. t->set_stylebox("panel","PopupMenu", style_pp );
  302. t->set_stylebox("panel","PopupPanel", style_pp );
  303. Ref<StyleBoxTexture> selected = make_stylebox( selection_png,6,6,6,6);
  304. for(int i=0;i<4;i++) {
  305. selected->set_expand_margin_size(Margin(i),2);
  306. }
  307. t->set_stylebox("panel_disabled","PopupMenu", make_stylebox( popup_bg_disabled_png,5,5,5,5) );
  308. t->set_stylebox("hover","PopupMenu", selected );
  309. t->set_stylebox("separator","PopupMenu", make_stylebox( vseparator_png,3,3,3,3) );
  310. t->set_icon("checked","PopupMenu", make_icon(popup_checked_png) );
  311. t->set_icon("unchecked","PopupMenu", make_icon(popup_unchecked_png) );
  312. t->set_icon("submenu","PopupMenu", make_icon(submenu_png) );
  313. t->set_font("font","PopupMenu", default_font );
  314. t->set_color("font_color","PopupMenu", control_font_color );
  315. t->set_color("font_color_accel","PopupMenu", Color(0.7,0.7,0.7,0.8) );
  316. t->set_color("font_color_disabled","PopupMenu", Color(0.4,0.4,0.4,0.8) );
  317. t->set_color("font_color_hover","PopupMenu", control_font_color );
  318. t->set_constant("hseparation","PopupMenu",2);
  319. t->set_constant("vseparation","PopupMenu",1);
  320. t->set_stylebox("bg","Tree", make_stylebox( tree_bg_png,4,4,4,5,3,3,3,3) );
  321. t->set_stylebox("bg_focus","Tree", focus );
  322. Ref<StyleBoxTexture> tree_selected = make_stylebox( selection_png,4,4,4,4);
  323. Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4);
  324. for(int i=0;i<4;i++) {
  325. tree_selected->set_expand_margin_size(Margin(i),2);
  326. tree_selected_oof->set_expand_margin_size(Margin(i),2);
  327. }
  328. t->set_stylebox("selected","Tree", tree_selected_oof );
  329. t->set_stylebox("selected_focus","Tree", tree_selected );
  330. t->set_stylebox("completion_selected","TextEdit", tree_selected );
  331. t->set_stylebox("cursor","Tree", focus );
  332. t->set_stylebox("cursor_unfocused","Tree", focus );
  333. t->set_stylebox("button_pressed","Tree",make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3));
  334. t->set_font("font","Tree", default_font );
  335. t->set_color("font_color","Tree", control_font_color_low );
  336. t->set_color("font_color_selected","Tree", control_font_color );
  337. t->set_color("selection_color","Tree", Color(0.1,0.1,1,0.8) );
  338. t->set_color("cursor_color","Tree", Color(0,0,0) );
  339. t->set_color("guide_color","Tree", Color(0,0,0,0.1) );
  340. t->set_constant("hseparation","Tree",2);
  341. t->set_constant("vseparation","Tree",1);
  342. t->set_constant("guide_width","Tree",1);
  343. t->set_constant("item_margin","Tree",12);
  344. t->set_constant("button_margin","Tree",2);
  345. t->set_stylebox("title_button_normal","Tree", make_stylebox( tree_title_png,4,4,4,4,3,3,3,3) );
  346. t->set_stylebox("title_button_pressed","Tree", make_stylebox( tree_title_pressed_png,4,4,4,4,3,3,3,3) );
  347. t->set_stylebox("title_button_hover","Tree", make_stylebox( tree_title_png,4,4,4,4,3,3,3,3) );
  348. t->set_color("title_button_color","Tree", control_font_color );
  349. t->set_font("title_button_font","Tree", default_font );
  350. t->set_icon("checked","Tree",make_icon(checked_png));
  351. t->set_icon("unchecked","Tree",make_icon(unchecked_png));
  352. t->set_icon("updown","Tree",make_icon(updown_png));
  353. t->set_icon("select_arrow","Tree",make_icon(dropdown_png));
  354. t->set_icon("arrow","Tree",make_icon(arrow_down_png));
  355. t->set_icon("arrow_collapsed","Tree",make_icon(arrow_right_png));
  356. t->set_stylebox("tab_fg","TabContainer", make_stylebox( tab_current_png,5,5,5,5,8,3,8,3) );
  357. t->set_stylebox("tab_bg","TabContainer", make_stylebox( tab_behind_png,5,5,5,5,8,4,8,3) );
  358. Ref<StyleBoxTexture> tc_sb = make_stylebox( tab_container_bg_png,6,19,6,7);
  359. for(int i=0;i<4;i++) {
  360. tc_sb->set_default_margin(Margin(i),7);
  361. tc_sb->set_expand_margin_size(Margin(i),2);
  362. }
  363. //tc_sb->set_expand_margin_size(MARGIN_TOP,2);
  364. //tc_sb->set_default_margin(MARGIN_TOP,6);
  365. t->set_stylebox("panel","TabContainer", tc_sb );
  366. t->set_icon("increment","TabContainer",make_icon( scroll_button_right_png));
  367. t->set_icon("increment_hilite","TabContainer",make_icon( scroll_button_right_hl_png));
  368. t->set_icon("decrement","TabContainer",make_icon( scroll_button_left_png));
  369. t->set_icon("decrement_hilite","TabContainer",make_icon( scroll_button_left_hl_png));
  370. t->set_font("font","TabContainer", default_font );
  371. t->set_color("font_color_fg","TabContainer", control_font_color_hover );
  372. t->set_color("font_color_bg","TabContainer", control_font_color );
  373. t->set_constant("side_margin","TabContainer", 5 );
  374. t->set_constant("top_margin","TabContainer", 24);
  375. t->set_constant("label_valign_fg","TabContainer", 4);
  376. t->set_constant("label_valign_bg","TabContainer", 5);
  377. t->set_constant("hseparation","TabContainer", 2);
  378. t->set_stylebox("tab_fg","Tabs", make_stylebox( tab_current_png,5,5,5,5,8,3,8,3) );
  379. t->set_stylebox("tab_bg","Tabs", make_stylebox( tab_behind_png,5,5,5,5,8,4,8,3) );
  380. t->set_stylebox("panel","Tabs", make_stylebox( tab_container_bg_png,3,3,3,3) );
  381. t->set_font("font","Tabs", default_font );
  382. t->set_color("font_color_fg","Tabs", control_font_color_hover );
  383. t->set_color("font_color_bg","Tabs", control_font_color );
  384. t->set_constant("top_margin","Tabs", 24);
  385. t->set_constant("label_valign_fg","Tabs", 4);
  386. t->set_constant("label_valign_bg","Tabs", 5);
  387. t->set_constant("hseparation","Tabs", 2);
  388. t->set_stylebox("separator","HSeparator", make_stylebox( vseparator_png,3,3,3,3) );
  389. t->set_constant("separation","HSeparator", 7);
  390. t->set_stylebox("separator","VSeparator", make_stylebox( hseparator_png,3,3,3,3) );
  391. t->set_constant("separation","VSeparator", 7);
  392. t->set_icon("close","Icons", make_icon(icon_close_png));
  393. t->set_font("source","Fonts", source_font);
  394. t->set_font("normal","Fonts", default_font );
  395. t->set_font("large","Fonts", large_font );
  396. t->set_constant("margin","Dialogs",10);
  397. t->set_constant("button_margin","Dialogs",32);
  398. t->set_icon("folder","FileDialog",make_icon(icon_folder_png));
  399. t->set_color("files_disabled","FileDialog",Color(0,0,0,0.7));
  400. t->set_constant("value_height","ColorPicker", 23 );
  401. t->set_constant("value_width","ColorPicker", 50);
  402. t->set_constant("color_width","ColorPicker", 100);
  403. t->set_constant("label_width","ColorPicker", 15);
  404. t->set_constant("hseparator","ColorPicker", 4);
  405. Ref<StyleBoxTexture> style_tt = make_stylebox( tooltip_bg_png,9,9,9,9,8,8,8,8);
  406. for(int i=0;i<4;i++)
  407. style_tt->set_expand_margin_size((Margin)i,4);
  408. t->set_stylebox("panel","TooltipPanel", style_tt );
  409. t->set_font("font","TooltipLabel", default_font );
  410. t->set_color("font_color","TooltipLabel", Color(0,0,0) );
  411. t->set_color("font_color_shadow","TooltipLabel", Color(0,0,0,0.1) );
  412. t->set_constant("shadow_offset_x","TooltipLabel", 1 );
  413. t->set_constant("shadow_offset_y","TooltipLabel", 1 );
  414. t->set_font("default_font","RichTextLabel", default_font );
  415. t->set_color("default_color","RichTextLabel", control_font_color );
  416. t->set_color("font_color_selected","RichTextLabel", font_color_selection );
  417. t->set_color("selection_color","RichTextLabel", Color(0.1,0.1,1,0.8) );
  418. t->set_constant("line_separation","RichTextLabel", 1 );
  419. t->set_stylebox("focus","RichTextLabel", focus );
  420. t->set_constant("separation","HBoxContainer",4);
  421. t->set_constant("separation","VBoxContainer",4);
  422. t->set_constant("margin","MarginContainer",15);
  423. t->set_constant("separation","GridContainer",4);
  424. t->set_constant("separation","HSplitContainer",8);
  425. t->set_constant("separation","VSplitContainer",8);
  426. t->set_constant("autohide","HSplitContainer",1);
  427. t->set_constant("autohide","VSplitContainer",1);
  428. t->set_icon("grabber","VSplitContainer",make_icon(vsplitter_png));
  429. t->set_icon("grabber","HSplitContainer",make_icon(hsplitter_png));
  430. t->set_stylebox("bg","VSplitContainer", make_stylebox( vsplit_bg_png,1,1,1,1,1,1,1,1) );
  431. t->set_stylebox("bg","HSplitContainer", make_stylebox( hsplit_bg_png,1,1,1,1,1,1,1,1) );
  432. t->set_stylebox("normal","HButtonArray", make_stylebox( button_normal_png,2,2,2,2,3,3,3,3) );
  433. t->set_stylebox("selected","HButtonArray", make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3) );
  434. t->set_stylebox("hover","HButtonArray", make_stylebox( button_hover_png,5,5,5,5,3,3,3,3) );
  435. t->set_stylebox("focus","HButtonArray", make_stylebox( focus_png,5,5,5,5,3,3,3,3) );
  436. t->set_font("font","HButtonArray", default_font);
  437. t->set_font("font_selected","HButtonArray", default_font);
  438. t->set_color("font_color","HButtonArray", Color(1,1,1,1) );
  439. t->set_color("font_color_selected","HButtonArray", Color(0.7,0.7,0.7,1) );
  440. t->set_constant("icon_separator","HButtonArray", 2 );
  441. t->set_constant("button_separator","HButtonArray", 3 );
  442. t->set_stylebox("normal","VButtonArray", make_stylebox( button_normal_png,2,2,2,2,3,3,3,3) );
  443. t->set_stylebox("selected","VButtonArray", make_stylebox( button_pressed_png,5,5,5,5,3,3,3,3) );
  444. t->set_stylebox("hover","VButtonArray", make_stylebox( button_hover_png,5,5,5,5,3,3,3,3) );
  445. t->set_stylebox("focus","VButtonArray", make_stylebox( focus_png,5,5,5,5,3,3,3,3) );
  446. t->set_font("font","VButtonArray", default_font);
  447. t->set_font("font_selected","VButtonArray", default_font);
  448. t->set_color("font_color","VButtonArray", Color(1,1,1,1) );
  449. t->set_color("font_color_selected","VButtonArray", Color(0.7,0.7,0.7,1) );
  450. t->set_constant("icon_separator","VButtonArray", 2 );
  451. t->set_constant("button_separator","VButtonArray", 3 );
  452. t->set_stylebox("border","ReferenceFrame", make_stylebox( reference_border_png,5,5,5,5,3,3,3,3) );
  453. Ref<StyleBoxTexture> ttnc = make_stylebox( full_panel_bg_png,8,8,8,8);
  454. ttnc->set_draw_center(false);
  455. t->set_stylebox("panelnc","Panel", ttnc );
  456. t->set_stylebox("panelf","Panel", tc_sb );
  457. t->set_stylebox("panel","PanelContainer", tc_sb );
  458. t->set_icon( "logo","Icons", make_icon(logo_png) );
  459. Theme::set_default( t );
  460. Theme::set_default_icon( make_icon(error_icon_png) );
  461. Theme::set_default_style( make_stylebox( error_icon_png,2,2,2,2) );
  462. Theme::set_default_font( default_font );
  463. memdelete( tex_cache );
  464. }
  465. #else
  466. #include "error_icon.xpm"
  467. void make_default_theme() {
  468. Ref<Theme> t( memnew( Theme ) );
  469. Image error_img(error_icon_xpm);
  470. Ref<Texture> texture( memnew( Texture ) );
  471. texture->create_from_image( error_img );
  472. Ref<StyleBoxTexture> style( memnew( StyleBoxTexture ) );
  473. style->set_texture(texture);
  474. for(int i=0;i<4;i++) {
  475. style->set_margin_size( Margin(),2);
  476. style->set_default_margin( Margin(),2);
  477. }
  478. Ref<Font> f = make_default_font();
  479. Theme::set_default( t );
  480. Theme::set_default_icon( texture );
  481. Theme::set_default_style( style );
  482. Theme::set_default_font( f );
  483. }
  484. #endif
  485. void clear_default_theme() {
  486. Theme::set_default( Ref<Theme>() );
  487. Theme::set_default_icon( Ref< Texture >() );
  488. Theme::set_default_style( Ref< StyleBox >() );
  489. Theme::set_default_font( Ref< Font >() );
  490. }