editor_themes.cpp 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  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. #ifdef SVG_ENABLED
  37. #include "modules/svg/image_loader_svg.h"
  38. #endif
  39. static Ref<StyleBoxTexture> make_stylebox(Ref<Texture> 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) {
  40. Ref<StyleBoxTexture> style(memnew(StyleBoxTexture));
  41. style->set_texture(p_texture);
  42. style->set_margin_size(MARGIN_LEFT, p_left * EDSCALE);
  43. style->set_margin_size(MARGIN_RIGHT, p_right * EDSCALE);
  44. style->set_margin_size(MARGIN_BOTTOM, p_bottom * EDSCALE);
  45. style->set_margin_size(MARGIN_TOP, p_top * EDSCALE);
  46. style->set_default_margin(MARGIN_LEFT, p_margin_left * EDSCALE);
  47. style->set_default_margin(MARGIN_RIGHT, p_margin_right * EDSCALE);
  48. style->set_default_margin(MARGIN_BOTTOM, p_margin_bottom * EDSCALE);
  49. style->set_default_margin(MARGIN_TOP, p_margin_top * EDSCALE);
  50. style->set_draw_center(p_draw_center);
  51. return style;
  52. }
  53. 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) {
  54. Ref<StyleBoxEmpty> style(memnew(StyleBoxEmpty));
  55. style->set_default_margin(MARGIN_LEFT, p_margin_left * EDSCALE);
  56. style->set_default_margin(MARGIN_RIGHT, p_margin_right * EDSCALE);
  57. style->set_default_margin(MARGIN_BOTTOM, p_margin_bottom * EDSCALE);
  58. style->set_default_margin(MARGIN_TOP, p_margin_top * EDSCALE);
  59. return style;
  60. }
  61. 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) {
  62. Ref<StyleBoxFlat> style(memnew(StyleBoxFlat));
  63. style->set_bg_color(p_color);
  64. style->set_default_margin(MARGIN_LEFT, p_margin_left * EDSCALE);
  65. style->set_default_margin(MARGIN_RIGHT, p_margin_right * EDSCALE);
  66. style->set_default_margin(MARGIN_BOTTOM, p_margin_bottom * EDSCALE);
  67. style->set_default_margin(MARGIN_TOP, p_margin_top * EDSCALE);
  68. return style;
  69. }
  70. 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) {
  71. Ref<StyleBoxLine> style(memnew(StyleBoxLine));
  72. style->set_color(p_color);
  73. style->set_grow_begin(p_grow_begin);
  74. style->set_grow_end(p_grow_end);
  75. style->set_thickness(p_thickness);
  76. style->set_vertical(p_vertical);
  77. return style;
  78. }
  79. static Ref<Texture> flip_icon(Ref<Texture> p_texture, bool p_flip_y = false, bool p_flip_x = false) {
  80. if (!p_flip_y && !p_flip_x) {
  81. return p_texture;
  82. }
  83. Ref<ImageTexture> texture(memnew(ImageTexture));
  84. Ref<Image> img = p_texture->get_data();
  85. img = img->duplicate();
  86. if (p_flip_y) {
  87. img->flip_y();
  88. }
  89. if (p_flip_x) {
  90. img->flip_x();
  91. }
  92. texture->create_from_image(img);
  93. return texture;
  94. }
  95. #ifdef SVG_ENABLED
  96. static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, float p_scale = EDSCALE, bool p_force_filter = false) {
  97. Ref<ImageTexture> icon = memnew(ImageTexture);
  98. Ref<Image> img = memnew(Image);
  99. // dumb gizmo check
  100. bool is_gizmo = String(editor_icons_names[p_index]).begins_with("Gizmo");
  101. // Upsample icon generation only if the editor scale isn't an integer multiplier.
  102. // Generating upsampled icons is slower, and the benefit is hardly visible
  103. // with integer editor scales.
  104. const bool upsample = !Math::is_equal_approx(Math::round(p_scale), p_scale);
  105. ImageLoaderSVG::create_image_from_string(img, editor_icons_sources[p_index], p_scale, upsample, p_convert_color);
  106. if ((p_scale - (float)((int)p_scale)) > 0.0 || is_gizmo || p_force_filter)
  107. icon->create_from_image(img); // in this case filter really helps
  108. else
  109. icon->create_from_image(img, 0);
  110. return icon;
  111. }
  112. #endif
  113. #ifndef ADD_CONVERT_COLOR
  114. #define ADD_CONVERT_COLOR(dictionary, old_color, new_color) dictionary[Color::html(old_color)] = Color::html(new_color)
  115. #endif
  116. 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) {
  117. #ifdef SVG_ENABLED
  118. // The default icon theme is designed to be used for a dark theme.
  119. // This dictionary stores color codes to convert to other colors
  120. // for better readability on a light theme.
  121. Dictionary dark_icon_color_dictionary;
  122. // The names of the icons to never convert, even if one of their colors
  123. // are contained in the dictionary above.
  124. Set<StringName> exceptions;
  125. if (!p_dark_theme) {
  126. // convert color: FROM TO
  127. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#e0e0e0", "#5a5a5a"); // common icon color
  128. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffffff", "#414141"); // white
  129. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#b4b4b4", "#363636"); // script darker color
  130. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#f9f9f9", "#606060"); // scrollbar grabber highlight color
  131. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#cea4f1", "#a85de9"); // animation
  132. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#fc9c9c", "#cd3838"); // spatial
  133. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#a5b7f3", "#3d64dd"); // 2d
  134. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#708cea", "#1a3eac"); // 2d dark
  135. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#a5efac", "#2fa139"); // control
  136. // rainbow
  137. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff7070", "#ff2929"); // red
  138. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffeb70", "#ffe337"); // yellow
  139. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#9dff70", "#74ff34"); // green
  140. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#70ffb9", "#2cff98"); // aqua
  141. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#70deff", "#22ccff"); // blue
  142. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#9f70ff", "#702aff"); // purple
  143. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff70ac", "#ff2781"); // pink
  144. // audio gradient
  145. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff8484", "#ff4040"); // red
  146. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#e1dc7a", "#d6cf4b"); // yellow
  147. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#84ffb1", "#00f010"); // green
  148. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffd684", "#fea900"); // mesh (orange)
  149. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#40a2ff", "#68b6ff"); // shape (blue)
  150. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff8484", "#ff3333"); // remove (red)
  151. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#84ffb1", "#00db50"); // add (green)
  152. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#84c2ff", "#5caeff"); // selection (blue)
  153. // Animation editor tracks
  154. // The property track icon color is set by the common icon color
  155. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ea9568", "#bd5e2c"); // 3D Transform track
  156. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#66f376", "#16a827"); // Call Method track
  157. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#5792f6", "#236be6"); // Bezier Curve track
  158. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#eae668", "#9f9722"); // Audio Playback track
  159. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#b76ef0", "#9853ce"); // Animation Playback track
  160. // TileSet editor icons
  161. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#fce844", "#aa8d24"); // New Single Tile
  162. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#4490fc", "#0350bd"); // New Autotile
  163. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#c9cfd4", "#828f9b"); // New Atlas
  164. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#69ecbd", "#25e3a0"); // VS variant
  165. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#8da6f0", "#6d8eeb"); // VS bool
  166. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#7dc6ef", "#4fb2e9"); // VS int
  167. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#61daf4", "#27ccf0"); // VS float
  168. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#6ba7ec", "#4690e7"); // VS string
  169. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#bd91f1", "#ad76ee"); // VS vector2
  170. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#f191a5", "#ee758e"); // VS rect
  171. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#e286f0", "#dc6aed"); // VS vector3
  172. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#c4ec69", "#96ce1a"); // VS transform2D
  173. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#f77070", "#f77070"); // VS plane
  174. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ec69a3", "#ec69a3"); // VS quat
  175. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ee7991", "#ee7991"); // VS aabb
  176. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#e3ec69", "#b2bb19"); // VS basis
  177. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#f6a86e", "#f49047"); // VS transform
  178. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#6993ec", "#6993ec"); // VS path
  179. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#69ec9a", "#2ce573"); // VS rid
  180. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#79f3e8", "#12d5c3"); // VS object
  181. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#77edb1", "#57e99f"); // VS dict
  182. exceptions.insert("EditorPivot");
  183. exceptions.insert("EditorHandle");
  184. exceptions.insert("Editor3DHandle");
  185. exceptions.insert("Godot");
  186. exceptions.insert("PanoramaSky");
  187. exceptions.insert("ProceduralSky");
  188. exceptions.insert("EditorControlAnchor");
  189. exceptions.insert("DefaultProjectIcon");
  190. exceptions.insert("GuiCloseCustomizable");
  191. exceptions.insert("GuiGraphNodePort");
  192. exceptions.insert("GuiResizer");
  193. exceptions.insert("ZoomMore");
  194. exceptions.insert("ZoomLess");
  195. exceptions.insert("ZoomReset");
  196. exceptions.insert("LockViewport");
  197. exceptions.insert("GroupViewport");
  198. exceptions.insert("StatusError");
  199. exceptions.insert("StatusSuccess");
  200. exceptions.insert("StatusWarning");
  201. exceptions.insert("NodeWarning");
  202. exceptions.insert("OverbrightIndicator");
  203. }
  204. // These ones should be converted even if we are using a dark theme.
  205. const Color error_color = p_theme->get_color("error_color", "Editor");
  206. const Color success_color = p_theme->get_color("success_color", "Editor");
  207. const Color warning_color = p_theme->get_color("warning_color", "Editor");
  208. dark_icon_color_dictionary[Color::html("#ff0000")] = error_color;
  209. dark_icon_color_dictionary[Color::html("#45ff8b")] = success_color;
  210. dark_icon_color_dictionary[Color::html("#dbab09")] = warning_color;
  211. ImageLoaderSVG::set_convert_colors(&dark_icon_color_dictionary);
  212. // Generate icons.
  213. if (!p_only_thumbs) {
  214. for (int i = 0; i < editor_icons_count; i++) {
  215. const int is_exception = exceptions.has(editor_icons_names[i]);
  216. const Ref<ImageTexture> icon = editor_generate_icon(i, !is_exception);
  217. p_theme->set_icon(editor_icons_names[i], "EditorIcons", icon);
  218. }
  219. }
  220. // Generate thumbnail icons with the given thumbnail size.
  221. // We don't need filtering when generating at one of the default resolutions.
  222. const bool force_filter = p_thumb_size != 64 && p_thumb_size != 32;
  223. if (p_thumb_size >= 64) {
  224. const float scale = (float)p_thumb_size / 64.0 * EDSCALE;
  225. for (int i = 0; i < editor_bg_thumbs_count; i++) {
  226. const int index = editor_bg_thumbs_indices[i];
  227. const int is_exception = exceptions.has(editor_icons_names[index]);
  228. const Ref<ImageTexture> icon = editor_generate_icon(index, !p_dark_theme && !is_exception, scale, force_filter);
  229. p_theme->set_icon(editor_icons_names[index], "EditorIcons", icon);
  230. }
  231. } else {
  232. const float scale = (float)p_thumb_size / 32.0 * EDSCALE;
  233. for (int i = 0; i < editor_md_thumbs_count; i++) {
  234. const int index = editor_md_thumbs_indices[i];
  235. const bool is_exception = exceptions.has(editor_icons_names[index]);
  236. const Ref<ImageTexture> icon = editor_generate_icon(index, !p_dark_theme && !is_exception, scale, force_filter);
  237. p_theme->set_icon(editor_icons_names[index], "EditorIcons", icon);
  238. }
  239. }
  240. ImageLoaderSVG::set_convert_colors(NULL);
  241. #else
  242. WARN_PRINT("SVG support disabled, editor icons won't be rendered.");
  243. #endif
  244. }
  245. Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
  246. Ref<Theme> theme = Ref<Theme>(memnew(Theme));
  247. const float default_contrast = 0.25;
  248. //Theme settings
  249. Color accent_color = EDITOR_GET("interface/theme/accent_color");
  250. Color base_color = EDITOR_GET("interface/theme/base_color");
  251. float contrast = EDITOR_GET("interface/theme/contrast");
  252. float relationship_line_opacity = EDITOR_GET("interface/theme/relationship_line_opacity");
  253. String preset = EDITOR_GET("interface/theme/preset");
  254. bool highlight_tabs = EDITOR_GET("interface/theme/highlight_tabs");
  255. int border_size = EDITOR_GET("interface/theme/border_size");
  256. bool use_gn_headers = EDITOR_GET("interface/theme/use_graph_node_headers");
  257. Color preset_accent_color;
  258. Color preset_base_color;
  259. float preset_contrast = 0;
  260. // Please, use alphabet order if you've added new theme here(After "Default" and "Custom")
  261. if (preset == "Default") {
  262. preset_accent_color = Color(0.41, 0.61, 0.91);
  263. preset_base_color = Color(0.2, 0.23, 0.31);
  264. preset_contrast = default_contrast;
  265. } else if (preset == "Custom") {
  266. accent_color = EDITOR_GET("interface/theme/accent_color");
  267. base_color = EDITOR_GET("interface/theme/base_color");
  268. contrast = EDITOR_GET("interface/theme/contrast");
  269. } else if (preset == "Alien") {
  270. preset_accent_color = Color(0.11, 1.0, 0.6);
  271. preset_base_color = Color(0.18, 0.22, 0.25);
  272. preset_contrast = 0.25;
  273. } else if (preset == "Arc") {
  274. preset_accent_color = Color(0.32, 0.58, 0.89);
  275. preset_base_color = Color(0.22, 0.24, 0.29);
  276. preset_contrast = 0.25;
  277. } else if (preset == "Godot 2") {
  278. preset_accent_color = Color(0.53, 0.67, 0.89);
  279. preset_base_color = Color(0.24, 0.23, 0.27);
  280. preset_contrast = 0.25;
  281. } else if (preset == "Grey") {
  282. preset_accent_color = Color(0.72, 0.89, 1.0);
  283. preset_base_color = Color(0.24, 0.24, 0.24);
  284. preset_contrast = 0.2;
  285. } else if (preset == "Light") {
  286. preset_accent_color = Color(0.13, 0.44, 1.0);
  287. preset_base_color = Color(1, 1, 1);
  288. preset_contrast = 0.08;
  289. } else if (preset == "Solarized (Dark)") {
  290. preset_accent_color = Color(0.15, 0.55, 0.82);
  291. preset_base_color = Color(0.03, 0.21, 0.26);
  292. preset_contrast = 0.23;
  293. } else if (preset == "Solarized (Light)") {
  294. preset_accent_color = Color(0.15, 0.55, 0.82);
  295. preset_base_color = Color(0.99, 0.96, 0.89);
  296. preset_contrast = 0.06;
  297. } else { // Default
  298. preset_accent_color = Color(0.41, 0.61, 0.91);
  299. preset_base_color = Color(0.2, 0.23, 0.31);
  300. preset_contrast = default_contrast;
  301. }
  302. if (preset != "Custom") {
  303. accent_color = preset_accent_color;
  304. base_color = preset_base_color;
  305. contrast = preset_contrast;
  306. EditorSettings::get_singleton()->set_initial_value("interface/theme/accent_color", accent_color);
  307. EditorSettings::get_singleton()->set_initial_value("interface/theme/base_color", base_color);
  308. EditorSettings::get_singleton()->set_initial_value("interface/theme/contrast", contrast);
  309. }
  310. EditorSettings::get_singleton()->set_manually("interface/theme/preset", preset);
  311. EditorSettings::get_singleton()->set_manually("interface/theme/accent_color", accent_color);
  312. EditorSettings::get_singleton()->set_manually("interface/theme/base_color", base_color);
  313. EditorSettings::get_singleton()->set_manually("interface/theme/contrast", contrast);
  314. //Colors
  315. bool dark_theme = EditorSettings::get_singleton()->is_dark_theme();
  316. const Color dark_color_1 = base_color.linear_interpolate(Color(0, 0, 0, 1), contrast);
  317. const Color dark_color_2 = base_color.linear_interpolate(Color(0, 0, 0, 1), contrast * 1.5);
  318. const Color dark_color_3 = base_color.linear_interpolate(Color(0, 0, 0, 1), contrast * 2);
  319. const Color background_color = dark_color_2;
  320. // white (dark theme) or black (light theme), will be used to generate the rest of the colors
  321. const Color mono_color = dark_theme ? Color(1, 1, 1) : Color(0, 0, 0);
  322. const Color contrast_color_1 = base_color.linear_interpolate(mono_color, MAX(contrast, default_contrast));
  323. const Color contrast_color_2 = base_color.linear_interpolate(mono_color, MAX(contrast * 1.5, default_contrast * 1.5));
  324. const Color font_color = mono_color.linear_interpolate(base_color, 0.25);
  325. const Color font_color_hl = mono_color.linear_interpolate(base_color, 0.15);
  326. const Color font_color_disabled = Color(mono_color.r, mono_color.g, mono_color.b, 0.3);
  327. const Color font_color_selection = accent_color * Color(1, 1, 1, 0.4);
  328. const Color color_disabled = mono_color.inverted().linear_interpolate(base_color, 0.7);
  329. const Color color_disabled_bg = mono_color.inverted().linear_interpolate(base_color, 0.9);
  330. Color icon_color_hover = Color(1, 1, 1) * (dark_theme ? 1.15 : 1.45);
  331. icon_color_hover.a = 1.0;
  332. // Make the pressed icon color overbright because icons are not completely white on a dark theme.
  333. // On a light theme, icons are dark, so we need to modulate them with an even brighter color.
  334. Color icon_color_pressed = accent_color * (dark_theme ? 1.15 : 3.5);
  335. icon_color_pressed.a = 1.0;
  336. const Color separator_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.1);
  337. const Color highlight_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.2);
  338. theme->set_color("accent_color", "Editor", accent_color);
  339. theme->set_color("highlight_color", "Editor", highlight_color);
  340. theme->set_color("base_color", "Editor", base_color);
  341. theme->set_color("dark_color_1", "Editor", dark_color_1);
  342. theme->set_color("dark_color_2", "Editor", dark_color_2);
  343. theme->set_color("dark_color_3", "Editor", dark_color_3);
  344. theme->set_color("contrast_color_1", "Editor", contrast_color_1);
  345. theme->set_color("contrast_color_2", "Editor", contrast_color_2);
  346. theme->set_color("box_selection_fill_color", "Editor", accent_color * Color(1, 1, 1, 0.3));
  347. theme->set_color("box_selection_stroke_color", "Editor", accent_color * Color(1, 1, 1, 0.8));
  348. theme->set_color("axis_x_color", "Editor", Color(0.96, 0.20, 0.32));
  349. theme->set_color("axis_y_color", "Editor", Color(0.53, 0.84, 0.01));
  350. theme->set_color("axis_z_color", "Editor", Color(0.16, 0.55, 0.96));
  351. theme->set_color("font_color", "Editor", font_color);
  352. theme->set_color("highlighted_font_color", "Editor", font_color_hl);
  353. theme->set_color("disabled_font_color", "Editor", font_color_disabled);
  354. theme->set_color("mono_color", "Editor", mono_color);
  355. Color success_color = Color(0.45, 0.95, 0.5);
  356. Color warning_color = Color(1, 0.87, 0.4);
  357. Color error_color = Color(1, 0.47, 0.42);
  358. Color property_color = font_color.linear_interpolate(Color(0.5, 0.5, 0.5), 0.5);
  359. if (!dark_theme) {
  360. // Darken some colors to be readable on a light background
  361. success_color = success_color.linear_interpolate(mono_color, 0.35);
  362. warning_color = warning_color.linear_interpolate(mono_color, 0.35);
  363. error_color = error_color.linear_interpolate(mono_color, 0.25);
  364. }
  365. theme->set_color("success_color", "Editor", success_color);
  366. theme->set_color("warning_color", "Editor", warning_color);
  367. theme->set_color("error_color", "Editor", error_color);
  368. theme->set_color("property_color", "Editor", property_color);
  369. const int thumb_size = EDITOR_GET("filesystem/file_dialog/thumbnail_size");
  370. theme->set_constant("scale", "Editor", EDSCALE);
  371. theme->set_constant("thumb_size", "Editor", thumb_size);
  372. theme->set_constant("dark_theme", "Editor", dark_theme);
  373. //Register icons + font
  374. // the resolution and the icon color (dark_theme bool) has not changed, so we do not regenerate the icons
  375. if (p_theme != NULL && fabs(p_theme->get_constant("scale", "Editor") - EDSCALE) < 0.00001 && (bool)p_theme->get_constant("dark_theme", "Editor") == dark_theme) {
  376. // register already generated icons
  377. for (int i = 0; i < editor_icons_count; i++) {
  378. theme->set_icon(editor_icons_names[i], "EditorIcons", p_theme->get_icon(editor_icons_names[i], "EditorIcons"));
  379. }
  380. } else {
  381. editor_register_and_generate_icons(theme, dark_theme, thumb_size);
  382. }
  383. // thumbnail size has changed, so we regenerate the medium sizes
  384. if (p_theme != NULL && fabs((double)p_theme->get_constant("thumb_size", "Editor") - thumb_size) > 0.00001) {
  385. editor_register_and_generate_icons(p_theme, dark_theme, thumb_size, true);
  386. }
  387. editor_register_fonts(theme);
  388. // Highlighted tabs and border width
  389. Color tab_color = highlight_tabs ? base_color.linear_interpolate(font_color, contrast) : base_color;
  390. // Ensure borders are visible when using an editor scale below 100%.
  391. const int border_width = CLAMP(border_size, 0, 3) * MAX(1, EDSCALE);
  392. const int default_margin_size = 4;
  393. const int margin_size_extra = default_margin_size + CLAMP(border_size, 0, 3);
  394. // styleboxes
  395. // this is the most commonly used stylebox, variations should be made as duplicate of this
  396. Ref<StyleBoxFlat> style_default = make_flat_stylebox(base_color, default_margin_size, default_margin_size, default_margin_size, default_margin_size);
  397. style_default->set_border_width_all(border_width);
  398. style_default->set_border_color(base_color);
  399. style_default->set_draw_center(true);
  400. // Button and widgets
  401. const float extra_spacing = EDITOR_GET("interface/theme/additional_spacing");
  402. Ref<StyleBoxFlat> style_widget = style_default->duplicate();
  403. style_widget->set_default_margin(MARGIN_LEFT, (extra_spacing + 6) * EDSCALE);
  404. style_widget->set_default_margin(MARGIN_TOP, (extra_spacing + default_margin_size) * EDSCALE);
  405. style_widget->set_default_margin(MARGIN_RIGHT, (extra_spacing + 6) * EDSCALE);
  406. style_widget->set_default_margin(MARGIN_BOTTOM, (extra_spacing + default_margin_size) * EDSCALE);
  407. style_widget->set_bg_color(dark_color_1);
  408. style_widget->set_border_color(dark_color_2);
  409. Ref<StyleBoxFlat> style_widget_disabled = style_widget->duplicate();
  410. style_widget_disabled->set_border_color(color_disabled);
  411. style_widget_disabled->set_bg_color(color_disabled_bg);
  412. Ref<StyleBoxFlat> style_widget_focus = style_widget->duplicate();
  413. style_widget_focus->set_border_color(accent_color);
  414. Ref<StyleBoxFlat> style_widget_pressed = style_widget->duplicate();
  415. style_widget_pressed->set_border_color(accent_color);
  416. Ref<StyleBoxFlat> style_widget_hover = style_widget->duplicate();
  417. style_widget_hover->set_border_color(contrast_color_1);
  418. // style for windows, popups, etc..
  419. Ref<StyleBoxFlat> style_popup = style_default->duplicate();
  420. const int popup_margin_size = default_margin_size * EDSCALE * 2;
  421. style_popup->set_default_margin(MARGIN_LEFT, popup_margin_size);
  422. style_popup->set_default_margin(MARGIN_TOP, popup_margin_size);
  423. style_popup->set_default_margin(MARGIN_RIGHT, popup_margin_size);
  424. style_popup->set_default_margin(MARGIN_BOTTOM, popup_margin_size);
  425. style_popup->set_border_color(contrast_color_1);
  426. style_popup->set_border_width_all(MAX(EDSCALE, border_width));
  427. const Color shadow_color = Color(0, 0, 0, dark_theme ? 0.3 : 0.1);
  428. style_popup->set_shadow_color(shadow_color);
  429. style_popup->set_shadow_size(4 * EDSCALE);
  430. Ref<StyleBoxLine> style_popup_separator(memnew(StyleBoxLine));
  431. style_popup_separator->set_color(separator_color);
  432. style_popup_separator->set_grow_begin(popup_margin_size - MAX(EDSCALE, border_width));
  433. style_popup_separator->set_grow_end(popup_margin_size - MAX(EDSCALE, border_width));
  434. style_popup_separator->set_thickness(MAX(EDSCALE, border_width));
  435. Ref<StyleBoxLine> style_popup_labeled_separator_left(memnew(StyleBoxLine));
  436. style_popup_labeled_separator_left->set_grow_begin(popup_margin_size - MAX(EDSCALE, border_width));
  437. style_popup_labeled_separator_left->set_color(separator_color);
  438. style_popup_labeled_separator_left->set_thickness(MAX(EDSCALE, border_width));
  439. Ref<StyleBoxLine> style_popup_labeled_separator_right(memnew(StyleBoxLine));
  440. style_popup_labeled_separator_right->set_grow_end(popup_margin_size - MAX(EDSCALE, border_width));
  441. style_popup_labeled_separator_right->set_color(separator_color);
  442. style_popup_labeled_separator_right->set_thickness(MAX(EDSCALE, border_width));
  443. Ref<StyleBoxEmpty> style_empty = make_empty_stylebox(default_margin_size, default_margin_size, default_margin_size, default_margin_size);
  444. // Tabs
  445. const int tab_default_margin_side = 10 * EDSCALE + extra_spacing * EDSCALE;
  446. const int tab_default_margin_vertical = 5 * EDSCALE + extra_spacing * EDSCALE;
  447. Ref<StyleBoxFlat> style_tab_selected = style_widget->duplicate();
  448. style_tab_selected->set_border_width_all(border_width);
  449. style_tab_selected->set_border_width(MARGIN_BOTTOM, 0);
  450. style_tab_selected->set_border_color(dark_color_3);
  451. style_tab_selected->set_expand_margin_size(MARGIN_BOTTOM, border_width);
  452. style_tab_selected->set_default_margin(MARGIN_LEFT, tab_default_margin_side);
  453. style_tab_selected->set_default_margin(MARGIN_RIGHT, tab_default_margin_side);
  454. style_tab_selected->set_default_margin(MARGIN_BOTTOM, tab_default_margin_vertical);
  455. style_tab_selected->set_default_margin(MARGIN_TOP, tab_default_margin_vertical);
  456. style_tab_selected->set_bg_color(tab_color);
  457. Ref<StyleBoxFlat> style_tab_unselected = style_tab_selected->duplicate();
  458. style_tab_unselected->set_bg_color(dark_color_1);
  459. style_tab_unselected->set_border_color(dark_color_2);
  460. Ref<StyleBoxFlat> style_tab_disabled = style_tab_selected->duplicate();
  461. style_tab_disabled->set_bg_color(color_disabled_bg);
  462. style_tab_disabled->set_border_color(color_disabled);
  463. // Editor background
  464. Color background_color_opaque = background_color;
  465. background_color_opaque.a = 1.0;
  466. theme->set_stylebox("Background", "EditorStyles", make_flat_stylebox(background_color_opaque, default_margin_size, default_margin_size, default_margin_size, default_margin_size));
  467. // Focus
  468. Ref<StyleBoxFlat> style_focus = style_default->duplicate();
  469. style_focus->set_draw_center(false);
  470. style_focus->set_border_color(contrast_color_2);
  471. theme->set_stylebox("Focus", "EditorStyles", style_focus);
  472. // Menu
  473. Ref<StyleBoxFlat> style_menu = style_widget->duplicate();
  474. style_menu->set_draw_center(false);
  475. style_menu->set_border_width_all(0);
  476. theme->set_stylebox("panel", "PanelContainer", style_menu);
  477. theme->set_stylebox("MenuPanel", "EditorStyles", style_menu);
  478. // Script Editor
  479. theme->set_stylebox("ScriptEditorPanel", "EditorStyles", make_empty_stylebox(default_margin_size, 0, default_margin_size, default_margin_size));
  480. theme->set_stylebox("ScriptEditor", "EditorStyles", make_empty_stylebox(0, 0, 0, 0));
  481. // Play button group
  482. theme->set_stylebox("PlayButtonPanel", "EditorStyles", style_empty);
  483. //MenuButton
  484. Ref<StyleBoxFlat> style_menu_hover_border = style_widget->duplicate();
  485. style_menu_hover_border->set_draw_center(false);
  486. style_menu_hover_border->set_border_width_all(0);
  487. style_menu_hover_border->set_border_width(MARGIN_BOTTOM, border_width);
  488. style_menu_hover_border->set_border_color(accent_color);
  489. Ref<StyleBoxFlat> style_menu_hover_bg = style_widget->duplicate();
  490. style_menu_hover_bg->set_border_width_all(0);
  491. style_menu_hover_bg->set_bg_color(dark_color_1);
  492. theme->set_stylebox("normal", "MenuButton", style_menu);
  493. theme->set_stylebox("hover", "MenuButton", style_menu);
  494. theme->set_stylebox("pressed", "MenuButton", style_menu);
  495. theme->set_stylebox("focus", "MenuButton", style_menu);
  496. theme->set_stylebox("disabled", "MenuButton", style_menu);
  497. theme->set_stylebox("normal", "PopupMenu", style_menu);
  498. theme->set_stylebox("hover", "PopupMenu", style_menu_hover_bg);
  499. theme->set_stylebox("pressed", "PopupMenu", style_menu);
  500. theme->set_stylebox("focus", "PopupMenu", style_menu);
  501. theme->set_stylebox("disabled", "PopupMenu", style_menu);
  502. theme->set_stylebox("normal", "ToolButton", style_menu);
  503. theme->set_stylebox("hover", "ToolButton", style_menu);
  504. theme->set_stylebox("pressed", "ToolButton", style_menu);
  505. theme->set_stylebox("focus", "ToolButton", style_menu);
  506. theme->set_stylebox("disabled", "ToolButton", style_menu);
  507. theme->set_color("font_color", "MenuButton", font_color);
  508. theme->set_color("font_color_hover", "MenuButton", font_color_hl);
  509. theme->set_color("font_color", "ToolButton", font_color);
  510. theme->set_color("font_color_hover", "ToolButton", font_color_hl);
  511. theme->set_color("font_color_pressed", "ToolButton", accent_color);
  512. theme->set_stylebox("MenuHover", "EditorStyles", style_menu_hover_border);
  513. // Buttons
  514. theme->set_stylebox("normal", "Button", style_widget);
  515. theme->set_stylebox("hover", "Button", style_widget_hover);
  516. theme->set_stylebox("pressed", "Button", style_widget_pressed);
  517. theme->set_stylebox("focus", "Button", style_widget_focus);
  518. theme->set_stylebox("disabled", "Button", style_widget_disabled);
  519. theme->set_color("font_color", "Button", font_color);
  520. theme->set_color("font_color_hover", "Button", font_color_hl);
  521. theme->set_color("font_color_pressed", "Button", accent_color);
  522. theme->set_color("font_color_disabled", "Button", font_color_disabled);
  523. theme->set_color("icon_color_hover", "Button", icon_color_hover);
  524. theme->set_color("icon_color_pressed", "Button", icon_color_pressed);
  525. // OptionButton
  526. theme->set_stylebox("normal", "OptionButton", style_widget);
  527. theme->set_stylebox("hover", "OptionButton", style_widget_hover);
  528. theme->set_stylebox("pressed", "OptionButton", style_widget_pressed);
  529. theme->set_stylebox("focus", "OptionButton", style_widget_focus);
  530. theme->set_stylebox("disabled", "OptionButton", style_widget_disabled);
  531. theme->set_color("font_color", "OptionButton", font_color);
  532. theme->set_color("font_color_hover", "OptionButton", font_color_hl);
  533. theme->set_color("font_color_pressed", "OptionButton", accent_color);
  534. theme->set_color("font_color_disabled", "OptionButton", font_color_disabled);
  535. theme->set_color("icon_color_hover", "OptionButton", icon_color_hover);
  536. theme->set_icon("arrow", "OptionButton", theme->get_icon("GuiOptionArrow", "EditorIcons"));
  537. theme->set_constant("arrow_margin", "OptionButton", default_margin_size * EDSCALE);
  538. theme->set_constant("modulate_arrow", "OptionButton", true);
  539. theme->set_constant("hseparation", "OptionButton", 4 * EDSCALE);
  540. // CheckButton
  541. theme->set_stylebox("normal", "CheckButton", style_menu);
  542. theme->set_stylebox("pressed", "CheckButton", style_menu);
  543. theme->set_stylebox("disabled", "CheckButton", style_menu);
  544. theme->set_stylebox("hover", "CheckButton", style_menu);
  545. theme->set_icon("on", "CheckButton", theme->get_icon("GuiToggleOn", "EditorIcons"));
  546. theme->set_icon("on_disabled", "CheckButton", theme->get_icon("GuiToggleOnDisabled", "EditorIcons"));
  547. theme->set_icon("off", "CheckButton", theme->get_icon("GuiToggleOff", "EditorIcons"));
  548. theme->set_icon("off_disabled", "CheckButton", theme->get_icon("GuiToggleOffDisabled", "EditorIcons"));
  549. theme->set_color("font_color", "CheckButton", font_color);
  550. theme->set_color("font_color_hover", "CheckButton", font_color_hl);
  551. theme->set_color("font_color_pressed", "CheckButton", accent_color);
  552. theme->set_color("font_color_disabled", "CheckButton", font_color_disabled);
  553. theme->set_color("icon_color_hover", "CheckButton", icon_color_hover);
  554. theme->set_constant("hseparation", "CheckButton", 4 * EDSCALE);
  555. theme->set_constant("check_vadjust", "CheckButton", 0 * EDSCALE);
  556. // Checkbox
  557. Ref<StyleBoxFlat> sb_checkbox = style_menu->duplicate();
  558. sb_checkbox->set_default_margin(MARGIN_LEFT, default_margin_size * EDSCALE);
  559. sb_checkbox->set_default_margin(MARGIN_RIGHT, default_margin_size * EDSCALE);
  560. sb_checkbox->set_default_margin(MARGIN_TOP, default_margin_size * EDSCALE);
  561. sb_checkbox->set_default_margin(MARGIN_BOTTOM, default_margin_size * EDSCALE);
  562. theme->set_stylebox("normal", "CheckBox", sb_checkbox);
  563. theme->set_stylebox("pressed", "CheckBox", sb_checkbox);
  564. theme->set_stylebox("disabled", "CheckBox", sb_checkbox);
  565. theme->set_stylebox("hover", "CheckBox", sb_checkbox);
  566. theme->set_icon("checked", "CheckBox", theme->get_icon("GuiChecked", "EditorIcons"));
  567. theme->set_icon("unchecked", "CheckBox", theme->get_icon("GuiUnchecked", "EditorIcons"));
  568. theme->set_icon("radio_checked", "CheckBox", theme->get_icon("GuiRadioChecked", "EditorIcons"));
  569. theme->set_icon("radio_unchecked", "CheckBox", theme->get_icon("GuiRadioUnchecked", "EditorIcons"));
  570. theme->set_color("font_color", "CheckBox", font_color);
  571. theme->set_color("font_color_hover", "CheckBox", font_color_hl);
  572. theme->set_color("font_color_pressed", "CheckBox", accent_color);
  573. theme->set_color("font_color_disabled", "CheckBox", font_color_disabled);
  574. theme->set_color("icon_color_hover", "CheckBox", icon_color_hover);
  575. theme->set_constant("hseparation", "CheckBox", 4 * EDSCALE);
  576. theme->set_constant("check_vadjust", "CheckBox", 0 * EDSCALE);
  577. // PopupDialog
  578. theme->set_stylebox("panel", "PopupDialog", style_popup);
  579. // PopupMenu
  580. theme->set_stylebox("panel", "PopupMenu", style_popup);
  581. theme->set_stylebox("separator", "PopupMenu", style_popup_separator);
  582. theme->set_stylebox("labeled_separator_left", "PopupMenu", style_popup_labeled_separator_left);
  583. theme->set_stylebox("labeled_separator_right", "PopupMenu", style_popup_labeled_separator_right);
  584. theme->set_color("font_color", "PopupMenu", font_color);
  585. theme->set_color("font_color_hover", "PopupMenu", font_color_hl);
  586. theme->set_color("font_color_accel", "PopupMenu", font_color_disabled);
  587. theme->set_color("font_color_disabled", "PopupMenu", font_color_disabled);
  588. theme->set_color("font_color_separator", "PopupMenu", font_color_disabled);
  589. theme->set_icon("checked", "PopupMenu", theme->get_icon("GuiChecked", "EditorIcons"));
  590. theme->set_icon("unchecked", "PopupMenu", theme->get_icon("GuiUnchecked", "EditorIcons"));
  591. theme->set_icon("radio_checked", "PopupMenu", theme->get_icon("GuiRadioChecked", "EditorIcons"));
  592. theme->set_icon("radio_unchecked", "PopupMenu", theme->get_icon("GuiRadioUnchecked", "EditorIcons"));
  593. theme->set_icon("submenu", "PopupMenu", theme->get_icon("ArrowRight", "EditorIcons"));
  594. theme->set_icon("visibility_hidden", "PopupMenu", theme->get_icon("GuiVisibilityHidden", "EditorIcons"));
  595. theme->set_icon("visibility_visible", "PopupMenu", theme->get_icon("GuiVisibilityVisible", "EditorIcons"));
  596. theme->set_icon("visibility_xray", "PopupMenu", theme->get_icon("GuiVisibilityXray", "EditorIcons"));
  597. theme->set_constant("vseparation", "PopupMenu", (extra_spacing + default_margin_size + 1) * EDSCALE);
  598. for (int i = 0; i < 16; i++) {
  599. Color si_base_color = accent_color;
  600. float hue_rotate = (i * 2 % 16) / 16.0;
  601. 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());
  602. si_base_color = accent_color.linear_interpolate(si_base_color, float(EDITOR_GET("docks/property_editor/subresource_hue_tint")));
  603. Ref<StyleBoxFlat> sub_inspector_bg;
  604. sub_inspector_bg = make_flat_stylebox(dark_color_1.linear_interpolate(si_base_color, 0.08), 2, 0, 2, 2);
  605. sub_inspector_bg->set_border_width(MARGIN_LEFT, 2);
  606. sub_inspector_bg->set_border_width(MARGIN_RIGHT, 2);
  607. sub_inspector_bg->set_border_width(MARGIN_BOTTOM, 2);
  608. sub_inspector_bg->set_border_width(MARGIN_TOP, 2);
  609. sub_inspector_bg->set_default_margin(MARGIN_LEFT, 3);
  610. sub_inspector_bg->set_default_margin(MARGIN_RIGHT, 3);
  611. sub_inspector_bg->set_default_margin(MARGIN_BOTTOM, 10);
  612. sub_inspector_bg->set_default_margin(MARGIN_TOP, 5);
  613. sub_inspector_bg->set_border_color(si_base_color * Color(0.7, 0.7, 0.7, 0.8));
  614. sub_inspector_bg->set_draw_center(true);
  615. theme->set_stylebox("sub_inspector_bg" + itos(i), "Editor", sub_inspector_bg);
  616. Ref<StyleBoxFlat> bg_color;
  617. bg_color.instance();
  618. bg_color->set_bg_color(si_base_color * Color(0.7, 0.7, 0.7, 0.8));
  619. bg_color->set_border_width_all(0);
  620. Ref<StyleBoxFlat> bg_color_selected;
  621. bg_color_selected.instance();
  622. bg_color_selected->set_border_width_all(0);
  623. bg_color_selected->set_bg_color(si_base_color * Color(0.8, 0.8, 0.8, 0.8));
  624. theme->set_stylebox("sub_inspector_property_bg" + itos(i), "Editor", bg_color);
  625. theme->set_stylebox("sub_inspector_property_bg_selected" + itos(i), "Editor", bg_color_selected);
  626. }
  627. theme->set_color("sub_inspector_property_color", "Editor", dark_theme ? Color(1, 1, 1, 1) : Color(0, 0, 0, 1));
  628. theme->set_constant("sub_inspector_font_offset", "Editor", 4 * EDSCALE);
  629. Ref<StyleBoxFlat> style_property_bg = style_default->duplicate();
  630. style_property_bg->set_bg_color(highlight_color);
  631. style_property_bg->set_border_width_all(0);
  632. theme->set_constant("font_offset", "EditorProperty", 1 * EDSCALE);
  633. theme->set_stylebox("bg_selected", "EditorProperty", style_property_bg);
  634. theme->set_stylebox("bg", "EditorProperty", Ref<StyleBoxEmpty>(memnew(StyleBoxEmpty)));
  635. theme->set_constant("vseparation", "EditorProperty", (extra_spacing + default_margin_size) * EDSCALE);
  636. theme->set_color("error_color", "EditorProperty", error_color);
  637. theme->set_color("property_color", "EditorProperty", property_color);
  638. theme->set_constant("inspector_margin", "Editor", 8 * EDSCALE);
  639. // Tree & ItemList background
  640. Ref<StyleBoxFlat> style_tree_bg = style_default->duplicate();
  641. style_tree_bg->set_bg_color(dark_color_1);
  642. style_tree_bg->set_border_color(dark_color_3);
  643. theme->set_stylebox("bg", "Tree", style_tree_bg);
  644. const Color guide_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.05);
  645. Color relationship_line_color = Color(mono_color.r, mono_color.g, mono_color.b, relationship_line_opacity);
  646. // Tree
  647. theme->set_icon("checked", "Tree", theme->get_icon("GuiChecked", "EditorIcons"));
  648. theme->set_icon("unchecked", "Tree", theme->get_icon("GuiUnchecked", "EditorIcons"));
  649. theme->set_icon("arrow", "Tree", theme->get_icon("GuiTreeArrowDown", "EditorIcons"));
  650. theme->set_icon("arrow_collapsed", "Tree", theme->get_icon("GuiTreeArrowRight", "EditorIcons"));
  651. theme->set_icon("updown", "Tree", theme->get_icon("GuiTreeUpdown", "EditorIcons"));
  652. theme->set_icon("select_arrow", "Tree", theme->get_icon("GuiDropdown", "EditorIcons"));
  653. theme->set_stylebox("bg_focus", "Tree", style_focus);
  654. theme->set_stylebox("custom_button", "Tree", make_empty_stylebox());
  655. theme->set_stylebox("custom_button_pressed", "Tree", make_empty_stylebox());
  656. theme->set_stylebox("custom_button_hover", "Tree", style_widget);
  657. theme->set_color("custom_button_font_highlight", "Tree", font_color_hl);
  658. theme->set_color("font_color", "Tree", font_color);
  659. theme->set_color("font_color_selected", "Tree", mono_color);
  660. theme->set_color("title_button_color", "Tree", font_color);
  661. theme->set_color("guide_color", "Tree", guide_color);
  662. theme->set_color("relationship_line_color", "Tree", relationship_line_color);
  663. theme->set_color("drop_position_color", "Tree", accent_color);
  664. theme->set_constant("vseparation", "Tree", (extra_spacing + default_margin_size) * EDSCALE);
  665. theme->set_constant("hseparation", "Tree", (extra_spacing + default_margin_size) * EDSCALE);
  666. theme->set_constant("item_margin", "Tree", 3 * default_margin_size * EDSCALE);
  667. theme->set_constant("button_margin", "Tree", default_margin_size * EDSCALE);
  668. theme->set_constant("draw_relationship_lines", "Tree", relationship_line_opacity >= 0.01);
  669. theme->set_constant("draw_guides", "Tree", relationship_line_opacity < 0.01);
  670. theme->set_constant("scroll_border", "Tree", 40 * EDSCALE);
  671. theme->set_constant("scroll_speed", "Tree", 12);
  672. Ref<StyleBoxFlat> style_tree_btn = style_default->duplicate();
  673. style_tree_btn->set_bg_color(contrast_color_1);
  674. style_tree_btn->set_border_width_all(0);
  675. theme->set_stylebox("button_pressed", "Tree", style_tree_btn);
  676. Ref<StyleBoxFlat> style_tree_hover = style_default->duplicate();
  677. style_tree_hover->set_bg_color(highlight_color * Color(1, 1, 1, 0.4));
  678. style_tree_hover->set_border_width_all(0);
  679. theme->set_stylebox("hover", "Tree", style_tree_hover);
  680. Ref<StyleBoxFlat> style_tree_focus = style_default->duplicate();
  681. style_tree_focus->set_bg_color(highlight_color);
  682. style_tree_focus->set_border_width_all(0);
  683. theme->set_stylebox("selected_focus", "Tree", style_tree_focus);
  684. Ref<StyleBoxFlat> style_tree_selected = style_tree_focus->duplicate();
  685. theme->set_stylebox("selected", "Tree", style_tree_selected);
  686. Ref<StyleBoxFlat> style_tree_cursor = style_default->duplicate();
  687. style_tree_cursor->set_draw_center(false);
  688. style_tree_cursor->set_border_width_all(MAX(1, border_width));
  689. style_tree_cursor->set_border_color(contrast_color_1);
  690. Ref<StyleBoxFlat> style_tree_title = style_default->duplicate();
  691. style_tree_title->set_bg_color(dark_color_3);
  692. style_tree_title->set_border_width_all(0);
  693. theme->set_stylebox("cursor", "Tree", style_tree_cursor);
  694. theme->set_stylebox("cursor_unfocused", "Tree", style_tree_cursor);
  695. theme->set_stylebox("title_button_normal", "Tree", style_tree_title);
  696. theme->set_stylebox("title_button_hover", "Tree", style_tree_title);
  697. theme->set_stylebox("title_button_pressed", "Tree", style_tree_title);
  698. Color prop_category_color = dark_color_1.linear_interpolate(mono_color, 0.12);
  699. Color prop_section_color = dark_color_1.linear_interpolate(mono_color, 0.09);
  700. Color prop_subsection_color = dark_color_1.linear_interpolate(mono_color, 0.06);
  701. theme->set_color("prop_category", "Editor", prop_category_color);
  702. theme->set_color("prop_section", "Editor", prop_section_color);
  703. theme->set_color("prop_subsection", "Editor", prop_subsection_color);
  704. theme->set_color("drop_position_color", "Tree", accent_color);
  705. // ItemList
  706. Ref<StyleBoxFlat> style_itemlist_bg = style_default->duplicate();
  707. style_itemlist_bg->set_bg_color(dark_color_1);
  708. style_itemlist_bg->set_border_width_all(border_width);
  709. style_itemlist_bg->set_border_color(dark_color_3);
  710. Ref<StyleBoxFlat> style_itemlist_cursor = style_default->duplicate();
  711. style_itemlist_cursor->set_draw_center(false);
  712. style_itemlist_cursor->set_border_width_all(border_width);
  713. style_itemlist_cursor->set_border_color(highlight_color);
  714. theme->set_stylebox("cursor", "ItemList", style_itemlist_cursor);
  715. theme->set_stylebox("cursor_unfocused", "ItemList", style_itemlist_cursor);
  716. theme->set_stylebox("selected_focus", "ItemList", style_tree_focus);
  717. theme->set_stylebox("selected", "ItemList", style_tree_selected);
  718. theme->set_stylebox("bg_focus", "ItemList", style_focus);
  719. theme->set_stylebox("bg", "ItemList", style_itemlist_bg);
  720. theme->set_color("font_color", "ItemList", font_color);
  721. theme->set_color("font_color_selected", "ItemList", mono_color);
  722. theme->set_color("guide_color", "ItemList", guide_color);
  723. theme->set_constant("vseparation", "ItemList", 3 * EDSCALE);
  724. theme->set_constant("hseparation", "ItemList", 3 * EDSCALE);
  725. theme->set_constant("icon_margin", "ItemList", default_margin_size * EDSCALE);
  726. theme->set_constant("line_separation", "ItemList", 3 * EDSCALE);
  727. // Tabs & TabContainer
  728. theme->set_stylebox("tab_fg", "TabContainer", style_tab_selected);
  729. theme->set_stylebox("tab_bg", "TabContainer", style_tab_unselected);
  730. theme->set_stylebox("tab_disabled", "TabContainer", style_tab_disabled);
  731. theme->set_stylebox("tab_fg", "Tabs", style_tab_selected);
  732. theme->set_stylebox("tab_bg", "Tabs", style_tab_unselected);
  733. theme->set_stylebox("tab_disabled", "Tabs", style_tab_disabled);
  734. theme->set_color("font_color_fg", "TabContainer", font_color);
  735. theme->set_color("font_color_bg", "TabContainer", font_color_disabled);
  736. theme->set_color("font_color_fg", "Tabs", font_color);
  737. theme->set_color("font_color_bg", "Tabs", font_color_disabled);
  738. theme->set_icon("menu", "TabContainer", theme->get_icon("GuiTabMenu", "EditorIcons"));
  739. theme->set_icon("menu_highlight", "TabContainer", theme->get_icon("GuiTabMenuHl", "EditorIcons"));
  740. theme->set_stylebox("SceneTabFG", "EditorStyles", style_tab_selected);
  741. theme->set_stylebox("SceneTabBG", "EditorStyles", style_tab_unselected);
  742. theme->set_icon("close", "Tabs", theme->get_icon("GuiClose", "EditorIcons"));
  743. theme->set_stylebox("button_pressed", "Tabs", style_menu);
  744. theme->set_stylebox("button", "Tabs", style_menu);
  745. theme->set_icon("increment", "TabContainer", theme->get_icon("GuiScrollArrowRight", "EditorIcons"));
  746. theme->set_icon("decrement", "TabContainer", theme->get_icon("GuiScrollArrowLeft", "EditorIcons"));
  747. theme->set_icon("increment", "Tabs", theme->get_icon("GuiScrollArrowRight", "EditorIcons"));
  748. theme->set_icon("decrement", "Tabs", theme->get_icon("GuiScrollArrowLeft", "EditorIcons"));
  749. theme->set_icon("increment_highlight", "Tabs", theme->get_icon("GuiScrollArrowRightHl", "EditorIcons"));
  750. theme->set_icon("decrement_highlight", "Tabs", theme->get_icon("GuiScrollArrowLeftHl", "EditorIcons"));
  751. theme->set_icon("increment_highlight", "TabContainer", theme->get_icon("GuiScrollArrowRightHl", "EditorIcons"));
  752. theme->set_icon("decrement_highlight", "TabContainer", theme->get_icon("GuiScrollArrowLeftHl", "EditorIcons"));
  753. theme->set_constant("hseparation", "Tabs", 4 * EDSCALE);
  754. // Content of each tab
  755. Ref<StyleBoxFlat> style_content_panel = style_default->duplicate();
  756. style_content_panel->set_border_color(dark_color_3);
  757. style_content_panel->set_border_width_all(border_width);
  758. // compensate the border
  759. style_content_panel->set_default_margin(MARGIN_TOP, margin_size_extra * EDSCALE);
  760. style_content_panel->set_default_margin(MARGIN_RIGHT, margin_size_extra * EDSCALE);
  761. style_content_panel->set_default_margin(MARGIN_BOTTOM, margin_size_extra * EDSCALE);
  762. style_content_panel->set_default_margin(MARGIN_LEFT, margin_size_extra * EDSCALE);
  763. // this is the stylebox used in 3d and 2d viewports (no borders)
  764. Ref<StyleBoxFlat> style_content_panel_vp = style_content_panel->duplicate();
  765. style_content_panel_vp->set_default_margin(MARGIN_LEFT, border_width * 2);
  766. style_content_panel_vp->set_default_margin(MARGIN_TOP, default_margin_size * EDSCALE);
  767. style_content_panel_vp->set_default_margin(MARGIN_RIGHT, border_width * 2);
  768. style_content_panel_vp->set_default_margin(MARGIN_BOTTOM, border_width * 2);
  769. theme->set_stylebox("panel", "TabContainer", style_content_panel);
  770. theme->set_stylebox("Content", "EditorStyles", style_content_panel_vp);
  771. // Separators
  772. theme->set_stylebox("separator", "HSeparator", make_line_stylebox(separator_color, border_width));
  773. theme->set_stylebox("separator", "VSeparator", make_line_stylebox(separator_color, border_width, 0, 0, true));
  774. // Debugger
  775. Ref<StyleBoxFlat> style_panel_debugger = style_content_panel->duplicate();
  776. style_panel_debugger->set_border_width(MARGIN_BOTTOM, 0);
  777. theme->set_stylebox("DebuggerPanel", "EditorStyles", style_panel_debugger);
  778. theme->set_stylebox("DebuggerTabFG", "EditorStyles", style_tab_selected);
  779. theme->set_stylebox("DebuggerTabBG", "EditorStyles", style_tab_unselected);
  780. Ref<StyleBoxFlat> style_panel_invisible_top = style_content_panel->duplicate();
  781. int stylebox_offset = theme->get_font("tab_fg", "TabContainer")->get_height() + theme->get_stylebox("tab_fg", "TabContainer")->get_minimum_size().height + theme->get_stylebox("panel", "TabContainer")->get_default_margin(MARGIN_TOP);
  782. style_panel_invisible_top->set_expand_margin_size(MARGIN_TOP, -stylebox_offset);
  783. style_panel_invisible_top->set_default_margin(MARGIN_TOP, 0);
  784. theme->set_stylebox("BottomPanelDebuggerOverride", "EditorStyles", style_panel_invisible_top);
  785. // LineEdit
  786. theme->set_stylebox("normal", "LineEdit", style_widget);
  787. theme->set_stylebox("focus", "LineEdit", style_widget_focus);
  788. theme->set_stylebox("read_only", "LineEdit", style_widget_disabled);
  789. theme->set_icon("clear", "LineEdit", theme->get_icon("GuiClose", "EditorIcons"));
  790. theme->set_color("read_only", "LineEdit", font_color_disabled);
  791. theme->set_color("font_color", "LineEdit", font_color);
  792. theme->set_color("font_color_selected", "LineEdit", mono_color);
  793. theme->set_color("cursor_color", "LineEdit", font_color);
  794. theme->set_color("selection_color", "LineEdit", font_color_selection);
  795. theme->set_color("clear_button_color", "LineEdit", font_color);
  796. theme->set_color("clear_button_color_pressed", "LineEdit", accent_color);
  797. // TextEdit
  798. theme->set_stylebox("normal", "TextEdit", style_widget);
  799. theme->set_stylebox("focus", "TextEdit", style_widget_hover);
  800. theme->set_stylebox("read_only", "TextEdit", style_widget_disabled);
  801. theme->set_constant("side_margin", "TabContainer", 0);
  802. theme->set_icon("tab", "TextEdit", theme->get_icon("GuiTab", "EditorIcons"));
  803. theme->set_icon("space", "TextEdit", theme->get_icon("GuiSpace", "EditorIcons"));
  804. theme->set_icon("folded", "TextEdit", theme->get_icon("GuiTreeArrowRight", "EditorIcons"));
  805. theme->set_icon("fold", "TextEdit", theme->get_icon("GuiTreeArrowDown", "EditorIcons"));
  806. theme->set_color("font_color", "TextEdit", font_color);
  807. theme->set_color("caret_color", "TextEdit", font_color);
  808. theme->set_color("selection_color", "TextEdit", font_color_selection);
  809. // H/VSplitContainer
  810. theme->set_stylebox("bg", "VSplitContainer", make_stylebox(theme->get_icon("GuiVsplitBg", "EditorIcons"), 1, 1, 1, 1));
  811. theme->set_stylebox("bg", "HSplitContainer", make_stylebox(theme->get_icon("GuiHsplitBg", "EditorIcons"), 1, 1, 1, 1));
  812. theme->set_icon("grabber", "VSplitContainer", theme->get_icon("GuiVsplitter", "EditorIcons"));
  813. theme->set_icon("grabber", "HSplitContainer", theme->get_icon("GuiHsplitter", "EditorIcons"));
  814. theme->set_constant("separation", "HSplitContainer", default_margin_size * 2 * EDSCALE);
  815. theme->set_constant("separation", "VSplitContainer", default_margin_size * 2 * EDSCALE);
  816. // Containers
  817. theme->set_constant("separation", "BoxContainer", default_margin_size * EDSCALE);
  818. theme->set_constant("separation", "HBoxContainer", default_margin_size * EDSCALE);
  819. theme->set_constant("separation", "VBoxContainer", default_margin_size * EDSCALE);
  820. theme->set_constant("margin_left", "MarginContainer", 0);
  821. theme->set_constant("margin_top", "MarginContainer", 0);
  822. theme->set_constant("margin_right", "MarginContainer", 0);
  823. theme->set_constant("margin_bottom", "MarginContainer", 0);
  824. theme->set_constant("hseparation", "GridContainer", default_margin_size * EDSCALE);
  825. theme->set_constant("vseparation", "GridContainer", default_margin_size * EDSCALE);
  826. // WindowDialog
  827. Ref<StyleBoxFlat> style_window = style_popup->duplicate();
  828. style_window->set_border_color(tab_color);
  829. style_window->set_border_width(MARGIN_TOP, 24 * EDSCALE);
  830. style_window->set_expand_margin_size(MARGIN_TOP, 24 * EDSCALE);
  831. theme->set_stylebox("panel", "WindowDialog", style_window);
  832. theme->set_color("title_color", "WindowDialog", font_color);
  833. theme->set_icon("close", "WindowDialog", theme->get_icon("GuiClose", "EditorIcons"));
  834. theme->set_icon("close_highlight", "WindowDialog", theme->get_icon("GuiClose", "EditorIcons"));
  835. theme->set_constant("close_h_ofs", "WindowDialog", 22 * EDSCALE);
  836. theme->set_constant("close_v_ofs", "WindowDialog", 20 * EDSCALE);
  837. theme->set_constant("title_height", "WindowDialog", 24 * EDSCALE);
  838. theme->set_font("title_font", "WindowDialog", theme->get_font("title", "EditorFonts"));
  839. // complex window, for now only Editor settings and Project settings
  840. Ref<StyleBoxFlat> style_complex_window = style_window->duplicate();
  841. style_complex_window->set_bg_color(dark_color_2);
  842. style_complex_window->set_border_color(highlight_tabs ? tab_color : dark_color_2);
  843. theme->set_stylebox("panel", "EditorSettingsDialog", style_complex_window);
  844. theme->set_stylebox("panel", "ProjectSettingsEditor", style_complex_window);
  845. theme->set_stylebox("panel", "EditorAbout", style_complex_window);
  846. // HScrollBar
  847. Ref<Texture> empty_icon = memnew(ImageTexture);
  848. theme->set_stylebox("scroll", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  849. theme->set_stylebox("scroll_focus", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  850. theme->set_stylebox("grabber", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabber", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  851. theme->set_stylebox("grabber_highlight", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberHl", "EditorIcons"), 5, 5, 5, 5, 2, 2, 2, 2));
  852. theme->set_stylebox("grabber_pressed", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberPressed", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  853. theme->set_icon("increment", "HScrollBar", empty_icon);
  854. theme->set_icon("increment_highlight", "HScrollBar", empty_icon);
  855. theme->set_icon("decrement", "HScrollBar", empty_icon);
  856. theme->set_icon("decrement_highlight", "HScrollBar", empty_icon);
  857. // VScrollBar
  858. theme->set_stylebox("scroll", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  859. theme->set_stylebox("scroll_focus", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
  860. theme->set_stylebox("grabber", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabber", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  861. theme->set_stylebox("grabber_highlight", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberHl", "EditorIcons"), 5, 5, 5, 5, 2, 2, 2, 2));
  862. theme->set_stylebox("grabber_pressed", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberPressed", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2));
  863. theme->set_icon("increment", "VScrollBar", empty_icon);
  864. theme->set_icon("increment_highlight", "VScrollBar", empty_icon);
  865. theme->set_icon("decrement", "VScrollBar", empty_icon);
  866. theme->set_icon("decrement_highlight", "VScrollBar", empty_icon);
  867. // HSlider
  868. theme->set_icon("grabber_highlight", "HSlider", theme->get_icon("GuiSliderGrabberHl", "EditorIcons"));
  869. theme->set_icon("grabber", "HSlider", theme->get_icon("GuiSliderGrabber", "EditorIcons"));
  870. theme->set_stylebox("slider", "HSlider", make_flat_stylebox(dark_color_3, 0, default_margin_size / 2, 0, default_margin_size / 2));
  871. theme->set_stylebox("grabber_area", "HSlider", make_flat_stylebox(contrast_color_1, 0, default_margin_size / 2, 0, default_margin_size / 2));
  872. theme->set_stylebox("grabber_area_highlight", "HSlider", make_flat_stylebox(contrast_color_1, 0, default_margin_size / 2, 0, default_margin_size / 2));
  873. // VSlider
  874. theme->set_icon("grabber", "VSlider", theme->get_icon("GuiSliderGrabber", "EditorIcons"));
  875. theme->set_icon("grabber_highlight", "VSlider", theme->get_icon("GuiSliderGrabberHl", "EditorIcons"));
  876. theme->set_stylebox("slider", "VSlider", make_flat_stylebox(dark_color_3, default_margin_size / 2, 0, default_margin_size / 2, 0));
  877. theme->set_stylebox("grabber_area", "VSlider", make_flat_stylebox(contrast_color_1, default_margin_size / 2, 0, default_margin_size / 2, 0));
  878. theme->set_stylebox("grabber_area_highlight", "VSlider", make_flat_stylebox(contrast_color_1, default_margin_size / 2, 0, default_margin_size / 2, 0));
  879. //RichTextLabel
  880. theme->set_color("default_color", "RichTextLabel", font_color);
  881. theme->set_color("font_color_shadow", "RichTextLabel", Color(0, 0, 0, 0));
  882. theme->set_constant("shadow_offset_x", "RichTextLabel", 1 * EDSCALE);
  883. theme->set_constant("shadow_offset_y", "RichTextLabel", 1 * EDSCALE);
  884. theme->set_constant("shadow_as_outline", "RichTextLabel", 0 * EDSCALE);
  885. theme->set_stylebox("focus", "RichTextLabel", make_empty_stylebox());
  886. theme->set_stylebox("normal", "RichTextLabel", style_tree_bg);
  887. theme->set_color("headline_color", "EditorHelp", mono_color);
  888. // Panel
  889. theme->set_stylebox("panel", "Panel", make_flat_stylebox(dark_color_1, 6, 4, 6, 4));
  890. // Label
  891. theme->set_stylebox("normal", "Label", style_empty);
  892. theme->set_color("font_color", "Label", font_color);
  893. theme->set_color("font_color_shadow", "Label", Color(0, 0, 0, 0));
  894. theme->set_constant("shadow_offset_x", "Label", 1 * EDSCALE);
  895. theme->set_constant("shadow_offset_y", "Label", 1 * EDSCALE);
  896. theme->set_constant("shadow_as_outline", "Label", 0 * EDSCALE);
  897. theme->set_constant("line_spacing", "Label", 3 * EDSCALE);
  898. // LinkButton
  899. theme->set_stylebox("focus", "LinkButton", style_empty);
  900. theme->set_color("font_color", "LinkButton", font_color);
  901. theme->set_color("font_color_hover", "LinkButton", font_color_hl);
  902. theme->set_color("font_color_pressed", "LinkButton", accent_color);
  903. theme->set_color("font_color_disabled", "LinkButton", font_color_disabled);
  904. // TooltipPanel
  905. Ref<StyleBoxFlat> style_tooltip = style_popup->duplicate();
  906. float v = MAX(border_size * EDSCALE, 1.0);
  907. style_tooltip->set_default_margin(MARGIN_LEFT, v);
  908. style_tooltip->set_default_margin(MARGIN_TOP, v);
  909. style_tooltip->set_default_margin(MARGIN_RIGHT, v);
  910. style_tooltip->set_default_margin(MARGIN_BOTTOM, v);
  911. style_tooltip->set_bg_color(Color(mono_color.r, mono_color.g, mono_color.b, 0.9));
  912. style_tooltip->set_border_width_all(border_width);
  913. style_tooltip->set_border_color(mono_color);
  914. theme->set_color("font_color", "TooltipLabel", font_color.inverted());
  915. theme->set_color("font_color_shadow", "TooltipLabel", mono_color.inverted() * Color(1, 1, 1, 0.1));
  916. theme->set_stylebox("panel", "TooltipPanel", style_tooltip);
  917. // PopupPanel
  918. theme->set_stylebox("panel", "PopupPanel", style_popup);
  919. // SpinBox
  920. theme->set_icon("updown", "SpinBox", theme->get_icon("GuiSpinboxUpdown", "EditorIcons"));
  921. // ProgressBar
  922. theme->set_stylebox("bg", "ProgressBar", make_stylebox(theme->get_icon("GuiProgressBar", "EditorIcons"), 4, 4, 4, 4, 0, 0, 0, 0));
  923. theme->set_stylebox("fg", "ProgressBar", make_stylebox(theme->get_icon("GuiProgressFill", "EditorIcons"), 6, 6, 6, 6, 2, 1, 2, 1));
  924. theme->set_color("font_color", "ProgressBar", font_color);
  925. // GraphEdit
  926. theme->set_stylebox("bg", "GraphEdit", style_tree_bg);
  927. if (dark_theme) {
  928. theme->set_color("grid_major", "GraphEdit", Color(1.0, 1.0, 1.0, 0.15));
  929. theme->set_color("grid_minor", "GraphEdit", Color(1.0, 1.0, 1.0, 0.07));
  930. } else {
  931. theme->set_color("grid_major", "GraphEdit", Color(0.0, 0.0, 0.0, 0.15));
  932. theme->set_color("grid_minor", "GraphEdit", Color(0.0, 0.0, 0.0, 0.07));
  933. }
  934. theme->set_color("selection_fill", "GraphEdit", theme->get_color("box_selection_fill_color", "Editor"));
  935. theme->set_color("selection_stroke", "GraphEdit", theme->get_color("box_selection_stroke_color", "Editor"));
  936. theme->set_color("activity", "GraphEdit", accent_color);
  937. theme->set_icon("minus", "GraphEdit", theme->get_icon("ZoomLess", "EditorIcons"));
  938. theme->set_icon("more", "GraphEdit", theme->get_icon("ZoomMore", "EditorIcons"));
  939. theme->set_icon("reset", "GraphEdit", theme->get_icon("ZoomReset", "EditorIcons"));
  940. theme->set_icon("snap", "GraphEdit", theme->get_icon("SnapGrid", "EditorIcons"));
  941. theme->set_icon("minimap", "GraphEdit", theme->get_icon("GridMinimap", "EditorIcons"));
  942. theme->set_constant("bezier_len_pos", "GraphEdit", 80 * EDSCALE);
  943. theme->set_constant("bezier_len_neg", "GraphEdit", 160 * EDSCALE);
  944. // GraphEditMinimap
  945. Ref<StyleBoxFlat> style_minimap_bg = make_flat_stylebox(dark_color_1, 0, 0, 0, 0);
  946. style_minimap_bg->set_border_color(dark_color_3);
  947. style_minimap_bg->set_border_width_all(1);
  948. theme->set_stylebox("bg", "GraphEditMinimap", style_minimap_bg);
  949. Ref<StyleBoxFlat> style_minimap_camera;
  950. Ref<StyleBoxFlat> style_minimap_node;
  951. if (dark_theme) {
  952. style_minimap_camera = make_flat_stylebox(Color(0.65, 0.65, 0.65, 0.2), 0, 0, 0, 0);
  953. style_minimap_camera->set_border_color(Color(0.65, 0.65, 0.65, 0.45));
  954. style_minimap_node = make_flat_stylebox(Color(1, 1, 1), 0, 0, 0, 0);
  955. } else {
  956. style_minimap_camera = make_flat_stylebox(Color(0.38, 0.38, 0.38, 0.2), 0, 0, 0, 0);
  957. style_minimap_camera->set_border_color(Color(0.38, 0.38, 0.38, 0.45));
  958. style_minimap_node = make_flat_stylebox(Color(0, 0, 0), 0, 0, 0, 0);
  959. }
  960. style_minimap_camera->set_border_width_all(1);
  961. style_minimap_node->set_corner_radius_all(1);
  962. theme->set_stylebox("camera", "GraphEditMinimap", style_minimap_camera);
  963. theme->set_stylebox("node", "GraphEditMinimap", style_minimap_node);
  964. Ref<Texture> minimap_resizer_icon = theme->get_icon("GuiResizer", "EditorIcons");
  965. Color minimap_resizer_color;
  966. if (dark_theme) {
  967. minimap_resizer_color = Color(1, 1, 1, 0.65);
  968. } else {
  969. minimap_resizer_color = Color(0, 0, 0, 0.65);
  970. }
  971. theme->set_icon("resizer", "GraphEditMinimap", flip_icon(minimap_resizer_icon, true, true));
  972. theme->set_color("resizer_color", "GraphEditMinimap", minimap_resizer_color);
  973. // GraphNode
  974. const float mv = dark_theme ? 0.0 : 1.0;
  975. const float mv2 = 1.0 - mv;
  976. const int gn_margin_side = 28;
  977. Ref<StyleBoxFlat> graphsb = make_flat_stylebox(Color(mv, mv, mv, 0.7), gn_margin_side, 24, gn_margin_side, 5);
  978. graphsb->set_border_width_all(border_width);
  979. graphsb->set_border_color(Color(mv2, mv2, mv2, 0.9));
  980. Ref<StyleBoxFlat> graphsbselected = make_flat_stylebox(Color(mv, mv, mv, 0.9), gn_margin_side, 24, gn_margin_side, 5);
  981. graphsbselected->set_border_width_all(border_width);
  982. graphsbselected->set_border_color(Color(accent_color.r, accent_color.g, accent_color.b, 0.9));
  983. graphsbselected->set_shadow_size(8 * EDSCALE);
  984. graphsbselected->set_shadow_color(shadow_color);
  985. Ref<StyleBoxFlat> graphsbcomment = make_flat_stylebox(Color(mv, mv, mv, 0.3), gn_margin_side, 24, gn_margin_side, 5);
  986. graphsbcomment->set_border_width_all(border_width);
  987. graphsbcomment->set_border_color(Color(mv2, mv2, mv2, 0.9));
  988. Ref<StyleBoxFlat> graphsbcommentselected = make_flat_stylebox(Color(mv, mv, mv, 0.4), gn_margin_side, 24, gn_margin_side, 5);
  989. graphsbcommentselected->set_border_width_all(border_width);
  990. graphsbcommentselected->set_border_color(Color(mv2, mv2, mv2, 0.9));
  991. Ref<StyleBoxFlat> graphsbbreakpoint = graphsbselected->duplicate();
  992. graphsbbreakpoint->set_draw_center(false);
  993. graphsbbreakpoint->set_border_color(warning_color);
  994. graphsbbreakpoint->set_shadow_color(warning_color * Color(1.0, 1.0, 1.0, 0.1));
  995. Ref<StyleBoxFlat> graphsbposition = graphsbselected->duplicate();
  996. graphsbposition->set_draw_center(false);
  997. graphsbposition->set_border_color(error_color);
  998. graphsbposition->set_shadow_color(error_color * Color(1.0, 1.0, 1.0, 0.2));
  999. Ref<StyleBoxFlat> smgraphsb = make_flat_stylebox(Color(mv, mv, mv, 0.7), gn_margin_side, 24, gn_margin_side, 5);
  1000. smgraphsb->set_border_width_all(border_width);
  1001. smgraphsb->set_border_color(Color(mv2, mv2, mv2, 0.9));
  1002. Ref<StyleBoxFlat> smgraphsbselected = make_flat_stylebox(Color(mv, mv, mv, 0.9), gn_margin_side, 24, gn_margin_side, 5);
  1003. smgraphsbselected->set_border_width_all(border_width);
  1004. smgraphsbselected->set_border_color(Color(accent_color.r, accent_color.g, accent_color.b, 0.9));
  1005. smgraphsbselected->set_shadow_size(8 * EDSCALE);
  1006. smgraphsbselected->set_shadow_color(shadow_color);
  1007. if (use_gn_headers) {
  1008. graphsb->set_border_width(MARGIN_TOP, 24 * EDSCALE);
  1009. graphsbselected->set_border_width(MARGIN_TOP, 24 * EDSCALE);
  1010. graphsbcomment->set_border_width(MARGIN_TOP, 24 * EDSCALE);
  1011. graphsbcommentselected->set_border_width(MARGIN_TOP, 24 * EDSCALE);
  1012. }
  1013. theme->set_stylebox("frame", "GraphNode", graphsb);
  1014. theme->set_stylebox("selectedframe", "GraphNode", graphsbselected);
  1015. theme->set_stylebox("comment", "GraphNode", graphsbcomment);
  1016. theme->set_stylebox("commentfocus", "GraphNode", graphsbcommentselected);
  1017. theme->set_stylebox("breakpoint", "GraphNode", graphsbbreakpoint);
  1018. theme->set_stylebox("position", "GraphNode", graphsbposition);
  1019. theme->set_stylebox("state_machine_frame", "GraphNode", smgraphsb);
  1020. theme->set_stylebox("state_machine_selectedframe", "GraphNode", smgraphsbselected);
  1021. Color default_node_color = Color(mv2, mv2, mv2);
  1022. theme->set_color("title_color", "GraphNode", default_node_color);
  1023. default_node_color.a = 0.7;
  1024. theme->set_color("close_color", "GraphNode", default_node_color);
  1025. theme->set_color("resizer_color", "GraphNode", default_node_color);
  1026. theme->set_constant("port_offset", "GraphNode", 14 * EDSCALE);
  1027. theme->set_constant("title_h_offset", "GraphNode", -16 * EDSCALE);
  1028. theme->set_constant("title_offset", "GraphNode", 20 * EDSCALE);
  1029. theme->set_constant("close_h_offset", "GraphNode", 20 * EDSCALE);
  1030. theme->set_constant("close_offset", "GraphNode", 20 * EDSCALE);
  1031. theme->set_constant("separation", "GraphNode", 1 * EDSCALE);
  1032. theme->set_icon("close", "GraphNode", theme->get_icon("GuiCloseCustomizable", "EditorIcons"));
  1033. theme->set_icon("resizer", "GraphNode", theme->get_icon("GuiResizer", "EditorIcons"));
  1034. theme->set_icon("port", "GraphNode", theme->get_icon("GuiGraphNodePort", "EditorIcons"));
  1035. // GridContainer
  1036. theme->set_constant("vseparation", "GridContainer", (extra_spacing + default_margin_size) * EDSCALE);
  1037. // FileDialog
  1038. theme->set_icon("folder", "FileDialog", theme->get_icon("Folder", "EditorIcons"));
  1039. theme->set_icon("parent_folder", "FileDialog", theme->get_icon("ArrowUp", "EditorIcons"));
  1040. theme->set_icon("reload", "FileDialog", theme->get_icon("Reload", "EditorIcons"));
  1041. theme->set_icon("toggle_hidden", "FileDialog", theme->get_icon("GuiVisibilityVisible", "EditorIcons"));
  1042. // Use a different color for folder icons to make them easier to distinguish from files.
  1043. // On a light theme, the icon will be dark, so we need to lighten it before blending it with the accent color.
  1044. theme->set_color("folder_icon_modulate", "FileDialog", (dark_theme ? Color(1, 1, 1) : Color(4.25, 4.25, 4.25)).linear_interpolate(accent_color, 0.7));
  1045. theme->set_color("files_disabled", "FileDialog", font_color_disabled);
  1046. // color picker
  1047. theme->set_constant("margin", "ColorPicker", popup_margin_size);
  1048. theme->set_constant("sv_width", "ColorPicker", 256 * EDSCALE);
  1049. theme->set_constant("sv_height", "ColorPicker", 256 * EDSCALE);
  1050. theme->set_constant("h_width", "ColorPicker", 30 * EDSCALE);
  1051. theme->set_constant("label_width", "ColorPicker", 10 * EDSCALE);
  1052. theme->set_icon("screen_picker", "ColorPicker", theme->get_icon("ColorPick", "EditorIcons"));
  1053. theme->set_icon("add_preset", "ColorPicker", theme->get_icon("Add", "EditorIcons"));
  1054. theme->set_icon("preset_bg", "ColorPicker", theme->get_icon("GuiMiniCheckerboard", "EditorIcons"));
  1055. theme->set_icon("overbright_indicator", "ColorPicker", theme->get_icon("OverbrightIndicator", "EditorIcons"));
  1056. theme->set_icon("bg", "ColorPickerButton", theme->get_icon("GuiMiniCheckerboard", "EditorIcons"));
  1057. // Information on 3D viewport
  1058. Ref<StyleBoxFlat> style_info_3d_viewport = style_default->duplicate();
  1059. style_info_3d_viewport->set_bg_color(style_info_3d_viewport->get_bg_color() * Color(1, 1, 1, 0.5));
  1060. style_info_3d_viewport->set_border_width_all(0);
  1061. theme->set_stylebox("Information3dViewport", "EditorStyles", style_info_3d_viewport);
  1062. // adaptive script theme constants
  1063. // for comments and elements with lower relevance
  1064. const Color dim_color = Color(font_color.r, font_color.g, font_color.b, 0.5);
  1065. const float mono_value = mono_color.r;
  1066. const Color alpha1 = Color(mono_value, mono_value, mono_value, 0.07);
  1067. const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.14);
  1068. const Color alpha3 = Color(mono_value, mono_value, mono_value, 0.7);
  1069. // editor main color
  1070. const Color main_color = dark_theme ? Color(0.34, 0.7, 1.0) : Color(0.02, 0.5, 1.0);
  1071. const Color symbol_color = Color(0.34, 0.57, 1.0).linear_interpolate(mono_color, dark_theme ? 0.5 : 0.3);
  1072. const Color keyword_color = Color(1.0, 0.44, 0.52);
  1073. const Color basetype_color = dark_theme ? Color(0.26, 1.0, 0.76) : Color(0.0, 0.76, 0.38);
  1074. const Color type_color = basetype_color.linear_interpolate(mono_color, dark_theme ? 0.4 : 0.3);
  1075. const Color usertype_color = basetype_color.linear_interpolate(mono_color, dark_theme ? 0.7 : 0.5);
  1076. const Color comment_color = dim_color;
  1077. const Color string_color = (dark_theme ? Color(1.0, 0.85, 0.26) : Color(1.0, 0.82, 0.09)).linear_interpolate(mono_color, dark_theme ? 0.5 : 0.3);
  1078. const Color te_background_color = dark_theme ? background_color : base_color;
  1079. const Color completion_background_color = dark_theme ? base_color : background_color;
  1080. const Color completion_selected_color = alpha1;
  1081. const Color completion_existing_color = alpha2;
  1082. const Color completion_scroll_color = alpha1;
  1083. const Color completion_font_color = font_color;
  1084. const Color text_color = font_color;
  1085. const Color line_number_color = dim_color;
  1086. const Color safe_line_number_color = dim_color * Color(1, 1.2, 1, 1.5);
  1087. const Color caret_color = mono_color;
  1088. const Color caret_background_color = mono_color.inverted();
  1089. const Color text_selected_color = dark_color_3;
  1090. const Color selection_color = accent_color * Color(1, 1, 1, 0.35);
  1091. const Color brace_mismatch_color = error_color;
  1092. const Color current_line_color = alpha1;
  1093. const Color line_length_guideline_color = dark_theme ? base_color : background_color;
  1094. const Color word_highlighted_color = alpha1;
  1095. const Color number_color = basetype_color.linear_interpolate(mono_color, dark_theme ? 0.5 : 0.3);
  1096. const Color function_color = main_color;
  1097. const Color member_variable_color = main_color.linear_interpolate(mono_color, 0.6);
  1098. const Color mark_color = Color(error_color.r, error_color.g, error_color.b, 0.3);
  1099. const Color bookmark_color = Color(0.08, 0.49, 0.98);
  1100. const Color breakpoint_color = error_color;
  1101. const Color executing_line_color = Color(0.2, 0.8, 0.2, 0.4);
  1102. const Color code_folding_color = alpha3;
  1103. const Color search_result_color = alpha1;
  1104. const Color search_result_border_color = Color(0.41, 0.61, 0.91, 0.38);
  1105. EditorSettings *setting = EditorSettings::get_singleton();
  1106. String text_editor_color_theme = setting->get("text_editor/theme/color_theme");
  1107. if (text_editor_color_theme == "Adaptive") {
  1108. setting->set_initial_value("text_editor/highlighting/symbol_color", symbol_color, true);
  1109. setting->set_initial_value("text_editor/highlighting/keyword_color", keyword_color, true);
  1110. setting->set_initial_value("text_editor/highlighting/base_type_color", basetype_color, true);
  1111. setting->set_initial_value("text_editor/highlighting/engine_type_color", type_color, true);
  1112. setting->set_initial_value("text_editor/highlighting/user_type_color", usertype_color, true);
  1113. setting->set_initial_value("text_editor/highlighting/comment_color", comment_color, true);
  1114. setting->set_initial_value("text_editor/highlighting/string_color", string_color, true);
  1115. setting->set_initial_value("text_editor/highlighting/background_color", te_background_color, true);
  1116. setting->set_initial_value("text_editor/highlighting/completion_background_color", completion_background_color, true);
  1117. setting->set_initial_value("text_editor/highlighting/completion_selected_color", completion_selected_color, true);
  1118. setting->set_initial_value("text_editor/highlighting/completion_existing_color", completion_existing_color, true);
  1119. setting->set_initial_value("text_editor/highlighting/completion_scroll_color", completion_scroll_color, true);
  1120. setting->set_initial_value("text_editor/highlighting/completion_font_color", completion_font_color, true);
  1121. setting->set_initial_value("text_editor/highlighting/text_color", text_color, true);
  1122. setting->set_initial_value("text_editor/highlighting/line_number_color", line_number_color, true);
  1123. setting->set_initial_value("text_editor/highlighting/safe_line_number_color", safe_line_number_color, true);
  1124. setting->set_initial_value("text_editor/highlighting/caret_color", caret_color, true);
  1125. setting->set_initial_value("text_editor/highlighting/caret_background_color", caret_background_color, true);
  1126. setting->set_initial_value("text_editor/highlighting/text_selected_color", text_selected_color, true);
  1127. setting->set_initial_value("text_editor/highlighting/selection_color", selection_color, true);
  1128. setting->set_initial_value("text_editor/highlighting/brace_mismatch_color", brace_mismatch_color, true);
  1129. setting->set_initial_value("text_editor/highlighting/current_line_color", current_line_color, true);
  1130. setting->set_initial_value("text_editor/highlighting/line_length_guideline_color", line_length_guideline_color, true);
  1131. setting->set_initial_value("text_editor/highlighting/word_highlighted_color", word_highlighted_color, true);
  1132. setting->set_initial_value("text_editor/highlighting/number_color", number_color, true);
  1133. setting->set_initial_value("text_editor/highlighting/function_color", function_color, true);
  1134. setting->set_initial_value("text_editor/highlighting/member_variable_color", member_variable_color, true);
  1135. setting->set_initial_value("text_editor/highlighting/mark_color", mark_color, true);
  1136. setting->set_initial_value("text_editor/highlighting/bookmark_color", bookmark_color, true);
  1137. setting->set_initial_value("text_editor/highlighting/breakpoint_color", breakpoint_color, true);
  1138. setting->set_initial_value("text_editor/highlighting/executing_line_color", executing_line_color, true);
  1139. setting->set_initial_value("text_editor/highlighting/code_folding_color", code_folding_color, true);
  1140. setting->set_initial_value("text_editor/highlighting/search_result_color", search_result_color, true);
  1141. setting->set_initial_value("text_editor/highlighting/search_result_border_color", search_result_border_color, true);
  1142. } else if (text_editor_color_theme == "Default") {
  1143. setting->load_text_editor_theme();
  1144. }
  1145. return theme;
  1146. }
  1147. Ref<Theme> create_custom_theme(const Ref<Theme> p_theme) {
  1148. Ref<Theme> theme;
  1149. const String custom_theme = EditorSettings::get_singleton()->get("interface/theme/custom_theme");
  1150. if (custom_theme != "") {
  1151. theme = ResourceLoader::load(custom_theme);
  1152. }
  1153. if (!theme.is_valid()) {
  1154. theme = create_editor_theme(p_theme);
  1155. }
  1156. return theme;
  1157. }
  1158. Ref<ImageTexture> create_unscaled_default_project_icon() {
  1159. #ifdef SVG_ENABLED
  1160. for (int i = 0; i < editor_icons_count; i++) {
  1161. // ESCALE should never affect size of the icon
  1162. if (strcmp(editor_icons_names[i], "DefaultProjectIcon") == 0) {
  1163. return editor_generate_icon(i, false, 1.0);
  1164. }
  1165. }
  1166. #endif
  1167. return Ref<ImageTexture>(memnew(ImageTexture));
  1168. }