theme.cpp 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737
  1. /**************************************************************************/
  2. /* theme.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "theme.h"
  31. #include "core/print_string.h"
  32. // Universal Theme resources used when no other theme has the item.
  33. Ref<Theme> Theme::default_theme;
  34. Ref<Theme> Theme::project_default_theme;
  35. // Universal default values, final fallback for every theme.
  36. Ref<Texture> Theme::default_icon;
  37. Ref<StyleBox> Theme::default_style;
  38. Ref<Font> Theme::default_font;
  39. // Dynamic properties.
  40. bool Theme::_set(const StringName &p_name, const Variant &p_value) {
  41. String sname = p_name;
  42. if (sname.find("/") != -1) {
  43. String type = sname.get_slicec('/', 1);
  44. String theme_type = sname.get_slicec('/', 0);
  45. String name = sname.get_slicec('/', 2);
  46. if (type == "icons") {
  47. set_icon(name, theme_type, p_value);
  48. } else if (type == "styles") {
  49. set_stylebox(name, theme_type, p_value);
  50. } else if (type == "fonts") {
  51. set_font(name, theme_type, p_value);
  52. } else if (type == "colors") {
  53. set_color(name, theme_type, p_value);
  54. } else if (type == "constants") {
  55. set_constant(name, theme_type, p_value);
  56. } else if (type == "base_type") {
  57. set_type_variation(theme_type, p_value);
  58. } else {
  59. return false;
  60. }
  61. return true;
  62. }
  63. return false;
  64. }
  65. bool Theme::_get(const StringName &p_name, Variant &r_ret) const {
  66. String sname = p_name;
  67. if (sname.find("/") != -1) {
  68. String type = sname.get_slicec('/', 1);
  69. String theme_type = sname.get_slicec('/', 0);
  70. String name = sname.get_slicec('/', 2);
  71. if (type == "icons") {
  72. if (!has_icon(name, theme_type)) {
  73. r_ret = Ref<Texture>();
  74. } else {
  75. r_ret = get_icon(name, theme_type);
  76. }
  77. } else if (type == "styles") {
  78. if (!has_stylebox(name, theme_type)) {
  79. r_ret = Ref<StyleBox>();
  80. } else {
  81. r_ret = get_stylebox(name, theme_type);
  82. }
  83. } else if (type == "fonts") {
  84. if (!has_font(name, theme_type)) {
  85. r_ret = Ref<Font>();
  86. } else {
  87. r_ret = get_font(name, theme_type);
  88. }
  89. } else if (type == "colors") {
  90. r_ret = get_color(name, theme_type);
  91. } else if (type == "constants") {
  92. r_ret = get_constant(name, theme_type);
  93. } else if (type == "base_type") {
  94. r_ret = get_type_variation_base(theme_type);
  95. } else {
  96. return false;
  97. }
  98. return true;
  99. }
  100. return false;
  101. }
  102. void Theme::_get_property_list(List<PropertyInfo> *p_list) const {
  103. List<PropertyInfo> list;
  104. const StringName *key = nullptr;
  105. // Type variations.
  106. while ((key = variation_map.next(key))) {
  107. list.push_back(PropertyInfo(Variant::STRING, String() + *key + "/base_type"));
  108. }
  109. key = nullptr;
  110. // Icons.
  111. while ((key = icon_map.next(key))) {
  112. const StringName *key2 = nullptr;
  113. while ((key2 = icon_map[*key].next(key2))) {
  114. list.push_back(PropertyInfo(Variant::OBJECT, String() + *key + "/icons/" + *key2, PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL));
  115. }
  116. }
  117. key = nullptr;
  118. // Styles.
  119. while ((key = style_map.next(key))) {
  120. const StringName *key2 = nullptr;
  121. while ((key2 = style_map[*key].next(key2))) {
  122. list.push_back(PropertyInfo(Variant::OBJECT, String() + *key + "/styles/" + *key2, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL));
  123. }
  124. }
  125. key = nullptr;
  126. // Fonts.
  127. while ((key = font_map.next(key))) {
  128. const StringName *key2 = nullptr;
  129. while ((key2 = font_map[*key].next(key2))) {
  130. list.push_back(PropertyInfo(Variant::OBJECT, String() + *key + "/fonts/" + *key2, PROPERTY_HINT_RESOURCE_TYPE, "Font", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL));
  131. }
  132. }
  133. key = nullptr;
  134. // Colors.
  135. while ((key = color_map.next(key))) {
  136. const StringName *key2 = nullptr;
  137. while ((key2 = color_map[*key].next(key2))) {
  138. list.push_back(PropertyInfo(Variant::COLOR, String() + *key + "/colors/" + *key2));
  139. }
  140. }
  141. key = nullptr;
  142. // Constants.
  143. while ((key = constant_map.next(key))) {
  144. const StringName *key2 = nullptr;
  145. while ((key2 = constant_map[*key].next(key2))) {
  146. list.push_back(PropertyInfo(Variant::INT, String() + *key + "/constants/" + *key2));
  147. }
  148. }
  149. list.sort();
  150. String prev_type;
  151. for (List<PropertyInfo>::Element *E = list.front(); E; E = E->next()) {
  152. // Add groups for types so that their names are left unchanged in the inspector.
  153. String current_type = E->get().name.get_slice("/", 0);
  154. if (prev_type != current_type) {
  155. p_list->push_back(PropertyInfo(Variant::NIL, current_type, PROPERTY_HINT_NONE, current_type + "/", PROPERTY_USAGE_GROUP));
  156. prev_type = current_type;
  157. }
  158. p_list->push_back(E->get());
  159. }
  160. }
  161. // Universal fallback Theme resources.
  162. Ref<Theme> Theme::get_default() {
  163. return default_theme;
  164. }
  165. void Theme::set_default(const Ref<Theme> &p_default) {
  166. default_theme = p_default;
  167. }
  168. Ref<Theme> Theme::get_project_default() {
  169. return project_default_theme;
  170. }
  171. void Theme::set_project_default(const Ref<Theme> &p_project_default) {
  172. project_default_theme = p_project_default;
  173. }
  174. // Universal fallback values for theme item types.
  175. void Theme::set_default_icon(const Ref<Texture> &p_icon) {
  176. default_icon = p_icon;
  177. }
  178. void Theme::set_default_style(const Ref<StyleBox> &p_style) {
  179. default_style = p_style;
  180. }
  181. void Theme::set_default_font(const Ref<Font> &p_font) {
  182. default_font = p_font;
  183. }
  184. bool Theme::is_valid_type_name(const String &p_name) {
  185. for (int i = 0; i < p_name.length(); i++) {
  186. const CharType c = p_name[i];
  187. if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_')) {
  188. return false;
  189. }
  190. }
  191. return true;
  192. }
  193. bool Theme::is_valid_item_name(const String &p_name) {
  194. if (p_name.empty()) {
  195. return false;
  196. }
  197. for (int i = 0; i < p_name.length(); i++) {
  198. const CharType c = p_name[i];
  199. if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_')) {
  200. return false;
  201. }
  202. }
  203. return true;
  204. }
  205. // Fallback values for theme item types, configurable per theme.
  206. void Theme::set_default_theme_font(const Ref<Font> &p_default_font) {
  207. if (default_theme_font == p_default_font) {
  208. return;
  209. }
  210. if (default_theme_font.is_valid()) {
  211. default_theme_font->disconnect("changed", this, "_emit_theme_changed");
  212. }
  213. default_theme_font = p_default_font;
  214. if (default_theme_font.is_valid()) {
  215. default_theme_font->connect("changed", this, "_emit_theme_changed", varray(), CONNECT_REFERENCE_COUNTED);
  216. }
  217. _emit_theme_changed();
  218. }
  219. Ref<Font> Theme::get_default_theme_font() const {
  220. return default_theme_font;
  221. }
  222. bool Theme::has_default_theme_font() const {
  223. return default_theme_font.is_valid();
  224. }
  225. // Icons.
  226. void Theme::set_icon(const StringName &p_name, const StringName &p_theme_type, const Ref<Texture> &p_icon) {
  227. ERR_FAIL_COND_MSG(!is_valid_item_name(p_name), vformat("Invalid item name: '%s'", p_name));
  228. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  229. bool existing = false;
  230. if (icon_map[p_theme_type].has(p_name) && icon_map[p_theme_type][p_name].is_valid()) {
  231. existing = true;
  232. icon_map[p_theme_type][p_name]->disconnect("changed", this, "_emit_theme_changed");
  233. }
  234. icon_map[p_theme_type][p_name] = p_icon;
  235. if (p_icon.is_valid()) {
  236. icon_map[p_theme_type][p_name]->connect("changed", this, "_emit_theme_changed", varray(), CONNECT_REFERENCE_COUNTED);
  237. }
  238. _emit_theme_changed(!existing);
  239. }
  240. Ref<Texture> Theme::get_icon(const StringName &p_name, const StringName &p_theme_type) const {
  241. if (icon_map.has(p_theme_type) && icon_map[p_theme_type].has(p_name) && icon_map[p_theme_type][p_name].is_valid()) {
  242. return icon_map[p_theme_type][p_name];
  243. } else {
  244. return default_icon;
  245. }
  246. }
  247. bool Theme::has_icon(const StringName &p_name, const StringName &p_theme_type) const {
  248. return (icon_map.has(p_theme_type) && icon_map[p_theme_type].has(p_name) && icon_map[p_theme_type][p_name].is_valid());
  249. }
  250. bool Theme::has_icon_nocheck(const StringName &p_name, const StringName &p_theme_type) const {
  251. return (icon_map.has(p_theme_type) && icon_map[p_theme_type].has(p_name));
  252. }
  253. void Theme::rename_icon(const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type) {
  254. ERR_FAIL_COND_MSG(!is_valid_item_name(p_name), vformat("Invalid item name: '%s'", p_name));
  255. ERR_FAIL_COND_MSG(!icon_map.has(p_theme_type), "Cannot rename the icon '" + String(p_old_name) + "' because the node type '" + String(p_theme_type) + "' does not exist.");
  256. ERR_FAIL_COND_MSG(icon_map[p_theme_type].has(p_name), "Cannot rename the icon '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists.");
  257. ERR_FAIL_COND_MSG(!icon_map[p_theme_type].has(p_old_name), "Cannot rename the icon '" + String(p_old_name) + "' because it does not exist.");
  258. icon_map[p_theme_type][p_name] = icon_map[p_theme_type][p_old_name];
  259. icon_map[p_theme_type].erase(p_old_name);
  260. _emit_theme_changed(true);
  261. }
  262. void Theme::clear_icon(const StringName &p_name, const StringName &p_theme_type) {
  263. ERR_FAIL_COND_MSG(!icon_map.has(p_theme_type), "Cannot clear the icon '" + String(p_name) + "' because the node type '" + String(p_theme_type) + "' does not exist.");
  264. ERR_FAIL_COND_MSG(!icon_map[p_theme_type].has(p_name), "Cannot clear the icon '" + String(p_name) + "' because it does not exist.");
  265. if (icon_map[p_theme_type][p_name].is_valid()) {
  266. icon_map[p_theme_type][p_name]->disconnect("changed", this, "_emit_theme_changed");
  267. }
  268. icon_map[p_theme_type].erase(p_name);
  269. _emit_theme_changed(true);
  270. }
  271. void Theme::get_icon_list(StringName p_theme_type, List<StringName> *p_list) const {
  272. ERR_FAIL_NULL(p_list);
  273. if (!icon_map.has(p_theme_type)) {
  274. return;
  275. }
  276. const StringName *key = nullptr;
  277. while ((key = icon_map[p_theme_type].next(key))) {
  278. p_list->push_back(*key);
  279. }
  280. }
  281. void Theme::add_icon_type(const StringName &p_theme_type) {
  282. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  283. if (icon_map.has(p_theme_type)) {
  284. return;
  285. }
  286. icon_map[p_theme_type] = HashMap<StringName, Ref<Texture>>();
  287. }
  288. void Theme::remove_icon_type(const StringName &p_theme_type) {
  289. if (!icon_map.has(p_theme_type)) {
  290. return;
  291. }
  292. _freeze_change_propagation();
  293. const StringName *L = nullptr;
  294. while ((L = icon_map[p_theme_type].next(L))) {
  295. Ref<Texture> icon = icon_map[p_theme_type][*L];
  296. if (icon.is_valid()) {
  297. icon->disconnect("changed", this, "_emit_theme_changed");
  298. }
  299. }
  300. icon_map.erase(p_theme_type);
  301. _unfreeze_and_propagate_changes();
  302. }
  303. void Theme::get_icon_types(List<StringName> *p_list) const {
  304. ERR_FAIL_NULL(p_list);
  305. const StringName *key = nullptr;
  306. while ((key = icon_map.next(key))) {
  307. p_list->push_back(*key);
  308. }
  309. }
  310. // Shaders.
  311. void Theme::set_shader(const StringName &p_name, const StringName &p_theme_type, const Ref<Shader> &p_shader) {
  312. ERR_FAIL_COND_MSG(!is_valid_item_name(p_name), vformat("Invalid item name: '%s'", p_name));
  313. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  314. bool existing = (shader_map.has(p_theme_type) && shader_map[p_theme_type].has(p_name));
  315. shader_map[p_theme_type][p_name] = p_shader;
  316. _emit_theme_changed(!existing);
  317. }
  318. Ref<Shader> Theme::get_shader(const StringName &p_name, const StringName &p_theme_type) const {
  319. if (shader_map.has(p_theme_type) && shader_map[p_theme_type].has(p_name) && shader_map[p_theme_type][p_name].is_valid()) {
  320. return shader_map[p_theme_type][p_name];
  321. } else {
  322. return nullptr;
  323. }
  324. }
  325. bool Theme::has_shader(const StringName &p_name, const StringName &p_theme_type) const {
  326. return (shader_map.has(p_theme_type) && shader_map[p_theme_type].has(p_name) && shader_map[p_theme_type][p_name].is_valid());
  327. }
  328. void Theme::clear_shader(const StringName &p_name, const StringName &p_theme_type) {
  329. ERR_FAIL_COND(!shader_map.has(p_theme_type));
  330. ERR_FAIL_COND(!shader_map[p_theme_type].has(p_name));
  331. shader_map[p_theme_type].erase(p_name);
  332. _emit_theme_changed(true);
  333. }
  334. void Theme::get_shader_list(const StringName &p_theme_type, List<StringName> *p_list) const {
  335. ERR_FAIL_NULL(p_list);
  336. if (!shader_map.has(p_theme_type)) {
  337. return;
  338. }
  339. const StringName *key = nullptr;
  340. while ((key = shader_map[p_theme_type].next(key))) {
  341. p_list->push_back(*key);
  342. }
  343. }
  344. // Styleboxes.
  345. void Theme::set_stylebox(const StringName &p_name, const StringName &p_theme_type, const Ref<StyleBox> &p_style) {
  346. ERR_FAIL_COND_MSG(!is_valid_item_name(p_name), vformat("Invalid item name: '%s'", p_name));
  347. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  348. bool existing = false;
  349. if (style_map[p_theme_type].has(p_name) && style_map[p_theme_type][p_name].is_valid()) {
  350. existing = true;
  351. style_map[p_theme_type][p_name]->disconnect("changed", this, "_emit_theme_changed");
  352. }
  353. style_map[p_theme_type][p_name] = p_style;
  354. if (p_style.is_valid()) {
  355. style_map[p_theme_type][p_name]->connect("changed", this, "_emit_theme_changed", varray(), CONNECT_REFERENCE_COUNTED);
  356. }
  357. _emit_theme_changed(!existing);
  358. }
  359. Ref<StyleBox> Theme::get_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
  360. if (style_map.has(p_theme_type) && style_map[p_theme_type].has(p_name) && style_map[p_theme_type][p_name].is_valid()) {
  361. return style_map[p_theme_type][p_name];
  362. } else {
  363. return default_style;
  364. }
  365. }
  366. bool Theme::has_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
  367. return (style_map.has(p_theme_type) && style_map[p_theme_type].has(p_name) && style_map[p_theme_type][p_name].is_valid());
  368. }
  369. bool Theme::has_stylebox_nocheck(const StringName &p_name, const StringName &p_theme_type) const {
  370. return (style_map.has(p_theme_type) && style_map[p_theme_type].has(p_name));
  371. }
  372. void Theme::rename_stylebox(const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type) {
  373. ERR_FAIL_COND_MSG(!is_valid_item_name(p_name), vformat("Invalid item name: '%s'", p_name));
  374. ERR_FAIL_COND_MSG(!style_map.has(p_theme_type), "Cannot rename the stylebox '" + String(p_old_name) + "' because the node type '" + String(p_theme_type) + "' does not exist.");
  375. ERR_FAIL_COND_MSG(style_map[p_theme_type].has(p_name), "Cannot rename the stylebox '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists.");
  376. ERR_FAIL_COND_MSG(!style_map[p_theme_type].has(p_old_name), "Cannot rename the stylebox '" + String(p_old_name) + "' because it does not exist.");
  377. style_map[p_theme_type][p_name] = style_map[p_theme_type][p_old_name];
  378. style_map[p_theme_type].erase(p_old_name);
  379. _emit_theme_changed(true);
  380. }
  381. void Theme::clear_stylebox(const StringName &p_name, const StringName &p_theme_type) {
  382. ERR_FAIL_COND_MSG(!style_map.has(p_theme_type), "Cannot clear the stylebox '" + String(p_name) + "' because the node type '" + String(p_theme_type) + "' does not exist.");
  383. ERR_FAIL_COND_MSG(!style_map[p_theme_type].has(p_name), "Cannot clear the stylebox '" + String(p_name) + "' because it does not exist.");
  384. if (style_map[p_theme_type][p_name].is_valid()) {
  385. style_map[p_theme_type][p_name]->disconnect("changed", this, "_emit_theme_changed");
  386. }
  387. style_map[p_theme_type].erase(p_name);
  388. _emit_theme_changed(true);
  389. }
  390. void Theme::get_stylebox_list(StringName p_theme_type, List<StringName> *p_list) const {
  391. ERR_FAIL_NULL(p_list);
  392. if (!style_map.has(p_theme_type)) {
  393. return;
  394. }
  395. const StringName *key = nullptr;
  396. while ((key = style_map[p_theme_type].next(key))) {
  397. p_list->push_back(*key);
  398. }
  399. }
  400. void Theme::add_stylebox_type(const StringName &p_theme_type) {
  401. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  402. if (style_map.has(p_theme_type)) {
  403. return;
  404. }
  405. style_map[p_theme_type] = HashMap<StringName, Ref<StyleBox>>();
  406. }
  407. void Theme::remove_stylebox_type(const StringName &p_theme_type) {
  408. if (!style_map.has(p_theme_type)) {
  409. return;
  410. }
  411. _freeze_change_propagation();
  412. const StringName *L = nullptr;
  413. while ((L = style_map[p_theme_type].next(L))) {
  414. Ref<StyleBox> style = style_map[p_theme_type][*L];
  415. if (style.is_valid()) {
  416. style->disconnect("changed", this, "_emit_theme_changed");
  417. }
  418. }
  419. style_map.erase(p_theme_type);
  420. _unfreeze_and_propagate_changes();
  421. }
  422. void Theme::get_stylebox_types(List<StringName> *p_list) const {
  423. ERR_FAIL_NULL(p_list);
  424. const StringName *key = nullptr;
  425. while ((key = style_map.next(key))) {
  426. p_list->push_back(*key);
  427. }
  428. }
  429. // Fonts.
  430. void Theme::set_font(const StringName &p_name, const StringName &p_theme_type, const Ref<Font> &p_font) {
  431. ERR_FAIL_COND_MSG(!is_valid_item_name(p_name), vformat("Invalid item name: '%s'", p_name));
  432. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  433. bool existing = false;
  434. if (font_map[p_theme_type][p_name].is_valid()) {
  435. existing = true;
  436. font_map[p_theme_type][p_name]->disconnect("changed", this, "_emit_theme_changed");
  437. }
  438. font_map[p_theme_type][p_name] = p_font;
  439. if (p_font.is_valid()) {
  440. font_map[p_theme_type][p_name]->connect("changed", this, "_emit_theme_changed", varray(), CONNECT_REFERENCE_COUNTED);
  441. }
  442. _emit_theme_changed(!existing);
  443. }
  444. Ref<Font> Theme::get_font(const StringName &p_name, const StringName &p_theme_type) const {
  445. if (font_map.has(p_theme_type) && font_map[p_theme_type].has(p_name) && font_map[p_theme_type][p_name].is_valid()) {
  446. return font_map[p_theme_type][p_name];
  447. } else if (has_default_theme_font()) {
  448. return default_theme_font;
  449. } else {
  450. return default_font;
  451. }
  452. }
  453. bool Theme::has_font(const StringName &p_name, const StringName &p_theme_type) const {
  454. return ((font_map.has(p_theme_type) && font_map[p_theme_type].has(p_name) && font_map[p_theme_type][p_name].is_valid()) || has_default_theme_font());
  455. }
  456. bool Theme::has_font_nocheck(const StringName &p_name, const StringName &p_theme_type) const {
  457. return (font_map.has(p_theme_type) && font_map[p_theme_type].has(p_name));
  458. }
  459. void Theme::rename_font(const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type) {
  460. ERR_FAIL_COND_MSG(!is_valid_item_name(p_name), vformat("Invalid item name: '%s'", p_name));
  461. ERR_FAIL_COND_MSG(!font_map.has(p_theme_type), "Cannot rename the font '" + String(p_old_name) + "' because the node type '" + String(p_theme_type) + "' does not exist.");
  462. ERR_FAIL_COND_MSG(font_map[p_theme_type].has(p_name), "Cannot rename the font '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists.");
  463. ERR_FAIL_COND_MSG(!font_map[p_theme_type].has(p_old_name), "Cannot rename the font '" + String(p_old_name) + "' because it does not exist.");
  464. font_map[p_theme_type][p_name] = font_map[p_theme_type][p_old_name];
  465. font_map[p_theme_type].erase(p_old_name);
  466. _emit_theme_changed(true);
  467. }
  468. void Theme::clear_font(const StringName &p_name, const StringName &p_theme_type) {
  469. ERR_FAIL_COND_MSG(!font_map.has(p_theme_type), "Cannot clear the font '" + String(p_name) + "' because the node type '" + String(p_theme_type) + "' does not exist.");
  470. ERR_FAIL_COND_MSG(!font_map[p_theme_type].has(p_name), "Cannot clear the font '" + String(p_name) + "' because it does not exist.");
  471. if (font_map[p_theme_type][p_name].is_valid()) {
  472. font_map[p_theme_type][p_name]->disconnect("changed", this, "_emit_theme_changed");
  473. }
  474. font_map[p_theme_type].erase(p_name);
  475. _emit_theme_changed(true);
  476. }
  477. void Theme::get_font_list(StringName p_theme_type, List<StringName> *p_list) const {
  478. ERR_FAIL_NULL(p_list);
  479. if (!font_map.has(p_theme_type)) {
  480. return;
  481. }
  482. const StringName *key = nullptr;
  483. while ((key = font_map[p_theme_type].next(key))) {
  484. p_list->push_back(*key);
  485. }
  486. }
  487. void Theme::add_font_type(const StringName &p_theme_type) {
  488. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  489. if (font_map.has(p_theme_type)) {
  490. return;
  491. }
  492. font_map[p_theme_type] = HashMap<StringName, Ref<Font>>();
  493. }
  494. void Theme::remove_font_type(const StringName &p_theme_type) {
  495. if (!font_map.has(p_theme_type)) {
  496. return;
  497. }
  498. _freeze_change_propagation();
  499. const StringName *L = nullptr;
  500. while ((L = font_map[p_theme_type].next(L))) {
  501. Ref<Font> font = font_map[p_theme_type][*L];
  502. if (font.is_valid()) {
  503. font->disconnect("changed", this, "_emit_theme_changed");
  504. }
  505. }
  506. font_map.erase(p_theme_type);
  507. _unfreeze_and_propagate_changes();
  508. }
  509. void Theme::get_font_types(List<StringName> *p_list) const {
  510. ERR_FAIL_NULL(p_list);
  511. const StringName *key = nullptr;
  512. while ((key = font_map.next(key))) {
  513. p_list->push_back(*key);
  514. }
  515. }
  516. // Colors.
  517. void Theme::set_color(const StringName &p_name, const StringName &p_theme_type, const Color &p_color) {
  518. ERR_FAIL_COND_MSG(!is_valid_item_name(p_name), vformat("Invalid item name: '%s'", p_name));
  519. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  520. bool existing = has_color_nocheck(p_name, p_theme_type);
  521. color_map[p_theme_type][p_name] = p_color;
  522. _emit_theme_changed(!existing);
  523. }
  524. Color Theme::get_color(const StringName &p_name, const StringName &p_theme_type) const {
  525. if (color_map.has(p_theme_type) && color_map[p_theme_type].has(p_name)) {
  526. return color_map[p_theme_type][p_name];
  527. } else {
  528. return Color();
  529. }
  530. }
  531. bool Theme::has_color(const StringName &p_name, const StringName &p_theme_type) const {
  532. return (color_map.has(p_theme_type) && color_map[p_theme_type].has(p_name));
  533. }
  534. bool Theme::has_color_nocheck(const StringName &p_name, const StringName &p_theme_type) const {
  535. return (color_map.has(p_theme_type) && color_map[p_theme_type].has(p_name));
  536. }
  537. void Theme::rename_color(const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type) {
  538. ERR_FAIL_COND_MSG(!is_valid_item_name(p_name), vformat("Invalid item name: '%s'", p_name));
  539. ERR_FAIL_COND_MSG(!color_map.has(p_theme_type), "Cannot rename the color '" + String(p_old_name) + "' because the node type '" + String(p_theme_type) + "' does not exist.");
  540. ERR_FAIL_COND_MSG(color_map[p_theme_type].has(p_name), "Cannot rename the color '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists.");
  541. ERR_FAIL_COND_MSG(!color_map[p_theme_type].has(p_old_name), "Cannot rename the color '" + String(p_old_name) + "' because it does not exist.");
  542. color_map[p_theme_type][p_name] = color_map[p_theme_type][p_old_name];
  543. color_map[p_theme_type].erase(p_old_name);
  544. _emit_theme_changed(true);
  545. }
  546. void Theme::clear_color(const StringName &p_name, const StringName &p_theme_type) {
  547. ERR_FAIL_COND_MSG(!color_map.has(p_theme_type), "Cannot clear the color '" + String(p_name) + "' because the node type '" + String(p_theme_type) + "' does not exist.");
  548. ERR_FAIL_COND_MSG(!color_map[p_theme_type].has(p_name), "Cannot clear the color '" + String(p_name) + "' because it does not exist.");
  549. color_map[p_theme_type].erase(p_name);
  550. _emit_theme_changed(true);
  551. }
  552. void Theme::get_color_list(StringName p_theme_type, List<StringName> *p_list) const {
  553. ERR_FAIL_NULL(p_list);
  554. if (!color_map.has(p_theme_type)) {
  555. return;
  556. }
  557. const StringName *key = nullptr;
  558. while ((key = color_map[p_theme_type].next(key))) {
  559. p_list->push_back(*key);
  560. }
  561. }
  562. void Theme::add_color_type(const StringName &p_theme_type) {
  563. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  564. if (color_map.has(p_theme_type)) {
  565. return;
  566. }
  567. color_map[p_theme_type] = HashMap<StringName, Color>();
  568. }
  569. void Theme::remove_color_type(const StringName &p_theme_type) {
  570. if (!color_map.has(p_theme_type)) {
  571. return;
  572. }
  573. color_map.erase(p_theme_type);
  574. }
  575. void Theme::get_color_types(List<StringName> *p_list) const {
  576. ERR_FAIL_NULL(p_list);
  577. const StringName *key = nullptr;
  578. while ((key = color_map.next(key))) {
  579. p_list->push_back(*key);
  580. }
  581. }
  582. // Theme constants.
  583. void Theme::set_constant(const StringName &p_name, const StringName &p_theme_type, int p_constant) {
  584. ERR_FAIL_COND_MSG(!is_valid_item_name(p_name), vformat("Invalid item name: '%s'", p_name));
  585. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  586. bool existing = has_constant_nocheck(p_name, p_theme_type);
  587. constant_map[p_theme_type][p_name] = p_constant;
  588. _emit_theme_changed(!existing);
  589. }
  590. int Theme::get_constant(const StringName &p_name, const StringName &p_theme_type) const {
  591. if (constant_map.has(p_theme_type) && constant_map[p_theme_type].has(p_name)) {
  592. return constant_map[p_theme_type][p_name];
  593. } else {
  594. return 0;
  595. }
  596. }
  597. bool Theme::has_constant(const StringName &p_name, const StringName &p_theme_type) const {
  598. return (constant_map.has(p_theme_type) && constant_map[p_theme_type].has(p_name));
  599. }
  600. bool Theme::has_constant_nocheck(const StringName &p_name, const StringName &p_theme_type) const {
  601. return (constant_map.has(p_theme_type) && constant_map[p_theme_type].has(p_name));
  602. }
  603. void Theme::rename_constant(const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type) {
  604. ERR_FAIL_COND_MSG(!is_valid_item_name(p_name), vformat("Invalid item name: '%s'", p_name));
  605. ERR_FAIL_COND_MSG(!constant_map.has(p_theme_type), "Cannot rename the constant '" + String(p_old_name) + "' because the node type '" + String(p_theme_type) + "' does not exist.");
  606. ERR_FAIL_COND_MSG(constant_map[p_theme_type].has(p_name), "Cannot rename the constant '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists.");
  607. ERR_FAIL_COND_MSG(!constant_map[p_theme_type].has(p_old_name), "Cannot rename the constant '" + String(p_old_name) + "' because it does not exist.");
  608. constant_map[p_theme_type][p_name] = constant_map[p_theme_type][p_old_name];
  609. constant_map[p_theme_type].erase(p_old_name);
  610. _emit_theme_changed(true);
  611. }
  612. void Theme::clear_constant(const StringName &p_name, const StringName &p_theme_type) {
  613. ERR_FAIL_COND_MSG(!constant_map.has(p_theme_type), "Cannot clear the constant '" + String(p_name) + "' because the node type '" + String(p_theme_type) + "' does not exist.");
  614. ERR_FAIL_COND_MSG(!constant_map[p_theme_type].has(p_name), "Cannot clear the constant '" + String(p_name) + "' because it does not exist.");
  615. constant_map[p_theme_type].erase(p_name);
  616. _emit_theme_changed(true);
  617. }
  618. void Theme::get_constant_list(StringName p_theme_type, List<StringName> *p_list) const {
  619. ERR_FAIL_NULL(p_list);
  620. if (!constant_map.has(p_theme_type)) {
  621. return;
  622. }
  623. const StringName *key = nullptr;
  624. while ((key = constant_map[p_theme_type].next(key))) {
  625. p_list->push_back(*key);
  626. }
  627. }
  628. void Theme::add_constant_type(const StringName &p_theme_type) {
  629. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  630. if (constant_map.has(p_theme_type)) {
  631. return;
  632. }
  633. constant_map[p_theme_type] = HashMap<StringName, int>();
  634. }
  635. void Theme::remove_constant_type(const StringName &p_theme_type) {
  636. if (!constant_map.has(p_theme_type)) {
  637. return;
  638. }
  639. constant_map.erase(p_theme_type);
  640. }
  641. void Theme::get_constant_types(List<StringName> *p_list) const {
  642. ERR_FAIL_NULL(p_list);
  643. const StringName *key = nullptr;
  644. while ((key = constant_map.next(key))) {
  645. p_list->push_back(*key);
  646. }
  647. }
  648. // Generic methods for managing theme items.
  649. void Theme::set_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type, const Variant &p_value) {
  650. switch (p_data_type) {
  651. case DATA_TYPE_COLOR: {
  652. ERR_FAIL_COND_MSG(p_value.get_type() != Variant::COLOR, "Theme item's data type (Color) does not match Variant's type (" + Variant::get_type_name(p_value.get_type()) + ").");
  653. Color color_value = p_value;
  654. set_color(p_name, p_theme_type, color_value);
  655. } break;
  656. case DATA_TYPE_CONSTANT: {
  657. ERR_FAIL_COND_MSG(p_value.get_type() != Variant::INT, "Theme item's data type (int) does not match Variant's type (" + Variant::get_type_name(p_value.get_type()) + ").");
  658. int constant_value = p_value;
  659. set_constant(p_name, p_theme_type, constant_value);
  660. } break;
  661. case DATA_TYPE_FONT: {
  662. ERR_FAIL_COND_MSG(p_value.get_type() != Variant::OBJECT, "Theme item's data type (Object) does not match Variant's type (" + Variant::get_type_name(p_value.get_type()) + ").");
  663. Ref<Font> font_value = Object::cast_to<Font>(p_value);
  664. set_font(p_name, p_theme_type, font_value);
  665. } break;
  666. case DATA_TYPE_ICON: {
  667. ERR_FAIL_COND_MSG(p_value.get_type() != Variant::OBJECT, "Theme item's data type (Object) does not match Variant's type (" + Variant::get_type_name(p_value.get_type()) + ").");
  668. Ref<Texture> icon_value = Object::cast_to<Texture>(p_value);
  669. set_icon(p_name, p_theme_type, icon_value);
  670. } break;
  671. case DATA_TYPE_STYLEBOX: {
  672. ERR_FAIL_COND_MSG(p_value.get_type() != Variant::OBJECT, "Theme item's data type (Object) does not match Variant's type (" + Variant::get_type_name(p_value.get_type()) + ").");
  673. Ref<StyleBox> stylebox_value = Object::cast_to<StyleBox>(p_value);
  674. set_stylebox(p_name, p_theme_type, stylebox_value);
  675. } break;
  676. case DATA_TYPE_MAX:
  677. break; // Can't happen, but silences warning.
  678. }
  679. }
  680. Variant Theme::get_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type) const {
  681. switch (p_data_type) {
  682. case DATA_TYPE_COLOR:
  683. return get_color(p_name, p_theme_type);
  684. case DATA_TYPE_CONSTANT:
  685. return get_constant(p_name, p_theme_type);
  686. case DATA_TYPE_FONT:
  687. return get_font(p_name, p_theme_type);
  688. case DATA_TYPE_ICON:
  689. return get_icon(p_name, p_theme_type);
  690. case DATA_TYPE_STYLEBOX:
  691. return get_stylebox(p_name, p_theme_type);
  692. case DATA_TYPE_MAX:
  693. break; // Can't happen, but silences warning.
  694. }
  695. return Variant();
  696. }
  697. bool Theme::has_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type) const {
  698. switch (p_data_type) {
  699. case DATA_TYPE_COLOR:
  700. return has_color(p_name, p_theme_type);
  701. case DATA_TYPE_CONSTANT:
  702. return has_constant(p_name, p_theme_type);
  703. case DATA_TYPE_FONT:
  704. return has_font(p_name, p_theme_type);
  705. case DATA_TYPE_ICON:
  706. return has_icon(p_name, p_theme_type);
  707. case DATA_TYPE_STYLEBOX:
  708. return has_stylebox(p_name, p_theme_type);
  709. case DATA_TYPE_MAX:
  710. break; // Can't happen, but silences warning.
  711. }
  712. return false;
  713. }
  714. bool Theme::has_theme_item_nocheck(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type) const {
  715. switch (p_data_type) {
  716. case DATA_TYPE_COLOR:
  717. return has_color_nocheck(p_name, p_theme_type);
  718. case DATA_TYPE_CONSTANT:
  719. return has_constant_nocheck(p_name, p_theme_type);
  720. case DATA_TYPE_FONT:
  721. return has_font_nocheck(p_name, p_theme_type);
  722. case DATA_TYPE_ICON:
  723. return has_icon_nocheck(p_name, p_theme_type);
  724. case DATA_TYPE_STYLEBOX:
  725. return has_stylebox_nocheck(p_name, p_theme_type);
  726. case DATA_TYPE_MAX:
  727. break; // Can't happen, but silences warning.
  728. }
  729. return false;
  730. }
  731. void Theme::rename_theme_item(DataType p_data_type, const StringName &p_old_name, const StringName &p_name, const StringName &p_theme_type) {
  732. switch (p_data_type) {
  733. case DATA_TYPE_COLOR:
  734. rename_color(p_old_name, p_name, p_theme_type);
  735. break;
  736. case DATA_TYPE_CONSTANT:
  737. rename_constant(p_old_name, p_name, p_theme_type);
  738. break;
  739. case DATA_TYPE_FONT:
  740. rename_font(p_old_name, p_name, p_theme_type);
  741. break;
  742. case DATA_TYPE_ICON:
  743. rename_icon(p_old_name, p_name, p_theme_type);
  744. break;
  745. case DATA_TYPE_STYLEBOX:
  746. rename_stylebox(p_old_name, p_name, p_theme_type);
  747. break;
  748. case DATA_TYPE_MAX:
  749. break; // Can't happen, but silences warning.
  750. }
  751. }
  752. void Theme::clear_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type) {
  753. switch (p_data_type) {
  754. case DATA_TYPE_COLOR:
  755. clear_color(p_name, p_theme_type);
  756. break;
  757. case DATA_TYPE_CONSTANT:
  758. clear_constant(p_name, p_theme_type);
  759. break;
  760. case DATA_TYPE_FONT:
  761. clear_font(p_name, p_theme_type);
  762. break;
  763. case DATA_TYPE_ICON:
  764. clear_icon(p_name, p_theme_type);
  765. break;
  766. case DATA_TYPE_STYLEBOX:
  767. clear_stylebox(p_name, p_theme_type);
  768. break;
  769. case DATA_TYPE_MAX:
  770. break; // Can't happen, but silences warning.
  771. }
  772. }
  773. void Theme::get_theme_item_list(DataType p_data_type, StringName p_theme_type, List<StringName> *p_list) const {
  774. switch (p_data_type) {
  775. case DATA_TYPE_COLOR:
  776. get_color_list(p_theme_type, p_list);
  777. break;
  778. case DATA_TYPE_CONSTANT:
  779. get_constant_list(p_theme_type, p_list);
  780. break;
  781. case DATA_TYPE_FONT:
  782. get_font_list(p_theme_type, p_list);
  783. break;
  784. case DATA_TYPE_ICON:
  785. get_icon_list(p_theme_type, p_list);
  786. break;
  787. case DATA_TYPE_STYLEBOX:
  788. get_stylebox_list(p_theme_type, p_list);
  789. break;
  790. case DATA_TYPE_MAX:
  791. break; // Can't happen, but silences warning.
  792. }
  793. }
  794. void Theme::add_theme_item_type(DataType p_data_type, const StringName &p_theme_type) {
  795. switch (p_data_type) {
  796. case DATA_TYPE_COLOR:
  797. add_color_type(p_theme_type);
  798. break;
  799. case DATA_TYPE_CONSTANT:
  800. add_constant_type(p_theme_type);
  801. break;
  802. case DATA_TYPE_FONT:
  803. add_font_type(p_theme_type);
  804. break;
  805. case DATA_TYPE_ICON:
  806. add_icon_type(p_theme_type);
  807. break;
  808. case DATA_TYPE_STYLEBOX:
  809. add_stylebox_type(p_theme_type);
  810. break;
  811. case DATA_TYPE_MAX:
  812. break; // Can't happen, but silences warning.
  813. }
  814. }
  815. void Theme::remove_theme_item_type(DataType p_data_type, const StringName &p_theme_type) {
  816. switch (p_data_type) {
  817. case DATA_TYPE_COLOR:
  818. remove_color_type(p_theme_type);
  819. break;
  820. case DATA_TYPE_CONSTANT:
  821. remove_constant_type(p_theme_type);
  822. break;
  823. case DATA_TYPE_FONT:
  824. remove_font_type(p_theme_type);
  825. break;
  826. case DATA_TYPE_ICON:
  827. remove_icon_type(p_theme_type);
  828. break;
  829. case DATA_TYPE_STYLEBOX:
  830. remove_stylebox_type(p_theme_type);
  831. break;
  832. case DATA_TYPE_MAX:
  833. break; // Can't happen, but silences warning.
  834. }
  835. }
  836. void Theme::get_theme_item_types(DataType p_data_type, List<StringName> *p_list) const {
  837. switch (p_data_type) {
  838. case DATA_TYPE_COLOR:
  839. get_color_types(p_list);
  840. break;
  841. case DATA_TYPE_CONSTANT:
  842. get_constant_types(p_list);
  843. break;
  844. case DATA_TYPE_FONT:
  845. get_font_types(p_list);
  846. break;
  847. case DATA_TYPE_ICON:
  848. get_icon_types(p_list);
  849. break;
  850. case DATA_TYPE_STYLEBOX:
  851. get_stylebox_types(p_list);
  852. break;
  853. case DATA_TYPE_MAX:
  854. break; // Can't happen, but silences warning.
  855. }
  856. }
  857. // Theme type variations.
  858. void Theme::set_type_variation(const StringName &p_theme_type, const StringName &p_base_type) {
  859. ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
  860. ERR_FAIL_COND_MSG(!is_valid_type_name(p_base_type), vformat("Invalid type name: '%s'", p_base_type));
  861. ERR_FAIL_COND_MSG(p_theme_type == StringName(), "An empty theme type cannot be marked as a variation of another type.");
  862. ERR_FAIL_COND_MSG(ClassDB::class_exists(p_theme_type), "A type associated with a built-in class cannot be marked as a variation of another type.");
  863. ERR_FAIL_COND_MSG(p_base_type == StringName(), "An empty theme type cannot be the base type of a variation. Use clear_type_variation() instead if you want to unmark '" + String(p_theme_type) + "' as a variation.");
  864. if (variation_map.has(p_theme_type)) {
  865. StringName old_base = variation_map[p_theme_type];
  866. variation_base_map[old_base].erase(p_theme_type);
  867. }
  868. variation_map[p_theme_type] = p_base_type;
  869. variation_base_map[p_base_type].push_back(p_theme_type);
  870. _emit_theme_changed(true);
  871. }
  872. bool Theme::is_type_variation(const StringName &p_theme_type, const StringName &p_base_type) const {
  873. return (variation_map.has(p_theme_type) && variation_map[p_theme_type] == p_base_type);
  874. }
  875. void Theme::clear_type_variation(const StringName &p_theme_type) {
  876. ERR_FAIL_COND_MSG(!variation_map.has(p_theme_type), "Cannot clear the type variation '" + String(p_theme_type) + "' because it does not exist.");
  877. StringName base_type = variation_map[p_theme_type];
  878. variation_base_map[base_type].erase(p_theme_type);
  879. variation_map.erase(p_theme_type);
  880. _emit_theme_changed(true);
  881. }
  882. StringName Theme::get_type_variation_base(const StringName &p_theme_type) const {
  883. if (!variation_map.has(p_theme_type)) {
  884. return StringName();
  885. }
  886. return variation_map[p_theme_type];
  887. }
  888. void Theme::get_type_variation_list(const StringName &p_base_type, List<StringName> *p_list) const {
  889. ERR_FAIL_NULL(p_list);
  890. if (!variation_base_map.has(p_base_type)) {
  891. return;
  892. }
  893. for (const List<StringName>::Element *E = variation_base_map[p_base_type].front(); E; E = E->next()) {
  894. // Prevent infinite loops if variants were set to be cross-dependent (that's still invalid usage, but handling for stability sake).
  895. if (p_list->find(E->get())) {
  896. continue;
  897. }
  898. p_list->push_back(E->get());
  899. // Continue looking for sub-variations.
  900. get_type_variation_list(E->get(), p_list);
  901. }
  902. }
  903. // Theme types.
  904. void Theme::add_type(const StringName &p_theme_type) {
  905. // Add a record to every data type map.
  906. for (int i = 0; i < Theme::DATA_TYPE_MAX; i++) {
  907. Theme::DataType dt = (Theme::DataType)i;
  908. add_theme_item_type(dt, p_theme_type);
  909. }
  910. _emit_theme_changed(true);
  911. }
  912. void Theme::remove_type(const StringName &p_theme_type) {
  913. // Gracefully remove the record from every data type map.
  914. for (int i = 0; i < Theme::DATA_TYPE_MAX; i++) {
  915. Theme::DataType dt = (Theme::DataType)i;
  916. remove_theme_item_type(dt, p_theme_type);
  917. }
  918. // If type is a variation, remove that connection.
  919. if (get_type_variation_base(p_theme_type) != StringName()) {
  920. clear_type_variation(p_theme_type);
  921. }
  922. // If type is a variation base, remove all those connections.
  923. List<StringName> names;
  924. get_type_variation_list(p_theme_type, &names);
  925. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  926. clear_type_variation(E->get());
  927. }
  928. _emit_theme_changed(true);
  929. }
  930. void Theme::get_type_list(List<StringName> *p_list) const {
  931. ERR_FAIL_NULL(p_list);
  932. Set<StringName> types;
  933. const StringName *key = nullptr;
  934. while ((key = icon_map.next(key))) {
  935. types.insert(*key);
  936. }
  937. key = nullptr;
  938. while ((key = style_map.next(key))) {
  939. types.insert(*key);
  940. }
  941. key = nullptr;
  942. while ((key = font_map.next(key))) {
  943. types.insert(*key);
  944. }
  945. key = nullptr;
  946. while ((key = color_map.next(key))) {
  947. types.insert(*key);
  948. }
  949. key = nullptr;
  950. while ((key = constant_map.next(key))) {
  951. types.insert(*key);
  952. }
  953. for (Set<StringName>::Element *E = types.front(); E; E = E->next()) {
  954. p_list->push_back(E->get());
  955. }
  956. }
  957. void Theme::get_type_dependencies(const StringName &p_base_type, const StringName &p_type_variation, List<StringName> *p_list) {
  958. ERR_FAIL_NULL(p_list);
  959. // Build the dependency chain for type variations.
  960. if (p_type_variation != StringName()) {
  961. StringName variation_name = p_type_variation;
  962. while (variation_name != StringName()) {
  963. p_list->push_back(variation_name);
  964. variation_name = get_type_variation_base(variation_name);
  965. // If we have reached the base type dependency, it's safe to stop (assuming no funny business was done to the Theme).
  966. if (variation_name == p_base_type) {
  967. break;
  968. }
  969. }
  970. }
  971. // Continue building the chain using native class hierarchy.
  972. StringName class_name = p_base_type;
  973. while (class_name != StringName()) {
  974. p_list->push_back(class_name);
  975. class_name = ClassDB::get_parent_class_nocheck(class_name);
  976. }
  977. }
  978. // Internal methods for getting lists as a Vector of String (compatible with public API).
  979. PoolVector<String> Theme::_get_icon_list(const String &p_theme_type) const {
  980. PoolVector<String> ilret;
  981. List<StringName> il;
  982. get_icon_list(p_theme_type, &il);
  983. ilret.resize(il.size());
  984. int i = 0;
  985. PoolVector<String>::Write w = ilret.write();
  986. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  987. w[i] = E->get();
  988. }
  989. return ilret;
  990. }
  991. PoolVector<String> Theme::_get_icon_types() const {
  992. PoolVector<String> ilret;
  993. List<StringName> il;
  994. get_icon_types(&il);
  995. ilret.resize(il.size());
  996. int i = 0;
  997. PoolVector<String>::Write w = ilret.write();
  998. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  999. w[i] = E->get();
  1000. }
  1001. return ilret;
  1002. }
  1003. PoolVector<String> Theme::_get_stylebox_list(const String &p_theme_type) const {
  1004. PoolVector<String> ilret;
  1005. List<StringName> il;
  1006. get_stylebox_list(p_theme_type, &il);
  1007. ilret.resize(il.size());
  1008. int i = 0;
  1009. PoolVector<String>::Write w = ilret.write();
  1010. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  1011. w[i] = E->get();
  1012. }
  1013. return ilret;
  1014. }
  1015. PoolVector<String> Theme::_get_stylebox_types() const {
  1016. PoolVector<String> ilret;
  1017. List<StringName> il;
  1018. get_stylebox_types(&il);
  1019. ilret.resize(il.size());
  1020. int i = 0;
  1021. PoolVector<String>::Write w = ilret.write();
  1022. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  1023. w[i] = E->get();
  1024. }
  1025. return ilret;
  1026. }
  1027. PoolVector<String> Theme::_get_font_list(const String &p_theme_type) const {
  1028. PoolVector<String> ilret;
  1029. List<StringName> il;
  1030. get_font_list(p_theme_type, &il);
  1031. ilret.resize(il.size());
  1032. int i = 0;
  1033. PoolVector<String>::Write w = ilret.write();
  1034. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  1035. w[i] = E->get();
  1036. }
  1037. return ilret;
  1038. }
  1039. PoolVector<String> Theme::_get_font_types() const {
  1040. PoolVector<String> ilret;
  1041. List<StringName> il;
  1042. get_font_types(&il);
  1043. ilret.resize(il.size());
  1044. int i = 0;
  1045. PoolVector<String>::Write w = ilret.write();
  1046. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  1047. w[i] = E->get();
  1048. }
  1049. return ilret;
  1050. }
  1051. PoolVector<String> Theme::_get_color_list(const String &p_theme_type) const {
  1052. PoolVector<String> ilret;
  1053. List<StringName> il;
  1054. get_color_list(p_theme_type, &il);
  1055. ilret.resize(il.size());
  1056. int i = 0;
  1057. PoolVector<String>::Write w = ilret.write();
  1058. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  1059. w[i] = E->get();
  1060. }
  1061. return ilret;
  1062. }
  1063. PoolVector<String> Theme::_get_color_types() const {
  1064. PoolVector<String> ilret;
  1065. List<StringName> il;
  1066. get_color_types(&il);
  1067. ilret.resize(il.size());
  1068. int i = 0;
  1069. PoolVector<String>::Write w = ilret.write();
  1070. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  1071. w[i] = E->get();
  1072. }
  1073. return ilret;
  1074. }
  1075. PoolVector<String> Theme::_get_constant_list(const String &p_theme_type) const {
  1076. PoolVector<String> ilret;
  1077. List<StringName> il;
  1078. get_constant_list(p_theme_type, &il);
  1079. ilret.resize(il.size());
  1080. int i = 0;
  1081. PoolVector<String>::Write w = ilret.write();
  1082. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  1083. w[i] = E->get();
  1084. }
  1085. return ilret;
  1086. }
  1087. PoolVector<String> Theme::_get_constant_types() const {
  1088. PoolVector<String> ilret;
  1089. List<StringName> il;
  1090. get_constant_types(&il);
  1091. ilret.resize(il.size());
  1092. int i = 0;
  1093. PoolVector<String>::Write w = ilret.write();
  1094. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  1095. w[i] = E->get();
  1096. }
  1097. return ilret;
  1098. }
  1099. PoolVector<String> Theme::_get_theme_item_list(DataType p_data_type, const String &p_theme_type) const {
  1100. switch (p_data_type) {
  1101. case DATA_TYPE_COLOR:
  1102. return _get_color_list(p_theme_type);
  1103. case DATA_TYPE_CONSTANT:
  1104. return _get_constant_list(p_theme_type);
  1105. case DATA_TYPE_FONT:
  1106. return _get_font_list(p_theme_type);
  1107. case DATA_TYPE_ICON:
  1108. return _get_icon_list(p_theme_type);
  1109. case DATA_TYPE_STYLEBOX:
  1110. return _get_stylebox_list(p_theme_type);
  1111. case DATA_TYPE_MAX:
  1112. break; // Can't happen, but silences warning.
  1113. }
  1114. return PoolVector<String>();
  1115. }
  1116. PoolVector<String> Theme::_get_theme_item_types(DataType p_data_type) const {
  1117. switch (p_data_type) {
  1118. case DATA_TYPE_COLOR:
  1119. return _get_color_types();
  1120. case DATA_TYPE_CONSTANT:
  1121. return _get_constant_types();
  1122. case DATA_TYPE_FONT:
  1123. return _get_font_types();
  1124. case DATA_TYPE_ICON:
  1125. return _get_icon_types();
  1126. case DATA_TYPE_STYLEBOX:
  1127. return _get_stylebox_types();
  1128. case DATA_TYPE_MAX:
  1129. break; // Can't happen, but silences warning.
  1130. }
  1131. return PoolVector<String>();
  1132. }
  1133. Vector<String> Theme::_get_type_variation_list(const StringName &p_theme_type) const {
  1134. Vector<String> ilret;
  1135. List<StringName> il;
  1136. get_type_variation_list(p_theme_type, &il);
  1137. ilret.resize(il.size());
  1138. int i = 0;
  1139. String *w = ilret.ptrw();
  1140. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  1141. w[i] = E->get();
  1142. }
  1143. return ilret;
  1144. }
  1145. PoolVector<String> Theme::_get_type_list(const String &p_theme_type) const {
  1146. PoolVector<String> ilret;
  1147. List<StringName> il;
  1148. get_type_list(&il);
  1149. ilret.resize(il.size());
  1150. int i = 0;
  1151. PoolVector<String>::Write w = ilret.write();
  1152. for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
  1153. w[i] = E->get();
  1154. }
  1155. return ilret;
  1156. }
  1157. // Theme bulk manipulations.
  1158. void Theme::_emit_theme_changed(bool p_notify_list_changed) {
  1159. if (no_change_propagation) {
  1160. return;
  1161. }
  1162. if (p_notify_list_changed) {
  1163. _change_notify();
  1164. }
  1165. emit_changed();
  1166. }
  1167. void Theme::_freeze_change_propagation() {
  1168. no_change_propagation = true;
  1169. }
  1170. void Theme::_unfreeze_and_propagate_changes() {
  1171. no_change_propagation = false;
  1172. _emit_theme_changed(true);
  1173. }
  1174. void Theme::copy_default_theme() {
  1175. Ref<Theme> default_theme2 = get_default();
  1176. copy_theme(default_theme2);
  1177. }
  1178. void Theme::copy_theme(const Ref<Theme> &p_other) {
  1179. if (p_other.is_null()) {
  1180. clear();
  1181. return;
  1182. }
  1183. _freeze_change_propagation();
  1184. // These items need reconnecting, so add them normally.
  1185. {
  1186. const StringName *K = nullptr;
  1187. while ((K = p_other->icon_map.next(K))) {
  1188. const StringName *L = nullptr;
  1189. while ((L = p_other->icon_map[*K].next(L))) {
  1190. set_icon(*L, *K, p_other->icon_map[*K][*L]);
  1191. }
  1192. }
  1193. }
  1194. {
  1195. const StringName *K = nullptr;
  1196. while ((K = p_other->style_map.next(K))) {
  1197. const StringName *L = nullptr;
  1198. while ((L = p_other->style_map[*K].next(L))) {
  1199. set_stylebox(*L, *K, p_other->style_map[*K][*L]);
  1200. }
  1201. }
  1202. }
  1203. {
  1204. const StringName *K = nullptr;
  1205. while ((K = p_other->font_map.next(K))) {
  1206. const StringName *L = nullptr;
  1207. while ((L = p_other->font_map[*K].next(L))) {
  1208. set_font(*L, *K, p_other->font_map[*K][*L]);
  1209. }
  1210. }
  1211. }
  1212. // These items can be simply copied.
  1213. color_map = p_other->color_map;
  1214. constant_map = p_other->constant_map;
  1215. shader_map = p_other->shader_map;
  1216. _unfreeze_and_propagate_changes();
  1217. }
  1218. void Theme::merge_with(const Ref<Theme> &p_other) {
  1219. if (p_other.is_null()) {
  1220. return;
  1221. }
  1222. _freeze_change_propagation();
  1223. // Colors.
  1224. {
  1225. const StringName *K = nullptr;
  1226. while ((K = p_other->color_map.next(K))) {
  1227. const StringName *L = nullptr;
  1228. while ((L = p_other->color_map[*K].next(L))) {
  1229. set_color(*L, *K, p_other->color_map[*K][*L]);
  1230. }
  1231. }
  1232. }
  1233. // Constants.
  1234. {
  1235. const StringName *K = nullptr;
  1236. while ((K = p_other->constant_map.next(K))) {
  1237. const StringName *L = nullptr;
  1238. while ((L = p_other->constant_map[*K].next(L))) {
  1239. set_constant(*L, *K, p_other->constant_map[*K][*L]);
  1240. }
  1241. }
  1242. }
  1243. // Fonts.
  1244. {
  1245. const StringName *K = nullptr;
  1246. while ((K = p_other->font_map.next(K))) {
  1247. const StringName *L = nullptr;
  1248. while ((L = p_other->font_map[*K].next(L))) {
  1249. set_font(*L, *K, p_other->font_map[*K][*L]);
  1250. }
  1251. }
  1252. }
  1253. // Icons.
  1254. {
  1255. const StringName *K = nullptr;
  1256. while ((K = p_other->icon_map.next(K))) {
  1257. const StringName *L = nullptr;
  1258. while ((L = p_other->icon_map[*K].next(L))) {
  1259. set_icon(*L, *K, p_other->icon_map[*K][*L]);
  1260. }
  1261. }
  1262. }
  1263. // Shaders.
  1264. {
  1265. const StringName *K = nullptr;
  1266. while ((K = p_other->shader_map.next(K))) {
  1267. const StringName *L = nullptr;
  1268. while ((L = p_other->shader_map[*K].next(L))) {
  1269. set_shader(*L, *K, p_other->shader_map[*K][*L]);
  1270. }
  1271. }
  1272. }
  1273. // Styleboxes.
  1274. {
  1275. const StringName *K = nullptr;
  1276. while ((K = p_other->style_map.next(K))) {
  1277. const StringName *L = nullptr;
  1278. while ((L = p_other->style_map[*K].next(L))) {
  1279. set_stylebox(*L, *K, p_other->style_map[*K][*L]);
  1280. }
  1281. }
  1282. }
  1283. // Type variations.
  1284. {
  1285. const StringName *K = nullptr;
  1286. while ((K = p_other->variation_map.next(K))) {
  1287. set_type_variation(*K, p_other->variation_map[*K]);
  1288. }
  1289. }
  1290. _unfreeze_and_propagate_changes();
  1291. }
  1292. void Theme::clear() {
  1293. //these need disconnecting
  1294. {
  1295. const StringName *K = nullptr;
  1296. while ((K = icon_map.next(K))) {
  1297. const StringName *L = nullptr;
  1298. while ((L = icon_map[*K].next(L))) {
  1299. Ref<Texture> icon = icon_map[*K][*L];
  1300. if (icon.is_valid()) {
  1301. icon->disconnect("changed", this, "_emit_theme_changed");
  1302. }
  1303. }
  1304. }
  1305. }
  1306. {
  1307. const StringName *K = nullptr;
  1308. while ((K = style_map.next(K))) {
  1309. const StringName *L = nullptr;
  1310. while ((L = style_map[*K].next(L))) {
  1311. Ref<StyleBox> style = style_map[*K][*L];
  1312. if (style.is_valid()) {
  1313. style->disconnect("changed", this, "_emit_theme_changed");
  1314. }
  1315. }
  1316. }
  1317. }
  1318. {
  1319. const StringName *K = nullptr;
  1320. while ((K = font_map.next(K))) {
  1321. const StringName *L = nullptr;
  1322. while ((L = font_map[*K].next(L))) {
  1323. Ref<Font> font = font_map[*K][*L];
  1324. if (font.is_valid()) {
  1325. font->disconnect("changed", this, "_emit_theme_changed");
  1326. }
  1327. }
  1328. }
  1329. }
  1330. icon_map.clear();
  1331. style_map.clear();
  1332. font_map.clear();
  1333. shader_map.clear();
  1334. color_map.clear();
  1335. constant_map.clear();
  1336. variation_map.clear();
  1337. variation_base_map.clear();
  1338. _emit_theme_changed(true);
  1339. }
  1340. void Theme::_bind_methods() {
  1341. ClassDB::bind_method(D_METHOD("set_icon", "name", "theme_type", "texture"), &Theme::set_icon);
  1342. ClassDB::bind_method(D_METHOD("get_icon", "name", "theme_type"), &Theme::get_icon);
  1343. ClassDB::bind_method(D_METHOD("has_icon", "name", "theme_type"), &Theme::has_icon);
  1344. ClassDB::bind_method(D_METHOD("rename_icon", "old_name", "name", "theme_type"), &Theme::rename_icon);
  1345. ClassDB::bind_method(D_METHOD("clear_icon", "name", "theme_type"), &Theme::clear_icon);
  1346. ClassDB::bind_method(D_METHOD("get_icon_list", "theme_type"), &Theme::_get_icon_list);
  1347. ClassDB::bind_method(D_METHOD("get_icon_types"), &Theme::_get_icon_types);
  1348. ClassDB::bind_method(D_METHOD("set_stylebox", "name", "theme_type", "texture"), &Theme::set_stylebox);
  1349. ClassDB::bind_method(D_METHOD("get_stylebox", "name", "theme_type"), &Theme::get_stylebox);
  1350. ClassDB::bind_method(D_METHOD("has_stylebox", "name", "theme_type"), &Theme::has_stylebox);
  1351. ClassDB::bind_method(D_METHOD("rename_stylebox", "old_name", "name", "theme_type"), &Theme::rename_stylebox);
  1352. ClassDB::bind_method(D_METHOD("clear_stylebox", "name", "theme_type"), &Theme::clear_stylebox);
  1353. ClassDB::bind_method(D_METHOD("get_stylebox_list", "theme_type"), &Theme::_get_stylebox_list);
  1354. ClassDB::bind_method(D_METHOD("get_stylebox_types"), &Theme::_get_stylebox_types);
  1355. ClassDB::bind_method(D_METHOD("set_font", "name", "theme_type", "font"), &Theme::set_font);
  1356. ClassDB::bind_method(D_METHOD("get_font", "name", "theme_type"), &Theme::get_font);
  1357. ClassDB::bind_method(D_METHOD("has_font", "name", "theme_type"), &Theme::has_font);
  1358. ClassDB::bind_method(D_METHOD("rename_font", "old_name", "name", "theme_type"), &Theme::rename_font);
  1359. ClassDB::bind_method(D_METHOD("clear_font", "name", "theme_type"), &Theme::clear_font);
  1360. ClassDB::bind_method(D_METHOD("get_font_list", "theme_type"), &Theme::_get_font_list);
  1361. ClassDB::bind_method(D_METHOD("get_font_types"), &Theme::_get_font_types);
  1362. ClassDB::bind_method(D_METHOD("set_color", "name", "theme_type", "color"), &Theme::set_color);
  1363. ClassDB::bind_method(D_METHOD("get_color", "name", "theme_type"), &Theme::get_color);
  1364. ClassDB::bind_method(D_METHOD("has_color", "name", "theme_type"), &Theme::has_color);
  1365. ClassDB::bind_method(D_METHOD("rename_color", "old_name", "name", "theme_type"), &Theme::rename_color);
  1366. ClassDB::bind_method(D_METHOD("clear_color", "name", "theme_type"), &Theme::clear_color);
  1367. ClassDB::bind_method(D_METHOD("get_color_list", "theme_type"), &Theme::_get_color_list);
  1368. ClassDB::bind_method(D_METHOD("get_color_types"), &Theme::_get_color_types);
  1369. ClassDB::bind_method(D_METHOD("set_constant", "name", "theme_type", "constant"), &Theme::set_constant);
  1370. ClassDB::bind_method(D_METHOD("get_constant", "name", "theme_type"), &Theme::get_constant);
  1371. ClassDB::bind_method(D_METHOD("has_constant", "name", "theme_type"), &Theme::has_constant);
  1372. ClassDB::bind_method(D_METHOD("rename_constant", "old_name", "name", "theme_type"), &Theme::rename_constant);
  1373. ClassDB::bind_method(D_METHOD("clear_constant", "name", "theme_type"), &Theme::clear_constant);
  1374. ClassDB::bind_method(D_METHOD("get_constant_list", "theme_type"), &Theme::_get_constant_list);
  1375. ClassDB::bind_method(D_METHOD("get_constant_types"), &Theme::_get_constant_types);
  1376. ClassDB::bind_method(D_METHOD("set_default_font", "font"), &Theme::set_default_theme_font);
  1377. ClassDB::bind_method(D_METHOD("get_default_font"), &Theme::get_default_theme_font);
  1378. ClassDB::bind_method(D_METHOD("has_default_font"), &Theme::has_default_theme_font);
  1379. ClassDB::bind_method(D_METHOD("set_theme_item", "data_type", "name", "theme_type", "value"), &Theme::set_theme_item);
  1380. ClassDB::bind_method(D_METHOD("get_theme_item", "data_type", "name", "theme_type"), &Theme::get_theme_item);
  1381. ClassDB::bind_method(D_METHOD("has_theme_item", "data_type", "name", "theme_type"), &Theme::has_theme_item);
  1382. ClassDB::bind_method(D_METHOD("rename_theme_item", "data_type", "old_name", "name", "theme_type"), &Theme::rename_theme_item);
  1383. ClassDB::bind_method(D_METHOD("clear_theme_item", "data_type", "name", "theme_type"), &Theme::clear_theme_item);
  1384. ClassDB::bind_method(D_METHOD("get_theme_item_list", "data_type", "theme_type"), &Theme::_get_theme_item_list);
  1385. ClassDB::bind_method(D_METHOD("get_theme_item_types", "data_type"), &Theme::_get_theme_item_types);
  1386. ClassDB::bind_method(D_METHOD("set_type_variation", "theme_type", "base_type"), &Theme::set_type_variation);
  1387. ClassDB::bind_method(D_METHOD("is_type_variation", "theme_type", "base_type"), &Theme::is_type_variation);
  1388. ClassDB::bind_method(D_METHOD("clear_type_variation", "theme_type"), &Theme::clear_type_variation);
  1389. ClassDB::bind_method(D_METHOD("get_type_variation_base", "theme_type"), &Theme::get_type_variation_base);
  1390. ClassDB::bind_method(D_METHOD("get_type_variation_list", "base_type"), &Theme::_get_type_variation_list);
  1391. ClassDB::bind_method(D_METHOD("add_type", "theme_type"), &Theme::add_type);
  1392. ClassDB::bind_method(D_METHOD("remove_type", "theme_type"), &Theme::remove_type);
  1393. ClassDB::bind_method(D_METHOD("get_type_list", "theme_type"), &Theme::_get_type_list);
  1394. ClassDB::bind_method(D_METHOD("_emit_theme_changed", "notify_list_changed"), &Theme::_emit_theme_changed, DEFVAL(false));
  1395. ClassDB::bind_method("copy_default_theme", &Theme::copy_default_theme);
  1396. ClassDB::bind_method(D_METHOD("copy_theme", "other"), &Theme::copy_theme);
  1397. ClassDB::bind_method(D_METHOD("merge_with", "other"), &Theme::merge_with);
  1398. ClassDB::bind_method(D_METHOD("clear"), &Theme::clear);
  1399. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "default_font", PROPERTY_HINT_RESOURCE_TYPE, "Font"), "set_default_font", "get_default_font");
  1400. BIND_ENUM_CONSTANT(DATA_TYPE_COLOR);
  1401. BIND_ENUM_CONSTANT(DATA_TYPE_CONSTANT);
  1402. BIND_ENUM_CONSTANT(DATA_TYPE_FONT);
  1403. BIND_ENUM_CONSTANT(DATA_TYPE_ICON);
  1404. BIND_ENUM_CONSTANT(DATA_TYPE_STYLEBOX);
  1405. BIND_ENUM_CONSTANT(DATA_TYPE_MAX);
  1406. }
  1407. Theme::Theme() {
  1408. }
  1409. Theme::~Theme() {
  1410. }