default_theme.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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-2016 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. static Ref<StyleBoxTexture> sb_expand(Ref<StyleBoxTexture> p_sbox,float p_left, float p_top, float p_right, float p_botton) {
  47. p_sbox->set_expand_margin_size(MARGIN_LEFT,p_left);
  48. p_sbox->set_expand_margin_size(MARGIN_TOP,p_top);
  49. p_sbox->set_expand_margin_size(MARGIN_RIGHT,p_right);
  50. p_sbox->set_expand_margin_size(MARGIN_BOTTOM,p_botton);
  51. return p_sbox;
  52. }
  53. template<class T>
  54. static Ref<Texture> make_icon(T p_src) {
  55. Ref<ImageTexture> texture( memnew( ImageTexture ) );
  56. texture->create_from_image( Image(p_src),ImageTexture::FLAG_FILTER );
  57. return texture;
  58. }
  59. static Ref<Shader> make_shader(const char*vertex_code,const char*fragment_code,const char*lighting_code) {
  60. Ref<Shader> shader = (memnew( Shader(Shader::MODE_CANVAS_ITEM) ));
  61. shader->set_code(vertex_code, fragment_code, lighting_code);
  62. return shader;
  63. }
  64. 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) {
  65. Ref<Font> font( memnew( Font ) );
  66. font->add_texture( p_texture );
  67. for (int i=0;i<p_charcount;i++) {
  68. const int *c = &p_chars[i*8];
  69. int chr=c[0];
  70. Rect2 frect;
  71. frect.pos.x=c[1];
  72. frect.pos.y=c[2];
  73. frect.size.x=c[3];
  74. frect.size.y=c[4];
  75. Point2 align( c[5], c[6]+p_valign);
  76. int advance=c[7];
  77. font->add_char( chr, 0, frect, align,advance );
  78. }
  79. font->set_height( p_height );
  80. font->set_ascent( p_ascent );
  81. return font;
  82. }
  83. 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) {
  84. Ref<Font> font( memnew( Font ) );
  85. DVector<uint8_t> img;
  86. img.resize(p_w*p_h*2);
  87. {
  88. DVector<uint8_t>::Write w = img.write();
  89. for(int i=0;i<(p_w*p_h*2);i++) {
  90. w[i]=p_img[i];
  91. }
  92. }
  93. Image image(p_w,p_h,0,Image::FORMAT_GRAYSCALE_ALPHA,img);
  94. Ref<ImageTexture> tex = memnew( ImageTexture );
  95. tex->create_from_image(image);
  96. font->add_texture( tex );
  97. for (int i=0;i<p_charcount;i++) {
  98. const int *c = &p_char_rects[i*8];
  99. int chr=c[0];
  100. Rect2 frect;
  101. frect.pos.x=c[1];
  102. frect.pos.y=c[2];
  103. frect.size.x=c[3];
  104. frect.size.y=c[4];
  105. Point2 align( c[6], c[5]);
  106. int advance=c[7];
  107. font->add_char( chr, 0, frect, align,advance );
  108. }
  109. for(int i=0;i<p_kerning_count;i++) {
  110. font->add_kerning_pair(p_kernings[i*3+0],p_kernings[i*3+1],p_kernings[i*3+2]);
  111. }
  112. font->set_height( p_height );
  113. font->set_ascent( p_ascent );
  114. return font;
  115. }
  116. 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) {
  117. Ref<StyleBox> style( memnew( StyleBoxEmpty) );
  118. style->set_default_margin( MARGIN_LEFT, p_margin_left );
  119. style->set_default_margin( MARGIN_RIGHT, p_margin_right );
  120. style->set_default_margin( MARGIN_BOTTOM, p_margin_botton );
  121. style->set_default_margin( MARGIN_TOP, p_margin_top );
  122. return style;
  123. }
  124. #ifndef DEFAULT_THEME_DISABLED
  125. void make_default_theme() {
  126. tex_cache = memnew( TexCacheMap );
  127. Ref<Theme> t( memnew( Theme ) );
  128. //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));
  129. 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);
  130. 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);
  131. 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);
  132. // Font Colors
  133. Color control_font_color = Color::html("e0e0e0");
  134. Color control_font_color_lower = Color::html("a0a0a0");
  135. Color control_font_color_low = Color::html("b0b0b0");
  136. Color control_font_color_hover = Color::html("f0f0f0");
  137. Color control_font_color_disabled = Color(0.9,0.9,0.9,0.2);
  138. Color control_font_color_pressed = Color::html("ffffff");
  139. Color font_color_selection = Color::html("7d7d7d");
  140. // Panel
  141. t->set_stylebox("panel","Panel", make_stylebox( panel_bg_png,0,0,0,0) );
  142. // Focus
  143. Ref<StyleBoxTexture> focus = make_stylebox( focus_png,5,5,5,5);
  144. for(int i=0;i<4;i++) {
  145. focus->set_expand_margin_size(Margin(i),1);
  146. }
  147. // Button
  148. Ref<StyleBox> sb_button_normal = sb_expand( make_stylebox( button_normal_png,4,4,4,4,6,3,6,3),2,2,2,2);
  149. Ref<StyleBox> sb_button_pressed = sb_expand( make_stylebox( button_pressed_png,4,4,4,4,6,3,6,3),2,2,2,2);
  150. Ref<StyleBox> sb_button_hover = sb_expand( make_stylebox( button_hover_png,4,4,4,4,6,2,6,2),2,2,2,2);
  151. Ref<StyleBox> sb_button_disabled = sb_expand( make_stylebox( button_disabled_png,4,4,4,4,6,2,6,2),2,2,2,2);
  152. Ref<StyleBox> sb_button_focus = sb_expand( make_stylebox( button_focus_png,4,4,4,4,6,2,6,2),2,2,2,2);
  153. t->set_stylebox("normal","Button", sb_button_normal);
  154. t->set_stylebox("pressed","Button", sb_button_pressed);
  155. t->set_stylebox("hover","Button", sb_button_hover);
  156. t->set_stylebox("disabled","Button", sb_button_disabled);
  157. t->set_stylebox("focus","Button", sb_button_focus);
  158. t->set_font("font","Button", default_font );
  159. t->set_color("font_color","Button", control_font_color );
  160. t->set_color("font_color_pressed","Button", control_font_color_pressed );
  161. t->set_color("font_color_hover","Button", control_font_color_hover );
  162. t->set_color("font_color_disabled","Button", control_font_color_disabled );
  163. t->set_constant("hseparation","Button", 2);
  164. // ColorPickerButton
  165. t->set_stylebox("normal","ColorPickerButton", sb_button_normal);
  166. t->set_stylebox("pressed","ColorPickerButton", sb_button_pressed);
  167. t->set_stylebox("hover","ColorPickerButton", sb_button_hover);
  168. t->set_stylebox("disabled","ColorPickerButton", sb_button_disabled);
  169. t->set_stylebox("focus","ColorPickerButton", sb_button_focus);
  170. t->set_font("font","ColorPickerButton", default_font );
  171. t->set_color("font_color","ColorPickerButton", Color(1,1,1,1) );
  172. t->set_color("font_color_pressed","ColorPickerButton", Color(0.8,0.8,0.8,1) );
  173. t->set_color("font_color_hover","ColorPickerButton", Color(1,1,1,1) );
  174. t->set_color("font_color_disabled","ColorPickerButton", Color(0.9,0.9,0.9,0.3) );
  175. t->set_constant("hseparation","ColorPickerButton", 2 );
  176. // ToolButton
  177. Ref<StyleBox> tb_empty = memnew( StyleBoxEmpty );
  178. tb_empty->set_default_margin(MARGIN_LEFT,6);
  179. tb_empty->set_default_margin(MARGIN_RIGHT,6);
  180. tb_empty->set_default_margin(MARGIN_TOP,4);
  181. tb_empty->set_default_margin(MARGIN_BOTTOM,4);
  182. t->set_stylebox("normal","ToolButton", tb_empty);
  183. t->set_stylebox("pressed","ToolButton", make_stylebox( button_pressed_png,4,4,4,4) );
  184. t->set_stylebox("hover","ToolButton", make_stylebox( button_normal_png,4,4,4,4) );
  185. t->set_stylebox("disabled","ToolButton", make_empty_stylebox(4,4,4,4) );
  186. t->set_stylebox("focus","ToolButton", focus );
  187. t->set_font("font","ToolButton", default_font );
  188. t->set_color("font_color","ToolButton", control_font_color );
  189. t->set_color("font_color_pressed","ToolButton", control_font_color_pressed );
  190. t->set_color("font_color_hover","ToolButton", control_font_color_hover );
  191. t->set_color("font_color_disabled","ToolButton", Color(0.9,0.95,1,0.3) );
  192. t->set_constant("hseparation","ToolButton", 3 );
  193. // OptionButton
  194. Ref<StyleBox> sb_optbutton_normal = sb_expand( make_stylebox( option_button_normal_png,4,4,21,4,6,3,21,3),2,2,2,2);
  195. Ref<StyleBox> sb_optbutton_pressed = sb_expand( make_stylebox( option_button_pressed_png,4,4,21,4,6,3,21,3),2,2,2,2);
  196. 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);
  197. 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);
  198. Ref<StyleBox> sb_optbutton_focus = sb_expand( make_stylebox( button_focus_png,4,4,4,4,6,2,6,2),2,2,2,2);
  199. t->set_stylebox("normal","OptionButton", sb_optbutton_normal );
  200. t->set_stylebox("pressed","OptionButton", sb_optbutton_pressed );
  201. t->set_stylebox("hover","OptionButton", sb_optbutton_hover );
  202. t->set_stylebox("disabled","OptionButton", sb_optbutton_disabled );
  203. t->set_stylebox("focus","OptionButton", sb_button_focus );
  204. t->set_icon("arrow","OptionButton", make_icon( option_arrow_png ) );
  205. t->set_font("font","OptionButton", default_font );
  206. t->set_color("font_color","OptionButton", control_font_color );
  207. t->set_color("font_color_pressed","OptionButton", control_font_color_pressed );
  208. t->set_color("font_color_hover","OptionButton", control_font_color_hover );
  209. t->set_color("font_color_disabled","OptionButton", control_font_color_disabled );
  210. t->set_constant("hseparation","OptionButton", 2 );
  211. t->set_constant("arrow_margin","OptionButton", 2 );
  212. // MenuButton
  213. t->set_stylebox("normal","MenuButton", sb_button_normal );
  214. t->set_stylebox("pressed","MenuButton", sb_button_pressed );
  215. t->set_stylebox("hover","MenuButton", sb_button_pressed );
  216. t->set_stylebox("disabled","MenuButton", make_empty_stylebox(0,0,0,0) );
  217. t->set_stylebox("focus","MenuButton", sb_button_focus );
  218. t->set_font("font","MenuButton", default_font );
  219. t->set_color("font_color","MenuButton", control_font_color );
  220. t->set_color("font_color_pressed","MenuButton", control_font_color_pressed );
  221. t->set_color("font_color_hover","MenuButton", control_font_color_hover );
  222. t->set_color("font_color_disabled","MenuButton", Color(1,1,1,0.3) );
  223. t->set_constant("hseparation","MenuButton", 3 );
  224. // ButtonGroup
  225. t->set_stylebox("panel","ButtonGroup", memnew( StyleBoxEmpty ));
  226. // CheckBox
  227. Ref<StyleBox> cbx_empty = memnew( StyleBoxEmpty );
  228. cbx_empty->set_default_margin(MARGIN_LEFT,22);
  229. cbx_empty->set_default_margin(MARGIN_RIGHT,4);
  230. cbx_empty->set_default_margin(MARGIN_TOP,4);
  231. cbx_empty->set_default_margin(MARGIN_BOTTOM,5);
  232. Ref<StyleBox> cbx_focus = focus;
  233. cbx_focus->set_default_margin(MARGIN_LEFT,4);
  234. cbx_focus->set_default_margin(MARGIN_RIGHT,22);
  235. cbx_focus->set_default_margin(MARGIN_TOP,4);
  236. cbx_focus->set_default_margin(MARGIN_BOTTOM,5);
  237. t->set_stylebox("normal","CheckBox", cbx_empty );
  238. t->set_stylebox("pressed","CheckBox", cbx_empty );
  239. t->set_stylebox("disabled","CheckBox", cbx_empty );
  240. t->set_stylebox("hover","CheckBox", cbx_empty );
  241. t->set_stylebox("focus","CheckBox", cbx_focus );
  242. t->set_icon("checked", "CheckBox", make_icon(checked_png));
  243. t->set_icon("unchecked", "CheckBox", make_icon(unchecked_png));
  244. t->set_icon("radio_checked", "CheckBox", make_icon(radio_checked_png));
  245. t->set_icon("radio_unchecked", "CheckBox", make_icon(radio_unchecked_png));
  246. t->set_font("font","CheckBox", default_font );
  247. t->set_color("font_color","CheckBox", control_font_color );
  248. t->set_color("font_color_pressed","CheckBox", control_font_color_pressed );
  249. t->set_color("font_color_hover","CheckBox", control_font_color_hover );
  250. t->set_color("font_color_disabled","CheckBox", control_font_color_disabled );
  251. t->set_constant("hseparation","CheckBox",4);
  252. t->set_constant("check_vadjust","CheckBox",0);
  253. // CheckButton
  254. Ref<StyleBox> cb_empty = memnew( StyleBoxEmpty );
  255. cb_empty->set_default_margin(MARGIN_LEFT,6);
  256. cb_empty->set_default_margin(MARGIN_RIGHT,70);
  257. cb_empty->set_default_margin(MARGIN_TOP,4);
  258. cb_empty->set_default_margin(MARGIN_BOTTOM,4);
  259. t->set_stylebox("normal","CheckButton", cb_empty );
  260. t->set_stylebox("pressed","CheckButton", cb_empty );
  261. t->set_stylebox("disabled","CheckButton", cb_empty );
  262. t->set_stylebox("hover","CheckButton", cb_empty );
  263. t->set_stylebox("focus","CheckButton", focus );
  264. t->set_icon("on","CheckButton", make_icon(toggle_on_png) );
  265. t->set_icon("off","CheckButton", make_icon(toggle_off_png));
  266. t->set_font("font","CheckButton", default_font );
  267. t->set_color("font_color","CheckButton", control_font_color );
  268. t->set_color("font_color_pressed","CheckButton", control_font_color_pressed );
  269. t->set_color("font_color_hover","CheckButton", control_font_color_hover );
  270. t->set_color("font_color_disabled","CheckButton", control_font_color_disabled );
  271. t->set_constant("hseparation","CheckButton",4);
  272. t->set_constant("check_vadjust","CheckButton",0);
  273. // Label
  274. t->set_font("font","Label", default_font );
  275. t->set_color("font_color","Label", Color(1,1,1) );
  276. t->set_color("font_color_shadow","Label", Color(0,0,0,0) );
  277. t->set_constant("shadow_offset_x","Label", 1 );
  278. t->set_constant("shadow_offset_y","Label", 1 );
  279. t->set_constant("shadow_as_outline","Label", 0 );
  280. // LineEdit
  281. t->set_stylebox("normal","LineEdit", make_stylebox( line_edit_png,5,5,5,5) );
  282. t->set_stylebox("focus","LineEdit", focus );
  283. t->set_stylebox("read_only","LineEdit", make_stylebox( line_edit_disabled_png,6,6,6,6) );
  284. t->set_font("font","LineEdit", default_font );
  285. t->set_color("font_color","LineEdit", control_font_color );
  286. t->set_color("font_color_selected","LineEdit", Color(0,0,0) );
  287. t->set_color("cursor_color","LineEdit", control_font_color_hover );
  288. t->set_color("selection_color","LineEdit", font_color_selection );
  289. t->set_constant("minimum_spaces","LineEdit", 12 );
  290. // ProgressBar
  291. t->set_stylebox("bg","ProgressBar", make_stylebox( progress_bar_png,4,4,4,4,0,0,0,0) );
  292. t->set_stylebox("fg","ProgressBar", make_stylebox( progress_fill_png,6,6,6,6,2,1,2,1) );
  293. t->set_font("font","ProgressBar", default_font );
  294. t->set_color("font_color","ProgressBar", control_font_color_hover );
  295. t->set_color("font_color_shadow","ProgressBar", Color(0,0,0) );
  296. // TextEdit
  297. t->set_stylebox("normal","TextEdit", make_stylebox( tree_bg_png,3,3,3,3) );
  298. t->set_stylebox("focus","TextEdit", focus );
  299. t->set_stylebox("completion","TextEdit", make_stylebox( tree_bg_png,3,3,3,3) );
  300. t->set_icon("tab","TextEdit", make_icon( tab_png) );
  301. t->set_font("font","TextEdit", default_font );
  302. t->set_color("completion_scroll_color","TextEdit", control_font_color_pressed );
  303. t->set_color("completion_existing","TextEdit", control_font_color );
  304. t->set_color("font_color","TextEdit", control_font_color );
  305. t->set_color("font_color_selected","TextEdit", Color(0,0,0) );
  306. t->set_color("selection_color","TextEdit", font_color_selection );
  307. t->set_color("mark_color","TextEdit", Color(1.0,0.4,0.4,0.4) );
  308. t->set_color("breakpoint_color","TextEdit", Color(0.8,0.8,0.4,0.2) );
  309. t->set_color("current_line_color","TextEdit", Color(0.25,0.25,0.26,0.8) );
  310. t->set_color("caret_color","TextEdit", control_font_color );
  311. t->set_color("symbol_color","TextEdit", control_font_color_hover );
  312. t->set_color("brace_mismatch_color","TextEdit", Color(1,0.2,0.2) );
  313. t->set_constant("completion_lines","TextEdit", 7 );
  314. t->set_constant("completion_max_width","TextEdit", 50 );
  315. t->set_constant("completion_scroll_width","TextEdit", 3 );
  316. t->set_constant("line_spacing","TextEdit",4 );
  317. Ref<Texture> empty_icon = memnew( ImageTexture );
  318. // HScrollBar
  319. t->set_stylebox("scroll","HScrollBar", make_stylebox( scroll_bg_png,5,5,5,5,0,0,0,0) );
  320. t->set_stylebox("scroll_focus","HScrollBar", make_stylebox( scroll_bg_png,5,5,5,5,0,0,0,0) );
  321. t->set_stylebox("grabber","HScrollBar", make_stylebox( scroll_grabber_png,5,5,5,5,2,2,2,2) );
  322. t->set_stylebox("grabber_hilite","HScrollBar", make_stylebox( scroll_grabber_hl_png,5,5,5,5,2,2,2,2) );
  323. t->set_icon("increment","HScrollBar",empty_icon);
  324. t->set_icon("increment_hilite","HScrollBar",empty_icon);
  325. t->set_icon("decrement","HScrollBar",empty_icon);
  326. t->set_icon("decrement_hilite","HScrollBar",empty_icon);
  327. // VScrollBar
  328. t->set_stylebox("scroll","VScrollBar", make_stylebox( scroll_bg_png,5,5,5,5,0,0,0,0) );
  329. t->set_stylebox("scroll_focus","VScrollBar", make_stylebox( scroll_bg_png,5,5,5,5,0,0,0,0) );
  330. t->set_stylebox("grabber","VScrollBar", make_stylebox( scroll_grabber_png,5,5,5,5,2,2,2,2) );
  331. t->set_stylebox("grabber_hilite","VScrollBar", make_stylebox( scroll_grabber_hl_png,5,5,5,5,2,2,2,2) );
  332. t->set_icon("increment","VScrollBar",empty_icon);
  333. t->set_icon("increment_hilite","VScrollBar",empty_icon);
  334. t->set_icon("decrement","VScrollBar",empty_icon);
  335. t->set_icon("decrement_hilite","VScrollBar",empty_icon);
  336. // HSlider
  337. t->set_stylebox("slider","HSlider", make_stylebox( hslider_bg_png,4,4,4,4) );
  338. t->set_stylebox("grabber_hilite","HSlider", make_stylebox( hslider_grabber_hl_png,6,6,6,6) );
  339. t->set_stylebox("focus","HSlider", focus );
  340. t->set_icon("grabber","HSlider", make_icon( hslider_grabber_png ) );
  341. t->set_icon("grabber_hilite","HSlider", make_icon( hslider_grabber_hl_png ) );
  342. t->set_icon("tick","HSlider", make_icon( hslider_tick_png ) );
  343. // VSlider
  344. t->set_stylebox("slider","VSlider", make_stylebox( vslider_bg_png,4,4,4,4) );
  345. t->set_stylebox("grabber_hilite","VSlider", make_stylebox( vslider_grabber_hl_png,6,6,6,6) );
  346. t->set_stylebox("focus","HSlider", focus );
  347. t->set_icon("grabber","VSlider", make_icon( vslider_grabber_png) );
  348. t->set_icon("grabber_hilite","VSlider", make_icon( vslider_grabber_hl_png ) );
  349. t->set_icon("tick","VSlider", make_icon( vslider_tick_png ) );
  350. // SpinBox
  351. t->set_icon("updown","SpinBox",make_icon(spinbox_updown_png));
  352. // WindowDialog
  353. Ref<StyleBoxTexture> style_pp_win = sb_expand(make_stylebox( popup_window_png,10,30,10,8),8,26,8,4);
  354. /*for(int i=0;i<4;i++)
  355. style_pp_win->set_expand_margin_size((Margin)i,3);
  356. style_pp_win->set_expand_margin_size(MARGIN_TOP,26);*/
  357. t->set_stylebox("panel","WindowDialog", style_pp_win );
  358. t->set_icon("close","WindowDialog", make_icon( close_png ) );
  359. t->set_icon("close_hilite","WindowDialog", make_icon( close_hl_png ) );
  360. t->set_font("title_font","WindowDialog", large_font );
  361. t->set_color("title_color","WindowDialog", Color(0,0,0) );
  362. t->set_constant("close_h_ofs","WindowDialog", 22 );
  363. t->set_constant("close_v_ofs","WindowDialog", 20 );
  364. t->set_constant("titlebar_height","WindowDialog", 18 );
  365. t->set_constant("title_height","WindowDialog", 20 );
  366. // File Dialog
  367. t->set_icon("reload","FileDialog",make_icon( icon_reload_png ));
  368. // Popup
  369. Ref<StyleBoxTexture> style_pp = sb_expand( make_stylebox( popup_bg_png,5,5,5,5,4,4,4,4),2,2,2,2);
  370. Ref<StyleBoxTexture> selected = make_stylebox( selection_png,6,6,6,6);
  371. for(int i=0;i<4;i++) {
  372. selected->set_expand_margin_size(Margin(i),2);
  373. }
  374. t->set_stylebox("panel","PopupPanel", style_pp );
  375. // PopupMenu
  376. t->set_stylebox("panel","PopupMenu", make_stylebox( popup_bg_png,4,4,4,4,10,10,10,10) );
  377. t->set_stylebox("panel_disabled","PopupMenu", make_stylebox( popup_bg_disabled_png,4,4,4,4) );
  378. t->set_stylebox("hover","PopupMenu", selected );
  379. t->set_stylebox("separator","PopupMenu", make_stylebox( vseparator_png,3,3,3,3) );
  380. t->set_icon("checked","PopupMenu", make_icon(checked_png) );
  381. t->set_icon("unchecked","PopupMenu", make_icon(unchecked_png) );
  382. t->set_icon("submenu","PopupMenu", make_icon(submenu_png) );
  383. t->set_font("font","PopupMenu", default_font );
  384. t->set_color("font_color","PopupMenu", control_font_color );
  385. t->set_color("font_color_accel","PopupMenu", Color(0.7,0.7,0.7,0.8) );
  386. t->set_color("font_color_disabled","PopupMenu", Color(0.4,0.4,0.4,0.8) );
  387. t->set_color("font_color_hover","PopupMenu", control_font_color );
  388. t->set_constant("hseparation","PopupMenu",4);
  389. t->set_constant("vseparation","PopupMenu",4);
  390. // GraphNode
  391. Ref<StyleBoxTexture> graphsb = make_stylebox(graph_node_png,6,24,6,5,3,24,16,5);
  392. Ref<StyleBoxTexture> graphsbselected = make_stylebox(graph_node_selected_png,6,24,6,5,3,24,16,5);
  393. Ref<StyleBoxTexture> graphsbdefault = make_stylebox(graph_node_default_png,4,4,4,4,6,4,4,4);
  394. Ref<StyleBoxTexture> graphsbdeffocus = make_stylebox(graph_node_default_focus_png,4,4,4,4,6,4,4,4);
  395. //graphsb->set_expand_margin_size(MARGIN_LEFT,10);
  396. //graphsb->set_expand_margin_size(MARGIN_RIGHT,10);
  397. t->set_stylebox("frame","GraphNode", graphsb );
  398. t->set_stylebox("selectedframe","GraphNode", graphsbselected );
  399. t->set_stylebox("defaultframe", "GraphNode", graphsbdefault );
  400. t->set_stylebox("defaultfocus", "GraphNode", graphsbdeffocus );
  401. t->set_constant("separation","GraphNode", 1 );
  402. t->set_icon("port","GraphNode", make_icon( graph_port_png ) );
  403. t->set_icon("close","GraphNode", make_icon( graph_node_close_png ) );
  404. t->set_font("title_font","GraphNode", default_font );
  405. t->set_color("title_color","GraphNode", Color(0,0,0,1));
  406. t->set_constant("title_offset","GraphNode", 18);
  407. t->set_constant("close_offset","GraphNode", 18);
  408. t->set_constant("port_offset","GraphNode", 3);
  409. // Tree
  410. Ref<StyleBoxTexture> tree_selected = make_stylebox( selection_png,4,4,4,4,8,0,8,0);
  411. Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0);
  412. t->set_stylebox("bg","Tree", make_stylebox( tree_bg_png,4,4,4,5) );
  413. t->set_stylebox("bg_focus","Tree", focus );
  414. t->set_stylebox("selected","Tree", tree_selected_oof );
  415. t->set_stylebox("selected_focus","Tree", tree_selected );
  416. t->set_stylebox("cursor","Tree", focus );
  417. t->set_stylebox("cursor_unfocused","Tree", focus );
  418. t->set_stylebox("button_pressed","Tree",make_stylebox( button_pressed_png,4,4,4,4));
  419. t->set_stylebox("title_button_normal","Tree", make_stylebox( tree_title_png,4,4,4,4) );
  420. t->set_stylebox("title_button_pressed","Tree", make_stylebox( tree_title_pressed_png,4,4,4,4) );
  421. t->set_stylebox("title_button_hover","Tree", make_stylebox( tree_title_png,4,4,4,4) );
  422. t->set_icon("checked","Tree",make_icon(checked_png));
  423. t->set_icon("unchecked","Tree",make_icon(unchecked_png));
  424. t->set_icon("updown","Tree",make_icon(updown_png));
  425. t->set_icon("select_arrow","Tree",make_icon(dropdown_png));
  426. t->set_icon("arrow","Tree",make_icon(arrow_down_png));
  427. t->set_icon("arrow_collapsed","Tree",make_icon(arrow_right_png));
  428. t->set_font("title_button_font","Tree", default_font );
  429. t->set_font("font","Tree", default_font );
  430. t->set_color("title_button_color","Tree", control_font_color );
  431. t->set_color("font_color","Tree", control_font_color_low );
  432. t->set_color("font_color_selected","Tree", control_font_color_pressed );
  433. t->set_color("selection_color","Tree", Color(0.1,0.1,1,0.8) );
  434. t->set_color("cursor_color","Tree", Color(0,0,0) );
  435. t->set_color("guide_color","Tree", Color(0,0,0,0.1) );
  436. t->set_constant("hseparation","Tree",4);
  437. t->set_constant("vseparation","Tree",4);
  438. t->set_constant("guide_width","Tree",2);
  439. t->set_constant("item_margin","Tree",12);
  440. t->set_constant("button_margin","Tree",4);
  441. // ItemList
  442. Ref<StyleBoxTexture> item_selected = make_stylebox( selection_png,4,4,4,4,8,2,8,2);
  443. Ref<StyleBoxTexture> item_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,2,8,2);
  444. t->set_stylebox("bg","ItemList", make_stylebox( tree_bg_png,4,4,4,5) );
  445. t->set_stylebox("bg_focus","ItemList", focus );
  446. t->set_constant("hseparation","ItemList",4);
  447. t->set_constant("vseparation","ItemList",2);
  448. t->set_constant("icon_margin","ItemList",4);
  449. t->set_constant("line_separation","ItemList",2);
  450. t->set_font("font","ItemList", default_font );
  451. t->set_color("font_color","ItemList", control_font_color_lower );
  452. t->set_color("font_color_selected","ItemList", control_font_color_pressed );
  453. t->set_color("guide_color","ItemList", Color(0,0,0,0.1) );
  454. t->set_stylebox("selected","ItemList", item_selected_oof );
  455. t->set_stylebox("selected_focus","ItemList", item_selected );
  456. t->set_stylebox("cursor","ItemList", focus );
  457. t->set_stylebox("cursor_unfocused","ItemList", focus );
  458. // TextEdit
  459. t->set_stylebox("completion_selected","TextEdit", tree_selected );
  460. // TabContainer
  461. Ref<StyleBoxTexture> tc_sb = sb_expand( make_stylebox( tab_container_bg_png,4,4,4,4,4,4,4,4),3,3,3,3);
  462. tc_sb->set_expand_margin_size(MARGIN_TOP,2);
  463. tc_sb->set_default_margin(MARGIN_TOP,8);
  464. 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) );
  465. 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) );
  466. t->set_stylebox("panel","TabContainer", tc_sb );
  467. t->set_icon("increment","TabContainer",make_icon( scroll_button_right_png));
  468. t->set_icon("increment_hilite","TabContainer",make_icon( scroll_button_right_hl_png));
  469. t->set_icon("decrement","TabContainer",make_icon( scroll_button_left_png));
  470. t->set_icon("decrement_hilite","TabContainer",make_icon( scroll_button_left_hl_png));
  471. t->set_icon("menu","TabContainer",make_icon( tab_menu_png));
  472. t->set_icon("menu_hilite","TabContainer",make_icon( tab_menu_hl_png));
  473. t->set_font("font","TabContainer", default_font );
  474. t->set_color("font_color_fg","TabContainer", control_font_color_hover );
  475. t->set_color("font_color_bg","TabContainer", control_font_color_low );
  476. t->set_constant("side_margin","TabContainer", 8 );
  477. t->set_constant("top_margin","TabContainer", 24);
  478. t->set_constant("label_valign_fg","TabContainer", 0);
  479. t->set_constant("label_valign_bg","TabContainer", 2);
  480. t->set_constant("hseparation","TabContainer", 4);
  481. // Tabs
  482. t->set_stylebox("tab_fg","Tabs", sb_expand( make_stylebox( tab_current_png,4,3,4,1,16,3,16,2),2,2,2,2) );
  483. t->set_stylebox("tab_bg","Tabs", sb_expand( make_stylebox( tab_behind_png,5,4,5,1,16,5,16,2),3,3,3,3) );
  484. t->set_stylebox("panel","Tabs",tc_sb );
  485. t->set_stylebox("button_pressed","Tabs", make_stylebox( button_pressed_png,4,4,4,4) );
  486. t->set_stylebox("button","Tabs", make_stylebox( button_normal_png,4,4,4,4) );
  487. t->set_icon("increment","Tabs",make_icon( scroll_button_right_png));
  488. t->set_icon("increment_hilite","Tabs",make_icon( scroll_button_right_hl_png));
  489. t->set_icon("decrement","Tabs",make_icon( scroll_button_left_png));
  490. t->set_icon("decrement_hilite","Tabs",make_icon( scroll_button_left_hl_png));
  491. t->set_icon("close","Tabs",make_icon( tab_close_png));
  492. t->set_font("font","Tabs", default_font );
  493. t->set_color("font_color_fg","Tabs", control_font_color_hover );
  494. t->set_color("font_color_bg","Tabs", control_font_color_low );
  495. t->set_constant("top_margin","Tabs", 24);
  496. t->set_constant("label_valign_fg","Tabs", 0);
  497. t->set_constant("label_valign_bg","Tabs", 2);
  498. t->set_constant("hseparation","Tabs", 4);
  499. // Separators
  500. t->set_stylebox("separator","HSeparator", make_stylebox( vseparator_png,3,3,3,3) );
  501. t->set_stylebox("separator","VSeparator", make_stylebox( hseparator_png,3,3,3,3) );
  502. t->set_icon("close","Icons", make_icon(icon_close_png));
  503. t->set_font("source","Fonts", source_font);
  504. t->set_font("normal","Fonts", default_font );
  505. t->set_font("large","Fonts", large_font );
  506. t->set_constant("separation","HSeparator", 4);
  507. t->set_constant("separation","VSeparator", 4);
  508. // Dialogs
  509. t->set_constant("margin","Dialogs",8);
  510. t->set_constant("button_margin","Dialogs",32);
  511. // FileDialog
  512. t->set_icon("folder","FileDialog",make_icon(icon_folder_png));
  513. t->set_color("files_disabled","FileDialog",Color(0,0,0,0.7));
  514. // colorPicker
  515. t->set_constant("value_height","ColorPicker", 23 );
  516. t->set_constant("value_width","ColorPicker", 50);
  517. t->set_constant("color_width","ColorPicker", 100);
  518. t->set_constant("label_width","ColorPicker", 20);
  519. t->set_constant("hseparator","ColorPicker", 4);
  520. t->set_icon("screen_picker","ColorPicker", make_icon( icon_color_pick_png ) );
  521. t->set_icon("add_preset","ColorPicker", make_icon( icon_add_png ) );
  522. t->set_shader("uv_editor", "ColorPicker", make_shader("", uv_editor_shader_code, ""));
  523. t->set_shader("w_editor", "ColorPicker", make_shader("", w_editor_shader_code, ""));
  524. // TooltipPanel
  525. Ref<StyleBoxTexture> style_tt = make_stylebox( tooltip_bg_png,4,4,4,4);
  526. for(int i=0;i<4;i++)
  527. style_tt->set_expand_margin_size((Margin)i,4);
  528. t->set_stylebox("panel","TooltipPanel", style_tt );
  529. t->set_font("font","TooltipLabel", default_font );
  530. t->set_color("font_color","TooltipLabel", Color(0,0,0) );
  531. t->set_color("font_color_shadow","TooltipLabel", Color(0,0,0,0.1) );
  532. t->set_constant("shadow_offset_x","TooltipLabel", 1 );
  533. t->set_constant("shadow_offset_y","TooltipLabel", 1 );
  534. // RichTextLabel
  535. t->set_stylebox("focus","RichTextLabel", focus );
  536. t->set_font("normal_font","RichTextLabel", default_font );
  537. t->set_font("bold_font","RichTextLabel", default_font );
  538. t->set_font("italics_font","RichTextLabel", default_font );
  539. t->set_font("bold_italics_font","RichTextLabel", default_font );
  540. t->set_font("mono_font","RichTextLabel", default_font );
  541. t->set_color("default_color","RichTextLabel", control_font_color );
  542. t->set_color("font_color_selected","RichTextLabel", font_color_selection );
  543. t->set_color("selection_color","RichTextLabel", Color(0.1,0.1,1,0.8) );
  544. t->set_constant("line_separation","RichTextLabel", 1 );
  545. t->set_constant("table_hseparation","RichTextLabel", 3 );
  546. t->set_constant("table_vseparation","RichTextLabel", 3 );
  547. // Containers
  548. t->set_stylebox("bg","VSplitContainer", make_stylebox( vsplit_bg_png,1,1,1,1) );
  549. t->set_stylebox("bg","HSplitContainer", make_stylebox( hsplit_bg_png,1,1,1,1) );
  550. t->set_icon("grabber","VSplitContainer",make_icon(vsplitter_png));
  551. t->set_icon("grabber","HSplitContainer",make_icon(hsplitter_png));
  552. t->set_constant("separation","HBoxContainer",4);
  553. t->set_constant("separation","VBoxContainer",4);
  554. t->set_constant("margin","MarginContainer",8);
  555. t->set_constant("hseparation","GridContainer",4);
  556. t->set_constant("vseparation","GridContainer",4);
  557. t->set_constant("separation","HSplitContainer",12);
  558. t->set_constant("separation","VSplitContainer",12);
  559. t->set_constant("autohide","HSplitContainer",1);
  560. t->set_constant("autohide","VSplitContainer",1);
  561. // HButtonArray
  562. t->set_stylebox("normal","HButtonArray", make_stylebox( button_normal_png,4,4,4,4,0,4,22,4) );
  563. t->set_stylebox("selected","HButtonArray", make_stylebox( button_pressed_png,4,4,4,4,0,4,22,4) );
  564. t->set_stylebox("hover","HButtonArray", make_stylebox( button_hover_png,4,4,4,4) );
  565. t->set_font("font","HButtonArray", default_font);
  566. t->set_font("font_selected","HButtonArray", default_font);
  567. t->set_color("font_color","HButtonArray", control_font_color_low );
  568. t->set_color("font_color_selected","HButtonArray", control_font_color_hover );
  569. t->set_constant("icon_separator","HButtonArray", 4 );
  570. t->set_constant("button_separator","HButtonArray", 8 );
  571. t->set_stylebox("focus","HButtonArray", focus );
  572. // VButtonArray
  573. t->set_stylebox("normal","VButtonArray", make_stylebox( button_normal_png,4,4,4,4,0,4,22,4) );
  574. t->set_stylebox("selected","VButtonArray", make_stylebox( button_pressed_png,4,4,4,4,0,4,22,4) );
  575. t->set_stylebox("hover","VButtonArray", make_stylebox( button_hover_png,4,4,4,4) );
  576. t->set_font("font","VButtonArray", default_font);
  577. t->set_font("font_selected","VButtonArray", default_font);
  578. t->set_color("font_color","VButtonArray", control_font_color_low );
  579. t->set_color("font_color_selected","VButtonArray", control_font_color_hover );
  580. t->set_constant("icon_separator","VButtonArray", 4);
  581. t->set_constant("button_separator","VButtonArray", 8);
  582. t->set_stylebox("focus","VButtonArray", focus );
  583. // ReferenceFrame
  584. Ref<StyleBoxTexture> ttnc = make_stylebox( full_panel_bg_png,8,8,8,8);
  585. ttnc->set_draw_center(false);
  586. t->set_stylebox("border","ReferenceFrame", make_stylebox( reference_border_png,4,4,4,4) );
  587. t->set_stylebox("panelnc","Panel", ttnc );
  588. t->set_stylebox("panelf","Panel", tc_sb );
  589. t->set_stylebox("panel","PanelContainer", tc_sb );
  590. t->set_icon("minus","GraphEdit", make_icon(icon_zoom_less_png) );
  591. t->set_icon("reset","GraphEdit", make_icon(icon_zoom_reset_png) );
  592. t->set_icon("more","GraphEdit", make_icon(icon_zoom_more_png) );
  593. t->set_stylebox("bg","GraphEdit", make_stylebox( tree_bg_png,4,4,4,5) );
  594. t->set_icon( "logo","Icons", make_icon(logo_png) );
  595. // Theme
  596. Theme::set_default( t );
  597. Theme::set_default_icon( make_icon(error_icon_png) );
  598. Theme::set_default_style( make_stylebox( error_icon_png,2,2,2,2) );
  599. Theme::set_default_font( default_font );
  600. memdelete( tex_cache );
  601. }
  602. #else
  603. #include "error_icon.xpm"
  604. void make_default_theme() {
  605. Ref<Theme> t( memnew( Theme ) );
  606. Image error_img(error_icon_xpm);
  607. Ref<Texture> texture( memnew( Texture ) );
  608. texture->create_from_image( error_img );
  609. Ref<StyleBoxTexture> style( memnew( StyleBoxTexture ) );
  610. style->set_texture(texture);
  611. for(int i=0;i<4;i++) {
  612. style->set_margin_size( Margin(),8);
  613. style->set_default_margin( Margin(),8);
  614. }
  615. Ref<Font> f = make_default_font();
  616. Theme::set_default( t );
  617. Theme::set_default_icon( texture );
  618. Theme::set_default_style( style );
  619. Theme::set_default_font( f );
  620. }
  621. #endif
  622. void clear_default_theme() {
  623. Theme::set_default( Ref<Theme>() );
  624. Theme::set_default_icon( Ref< Texture >() );
  625. Theme::set_default_style( Ref< StyleBox >() );
  626. Theme::set_default_font( Ref< Font >() );
  627. }