editor_themes.cpp 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576
  1. /*************************************************************************/
  2. /* editor_themes.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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/modules_enabled.gen.h"
  37. #ifdef MODULE_SVG_ENABLED
  38. #include "modules/svg/image_loader_svg.h"
  39. #endif
  40. static Ref<StyleBoxTexture> make_stylebox(Ref<Texture2D> p_texture, float p_left, float p_top, float p_right, float p_bottom, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1, bool p_draw_center = true) {
  41. Ref<StyleBoxTexture> style(memnew(StyleBoxTexture));
  42. style->set_texture(p_texture);
  43. style->set_margin_size(SIDE_LEFT, p_left * EDSCALE);
  44. style->set_margin_size(SIDE_RIGHT, p_right * EDSCALE);
  45. style->set_margin_size(SIDE_BOTTOM, p_bottom * EDSCALE);
  46. style->set_margin_size(SIDE_TOP, p_top * EDSCALE);
  47. style->set_default_margin(SIDE_LEFT, p_margin_left * EDSCALE);
  48. style->set_default_margin(SIDE_RIGHT, p_margin_right * EDSCALE);
  49. style->set_default_margin(SIDE_BOTTOM, p_margin_bottom * EDSCALE);
  50. style->set_default_margin(SIDE_TOP, p_margin_top * EDSCALE);
  51. style->set_draw_center(p_draw_center);
  52. return style;
  53. }
  54. 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) {
  55. Ref<StyleBoxEmpty> style(memnew(StyleBoxEmpty));
  56. style->set_default_margin(SIDE_LEFT, p_margin_left * EDSCALE);
  57. style->set_default_margin(SIDE_RIGHT, p_margin_right * EDSCALE);
  58. style->set_default_margin(SIDE_BOTTOM, p_margin_bottom * EDSCALE);
  59. style->set_default_margin(SIDE_TOP, p_margin_top * EDSCALE);
  60. return style;
  61. }
  62. 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, int p_corner_width = 0) {
  63. Ref<StyleBoxFlat> style(memnew(StyleBoxFlat));
  64. style->set_bg_color(p_color);
  65. // Adjust level of detail based on the corners' effective sizes.
  66. style->set_corner_detail(Math::ceil(1.5 * p_corner_width * EDSCALE));
  67. style->set_corner_radius_all(p_corner_width);
  68. style->set_default_margin(SIDE_LEFT, p_margin_left * EDSCALE);
  69. style->set_default_margin(SIDE_RIGHT, p_margin_right * EDSCALE);
  70. style->set_default_margin(SIDE_BOTTOM, p_margin_bottom * EDSCALE);
  71. style->set_default_margin(SIDE_TOP, p_margin_top * EDSCALE);
  72. return style;
  73. }
  74. static Ref<StyleBoxLine> make_line_stylebox(Color p_color, int p_thickness = 1, float p_grow_begin = 1, float p_grow_end = 1, bool p_vertical = false) {
  75. Ref<StyleBoxLine> style(memnew(StyleBoxLine));
  76. style->set_color(p_color);
  77. style->set_grow_begin(p_grow_begin);
  78. style->set_grow_end(p_grow_end);
  79. style->set_thickness(p_thickness);
  80. style->set_vertical(p_vertical);
  81. return style;
  82. }
  83. static Ref<Texture2D> flip_icon(Ref<Texture2D> p_texture, bool p_flip_y = false, bool p_flip_x = false) {
  84. if (!p_flip_y && !p_flip_x) {
  85. return p_texture;
  86. }
  87. Ref<ImageTexture> texture(memnew(ImageTexture));
  88. Ref<Image> img = p_texture->get_image();
  89. img = img->duplicate();
  90. if (p_flip_y) {
  91. img->flip_y();
  92. }
  93. if (p_flip_x) {
  94. img->flip_x();
  95. }
  96. texture->create_from_image(img);
  97. return texture;
  98. }
  99. #ifdef MODULE_SVG_ENABLED
  100. static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, float p_scale = EDSCALE, float p_saturation = 1.0) {
  101. Ref<ImageTexture> icon = memnew(ImageTexture);
  102. Ref<Image> img = memnew(Image);
  103. // Upsample icon generation only if the editor scale isn't an integer multiplier.
  104. // Generating upsampled icons is slower, and the benefit is hardly visible
  105. // with integer editor scales.
  106. const bool upsample = !Math::is_equal_approx(Math::round(p_scale), p_scale);
  107. ImageLoaderSVG::create_image_from_string(img, editor_icons_sources[p_index], p_scale, upsample, p_convert_color);
  108. if (p_saturation != 1.0) {
  109. img->adjust_bcs(1.0, 1.0, p_saturation);
  110. }
  111. icon->create_from_image(img); // in this case filter really helps
  112. return icon;
  113. }
  114. #endif
  115. #ifndef ADD_CONVERT_COLOR
  116. #define ADD_CONVERT_COLOR(dictionary, old_color, new_color) dictionary[Color::html(old_color)] = Color::html(new_color)
  117. #endif
  118. 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, float p_icon_saturation = 1.0) {
  119. #ifdef MODULE_SVG_ENABLED
  120. // The default icon theme is designed to be used for a dark theme.
  121. // This dictionary stores color codes to convert to other colors
  122. // for better readability on a light theme.
  123. Dictionary dark_icon_color_dictionary;
  124. // The names of the icons to never convert, even if one of their colors
  125. // are contained in the dictionary above.
  126. Set<StringName> exceptions;
  127. if (!p_dark_theme) {
  128. // Convert color: FROM TO
  129. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#e0e0e0", "#5a5a5a"); // Common icon color
  130. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffffff", "#414141"); // White
  131. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#b4b4b4", "#363636"); // Script darker color
  132. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#f9f9f9", "#606060"); // Scrollbar grabber highlight color
  133. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#c38ef1", "#a85de9"); // Animation
  134. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#fc7f7f", "#cd3838"); // Spatial
  135. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#8da5f3", "#3d64dd"); // 2D
  136. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#4b70ea", "#1a3eac"); // 2D Dark
  137. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#8eef97", "#2fa139"); // Control
  138. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffdd65", "#ca8a04"); // Node warning
  139. // Rainbow
  140. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff4545", "#ff2929"); // Red
  141. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffe345", "#ffe337"); // Yellow
  142. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#80ff45", "#74ff34"); // Green
  143. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#45ffa2", "#2cff98"); // Aqua
  144. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#45d7ff", "#22ccff"); // Blue
  145. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#8045ff", "#702aff"); // Purple
  146. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff4596", "#ff2781"); // Pink
  147. // Audio gradient
  148. // Red is defined further below.
  149. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#e1da5b", "#d6cf4b"); // Yellow
  150. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#5fff97", "#00f010"); // Green
  151. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffca5f", "#fea900"); // Mesh resource (orange)
  152. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#0787ff", "#68b6ff"); // Shape resource (blue)
  153. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff5f5f", "#ff3333"); // Red audio gradient + remove (red)
  154. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#5fff97", "#00db50"); // Add (green)
  155. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#5fb2ff", "#5caeff"); // Selection (blue)
  156. // Animation editor tracks
  157. // The property track icon color is set by the common icon color.
  158. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ea7940", "#bd5e2c"); // 3D Transform track
  159. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#3cf34e", "#16a827"); // Call Method track
  160. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#2877f6", "#236be6"); // Bezier Curve track
  161. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#eae440", "#9f9722"); // Audio Playback track
  162. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#a448f0", "#9853ce"); // Animation Playback track
  163. // TileSet editor icons
  164. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#fce00e", "#aa8d24"); // New Single Tile
  165. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#0e71fc", "#0350bd"); // New Autotile
  166. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#c6ced4", "#828f9b"); // New Atlas
  167. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#41ecad", "#25e3a0"); // VisualScript variant
  168. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#6f91f0", "#6d8eeb"); // VisualScript bool
  169. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#5abbef", "#4fb2e9"); // VisualScript int
  170. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#35d4f4", "#27ccf0"); // VisualScript float
  171. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#4593ec", "#4690e7"); // VisualScript String
  172. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ac73f1", "#ad76ee"); // VisualScript Vector2
  173. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#f1738f", "#ee758e"); // VisualScript Rect2
  174. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#de66f0", "#dc6aed"); // VisualScript Vector3
  175. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#b9ec41", "#96ce1a"); // VisualScript Transform2D
  176. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#f74949", "#f77070"); // VisualScript Plane
  177. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ec418e", "#ec69a3"); // VisualScript Quat
  178. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ee5677", "#ee7991"); // VisualScript AABB
  179. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#e1ec41", "#b2bb19"); // VisualScript Basis
  180. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#f68f45", "#f49047"); // VisualScript Transform
  181. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#417aec", "#6993ec"); // VisualScript NodePath
  182. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#41ec80", "#2ce573"); // VisualScript RID
  183. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#55f3e3", "#12d5c3"); // VisualScript Object
  184. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#54ed9e", "#57e99f"); // VisualScript Dictionary
  185. exceptions.insert("EditorPivot");
  186. exceptions.insert("EditorHandle");
  187. exceptions.insert("Editor3DHandle");
  188. exceptions.insert("EditorBoneHandle");
  189. exceptions.insert("Godot");
  190. exceptions.insert("Sky");
  191. exceptions.insert("EditorControlAnchor");
  192. exceptions.insert("DefaultProjectIcon");
  193. exceptions.insert("GuiChecked");
  194. exceptions.insert("GuiRadioChecked");
  195. exceptions.insert("GuiIndeterminate");
  196. exceptions.insert("GuiCloseCustomizable");
  197. exceptions.insert("GuiGraphNodePort");
  198. exceptions.insert("GuiResizer");
  199. exceptions.insert("ZoomMore");
  200. exceptions.insert("ZoomLess");
  201. exceptions.insert("ZoomReset");
  202. exceptions.insert("LockViewport");
  203. exceptions.insert("GroupViewport");
  204. exceptions.insert("StatusError");
  205. exceptions.insert("StatusSuccess");
  206. exceptions.insert("StatusWarning");
  207. exceptions.insert("OverbrightIndicator");
  208. }
  209. // These ones should be converted even if we are using a dark theme.
  210. const Color error_color = p_theme->get_color("error_color", "Editor");
  211. const Color success_color = p_theme->get_color("success_color", "Editor");
  212. const Color warning_color = p_theme->get_color("warning_color", "Editor");
  213. dark_icon_color_dictionary[Color::html("#ff0000")] = error_color;
  214. dark_icon_color_dictionary[Color::html("#45ff8b")] = success_color;
  215. dark_icon_color_dictionary[Color::html("#dbab09")] = warning_color;
  216. ImageLoaderSVG::set_convert_colors(&dark_icon_color_dictionary);
  217. // Generate icons.
  218. if (!p_only_thumbs) {
  219. for (int i = 0; i < editor_icons_count; i++) {
  220. float saturation = p_icon_saturation;
  221. if (strcmp(editor_icons_names[i], "DefaultProjectIcon") == 0 || strcmp(editor_icons_names[i], "Godot") == 0 || strcmp(editor_icons_names[i], "Logo") == 0) {
  222. saturation = 1.0;
  223. }
  224. const int is_exception = exceptions.has(editor_icons_names[i]);
  225. const Ref<ImageTexture> icon = editor_generate_icon(i, !is_exception, EDSCALE, saturation);
  226. p_theme->set_icon(editor_icons_names[i], "EditorIcons", icon);
  227. }
  228. }
  229. // Generate thumbnail icons with the given thumbnail size.
  230. // We don't need filtering when generating at one of the default resolutions.
  231. const bool force_filter = p_thumb_size != 64 && p_thumb_size != 32;
  232. if (p_thumb_size >= 64) {
  233. const float scale = (float)p_thumb_size / 64.0 * EDSCALE;
  234. for (int i = 0; i < editor_bg_thumbs_count; i++) {
  235. const int index = editor_bg_thumbs_indices[i];
  236. const int is_exception = exceptions.has(editor_icons_names[index]);
  237. const Ref<ImageTexture> icon = editor_generate_icon(index, !p_dark_theme && !is_exception, scale, force_filter);
  238. p_theme->set_icon(editor_icons_names[index], "EditorIcons", icon);
  239. }
  240. } else {
  241. const float scale = (float)p_thumb_size / 32.0 * EDSCALE;
  242. for (int i = 0; i < editor_md_thumbs_count; i++) {
  243. const int index = editor_md_thumbs_indices[i];
  244. const bool is_exception = exceptions.has(editor_icons_names[index]);
  245. const Ref<ImageTexture> icon = editor_generate_icon(index, !p_dark_theme && !is_exception, scale, force_filter);
  246. p_theme->set_icon(editor_icons_names[index], "EditorIcons", icon);
  247. }
  248. }
  249. ImageLoaderSVG::set_convert_colors(nullptr);
  250. #else
  251. WARN_PRINT("SVG support disabled, editor icons won't be rendered.");
  252. #endif
  253. }
  254. Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
  255. Ref<Theme> theme = Ref<Theme>(memnew(Theme));
  256. // Controls may rely on the scale for their internal drawing logic.
  257. theme->set_default_theme_base_scale(EDSCALE);
  258. // Theme settings
  259. Color accent_color = EDITOR_GET("interface/theme/accent_color");
  260. Color base_color = EDITOR_GET("interface/theme/base_color");
  261. float contrast = EDITOR_GET("interface/theme/contrast");
  262. float icon_saturation = EDITOR_GET("interface/theme/icon_saturation");
  263. float relationship_line_opacity = EDITOR_GET("interface/theme/relationship_line_opacity");
  264. String preset = EDITOR_GET("interface/theme/preset");
  265. int border_size = EDITOR_GET("interface/theme/border_size");
  266. int corner_radius = EDITOR_GET("interface/theme/corner_radius");
  267. Color preset_accent_color;
  268. Color preset_base_color;
  269. float preset_contrast = 0;
  270. const float default_contrast = 0.3;
  271. // Please use alphabetical order if you're adding a new theme here
  272. // (after "Custom")
  273. if (preset == "Custom") {
  274. accent_color = EDITOR_GET("interface/theme/accent_color");
  275. base_color = EDITOR_GET("interface/theme/base_color");
  276. contrast = EDITOR_GET("interface/theme/contrast");
  277. } else if (preset == "Breeze Dark") {
  278. preset_accent_color = Color(0.26, 0.76, 1.00);
  279. preset_base_color = Color(0.24, 0.26, 0.28);
  280. preset_contrast = default_contrast;
  281. } else if (preset == "Godot 2") {
  282. preset_accent_color = Color(0.53, 0.67, 0.89);
  283. preset_base_color = Color(0.24, 0.23, 0.27);
  284. preset_contrast = default_contrast;
  285. } else if (preset == "Grey") {
  286. preset_accent_color = Color(0.72, 0.89, 1.00);
  287. preset_base_color = Color(0.24, 0.24, 0.24);
  288. preset_contrast = default_contrast;
  289. } else if (preset == "Light") {
  290. preset_accent_color = Color(0.18, 0.50, 1.00);
  291. preset_base_color = Color(0.9, 0.9, 0.9);
  292. // A negative contrast rate looks better for light themes, since it better follows the natural order of UI "elevation".
  293. preset_contrast = -0.08;
  294. } else if (preset == "Solarized (Dark)") {
  295. preset_accent_color = Color(0.15, 0.55, 0.82);
  296. preset_base_color = Color(0.04, 0.23, 0.27);
  297. preset_contrast = default_contrast;
  298. } else if (preset == "Solarized (Light)") {
  299. preset_accent_color = Color(0.15, 0.55, 0.82);
  300. preset_base_color = Color(0.89, 0.86, 0.79);
  301. // A negative contrast rate looks better for light themes, since it better follows the natural order of UI "elevation".
  302. preset_contrast = -0.08;
  303. } else { // Default
  304. preset_accent_color = Color(0.44, 0.73, 0.98);
  305. preset_base_color = Color(0.21, 0.24, 0.29);
  306. preset_contrast = default_contrast;
  307. }
  308. if (preset != "Custom") {
  309. accent_color = preset_accent_color;
  310. base_color = preset_base_color;
  311. contrast = preset_contrast;
  312. EditorSettings::get_singleton()->set_initial_value("interface/theme/accent_color", accent_color);
  313. EditorSettings::get_singleton()->set_initial_value("interface/theme/base_color", base_color);
  314. EditorSettings::get_singleton()->set_initial_value("interface/theme/contrast", contrast);
  315. }
  316. EditorSettings::get_singleton()->set_manually("interface/theme/preset", preset);
  317. EditorSettings::get_singleton()->set_manually("interface/theme/accent_color", accent_color);
  318. EditorSettings::get_singleton()->set_manually("interface/theme/base_color", base_color);
  319. EditorSettings::get_singleton()->set_manually("interface/theme/contrast", contrast);
  320. // Colors
  321. bool dark_theme = EditorSettings::get_singleton()->is_dark_theme();
  322. const Color dark_color_1 = base_color.lerp(Color(0, 0, 0, 1), contrast);
  323. const Color dark_color_2 = base_color.lerp(Color(0, 0, 0, 1), contrast * 1.5);
  324. const Color dark_color_3 = base_color.lerp(Color(0, 0, 0, 1), contrast * 2);
  325. const Color background_color = dark_color_2;
  326. // White (dark theme) or black (light theme), will be used to generate the rest of the colors
  327. const Color mono_color = dark_theme ? Color(1, 1, 1) : Color(0, 0, 0);
  328. const Color contrast_color_1 = base_color.lerp(mono_color, MAX(contrast, default_contrast));
  329. const Color contrast_color_2 = base_color.lerp(mono_color, MAX(contrast * 1.5, default_contrast * 1.5));
  330. const Color font_color = mono_color.lerp(base_color, 0.25);
  331. const Color font_hover_color = mono_color.lerp(base_color, 0.125);
  332. const Color font_focus_color = mono_color.lerp(base_color, 0.125);
  333. const Color font_disabled_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.3);
  334. const Color font_readonly_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.65);
  335. const Color selection_color = accent_color * Color(1, 1, 1, 0.4);
  336. const Color disabled_color = mono_color.inverted().lerp(base_color, 0.7);
  337. const Color disabled_bg_color = mono_color.inverted().lerp(base_color, 0.9);
  338. Color icon_hover_color = Color(1, 1, 1) * (dark_theme ? 1.15 : 1.45);
  339. icon_hover_color.a = 1.0;
  340. Color icon_focus_color = icon_hover_color;
  341. // Make the pressed icon color overbright because icons are not completely white on a dark theme.
  342. // On a light theme, icons are dark, so we need to modulate them with an even brighter color.
  343. Color icon_pressed_color = accent_color * (dark_theme ? 1.15 : 3.5);
  344. icon_pressed_color.a = 1.0;
  345. const Color separator_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.1);
  346. const Color highlight_color = Color(accent_color.r, accent_color.g, accent_color.b, 0.275);
  347. const Color disabled_highlight_color = highlight_color.lerp(dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.5);
  348. float prev_icon_saturation = theme->has_color("icon_saturation", "Editor") ? theme->get_color("icon_saturation", "Editor").r : 1.0;
  349. theme->set_color("icon_saturation", "Editor", Color(icon_saturation, icon_saturation, icon_saturation)); // can't save single float in theme, so using color
  350. theme->set_color("accent_color", "Editor", accent_color);
  351. theme->set_color("highlight_color", "Editor", highlight_color);
  352. theme->set_color("disabled_highlight_color", "Editor", disabled_highlight_color);
  353. theme->set_color("base_color", "Editor", base_color);
  354. theme->set_color("dark_color_1", "Editor", dark_color_1);
  355. theme->set_color("dark_color_2", "Editor", dark_color_2);
  356. theme->set_color("dark_color_3", "Editor", dark_color_3);
  357. theme->set_color("contrast_color_1", "Editor", contrast_color_1);
  358. theme->set_color("contrast_color_2", "Editor", contrast_color_2);
  359. theme->set_color("box_selection_fill_color", "Editor", accent_color * Color(1, 1, 1, 0.3));
  360. theme->set_color("box_selection_stroke_color", "Editor", accent_color * Color(1, 1, 1, 0.8));
  361. theme->set_color("axis_x_color", "Editor", Color(0.96, 0.20, 0.32));
  362. theme->set_color("axis_y_color", "Editor", Color(0.53, 0.84, 0.01));
  363. theme->set_color("axis_z_color", "Editor", Color(0.16, 0.55, 0.96));
  364. theme->set_color("font_color", "Editor", font_color);
  365. theme->set_color("highlighted_font_color", "Editor", font_hover_color);
  366. theme->set_color("disabled_font_color", "Editor", font_disabled_color);
  367. theme->set_color("mono_color", "Editor", mono_color);
  368. Color success_color = Color(0.45, 0.95, 0.5);
  369. Color warning_color = Color(1, 0.87, 0.4);
  370. Color error_color = Color(1, 0.47, 0.42);
  371. Color property_color = font_color.lerp(Color(0.5, 0.5, 0.5), 0.5);
  372. Color readonly_color = property_color.lerp(dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.5);
  373. Color readonly_warning_color = error_color.lerp(dark_theme ? Color(0, 0, 0) : Color(1, 1, 1), 0.5);
  374. if (!dark_theme) {
  375. // Darken some colors to be readable on a light background
  376. success_color = success_color.lerp(mono_color, 0.35);
  377. warning_color = warning_color.lerp(mono_color, 0.35);
  378. error_color = error_color.lerp(mono_color, 0.25);
  379. }
  380. theme->set_color("success_color", "Editor", success_color);
  381. theme->set_color("warning_color", "Editor", warning_color);
  382. theme->set_color("error_color", "Editor", error_color);
  383. theme->set_color("property_color", "Editor", property_color);
  384. theme->set_color("readonly_color", "Editor", readonly_color);
  385. if (!dark_theme) {
  386. theme->set_color("vulkan_color", "Editor", Color::hex(0xad1128ff));
  387. } else {
  388. theme->set_color("vulkan_color", "Editor", Color(1.0, 0.0, 0.0));
  389. }
  390. const int thumb_size = EDITOR_GET("filesystem/file_dialog/thumbnail_size");
  391. theme->set_constant("scale", "Editor", EDSCALE);
  392. theme->set_constant("thumb_size", "Editor", thumb_size);
  393. theme->set_constant("dark_theme", "Editor", dark_theme);
  394. // Register icons + font
  395. // The resolution and the icon color (dark_theme bool) has not changed, so we do not regenerate the icons.
  396. if (p_theme != nullptr && fabs(p_theme->get_constant("scale", "Editor") - EDSCALE) < 0.00001 && (bool)p_theme->get_constant("dark_theme", "Editor") == dark_theme && prev_icon_saturation == icon_saturation) {
  397. // Register already generated icons.
  398. for (int i = 0; i < editor_icons_count; i++) {
  399. theme->set_icon(editor_icons_names[i], "EditorIcons", p_theme->get_icon(editor_icons_names[i], "EditorIcons"));
  400. }
  401. } else {
  402. editor_register_and_generate_icons(theme, dark_theme, thumb_size, false, icon_saturation);
  403. }
  404. // Thumbnail size has changed, so we regenerate the medium sizes
  405. if (p_theme != nullptr && fabs((double)p_theme->get_constant("thumb_size", "Editor") - thumb_size) > 0.00001) {
  406. editor_register_and_generate_icons(p_theme, dark_theme, thumb_size, true);
  407. }
  408. editor_register_fonts(theme);
  409. // Ensure borders are visible when using an editor scale below 100%.
  410. const int border_width = CLAMP(border_size, 0, 2) * MAX(1, EDSCALE);
  411. const int corner_width = CLAMP(corner_radius, 0, 6);
  412. const int default_margin_size = 4;
  413. const int margin_size_extra = default_margin_size + CLAMP(border_size, 0, 2);
  414. // Styleboxes
  415. // This is the most commonly used stylebox, variations should be made as duplicate of this
  416. Ref<StyleBoxFlat> style_default = make_flat_stylebox(base_color, default_margin_size, default_margin_size, default_margin_size, default_margin_size, corner_width);
  417. // Work around issue about antialiased edges being blurrier (GH-35279).
  418. style_default->set_anti_aliased(false);
  419. style_default->set_border_width_all(border_width);
  420. style_default->set_border_color(base_color);
  421. style_default->set_draw_center(true);
  422. // Button and widgets
  423. const float extra_spacing = EDITOR_GET("interface/theme/additional_spacing");
  424. const Vector2 widget_default_margin = Vector2(extra_spacing + 6, extra_spacing + default_margin_size + 1) * EDSCALE;
  425. Ref<StyleBoxFlat> style_widget = style_default->duplicate();
  426. style_widget->set_default_margin(SIDE_LEFT, widget_default_margin.x);
  427. style_widget->set_default_margin(SIDE_TOP, widget_default_margin.y);
  428. style_widget->set_default_margin(SIDE_RIGHT, widget_default_margin.x);
  429. style_widget->set_default_margin(SIDE_BOTTOM, widget_default_margin.y);
  430. style_widget->set_bg_color(dark_color_1);
  431. style_widget->set_border_color(dark_color_2);
  432. Ref<StyleBoxFlat> style_widget_disabled = style_widget->duplicate();
  433. style_widget_disabled->set_border_color(disabled_color);
  434. style_widget_disabled->set_bg_color(disabled_bg_color);
  435. Ref<StyleBoxFlat> style_widget_focus = style_widget->duplicate();
  436. style_widget_focus->set_draw_center(false);
  437. style_widget_focus->set_border_width_all(Math::round(2 * MAX(1, EDSCALE)));
  438. style_widget_focus->set_border_color(accent_color);
  439. Ref<StyleBoxFlat> style_widget_pressed = style_widget->duplicate();
  440. style_widget_pressed->set_bg_color(dark_color_1.darkened(0.125));
  441. Ref<StyleBoxFlat> style_widget_hover = style_widget->duplicate();
  442. style_widget_hover->set_bg_color(mono_color * Color(1, 1, 1, 0.11));
  443. style_widget_hover->set_border_color(mono_color * Color(1, 1, 1, 0.05));
  444. // Style for windows, popups, etc..
  445. Ref<StyleBoxFlat> style_popup = style_default->duplicate();
  446. const int popup_margin_size = default_margin_size * EDSCALE * 3;
  447. style_popup->set_default_margin(SIDE_LEFT, popup_margin_size);
  448. style_popup->set_default_margin(SIDE_TOP, popup_margin_size);
  449. style_popup->set_default_margin(SIDE_RIGHT, popup_margin_size);
  450. style_popup->set_default_margin(SIDE_BOTTOM, popup_margin_size);
  451. style_popup->set_border_color(contrast_color_1);
  452. const Color shadow_color = Color(0, 0, 0, dark_theme ? 0.3 : 0.1);
  453. style_popup->set_shadow_color(shadow_color);
  454. style_popup->set_shadow_size(4 * EDSCALE);
  455. Ref<StyleBoxLine> style_popup_separator(memnew(StyleBoxLine));
  456. style_popup_separator->set_color(separator_color);
  457. style_popup_separator->set_grow_begin(popup_margin_size - MAX(Math::round(EDSCALE), border_width));
  458. style_popup_separator->set_grow_end(popup_margin_size - MAX(Math::round(EDSCALE), border_width));
  459. style_popup_separator->set_thickness(MAX(Math::round(EDSCALE), border_width));
  460. Ref<StyleBoxLine> style_popup_labeled_separator_left(memnew(StyleBoxLine));
  461. style_popup_labeled_separator_left->set_grow_begin(popup_margin_size - MAX(Math::round(EDSCALE), border_width));
  462. style_popup_labeled_separator_left->set_color(separator_color);
  463. style_popup_labeled_separator_left->set_thickness(MAX(Math::round(EDSCALE), border_width));
  464. Ref<StyleBoxLine> style_popup_labeled_separator_right(memnew(StyleBoxLine));
  465. style_popup_labeled_separator_right->set_grow_end(popup_margin_size - MAX(Math::round(EDSCALE), border_width));
  466. style_popup_labeled_separator_right->set_color(separator_color);
  467. style_popup_labeled_separator_right->set_thickness(MAX(Math::round(EDSCALE), border_width));
  468. Ref<StyleBoxEmpty> style_empty = make_empty_stylebox(default_margin_size, default_margin_size, default_margin_size, default_margin_size);
  469. // TabBar
  470. Ref<StyleBoxFlat> style_tab_selected = style_widget->duplicate();
  471. // Add a highlight line at the top of the selected tab.
  472. style_tab_selected->set_border_width_all(0);
  473. style_tab_selected->set_border_width(SIDE_TOP, Math::round(2 * EDSCALE));
  474. // Make the highlight line prominent, but not too prominent as to not be distracting.
  475. style_tab_selected->set_border_color(dark_color_2.lerp(accent_color, 0.75));
  476. // Don't round the top corners to avoid creating a small blank space between the tabs and the main panel.
  477. // This also makes the top highlight look better.
  478. style_tab_selected->set_corner_radius_all(0);
  479. // Prevent visible artifacts and cover the top-left rounded corner of the panel below the tab if selected
  480. // We can't prevent them with both rounded corners and non-zero border width, though
  481. style_tab_selected->set_expand_margin_size(SIDE_BOTTOM, corner_width > 0 ? corner_width : border_width);
  482. style_tab_selected->set_default_margin(SIDE_LEFT, widget_default_margin.x + 2 * EDSCALE);
  483. style_tab_selected->set_default_margin(SIDE_RIGHT, widget_default_margin.x + 2 * EDSCALE);
  484. style_tab_selected->set_default_margin(SIDE_BOTTOM, widget_default_margin.y);
  485. style_tab_selected->set_default_margin(SIDE_TOP, widget_default_margin.y);
  486. style_tab_selected->set_bg_color(base_color);
  487. Ref<StyleBoxFlat> style_tab_unselected = style_tab_selected->duplicate();
  488. style_tab_unselected->set_bg_color(dark_color_1);
  489. style_tab_unselected->set_expand_margin_size(SIDE_BOTTOM, 0);
  490. // Add some spacing between unselected tabs to make them easier to distinguish from each other
  491. style_tab_unselected->set_border_color(Color(0, 0, 0, 0));
  492. style_tab_unselected->set_border_width(SIDE_LEFT, Math::round(1 * EDSCALE));
  493. style_tab_unselected->set_border_width(SIDE_RIGHT, Math::round(1 * EDSCALE));
  494. style_tab_unselected->set_default_margin(SIDE_LEFT, widget_default_margin.x + 2 * EDSCALE);
  495. style_tab_unselected->set_default_margin(SIDE_RIGHT, widget_default_margin.x + 2 * EDSCALE);
  496. Ref<StyleBoxFlat> style_tab_disabled = style_tab_selected->duplicate();
  497. style_tab_disabled->set_bg_color(disabled_bg_color);
  498. style_tab_disabled->set_expand_margin_size(SIDE_BOTTOM, 0);
  499. style_tab_disabled->set_border_color(disabled_bg_color);
  500. // Editor background
  501. Color background_color_opaque = background_color;
  502. background_color_opaque.a = 1.0;
  503. theme->set_stylebox("Background", "EditorStyles", make_flat_stylebox(background_color_opaque, default_margin_size, default_margin_size, default_margin_size, default_margin_size));
  504. // Focus
  505. theme->set_stylebox("Focus", "EditorStyles", style_widget_focus);
  506. // Use a less opaque color to be less distracting for the 2D and 3D editor viewports.
  507. Ref<StyleBoxFlat> style_widget_focus_viewport = style_widget_focus->duplicate();
  508. style_widget_focus_viewport->set_border_color(accent_color * Color(1, 1, 1, 0.5));
  509. theme->set_stylebox("FocusViewport", "EditorStyles", style_widget_focus_viewport);
  510. // Menu
  511. Ref<StyleBoxFlat> style_menu = style_widget->duplicate();
  512. style_menu->set_draw_center(false);
  513. style_menu->set_border_width_all(0);
  514. theme->set_stylebox("panel", "PanelContainer", style_menu);
  515. theme->set_stylebox("MenuPanel", "EditorStyles", style_menu);
  516. // CanvasItem Editor
  517. Ref<StyleBoxFlat> style_canvas_editor_info = make_flat_stylebox(Color(0.0, 0.0, 0.0, 0.2));
  518. style_canvas_editor_info->set_expand_margin_size_all(4 * EDSCALE);
  519. theme->set_stylebox("CanvasItemInfoOverlay", "EditorStyles", style_canvas_editor_info);
  520. // Script Editor
  521. theme->set_stylebox("ScriptEditorPanel", "EditorStyles", make_empty_stylebox(default_margin_size, 0, default_margin_size, default_margin_size));
  522. theme->set_stylebox("ScriptEditor", "EditorStyles", make_empty_stylebox(0, 0, 0, 0));
  523. // Play button group
  524. theme->set_stylebox("PlayButtonPanel", "EditorStyles", style_empty);
  525. theme->set_stylebox("normal", "MenuButton", style_menu);
  526. theme->set_stylebox("hover", "MenuButton", style_widget_hover);
  527. theme->set_stylebox("pressed", "MenuButton", style_menu);
  528. theme->set_stylebox("focus", "MenuButton", style_menu);
  529. theme->set_stylebox("disabled", "MenuButton", style_menu);
  530. theme->set_color("font_color", "MenuButton", font_color);
  531. theme->set_color("font_hover_color", "MenuButton", font_hover_color);
  532. theme->set_color("font_focus_color", "MenuButton", font_focus_color);
  533. theme->set_stylebox("MenuHover", "EditorStyles", style_widget_hover);
  534. // Buttons
  535. theme->set_stylebox("normal", "Button", style_widget);
  536. theme->set_stylebox("hover", "Button", style_widget_hover);
  537. theme->set_stylebox("pressed", "Button", style_widget_pressed);
  538. theme->set_stylebox("focus", "Button", style_widget_focus);
  539. theme->set_stylebox("disabled", "Button", style_widget_disabled);
  540. theme->set_color("font_color", "Button", font_color);
  541. theme->set_color("font_hover_color", "Button", font_hover_color);
  542. theme->set_color("font_focus_color", "Button", font_focus_color);
  543. theme->set_color("font_pressed_color", "Button", accent_color);
  544. theme->set_color("font_disabled_color", "Button", font_disabled_color);
  545. theme->set_color("icon_hover_color", "Button", icon_hover_color);
  546. theme->set_color("icon_focus_color", "Button", icon_focus_color);
  547. theme->set_color("icon_pressed_color", "Button", icon_pressed_color);
  548. // OptionButton
  549. theme->set_stylebox("focus", "OptionButton", style_widget_focus);
  550. theme->set_stylebox("normal", "OptionButton", style_widget);
  551. theme->set_stylebox("hover", "OptionButton", style_widget_hover);
  552. theme->set_stylebox("pressed", "OptionButton", style_widget_pressed);
  553. theme->set_stylebox("disabled", "OptionButton", style_widget_disabled);
  554. theme->set_stylebox("normal_mirrored", "OptionButton", style_widget);
  555. theme->set_stylebox("hover_mirrored", "OptionButton", style_widget_hover);
  556. theme->set_stylebox("pressed_mirrored", "OptionButton", style_widget_pressed);
  557. theme->set_stylebox("disabled_mirrored", "OptionButton", style_widget_disabled);
  558. theme->set_color("font_color", "OptionButton", font_color);
  559. theme->set_color("font_hover_color", "OptionButton", font_hover_color);
  560. theme->set_color("font_focus_color", "OptionButton", font_focus_color);
  561. theme->set_color("font_pressed_color", "OptionButton", accent_color);
  562. theme->set_color("font_disabled_color", "OptionButton", font_disabled_color);
  563. theme->set_color("icon_hover_color", "OptionButton", icon_hover_color);
  564. theme->set_color("icon_focus_color", "OptionButton", icon_focus_color);
  565. theme->set_icon("arrow", "OptionButton", theme->get_icon("GuiOptionArrow", "EditorIcons"));
  566. theme->set_constant("arrow_margin", "OptionButton", widget_default_margin.x - 2 * EDSCALE);
  567. theme->set_constant("modulate_arrow", "OptionButton", true);
  568. theme->set_constant("hseparation", "OptionButton", 4 * EDSCALE);
  569. // CheckButton
  570. theme->set_stylebox("normal", "CheckButton", style_menu);
  571. theme->set_stylebox("pressed", "CheckButton", style_menu);
  572. theme->set_stylebox("disabled", "CheckButton", style_menu);
  573. theme->set_stylebox("hover", "CheckButton", style_menu);
  574. theme->set_icon("on", "CheckButton", theme->get_icon("GuiToggleOn", "EditorIcons"));
  575. theme->set_icon("on_disabled", "CheckButton", theme->get_icon("GuiToggleOnDisabled", "EditorIcons"));
  576. theme->set_icon("off", "CheckButton", theme->get_icon("GuiToggleOff", "EditorIcons"));
  577. theme->set_icon("off_disabled", "CheckButton", theme->get_icon("GuiToggleOffDisabled", "EditorIcons"));
  578. theme->set_icon("on_mirrored", "CheckButton", theme->get_icon("GuiToggleOnMirrored", "EditorIcons"));
  579. theme->set_icon("on_disabled_mirrored", "CheckButton", theme->get_icon("GuiToggleOnDisabledMirrored", "EditorIcons"));
  580. theme->set_icon("off_mirrored", "CheckButton", theme->get_icon("GuiToggleOffMirrored", "EditorIcons"));
  581. theme->set_icon("off_disabled_mirrored", "CheckButton", theme->get_icon("GuiToggleOffDisabledMirrored", "EditorIcons"));
  582. theme->set_color("font_color", "CheckButton", font_color);
  583. theme->set_color("font_hover_color", "CheckButton", font_hover_color);
  584. theme->set_color("font_focus_color", "CheckButton", font_focus_color);
  585. theme->set_color("font_pressed_color", "CheckButton", accent_color);
  586. theme->set_color("font_disabled_color", "CheckButton", font_disabled_color);
  587. theme->set_color("icon_hover_color", "CheckButton", icon_hover_color);
  588. theme->set_color("icon_focus_color", "CheckButton", icon_focus_color);
  589. theme->set_constant("hseparation", "CheckButton", 8 * EDSCALE);
  590. theme->set_constant("check_vadjust", "CheckButton", 0 * EDSCALE);
  591. // Checkbox
  592. Ref<StyleBoxFlat> sb_checkbox = style_menu->duplicate();
  593. sb_checkbox->set_default_margin(SIDE_LEFT, default_margin_size * EDSCALE);
  594. sb_checkbox->set_default_margin(SIDE_RIGHT, default_margin_size * EDSCALE);
  595. sb_checkbox->set_default_margin(SIDE_TOP, default_margin_size * EDSCALE);
  596. sb_checkbox->set_default_margin(SIDE_BOTTOM, default_margin_size * EDSCALE);
  597. theme->set_stylebox("normal", "CheckBox", sb_checkbox);
  598. theme->set_stylebox("pressed", "CheckBox", sb_checkbox);
  599. theme->set_stylebox("disabled", "CheckBox", sb_checkbox);
  600. theme->set_stylebox("hover", "CheckBox", sb_checkbox);
  601. theme->set_icon("checked", "CheckBox", theme->get_icon("GuiChecked", "EditorIcons"));
  602. theme->set_icon("unchecked", "CheckBox", theme->get_icon("GuiUnchecked", "EditorIcons"));
  603. theme->set_icon("radio_checked", "CheckBox", theme->get_icon("GuiRadioChecked", "EditorIcons"));
  604. theme->set_icon("radio_unchecked", "CheckBox", theme->get_icon("GuiRadioUnchecked", "EditorIcons"));
  605. theme->set_icon("checked_disabled", "CheckBox", theme->get_icon("GuiCheckedDisabled", "EditorIcons"));
  606. theme->set_icon("unchecked_disabled", "CheckBox", theme->get_icon("GuiUncheckedDisabled", "EditorIcons"));
  607. theme->set_icon("radio_checked_disabled", "CheckBox", theme->get_icon("GuiRadioCheckedDisabled", "EditorIcons"));
  608. theme->set_icon("radio_unchecked_disabled", "CheckBox", theme->get_icon("GuiRadioUncheckedDisabled", "EditorIcons"));
  609. theme->set_color("font_color", "CheckBox", font_color);
  610. theme->set_color("font_hover_color", "CheckBox", font_hover_color);
  611. theme->set_color("font_focus_color", "CheckBox", font_focus_color);
  612. theme->set_color("font_pressed_color", "CheckBox", accent_color);
  613. theme->set_color("font_disabled_color", "CheckBox", font_disabled_color);
  614. theme->set_color("icon_hover_color", "CheckBox", icon_hover_color);
  615. theme->set_color("icon_focus_color", "CheckBox", icon_focus_color);
  616. theme->set_constant("hseparation", "CheckBox", 8 * EDSCALE);
  617. theme->set_constant("check_vadjust", "CheckBox", 0 * EDSCALE);
  618. // PopupDialog
  619. theme->set_stylebox("panel", "PopupDialog", style_popup);
  620. // PopupMenu
  621. const int popup_menu_margin_size = default_margin_size * 1.5 * EDSCALE;
  622. Ref<StyleBoxFlat> style_popup_menu = style_popup->duplicate();
  623. // Use 1 pixel for the sides, since if 0 is used, the highlight of hovered items is drawn
  624. // on top of the popup border. This causes a 'gap' in the panel border when an item is highlighted,
  625. // and it looks weird. 1px solves this.
  626. style_popup_menu->set_default_margin(SIDE_LEFT, 1 * EDSCALE);
  627. style_popup_menu->set_default_margin(SIDE_TOP, popup_menu_margin_size);
  628. style_popup_menu->set_default_margin(SIDE_RIGHT, 1 * EDSCALE);
  629. style_popup_menu->set_default_margin(SIDE_BOTTOM, popup_menu_margin_size);
  630. // Always display a border for PopupMenus so they can be distinguished from their background.
  631. style_popup_menu->set_border_width_all(1 * EDSCALE);
  632. style_popup_menu->set_border_color(dark_color_2);
  633. theme->set_stylebox("panel", "PopupMenu", style_popup_menu);
  634. Ref<StyleBoxFlat> style_menu_hover = style_widget_hover->duplicate();
  635. // Don't use rounded corners for hover highlights since the StyleBox touches the PopupMenu's edges.
  636. style_menu_hover->set_corner_radius_all(0);
  637. theme->set_stylebox("hover", "PopupMenu", style_menu_hover);
  638. theme->set_stylebox("separator", "PopupMenu", style_popup_separator);
  639. theme->set_stylebox("labeled_separator_left", "PopupMenu", style_popup_labeled_separator_left);
  640. theme->set_stylebox("labeled_separator_right", "PopupMenu", style_popup_labeled_separator_right);
  641. theme->set_color("font_color", "PopupMenu", font_color);
  642. theme->set_color("font_hover_color", "PopupMenu", font_hover_color);
  643. theme->set_color("font_accelerator_color", "PopupMenu", font_disabled_color);
  644. theme->set_color("font_disabled_color", "PopupMenu", font_disabled_color);
  645. theme->set_color("font_separator_color", "PopupMenu", font_disabled_color);
  646. theme->set_icon("checked", "PopupMenu", theme->get_icon("GuiChecked", "EditorIcons"));
  647. theme->set_icon("unchecked", "PopupMenu", theme->get_icon("GuiUnchecked", "EditorIcons"));
  648. theme->set_icon("radio_checked", "PopupMenu", theme->get_icon("GuiRadioChecked", "EditorIcons"));
  649. theme->set_icon("radio_unchecked", "PopupMenu", theme->get_icon("GuiRadioUnchecked", "EditorIcons"));
  650. theme->set_icon("checked_disabled", "PopupMenu", theme->get_icon("GuiCheckedDisabled", "EditorIcons"));
  651. theme->set_icon("unchecked_disabled", "PopupMenu", theme->get_icon("GuiUncheckedDisabled", "EditorIcons"));
  652. theme->set_icon("radio_checked_disabled", "PopupMenu", theme->get_icon("GuiRadioCheckedDisabled", "EditorIcons"));
  653. theme->set_icon("radio_unchecked_disabled", "PopupMenu", theme->get_icon("GuiRadioUncheckedDisabled", "EditorIcons"));
  654. theme->set_icon("submenu", "PopupMenu", theme->get_icon("ArrowRight", "EditorIcons"));
  655. theme->set_icon("submenu_mirrored", "PopupMenu", theme->get_icon("ArrowLeft", "EditorIcons"));
  656. theme->set_icon("visibility_hidden", "PopupMenu", theme->get_icon("GuiVisibilityHidden", "EditorIcons"));
  657. theme->set_icon("visibility_visible", "PopupMenu", theme->get_icon("GuiVisibilityVisible", "EditorIcons"));
  658. theme->set_icon("visibility_xray", "PopupMenu", theme->get_icon("GuiVisibilityXray", "EditorIcons"));
  659. theme->set_constant("vseparation", "PopupMenu", (extra_spacing + default_margin_size + 1) * EDSCALE);
  660. theme->set_constant("item_start_padding", "PopupMenu", popup_menu_margin_size * EDSCALE);
  661. theme->set_constant("item_end_padding", "PopupMenu", popup_menu_margin_size * EDSCALE);
  662. for (int i = 0; i < 16; i++) {
  663. Color si_base_color = accent_color;
  664. float hue_rotate = (i * 2 % 16) / 16.0;
  665. si_base_color.set_hsv(Math::fmod(float(si_base_color.get_h() + hue_rotate), float(1.0)), si_base_color.get_s(), si_base_color.get_v());
  666. si_base_color = accent_color.lerp(si_base_color, float(EDITOR_GET("docks/property_editor/subresource_hue_tint")));
  667. Ref<StyleBoxFlat> sub_inspector_bg;
  668. sub_inspector_bg = make_flat_stylebox(dark_color_1.lerp(si_base_color, 0.08), 2, 0, 2, 2);
  669. sub_inspector_bg->set_border_width(SIDE_LEFT, 2);
  670. sub_inspector_bg->set_border_width(SIDE_RIGHT, 2);
  671. sub_inspector_bg->set_border_width(SIDE_BOTTOM, 2);
  672. sub_inspector_bg->set_border_width(SIDE_TOP, 2);
  673. sub_inspector_bg->set_default_margin(SIDE_LEFT, 3);
  674. sub_inspector_bg->set_default_margin(SIDE_RIGHT, 3);
  675. sub_inspector_bg->set_default_margin(SIDE_BOTTOM, 10);
  676. sub_inspector_bg->set_default_margin(SIDE_TOP, 5);
  677. sub_inspector_bg->set_border_color(si_base_color * Color(0.7, 0.7, 0.7, 0.8));
  678. sub_inspector_bg->set_draw_center(true);
  679. theme->set_stylebox("sub_inspector_bg" + itos(i), "Editor", sub_inspector_bg);
  680. Ref<StyleBoxFlat> bg_color;
  681. bg_color.instantiate();
  682. bg_color->set_bg_color(si_base_color * Color(0.7, 0.7, 0.7, 0.8));
  683. bg_color->set_border_width_all(0);
  684. Ref<StyleBoxFlat> bg_color_selected;
  685. bg_color_selected.instantiate();
  686. bg_color_selected->set_border_width_all(0);
  687. bg_color_selected->set_bg_color(si_base_color * Color(0.8, 0.8, 0.8, 0.8));
  688. theme->set_stylebox("sub_inspector_property_bg" + itos(i), "Editor", bg_color);
  689. theme->set_stylebox("sub_inspector_property_bg_selected" + itos(i), "Editor", bg_color_selected);
  690. }
  691. theme->set_color("sub_inspector_property_color", "Editor", dark_theme ? Color(1, 1, 1, 1) : Color(0, 0, 0, 1));
  692. theme->set_constant("sub_inspector_font_offset", "Editor", 4 * EDSCALE);
  693. Ref<StyleBoxFlat> style_property_bg = style_default->duplicate();
  694. style_property_bg->set_bg_color(highlight_color);
  695. style_property_bg->set_border_width_all(0);
  696. theme->set_constant("font_offset", "EditorProperty", 8 * EDSCALE);
  697. theme->set_stylebox("bg_selected", "EditorProperty", style_property_bg);
  698. theme->set_stylebox("bg", "EditorProperty", Ref<StyleBoxEmpty>(memnew(StyleBoxEmpty)));
  699. theme->set_constant("vseparation", "EditorProperty", (extra_spacing + default_margin_size) * EDSCALE);
  700. theme->set_color("warning_color", "EditorProperty", warning_color);
  701. theme->set_color("property_color", "EditorProperty", property_color);
  702. theme->set_color("readonly_color", "EditorProperty", readonly_color);
  703. theme->set_color("readonly_warning_color", "EditorProperty", readonly_warning_color);
  704. Color inspector_section_color = font_color.lerp(Color(0.5, 0.5, 0.5), 0.35);
  705. theme->set_color("font_color", "EditorInspectorSection", inspector_section_color);
  706. theme->set_constant("inspector_margin", "Editor", 12 * EDSCALE);
  707. // Tree & ItemList background
  708. Ref<StyleBoxFlat> style_tree_bg = style_default->duplicate();
  709. // Make Trees easier to distinguish from other controls by using a darker background color.
  710. style_tree_bg->set_bg_color(dark_color_1.lerp(dark_color_2, 0.5));
  711. style_tree_bg->set_border_color(dark_color_3);
  712. theme->set_stylebox("bg", "Tree", style_tree_bg);
  713. // Tree
  714. theme->set_icon("checked", "Tree", theme->get_icon("GuiChecked", "EditorIcons"));
  715. theme->set_icon("indeterminate", "Tree", theme->get_icon("GuiIndeterminate", "EditorIcons"));
  716. theme->set_icon("unchecked", "Tree", theme->get_icon("GuiUnchecked", "EditorIcons"));
  717. theme->set_icon("arrow", "Tree", theme->get_icon("GuiTreeArrowDown", "EditorIcons"));
  718. theme->set_icon("arrow_collapsed", "Tree", theme->get_icon("GuiTreeArrowRight", "EditorIcons"));
  719. theme->set_icon("arrow_collapsed_mirrored", "Tree", theme->get_icon("GuiTreeArrowLeft", "EditorIcons"));
  720. theme->set_icon("updown", "Tree", theme->get_icon("GuiTreeUpdown", "EditorIcons"));
  721. theme->set_icon("select_arrow", "Tree", theme->get_icon("GuiDropdown", "EditorIcons"));
  722. theme->set_stylebox("bg_focus", "Tree", style_widget_focus);
  723. theme->set_stylebox("custom_button", "Tree", make_empty_stylebox());
  724. theme->set_stylebox("custom_button_pressed", "Tree", make_empty_stylebox());
  725. theme->set_stylebox("custom_button_hover", "Tree", style_widget);
  726. theme->set_color("custom_button_font_highlight", "Tree", font_hover_color);
  727. theme->set_color("font_color", "Tree", font_color);
  728. theme->set_color("font_selected_color", "Tree", mono_color);
  729. theme->set_color("title_button_color", "Tree", font_color);
  730. theme->set_color("drop_position_color", "Tree", accent_color);
  731. theme->set_constant("vseparation", "Tree", widget_default_margin.y - EDSCALE);
  732. theme->set_constant("hseparation", "Tree", 6 * EDSCALE);
  733. theme->set_constant("guide_width", "Tree", border_width);
  734. theme->set_constant("item_margin", "Tree", 3 * default_margin_size * EDSCALE);
  735. theme->set_constant("button_margin", "Tree", default_margin_size * EDSCALE);
  736. theme->set_constant("scroll_border", "Tree", 40 * EDSCALE);
  737. theme->set_constant("scroll_speed", "Tree", 12);
  738. const Color guide_color = mono_color * Color(1, 1, 1, 0.05);
  739. Color relationship_line_color = mono_color * Color(1, 1, 1, relationship_line_opacity);
  740. theme->set_constant("draw_guides", "Tree", relationship_line_opacity < 0.01);
  741. theme->set_color("guide_color", "Tree", guide_color);
  742. int relationship_line_width = 1;
  743. Color parent_line_color = mono_color * Color(1, 1, 1, CLAMP(relationship_line_opacity + 0.45, 0.0, 1.0));
  744. Color children_line_color = mono_color * Color(1, 1, 1, CLAMP(relationship_line_opacity + 0.25, 0.0, 1.0));
  745. theme->set_constant("draw_relationship_lines", "Tree", relationship_line_opacity >= 0.01);
  746. theme->set_constant("relationship_line_width", "Tree", relationship_line_width);
  747. theme->set_constant("parent_hl_line_width", "Tree", relationship_line_width * 2);
  748. theme->set_constant("children_hl_line_width", "Tree", relationship_line_width);
  749. theme->set_constant("parent_hl_line_margin", "Tree", relationship_line_width * 3);
  750. theme->set_color("relationship_line_color", "Tree", relationship_line_color);
  751. theme->set_color("parent_hl_line_color", "Tree", parent_line_color);
  752. theme->set_color("children_hl_line_color", "Tree", children_line_color);
  753. Ref<StyleBoxFlat> style_tree_btn = style_default->duplicate();
  754. style_tree_btn->set_bg_color(highlight_color);
  755. style_tree_btn->set_border_width_all(0);
  756. theme->set_stylebox("button_pressed", "Tree", style_tree_btn);
  757. Ref<StyleBoxFlat> style_tree_hover = style_default->duplicate();
  758. style_tree_hover->set_bg_color(highlight_color * Color(1, 1, 1, 0.4));
  759. style_tree_hover->set_border_width_all(0);
  760. theme->set_stylebox("hover", "Tree", style_tree_hover);
  761. Ref<StyleBoxFlat> style_tree_focus = style_default->duplicate();
  762. style_tree_focus->set_bg_color(highlight_color);
  763. style_tree_focus->set_border_width_all(0);
  764. theme->set_stylebox("selected_focus", "Tree", style_tree_focus);
  765. Ref<StyleBoxFlat> style_tree_selected = style_tree_focus->duplicate();
  766. theme->set_stylebox("selected", "Tree", style_tree_selected);
  767. Ref<StyleBoxFlat> style_tree_cursor = style_default->duplicate();
  768. style_tree_cursor->set_draw_center(false);
  769. style_tree_cursor->set_border_width_all(MAX(1, border_width));
  770. style_tree_cursor->set_border_color(contrast_color_1);
  771. Ref<StyleBoxFlat> style_tree_title = style_default->duplicate();
  772. style_tree_title->set_bg_color(dark_color_3);
  773. style_tree_title->set_border_width_all(0);
  774. theme->set_stylebox("cursor", "Tree", style_tree_cursor);
  775. theme->set_stylebox("cursor_unfocused", "Tree", style_tree_cursor);
  776. theme->set_stylebox("title_button_normal", "Tree", style_tree_title);
  777. theme->set_stylebox("title_button_hover", "Tree", style_tree_title);
  778. theme->set_stylebox("title_button_pressed", "Tree", style_tree_title);
  779. Color prop_category_color = dark_color_1.lerp(mono_color, 0.12);
  780. Color prop_section_color = dark_color_1.lerp(mono_color, 0.09);
  781. Color prop_subsection_color = dark_color_1.lerp(mono_color, 0.06);
  782. theme->set_color("prop_category", "Editor", prop_category_color);
  783. theme->set_color("prop_section", "Editor", prop_section_color);
  784. theme->set_color("prop_subsection", "Editor", prop_subsection_color);
  785. theme->set_color("drop_position_color", "Tree", accent_color);
  786. Ref<StyleBoxFlat> category_bg = style_default->duplicate();
  787. // Make Trees easier to distinguish from other controls by using a darker background color.
  788. category_bg->set_bg_color(prop_category_color);
  789. category_bg->set_border_color(prop_category_color);
  790. theme->set_stylebox("prop_category_style", "Editor", category_bg);
  791. // ItemList
  792. Ref<StyleBoxFlat> style_itemlist_bg = style_default->duplicate();
  793. style_itemlist_bg->set_bg_color(dark_color_1);
  794. style_itemlist_bg->set_border_width_all(border_width);
  795. style_itemlist_bg->set_border_color(dark_color_3);
  796. Ref<StyleBoxFlat> style_itemlist_cursor = style_default->duplicate();
  797. style_itemlist_cursor->set_draw_center(false);
  798. style_itemlist_cursor->set_border_width_all(border_width);
  799. style_itemlist_cursor->set_border_color(highlight_color);
  800. theme->set_stylebox("cursor", "ItemList", style_itemlist_cursor);
  801. theme->set_stylebox("cursor_unfocused", "ItemList", style_itemlist_cursor);
  802. theme->set_stylebox("selected_focus", "ItemList", style_tree_focus);
  803. theme->set_stylebox("selected", "ItemList", style_tree_selected);
  804. theme->set_stylebox("bg_focus", "ItemList", style_widget_focus);
  805. theme->set_stylebox("bg", "ItemList", style_itemlist_bg);
  806. theme->set_color("font_color", "ItemList", font_color);
  807. theme->set_color("font_selected_color", "ItemList", mono_color);
  808. theme->set_color("guide_color", "ItemList", guide_color);
  809. theme->set_constant("vseparation", "ItemList", widget_default_margin.y - EDSCALE);
  810. theme->set_constant("hseparation", "ItemList", 6 * EDSCALE);
  811. theme->set_constant("icon_margin", "ItemList", 6 * EDSCALE);
  812. theme->set_constant("line_separation", "ItemList", 3 * EDSCALE);
  813. // TabBar & TabContainer
  814. theme->set_stylebox("tab_selected", "TabContainer", style_tab_selected);
  815. theme->set_stylebox("tab_unselected", "TabContainer", style_tab_unselected);
  816. theme->set_stylebox("tab_disabled", "TabContainer", style_tab_disabled);
  817. theme->set_stylebox("tab_selected", "TabBar", style_tab_selected);
  818. theme->set_stylebox("tab_unselected", "TabBar", style_tab_unselected);
  819. theme->set_stylebox("tab_disabled", "TabBar", style_tab_disabled);
  820. theme->set_color("font_selected_color", "TabContainer", font_color);
  821. theme->set_color("font_unselected_color", "TabContainer", font_disabled_color);
  822. theme->set_color("font_selected_color", "TabBar", font_color);
  823. theme->set_color("font_unselected_color", "TabBar", font_disabled_color);
  824. theme->set_icon("menu", "TabContainer", theme->get_icon("GuiTabMenu", "EditorIcons"));
  825. theme->set_icon("menu_highlight", "TabContainer", theme->get_icon("GuiTabMenuHl", "EditorIcons"));
  826. theme->set_stylebox("SceneTabFG", "EditorStyles", style_tab_selected);
  827. theme->set_stylebox("SceneTabBG", "EditorStyles", style_tab_unselected);
  828. theme->set_icon("close", "TabBar", theme->get_icon("GuiClose", "EditorIcons"));
  829. theme->set_stylebox("close_bg_pressed", "TabBar", style_menu);
  830. theme->set_stylebox("close_bg_highlight", "TabBar", style_menu);
  831. theme->set_icon("increment", "TabContainer", theme->get_icon("GuiScrollArrowRight", "EditorIcons"));
  832. theme->set_icon("decrement", "TabContainer", theme->get_icon("GuiScrollArrowLeft", "EditorIcons"));
  833. theme->set_icon("increment", "TabBar", theme->get_icon("GuiScrollArrowRight", "EditorIcons"));
  834. theme->set_icon("decrement", "TabBar", theme->get_icon("GuiScrollArrowLeft", "EditorIcons"));
  835. theme->set_icon("increment_highlight", "TabBar", theme->get_icon("GuiScrollArrowRightHl", "EditorIcons"));
  836. theme->set_icon("decrement_highlight", "TabBar", theme->get_icon("GuiScrollArrowLeftHl", "EditorIcons"));
  837. theme->set_icon("increment_highlight", "TabContainer", theme->get_icon("GuiScrollArrowRightHl", "EditorIcons"));
  838. theme->set_icon("decrement_highlight", "TabContainer", theme->get_icon("GuiScrollArrowLeftHl", "EditorIcons"));
  839. theme->set_constant("hseparation", "TabBar", 4 * EDSCALE);
  840. // Content of each tab
  841. Ref<StyleBoxFlat> style_content_panel = style_default->duplicate();
  842. style_content_panel->set_border_color(dark_color_3);
  843. style_content_panel->set_border_width_all(border_width);
  844. // compensate the border
  845. style_content_panel->set_default_margin(SIDE_TOP, (2 + margin_size_extra) * EDSCALE);
  846. style_content_panel->set_default_margin(SIDE_RIGHT, margin_size_extra * EDSCALE);
  847. style_content_panel->set_default_margin(SIDE_BOTTOM, margin_size_extra * EDSCALE);
  848. style_content_panel->set_default_margin(SIDE_LEFT, margin_size_extra * EDSCALE);
  849. // Display border to visually split the body of the container from its possible backgrounds.
  850. style_content_panel->set_border_width(Side::SIDE_TOP, Math::round(2 * EDSCALE));
  851. style_content_panel->set_border_color(dark_color_2);
  852. theme->set_stylebox("panel", "TabContainer", style_content_panel);
  853. // These styleboxes can be used on tabs against the base color background (e.g. nested tabs).
  854. Ref<StyleBoxFlat> style_tab_selected_odd = style_tab_selected->duplicate();
  855. style_tab_selected_odd->set_bg_color(disabled_bg_color);
  856. theme->set_stylebox("tab_selected_odd", "TabContainer", style_tab_selected_odd);
  857. Ref<StyleBoxFlat> style_content_panel_odd = style_content_panel->duplicate();
  858. style_content_panel_odd->set_bg_color(disabled_bg_color);
  859. theme->set_stylebox("panel_odd", "TabContainer", style_content_panel_odd);
  860. // This stylebox is used in 3d and 2d viewports (no borders).
  861. Ref<StyleBoxFlat> style_content_panel_vp = style_content_panel->duplicate();
  862. style_content_panel_vp->set_default_margin(SIDE_LEFT, border_width * 2);
  863. style_content_panel_vp->set_default_margin(SIDE_TOP, default_margin_size * EDSCALE);
  864. style_content_panel_vp->set_default_margin(SIDE_RIGHT, border_width * 2);
  865. style_content_panel_vp->set_default_margin(SIDE_BOTTOM, border_width * 2);
  866. theme->set_stylebox("Content", "EditorStyles", style_content_panel_vp);
  867. // This stylebox is used by preview tabs in the Theme Editor.
  868. Ref<StyleBoxFlat> style_theme_preview_tab = style_tab_selected_odd->duplicate();
  869. style_theme_preview_tab->set_expand_margin_size(SIDE_BOTTOM, 5 * EDSCALE);
  870. theme->set_stylebox("ThemeEditorPreviewFG", "EditorStyles", style_theme_preview_tab);
  871. Ref<StyleBoxFlat> style_theme_preview_bg_tab = style_tab_unselected->duplicate();
  872. style_theme_preview_bg_tab->set_expand_margin_size(SIDE_BOTTOM, 2 * EDSCALE);
  873. theme->set_stylebox("ThemeEditorPreviewBG", "EditorStyles", style_theme_preview_bg_tab);
  874. // Separators
  875. theme->set_stylebox("separator", "HSeparator", make_line_stylebox(separator_color, MAX(Math::round(EDSCALE), border_width)));
  876. theme->set_stylebox("separator", "VSeparator", make_line_stylebox(separator_color, MAX(Math::round(EDSCALE), border_width), 0, 0, true));
  877. // Debugger
  878. Ref<StyleBoxFlat> style_panel_debugger = style_content_panel->duplicate();
  879. style_panel_debugger->set_border_width(SIDE_BOTTOM, 0);
  880. theme->set_stylebox("DebuggerPanel", "EditorStyles", style_panel_debugger);
  881. Ref<StyleBoxFlat> style_panel_invisible_top = style_content_panel->duplicate();
  882. int stylebox_offset = theme->get_font("tab_selected", "TabContainer")->get_height(theme->get_font_size("tab_selected", "TabContainer")) + theme->get_stylebox(SNAME("tab_selected"), SNAME("TabContainer"))->get_minimum_size().height + theme->get_stylebox(SNAME("panel"), SNAME("TabContainer"))->get_default_margin(SIDE_TOP);
  883. style_panel_invisible_top->set_expand_margin_size(SIDE_TOP, -stylebox_offset);
  884. style_panel_invisible_top->set_default_margin(SIDE_TOP, 0);
  885. theme->set_stylebox("BottomPanelDebuggerOverride", "EditorStyles", style_panel_invisible_top);
  886. // LineEdit
  887. Ref<StyleBoxFlat> style_line_edit = style_widget->duplicate();
  888. // The original style_widget style has an extra 1 pixel offset that makes LineEdits not align with Buttons,
  889. // so this compensates for that.
  890. style_line_edit->set_default_margin(SIDE_TOP, style_line_edit->get_default_margin(SIDE_TOP) - 1 * EDSCALE);
  891. // Add a bottom line to make LineEdits more visible, especially in sectioned inspectors
  892. // such as the Project Settings.
  893. style_line_edit->set_border_width(SIDE_BOTTOM, Math::round(2 * EDSCALE));
  894. style_line_edit->set_border_color(dark_color_2);
  895. // Don't round the bottom corner to make the line look sharper.
  896. style_tab_selected->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
  897. style_tab_selected->set_corner_radius(CORNER_BOTTOM_RIGHT, 0);
  898. Ref<StyleBoxFlat> style_line_edit_disabled = style_line_edit->duplicate();
  899. style_line_edit_disabled->set_border_color(disabled_color);
  900. style_line_edit_disabled->set_bg_color(disabled_bg_color);
  901. theme->set_stylebox("normal", "LineEdit", style_line_edit);
  902. theme->set_stylebox("focus", "LineEdit", style_widget_focus);
  903. theme->set_stylebox("read_only", "LineEdit", style_line_edit_disabled);
  904. theme->set_icon("clear", "LineEdit", theme->get_icon("GuiClose", "EditorIcons"));
  905. theme->set_color("read_only", "LineEdit", font_disabled_color);
  906. theme->set_color("font_color", "LineEdit", font_color);
  907. theme->set_color("font_selected_color", "LineEdit", mono_color);
  908. theme->set_color("font_uneditable_color", "LineEdit", font_readonly_color);
  909. theme->set_color("caret_color", "LineEdit", font_color);
  910. theme->set_color("selection_color", "LineEdit", selection_color);
  911. theme->set_color("clear_button_color", "LineEdit", font_color);
  912. theme->set_color("clear_button_color_pressed", "LineEdit", accent_color);
  913. // TextEdit
  914. theme->set_stylebox("normal", "TextEdit", style_line_edit);
  915. theme->set_stylebox("focus", "TextEdit", style_widget_focus);
  916. theme->set_stylebox("read_only", "TextEdit", style_line_edit_disabled);
  917. theme->set_constant("side_margin", "TabContainer", 0);
  918. theme->set_icon("tab", "TextEdit", theme->get_icon("GuiTab", "EditorIcons"));
  919. theme->set_icon("space", "TextEdit", theme->get_icon("GuiSpace", "EditorIcons"));
  920. theme->set_color("font_color", "TextEdit", font_color);
  921. theme->set_color("font_readonly_color", "TextEdit", font_readonly_color);
  922. theme->set_color("caret_color", "TextEdit", font_color);
  923. theme->set_color("selection_color", "TextEdit", selection_color);
  924. theme->set_constant("line_spacing", "TextEdit", 4 * EDSCALE);
  925. // CodeEdit
  926. theme->set_font("font", "CodeEdit", theme->get_font("source", "EditorFonts"));
  927. theme->set_font_size("font_size", "CodeEdit", theme->get_font_size("source_size", "EditorFonts"));
  928. theme->set_stylebox("normal", "CodeEdit", style_widget);
  929. theme->set_stylebox("focus", "CodeEdit", style_widget_hover);
  930. theme->set_stylebox("read_only", "CodeEdit", style_widget_disabled);
  931. theme->set_icon("tab", "CodeEdit", theme->get_icon("GuiTab", "EditorIcons"));
  932. theme->set_icon("space", "CodeEdit", theme->get_icon("GuiSpace", "EditorIcons"));
  933. theme->set_icon("folded", "CodeEdit", theme->get_icon("GuiTreeArrowRight", "EditorIcons"));
  934. theme->set_icon("can_fold", "CodeEdit", theme->get_icon("GuiTreeArrowDown", "EditorIcons"));
  935. theme->set_icon("executing_line", "CodeEdit", theme->get_icon("MainPlay", "EditorIcons"));
  936. theme->set_icon("breakpoint", "CodeEdit", theme->get_icon("Breakpoint", "EditorIcons"));
  937. theme->set_constant("line_spacing", "CodeEdit", EDITOR_DEF("text_editor/appearance/whitespace/line_spacing", 6));
  938. // H/VSplitContainer
  939. theme->set_stylebox("bg", "VSplitContainer", make_stylebox(theme->get_icon("GuiVsplitBg", "EditorIcons"), 1, 1, 1, 1));
  940. theme->set_stylebox("bg", "HSplitContainer", make_stylebox(theme->get_icon("GuiHsplitBg", "EditorIcons"), 1, 1, 1, 1));
  941. theme->set_icon("grabber", "VSplitContainer", theme->get_icon("GuiVsplitter", "EditorIcons"));
  942. theme->set_icon("grabber", "HSplitContainer", theme->get_icon("GuiHsplitter", "EditorIcons"));
  943. theme->set_constant("separation", "HSplitContainer", default_margin_size * 2 * EDSCALE);
  944. theme->set_constant("separation", "VSplitContainer", default_margin_size * 2 * EDSCALE);
  945. // Containers
  946. theme->set_constant("separation", "BoxContainer", default_margin_size * EDSCALE);
  947. theme->set_constant("separation", "HBoxContainer", default_margin_size * EDSCALE);
  948. theme->set_constant("separation", "VBoxContainer", default_margin_size * EDSCALE);
  949. theme->set_constant("margin_left", "MarginContainer", 0);
  950. theme->set_constant("margin_top", "MarginContainer", 0);
  951. theme->set_constant("margin_right", "MarginContainer", 0);
  952. theme->set_constant("margin_bottom", "MarginContainer", 0);
  953. theme->set_constant("hseparation", "GridContainer", default_margin_size * EDSCALE);
  954. theme->set_constant("vseparation", "GridContainer", default_margin_size * EDSCALE);
  955. // Window
  956. // Prevent corner artifacts between window title and body.
  957. Ref<StyleBoxFlat> style_window_title = style_default->duplicate();
  958. style_window_title->set_corner_radius(CORNER_TOP_LEFT, 0);
  959. style_window_title->set_corner_radius(CORNER_TOP_RIGHT, 0);
  960. // Prevent visible line between window title and body.
  961. style_window_title->set_expand_margin_size(SIDE_BOTTOM, 2 * EDSCALE);
  962. Ref<StyleBoxFlat> style_window = style_popup->duplicate();
  963. style_window->set_border_color(base_color);
  964. style_window->set_border_width(SIDE_TOP, 24 * EDSCALE);
  965. style_window->set_expand_margin_size(SIDE_TOP, 24 * EDSCALE);
  966. theme->set_stylebox("embedded_border", "Window", style_window);
  967. theme->set_color("title_color", "Window", font_color);
  968. theme->set_icon("close", "Window", theme->get_icon("GuiClose", "EditorIcons"));
  969. theme->set_icon("close_pressed", "Window", theme->get_icon("GuiClose", "EditorIcons"));
  970. theme->set_constant("close_h_ofs", "Window", 22 * EDSCALE);
  971. theme->set_constant("close_v_ofs", "Window", 20 * EDSCALE);
  972. theme->set_constant("title_height", "Window", 24 * EDSCALE);
  973. theme->set_constant("resize_margin", "Window", 4 * EDSCALE);
  974. theme->set_font("title_font", "Window", theme->get_font("title", "EditorFonts"));
  975. theme->set_font_size("title_font_size", "Window", theme->get_font_size("title_size", "EditorFonts"));
  976. // Complex window (currently only Editor Settings and Project Settings)
  977. Ref<StyleBoxFlat> style_complex_window = style_window->duplicate();
  978. style_complex_window->set_bg_color(dark_color_2);
  979. style_complex_window->set_border_color(dark_color_2);
  980. theme->set_stylebox("panel", "EditorSettingsDialog", style_complex_window);
  981. theme->set_stylebox("panel", "ProjectSettingsEditor", style_complex_window);
  982. theme->set_stylebox("panel", "EditorAbout", style_complex_window);
  983. // AcceptDialog
  984. theme->set_stylebox("panel", "AcceptDialog", style_window_title);
  985. // HScrollBar
  986. Ref<Texture2D> empty_icon = memnew(ImageTexture);
  987. theme->set_stylebox("scroll", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  988. theme->set_stylebox("scroll_focus", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  989. theme->set_stylebox("grabber", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabber", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  990. theme->set_stylebox("grabber_highlight", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberHl", "EditorIcons"), 5, 5, 5, 5, 2, 2, 2, 2));
  991. theme->set_stylebox("grabber_pressed", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberPressed", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  992. theme->set_icon("increment", "HScrollBar", empty_icon);
  993. theme->set_icon("increment_highlight", "HScrollBar", empty_icon);
  994. theme->set_icon("increment_pressed", "HScrollBar", empty_icon);
  995. theme->set_icon("decrement", "HScrollBar", empty_icon);
  996. theme->set_icon("decrement_highlight", "HScrollBar", empty_icon);
  997. theme->set_icon("decrement_pressed", "HScrollBar", empty_icon);
  998. // VScrollBar
  999. theme->set_stylebox("scroll", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  1000. theme->set_stylebox("scroll_focus", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  1001. theme->set_stylebox("grabber", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabber", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  1002. theme->set_stylebox("grabber_highlight", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberHl", "EditorIcons"), 5, 5, 5, 5, 2, 2, 2, 2));
  1003. theme->set_stylebox("grabber_pressed", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberPressed", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  1004. theme->set_icon("increment", "VScrollBar", empty_icon);
  1005. theme->set_icon("increment_highlight", "VScrollBar", empty_icon);
  1006. theme->set_icon("increment_pressed", "VScrollBar", empty_icon);
  1007. theme->set_icon("decrement", "VScrollBar", empty_icon);
  1008. theme->set_icon("decrement_highlight", "VScrollBar", empty_icon);
  1009. theme->set_icon("decrement_pressed", "VScrollBar", empty_icon);
  1010. // HSlider
  1011. theme->set_icon("grabber_highlight", "HSlider", theme->get_icon("GuiSliderGrabberHl", "EditorIcons"));
  1012. theme->set_icon("grabber", "HSlider", theme->get_icon("GuiSliderGrabber", "EditorIcons"));
  1013. theme->set_stylebox("slider", "HSlider", make_flat_stylebox(dark_color_3, 0, default_margin_size / 2, 0, default_margin_size / 2, corner_width));
  1014. theme->set_stylebox("grabber_area", "HSlider", make_flat_stylebox(contrast_color_1, 0, default_margin_size / 2, 0, default_margin_size / 2, corner_width));
  1015. theme->set_stylebox("grabber_area_highlight", "HSlider", make_flat_stylebox(contrast_color_1, 0, default_margin_size / 2, 0, default_margin_size / 2));
  1016. // VSlider
  1017. theme->set_icon("grabber", "VSlider", theme->get_icon("GuiSliderGrabber", "EditorIcons"));
  1018. theme->set_icon("grabber_highlight", "VSlider", theme->get_icon("GuiSliderGrabberHl", "EditorIcons"));
  1019. theme->set_stylebox("slider", "VSlider", make_flat_stylebox(dark_color_3, default_margin_size / 2, 0, default_margin_size / 2, 0, corner_width));
  1020. theme->set_stylebox("grabber_area", "VSlider", make_flat_stylebox(contrast_color_1, default_margin_size / 2, 0, default_margin_size / 2, 0, corner_width));
  1021. theme->set_stylebox("grabber_area_highlight", "VSlider", make_flat_stylebox(contrast_color_1, default_margin_size / 2, 0, default_margin_size / 2, 0));
  1022. // RichTextLabel
  1023. theme->set_color("default_color", "RichTextLabel", font_color);
  1024. theme->set_color("font_shadow_color", "RichTextLabel", Color(0, 0, 0, 0));
  1025. theme->set_constant("shadow_offset_x", "RichTextLabel", 1 * EDSCALE);
  1026. theme->set_constant("shadow_offset_y", "RichTextLabel", 1 * EDSCALE);
  1027. theme->set_constant("shadow_as_outline", "RichTextLabel", 0 * EDSCALE);
  1028. theme->set_stylebox("focus", "RichTextLabel", make_empty_stylebox());
  1029. theme->set_stylebox("normal", "RichTextLabel", style_tree_bg);
  1030. theme->set_color("headline_color", "EditorHelp", mono_color);
  1031. // Panel
  1032. theme->set_stylebox("panel", "Panel", make_flat_stylebox(dark_color_1, 6, 4, 6, 4, corner_width));
  1033. theme->set_stylebox("panel_fg", "Panel", style_default);
  1034. // Label
  1035. theme->set_stylebox("normal", "Label", style_empty);
  1036. theme->set_color("font_color", "Label", font_color);
  1037. theme->set_color("font_shadow_color", "Label", Color(0, 0, 0, 0));
  1038. theme->set_constant("shadow_offset_x", "Label", 1 * EDSCALE);
  1039. theme->set_constant("shadow_offset_y", "Label", 1 * EDSCALE);
  1040. theme->set_constant("shadow_as_outline", "Label", 0 * EDSCALE);
  1041. theme->set_constant("line_spacing", "Label", 3 * EDSCALE);
  1042. // LinkButton
  1043. theme->set_stylebox("focus", "LinkButton", style_empty);
  1044. theme->set_color("font_color", "LinkButton", font_color);
  1045. theme->set_color("font_hover_color", "LinkButton", font_hover_color);
  1046. theme->set_color("font_focus_color", "LinkButton", font_focus_color);
  1047. theme->set_color("font_pressed_color", "LinkButton", accent_color);
  1048. theme->set_color("font_disabled_color", "LinkButton", font_disabled_color);
  1049. // TooltipPanel
  1050. Ref<StyleBoxFlat> style_tooltip = style_popup->duplicate();
  1051. style_tooltip->set_shadow_size(0);
  1052. style_tooltip->set_default_margin(SIDE_LEFT, default_margin_size * EDSCALE * 0.5);
  1053. style_tooltip->set_default_margin(SIDE_TOP, default_margin_size * EDSCALE * 0.5);
  1054. style_tooltip->set_default_margin(SIDE_RIGHT, default_margin_size * EDSCALE * 0.5);
  1055. style_tooltip->set_default_margin(SIDE_BOTTOM, default_margin_size * EDSCALE * 0.5);
  1056. style_tooltip->set_bg_color(dark_color_3 * Color(0.8, 0.8, 0.8, 0.9));
  1057. style_tooltip->set_border_width_all(0);
  1058. theme->set_color("font_color", "TooltipLabel", font_hover_color);
  1059. theme->set_color("font_color_shadow", "TooltipLabel", Color(0, 0, 0, 0));
  1060. theme->set_stylebox("panel", "TooltipPanel", style_tooltip);
  1061. // PopupPanel
  1062. theme->set_stylebox("panel", "PopupPanel", style_popup);
  1063. // SpinBox
  1064. theme->set_icon("updown", "SpinBox", theme->get_icon("GuiSpinboxUpdown", "EditorIcons"));
  1065. theme->set_icon("updown_disabled", "SpinBox", theme->get_icon("GuiSpinboxUpdownDisabled", "EditorIcons"));
  1066. // ProgressBar
  1067. theme->set_stylebox("bg", "ProgressBar", make_stylebox(theme->get_icon("GuiProgressBar", "EditorIcons"), 4, 4, 4, 4, 0, 0, 0, 0));
  1068. theme->set_stylebox("fg", "ProgressBar", make_stylebox(theme->get_icon("GuiProgressFill", "EditorIcons"), 6, 6, 6, 6, 2, 1, 2, 1));
  1069. theme->set_color("font_color", "ProgressBar", font_color);
  1070. // GraphEdit
  1071. theme->set_stylebox("bg", "GraphEdit", style_tree_bg);
  1072. if (dark_theme) {
  1073. theme->set_color("grid_major", "GraphEdit", Color(1.0, 1.0, 1.0, 0.15));
  1074. theme->set_color("grid_minor", "GraphEdit", Color(1.0, 1.0, 1.0, 0.07));
  1075. } else {
  1076. theme->set_color("grid_major", "GraphEdit", Color(0.0, 0.0, 0.0, 0.15));
  1077. theme->set_color("grid_minor", "GraphEdit", Color(0.0, 0.0, 0.0, 0.07));
  1078. }
  1079. theme->set_color("selection_fill", "GraphEdit", theme->get_color("box_selection_fill_color", "Editor"));
  1080. theme->set_color("selection_stroke", "GraphEdit", theme->get_color("box_selection_stroke_color", "Editor"));
  1081. theme->set_color("activity", "GraphEdit", accent_color);
  1082. theme->set_icon("minus", "GraphEdit", theme->get_icon("ZoomLess", "EditorIcons"));
  1083. theme->set_icon("more", "GraphEdit", theme->get_icon("ZoomMore", "EditorIcons"));
  1084. theme->set_icon("reset", "GraphEdit", theme->get_icon("ZoomReset", "EditorIcons"));
  1085. theme->set_icon("snap", "GraphEdit", theme->get_icon("SnapGrid", "EditorIcons"));
  1086. theme->set_icon("minimap", "GraphEdit", theme->get_icon("GridMinimap", "EditorIcons"));
  1087. theme->set_icon("layout", "GraphEdit", theme->get_icon("GridLayout", "EditorIcons"));
  1088. theme->set_constant("bezier_len_pos", "GraphEdit", 80 * EDSCALE);
  1089. theme->set_constant("bezier_len_neg", "GraphEdit", 160 * EDSCALE);
  1090. // GraphEditMinimap
  1091. Ref<StyleBoxFlat> style_minimap_bg = make_flat_stylebox(dark_color_1, 0, 0, 0, 0);
  1092. style_minimap_bg->set_border_color(dark_color_3);
  1093. style_minimap_bg->set_border_width_all(1);
  1094. theme->set_stylebox("bg", "GraphEditMinimap", style_minimap_bg);
  1095. Ref<StyleBoxFlat> style_minimap_camera;
  1096. Ref<StyleBoxFlat> style_minimap_node;
  1097. if (dark_theme) {
  1098. style_minimap_camera = make_flat_stylebox(Color(0.65, 0.65, 0.65, 0.2), 0, 0, 0, 0);
  1099. style_minimap_camera->set_border_color(Color(0.65, 0.65, 0.65, 0.45));
  1100. style_minimap_node = make_flat_stylebox(Color(1, 1, 1), 0, 0, 0, 0);
  1101. } else {
  1102. style_minimap_camera = make_flat_stylebox(Color(0.38, 0.38, 0.38, 0.2), 0, 0, 0, 0);
  1103. style_minimap_camera->set_border_color(Color(0.38, 0.38, 0.38, 0.45));
  1104. style_minimap_node = make_flat_stylebox(Color(0, 0, 0), 0, 0, 0, 0);
  1105. }
  1106. style_minimap_camera->set_border_width_all(1);
  1107. style_minimap_node->set_corner_radius_all(1);
  1108. theme->set_stylebox("camera", "GraphEditMinimap", style_minimap_camera);
  1109. theme->set_stylebox("node", "GraphEditMinimap", style_minimap_node);
  1110. Ref<Texture2D> minimap_resizer_icon = theme->get_icon("GuiResizer", "EditorIcons");
  1111. Color minimap_resizer_color;
  1112. if (dark_theme) {
  1113. minimap_resizer_color = Color(1, 1, 1, 0.65);
  1114. } else {
  1115. minimap_resizer_color = Color(0, 0, 0, 0.65);
  1116. }
  1117. theme->set_icon("resizer", "GraphEditMinimap", flip_icon(minimap_resizer_icon, true, true));
  1118. theme->set_color("resizer_color", "GraphEditMinimap", minimap_resizer_color);
  1119. // GraphNode
  1120. const int gn_margin_side = 28;
  1121. Ref<StyleBoxFlat> graphsb = make_flat_stylebox(dark_color_3 * Color(1, 1, 1, 0.7), gn_margin_side, 24, gn_margin_side, 5, corner_width);
  1122. graphsb->set_border_width_all(border_width);
  1123. graphsb->set_border_color(dark_color_3);
  1124. Ref<StyleBoxFlat> graphsbselected = make_flat_stylebox(dark_color_3 * Color(1, 1, 1, 0.9), gn_margin_side, 24, gn_margin_side, 5, corner_width);
  1125. graphsbselected->set_border_width_all(2 * EDSCALE + border_width);
  1126. graphsbselected->set_border_color(Color(accent_color.r, accent_color.g, accent_color.b, 0.9));
  1127. Ref<StyleBoxFlat> graphsbcomment = make_flat_stylebox(dark_color_3 * Color(1, 1, 1, 0.3), gn_margin_side, 24, gn_margin_side, 5, corner_width);
  1128. graphsbcomment->set_border_width_all(border_width);
  1129. graphsbcomment->set_border_color(dark_color_3);
  1130. Ref<StyleBoxFlat> graphsbcommentselected = make_flat_stylebox(dark_color_3 * Color(1, 1, 1, 0.4), gn_margin_side, 24, gn_margin_side, 5, corner_width);
  1131. graphsbcommentselected->set_border_width_all(border_width);
  1132. graphsbcommentselected->set_border_color(dark_color_3);
  1133. Ref<StyleBoxFlat> graphsbbreakpoint = graphsbselected->duplicate();
  1134. graphsbbreakpoint->set_draw_center(false);
  1135. graphsbbreakpoint->set_border_color(warning_color);
  1136. graphsbbreakpoint->set_shadow_color(warning_color * Color(1.0, 1.0, 1.0, 0.1));
  1137. Ref<StyleBoxFlat> graphsbposition = graphsbselected->duplicate();
  1138. graphsbposition->set_draw_center(false);
  1139. graphsbposition->set_border_color(error_color);
  1140. graphsbposition->set_shadow_color(error_color * Color(1.0, 1.0, 1.0, 0.2));
  1141. Ref<StyleBoxFlat> smgraphsb = make_flat_stylebox(dark_color_3 * Color(1, 1, 1, 0.7), gn_margin_side, 24, gn_margin_side, 5, corner_width);
  1142. smgraphsb->set_border_width_all(border_width);
  1143. smgraphsb->set_border_color(dark_color_3);
  1144. Ref<StyleBoxFlat> smgraphsbselected = make_flat_stylebox(dark_color_3 * Color(1, 1, 1, 0.9), gn_margin_side, 24, gn_margin_side, 5, corner_width);
  1145. smgraphsbselected->set_border_width_all(2 * EDSCALE + border_width);
  1146. smgraphsbselected->set_border_color(Color(accent_color.r, accent_color.g, accent_color.b, 0.9));
  1147. smgraphsbselected->set_shadow_size(8 * EDSCALE);
  1148. smgraphsbselected->set_shadow_color(shadow_color);
  1149. graphsb->set_border_width(SIDE_TOP, 24 * EDSCALE);
  1150. graphsbselected->set_border_width(SIDE_TOP, 24 * EDSCALE);
  1151. graphsbcomment->set_border_width(SIDE_TOP, 24 * EDSCALE);
  1152. graphsbcommentselected->set_border_width(SIDE_TOP, 24 * EDSCALE);
  1153. theme->set_stylebox("frame", "GraphNode", graphsb);
  1154. theme->set_stylebox("selectedframe", "GraphNode", graphsbselected);
  1155. theme->set_stylebox("comment", "GraphNode", graphsbcomment);
  1156. theme->set_stylebox("commentfocus", "GraphNode", graphsbcommentselected);
  1157. theme->set_stylebox("breakpoint", "GraphNode", graphsbbreakpoint);
  1158. theme->set_stylebox("position", "GraphNode", graphsbposition);
  1159. theme->set_stylebox("state_machine_frame", "GraphNode", smgraphsb);
  1160. theme->set_stylebox("state_machine_selectedframe", "GraphNode", smgraphsbselected);
  1161. Color default_node_color = dark_color_1.inverted();
  1162. theme->set_color("title_color", "GraphNode", default_node_color);
  1163. default_node_color.a = 0.7;
  1164. theme->set_color("close_color", "GraphNode", default_node_color);
  1165. theme->set_color("resizer_color", "GraphNode", default_node_color);
  1166. theme->set_constant("port_offset", "GraphNode", 14 * EDSCALE);
  1167. theme->set_constant("title_h_offset", "GraphNode", -16 * EDSCALE);
  1168. theme->set_constant("title_offset", "GraphNode", 20 * EDSCALE);
  1169. theme->set_constant("close_h_offset", "GraphNode", 20 * EDSCALE);
  1170. theme->set_constant("close_offset", "GraphNode", 20 * EDSCALE);
  1171. theme->set_constant("separation", "GraphNode", 1 * EDSCALE);
  1172. theme->set_icon("close", "GraphNode", theme->get_icon("GuiCloseCustomizable", "EditorIcons"));
  1173. theme->set_icon("resizer", "GraphNode", theme->get_icon("GuiResizer", "EditorIcons"));
  1174. theme->set_icon("port", "GraphNode", theme->get_icon("GuiGraphNodePort", "EditorIcons"));
  1175. // GridContainer
  1176. theme->set_constant("vseparation", "GridContainer", Math::round(widget_default_margin.y - 2 * EDSCALE));
  1177. // FileDialog
  1178. theme->set_icon("folder", "FileDialog", theme->get_icon("Folder", "EditorIcons"));
  1179. theme->set_icon("parent_folder", "FileDialog", theme->get_icon("ArrowUp", "EditorIcons"));
  1180. theme->set_icon("back_folder", "FileDialog", theme->get_icon("Back", "EditorIcons"));
  1181. theme->set_icon("forward_folder", "FileDialog", theme->get_icon("Forward", "EditorIcons"));
  1182. theme->set_icon("reload", "FileDialog", theme->get_icon("Reload", "EditorIcons"));
  1183. theme->set_icon("toggle_hidden", "FileDialog", theme->get_icon("GuiVisibilityVisible", "EditorIcons"));
  1184. // Use a different color for folder icons to make them easier to distinguish from files.
  1185. // On a light theme, the icon will be dark, so we need to lighten it before blending it with the accent color.
  1186. theme->set_color("folder_icon_modulate", "FileDialog", (dark_theme ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25)).lerp(accent_color, 0.7));
  1187. theme->set_color("files_disabled", "FileDialog", font_disabled_color);
  1188. // ColorPicker
  1189. theme->set_constant("margin", "ColorPicker", popup_margin_size);
  1190. theme->set_constant("sv_width", "ColorPicker", 256 * EDSCALE);
  1191. theme->set_constant("sv_height", "ColorPicker", 256 * EDSCALE);
  1192. theme->set_constant("h_width", "ColorPicker", 30 * EDSCALE);
  1193. theme->set_constant("label_width", "ColorPicker", 10 * EDSCALE);
  1194. theme->set_icon("screen_picker", "ColorPicker", theme->get_icon("ColorPick", "EditorIcons"));
  1195. theme->set_icon("add_preset", "ColorPicker", theme->get_icon("Add", "EditorIcons"));
  1196. theme->set_icon("sample_bg", "ColorPicker", theme->get_icon("GuiMiniCheckerboard", "EditorIcons"));
  1197. theme->set_icon("overbright_indicator", "ColorPicker", theme->get_icon("OverbrightIndicator", "EditorIcons"));
  1198. theme->set_icon("bar_arrow", "ColorPicker", theme->get_icon("ColorPickerBarArrow", "EditorIcons"));
  1199. theme->set_icon("picker_cursor", "ColorPicker", theme->get_icon("PickerCursor", "EditorIcons"));
  1200. // ColorPickerButton
  1201. theme->set_icon("bg", "ColorPickerButton", theme->get_icon("GuiMiniCheckerboard", "EditorIcons"));
  1202. // ColorPresetButton
  1203. Ref<StyleBoxFlat> preset_sb = make_flat_stylebox(Color(1, 1, 1), 2, 2, 2, 2, 2);
  1204. preset_sb->set_anti_aliased(false);
  1205. theme->set_stylebox("preset_fg", "ColorPresetButton", preset_sb);
  1206. theme->set_icon("preset_bg", "ColorPresetButton", theme->get_icon("GuiMiniCheckerboard", "EditorIcons"));
  1207. theme->set_icon("overbright_indicator", "ColorPresetButton", theme->get_icon("OverbrightIndicator", "EditorIcons"));
  1208. // Information on 3D viewport
  1209. Ref<StyleBoxFlat> style_info_3d_viewport = style_default->duplicate();
  1210. style_info_3d_viewport->set_bg_color(style_info_3d_viewport->get_bg_color() * Color(1, 1, 1, 0.5));
  1211. style_info_3d_viewport->set_border_width_all(0);
  1212. theme->set_stylebox("Information3dViewport", "EditorStyles", style_info_3d_viewport);
  1213. // Theme editor.
  1214. theme->set_color("preview_picker_overlay_color", "ThemeEditor", Color(0.1, 0.1, 0.1, 0.25));
  1215. Color theme_preview_picker_bg_color = accent_color;
  1216. theme_preview_picker_bg_color.a = 0.2;
  1217. Ref<StyleBoxFlat> theme_preview_picker_sb = make_flat_stylebox(theme_preview_picker_bg_color, 0, 0, 0, 0);
  1218. theme_preview_picker_sb->set_border_color(accent_color);
  1219. theme_preview_picker_sb->set_border_width_all(1.0 * EDSCALE);
  1220. theme->set_stylebox("preview_picker_overlay", "ThemeEditor", theme_preview_picker_sb);
  1221. Color theme_preview_picker_label_bg_color = accent_color;
  1222. theme_preview_picker_label_bg_color.set_v(0.5);
  1223. Ref<StyleBoxFlat> theme_preview_picker_label_sb = make_flat_stylebox(theme_preview_picker_label_bg_color, 4.0, 1.0, 4.0, 3.0);
  1224. theme->set_stylebox("preview_picker_label", "ThemeEditor", theme_preview_picker_label_sb);
  1225. // adaptive script theme constants
  1226. // for comments and elements with lower relevance
  1227. const Color dim_color = Color(font_color.r, font_color.g, font_color.b, 0.5);
  1228. const float mono_value = mono_color.r;
  1229. const Color alpha1 = Color(mono_value, mono_value, mono_value, 0.07);
  1230. const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.14);
  1231. const Color alpha3 = Color(mono_value, mono_value, mono_value, 0.7);
  1232. // editor main color
  1233. const Color main_color = dark_theme ? Color(0.34, 0.7, 1.0) : Color(0.02, 0.5, 1.0);
  1234. const Color symbol_color = Color(0.34, 0.57, 1.0).lerp(mono_color, dark_theme ? 0.5 : 0.3);
  1235. const Color keyword_color = Color(1.0, 0.44, 0.52);
  1236. const Color control_flow_keyword_color = dark_theme ? Color(1.0, 0.55, 0.8) : Color(0.8, 0.4, 0.6);
  1237. const Color basetype_color = dark_theme ? Color(0.26, 1.0, 0.76) : Color(0.0, 0.76, 0.38);
  1238. const Color type_color = basetype_color.lerp(mono_color, dark_theme ? 0.4 : 0.3);
  1239. const Color usertype_color = basetype_color.lerp(mono_color, dark_theme ? 0.7 : 0.5);
  1240. const Color comment_color = dim_color;
  1241. const Color string_color = (dark_theme ? Color(1.0, 0.85, 0.26) : Color(1.0, 0.82, 0.09)).lerp(mono_color, dark_theme ? 0.5 : 0.3);
  1242. // Use the brightest background color on a light theme (which generally uses a negative contrast rate).
  1243. const Color te_background_color = dark_theme ? background_color : dark_color_3;
  1244. const Color completion_background_color = dark_theme ? base_color : background_color;
  1245. const Color completion_selected_color = alpha1;
  1246. const Color completion_existing_color = alpha2;
  1247. const Color completion_scroll_color = alpha1;
  1248. const Color completion_font_color = font_color;
  1249. const Color text_color = font_color;
  1250. const Color line_number_color = dim_color;
  1251. const Color safe_line_number_color = dim_color * Color(1, 1.2, 1, 1.5);
  1252. const Color caret_color = mono_color;
  1253. const Color caret_background_color = mono_color.inverted();
  1254. const Color text_selected_color = dark_color_3;
  1255. const Color brace_mismatch_color = error_color;
  1256. const Color current_line_color = alpha1;
  1257. const Color line_length_guideline_color = dark_theme ? base_color : background_color;
  1258. const Color word_highlighted_color = alpha1;
  1259. const Color number_color = basetype_color.lerp(mono_color, dark_theme ? 0.5 : 0.3);
  1260. const Color function_color = main_color;
  1261. const Color member_variable_color = main_color.lerp(mono_color, 0.6);
  1262. const Color mark_color = Color(error_color.r, error_color.g, error_color.b, 0.3);
  1263. const Color bookmark_color = Color(0.08, 0.49, 0.98);
  1264. const Color breakpoint_color = error_color;
  1265. const Color executing_line_color = Color(0.98, 0.89, 0.27);
  1266. const Color code_folding_color = alpha3;
  1267. const Color search_result_color = alpha1;
  1268. const Color search_result_border_color = Color(0.41, 0.61, 0.91, 0.38);
  1269. EditorSettings *setting = EditorSettings::get_singleton();
  1270. String text_editor_color_theme = setting->get("text_editor/theme/color_theme");
  1271. if (text_editor_color_theme == "Default") {
  1272. setting->set_initial_value("text_editor/theme/highlighting/symbol_color", symbol_color, true);
  1273. setting->set_initial_value("text_editor/theme/highlighting/keyword_color", keyword_color, true);
  1274. setting->set_initial_value("text_editor/theme/highlighting/control_flow_keyword_color", control_flow_keyword_color, true);
  1275. setting->set_initial_value("text_editor/theme/highlighting/base_type_color", basetype_color, true);
  1276. setting->set_initial_value("text_editor/theme/highlighting/engine_type_color", type_color, true);
  1277. setting->set_initial_value("text_editor/theme/highlighting/user_type_color", usertype_color, true);
  1278. setting->set_initial_value("text_editor/theme/highlighting/comment_color", comment_color, true);
  1279. setting->set_initial_value("text_editor/theme/highlighting/string_color", string_color, true);
  1280. setting->set_initial_value("text_editor/theme/highlighting/background_color", te_background_color, true);
  1281. setting->set_initial_value("text_editor/theme/highlighting/completion_background_color", completion_background_color, true);
  1282. setting->set_initial_value("text_editor/theme/highlighting/completion_selected_color", completion_selected_color, true);
  1283. setting->set_initial_value("text_editor/theme/highlighting/completion_existing_color", completion_existing_color, true);
  1284. setting->set_initial_value("text_editor/theme/highlighting/completion_scroll_color", completion_scroll_color, true);
  1285. setting->set_initial_value("text_editor/theme/highlighting/completion_font_color", completion_font_color, true);
  1286. setting->set_initial_value("text_editor/theme/highlighting/text_color", text_color, true);
  1287. setting->set_initial_value("text_editor/theme/highlighting/line_number_color", line_number_color, true);
  1288. setting->set_initial_value("text_editor/theme/highlighting/safe_line_number_color", safe_line_number_color, true);
  1289. setting->set_initial_value("text_editor/theme/highlighting/caret_color", caret_color, true);
  1290. setting->set_initial_value("text_editor/theme/highlighting/caret_background_color", caret_background_color, true);
  1291. setting->set_initial_value("text_editor/theme/highlighting/text_selected_color", text_selected_color, true);
  1292. setting->set_initial_value("text_editor/theme/highlighting/selection_color", selection_color, true);
  1293. setting->set_initial_value("text_editor/theme/highlighting/brace_mismatch_color", brace_mismatch_color, true);
  1294. setting->set_initial_value("text_editor/theme/highlighting/current_line_color", current_line_color, true);
  1295. setting->set_initial_value("text_editor/theme/highlighting/line_length_guideline_color", line_length_guideline_color, true);
  1296. setting->set_initial_value("text_editor/theme/highlighting/word_highlighted_color", word_highlighted_color, true);
  1297. setting->set_initial_value("text_editor/theme/highlighting/number_color", number_color, true);
  1298. setting->set_initial_value("text_editor/theme/highlighting/function_color", function_color, true);
  1299. setting->set_initial_value("text_editor/theme/highlighting/member_variable_color", member_variable_color, true);
  1300. setting->set_initial_value("text_editor/theme/highlighting/mark_color", mark_color, true);
  1301. setting->set_initial_value("text_editor/theme/highlighting/bookmark_color", bookmark_color, true);
  1302. setting->set_initial_value("text_editor/theme/highlighting/breakpoint_color", breakpoint_color, true);
  1303. setting->set_initial_value("text_editor/theme/highlighting/executing_line_color", executing_line_color, true);
  1304. setting->set_initial_value("text_editor/theme/highlighting/code_folding_color", code_folding_color, true);
  1305. setting->set_initial_value("text_editor/theme/highlighting/search_result_color", search_result_color, true);
  1306. setting->set_initial_value("text_editor/theme/highlighting/search_result_border_color", search_result_border_color, true);
  1307. } else if (text_editor_color_theme == "Godot 2") {
  1308. setting->load_text_editor_theme();
  1309. }
  1310. // Now theme is loaded, apply it to CodeEdit.
  1311. theme->set_color("background_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/background_color"));
  1312. theme->set_color("completion_background_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_background_color"));
  1313. theme->set_color("completion_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_selected_color"));
  1314. theme->set_color("completion_existing_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_existing_color"));
  1315. theme->set_color("completion_scroll_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_scroll_color"));
  1316. theme->set_color("completion_font_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_font_color"));
  1317. theme->set_color("font_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_color"));
  1318. theme->set_color("line_number_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_number_color"));
  1319. theme->set_color("caret_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/caret_color"));
  1320. theme->set_color("font_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_selected_color"));
  1321. theme->set_color("selection_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/selection_color"));
  1322. theme->set_color("brace_mismatch_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/brace_mismatch_color"));
  1323. theme->set_color("current_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/current_line_color"));
  1324. theme->set_color("line_length_guideline_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_length_guideline_color"));
  1325. theme->set_color("word_highlighted_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/word_highlighted_color"));
  1326. theme->set_color("bookmark_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/bookmark_color"));
  1327. theme->set_color("breakpoint_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/breakpoint_color"));
  1328. theme->set_color("executing_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/executing_line_color"));
  1329. theme->set_color("code_folding_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/code_folding_color"));
  1330. theme->set_color("search_result_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_color"));
  1331. theme->set_color("search_result_border_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_border_color"));
  1332. return theme;
  1333. }
  1334. Ref<Theme> create_custom_theme(const Ref<Theme> p_theme) {
  1335. Ref<Theme> theme = create_editor_theme(p_theme);
  1336. const String custom_theme_path = EditorSettings::get_singleton()->get("interface/theme/custom_theme");
  1337. if (custom_theme_path != "") {
  1338. Ref<Theme> custom_theme = ResourceLoader::load(custom_theme_path);
  1339. if (custom_theme.is_valid()) {
  1340. theme->merge_with(custom_theme);
  1341. }
  1342. }
  1343. return theme;
  1344. }
  1345. Ref<ImageTexture> create_unscaled_default_project_icon() {
  1346. #ifdef MODULE_SVG_ENABLED
  1347. for (int i = 0; i < editor_icons_count; i++) {
  1348. // ESCALE should never affect size of the icon
  1349. if (strcmp(editor_icons_names[i], "DefaultProjectIcon") == 0) {
  1350. return editor_generate_icon(i, false, 1.0);
  1351. }
  1352. }
  1353. #endif
  1354. return Ref<ImageTexture>(memnew(ImageTexture));
  1355. }