editor_themes.cpp 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067
  1. /*************************************************************************/
  2. /* editor_themes.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "editor_themes.h"
  31. #include "core/io/resource_loader.h"
  32. #include "editor_fonts.h"
  33. #include "editor_icons.gen.h"
  34. #include "editor_scale.h"
  35. #include "editor_settings.h"
  36. #include "modules/svg/image_loader_svg.h"
  37. #include "time.h"
  38. static Ref<StyleBoxTexture> make_stylebox(Ref<Texture> p_texture, 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) {
  39. Ref<StyleBoxTexture> style(memnew(StyleBoxTexture));
  40. style->set_texture(p_texture);
  41. style->set_margin_size(MARGIN_LEFT, p_left * EDSCALE);
  42. style->set_margin_size(MARGIN_RIGHT, p_right * EDSCALE);
  43. style->set_margin_size(MARGIN_BOTTOM, p_botton * EDSCALE);
  44. style->set_margin_size(MARGIN_TOP, p_top * EDSCALE);
  45. style->set_default_margin(MARGIN_LEFT, p_margin_left * EDSCALE);
  46. style->set_default_margin(MARGIN_RIGHT, p_margin_right * EDSCALE);
  47. style->set_default_margin(MARGIN_BOTTOM, p_margin_botton * EDSCALE);
  48. style->set_default_margin(MARGIN_TOP, p_margin_top * EDSCALE);
  49. style->set_draw_center(p_draw_center);
  50. return style;
  51. }
  52. static Ref<StyleBoxEmpty> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) {
  53. Ref<StyleBoxEmpty> style(memnew(StyleBoxEmpty));
  54. style->set_default_margin(MARGIN_LEFT, p_margin_left * EDSCALE);
  55. style->set_default_margin(MARGIN_RIGHT, p_margin_right * EDSCALE);
  56. style->set_default_margin(MARGIN_BOTTOM, p_margin_bottom * EDSCALE);
  57. style->set_default_margin(MARGIN_TOP, p_margin_top * EDSCALE);
  58. return style;
  59. }
  60. static Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) {
  61. Ref<StyleBoxFlat> style(memnew(StyleBoxFlat));
  62. style->set_bg_color(p_color);
  63. style->set_default_margin(MARGIN_LEFT, p_margin_left * EDSCALE);
  64. style->set_default_margin(MARGIN_RIGHT, p_margin_right * EDSCALE);
  65. style->set_default_margin(MARGIN_BOTTOM, p_margin_bottom * EDSCALE);
  66. style->set_default_margin(MARGIN_TOP, p_margin_top * EDSCALE);
  67. return style;
  68. }
  69. static Ref<StyleBoxLine> make_line_stylebox(Color p_color, int p_thickness = 1, float p_grow = 1, bool p_vertical = false) {
  70. Ref<StyleBoxLine> style(memnew(StyleBoxLine));
  71. style->set_color(p_color);
  72. style->set_grow(p_grow);
  73. style->set_thickness(p_thickness);
  74. style->set_vertical(p_vertical);
  75. return style;
  76. }
  77. static Ref<StyleBoxFlat> change_border_color(Ref<StyleBoxFlat> p_style, Color p_color) {
  78. Ref<StyleBoxFlat> style = p_style->duplicate();
  79. style->set_border_color_all(p_color);
  80. return style;
  81. }
  82. Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, float p_scale = EDSCALE, bool p_force_filter = false) {
  83. Ref<ImageTexture> icon = memnew(ImageTexture);
  84. Ref<Image> img = memnew(Image);
  85. // dumb gizmo check
  86. bool is_gizmo = String(editor_icons_names[p_index]).begins_with("Gizmo");
  87. ImageLoaderSVG::create_image_from_string(img, editor_icons_sources[p_index], p_scale, true, p_convert_color);
  88. if ((p_scale - (float)((int)p_scale)) > 0.0 || is_gizmo || p_force_filter)
  89. icon->create_from_image(img); // in this case filter really helps
  90. else
  91. icon->create_from_image(img, 0);
  92. return icon;
  93. }
  94. #ifndef ADD_CONVERT_COLOR
  95. #define ADD_CONVERT_COLOR(dictionary, old_color, new_color) dictionary[Color::html(old_color)] = Color::html(new_color)
  96. #endif
  97. void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = true, int p_thumb_size = 32, bool p_only_thumbs = false) {
  98. #ifdef SVG_ENABLED
  99. Dictionary dark_icon_color_dictionary;
  100. if (!p_dark_theme) {
  101. //convert color: FROM TO
  102. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#e0e0e0", "#4f4f4f"); // common icon color
  103. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffffff", "#000000"); // white
  104. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#b4b4b4", "#000000"); // script darker color
  105. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#cea4f1", "#bb6dff"); // animation
  106. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#fc9c9c", "#ff5f5f"); // spatial
  107. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#a5b7f3", "#6d90ff"); // 2d
  108. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#708cea", "#0843ff"); // 2d dark
  109. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#a5efac", "#29d739"); // control
  110. // rainbow
  111. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff7070", "#ff2929"); // red
  112. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffeb70", "#ffe337"); // yellow
  113. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#9dff70", "#74ff34"); // green
  114. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#70ffb9", "#2cff98"); // aqua
  115. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#70deff", "#22ccff"); // blue
  116. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#9f70ff", "#702aff"); // purple
  117. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff70ac", "#ff2781"); // pink
  118. // audio gradient
  119. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff8484", "#ff4040"); // red
  120. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#e1dc7a", "#d6cf4b"); // yellow
  121. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#84ffb1", "#00f010"); // green
  122. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffd684", "#fea900"); // mesh (orange)
  123. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#40a2ff", "#68b6ff"); // shape (blue)
  124. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff8484", "#ff3333"); // remove (red)
  125. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#84ffb1", "#00db50"); // add (green)
  126. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#84c2ff", "#5caeff"); // selection (blue)
  127. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ea686c", "#e3383d"); // key xform (red)
  128. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#69ecbd", "#25e3a0"); // VS variant
  129. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#8da6f0", "#6d8eeb"); // VS bool
  130. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#7dc6ef", "#4fb2e9"); // VS int
  131. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#61daf4", "#27ccf0"); // VS float
  132. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#6ba7ec", "#4690e7"); // VS string
  133. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#bd91f1", "#ad76ee"); // VS vector2
  134. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#f191a5", "#ee758e"); // VS rect
  135. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#e286f0", "#dc6aed"); // VS vector3
  136. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#c4ec69", "#96ce1a"); // VS transform2D
  137. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#f77070", "#f77070"); // VS plane
  138. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ec69a3", "#ec69a3"); // VS quat
  139. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ee7991", "#ee7991"); // VS aabb
  140. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#e3ec69", "#b2bb19"); // VS basis
  141. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#f6a86e", "#f49047"); // VS transform
  142. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#6993ec", "#6993ec"); // VS path
  143. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#69ec9a", "#2ce573"); // VS rid
  144. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#79f3e8", "#12d5c3"); // VS object
  145. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#77edb1", "#57e99f"); // VS dict
  146. }
  147. // these ones should be converted even if we are using a dark theme
  148. const Color error_color = p_theme->get_color("error_color", "Editor");
  149. const Color success_color = p_theme->get_color("success_color", "Editor");
  150. const Color warning_color = p_theme->get_color("warning_color", "Editor");
  151. dark_icon_color_dictionary[Color::html("#ff5d5d")] = error_color;
  152. dark_icon_color_dictionary[Color::html("#45ff8b")] = success_color;
  153. dark_icon_color_dictionary[Color::html("#ffdd65")] = warning_color;
  154. List<String> exceptions;
  155. exceptions.push_back("EditorPivot");
  156. exceptions.push_back("EditorHandle");
  157. exceptions.push_back("Editor3DHandle");
  158. exceptions.push_back("Godot");
  159. exceptions.push_back("PanoramaSky");
  160. exceptions.push_back("ProceduralSky");
  161. exceptions.push_back("EditorControlAnchor");
  162. exceptions.push_back("DefaultProjectIcon");
  163. exceptions.push_back("GuiCloseCustomizable");
  164. exceptions.push_back("GuiGraphNodePort");
  165. exceptions.push_back("GuiResizer");
  166. exceptions.push_back("ZoomMore");
  167. exceptions.push_back("ZoomLess");
  168. exceptions.push_back("ZoomReset");
  169. exceptions.push_back("LockViewport");
  170. exceptions.push_back("GroupViewport");
  171. clock_t begin_time = clock();
  172. ImageLoaderSVG::set_convert_colors(&dark_icon_color_dictionary);
  173. // generate icons
  174. if (!p_only_thumbs)
  175. for (int i = 0; i < editor_icons_count; i++) {
  176. List<String>::Element *is_exception = exceptions.find(editor_icons_names[i]);
  177. if (is_exception) exceptions.erase(is_exception);
  178. Ref<ImageTexture> icon = editor_generate_icon(i, !is_exception);
  179. p_theme->set_icon(editor_icons_names[i], "EditorIcons", icon);
  180. }
  181. // generate thumb files with the given thumb size
  182. bool force_filter = !(p_thumb_size == 64 && p_thumb_size == 32); // we dont need filter with original resolution
  183. if (p_thumb_size >= 64) {
  184. float scale = (float)p_thumb_size / 64.0 * EDSCALE;
  185. for (int i = 0; i < editor_bg_thumbs_count; i++) {
  186. int index = editor_bg_thumbs_indices[i];
  187. List<String>::Element *is_exception = exceptions.find(editor_icons_names[index]);
  188. if (is_exception) exceptions.erase(is_exception);
  189. Ref<ImageTexture> icon = editor_generate_icon(index, !p_dark_theme && !is_exception, scale, force_filter);
  190. p_theme->set_icon(editor_icons_names[index], "EditorIcons", icon);
  191. }
  192. } else {
  193. float scale = (float)p_thumb_size / 32.0 * EDSCALE;
  194. for (int i = 0; i < editor_md_thumbs_count; i++) {
  195. int index = editor_md_thumbs_indices[i];
  196. List<String>::Element *is_exception = exceptions.find(editor_icons_names[index]);
  197. if (is_exception) exceptions.erase(is_exception);
  198. Ref<ImageTexture> icon = editor_generate_icon(index, !p_dark_theme && !is_exception, scale, force_filter);
  199. p_theme->set_icon(editor_icons_names[index], "EditorIcons", icon);
  200. }
  201. }
  202. ImageLoaderSVG::set_convert_colors(NULL);
  203. clock_t end_time = clock();
  204. double time_d = (double)(end_time - begin_time) / CLOCKS_PER_SEC;
  205. #else
  206. print_line("Sorry no icons for you");
  207. #endif
  208. }
  209. Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
  210. Ref<Theme> theme = Ref<Theme>(memnew(Theme));
  211. const float default_contrast = 0.25;
  212. //Theme settings
  213. Color accent_color = EDITOR_DEF("interface/theme/accent_color", Color::html("#699ce8"));
  214. Color base_color = EDITOR_DEF("interface/theme/base_color", Color::html("#323b4f"));
  215. float contrast = EDITOR_DEF("interface/theme/contrast", default_contrast);
  216. int preset = EDITOR_DEF("interface/theme/preset", 0);
  217. int icon_font_color_setting = EDITOR_DEF("interface/theme/icon_and_font_color", 0);
  218. bool highlight_tabs = EDITOR_DEF("interface/theme/highlight_tabs", false);
  219. int border_size = EDITOR_DEF("interface/theme/border_size", 1);
  220. bool use_gn_headers = EDITOR_DEF("interface/theme/use_graph_node_headers", false);
  221. Color script_bg_color = EDITOR_DEF("text_editor/highlighting/background_color", Color(0, 0, 0, 0));
  222. Color preset_accent_color;
  223. Color preset_base_color;
  224. float preset_contrast;
  225. switch (preset) {
  226. case 0: { // Default
  227. preset_accent_color = Color::html("#699ce8");
  228. preset_base_color = Color::html("#323b4f");
  229. preset_contrast = default_contrast;
  230. } break;
  231. case 1: { // Grey
  232. preset_accent_color = Color::html("#b8e4ff");
  233. preset_base_color = Color::html("#3d3d3d");
  234. preset_contrast = 0.2;
  235. } break;
  236. case 2: { // Godot 2
  237. preset_accent_color = Color::html("#86ace2");
  238. preset_base_color = Color::html("#3C3A44");
  239. preset_contrast = 0.25;
  240. } break;
  241. case 3: { // Arc
  242. preset_accent_color = Color::html("#5294e2");
  243. preset_base_color = Color::html("#383c4a");
  244. preset_contrast = 0.25;
  245. } break;
  246. case 4: { // Light
  247. preset_accent_color = Color::html("#2070ff");
  248. preset_base_color = Color::html("#ffffff");
  249. preset_contrast = 0.08;
  250. } break;
  251. case 5: { // Alien
  252. preset_accent_color = Color::html("#1bfe99");
  253. preset_base_color = Color::html("#2f373f");
  254. preset_contrast = 0.25;
  255. }
  256. default: { // Custom
  257. accent_color = EDITOR_DEF("interface/theme/accent_color", Color::html("#699ce8"));
  258. base_color = EDITOR_DEF("interface/theme/base_color", Color::html("#323b4f"));
  259. contrast = EDITOR_DEF("interface/theme/contrast", default_contrast);
  260. }
  261. }
  262. if (preset != 6) {
  263. accent_color = preset_accent_color;
  264. base_color = preset_base_color;
  265. contrast = preset_contrast;
  266. EditorSettings::get_singleton()->set_initial_value("interface/theme/accent_color", accent_color);
  267. EditorSettings::get_singleton()->set_initial_value("interface/theme/base_color", base_color);
  268. EditorSettings::get_singleton()->set_initial_value("interface/theme/contrast", contrast);
  269. }
  270. EditorSettings::get_singleton()->set_manually("interface/theme/preset", preset);
  271. EditorSettings::get_singleton()->set_manually("interface/theme/accent_color", accent_color);
  272. EditorSettings::get_singleton()->set_manually("interface/theme/base_color", base_color);
  273. EditorSettings::get_singleton()->set_manually("interface/theme/contrast", contrast);
  274. //Colors
  275. int AUTO_COLOR = 0;
  276. int LIGHT_COLOR = 2;
  277. bool dark_theme = (icon_font_color_setting == AUTO_COLOR && ((base_color.r + base_color.g + base_color.b) / 3.0) < 0.5) || icon_font_color_setting == LIGHT_COLOR;
  278. const Color dark_color_1 = base_color.linear_interpolate(Color(0, 0, 0, 1), contrast);
  279. const Color dark_color_2 = base_color.linear_interpolate(Color(0, 0, 0, 1), contrast * 1.5);
  280. const Color dark_color_3 = base_color.linear_interpolate(Color(0, 0, 0, 1), contrast * 2);
  281. const Color background_color = dark_color_2;
  282. // white (dark theme) or black (light theme), will be used to generate the rest of the colors
  283. const Color mono_color = dark_theme ? Color(1, 1, 1) : Color(0, 0, 0);
  284. const Color contrast_color_1 = base_color.linear_interpolate(mono_color, MAX(contrast, default_contrast));
  285. const Color contrast_color_2 = base_color.linear_interpolate(mono_color, MAX(contrast * 1.5, default_contrast * 1.5));
  286. const Color font_color = mono_color.linear_interpolate(base_color, 0.25);
  287. const Color font_color_hl = mono_color.linear_interpolate(base_color, 0.15);
  288. const Color font_color_disabled = Color(mono_color.r, mono_color.g, mono_color.b, 0.3);
  289. const Color color_disabled = mono_color.inverted().linear_interpolate(base_color, 0.7);
  290. const Color color_disabled_bg = mono_color.inverted().linear_interpolate(base_color, 0.9);
  291. const Color separator_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.1);
  292. const Color highlight_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.2);
  293. theme->set_color("accent_color", "Editor", accent_color);
  294. theme->set_color("highlight_color", "Editor", highlight_color);
  295. theme->set_color("base_color", "Editor", base_color);
  296. theme->set_color("dark_color_1", "Editor", dark_color_1);
  297. theme->set_color("dark_color_2", "Editor", dark_color_2);
  298. theme->set_color("dark_color_3", "Editor", dark_color_3);
  299. theme->set_color("contrast_color_1", "Editor", contrast_color_1);
  300. theme->set_color("contrast_color_2", "Editor", contrast_color_2);
  301. theme->set_color("font_color", "Editor", font_color);
  302. theme->set_color("highlighted_font_color", "Editor", font_color_hl);
  303. theme->set_color("disabled_font_color", "Editor", font_color_disabled);
  304. theme->set_color("mono_color", "Editor", mono_color);
  305. Color success_color = accent_color.linear_interpolate(Color(0.2, 1, 0.2), 0.6) * 1.2;
  306. Color warning_color = accent_color.linear_interpolate(Color(1, 1, 0), 0.7) * 1.2;
  307. Color error_color = accent_color.linear_interpolate(Color(1, 0, 0), 0.8) * 1.7;
  308. if (!dark_theme) {
  309. // yellow on white themes is a P.I.T.A.
  310. warning_color = accent_color.linear_interpolate(Color(1, 0.8, 0), 0.9);
  311. warning_color = warning_color.linear_interpolate(mono_color, 0.2);
  312. success_color = success_color.linear_interpolate(mono_color, 0.2);
  313. error_color = error_color.linear_interpolate(mono_color, 0.2);
  314. }
  315. theme->set_color("success_color", "Editor", success_color);
  316. theme->set_color("warning_color", "Editor", warning_color);
  317. theme->set_color("error_color", "Editor", error_color);
  318. // 2d grid color
  319. const Color grid_minor_color = mono_color * Color(1.0, 1.0, 1.0, 0.07);
  320. const Color grid_major_color = Color(font_color_disabled.r, font_color_disabled.g, font_color_disabled.b, 0.15);
  321. theme->set_color("grid_major_color", "Editor", grid_major_color);
  322. theme->set_color("grid_minor_color", "Editor", grid_minor_color);
  323. const int thumb_size = EDITOR_DEF("filesystem/file_dialog/thumbnail_size", 64);
  324. theme->set_constant("scale", "Editor", EDSCALE);
  325. theme->set_constant("thumb_size", "Editor", thumb_size);
  326. theme->set_constant("dark_theme", "Editor", dark_theme);
  327. //Register icons + font
  328. // the resolution and the icon color (dark_theme bool) has not changed, so we do not regenerate the icons
  329. if (p_theme != NULL && fabs(p_theme->get_constant("scale", "Editor") - EDSCALE) < 0.00001 && p_theme->get_constant("dark_theme", "Editor") == dark_theme) {
  330. // register already generated icons
  331. for (int i = 0; i < editor_icons_count; i++) {
  332. theme->set_icon(editor_icons_names[i], "EditorIcons", p_theme->get_icon(editor_icons_names[i], "EditorIcons"));
  333. }
  334. } else {
  335. editor_register_and_generate_icons(theme, dark_theme, thumb_size);
  336. }
  337. // thumbnail size has changed, so we regenerate the medium sizes
  338. if (p_theme != NULL && fabs((double)p_theme->get_constant("thumb_size", "Editor") - thumb_size) > 0.00001) {
  339. editor_register_and_generate_icons(p_theme, dark_theme, thumb_size, true);
  340. }
  341. editor_register_fonts(theme);
  342. // Highlighted tabs and border width
  343. Color tab_color = highlight_tabs ? base_color.linear_interpolate(font_color, contrast) : base_color;
  344. const int border_width = CLAMP(border_size, 0, 3) * EDSCALE;
  345. const int default_margin_size = 4;
  346. const int margin_size_extra = default_margin_size + CLAMP(border_size, 0, 3);
  347. // styleboxes
  348. // this is the most commonly used stylebox, variations should be made as duplicate of this
  349. Ref<StyleBoxFlat> style_default = make_flat_stylebox(base_color, default_margin_size, default_margin_size, default_margin_size, default_margin_size);
  350. style_default->set_border_width_all(border_width);
  351. style_default->set_border_color_all(base_color);
  352. style_default->set_draw_center(true);
  353. // Button and widgets
  354. const float extra_spacing = EDITOR_GET("interface/theme/additional_spacing");
  355. Ref<StyleBoxFlat> style_widget = style_default->duplicate();
  356. style_widget->set_default_margin(MARGIN_LEFT, (extra_spacing + 6) * EDSCALE);
  357. style_widget->set_default_margin(MARGIN_TOP, (extra_spacing + default_margin_size) * EDSCALE);
  358. style_widget->set_default_margin(MARGIN_RIGHT, (extra_spacing + 6) * EDSCALE);
  359. style_widget->set_default_margin(MARGIN_BOTTOM, (extra_spacing + default_margin_size) * EDSCALE);
  360. style_widget->set_bg_color(dark_color_1);
  361. style_widget->set_border_color_all(dark_color_2);
  362. Ref<StyleBoxFlat> style_widget_disabled = style_widget->duplicate();
  363. style_widget_disabled->set_border_color_all(color_disabled);
  364. style_widget_disabled->set_bg_color(color_disabled_bg);
  365. Ref<StyleBoxFlat> style_widget_focus = style_widget->duplicate();
  366. style_widget_focus->set_border_color_all(accent_color);
  367. Ref<StyleBoxFlat> style_widget_pressed = style_widget->duplicate();
  368. style_widget_pressed->set_border_color_all(accent_color);
  369. Ref<StyleBoxFlat> style_widget_hover = style_widget->duplicate();
  370. style_widget_hover->set_border_color_all(contrast_color_1);
  371. // style for windows, popups, etc..
  372. Ref<StyleBoxFlat> style_popup = style_default->duplicate();
  373. const int popup_margin_size = default_margin_size * EDSCALE * 2;
  374. style_popup->set_default_margin(MARGIN_LEFT, popup_margin_size);
  375. style_popup->set_default_margin(MARGIN_TOP, popup_margin_size);
  376. style_popup->set_default_margin(MARGIN_RIGHT, popup_margin_size);
  377. style_popup->set_default_margin(MARGIN_BOTTOM, popup_margin_size);
  378. style_popup->set_border_color_all(contrast_color_1);
  379. style_popup->set_border_width_all(MAX(EDSCALE, border_width));
  380. const Color shadow_color = Color(0, 0, 0, dark_theme ? 0.3 : 0.1);
  381. style_popup->set_shadow_color(shadow_color);
  382. style_popup->set_shadow_size(4 * EDSCALE);
  383. Ref<StyleBoxLine> style_popup_separator(memnew(StyleBoxLine));
  384. style_popup_separator->set_color(separator_color);
  385. style_popup_separator->set_grow(popup_margin_size - MAX(EDSCALE, border_width));
  386. style_popup_separator->set_thickness(MAX(EDSCALE, border_width));
  387. Ref<StyleBoxEmpty> style_empty = make_empty_stylebox(default_margin_size, default_margin_size, default_margin_size, default_margin_size);
  388. // Tabs
  389. const int tab_default_margin_side = 10 * EDSCALE + extra_spacing * EDSCALE;
  390. const int tab_default_margin_vertical = 5 * EDSCALE + extra_spacing * EDSCALE;
  391. Ref<StyleBoxFlat> style_tab_selected = style_widget->duplicate();
  392. style_tab_selected->set_border_width_all(border_width);
  393. style_tab_selected->set_border_width(MARGIN_BOTTOM, 0);
  394. style_tab_selected->set_border_color_all(dark_color_3);
  395. style_tab_selected->set_expand_margin_size(MARGIN_BOTTOM, border_width);
  396. style_tab_selected->set_default_margin(MARGIN_LEFT, tab_default_margin_side);
  397. style_tab_selected->set_default_margin(MARGIN_RIGHT, tab_default_margin_side);
  398. style_tab_selected->set_default_margin(MARGIN_BOTTOM, tab_default_margin_vertical);
  399. style_tab_selected->set_default_margin(MARGIN_TOP, tab_default_margin_vertical);
  400. style_tab_selected->set_bg_color(tab_color);
  401. Ref<StyleBoxFlat> style_tab_unselected = style_tab_selected->duplicate();
  402. style_tab_unselected->set_draw_center(false);
  403. style_tab_unselected->set_border_width_all(0);
  404. // Editor background
  405. theme->set_stylebox("Background", "EditorStyles", make_flat_stylebox(background_color, default_margin_size, default_margin_size, default_margin_size, default_margin_size));
  406. // Focus
  407. Ref<StyleBoxFlat> style_focus = style_default->duplicate();
  408. style_focus->set_draw_center(false);
  409. style_focus->set_border_color_all(contrast_color_2);
  410. theme->set_stylebox("Focus", "EditorStyles", style_focus);
  411. // Menu
  412. Ref<StyleBoxFlat> style_menu = style_widget->duplicate();
  413. style_menu->set_draw_center(false);
  414. style_menu->set_border_width_all(0);
  415. theme->set_stylebox("panel", "PanelContainer", style_menu);
  416. theme->set_stylebox("MenuPanel", "EditorStyles", style_menu);
  417. // Script Editor
  418. theme->set_stylebox("ScriptEditorPanel", "EditorStyles", make_empty_stylebox(default_margin_size, 0, default_margin_size, default_margin_size));
  419. theme->set_stylebox("ScriptEditor", "EditorStyles", make_empty_stylebox(0, 0, 0, 0));
  420. // Play button group
  421. theme->set_stylebox("PlayButtonPanel", "EditorStyles", style_empty);
  422. //MenuButton
  423. Ref<StyleBoxFlat> style_menu_hover_border = style_widget->duplicate();
  424. style_menu_hover_border->set_draw_center(false);
  425. style_menu_hover_border->set_border_width_all(0);
  426. style_menu_hover_border->set_border_width(MARGIN_BOTTOM, border_width);
  427. style_menu_hover_border->set_border_color_all(accent_color);
  428. Ref<StyleBoxFlat> style_menu_hover_bg = style_widget->duplicate();
  429. style_menu_hover_bg->set_border_width_all(0);
  430. style_menu_hover_bg->set_bg_color(dark_color_1);
  431. theme->set_stylebox("normal", "MenuButton", style_menu);
  432. theme->set_stylebox("hover", "MenuButton", style_menu);
  433. theme->set_stylebox("pressed", "MenuButton", style_menu);
  434. theme->set_stylebox("focus", "MenuButton", style_menu);
  435. theme->set_stylebox("disabled", "MenuButton", style_menu);
  436. theme->set_stylebox("normal", "PopupMenu", style_menu);
  437. theme->set_stylebox("hover", "PopupMenu", style_menu_hover_bg);
  438. theme->set_stylebox("pressed", "PopupMenu", style_menu);
  439. theme->set_stylebox("focus", "PopupMenu", style_menu);
  440. theme->set_stylebox("disabled", "PopupMenu", style_menu);
  441. theme->set_stylebox("normal", "ToolButton", style_menu);
  442. theme->set_stylebox("hover", "ToolButton", style_menu);
  443. theme->set_stylebox("pressed", "ToolButton", style_menu);
  444. theme->set_stylebox("focus", "ToolButton", style_menu);
  445. theme->set_stylebox("disabled", "ToolButton", style_menu);
  446. theme->set_color("font_color", "MenuButton", font_color);
  447. theme->set_color("font_color_hover", "MenuButton", font_color_hl);
  448. theme->set_color("font_color", "ToolButton", font_color);
  449. theme->set_color("font_color_hover", "ToolButton", font_color_hl);
  450. theme->set_color("font_color_pressed", "ToolButton", accent_color);
  451. theme->set_stylebox("MenuHover", "EditorStyles", style_menu_hover_border);
  452. // Buttons
  453. theme->set_stylebox("normal", "Button", style_widget);
  454. theme->set_stylebox("hover", "Button", style_widget_hover);
  455. theme->set_stylebox("pressed", "Button", style_widget_pressed);
  456. theme->set_stylebox("focus", "Button", style_widget_focus);
  457. theme->set_stylebox("disabled", "Button", style_widget_disabled);
  458. theme->set_color("font_color", "Button", font_color);
  459. theme->set_color("font_color_hover", "Button", font_color_hl);
  460. theme->set_color("font_color_pressed", "Button", accent_color);
  461. theme->set_color("font_color_disabled", "Button", font_color_disabled);
  462. theme->set_color("icon_color_hover", "Button", font_color_hl);
  463. // make icon color value bigger because icon image is not complete white
  464. theme->set_color("icon_color_pressed", "Button", Color(accent_color.r * 1.15, accent_color.g * 1.15, accent_color.b * 1.15, accent_color.a));
  465. // OptionButton
  466. theme->set_stylebox("normal", "OptionButton", style_widget);
  467. theme->set_stylebox("hover", "OptionButton", style_widget_hover);
  468. theme->set_stylebox("pressed", "OptionButton", style_widget_pressed);
  469. theme->set_stylebox("focus", "OptionButton", style_widget_focus);
  470. theme->set_stylebox("disabled", "OptionButton", style_widget_disabled);
  471. theme->set_color("font_color", "OptionButton", font_color);
  472. theme->set_color("font_color_hover", "OptionButton", font_color_hl);
  473. theme->set_color("font_color_pressed", "OptionButton", accent_color);
  474. theme->set_color("font_color_disabled", "OptionButton", font_color_disabled);
  475. theme->set_color("icon_color_hover", "OptionButton", font_color_hl);
  476. theme->set_icon("arrow", "OptionButton", theme->get_icon("GuiOptionArrow", "EditorIcons"));
  477. theme->set_constant("arrow_margin", "OptionButton", default_margin_size * EDSCALE);
  478. theme->set_constant("modulate_arrow", "OptionButton", true);
  479. // CheckButton
  480. theme->set_icon("on", "CheckButton", theme->get_icon("GuiToggleOn", "EditorIcons"));
  481. theme->set_icon("off", "CheckButton", theme->get_icon("GuiToggleOff", "EditorIcons"));
  482. theme->set_color("font_color", "CheckButton", font_color);
  483. theme->set_color("font_color_hover", "CheckButton", font_color_hl);
  484. theme->set_color("font_color_pressed", "CheckButton", accent_color);
  485. theme->set_color("font_color_disabled", "CheckButton", font_color_disabled);
  486. theme->set_color("icon_color_hover", "CheckButton", font_color_hl);
  487. // Checkbox
  488. theme->set_icon("checked", "CheckBox", theme->get_icon("GuiChecked", "EditorIcons"));
  489. theme->set_icon("unchecked", "CheckBox", theme->get_icon("GuiUnchecked", "EditorIcons"));
  490. theme->set_icon("radio_checked", "CheckBox", theme->get_icon("GuiRadioChecked", "EditorIcons"));
  491. theme->set_icon("radio_unchecked", "CheckBox", theme->get_icon("GuiRadioUnchecked", "EditorIcons"));
  492. theme->set_color("font_color", "CheckBox", font_color);
  493. theme->set_color("font_color_hover", "CheckBox", font_color_hl);
  494. theme->set_color("font_color_pressed", "CheckBox", accent_color);
  495. theme->set_color("font_color_disabled", "CheckBox", font_color_disabled);
  496. theme->set_color("icon_color_hover", "CheckBox", font_color_hl);
  497. // PopupMenu
  498. Ref<StyleBoxFlat> style_popup_menu = style_popup;
  499. theme->set_stylebox("panel", "PopupMenu", style_popup_menu);
  500. theme->set_stylebox("separator", "PopupMenu", style_popup_separator);
  501. theme->set_color("font_color", "PopupMenu", font_color);
  502. theme->set_color("font_color_hover", "PopupMenu", font_color_hl);
  503. theme->set_color("font_color_accel", "PopupMenu", font_color_disabled);
  504. theme->set_color("font_color_disabled", "PopupMenu", font_color_disabled);
  505. theme->set_icon("checked", "PopupMenu", theme->get_icon("GuiChecked", "EditorIcons"));
  506. theme->set_icon("unchecked", "PopupMenu", theme->get_icon("GuiUnchecked", "EditorIcons"));
  507. theme->set_icon("radio_checked", "PopupMenu", theme->get_icon("GuiChecked", "EditorIcons"));
  508. theme->set_icon("radio_unchecked", "PopupMenu", theme->get_icon("GuiUnchecked", "EditorIcons"));
  509. theme->set_icon("submenu", "PopupMenu", theme->get_icon("ArrowRight", "EditorIcons"));
  510. theme->set_constant("vseparation", "PopupMenu", (extra_spacing + default_margin_size) * EDSCALE);
  511. // Tree & ItemList background
  512. Ref<StyleBoxFlat> style_tree_bg = style_default->duplicate();
  513. style_tree_bg->set_bg_color(dark_color_1);
  514. style_tree_bg->set_border_color_all(dark_color_3);
  515. theme->set_stylebox("bg", "Tree", style_tree_bg);
  516. const Color guide_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.05);
  517. // Tree
  518. theme->set_icon("checked", "Tree", theme->get_icon("GuiChecked", "EditorIcons"));
  519. theme->set_icon("unchecked", "Tree", theme->get_icon("GuiUnchecked", "EditorIcons"));
  520. theme->set_icon("arrow", "Tree", theme->get_icon("GuiTreeArrowDown", "EditorIcons"));
  521. theme->set_icon("arrow_collapsed", "Tree", theme->get_icon("GuiTreeArrowRight", "EditorIcons"));
  522. theme->set_icon("updown", "Tree", theme->get_icon("GuiTreeUpdown", "EditorIcons"));
  523. theme->set_icon("select_arrow", "Tree", theme->get_icon("GuiDropdown", "EditorIcons"));
  524. theme->set_icon("select_option", "Tree", theme->get_icon("GuiTreeOption", "EditorIcons"));
  525. theme->set_stylebox("bg_focus", "Tree", style_focus);
  526. theme->set_stylebox("custom_button", "Tree", make_empty_stylebox());
  527. theme->set_stylebox("custom_button_pressed", "Tree", make_empty_stylebox());
  528. theme->set_stylebox("custom_button_hover", "Tree", style_widget);
  529. theme->set_color("custom_button_font_highlight", "Tree", font_color_hl);
  530. theme->set_color("font_color", "Tree", font_color);
  531. theme->set_color("font_color_selected", "Tree", mono_color);
  532. theme->set_color("title_button_color", "Tree", font_color);
  533. theme->set_color("guide_color", "Tree", guide_color);
  534. theme->set_color("drop_position_color", "Tree", accent_color);
  535. theme->set_constant("vseparation", "Tree", (extra_spacing + default_margin_size) * EDSCALE);
  536. theme->set_constant("hseparation", "Tree", (extra_spacing + default_margin_size) * EDSCALE);
  537. theme->set_constant("guide_width", "Tree", border_width);
  538. theme->set_constant("item_margin", "Tree", 3 * default_margin_size * EDSCALE);
  539. theme->set_constant("button_margin", "Tree", default_margin_size * EDSCALE);
  540. theme->set_constant("draw_relationship_lines", "Tree", 0);
  541. theme->set_constant("scroll_border", "Tree", default_margin_size * EDSCALE);
  542. theme->set_constant("scroll_speed", "Tree", 12);
  543. Ref<StyleBoxFlat> style_tree_btn = style_default->duplicate();
  544. style_tree_btn->set_bg_color(contrast_color_1);
  545. style_tree_btn->set_border_width_all(0);
  546. theme->set_stylebox("button_pressed", "Tree", style_tree_btn);
  547. Ref<StyleBoxFlat> style_tree_focus = style_default->duplicate();
  548. style_tree_focus->set_bg_color(highlight_color);
  549. style_tree_focus->set_border_width_all(0);
  550. theme->set_stylebox("selected_focus", "Tree", style_tree_focus);
  551. Ref<StyleBoxFlat> style_tree_selected = style_tree_focus->duplicate();
  552. theme->set_stylebox("selected", "Tree", style_tree_selected);
  553. Ref<StyleBoxFlat> style_tree_cursor = style_default->duplicate();
  554. style_tree_cursor->set_draw_center(false);
  555. style_tree_cursor->set_border_width_all(border_width);
  556. style_tree_cursor->set_border_color_all(contrast_color_1);
  557. Ref<StyleBoxFlat> style_tree_title = style_default->duplicate();
  558. style_tree_title->set_bg_color(dark_color_3);
  559. style_tree_title->set_border_width_all(0);
  560. theme->set_stylebox("cursor", "Tree", style_tree_cursor);
  561. theme->set_stylebox("cursor_unfocused", "Tree", style_tree_cursor);
  562. theme->set_stylebox("title_button_normal", "Tree", style_tree_title);
  563. theme->set_stylebox("title_button_hover", "Tree", style_tree_title);
  564. theme->set_stylebox("title_button_pressed", "Tree", style_tree_title);
  565. Color prop_category_color = dark_color_1.linear_interpolate(mono_color, 0.12);
  566. Color prop_section_color = dark_color_1.linear_interpolate(mono_color, 0.09);
  567. Color prop_subsection_color = dark_color_1.linear_interpolate(mono_color, 0.06);
  568. theme->set_color("prop_category", "Editor", prop_category_color);
  569. theme->set_color("prop_section", "Editor", prop_section_color);
  570. theme->set_color("prop_subsection", "Editor", prop_subsection_color);
  571. theme->set_color("drop_position_color", "Tree", accent_color);
  572. // ItemList
  573. Ref<StyleBoxFlat> style_itemlist_bg = style_default->duplicate();
  574. style_itemlist_bg->set_bg_color(dark_color_1);
  575. style_itemlist_bg->set_border_width_all(border_width);
  576. style_itemlist_bg->set_border_color_all(dark_color_3);
  577. Ref<StyleBoxFlat> style_itemlist_cursor = style_default->duplicate();
  578. style_itemlist_cursor->set_draw_center(false);
  579. style_itemlist_cursor->set_border_width_all(border_width);
  580. style_itemlist_cursor->set_border_color_all(highlight_color);
  581. theme->set_stylebox("cursor", "ItemList", style_itemlist_cursor);
  582. theme->set_stylebox("cursor_unfocused", "ItemList", style_itemlist_cursor);
  583. theme->set_stylebox("selected_focus", "ItemList", style_tree_focus);
  584. theme->set_stylebox("selected", "ItemList", style_tree_selected);
  585. theme->set_stylebox("bg_focus", "ItemList", style_focus);
  586. theme->set_stylebox("bg", "ItemList", style_itemlist_bg);
  587. theme->set_color("font_color", "ItemList", font_color);
  588. theme->set_color("font_color_selected", "ItemList", mono_color);
  589. theme->set_color("guide_color", "ItemList", guide_color);
  590. theme->set_constant("vseparation", "ItemList", 2 * EDSCALE);
  591. theme->set_constant("hseparation", "ItemList", 2 * EDSCALE);
  592. theme->set_constant("icon_margin", "ItemList", default_margin_size * EDSCALE);
  593. theme->set_constant("line_separation", "ItemList", 2 * EDSCALE);
  594. // Tabs & TabContainer
  595. theme->set_stylebox("tab_fg", "TabContainer", style_tab_selected);
  596. theme->set_stylebox("tab_bg", "TabContainer", style_tab_unselected);
  597. theme->set_stylebox("tab_fg", "Tabs", style_tab_selected);
  598. theme->set_stylebox("tab_bg", "Tabs", style_tab_unselected);
  599. theme->set_color("font_color_fg", "TabContainer", font_color);
  600. theme->set_color("font_color_bg", "TabContainer", font_color_disabled);
  601. theme->set_color("font_color_fg", "Tabs", font_color);
  602. theme->set_color("font_color_bg", "Tabs", font_color_disabled);
  603. theme->set_icon("menu", "TabContainer", theme->get_icon("GuiTabMenu", "EditorIcons"));
  604. theme->set_icon("menu_hl", "TabContainer", theme->get_icon("GuiTabMenu", "EditorIcons"));
  605. theme->set_stylebox("SceneTabFG", "EditorStyles", style_tab_selected);
  606. theme->set_stylebox("SceneTabBG", "EditorStyles", style_tab_unselected);
  607. theme->set_icon("close", "Tabs", theme->get_icon("GuiClose", "EditorIcons"));
  608. theme->set_stylebox("button_pressed", "Tabs", style_menu);
  609. theme->set_stylebox("button", "Tabs", style_menu);
  610. theme->set_icon("increment", "TabContainer", theme->get_icon("GuiScrollArrowRight", "EditorIcons"));
  611. theme->set_icon("decrement", "TabContainer", theme->get_icon("GuiScrollArrowLeft", "EditorIcons"));
  612. // Content of each tab
  613. Ref<StyleBoxFlat> style_content_panel = style_default->duplicate();
  614. style_content_panel->set_border_color_all(dark_color_3);
  615. style_content_panel->set_border_width_all(border_width);
  616. // compensate the border
  617. style_content_panel->set_default_margin(MARGIN_TOP, margin_size_extra * EDSCALE);
  618. style_content_panel->set_default_margin(MARGIN_RIGHT, margin_size_extra * EDSCALE);
  619. style_content_panel->set_default_margin(MARGIN_BOTTOM, margin_size_extra * EDSCALE);
  620. style_content_panel->set_default_margin(MARGIN_LEFT, margin_size_extra * EDSCALE);
  621. // this is the stylebox used in 3d and 2d viewports (no borders)
  622. Ref<StyleBoxFlat> style_content_panel_vp = style_content_panel->duplicate();
  623. style_content_panel_vp->set_default_margin(MARGIN_LEFT, border_width * 2);
  624. style_content_panel_vp->set_default_margin(MARGIN_TOP, default_margin_size * EDSCALE);
  625. style_content_panel_vp->set_default_margin(MARGIN_RIGHT, border_width * 2);
  626. style_content_panel_vp->set_default_margin(MARGIN_BOTTOM, border_width * 2);
  627. theme->set_stylebox("panel", "TabContainer", style_content_panel);
  628. theme->set_stylebox("Content", "EditorStyles", style_content_panel_vp);
  629. // Separators
  630. theme->set_stylebox("separator", "HSeparator", make_line_stylebox(separator_color, border_width));
  631. theme->set_stylebox("separator", "VSeparator", make_line_stylebox(separator_color, border_width, 0, true));
  632. // Debugger
  633. Ref<StyleBoxFlat> style_panel_debugger = style_content_panel->duplicate();
  634. style_panel_debugger->set_border_width(MARGIN_BOTTOM, 0);
  635. theme->set_stylebox("DebuggerPanel", "EditorStyles", style_panel_debugger);
  636. theme->set_stylebox("DebuggerTabFG", "EditorStyles", style_tab_selected);
  637. theme->set_stylebox("DebuggerTabBG", "EditorStyles", style_tab_unselected);
  638. Ref<StyleBoxFlat> style_panel_invisible_top = style_content_panel->duplicate();
  639. int stylebox_offset = theme->get_font("tab_fg", "TabContainer")->get_height() + theme->get_stylebox("tab_fg", "TabContainer")->get_minimum_size().height + theme->get_stylebox("panel", "TabContainer")->get_default_margin(MARGIN_TOP);
  640. style_panel_invisible_top->set_expand_margin_size(MARGIN_TOP, -stylebox_offset);
  641. theme->set_stylebox("BottomPanelDebuggerOverride", "EditorStyles", style_panel_invisible_top);
  642. // LineEdit
  643. theme->set_stylebox("normal", "LineEdit", style_widget);
  644. theme->set_stylebox("focus", "LineEdit", style_widget_focus);
  645. theme->set_stylebox("read_only", "LineEdit", style_widget_disabled);
  646. theme->set_color("read_only", "LineEdit", font_color_disabled);
  647. theme->set_color("font_color", "LineEdit", font_color);
  648. theme->set_color("cursor_color", "LineEdit", font_color);
  649. // TextEdit
  650. theme->set_stylebox("normal", "TextEdit", style_widget);
  651. theme->set_stylebox("focus", "TextEdit", style_widget_hover);
  652. theme->set_constant("side_margin", "TabContainer", 0);
  653. theme->set_icon("tab", "TextEdit", theme->get_icon("GuiTab", "EditorIcons"));
  654. theme->set_color("font_color", "TextEdit", font_color);
  655. theme->set_color("caret_color", "TextEdit", highlight_color);
  656. // H/VSplitContainer
  657. theme->set_stylebox("bg", "VSplitContainer", make_stylebox(theme->get_icon("GuiVsplitBg", "EditorIcons"), 1, 1, 1, 1));
  658. theme->set_stylebox("bg", "HSplitContainer", make_stylebox(theme->get_icon("GuiHsplitBg", "EditorIcons"), 1, 1, 1, 1));
  659. theme->set_icon("grabber", "VSplitContainer", theme->get_icon("GuiVsplitter", "EditorIcons"));
  660. theme->set_icon("grabber", "HSplitContainer", theme->get_icon("GuiHsplitter", "EditorIcons"));
  661. theme->set_constant("separation", "HSplitContainer", default_margin_size * 2 * EDSCALE);
  662. theme->set_constant("separation", "VSplitContainer", default_margin_size * 2 * EDSCALE);
  663. // Containers
  664. theme->set_constant("separation", "BoxContainer", default_margin_size * EDSCALE);
  665. theme->set_constant("separation", "HBoxContainer", default_margin_size * EDSCALE);
  666. theme->set_constant("separation", "VBoxContainer", default_margin_size * EDSCALE);
  667. theme->set_constant("margin_left", "MarginContainer", 0);
  668. theme->set_constant("margin_top", "MarginContainer", 0);
  669. theme->set_constant("margin_right", "MarginContainer", 0);
  670. theme->set_constant("margin_bottom", "MarginContainer", 0);
  671. theme->set_constant("hseparation", "GridContainer", default_margin_size * EDSCALE);
  672. theme->set_constant("vseparation", "GridContainer", default_margin_size * EDSCALE);
  673. // WindowDialog
  674. Ref<StyleBoxFlat> style_window = style_popup->duplicate();
  675. style_window->set_border_color_all(tab_color);
  676. style_window->set_border_width(MARGIN_TOP, 24 * EDSCALE);
  677. style_window->set_expand_margin_size(MARGIN_TOP, 24 * EDSCALE);
  678. theme->set_stylebox("panel", "WindowDialog", style_window);
  679. theme->set_color("title_color", "WindowDialog", font_color);
  680. theme->set_icon("close", "WindowDialog", theme->get_icon("GuiClose", "EditorIcons"));
  681. theme->set_icon("close_highlight", "WindowDialog", theme->get_icon("GuiClose", "EditorIcons"));
  682. theme->set_constant("close_h_ofs", "WindowDialog", 22 * EDSCALE);
  683. theme->set_constant("close_v_ofs", "WindowDialog", 20 * EDSCALE);
  684. theme->set_constant("title_height", "WindowDialog", 24 * EDSCALE);
  685. // complex window, for now only Editor settings and Project settings
  686. Ref<StyleBoxFlat> style_complex_window = style_window->duplicate();
  687. style_complex_window->set_bg_color(dark_color_2);
  688. style_complex_window->set_border_color_all(highlight_tabs ? tab_color : dark_color_2);
  689. theme->set_stylebox("panel", "EditorSettingsDialog", style_complex_window);
  690. theme->set_stylebox("panel", "ProjectSettingsEditor", style_complex_window);
  691. theme->set_stylebox("panel", "EditorAbout", style_complex_window);
  692. // HScrollBar
  693. Ref<Texture> empty_icon = memnew(ImageTexture);
  694. theme->set_stylebox("scroll", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  695. theme->set_stylebox("scroll_focus", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  696. theme->set_stylebox("grabber", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabber", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  697. theme->set_stylebox("grabber_highlight", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberHl", "EditorIcons"), 5, 5, 5, 5, 2, 2, 2, 2));
  698. theme->set_stylebox("grabber_pressed", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberPressed", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  699. theme->set_icon("increment", "HScrollBar", empty_icon);
  700. theme->set_icon("increment_highlight", "HScrollBar", empty_icon);
  701. theme->set_icon("decrement", "HScrollBar", empty_icon);
  702. theme->set_icon("decrement_highlight", "HScrollBar", empty_icon);
  703. // VScrollBar
  704. theme->set_stylebox("scroll", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  705. theme->set_stylebox("scroll_focus", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  706. theme->set_stylebox("grabber", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabber", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  707. theme->set_stylebox("grabber_highlight", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberHl", "EditorIcons"), 5, 5, 5, 5, 2, 2, 2, 2));
  708. theme->set_stylebox("grabber_pressed", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberPressed", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  709. theme->set_icon("increment", "VScrollBar", empty_icon);
  710. theme->set_icon("increment_highlight", "VScrollBar", empty_icon);
  711. theme->set_icon("decrement", "VScrollBar", empty_icon);
  712. theme->set_icon("decrement_highlight", "VScrollBar", empty_icon);
  713. // HSlider
  714. theme->set_icon("grabber_highlight", "HSlider", theme->get_icon("GuiSliderGrabberHl", "EditorIcons"));
  715. theme->set_icon("grabber", "HSlider", theme->get_icon("GuiSliderGrabber", "EditorIcons"));
  716. theme->set_stylebox("slider", "HSlider", make_flat_stylebox(dark_color_3, 0, default_margin_size / 2, 0, default_margin_size / 2));
  717. theme->set_stylebox("grabber_area", "HSlider", make_flat_stylebox(contrast_color_1, 0, default_margin_size / 2, 0, default_margin_size / 2));
  718. // VSlider
  719. theme->set_icon("grabber", "VSlider", theme->get_icon("GuiSliderGrabber", "EditorIcons"));
  720. theme->set_icon("grabber_highlight", "VSlider", theme->get_icon("GuiSliderGrabberHl", "EditorIcons"));
  721. theme->set_stylebox("slider", "VSlider", make_flat_stylebox(dark_color_3, default_margin_size / 2, 0, default_margin_size / 2, 0));
  722. theme->set_stylebox("grabber_area", "VSlider", make_flat_stylebox(contrast_color_1, default_margin_size / 2, 0, default_margin_size / 2, 0));
  723. //RichTextLabel
  724. theme->set_color("default_color", "RichTextLabel", font_color);
  725. theme->set_stylebox("focus", "RichTextLabel", make_empty_stylebox());
  726. theme->set_stylebox("normal", "RichTextLabel", style_tree_bg);
  727. theme->set_color("headline_color", "EditorHelp", mono_color);
  728. // Panel
  729. theme->set_stylebox("panel", "Panel", make_flat_stylebox(dark_color_1, 6, 4, 6, 4));
  730. // Label
  731. theme->set_stylebox("normal", "Label", style_empty);
  732. theme->set_color("font_color", "Label", font_color);
  733. theme->set_color("font_color_shadow", "Label", Color(0, 0, 0, 0));
  734. theme->set_constant("shadow_offset_x", "Label", 1 * EDSCALE);
  735. theme->set_constant("shadow_offset_y", "Label", 1 * EDSCALE);
  736. theme->set_constant("shadow_as_outline", "Label", 0 * EDSCALE);
  737. theme->set_constant("line_spacing", "Label", 3 * EDSCALE);
  738. // TooltipPanel
  739. Ref<StyleBoxFlat> style_tooltip = style_popup->duplicate();
  740. style_tooltip->set_bg_color(Color(mono_color.r, mono_color.g, mono_color.b, 0.9));
  741. style_tooltip->set_border_width_all(border_width);
  742. style_tooltip->set_border_color_all(mono_color);
  743. theme->set_color("font_color", "TooltipLabel", font_color.inverted());
  744. theme->set_color("font_color_shadow", "TooltipLabel", mono_color.inverted() * Color(1, 1, 1, 0.1));
  745. theme->set_stylebox("panel", "TooltipPanel", style_tooltip);
  746. // PopupPanel
  747. theme->set_stylebox("panel", "PopupPanel", style_popup);
  748. // SpinBox
  749. theme->set_icon("updown", "SpinBox", theme->get_icon("GuiSpinboxUpdown", "EditorIcons"));
  750. // ProgressBar
  751. theme->set_stylebox("bg", "ProgressBar", make_stylebox(theme->get_icon("GuiProgressBar", "EditorIcons"), 4, 4, 4, 4, 0, 0, 0, 0));
  752. theme->set_stylebox("fg", "ProgressBar", make_stylebox(theme->get_icon("GuiProgressFill", "EditorIcons"), 6, 6, 6, 6, 2, 1, 2, 1));
  753. theme->set_color("font_color", "ProgressBar", font_color);
  754. // GraphEdit
  755. theme->set_stylebox("bg", "GraphEdit", style_tree_bg);
  756. theme->set_color("grid_major", "GraphEdit", grid_major_color);
  757. theme->set_color("grid_minor", "GraphEdit", grid_minor_color);
  758. theme->set_icon("minus", "GraphEdit", theme->get_icon("ZoomLess", "EditorIcons"));
  759. theme->set_icon("more", "GraphEdit", theme->get_icon("ZoomMore", "EditorIcons"));
  760. theme->set_icon("reset", "GraphEdit", theme->get_icon("ZoomReset", "EditorIcons"));
  761. theme->set_icon("snap", "GraphEdit", theme->get_icon("SnapGrid", "EditorIcons"));
  762. theme->set_constant("bezier_len_pos", "GraphEdit", 80 * EDSCALE);
  763. theme->set_constant("bezier_len_neg", "GraphEdit", 160 * EDSCALE);
  764. // GraphNode
  765. const float mv = dark_theme ? 0.0 : 1.0;
  766. const float mv2 = 1.0 - mv;
  767. const int gn_margin_side = 28;
  768. Ref<StyleBoxFlat> graphsb = make_flat_stylebox(Color(mv, mv, mv, 0.7), gn_margin_side, 24, gn_margin_side, 5);
  769. graphsb->set_border_width_all(border_width);
  770. graphsb->set_border_color_all(Color(mv2, mv2, mv2, 0.9));
  771. Ref<StyleBoxFlat> graphsbselected = make_flat_stylebox(Color(mv, mv, mv, 0.9), gn_margin_side, 24, gn_margin_side, 5);
  772. graphsbselected->set_border_width_all(border_width);
  773. graphsbselected->set_border_color_all(Color(accent_color.r, accent_color.g, accent_color.b, 0.9));
  774. graphsbselected->set_shadow_size(8 * EDSCALE);
  775. graphsbselected->set_shadow_color(shadow_color);
  776. Ref<StyleBoxFlat> graphsbcomment = make_flat_stylebox(Color(mv, mv, mv, 0.3), gn_margin_side, 24, gn_margin_side, 5);
  777. graphsbcomment->set_border_width_all(border_width);
  778. graphsbcomment->set_border_color_all(Color(mv2, mv2, mv2, 0.9));
  779. Ref<StyleBoxFlat> graphsbcommentselected = make_flat_stylebox(Color(mv, mv, mv, 0.4), gn_margin_side, 24, gn_margin_side, 5);
  780. graphsbcommentselected->set_border_width_all(border_width);
  781. graphsbcommentselected->set_border_color_all(Color(mv2, mv2, mv2, 0.9));
  782. Ref<StyleBoxFlat> graphsbbreakpoint = graphsbselected->duplicate();
  783. graphsbbreakpoint->set_draw_center(false);
  784. graphsbbreakpoint->set_border_color_all(warning_color);
  785. graphsbbreakpoint->set_shadow_color(warning_color * Color(1.0, 1.0, 1.0, 0.1));
  786. Ref<StyleBoxFlat> graphsbposition = graphsbselected->duplicate();
  787. graphsbposition->set_draw_center(false);
  788. graphsbposition->set_border_color_all(error_color);
  789. graphsbposition->set_shadow_color(error_color * Color(1.0, 1.0, 1.0, 0.2));
  790. if (use_gn_headers) {
  791. graphsb->set_border_width(MARGIN_TOP, 24 * EDSCALE);
  792. graphsbselected->set_border_width(MARGIN_TOP, 24 * EDSCALE);
  793. graphsbcomment->set_border_width(MARGIN_TOP, 24 * EDSCALE);
  794. graphsbcommentselected->set_border_width(MARGIN_TOP, 24 * EDSCALE);
  795. }
  796. theme->set_stylebox("frame", "GraphNode", graphsb);
  797. theme->set_stylebox("selectedframe", "GraphNode", graphsbselected);
  798. theme->set_stylebox("comment", "GraphNode", graphsbcomment);
  799. theme->set_stylebox("commentfocus", "GraphNode", graphsbcommentselected);
  800. theme->set_stylebox("breakpoint", "GraphNode", graphsbbreakpoint);
  801. theme->set_stylebox("position", "GraphNode", graphsbposition);
  802. theme->set_constant("port_offset", "GraphNode", 14 * EDSCALE);
  803. theme->set_constant("title_h_offset", "GraphNode", -16 * EDSCALE);
  804. theme->set_constant("close_h_offset", "GraphNode", 20 * EDSCALE);
  805. theme->set_constant("close_offset", "GraphNode", 20 * EDSCALE);
  806. theme->set_icon("close", "GraphNode", theme->get_icon("GuiCloseCustomizable", "EditorIcons"));
  807. theme->set_icon("resizer", "GraphNode", theme->get_icon("GuiResizer", "EditorIcons"));
  808. theme->set_icon("port", "GraphNode", theme->get_icon("GuiGraphNodePort", "EditorIcons"));
  809. // GridContainer
  810. theme->set_constant("vseperation", "GridContainer", (extra_spacing + default_margin_size) * EDSCALE);
  811. // FileDialog
  812. theme->set_icon("folder", "FileDialog", theme->get_icon("Folder", "EditorIcons"));
  813. theme->set_color("files_disabled", "FileDialog", font_color_disabled);
  814. // color picker
  815. theme->set_constant("margin", "ColorPicker", popup_margin_size);
  816. theme->set_constant("sv_width", "ColorPicker", 256 * EDSCALE);
  817. theme->set_constant("sv_height", "ColorPicker", 256 * EDSCALE);
  818. theme->set_constant("h_width", "ColorPicker", 30 * EDSCALE);
  819. theme->set_constant("label_width", "ColorPicker", 10 * EDSCALE);
  820. theme->set_icon("screen_picker", "ColorPicker", theme->get_icon("ColorPick", "EditorIcons"));
  821. theme->set_icon("add_preset", "ColorPicker", theme->get_icon("Add", "EditorIcons"));
  822. theme->set_icon("preset_bg", "ColorPicker", theme->get_icon("GuiMiniCheckerboard", "EditorIcons"));
  823. theme->set_icon("bg", "ColorPickerButton", theme->get_icon("GuiMiniCheckerboard", "EditorIcons"));
  824. // adaptive script theme constants
  825. // for comments and elements with lower relevance
  826. const Color dim_color = Color(font_color.r, font_color.g, font_color.b, 0.5);
  827. const float mono_value = mono_color.r;
  828. const Color alpha1 = Color(mono_value, mono_value, mono_value, 0.07);
  829. const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.14);
  830. const Color alpha3 = Color(mono_value, mono_value, mono_value, 0.5);
  831. const Color alpha4 = Color(mono_value, mono_value, mono_value, 0.7);
  832. // editor main color
  833. const Color main_color = Color::html(dark_theme ? "#57b3ff" : "#0480ff");
  834. const Color symbol_color = Color::html("#5792ff").linear_interpolate(mono_color, dark_theme ? 0.5 : 0.3);
  835. const Color keyword_color = Color::html("#ff7185");
  836. const Color basetype_color = Color::html(dark_theme ? "#42ffc2" : "#00c161");
  837. const Color type_color = basetype_color.linear_interpolate(mono_color, dark_theme ? 0.7 : 0.5);
  838. const Color comment_color = dim_color;
  839. const Color string_color = Color::html(dark_theme ? "#ffd942" : "#ffd118").linear_interpolate(mono_color, dark_theme ? 0.5 : 0.3);
  840. const Color te_background_color = Color(0, 0, 0, 0);
  841. const Color completion_background_color = base_color;
  842. const Color completion_selected_color = alpha1;
  843. const Color completion_existing_color = alpha2;
  844. const Color completion_scroll_color = alpha1;
  845. const Color completion_font_color = font_color;
  846. const Color text_color = font_color;
  847. const Color line_number_color = dim_color;
  848. const Color caret_color = mono_color;
  849. const Color caret_background_color = mono_color.inverted();
  850. const Color text_selected_color = dark_color_3;
  851. const Color selection_color = alpha2;
  852. const Color brace_mismatch_color = error_color;
  853. const Color current_line_color = alpha1;
  854. const Color line_length_guideline_color = warning_color;
  855. const Color word_highlighted_color = alpha1;
  856. const Color number_color = basetype_color.linear_interpolate(mono_color, dark_theme ? 0.5 : 0.3);
  857. const Color function_color = main_color;
  858. const Color member_variable_color = mono_color;
  859. const Color mark_color = Color(error_color.r, error_color.g, error_color.b, 0.3);
  860. const Color breakpoint_color = error_color;
  861. const Color search_result_color = alpha1;
  862. const Color search_result_border_color = alpha4;
  863. theme->set_color("text_editor/theme/symbol_color", "Editor", symbol_color);
  864. theme->set_color("text_editor/theme/keyword_color", "Editor", keyword_color);
  865. theme->set_color("text_editor/theme/basetype_color", "Editor", basetype_color);
  866. theme->set_color("text_editor/theme/type_color", "Editor", type_color);
  867. theme->set_color("text_editor/theme/comment_color", "Editor", comment_color);
  868. theme->set_color("text_editor/theme/string_color", "Editor", string_color);
  869. theme->set_color("text_editor/theme/background_color", "Editor", te_background_color);
  870. theme->set_color("text_editor/theme/completion_background_color", "Editor", completion_background_color);
  871. theme->set_color("text_editor/theme/completion_selected_color", "Editor", completion_selected_color);
  872. theme->set_color("text_editor/theme/completion_existing_color", "Editor", completion_existing_color);
  873. theme->set_color("text_editor/theme/completion_scroll_color", "Editor", completion_scroll_color);
  874. theme->set_color("text_editor/theme/completion_font_color", "Editor", completion_font_color);
  875. theme->set_color("text_editor/theme/text_color", "Editor", text_color);
  876. theme->set_color("text_editor/theme/line_number_color", "Editor", line_number_color);
  877. theme->set_color("text_editor/theme/caret_color", "Editor", caret_color);
  878. theme->set_color("text_editor/theme/caret_background_color", "Editor", caret_background_color);
  879. theme->set_color("text_editor/theme/text_selected_color", "Editor", text_selected_color);
  880. theme->set_color("text_editor/theme/selection_color", "Editor", selection_color);
  881. theme->set_color("text_editor/theme/brace_mismatch_color", "Editor", brace_mismatch_color);
  882. theme->set_color("text_editor/theme/current_line_color", "Editor", current_line_color);
  883. theme->set_color("text_editor/theme/line_length_guideline_color", "Editor", line_length_guideline_color);
  884. theme->set_color("text_editor/theme/word_highlighted_color", "Editor", word_highlighted_color);
  885. theme->set_color("text_editor/theme/number_color", "Editor", number_color);
  886. theme->set_color("text_editor/theme/function_color", "Editor", function_color);
  887. theme->set_color("text_editor/theme/member_variable_color", "Editor", member_variable_color);
  888. theme->set_color("text_editor/theme/mark_color", "Editor", mark_color);
  889. theme->set_color("text_editor/theme/breakpoint_color", "Editor", breakpoint_color);
  890. theme->set_color("text_editor/theme/search_result_color", "Editor", search_result_color);
  891. theme->set_color("text_editor/theme/search_result_border_color", "Editor", search_result_border_color);
  892. return theme;
  893. }
  894. Ref<Theme> create_custom_theme() {
  895. Ref<Theme> theme;
  896. String custom_theme = EditorSettings::get_singleton()->get("interface/theme/custom_theme");
  897. if (custom_theme != "") {
  898. theme = ResourceLoader::load(custom_theme);
  899. }
  900. String global_font = EditorSettings::get_singleton()->get("interface/editor/custom_font");
  901. if (global_font != "") {
  902. Ref<Font> fnt = ResourceLoader::load(global_font);
  903. if (fnt.is_valid()) {
  904. if (!theme.is_valid()) {
  905. theme.instance();
  906. }
  907. theme->set_default_theme_font(fnt);
  908. }
  909. }
  910. return theme;
  911. }