control.cpp 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145
  1. /*************************************************************************/
  2. /* control.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 "control.h"
  31. #include "container.h"
  32. #include "core/config/project_settings.h"
  33. #include "core/math/geometry_2d.h"
  34. #include "core/object/message_queue.h"
  35. #include "core/os/keyboard.h"
  36. #include "core/os/os.h"
  37. #include "core/string/print_string.h"
  38. #include "core/string/translation.h"
  39. #include "scene/gui/label.h"
  40. #include "scene/gui/panel.h"
  41. #include "scene/main/canvas_layer.h"
  42. #include "scene/main/window.h"
  43. #include "scene/scene_string_names.h"
  44. #include "servers/rendering_server.h"
  45. #include "servers/text_server.h"
  46. #ifdef TOOLS_ENABLED
  47. #include "editor/plugins/canvas_item_editor_plugin.h"
  48. #endif
  49. #ifdef TOOLS_ENABLED
  50. Dictionary Control::_edit_get_state() const {
  51. Dictionary s;
  52. s["rotation"] = get_rotation();
  53. s["scale"] = get_scale();
  54. s["pivot"] = get_pivot_offset();
  55. Array anchors;
  56. anchors.push_back(get_anchor(SIDE_LEFT));
  57. anchors.push_back(get_anchor(SIDE_TOP));
  58. anchors.push_back(get_anchor(SIDE_RIGHT));
  59. anchors.push_back(get_anchor(SIDE_BOTTOM));
  60. s["anchors"] = anchors;
  61. Array offsets;
  62. offsets.push_back(get_offset(SIDE_LEFT));
  63. offsets.push_back(get_offset(SIDE_TOP));
  64. offsets.push_back(get_offset(SIDE_RIGHT));
  65. offsets.push_back(get_offset(SIDE_BOTTOM));
  66. s["offsets"] = offsets;
  67. return s;
  68. }
  69. void Control::_edit_set_state(const Dictionary &p_state) {
  70. ERR_FAIL_COND((p_state.size() <= 0) ||
  71. !p_state.has("rotation") || !p_state.has("scale") ||
  72. !p_state.has("pivot") || !p_state.has("anchors") || !p_state.has("offsets"));
  73. Dictionary state = p_state;
  74. set_rotation(state["rotation"]);
  75. set_scale(state["scale"]);
  76. set_pivot_offset(state["pivot"]);
  77. Array anchors = state["anchors"];
  78. data.anchor[SIDE_LEFT] = anchors[0];
  79. data.anchor[SIDE_TOP] = anchors[1];
  80. data.anchor[SIDE_RIGHT] = anchors[2];
  81. data.anchor[SIDE_BOTTOM] = anchors[3];
  82. Array offsets = state["offsets"];
  83. data.offset[SIDE_LEFT] = offsets[0];
  84. data.offset[SIDE_TOP] = offsets[1];
  85. data.offset[SIDE_RIGHT] = offsets[2];
  86. data.offset[SIDE_BOTTOM] = offsets[3];
  87. _size_changed();
  88. }
  89. void Control::_edit_set_position(const Point2 &p_position) {
  90. #ifdef TOOLS_ENABLED
  91. ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins.");
  92. set_position(p_position, CanvasItemEditor::get_singleton()->is_anchors_mode_enabled() && Object::cast_to<Control>(data.parent));
  93. #else
  94. // Unlikely to happen. TODO: enclose all _edit_ functions into TOOLS_ENABLED
  95. set_position(p_position);
  96. #endif
  97. };
  98. Point2 Control::_edit_get_position() const {
  99. return get_position();
  100. };
  101. void Control::_edit_set_scale(const Size2 &p_scale) {
  102. set_scale(p_scale);
  103. }
  104. Size2 Control::_edit_get_scale() const {
  105. return data.scale;
  106. }
  107. void Control::_edit_set_rect(const Rect2 &p_edit_rect) {
  108. #ifdef TOOLS_ENABLED
  109. ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins.");
  110. set_position((get_position() + get_transform().basis_xform(p_edit_rect.position)).snapped(Vector2(1, 1)), CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
  111. set_size(p_edit_rect.size.snapped(Vector2(1, 1)), CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
  112. #else
  113. // Unlikely to happen. TODO: enclose all _edit_ functions into TOOLS_ENABLED
  114. set_position((get_position() + get_transform().basis_xform(p_edit_rect.position)).snapped(Vector2(1, 1)));
  115. set_size(p_edit_rect.size.snapped(Vector2(1, 1)));
  116. #endif
  117. }
  118. Rect2 Control::_edit_get_rect() const {
  119. return Rect2(Point2(), get_size());
  120. }
  121. bool Control::_edit_use_rect() const {
  122. return true;
  123. }
  124. void Control::_edit_set_rotation(real_t p_rotation) {
  125. set_rotation(p_rotation);
  126. }
  127. real_t Control::_edit_get_rotation() const {
  128. return get_rotation();
  129. }
  130. bool Control::_edit_use_rotation() const {
  131. return true;
  132. }
  133. void Control::_edit_set_pivot(const Point2 &p_pivot) {
  134. Vector2 delta_pivot = p_pivot - get_pivot_offset();
  135. Vector2 move = Vector2((cos(data.rotation) - 1.0) * delta_pivot.x - sin(data.rotation) * delta_pivot.y, sin(data.rotation) * delta_pivot.x + (cos(data.rotation) - 1.0) * delta_pivot.y);
  136. set_position(get_position() + move);
  137. set_pivot_offset(p_pivot);
  138. }
  139. Point2 Control::_edit_get_pivot() const {
  140. return get_pivot_offset();
  141. }
  142. bool Control::_edit_use_pivot() const {
  143. return true;
  144. }
  145. Size2 Control::_edit_get_minimum_size() const {
  146. return get_combined_minimum_size();
  147. }
  148. #endif
  149. String Control::properties_managed_by_container[] = {
  150. "offset_left",
  151. "offset_top",
  152. "offset_right",
  153. "offset_bottom",
  154. "anchor_left",
  155. "anchor_top",
  156. "anchor_right",
  157. "anchor_bottom",
  158. "rect_position",
  159. "rect_scale",
  160. "rect_size"
  161. };
  162. void Control::accept_event() {
  163. if (is_inside_tree()) {
  164. get_viewport()->_gui_accept_event();
  165. }
  166. }
  167. void Control::set_custom_minimum_size(const Size2 &p_custom) {
  168. if (p_custom == data.custom_minimum_size) {
  169. return;
  170. }
  171. data.custom_minimum_size = p_custom;
  172. minimum_size_changed();
  173. }
  174. Size2 Control::get_custom_minimum_size() const {
  175. return data.custom_minimum_size;
  176. }
  177. void Control::_update_minimum_size_cache() {
  178. Size2 minsize = get_minimum_size();
  179. minsize.x = MAX(minsize.x, data.custom_minimum_size.x);
  180. minsize.y = MAX(minsize.y, data.custom_minimum_size.y);
  181. bool size_changed = false;
  182. if (data.minimum_size_cache != minsize) {
  183. size_changed = true;
  184. }
  185. data.minimum_size_cache = minsize;
  186. data.minimum_size_valid = true;
  187. if (size_changed) {
  188. minimum_size_changed();
  189. }
  190. }
  191. Size2 Control::get_combined_minimum_size() const {
  192. if (!data.minimum_size_valid) {
  193. const_cast<Control *>(this)->_update_minimum_size_cache();
  194. }
  195. return data.minimum_size_cache;
  196. }
  197. Transform2D Control::_get_internal_transform() const {
  198. Transform2D rot_scale;
  199. rot_scale.set_rotation_and_scale(data.rotation, data.scale);
  200. Transform2D offset;
  201. offset.set_origin(-data.pivot_offset);
  202. return offset.affine_inverse() * (rot_scale * offset);
  203. }
  204. bool Control::_set(const StringName &p_name, const Variant &p_value) {
  205. String name = p_name;
  206. // Prefixes "custom_*" are supported for compatibility with 3.x.
  207. if (!name.begins_with("theme_override") && !name.begins_with("custom")) {
  208. return false;
  209. }
  210. if (p_value.get_type() == Variant::NIL) {
  211. if (name.begins_with("theme_override_icons/") || name.begins_with("custom_icons/")) {
  212. String dname = name.get_slicec('/', 1);
  213. if (data.icon_override.has(dname)) {
  214. data.icon_override[dname]->disconnect("changed", callable_mp(this, &Control::_override_changed));
  215. }
  216. data.icon_override.erase(dname);
  217. notification(NOTIFICATION_THEME_CHANGED);
  218. } else if (name.begins_with("theme_override_styles/") || name.begins_with("custom_styles/")) {
  219. String dname = name.get_slicec('/', 1);
  220. if (data.style_override.has(dname)) {
  221. data.style_override[dname]->disconnect("changed", callable_mp(this, &Control::_override_changed));
  222. }
  223. data.style_override.erase(dname);
  224. notification(NOTIFICATION_THEME_CHANGED);
  225. } else if (name.begins_with("theme_override_fonts/") || name.begins_with("custom_fonts/")) {
  226. String dname = name.get_slicec('/', 1);
  227. if (data.font_override.has(dname)) {
  228. data.font_override[dname]->disconnect("changed", callable_mp(this, &Control::_override_changed));
  229. }
  230. data.font_override.erase(dname);
  231. notification(NOTIFICATION_THEME_CHANGED);
  232. } else if (name.begins_with("theme_override_font_sizes/") || name.begins_with("custom_font_sizes/")) {
  233. String dname = name.get_slicec('/', 1);
  234. data.font_size_override.erase(dname);
  235. notification(NOTIFICATION_THEME_CHANGED);
  236. } else if (name.begins_with("theme_override_colors/") || name.begins_with("custom_colors/")) {
  237. String dname = name.get_slicec('/', 1);
  238. data.color_override.erase(dname);
  239. notification(NOTIFICATION_THEME_CHANGED);
  240. } else if (name.begins_with("theme_override_constants/") || name.begins_with("custom_constants/")) {
  241. String dname = name.get_slicec('/', 1);
  242. data.constant_override.erase(dname);
  243. notification(NOTIFICATION_THEME_CHANGED);
  244. } else {
  245. return false;
  246. }
  247. } else {
  248. if (name.begins_with("theme_override_icons/") || name.begins_with("custom_icons/")) {
  249. String dname = name.get_slicec('/', 1);
  250. add_theme_icon_override(dname, p_value);
  251. } else if (name.begins_with("theme_override_styles/") || name.begins_with("custom_styles/")) {
  252. String dname = name.get_slicec('/', 1);
  253. add_theme_style_override(dname, p_value);
  254. } else if (name.begins_with("theme_override_fonts/") || name.begins_with("custom_fonts/")) {
  255. String dname = name.get_slicec('/', 1);
  256. add_theme_font_override(dname, p_value);
  257. } else if (name.begins_with("theme_override_font_sizes/") || name.begins_with("custom_font_sizes/")) {
  258. String dname = name.get_slicec('/', 1);
  259. add_theme_font_size_override(dname, p_value);
  260. } else if (name.begins_with("theme_override_colors/") || name.begins_with("custom_colors/")) {
  261. String dname = name.get_slicec('/', 1);
  262. add_theme_color_override(dname, p_value);
  263. } else if (name.begins_with("theme_override_constants/") || name.begins_with("custom_constants/")) {
  264. String dname = name.get_slicec('/', 1);
  265. add_theme_constant_override(dname, p_value);
  266. } else {
  267. return false;
  268. }
  269. }
  270. return true;
  271. }
  272. void Control::_update_minimum_size() {
  273. if (!is_inside_tree()) {
  274. return;
  275. }
  276. Size2 minsize = get_combined_minimum_size();
  277. data.updating_last_minimum_size = false;
  278. if (minsize != data.last_minimum_size) {
  279. data.last_minimum_size = minsize;
  280. _size_changed();
  281. emit_signal(SceneStringNames::get_singleton()->minimum_size_changed);
  282. }
  283. }
  284. bool Control::_get(const StringName &p_name, Variant &r_ret) const {
  285. String sname = p_name;
  286. if (!sname.begins_with("theme_override")) {
  287. return false;
  288. }
  289. if (sname.begins_with("theme_override_icons/")) {
  290. String name = sname.get_slicec('/', 1);
  291. r_ret = data.icon_override.has(name) ? Variant(data.icon_override[name]) : Variant();
  292. } else if (sname.begins_with("theme_override_styles/")) {
  293. String name = sname.get_slicec('/', 1);
  294. r_ret = data.style_override.has(name) ? Variant(data.style_override[name]) : Variant();
  295. } else if (sname.begins_with("theme_override_fonts/")) {
  296. String name = sname.get_slicec('/', 1);
  297. r_ret = data.font_override.has(name) ? Variant(data.font_override[name]) : Variant();
  298. } else if (sname.begins_with("theme_override_font_sizes/")) {
  299. String name = sname.get_slicec('/', 1);
  300. r_ret = data.font_size_override.has(name) ? Variant(data.font_size_override[name]) : Variant();
  301. } else if (sname.begins_with("theme_override_colors/")) {
  302. String name = sname.get_slicec('/', 1);
  303. r_ret = data.color_override.has(name) ? Variant(data.color_override[name]) : Variant();
  304. } else if (sname.begins_with("theme_override_constants/")) {
  305. String name = sname.get_slicec('/', 1);
  306. r_ret = data.constant_override.has(name) ? Variant(data.constant_override[name]) : Variant();
  307. } else {
  308. return false;
  309. }
  310. return true;
  311. }
  312. void Control::_get_property_list(List<PropertyInfo> *p_list) const {
  313. Ref<Theme> theme = Theme::get_default();
  314. p_list->push_back(PropertyInfo(Variant::NIL, "Theme Overrides", PROPERTY_HINT_NONE, "theme_override_", PROPERTY_USAGE_GROUP));
  315. {
  316. List<StringName> names;
  317. theme->get_color_list(get_class_name(), &names);
  318. for (const StringName &E : names) {
  319. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  320. if (data.color_override.has(E)) {
  321. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  322. }
  323. p_list->push_back(PropertyInfo(Variant::COLOR, "theme_override_colors/" + E, PROPERTY_HINT_NONE, "", usage));
  324. }
  325. }
  326. {
  327. List<StringName> names;
  328. theme->get_constant_list(get_class_name(), &names);
  329. for (const StringName &E : names) {
  330. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  331. if (data.constant_override.has(E)) {
  332. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  333. }
  334. p_list->push_back(PropertyInfo(Variant::INT, "theme_override_constants/" + E, PROPERTY_HINT_RANGE, "-16384,16384", usage));
  335. }
  336. }
  337. {
  338. List<StringName> names;
  339. theme->get_font_list(get_class_name(), &names);
  340. for (const StringName &E : names) {
  341. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  342. if (data.font_override.has(E)) {
  343. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  344. }
  345. p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_fonts/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Font", usage));
  346. }
  347. }
  348. {
  349. List<StringName> names;
  350. theme->get_font_size_list(get_class_name(), &names);
  351. for (const StringName &E : names) {
  352. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  353. if (data.font_size_override.has(E)) {
  354. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  355. }
  356. p_list->push_back(PropertyInfo(Variant::INT, "theme_override_font_sizes/" + E, PROPERTY_HINT_RANGE, "1,256,1,or_greater", usage));
  357. }
  358. }
  359. {
  360. List<StringName> names;
  361. theme->get_icon_list(get_class_name(), &names);
  362. for (const StringName &E : names) {
  363. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  364. if (data.icon_override.has(E)) {
  365. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  366. }
  367. p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_icons/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage));
  368. }
  369. }
  370. {
  371. List<StringName> names;
  372. theme->get_stylebox_list(get_class_name(), &names);
  373. for (const StringName &E : names) {
  374. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  375. if (data.style_override.has(E)) {
  376. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  377. }
  378. p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_styles/" + E, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage));
  379. }
  380. }
  381. }
  382. void Control::_validate_property(PropertyInfo &property) const {
  383. if (property.name == "theme_type_variation") {
  384. List<StringName> names;
  385. // Only the default theme and the project theme are used for the list of options.
  386. // This is an imposed limitation to simplify the logic needed to leverage those options.
  387. Theme::get_default()->get_type_variation_list(get_class_name(), &names);
  388. if (Theme::get_project_default().is_valid()) {
  389. Theme::get_project_default()->get_type_variation_list(get_class_name(), &names);
  390. }
  391. names.sort_custom<StringName::AlphCompare>();
  392. Vector<StringName> unique_names;
  393. String hint_string;
  394. for (const StringName &E : names) {
  395. // Skip duplicate values.
  396. if (unique_names.has(E)) {
  397. continue;
  398. }
  399. hint_string += String(E) + ",";
  400. unique_names.append(E);
  401. }
  402. property.hint_string = hint_string;
  403. }
  404. if (!Object::cast_to<Container>(get_parent())) {
  405. return;
  406. }
  407. // Disable the property if it's managed by the parent container.
  408. bool property_is_managed_by_container = false;
  409. for (unsigned i = 0; i < properties_managed_by_container_count; i++) {
  410. property_is_managed_by_container = properties_managed_by_container[i] == property.name;
  411. if (property_is_managed_by_container) {
  412. break;
  413. }
  414. }
  415. if (property_is_managed_by_container) {
  416. property.usage |= PROPERTY_USAGE_READ_ONLY;
  417. }
  418. }
  419. Control *Control::get_parent_control() const {
  420. return data.parent;
  421. }
  422. Window *Control::get_parent_window() const {
  423. return data.parent_window;
  424. }
  425. void Control::set_layout_direction(Control::LayoutDirection p_direction) {
  426. ERR_FAIL_INDEX((int)p_direction, 4);
  427. data.layout_dir = p_direction;
  428. data.is_rtl_dirty = true;
  429. propagate_notification(NOTIFICATION_LAYOUT_DIRECTION_CHANGED);
  430. }
  431. Control::LayoutDirection Control::get_layout_direction() const {
  432. return data.layout_dir;
  433. }
  434. bool Control::is_layout_rtl() const {
  435. if (data.is_rtl_dirty) {
  436. const_cast<Control *>(this)->data.is_rtl_dirty = false;
  437. if (data.layout_dir == LAYOUT_DIRECTION_INHERITED) {
  438. Window *parent_window = get_parent_window();
  439. Control *parent_control = get_parent_control();
  440. if (parent_control) {
  441. const_cast<Control *>(this)->data.is_rtl = parent_control->is_layout_rtl();
  442. } else if (parent_window) {
  443. const_cast<Control *>(this)->data.is_rtl = parent_window->is_layout_rtl();
  444. } else {
  445. if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
  446. const_cast<Control *>(this)->data.is_rtl = true;
  447. } else {
  448. String locale = TranslationServer::get_singleton()->get_tool_locale();
  449. const_cast<Control *>(this)->data.is_rtl = TS->is_locale_right_to_left(locale);
  450. }
  451. }
  452. } else if (data.layout_dir == LAYOUT_DIRECTION_LOCALE) {
  453. if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
  454. const_cast<Control *>(this)->data.is_rtl = true;
  455. } else {
  456. String locale = TranslationServer::get_singleton()->get_tool_locale();
  457. const_cast<Control *>(this)->data.is_rtl = TS->is_locale_right_to_left(locale);
  458. }
  459. } else {
  460. const_cast<Control *>(this)->data.is_rtl = (data.layout_dir == LAYOUT_DIRECTION_RTL);
  461. }
  462. }
  463. return data.is_rtl;
  464. }
  465. void Control::set_auto_translate(bool p_enable) {
  466. if (p_enable == data.auto_translate) {
  467. return;
  468. }
  469. data.auto_translate = p_enable;
  470. notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED);
  471. }
  472. bool Control::is_auto_translating() const {
  473. return data.auto_translate;
  474. }
  475. void Control::_clear_size_warning() {
  476. data.size_warning = false;
  477. }
  478. //moved theme configuration here, so controls can set up even if still not inside active scene
  479. void Control::add_child_notify(Node *p_child) {
  480. Control *child_c = Object::cast_to<Control>(p_child);
  481. if (child_c && child_c->data.theme.is_null() && (data.theme_owner || data.theme_owner_window)) {
  482. _propagate_theme_changed(child_c, data.theme_owner, data.theme_owner_window); //need to propagate here, since many controls may require setting up stuff
  483. }
  484. Window *child_w = Object::cast_to<Window>(p_child);
  485. if (child_w && child_w->theme.is_null() && (data.theme_owner || data.theme_owner_window)) {
  486. _propagate_theme_changed(child_w, data.theme_owner, data.theme_owner_window); //need to propagate here, since many controls may require setting up stuff
  487. }
  488. }
  489. void Control::remove_child_notify(Node *p_child) {
  490. Control *child_c = Object::cast_to<Control>(p_child);
  491. if (child_c && (child_c->data.theme_owner || child_c->data.theme_owner_window) && child_c->data.theme.is_null()) {
  492. _propagate_theme_changed(child_c, nullptr, nullptr);
  493. }
  494. Window *child_w = Object::cast_to<Window>(p_child);
  495. if (child_w && (child_w->theme_owner || child_w->theme_owner_window) && child_w->theme.is_null()) {
  496. _propagate_theme_changed(child_w, nullptr, nullptr);
  497. }
  498. }
  499. void Control::_update_canvas_item_transform() {
  500. Transform2D xform = _get_internal_transform();
  501. xform[2] += get_position();
  502. RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform);
  503. }
  504. void Control::_notification(int p_notification) {
  505. switch (p_notification) {
  506. case NOTIFICATION_ENTER_TREE: {
  507. } break;
  508. case NOTIFICATION_POST_ENTER_TREE: {
  509. data.minimum_size_valid = false;
  510. data.is_rtl_dirty = true;
  511. _size_changed();
  512. } break;
  513. case NOTIFICATION_EXIT_TREE: {
  514. get_viewport()->_gui_remove_control(this);
  515. } break;
  516. case NOTIFICATION_READY: {
  517. #ifdef DEBUG_ENABLED
  518. connect("ready", callable_mp(this, &Control::_clear_size_warning), varray(), CONNECT_DEFERRED | CONNECT_ONESHOT);
  519. #endif
  520. } break;
  521. case NOTIFICATION_ENTER_CANVAS: {
  522. data.parent = Object::cast_to<Control>(get_parent());
  523. data.parent_window = Object::cast_to<Window>(get_parent());
  524. data.is_rtl_dirty = true;
  525. Node *parent = this; //meh
  526. Control *parent_control = nullptr;
  527. bool subwindow = false;
  528. while (parent) {
  529. parent = parent->get_parent();
  530. if (!parent) {
  531. break;
  532. }
  533. CanvasItem *ci = Object::cast_to<CanvasItem>(parent);
  534. if (ci && ci->is_set_as_top_level()) {
  535. subwindow = true;
  536. break;
  537. }
  538. parent_control = Object::cast_to<Control>(parent);
  539. if (parent_control) {
  540. break;
  541. } else if (ci) {
  542. } else {
  543. break;
  544. }
  545. }
  546. if (parent_control && !subwindow) {
  547. //do nothing, has a parent control and not top_level
  548. if (data.theme.is_null() && parent_control->data.theme_owner) {
  549. data.theme_owner = parent_control->data.theme_owner;
  550. notification(NOTIFICATION_THEME_CHANGED);
  551. }
  552. } else {
  553. //is a regular root control or top_level
  554. Viewport *viewport = get_viewport();
  555. ERR_FAIL_COND(!viewport);
  556. data.RI = viewport->_gui_add_root_control(this);
  557. }
  558. data.parent_canvas_item = get_parent_item();
  559. if (data.parent_canvas_item) {
  560. data.parent_canvas_item->connect("item_rect_changed", callable_mp(this, &Control::_size_changed));
  561. } else {
  562. //connect viewport
  563. Viewport *viewport = get_viewport();
  564. ERR_FAIL_COND(!viewport);
  565. viewport->connect("size_changed", callable_mp(this, &Control::_size_changed));
  566. }
  567. } break;
  568. case NOTIFICATION_EXIT_CANVAS: {
  569. if (data.parent_canvas_item) {
  570. data.parent_canvas_item->disconnect("item_rect_changed", callable_mp(this, &Control::_size_changed));
  571. data.parent_canvas_item = nullptr;
  572. } else if (!is_set_as_top_level()) {
  573. //disconnect viewport
  574. Viewport *viewport = get_viewport();
  575. ERR_FAIL_COND(!viewport);
  576. viewport->disconnect("size_changed", callable_mp(this, &Control::_size_changed));
  577. }
  578. if (data.RI) {
  579. get_viewport()->_gui_remove_root_control(data.RI);
  580. data.RI = nullptr;
  581. }
  582. data.parent = nullptr;
  583. data.parent_canvas_item = nullptr;
  584. data.parent_window = nullptr;
  585. data.is_rtl_dirty = true;
  586. } break;
  587. case NOTIFICATION_MOVED_IN_PARENT: {
  588. // some parents need to know the order of the children to draw (like TabContainer)
  589. // update if necessary
  590. if (data.parent) {
  591. data.parent->update();
  592. }
  593. update();
  594. if (data.RI) {
  595. get_viewport()->_gui_set_root_order_dirty();
  596. }
  597. } break;
  598. case NOTIFICATION_RESIZED: {
  599. emit_signal(SceneStringNames::get_singleton()->resized);
  600. } break;
  601. case NOTIFICATION_DRAW: {
  602. _update_canvas_item_transform();
  603. RenderingServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size()));
  604. RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents);
  605. //emit_signal(SceneStringNames::get_singleton()->draw);
  606. } break;
  607. case NOTIFICATION_MOUSE_ENTER: {
  608. emit_signal(SceneStringNames::get_singleton()->mouse_entered);
  609. } break;
  610. case NOTIFICATION_MOUSE_EXIT: {
  611. emit_signal(SceneStringNames::get_singleton()->mouse_exited);
  612. } break;
  613. case NOTIFICATION_FOCUS_ENTER: {
  614. emit_signal(SceneStringNames::get_singleton()->focus_entered);
  615. update();
  616. } break;
  617. case NOTIFICATION_FOCUS_EXIT: {
  618. emit_signal(SceneStringNames::get_singleton()->focus_exited);
  619. update();
  620. } break;
  621. case NOTIFICATION_THEME_CHANGED: {
  622. minimum_size_changed();
  623. update();
  624. } break;
  625. case NOTIFICATION_VISIBILITY_CHANGED: {
  626. if (!is_visible_in_tree()) {
  627. if (get_viewport() != nullptr) {
  628. get_viewport()->_gui_hide_control(this);
  629. }
  630. //remove key focus
  631. } else {
  632. data.minimum_size_valid = false;
  633. _size_changed();
  634. }
  635. } break;
  636. case NOTIFICATION_TRANSLATION_CHANGED:
  637. case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
  638. data.is_rtl_dirty = true;
  639. _size_changed();
  640. } break;
  641. }
  642. }
  643. bool Control::has_point(const Point2 &p_point) const {
  644. bool ret;
  645. if (GDVIRTUAL_CALL(_has_point, p_point, ret)) {
  646. return ret;
  647. }
  648. return Rect2(Point2(), get_size()).has_point(p_point);
  649. }
  650. void Control::set_drag_forwarding(Object *p_target) {
  651. if (p_target) {
  652. data.drag_owner = p_target->get_instance_id();
  653. } else {
  654. data.drag_owner = ObjectID();
  655. }
  656. }
  657. Variant Control::get_drag_data(const Point2 &p_point) {
  658. if (data.drag_owner.is_valid()) {
  659. Object *obj = ObjectDB::get_instance(data.drag_owner);
  660. if (obj) {
  661. return obj->call("_get_drag_data_fw", p_point, this);
  662. }
  663. }
  664. Variant dd;
  665. if (GDVIRTUAL_CALL(_get_drag_data, p_point, dd)) {
  666. return dd;
  667. }
  668. return Variant();
  669. }
  670. bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
  671. if (data.drag_owner.is_valid()) {
  672. Object *obj = ObjectDB::get_instance(data.drag_owner);
  673. if (obj) {
  674. return obj->call("_can_drop_data_fw", p_point, p_data, this);
  675. }
  676. }
  677. bool ret;
  678. if (GDVIRTUAL_CALL(_can_drop_data, p_point, p_data, ret)) {
  679. return ret;
  680. }
  681. return false;
  682. }
  683. void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
  684. if (data.drag_owner.is_valid()) {
  685. Object *obj = ObjectDB::get_instance(data.drag_owner);
  686. if (obj) {
  687. obj->call("_drop_data_fw", p_point, p_data, this);
  688. return;
  689. }
  690. }
  691. GDVIRTUAL_CALL(_drop_data, p_point, p_data);
  692. }
  693. void Control::force_drag(const Variant &p_data, Control *p_control) {
  694. ERR_FAIL_COND(!is_inside_tree());
  695. ERR_FAIL_COND(p_data.get_type() == Variant::NIL);
  696. get_viewport()->_gui_force_drag(this, p_data, p_control);
  697. }
  698. void Control::set_drag_preview(Control *p_control) {
  699. ERR_FAIL_COND(!is_inside_tree());
  700. ERR_FAIL_COND(!get_viewport()->gui_is_dragging());
  701. get_viewport()->_gui_set_drag_preview(this, p_control);
  702. }
  703. void Control::_call_gui_input(const Ref<InputEvent> &p_event) {
  704. emit_signal(SceneStringNames::get_singleton()->gui_input, p_event); //signal should be first, so it's possible to override an event (and then accept it)
  705. if (!is_inside_tree() || get_viewport()->is_input_handled()) {
  706. return; //input was handled, abort
  707. }
  708. GDVIRTUAL_CALL(_gui_input, p_event);
  709. if (!is_inside_tree() || get_viewport()->is_input_handled()) {
  710. return; //input was handled, abort
  711. }
  712. gui_input(p_event);
  713. }
  714. void Control::gui_input(const Ref<InputEvent> &p_event) {
  715. }
  716. Size2 Control::get_minimum_size() const {
  717. Vector2 ms;
  718. if (GDVIRTUAL_CALL(_get_minimum_size, ms)) {
  719. return ms;
  720. }
  721. return Vector2();
  722. }
  723. template <class T>
  724. T Control::get_theme_item_in_types(Control *p_theme_owner, Window *p_theme_owner_window, Theme::DataType p_data_type, const StringName &p_name, List<StringName> p_theme_types) {
  725. ERR_FAIL_COND_V_MSG(p_theme_types.size() == 0, T(), "At least one theme type must be specified.");
  726. // First, look through each control or window node in the branch, until no valid parent can be found.
  727. // Only nodes with a theme resource attached are considered.
  728. Control *theme_owner = p_theme_owner;
  729. Window *theme_owner_window = p_theme_owner_window;
  730. while (theme_owner || theme_owner_window) {
  731. // For each theme resource check the theme types provided and see if p_name exists with any of them.
  732. for (const StringName &E : p_theme_types) {
  733. if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E)) {
  734. return theme_owner->data.theme->get_theme_item(p_data_type, p_name, E);
  735. }
  736. if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E)) {
  737. return theme_owner_window->theme->get_theme_item(p_data_type, p_name, E);
  738. }
  739. }
  740. Node *parent = theme_owner ? theme_owner->get_parent() : theme_owner_window->get_parent();
  741. Control *parent_c = Object::cast_to<Control>(parent);
  742. if (parent_c) {
  743. theme_owner = parent_c->data.theme_owner;
  744. theme_owner_window = parent_c->data.theme_owner_window;
  745. } else {
  746. Window *parent_w = Object::cast_to<Window>(parent);
  747. if (parent_w) {
  748. theme_owner = parent_w->theme_owner;
  749. theme_owner_window = parent_w->theme_owner_window;
  750. } else {
  751. theme_owner = nullptr;
  752. theme_owner_window = nullptr;
  753. }
  754. }
  755. }
  756. // Secondly, check the project-defined Theme resource.
  757. if (Theme::get_project_default().is_valid()) {
  758. for (const StringName &E : p_theme_types) {
  759. if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E)) {
  760. return Theme::get_project_default()->get_theme_item(p_data_type, p_name, E);
  761. }
  762. }
  763. }
  764. // Lastly, fall back on the items defined in the default Theme, if they exist.
  765. for (const StringName &E : p_theme_types) {
  766. if (Theme::get_default()->has_theme_item(p_data_type, p_name, E)) {
  767. return Theme::get_default()->get_theme_item(p_data_type, p_name, E);
  768. }
  769. }
  770. // If they don't exist, use any type to return the default/empty value.
  771. return Theme::get_default()->get_theme_item(p_data_type, p_name, p_theme_types[0]);
  772. }
  773. bool Control::has_theme_item_in_types(Control *p_theme_owner, Window *p_theme_owner_window, Theme::DataType p_data_type, const StringName &p_name, List<StringName> p_theme_types) {
  774. ERR_FAIL_COND_V_MSG(p_theme_types.size() == 0, false, "At least one theme type must be specified.");
  775. // First, look through each control or window node in the branch, until no valid parent can be found.
  776. // Only nodes with a theme resource attached are considered.
  777. Control *theme_owner = p_theme_owner;
  778. Window *theme_owner_window = p_theme_owner_window;
  779. while (theme_owner || theme_owner_window) {
  780. // For each theme resource check the theme types provided and see if p_name exists with any of them.
  781. for (const StringName &E : p_theme_types) {
  782. if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E)) {
  783. return true;
  784. }
  785. if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E)) {
  786. return true;
  787. }
  788. }
  789. Node *parent = theme_owner ? theme_owner->get_parent() : theme_owner_window->get_parent();
  790. Control *parent_c = Object::cast_to<Control>(parent);
  791. if (parent_c) {
  792. theme_owner = parent_c->data.theme_owner;
  793. theme_owner_window = parent_c->data.theme_owner_window;
  794. } else {
  795. Window *parent_w = Object::cast_to<Window>(parent);
  796. if (parent_w) {
  797. theme_owner = parent_w->theme_owner;
  798. theme_owner_window = parent_w->theme_owner_window;
  799. } else {
  800. theme_owner = nullptr;
  801. theme_owner_window = nullptr;
  802. }
  803. }
  804. }
  805. // Secondly, check the project-defined Theme resource.
  806. if (Theme::get_project_default().is_valid()) {
  807. for (const StringName &E : p_theme_types) {
  808. if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E)) {
  809. return true;
  810. }
  811. }
  812. }
  813. // Lastly, fall back on the items defined in the default Theme, if they exist.
  814. for (const StringName &E : p_theme_types) {
  815. if (Theme::get_default()->has_theme_item(p_data_type, p_name, E)) {
  816. return true;
  817. }
  818. }
  819. return false;
  820. }
  821. void Control::_get_theme_type_dependencies(const StringName &p_theme_type, List<StringName> *p_list) const {
  822. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  823. if (Theme::get_project_default().is_valid() && Theme::get_project_default()->get_type_variation_base(data.theme_type_variation) != StringName()) {
  824. Theme::get_project_default()->get_type_dependencies(get_class_name(), data.theme_type_variation, p_list);
  825. } else {
  826. Theme::get_default()->get_type_dependencies(get_class_name(), data.theme_type_variation, p_list);
  827. }
  828. } else {
  829. Theme::get_default()->get_type_dependencies(p_theme_type, StringName(), p_list);
  830. }
  831. }
  832. Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {
  833. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  834. const Ref<Texture2D> *tex = data.icon_override.getptr(p_name);
  835. if (tex) {
  836. return *tex;
  837. }
  838. }
  839. List<StringName> theme_types;
  840. _get_theme_type_dependencies(p_theme_type, &theme_types);
  841. return get_theme_item_in_types<Ref<Texture2D>>(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_ICON, p_name, theme_types);
  842. }
  843. Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
  844. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  845. const Ref<StyleBox> *style = data.style_override.getptr(p_name);
  846. if (style) {
  847. return *style;
  848. }
  849. }
  850. List<StringName> theme_types;
  851. _get_theme_type_dependencies(p_theme_type, &theme_types);
  852. return get_theme_item_in_types<Ref<StyleBox>>(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
  853. }
  854. Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const {
  855. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  856. const Ref<Font> *font = data.font_override.getptr(p_name);
  857. if (font && (*font)->get_data_count() > 0) {
  858. return *font;
  859. }
  860. }
  861. List<StringName> theme_types;
  862. _get_theme_type_dependencies(p_theme_type, &theme_types);
  863. return get_theme_item_in_types<Ref<Font>>(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_FONT, p_name, theme_types);
  864. }
  865. int Control::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const {
  866. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  867. const int *font_size = data.font_size_override.getptr(p_name);
  868. if (font_size && (*font_size) > 0) {
  869. return *font_size;
  870. }
  871. }
  872. List<StringName> theme_types;
  873. _get_theme_type_dependencies(p_theme_type, &theme_types);
  874. return get_theme_item_in_types<int>(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
  875. }
  876. Color Control::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const {
  877. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  878. const Color *color = data.color_override.getptr(p_name);
  879. if (color) {
  880. return *color;
  881. }
  882. }
  883. List<StringName> theme_types;
  884. _get_theme_type_dependencies(p_theme_type, &theme_types);
  885. return get_theme_item_in_types<Color>(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_COLOR, p_name, theme_types);
  886. }
  887. int Control::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const {
  888. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  889. const int *constant = data.constant_override.getptr(p_name);
  890. if (constant) {
  891. return *constant;
  892. }
  893. }
  894. List<StringName> theme_types;
  895. _get_theme_type_dependencies(p_theme_type, &theme_types);
  896. return get_theme_item_in_types<int>(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
  897. }
  898. bool Control::has_theme_icon_override(const StringName &p_name) const {
  899. const Ref<Texture2D> *tex = data.icon_override.getptr(p_name);
  900. return tex != nullptr;
  901. }
  902. bool Control::has_theme_stylebox_override(const StringName &p_name) const {
  903. const Ref<StyleBox> *style = data.style_override.getptr(p_name);
  904. return style != nullptr;
  905. }
  906. bool Control::has_theme_font_override(const StringName &p_name) const {
  907. const Ref<Font> *font = data.font_override.getptr(p_name);
  908. return font != nullptr;
  909. }
  910. bool Control::has_theme_font_size_override(const StringName &p_name) const {
  911. const int *font_size = data.font_size_override.getptr(p_name);
  912. return font_size != nullptr;
  913. }
  914. bool Control::has_theme_color_override(const StringName &p_name) const {
  915. const Color *color = data.color_override.getptr(p_name);
  916. return color != nullptr;
  917. }
  918. bool Control::has_theme_constant_override(const StringName &p_name) const {
  919. const int *constant = data.constant_override.getptr(p_name);
  920. return constant != nullptr;
  921. }
  922. bool Control::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {
  923. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  924. if (has_theme_icon_override(p_name)) {
  925. return true;
  926. }
  927. }
  928. List<StringName> theme_types;
  929. _get_theme_type_dependencies(p_theme_type, &theme_types);
  930. return has_theme_item_in_types(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_ICON, p_name, theme_types);
  931. }
  932. bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
  933. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  934. if (has_theme_stylebox_override(p_name)) {
  935. return true;
  936. }
  937. }
  938. List<StringName> theme_types;
  939. _get_theme_type_dependencies(p_theme_type, &theme_types);
  940. return has_theme_item_in_types(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
  941. }
  942. bool Control::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const {
  943. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  944. if (has_theme_font_override(p_name)) {
  945. return true;
  946. }
  947. }
  948. List<StringName> theme_types;
  949. _get_theme_type_dependencies(p_theme_type, &theme_types);
  950. return has_theme_item_in_types(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_FONT, p_name, theme_types);
  951. }
  952. bool Control::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const {
  953. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  954. if (has_theme_font_size_override(p_name)) {
  955. return true;
  956. }
  957. }
  958. List<StringName> theme_types;
  959. _get_theme_type_dependencies(p_theme_type, &theme_types);
  960. return has_theme_item_in_types(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
  961. }
  962. bool Control::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const {
  963. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  964. if (has_theme_color_override(p_name)) {
  965. return true;
  966. }
  967. }
  968. List<StringName> theme_types;
  969. _get_theme_type_dependencies(p_theme_type, &theme_types);
  970. return has_theme_item_in_types(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_COLOR, p_name, theme_types);
  971. }
  972. bool Control::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const {
  973. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
  974. if (has_theme_constant_override(p_name)) {
  975. return true;
  976. }
  977. }
  978. List<StringName> theme_types;
  979. _get_theme_type_dependencies(p_theme_type, &theme_types);
  980. return has_theme_item_in_types(data.theme_owner, data.theme_owner_window, Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
  981. }
  982. float Control::fetch_theme_default_base_scale(Control *p_theme_owner, Window *p_theme_owner_window) {
  983. // First, look through each control or window node in the branch, until no valid parent can be found.
  984. // Only nodes with a theme resource attached are considered.
  985. // For each theme resource see if their assigned theme has the default value defined and valid.
  986. Control *theme_owner = p_theme_owner;
  987. Window *theme_owner_window = p_theme_owner_window;
  988. while (theme_owner || theme_owner_window) {
  989. if (theme_owner && theme_owner->data.theme->has_default_theme_base_scale()) {
  990. return theme_owner->data.theme->get_default_theme_base_scale();
  991. }
  992. if (theme_owner_window && theme_owner_window->theme->has_default_theme_base_scale()) {
  993. return theme_owner_window->theme->get_default_theme_base_scale();
  994. }
  995. Node *parent = theme_owner ? theme_owner->get_parent() : theme_owner_window->get_parent();
  996. Control *parent_c = Object::cast_to<Control>(parent);
  997. if (parent_c) {
  998. theme_owner = parent_c->data.theme_owner;
  999. theme_owner_window = parent_c->data.theme_owner_window;
  1000. } else {
  1001. Window *parent_w = Object::cast_to<Window>(parent);
  1002. if (parent_w) {
  1003. theme_owner = parent_w->theme_owner;
  1004. theme_owner_window = parent_w->theme_owner_window;
  1005. } else {
  1006. theme_owner = nullptr;
  1007. theme_owner_window = nullptr;
  1008. }
  1009. }
  1010. }
  1011. // Secondly, check the project-defined Theme resource.
  1012. if (Theme::get_project_default().is_valid()) {
  1013. if (Theme::get_project_default()->has_default_theme_base_scale()) {
  1014. return Theme::get_project_default()->get_default_theme_base_scale();
  1015. }
  1016. }
  1017. // Lastly, fall back on the default Theme.
  1018. return Theme::get_default()->get_default_theme_base_scale();
  1019. }
  1020. float Control::get_theme_default_base_scale() const {
  1021. return fetch_theme_default_base_scale(data.theme_owner, data.theme_owner_window);
  1022. }
  1023. Ref<Font> Control::fetch_theme_default_font(Control *p_theme_owner, Window *p_theme_owner_window) {
  1024. // First, look through each control or window node in the branch, until no valid parent can be found.
  1025. // Only nodes with a theme resource attached are considered.
  1026. // For each theme resource see if their assigned theme has the default value defined and valid.
  1027. Control *theme_owner = p_theme_owner;
  1028. Window *theme_owner_window = p_theme_owner_window;
  1029. while (theme_owner || theme_owner_window) {
  1030. if (theme_owner && theme_owner->data.theme->has_default_theme_font()) {
  1031. return theme_owner->data.theme->get_default_theme_font();
  1032. }
  1033. if (theme_owner_window && theme_owner_window->theme->has_default_theme_font()) {
  1034. return theme_owner_window->theme->get_default_theme_font();
  1035. }
  1036. Node *parent = theme_owner ? theme_owner->get_parent() : theme_owner_window->get_parent();
  1037. Control *parent_c = Object::cast_to<Control>(parent);
  1038. if (parent_c) {
  1039. theme_owner = parent_c->data.theme_owner;
  1040. theme_owner_window = parent_c->data.theme_owner_window;
  1041. } else {
  1042. Window *parent_w = Object::cast_to<Window>(parent);
  1043. if (parent_w) {
  1044. theme_owner = parent_w->theme_owner;
  1045. theme_owner_window = parent_w->theme_owner_window;
  1046. } else {
  1047. theme_owner = nullptr;
  1048. theme_owner_window = nullptr;
  1049. }
  1050. }
  1051. }
  1052. // Secondly, check the project-defined Theme resource.
  1053. if (Theme::get_project_default().is_valid()) {
  1054. if (Theme::get_project_default()->has_default_theme_font()) {
  1055. return Theme::get_project_default()->get_default_theme_font();
  1056. }
  1057. }
  1058. // Lastly, fall back on the default Theme.
  1059. return Theme::get_default()->get_default_theme_font();
  1060. }
  1061. Ref<Font> Control::get_theme_default_font() const {
  1062. return fetch_theme_default_font(data.theme_owner, data.theme_owner_window);
  1063. }
  1064. int Control::fetch_theme_default_font_size(Control *p_theme_owner, Window *p_theme_owner_window) {
  1065. // First, look through each control or window node in the branch, until no valid parent can be found.
  1066. // Only nodes with a theme resource attached are considered.
  1067. // For each theme resource see if their assigned theme has the default value defined and valid.
  1068. Control *theme_owner = p_theme_owner;
  1069. Window *theme_owner_window = p_theme_owner_window;
  1070. while (theme_owner || theme_owner_window) {
  1071. if (theme_owner && theme_owner->data.theme->has_default_theme_font_size()) {
  1072. return theme_owner->data.theme->get_default_theme_font_size();
  1073. }
  1074. if (theme_owner_window && theme_owner_window->theme->has_default_theme_font_size()) {
  1075. return theme_owner_window->theme->get_default_theme_font_size();
  1076. }
  1077. Node *parent = theme_owner ? theme_owner->get_parent() : theme_owner_window->get_parent();
  1078. Control *parent_c = Object::cast_to<Control>(parent);
  1079. if (parent_c) {
  1080. theme_owner = parent_c->data.theme_owner;
  1081. theme_owner_window = parent_c->data.theme_owner_window;
  1082. } else {
  1083. Window *parent_w = Object::cast_to<Window>(parent);
  1084. if (parent_w) {
  1085. theme_owner = parent_w->theme_owner;
  1086. theme_owner_window = parent_w->theme_owner_window;
  1087. } else {
  1088. theme_owner = nullptr;
  1089. theme_owner_window = nullptr;
  1090. }
  1091. }
  1092. }
  1093. // Secondly, check the project-defined Theme resource.
  1094. if (Theme::get_project_default().is_valid()) {
  1095. if (Theme::get_project_default()->has_default_theme_font_size()) {
  1096. return Theme::get_project_default()->get_default_theme_font_size();
  1097. }
  1098. }
  1099. // Lastly, fall back on the default Theme.
  1100. return Theme::get_default()->get_default_theme_font_size();
  1101. }
  1102. int Control::get_theme_default_font_size() const {
  1103. return fetch_theme_default_font_size(data.theme_owner, data.theme_owner_window);
  1104. }
  1105. Rect2 Control::get_parent_anchorable_rect() const {
  1106. if (!is_inside_tree()) {
  1107. return Rect2();
  1108. }
  1109. Rect2 parent_rect;
  1110. if (data.parent_canvas_item) {
  1111. parent_rect = data.parent_canvas_item->get_anchorable_rect();
  1112. } else {
  1113. #ifdef TOOLS_ENABLED
  1114. Node *edited_root = get_tree()->get_edited_scene_root();
  1115. if (edited_root && (this == edited_root || edited_root->is_ancestor_of(this))) {
  1116. parent_rect.size = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height"));
  1117. } else {
  1118. parent_rect = get_viewport()->get_visible_rect();
  1119. }
  1120. #else
  1121. parent_rect = get_viewport()->get_visible_rect();
  1122. #endif
  1123. }
  1124. return parent_rect;
  1125. }
  1126. Size2 Control::get_parent_area_size() const {
  1127. return get_parent_anchorable_rect().size;
  1128. }
  1129. void Control::_size_changed() {
  1130. Rect2 parent_rect = get_parent_anchorable_rect();
  1131. real_t edge_pos[4];
  1132. for (int i = 0; i < 4; i++) {
  1133. real_t area = parent_rect.size[i & 1];
  1134. edge_pos[i] = data.offset[i] + (data.anchor[i] * area);
  1135. }
  1136. Point2 new_pos_cache = Point2(edge_pos[0], edge_pos[1]);
  1137. Size2 new_size_cache = Point2(edge_pos[2], edge_pos[3]) - new_pos_cache;
  1138. Size2 minimum_size = get_combined_minimum_size();
  1139. if (minimum_size.width > new_size_cache.width) {
  1140. if (data.h_grow == GROW_DIRECTION_BEGIN) {
  1141. new_pos_cache.x += new_size_cache.width - minimum_size.width;
  1142. } else if (data.h_grow == GROW_DIRECTION_BOTH) {
  1143. new_pos_cache.x += 0.5 * (new_size_cache.width - minimum_size.width);
  1144. }
  1145. new_size_cache.width = minimum_size.width;
  1146. }
  1147. if (is_layout_rtl()) {
  1148. new_pos_cache.x = parent_rect.size.x - new_pos_cache.x - new_size_cache.x;
  1149. }
  1150. if (minimum_size.height > new_size_cache.height) {
  1151. if (data.v_grow == GROW_DIRECTION_BEGIN) {
  1152. new_pos_cache.y += new_size_cache.height - minimum_size.height;
  1153. } else if (data.v_grow == GROW_DIRECTION_BOTH) {
  1154. new_pos_cache.y += 0.5 * (new_size_cache.height - minimum_size.height);
  1155. }
  1156. new_size_cache.height = minimum_size.height;
  1157. }
  1158. bool pos_changed = new_pos_cache != data.pos_cache;
  1159. bool size_changed = new_size_cache != data.size_cache;
  1160. data.pos_cache = new_pos_cache;
  1161. data.size_cache = new_size_cache;
  1162. if (is_inside_tree()) {
  1163. if (size_changed) {
  1164. notification(NOTIFICATION_RESIZED);
  1165. }
  1166. if (pos_changed || size_changed) {
  1167. item_rect_changed(size_changed);
  1168. _notify_transform();
  1169. }
  1170. if (pos_changed && !size_changed) {
  1171. _update_canvas_item_transform(); //move because it won't be updated
  1172. }
  1173. }
  1174. }
  1175. void Control::set_anchor(Side p_side, real_t p_anchor, bool p_keep_offset, bool p_push_opposite_anchor) {
  1176. ERR_FAIL_INDEX((int)p_side, 4);
  1177. Rect2 parent_rect = get_parent_anchorable_rect();
  1178. real_t parent_range = (p_side == SIDE_LEFT || p_side == SIDE_RIGHT) ? parent_rect.size.x : parent_rect.size.y;
  1179. real_t previous_pos = data.offset[p_side] + data.anchor[p_side] * parent_range;
  1180. real_t previous_opposite_pos = data.offset[(p_side + 2) % 4] + data.anchor[(p_side + 2) % 4] * parent_range;
  1181. data.anchor[p_side] = p_anchor;
  1182. if (((p_side == SIDE_LEFT || p_side == SIDE_TOP) && data.anchor[p_side] > data.anchor[(p_side + 2) % 4]) ||
  1183. ((p_side == SIDE_RIGHT || p_side == SIDE_BOTTOM) && data.anchor[p_side] < data.anchor[(p_side + 2) % 4])) {
  1184. if (p_push_opposite_anchor) {
  1185. data.anchor[(p_side + 2) % 4] = data.anchor[p_side];
  1186. } else {
  1187. data.anchor[p_side] = data.anchor[(p_side + 2) % 4];
  1188. }
  1189. }
  1190. if (!p_keep_offset) {
  1191. data.offset[p_side] = previous_pos - data.anchor[p_side] * parent_range;
  1192. if (p_push_opposite_anchor) {
  1193. data.offset[(p_side + 2) % 4] = previous_opposite_pos - data.anchor[(p_side + 2) % 4] * parent_range;
  1194. }
  1195. }
  1196. if (is_inside_tree()) {
  1197. _size_changed();
  1198. }
  1199. update();
  1200. }
  1201. void Control::_set_anchor(Side p_side, real_t p_anchor) {
  1202. set_anchor(p_side, p_anchor);
  1203. }
  1204. void Control::set_anchor_and_offset(Side p_side, real_t p_anchor, real_t p_pos, bool p_push_opposite_anchor) {
  1205. set_anchor(p_side, p_anchor, false, p_push_opposite_anchor);
  1206. set_offset(p_side, p_pos);
  1207. }
  1208. void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_offsets) {
  1209. ERR_FAIL_INDEX((int)p_preset, 16);
  1210. //Left
  1211. switch (p_preset) {
  1212. case PRESET_TOP_LEFT:
  1213. case PRESET_BOTTOM_LEFT:
  1214. case PRESET_CENTER_LEFT:
  1215. case PRESET_TOP_WIDE:
  1216. case PRESET_BOTTOM_WIDE:
  1217. case PRESET_LEFT_WIDE:
  1218. case PRESET_HCENTER_WIDE:
  1219. case PRESET_WIDE:
  1220. set_anchor(SIDE_LEFT, ANCHOR_BEGIN, p_keep_offsets);
  1221. break;
  1222. case PRESET_CENTER_TOP:
  1223. case PRESET_CENTER_BOTTOM:
  1224. case PRESET_CENTER:
  1225. case PRESET_VCENTER_WIDE:
  1226. set_anchor(SIDE_LEFT, 0.5, p_keep_offsets);
  1227. break;
  1228. case PRESET_TOP_RIGHT:
  1229. case PRESET_BOTTOM_RIGHT:
  1230. case PRESET_CENTER_RIGHT:
  1231. case PRESET_RIGHT_WIDE:
  1232. set_anchor(SIDE_LEFT, ANCHOR_END, p_keep_offsets);
  1233. break;
  1234. }
  1235. // Top
  1236. switch (p_preset) {
  1237. case PRESET_TOP_LEFT:
  1238. case PRESET_TOP_RIGHT:
  1239. case PRESET_CENTER_TOP:
  1240. case PRESET_LEFT_WIDE:
  1241. case PRESET_RIGHT_WIDE:
  1242. case PRESET_TOP_WIDE:
  1243. case PRESET_VCENTER_WIDE:
  1244. case PRESET_WIDE:
  1245. set_anchor(SIDE_TOP, ANCHOR_BEGIN, p_keep_offsets);
  1246. break;
  1247. case PRESET_CENTER_LEFT:
  1248. case PRESET_CENTER_RIGHT:
  1249. case PRESET_CENTER:
  1250. case PRESET_HCENTER_WIDE:
  1251. set_anchor(SIDE_TOP, 0.5, p_keep_offsets);
  1252. break;
  1253. case PRESET_BOTTOM_LEFT:
  1254. case PRESET_BOTTOM_RIGHT:
  1255. case PRESET_CENTER_BOTTOM:
  1256. case PRESET_BOTTOM_WIDE:
  1257. set_anchor(SIDE_TOP, ANCHOR_END, p_keep_offsets);
  1258. break;
  1259. }
  1260. // Right
  1261. switch (p_preset) {
  1262. case PRESET_TOP_LEFT:
  1263. case PRESET_BOTTOM_LEFT:
  1264. case PRESET_CENTER_LEFT:
  1265. case PRESET_LEFT_WIDE:
  1266. set_anchor(SIDE_RIGHT, ANCHOR_BEGIN, p_keep_offsets);
  1267. break;
  1268. case PRESET_CENTER_TOP:
  1269. case PRESET_CENTER_BOTTOM:
  1270. case PRESET_CENTER:
  1271. case PRESET_VCENTER_WIDE:
  1272. set_anchor(SIDE_RIGHT, 0.5, p_keep_offsets);
  1273. break;
  1274. case PRESET_TOP_RIGHT:
  1275. case PRESET_BOTTOM_RIGHT:
  1276. case PRESET_CENTER_RIGHT:
  1277. case PRESET_TOP_WIDE:
  1278. case PRESET_RIGHT_WIDE:
  1279. case PRESET_BOTTOM_WIDE:
  1280. case PRESET_HCENTER_WIDE:
  1281. case PRESET_WIDE:
  1282. set_anchor(SIDE_RIGHT, ANCHOR_END, p_keep_offsets);
  1283. break;
  1284. }
  1285. // Bottom
  1286. switch (p_preset) {
  1287. case PRESET_TOP_LEFT:
  1288. case PRESET_TOP_RIGHT:
  1289. case PRESET_CENTER_TOP:
  1290. case PRESET_TOP_WIDE:
  1291. set_anchor(SIDE_BOTTOM, ANCHOR_BEGIN, p_keep_offsets);
  1292. break;
  1293. case PRESET_CENTER_LEFT:
  1294. case PRESET_CENTER_RIGHT:
  1295. case PRESET_CENTER:
  1296. case PRESET_HCENTER_WIDE:
  1297. set_anchor(SIDE_BOTTOM, 0.5, p_keep_offsets);
  1298. break;
  1299. case PRESET_BOTTOM_LEFT:
  1300. case PRESET_BOTTOM_RIGHT:
  1301. case PRESET_CENTER_BOTTOM:
  1302. case PRESET_LEFT_WIDE:
  1303. case PRESET_RIGHT_WIDE:
  1304. case PRESET_BOTTOM_WIDE:
  1305. case PRESET_VCENTER_WIDE:
  1306. case PRESET_WIDE:
  1307. set_anchor(SIDE_BOTTOM, ANCHOR_END, p_keep_offsets);
  1308. break;
  1309. }
  1310. }
  1311. void Control::set_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {
  1312. ERR_FAIL_INDEX((int)p_preset, 16);
  1313. ERR_FAIL_INDEX((int)p_resize_mode, 4);
  1314. // Calculate the size if the node is not resized
  1315. Size2 min_size = get_minimum_size();
  1316. Size2 new_size = get_size();
  1317. if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_HEIGHT) {
  1318. new_size.x = min_size.x;
  1319. }
  1320. if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_WIDTH) {
  1321. new_size.y = min_size.y;
  1322. }
  1323. Rect2 parent_rect = get_parent_anchorable_rect();
  1324. real_t x = parent_rect.size.x;
  1325. if (is_layout_rtl()) {
  1326. x = parent_rect.size.x - x - new_size.x;
  1327. }
  1328. //Left
  1329. switch (p_preset) {
  1330. case PRESET_TOP_LEFT:
  1331. case PRESET_BOTTOM_LEFT:
  1332. case PRESET_CENTER_LEFT:
  1333. case PRESET_TOP_WIDE:
  1334. case PRESET_BOTTOM_WIDE:
  1335. case PRESET_LEFT_WIDE:
  1336. case PRESET_HCENTER_WIDE:
  1337. case PRESET_WIDE:
  1338. data.offset[0] = x * (0.0 - data.anchor[0]) + p_margin + parent_rect.position.x;
  1339. break;
  1340. case PRESET_CENTER_TOP:
  1341. case PRESET_CENTER_BOTTOM:
  1342. case PRESET_CENTER:
  1343. case PRESET_VCENTER_WIDE:
  1344. data.offset[0] = x * (0.5 - data.anchor[0]) - new_size.x / 2 + parent_rect.position.x;
  1345. break;
  1346. case PRESET_TOP_RIGHT:
  1347. case PRESET_BOTTOM_RIGHT:
  1348. case PRESET_CENTER_RIGHT:
  1349. case PRESET_RIGHT_WIDE:
  1350. data.offset[0] = x * (1.0 - data.anchor[0]) - new_size.x - p_margin + parent_rect.position.x;
  1351. break;
  1352. }
  1353. // Top
  1354. switch (p_preset) {
  1355. case PRESET_TOP_LEFT:
  1356. case PRESET_TOP_RIGHT:
  1357. case PRESET_CENTER_TOP:
  1358. case PRESET_LEFT_WIDE:
  1359. case PRESET_RIGHT_WIDE:
  1360. case PRESET_TOP_WIDE:
  1361. case PRESET_VCENTER_WIDE:
  1362. case PRESET_WIDE:
  1363. data.offset[1] = parent_rect.size.y * (0.0 - data.anchor[1]) + p_margin + parent_rect.position.y;
  1364. break;
  1365. case PRESET_CENTER_LEFT:
  1366. case PRESET_CENTER_RIGHT:
  1367. case PRESET_CENTER:
  1368. case PRESET_HCENTER_WIDE:
  1369. data.offset[1] = parent_rect.size.y * (0.5 - data.anchor[1]) - new_size.y / 2 + parent_rect.position.y;
  1370. break;
  1371. case PRESET_BOTTOM_LEFT:
  1372. case PRESET_BOTTOM_RIGHT:
  1373. case PRESET_CENTER_BOTTOM:
  1374. case PRESET_BOTTOM_WIDE:
  1375. data.offset[1] = parent_rect.size.y * (1.0 - data.anchor[1]) - new_size.y - p_margin + parent_rect.position.y;
  1376. break;
  1377. }
  1378. // Right
  1379. switch (p_preset) {
  1380. case PRESET_TOP_LEFT:
  1381. case PRESET_BOTTOM_LEFT:
  1382. case PRESET_CENTER_LEFT:
  1383. case PRESET_LEFT_WIDE:
  1384. data.offset[2] = x * (0.0 - data.anchor[2]) + new_size.x + p_margin + parent_rect.position.x;
  1385. break;
  1386. case PRESET_CENTER_TOP:
  1387. case PRESET_CENTER_BOTTOM:
  1388. case PRESET_CENTER:
  1389. case PRESET_VCENTER_WIDE:
  1390. data.offset[2] = x * (0.5 - data.anchor[2]) + new_size.x / 2 + parent_rect.position.x;
  1391. break;
  1392. case PRESET_TOP_RIGHT:
  1393. case PRESET_BOTTOM_RIGHT:
  1394. case PRESET_CENTER_RIGHT:
  1395. case PRESET_TOP_WIDE:
  1396. case PRESET_RIGHT_WIDE:
  1397. case PRESET_BOTTOM_WIDE:
  1398. case PRESET_HCENTER_WIDE:
  1399. case PRESET_WIDE:
  1400. data.offset[2] = x * (1.0 - data.anchor[2]) - p_margin + parent_rect.position.x;
  1401. break;
  1402. }
  1403. // Bottom
  1404. switch (p_preset) {
  1405. case PRESET_TOP_LEFT:
  1406. case PRESET_TOP_RIGHT:
  1407. case PRESET_CENTER_TOP:
  1408. case PRESET_TOP_WIDE:
  1409. data.offset[3] = parent_rect.size.y * (0.0 - data.anchor[3]) + new_size.y + p_margin + parent_rect.position.y;
  1410. break;
  1411. case PRESET_CENTER_LEFT:
  1412. case PRESET_CENTER_RIGHT:
  1413. case PRESET_CENTER:
  1414. case PRESET_HCENTER_WIDE:
  1415. data.offset[3] = parent_rect.size.y * (0.5 - data.anchor[3]) + new_size.y / 2 + parent_rect.position.y;
  1416. break;
  1417. case PRESET_BOTTOM_LEFT:
  1418. case PRESET_BOTTOM_RIGHT:
  1419. case PRESET_CENTER_BOTTOM:
  1420. case PRESET_LEFT_WIDE:
  1421. case PRESET_RIGHT_WIDE:
  1422. case PRESET_BOTTOM_WIDE:
  1423. case PRESET_VCENTER_WIDE:
  1424. case PRESET_WIDE:
  1425. data.offset[3] = parent_rect.size.y * (1.0 - data.anchor[3]) - p_margin + parent_rect.position.y;
  1426. break;
  1427. }
  1428. _size_changed();
  1429. }
  1430. void Control::set_anchors_and_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {
  1431. set_anchors_preset(p_preset);
  1432. set_offsets_preset(p_preset, p_resize_mode, p_margin);
  1433. }
  1434. real_t Control::get_anchor(Side p_side) const {
  1435. ERR_FAIL_INDEX_V(int(p_side), 4, 0.0);
  1436. return data.anchor[p_side];
  1437. }
  1438. void Control::set_offset(Side p_side, real_t p_value) {
  1439. ERR_FAIL_INDEX((int)p_side, 4);
  1440. data.offset[p_side] = p_value;
  1441. _size_changed();
  1442. }
  1443. void Control::set_begin(const Size2 &p_point) {
  1444. data.offset[0] = p_point.x;
  1445. data.offset[1] = p_point.y;
  1446. _size_changed();
  1447. }
  1448. void Control::set_end(const Size2 &p_point) {
  1449. data.offset[2] = p_point.x;
  1450. data.offset[3] = p_point.y;
  1451. _size_changed();
  1452. }
  1453. real_t Control::get_offset(Side p_side) const {
  1454. ERR_FAIL_INDEX_V((int)p_side, 4, 0);
  1455. return data.offset[p_side];
  1456. }
  1457. Size2 Control::get_begin() const {
  1458. return Size2(data.offset[0], data.offset[1]);
  1459. }
  1460. Size2 Control::get_end() const {
  1461. return Size2(data.offset[2], data.offset[3]);
  1462. }
  1463. Point2 Control::get_global_position() const {
  1464. return get_global_transform().get_origin();
  1465. }
  1466. Point2 Control::get_screen_position() const {
  1467. ERR_FAIL_COND_V(!is_inside_tree(), Point2());
  1468. Point2 global_pos = get_viewport()->get_canvas_transform().xform(get_global_position());
  1469. Window *w = Object::cast_to<Window>(get_viewport());
  1470. if (w && !w->is_embedding_subwindows()) {
  1471. global_pos += w->get_position();
  1472. }
  1473. return global_pos;
  1474. }
  1475. void Control::_set_global_position(const Point2 &p_point) {
  1476. set_global_position(p_point);
  1477. }
  1478. void Control::set_global_position(const Point2 &p_point, bool p_keep_offsets) {
  1479. Transform2D inv;
  1480. if (data.parent_canvas_item) {
  1481. inv = data.parent_canvas_item->get_global_transform().affine_inverse();
  1482. }
  1483. set_position(inv.xform(p_point), p_keep_offsets);
  1484. }
  1485. void Control::_compute_anchors(Rect2 p_rect, const real_t p_offsets[4], real_t (&r_anchors)[4]) {
  1486. Size2 parent_rect_size = get_parent_anchorable_rect().size;
  1487. ERR_FAIL_COND(parent_rect_size.x == 0.0);
  1488. ERR_FAIL_COND(parent_rect_size.y == 0.0);
  1489. real_t x = p_rect.position.x;
  1490. if (is_layout_rtl()) {
  1491. x = parent_rect_size.x - x - p_rect.size.x;
  1492. }
  1493. r_anchors[0] = (x - p_offsets[0]) / parent_rect_size.x;
  1494. r_anchors[1] = (p_rect.position.y - p_offsets[1]) / parent_rect_size.y;
  1495. r_anchors[2] = (x + p_rect.size.x - p_offsets[2]) / parent_rect_size.x;
  1496. r_anchors[3] = (p_rect.position.y + p_rect.size.y - p_offsets[3]) / parent_rect_size.y;
  1497. }
  1498. void Control::_compute_offsets(Rect2 p_rect, const real_t p_anchors[4], real_t (&r_offsets)[4]) {
  1499. Size2 parent_rect_size = get_parent_anchorable_rect().size;
  1500. real_t x = p_rect.position.x;
  1501. if (is_layout_rtl()) {
  1502. x = parent_rect_size.x - x - p_rect.size.x;
  1503. }
  1504. r_offsets[0] = x - (p_anchors[0] * parent_rect_size.x);
  1505. r_offsets[1] = p_rect.position.y - (p_anchors[1] * parent_rect_size.y);
  1506. r_offsets[2] = x + p_rect.size.x - (p_anchors[2] * parent_rect_size.x);
  1507. r_offsets[3] = p_rect.position.y + p_rect.size.y - (p_anchors[3] * parent_rect_size.y);
  1508. }
  1509. void Control::_set_position(const Size2 &p_point) {
  1510. set_position(p_point);
  1511. }
  1512. void Control::set_position(const Size2 &p_point, bool p_keep_offsets) {
  1513. if (p_keep_offsets) {
  1514. _compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor);
  1515. } else {
  1516. _compute_offsets(Rect2(p_point, data.size_cache), data.anchor, data.offset);
  1517. }
  1518. _size_changed();
  1519. }
  1520. void Control::set_rect(const Rect2 &p_rect) {
  1521. for (int i = 0; i < 4; i++) {
  1522. data.anchor[i] = ANCHOR_BEGIN;
  1523. }
  1524. _compute_offsets(p_rect, data.anchor, data.offset);
  1525. if (is_inside_tree()) {
  1526. _size_changed();
  1527. }
  1528. }
  1529. void Control::_set_size(const Size2 &p_size) {
  1530. #ifdef DEBUG_ENABLED
  1531. if (data.size_warning && (data.anchor[SIDE_LEFT] != data.anchor[SIDE_RIGHT] || data.anchor[SIDE_TOP] != data.anchor[SIDE_BOTTOM])) {
  1532. WARN_PRINT("Nodes with non-equal opposite anchors will have their size overridden after _ready(). \nIf you want to set size, change the anchors or consider using set_deferred().");
  1533. }
  1534. #endif
  1535. set_size(p_size);
  1536. }
  1537. void Control::set_size(const Size2 &p_size, bool p_keep_offsets) {
  1538. Size2 new_size = p_size;
  1539. Size2 min = get_combined_minimum_size();
  1540. if (new_size.x < min.x) {
  1541. new_size.x = min.x;
  1542. }
  1543. if (new_size.y < min.y) {
  1544. new_size.y = min.y;
  1545. }
  1546. if (p_keep_offsets) {
  1547. _compute_anchors(Rect2(data.pos_cache, new_size), data.offset, data.anchor);
  1548. } else {
  1549. _compute_offsets(Rect2(data.pos_cache, new_size), data.anchor, data.offset);
  1550. }
  1551. _size_changed();
  1552. }
  1553. Size2 Control::get_position() const {
  1554. return data.pos_cache;
  1555. }
  1556. Size2 Control::get_size() const {
  1557. return data.size_cache;
  1558. }
  1559. Rect2 Control::get_global_rect() const {
  1560. return Rect2(get_global_position(), get_size());
  1561. }
  1562. Rect2 Control::get_screen_rect() const {
  1563. ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
  1564. Rect2 r(get_global_position(), get_size());
  1565. Window *w = Object::cast_to<Window>(get_viewport());
  1566. if (w && !w->is_embedding_subwindows()) {
  1567. r.position += w->get_position();
  1568. }
  1569. return r;
  1570. }
  1571. Rect2 Control::get_window_rect() const {
  1572. ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
  1573. Rect2 gr = get_global_rect();
  1574. gr.position += get_viewport()->get_visible_rect().position;
  1575. return gr;
  1576. }
  1577. Rect2 Control::get_rect() const {
  1578. return Rect2(get_position(), get_size());
  1579. }
  1580. Rect2 Control::get_anchorable_rect() const {
  1581. return Rect2(Point2(), get_size());
  1582. }
  1583. void Control::begin_bulk_theme_override() {
  1584. data.bulk_theme_override = true;
  1585. }
  1586. void Control::end_bulk_theme_override() {
  1587. ERR_FAIL_COND(!data.bulk_theme_override);
  1588. data.bulk_theme_override = false;
  1589. _notify_theme_changed();
  1590. }
  1591. void Control::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) {
  1592. ERR_FAIL_COND(!p_icon.is_valid());
  1593. if (data.icon_override.has(p_name)) {
  1594. data.icon_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
  1595. }
  1596. data.icon_override[p_name] = p_icon;
  1597. data.icon_override[p_name]->connect("changed", callable_mp(this, &Control::_override_changed), Vector<Variant>(), CONNECT_REFERENCE_COUNTED);
  1598. _notify_theme_changed();
  1599. }
  1600. void Control::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
  1601. ERR_FAIL_COND(!p_style.is_valid());
  1602. if (data.style_override.has(p_name)) {
  1603. data.style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
  1604. }
  1605. data.style_override[p_name] = p_style;
  1606. data.style_override[p_name]->connect("changed", callable_mp(this, &Control::_override_changed), Vector<Variant>(), CONNECT_REFERENCE_COUNTED);
  1607. _notify_theme_changed();
  1608. }
  1609. void Control::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) {
  1610. ERR_FAIL_COND(!p_font.is_valid());
  1611. if (data.font_override.has(p_name)) {
  1612. data.font_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
  1613. }
  1614. data.font_override[p_name] = p_font;
  1615. data.font_override[p_name]->connect("changed", callable_mp(this, &Control::_override_changed), Vector<Variant>(), CONNECT_REFERENCE_COUNTED);
  1616. _notify_theme_changed();
  1617. }
  1618. void Control::add_theme_font_size_override(const StringName &p_name, int p_font_size) {
  1619. data.font_size_override[p_name] = p_font_size;
  1620. _notify_theme_changed();
  1621. }
  1622. void Control::add_theme_color_override(const StringName &p_name, const Color &p_color) {
  1623. data.color_override[p_name] = p_color;
  1624. _notify_theme_changed();
  1625. }
  1626. void Control::add_theme_constant_override(const StringName &p_name, int p_constant) {
  1627. data.constant_override[p_name] = p_constant;
  1628. _notify_theme_changed();
  1629. }
  1630. void Control::remove_theme_icon_override(const StringName &p_name) {
  1631. if (data.icon_override.has(p_name)) {
  1632. data.icon_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
  1633. }
  1634. data.icon_override.erase(p_name);
  1635. _notify_theme_changed();
  1636. }
  1637. void Control::remove_theme_style_override(const StringName &p_name) {
  1638. if (data.style_override.has(p_name)) {
  1639. data.style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
  1640. }
  1641. data.style_override.erase(p_name);
  1642. _notify_theme_changed();
  1643. }
  1644. void Control::remove_theme_font_override(const StringName &p_name) {
  1645. if (data.font_override.has(p_name)) {
  1646. data.font_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
  1647. }
  1648. data.font_override.erase(p_name);
  1649. _notify_theme_changed();
  1650. }
  1651. void Control::remove_theme_font_size_override(const StringName &p_name) {
  1652. data.font_size_override.erase(p_name);
  1653. _notify_theme_changed();
  1654. }
  1655. void Control::remove_theme_color_override(const StringName &p_name) {
  1656. data.color_override.erase(p_name);
  1657. _notify_theme_changed();
  1658. }
  1659. void Control::remove_theme_constant_override(const StringName &p_name) {
  1660. data.constant_override.erase(p_name);
  1661. _notify_theme_changed();
  1662. }
  1663. void Control::set_focus_mode(FocusMode p_focus_mode) {
  1664. ERR_FAIL_INDEX((int)p_focus_mode, 3);
  1665. if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus()) {
  1666. release_focus();
  1667. }
  1668. data.focus_mode = p_focus_mode;
  1669. }
  1670. static Control *_next_control(Control *p_from) {
  1671. if (p_from->is_set_as_top_level()) {
  1672. return nullptr; // can't go above
  1673. }
  1674. Control *parent = Object::cast_to<Control>(p_from->get_parent());
  1675. if (!parent) {
  1676. return nullptr;
  1677. }
  1678. int next = p_from->get_index();
  1679. ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr);
  1680. for (int i = (next + 1); i < parent->get_child_count(); i++) {
  1681. Control *c = Object::cast_to<Control>(parent->get_child(i));
  1682. if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
  1683. continue;
  1684. }
  1685. return c;
  1686. }
  1687. //no next in parent, try the same in parent
  1688. return _next_control(parent);
  1689. }
  1690. Control *Control::find_next_valid_focus() const {
  1691. Control *from = const_cast<Control *>(this);
  1692. while (true) {
  1693. // If the focus property is manually overwritten, attempt to use it.
  1694. if (!data.focus_next.is_empty()) {
  1695. Node *n = get_node(data.focus_next);
  1696. Control *c;
  1697. if (n) {
  1698. c = Object::cast_to<Control>(n);
  1699. ERR_FAIL_COND_V_MSG(!c, nullptr, "Next focus node is not a control: " + n->get_name() + ".");
  1700. } else {
  1701. return nullptr;
  1702. }
  1703. if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
  1704. return c;
  1705. }
  1706. }
  1707. // find next child
  1708. Control *next_child = nullptr;
  1709. for (int i = 0; i < from->get_child_count(); i++) {
  1710. Control *c = Object::cast_to<Control>(from->get_child(i));
  1711. if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
  1712. continue;
  1713. }
  1714. next_child = c;
  1715. break;
  1716. }
  1717. if (!next_child) {
  1718. next_child = _next_control(from);
  1719. if (!next_child) { //nothing else.. go up and find either window or subwindow
  1720. next_child = const_cast<Control *>(this);
  1721. while (next_child && !next_child->is_set_as_top_level()) {
  1722. next_child = cast_to<Control>(next_child->get_parent());
  1723. }
  1724. if (!next_child) {
  1725. next_child = const_cast<Control *>(this);
  1726. while (next_child) {
  1727. if (next_child->data.RI) {
  1728. break;
  1729. }
  1730. next_child = next_child->get_parent_control();
  1731. }
  1732. }
  1733. }
  1734. }
  1735. if (next_child == this) { // no next control->
  1736. return (get_focus_mode() == FOCUS_ALL) ? next_child : nullptr;
  1737. }
  1738. if (next_child) {
  1739. if (next_child->get_focus_mode() == FOCUS_ALL) {
  1740. return next_child;
  1741. }
  1742. from = next_child;
  1743. } else {
  1744. break;
  1745. }
  1746. }
  1747. return nullptr;
  1748. }
  1749. static Control *_prev_control(Control *p_from) {
  1750. Control *child = nullptr;
  1751. for (int i = p_from->get_child_count() - 1; i >= 0; i--) {
  1752. Control *c = Object::cast_to<Control>(p_from->get_child(i));
  1753. if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
  1754. continue;
  1755. }
  1756. child = c;
  1757. break;
  1758. }
  1759. if (!child) {
  1760. return p_from;
  1761. }
  1762. //no prev in parent, try the same in parent
  1763. return _prev_control(child);
  1764. }
  1765. Control *Control::find_prev_valid_focus() const {
  1766. Control *from = const_cast<Control *>(this);
  1767. while (true) {
  1768. // If the focus property is manually overwritten, attempt to use it.
  1769. if (!data.focus_prev.is_empty()) {
  1770. Node *n = get_node(data.focus_prev);
  1771. Control *c;
  1772. if (n) {
  1773. c = Object::cast_to<Control>(n);
  1774. ERR_FAIL_COND_V_MSG(!c, nullptr, "Previous focus node is not a control: " + n->get_name() + ".");
  1775. } else {
  1776. return nullptr;
  1777. }
  1778. if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
  1779. return c;
  1780. }
  1781. }
  1782. // find prev child
  1783. Control *prev_child = nullptr;
  1784. if (from->is_set_as_top_level() || !Object::cast_to<Control>(from->get_parent())) {
  1785. //find last of the children
  1786. prev_child = _prev_control(from);
  1787. } else {
  1788. for (int i = (from->get_index() - 1); i >= 0; i--) {
  1789. Control *c = Object::cast_to<Control>(from->get_parent()->get_child(i));
  1790. if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
  1791. continue;
  1792. }
  1793. prev_child = c;
  1794. break;
  1795. }
  1796. if (!prev_child) {
  1797. prev_child = Object::cast_to<Control>(from->get_parent());
  1798. } else {
  1799. prev_child = _prev_control(prev_child);
  1800. }
  1801. }
  1802. if (prev_child == this) { // no prev control->
  1803. return (get_focus_mode() == FOCUS_ALL) ? prev_child : nullptr;
  1804. }
  1805. if (prev_child->get_focus_mode() == FOCUS_ALL) {
  1806. return prev_child;
  1807. }
  1808. from = prev_child;
  1809. }
  1810. return nullptr;
  1811. }
  1812. Control::FocusMode Control::get_focus_mode() const {
  1813. return data.focus_mode;
  1814. }
  1815. bool Control::has_focus() const {
  1816. return is_inside_tree() && get_viewport()->_gui_control_has_focus(this);
  1817. }
  1818. void Control::grab_focus() {
  1819. ERR_FAIL_COND(!is_inside_tree());
  1820. if (data.focus_mode == FOCUS_NONE) {
  1821. WARN_PRINT("This control can't grab focus. Use set_focus_mode() to allow a control to get focus.");
  1822. return;
  1823. }
  1824. get_viewport()->_gui_control_grab_focus(this);
  1825. }
  1826. void Control::release_focus() {
  1827. ERR_FAIL_COND(!is_inside_tree());
  1828. if (!has_focus()) {
  1829. return;
  1830. }
  1831. get_viewport()->_gui_remove_focus();
  1832. update();
  1833. }
  1834. bool Control::is_top_level_control() const {
  1835. return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_top_level());
  1836. }
  1837. void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_owner_window, bool p_assign) {
  1838. Control *c = Object::cast_to<Control>(p_at);
  1839. if (c && c != p_owner && c->data.theme.is_valid()) { // has a theme, this can't be propagated
  1840. return;
  1841. }
  1842. Window *w = c == nullptr ? Object::cast_to<Window>(p_at) : nullptr;
  1843. if (w && w != p_owner_window && w->theme.is_valid()) { // has a theme, this can't be propagated
  1844. return;
  1845. }
  1846. for (int i = 0; i < p_at->get_child_count(); i++) {
  1847. CanvasItem *child = Object::cast_to<CanvasItem>(p_at->get_child(i));
  1848. if (child) {
  1849. _propagate_theme_changed(child, p_owner, p_owner_window, p_assign);
  1850. } else {
  1851. Window *window = Object::cast_to<Window>(p_at->get_child(i));
  1852. if (window) {
  1853. _propagate_theme_changed(window, p_owner, p_owner_window, p_assign);
  1854. }
  1855. }
  1856. }
  1857. if (c) {
  1858. if (p_assign) {
  1859. c->data.theme_owner = p_owner;
  1860. c->data.theme_owner_window = p_owner_window;
  1861. }
  1862. c->notification(Control::NOTIFICATION_THEME_CHANGED);
  1863. c->emit_signal(SceneStringNames::get_singleton()->theme_changed);
  1864. }
  1865. if (w) {
  1866. if (p_assign) {
  1867. w->theme_owner = p_owner;
  1868. w->theme_owner_window = p_owner_window;
  1869. }
  1870. w->notification(Window::NOTIFICATION_THEME_CHANGED);
  1871. w->emit_signal(SceneStringNames::get_singleton()->theme_changed);
  1872. }
  1873. }
  1874. void Control::_theme_changed() {
  1875. _propagate_theme_changed(this, this, nullptr, false);
  1876. }
  1877. void Control::_notify_theme_changed() {
  1878. if (!data.bulk_theme_override) {
  1879. notification(NOTIFICATION_THEME_CHANGED);
  1880. }
  1881. }
  1882. void Control::set_theme(const Ref<Theme> &p_theme) {
  1883. if (data.theme == p_theme) {
  1884. return;
  1885. }
  1886. if (data.theme.is_valid()) {
  1887. data.theme->disconnect("changed", callable_mp(this, &Control::_theme_changed));
  1888. }
  1889. data.theme = p_theme;
  1890. if (!p_theme.is_null()) {
  1891. data.theme_owner = this;
  1892. data.theme_owner_window = nullptr;
  1893. _propagate_theme_changed(this, this, nullptr);
  1894. } else {
  1895. Control *parent_c = Object::cast_to<Control>(get_parent());
  1896. if (parent_c && (parent_c->data.theme_owner || parent_c->data.theme_owner_window)) {
  1897. Control::_propagate_theme_changed(this, parent_c->data.theme_owner, parent_c->data.theme_owner_window);
  1898. } else {
  1899. Window *parent_w = cast_to<Window>(get_parent());
  1900. if (parent_w && (parent_w->theme_owner || parent_w->theme_owner_window)) {
  1901. Control::_propagate_theme_changed(this, parent_w->theme_owner, parent_w->theme_owner_window);
  1902. } else {
  1903. Control::_propagate_theme_changed(this, nullptr, nullptr);
  1904. }
  1905. }
  1906. }
  1907. if (data.theme.is_valid()) {
  1908. data.theme->connect("changed", callable_mp(this, &Control::_theme_changed), varray(), CONNECT_DEFERRED);
  1909. }
  1910. }
  1911. Ref<Theme> Control::get_theme() const {
  1912. return data.theme;
  1913. }
  1914. void Control::set_theme_type_variation(const StringName &p_theme_type) {
  1915. data.theme_type_variation = p_theme_type;
  1916. _propagate_theme_changed(this, data.theme_owner, data.theme_owner_window);
  1917. }
  1918. StringName Control::get_theme_type_variation() const {
  1919. return data.theme_type_variation;
  1920. }
  1921. void Control::set_tooltip(const String &p_tooltip) {
  1922. data.tooltip = p_tooltip;
  1923. update_configuration_warnings();
  1924. }
  1925. String Control::get_tooltip(const Point2 &p_pos) const {
  1926. return data.tooltip;
  1927. }
  1928. Control *Control::make_custom_tooltip(const String &p_text) const {
  1929. Object *ret = nullptr;
  1930. if (GDVIRTUAL_CALL(_make_custom_tooltip, p_text, ret)) {
  1931. return Object::cast_to<Control>(ret);
  1932. }
  1933. return nullptr;
  1934. }
  1935. void Control::set_default_cursor_shape(CursorShape p_shape) {
  1936. ERR_FAIL_INDEX(int(p_shape), CURSOR_MAX);
  1937. data.default_cursor = p_shape;
  1938. }
  1939. Control::CursorShape Control::get_default_cursor_shape() const {
  1940. return data.default_cursor;
  1941. }
  1942. Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const {
  1943. return data.default_cursor;
  1944. }
  1945. Transform2D Control::get_transform() const {
  1946. Transform2D xform = _get_internal_transform();
  1947. xform[2] += get_position();
  1948. return xform;
  1949. }
  1950. String Control::_get_tooltip() const {
  1951. return data.tooltip;
  1952. }
  1953. void Control::set_focus_neighbor(Side p_side, const NodePath &p_neighbor) {
  1954. ERR_FAIL_INDEX((int)p_side, 4);
  1955. data.focus_neighbor[p_side] = p_neighbor;
  1956. }
  1957. NodePath Control::get_focus_neighbor(Side p_side) const {
  1958. ERR_FAIL_INDEX_V((int)p_side, 4, NodePath());
  1959. return data.focus_neighbor[p_side];
  1960. }
  1961. void Control::set_focus_next(const NodePath &p_next) {
  1962. data.focus_next = p_next;
  1963. }
  1964. NodePath Control::get_focus_next() const {
  1965. return data.focus_next;
  1966. }
  1967. void Control::set_focus_previous(const NodePath &p_prev) {
  1968. data.focus_prev = p_prev;
  1969. }
  1970. NodePath Control::get_focus_previous() const {
  1971. return data.focus_prev;
  1972. }
  1973. #define MAX_NEIGHBOR_SEARCH_COUNT 512
  1974. Control *Control::_get_focus_neighbor(Side p_side, int p_count) {
  1975. ERR_FAIL_INDEX_V((int)p_side, 4, nullptr);
  1976. if (p_count >= MAX_NEIGHBOR_SEARCH_COUNT) {
  1977. return nullptr;
  1978. }
  1979. if (!data.focus_neighbor[p_side].is_empty()) {
  1980. Control *c = nullptr;
  1981. Node *n = get_node(data.focus_neighbor[p_side]);
  1982. if (n) {
  1983. c = Object::cast_to<Control>(n);
  1984. ERR_FAIL_COND_V_MSG(!c, nullptr, "Neighbor focus node is not a control: " + n->get_name() + ".");
  1985. } else {
  1986. return nullptr;
  1987. }
  1988. bool valid = true;
  1989. if (!c->is_visible()) {
  1990. valid = false;
  1991. }
  1992. if (c->get_focus_mode() == FOCUS_NONE) {
  1993. valid = false;
  1994. }
  1995. if (valid) {
  1996. return c;
  1997. }
  1998. c = c->_get_focus_neighbor(p_side, p_count + 1);
  1999. return c;
  2000. }
  2001. real_t dist = 1e7;
  2002. Control *result = nullptr;
  2003. Point2 points[4];
  2004. Transform2D xform = get_global_transform();
  2005. points[0] = xform.xform(Point2());
  2006. points[1] = xform.xform(Point2(get_size().x, 0));
  2007. points[2] = xform.xform(get_size());
  2008. points[3] = xform.xform(Point2(0, get_size().y));
  2009. const Vector2 dir[4] = {
  2010. Vector2(-1, 0),
  2011. Vector2(0, -1),
  2012. Vector2(1, 0),
  2013. Vector2(0, 1)
  2014. };
  2015. Vector2 vdir = dir[p_side];
  2016. real_t maxd = -1e7;
  2017. for (int i = 0; i < 4; i++) {
  2018. real_t d = vdir.dot(points[i]);
  2019. if (d > maxd) {
  2020. maxd = d;
  2021. }
  2022. }
  2023. Node *base = this;
  2024. while (base) {
  2025. Control *c = Object::cast_to<Control>(base);
  2026. if (c) {
  2027. if (c->data.RI) {
  2028. break;
  2029. }
  2030. }
  2031. base = base->get_parent();
  2032. }
  2033. if (!base) {
  2034. return nullptr;
  2035. }
  2036. _window_find_focus_neighbor(vdir, base, points, maxd, dist, &result);
  2037. return result;
  2038. }
  2039. void Control::_window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, real_t p_min, real_t &r_closest_dist, Control **r_closest) {
  2040. if (Object::cast_to<Viewport>(p_at)) {
  2041. return; //bye
  2042. }
  2043. Control *c = Object::cast_to<Control>(p_at);
  2044. if (c && c != this && c->get_focus_mode() == FOCUS_ALL && c->is_visible_in_tree()) {
  2045. Point2 points[4];
  2046. Transform2D xform = c->get_global_transform();
  2047. points[0] = xform.xform(Point2());
  2048. points[1] = xform.xform(Point2(c->get_size().x, 0));
  2049. points[2] = xform.xform(c->get_size());
  2050. points[3] = xform.xform(Point2(0, c->get_size().y));
  2051. real_t min = 1e7;
  2052. for (int i = 0; i < 4; i++) {
  2053. real_t d = p_dir.dot(points[i]);
  2054. if (d < min) {
  2055. min = d;
  2056. }
  2057. }
  2058. if (min > (p_min - CMP_EPSILON)) {
  2059. for (int i = 0; i < 4; i++) {
  2060. Vector2 la = p_points[i];
  2061. Vector2 lb = p_points[(i + 1) % 4];
  2062. for (int j = 0; j < 4; j++) {
  2063. Vector2 fa = points[j];
  2064. Vector2 fb = points[(j + 1) % 4];
  2065. Vector2 pa, pb;
  2066. real_t d = Geometry2D::get_closest_points_between_segments(la, lb, fa, fb, pa, pb);
  2067. //real_t d = Geometry2D::get_closest_distance_between_segments(Vector3(la.x,la.y,0),Vector3(lb.x,lb.y,0),Vector3(fa.x,fa.y,0),Vector3(fb.x,fb.y,0));
  2068. if (d < r_closest_dist) {
  2069. r_closest_dist = d;
  2070. *r_closest = c;
  2071. }
  2072. }
  2073. }
  2074. }
  2075. }
  2076. for (int i = 0; i < p_at->get_child_count(); i++) {
  2077. Node *child = p_at->get_child(i);
  2078. Control *childc = Object::cast_to<Control>(child);
  2079. if (childc && childc->data.RI) {
  2080. continue; //subwindow, ignore
  2081. }
  2082. _window_find_focus_neighbor(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest);
  2083. }
  2084. }
  2085. void Control::set_h_size_flags(int p_flags) {
  2086. if (data.h_size_flags == p_flags) {
  2087. return;
  2088. }
  2089. data.h_size_flags = p_flags;
  2090. emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
  2091. }
  2092. int Control::get_h_size_flags() const {
  2093. return data.h_size_flags;
  2094. }
  2095. void Control::set_v_size_flags(int p_flags) {
  2096. if (data.v_size_flags == p_flags) {
  2097. return;
  2098. }
  2099. data.v_size_flags = p_flags;
  2100. emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
  2101. }
  2102. void Control::set_stretch_ratio(real_t p_ratio) {
  2103. if (data.expand == p_ratio) {
  2104. return;
  2105. }
  2106. data.expand = p_ratio;
  2107. emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
  2108. }
  2109. real_t Control::get_stretch_ratio() const {
  2110. return data.expand;
  2111. }
  2112. void Control::grab_click_focus() {
  2113. ERR_FAIL_COND(!is_inside_tree());
  2114. get_viewport()->_gui_grab_click_focus(this);
  2115. }
  2116. void Control::minimum_size_changed() {
  2117. if (!is_inside_tree() || data.block_minimum_size_adjust) {
  2118. return;
  2119. }
  2120. Control *invalidate = this;
  2121. //invalidate cache upwards
  2122. while (invalidate && invalidate->data.minimum_size_valid) {
  2123. invalidate->data.minimum_size_valid = false;
  2124. if (invalidate->is_set_as_top_level()) {
  2125. break; // do not go further up
  2126. }
  2127. if (!invalidate->data.parent && get_parent()) {
  2128. Window *parent_window = Object::cast_to<Window>(get_parent());
  2129. if (parent_window && parent_window->is_wrapping_controls()) {
  2130. parent_window->child_controls_changed();
  2131. }
  2132. }
  2133. invalidate = invalidate->data.parent;
  2134. }
  2135. if (!is_visible_in_tree()) {
  2136. return;
  2137. }
  2138. if (data.updating_last_minimum_size) {
  2139. return;
  2140. }
  2141. data.updating_last_minimum_size = true;
  2142. MessageQueue::get_singleton()->push_call(this, "_update_minimum_size");
  2143. }
  2144. int Control::get_v_size_flags() const {
  2145. return data.v_size_flags;
  2146. }
  2147. void Control::set_mouse_filter(MouseFilter p_filter) {
  2148. ERR_FAIL_INDEX(p_filter, 3);
  2149. data.mouse_filter = p_filter;
  2150. update_configuration_warnings();
  2151. }
  2152. Control::MouseFilter Control::get_mouse_filter() const {
  2153. return data.mouse_filter;
  2154. }
  2155. Control *Control::get_focus_owner() const {
  2156. ERR_FAIL_COND_V(!is_inside_tree(), nullptr);
  2157. return get_viewport()->_gui_get_focus_owner();
  2158. }
  2159. void Control::warp_mouse(const Point2 &p_to_pos) {
  2160. ERR_FAIL_COND(!is_inside_tree());
  2161. get_viewport()->warp_mouse(get_global_transform().xform(p_to_pos));
  2162. }
  2163. bool Control::is_text_field() const {
  2164. return false;
  2165. }
  2166. Array Control::structured_text_parser(StructuredTextParser p_theme_type, const Array &p_args, const String p_text) const {
  2167. Array ret;
  2168. switch (p_theme_type) {
  2169. case STRUCTURED_TEXT_URI: {
  2170. int prev = 0;
  2171. for (int i = 0; i < p_text.length(); i++) {
  2172. if ((p_text[i] == '\\') || (p_text[i] == '/') || (p_text[i] == '.') || (p_text[i] == ':') || (p_text[i] == '&') || (p_text[i] == '=') || (p_text[i] == '@') || (p_text[i] == '?') || (p_text[i] == '#')) {
  2173. if (prev != i) {
  2174. ret.push_back(Vector2i(prev, i));
  2175. }
  2176. ret.push_back(Vector2i(i, i + 1));
  2177. prev = i + 1;
  2178. }
  2179. }
  2180. if (prev != p_text.length()) {
  2181. ret.push_back(Vector2i(prev, p_text.length()));
  2182. }
  2183. } break;
  2184. case STRUCTURED_TEXT_FILE: {
  2185. int prev = 0;
  2186. for (int i = 0; i < p_text.length(); i++) {
  2187. if ((p_text[i] == '\\') || (p_text[i] == '/') || (p_text[i] == ':')) {
  2188. if (prev != i) {
  2189. ret.push_back(Vector2i(prev, i));
  2190. }
  2191. ret.push_back(Vector2i(i, i + 1));
  2192. prev = i + 1;
  2193. }
  2194. }
  2195. if (prev != p_text.length()) {
  2196. ret.push_back(Vector2i(prev, p_text.length()));
  2197. }
  2198. } break;
  2199. case STRUCTURED_TEXT_EMAIL: {
  2200. bool local = true;
  2201. int prev = 0;
  2202. for (int i = 0; i < p_text.length(); i++) {
  2203. if ((p_text[i] == '@') && local) { // Add full "local" as single context.
  2204. local = false;
  2205. ret.push_back(Vector2i(prev, i));
  2206. ret.push_back(Vector2i(i, i + 1));
  2207. prev = i + 1;
  2208. } else if (!local & (p_text[i] == '.')) { // Add each dot separated "domain" part as context.
  2209. if (prev != i) {
  2210. ret.push_back(Vector2i(prev, i));
  2211. }
  2212. ret.push_back(Vector2i(i, i + 1));
  2213. prev = i + 1;
  2214. }
  2215. }
  2216. if (prev != p_text.length()) {
  2217. ret.push_back(Vector2i(prev, p_text.length()));
  2218. }
  2219. } break;
  2220. case STRUCTURED_TEXT_LIST: {
  2221. if (p_args.size() == 1 && p_args[0].get_type() == Variant::STRING) {
  2222. Vector<String> tags = p_text.split(String(p_args[0]));
  2223. int prev = 0;
  2224. for (int i = 0; i < tags.size(); i++) {
  2225. if (prev != i) {
  2226. ret.push_back(Vector2i(prev, prev + tags[i].length()));
  2227. }
  2228. ret.push_back(Vector2i(prev + tags[i].length(), prev + tags[i].length() + 1));
  2229. prev = prev + tags[i].length() + 1;
  2230. }
  2231. }
  2232. } break;
  2233. case STRUCTURED_TEXT_CUSTOM: {
  2234. Array r;
  2235. if (GDVIRTUAL_CALL(_structured_text_parser, p_args, p_text, r)) {
  2236. for (int i = 0; i < r.size(); i++) {
  2237. if (r[i].get_type() == Variant::VECTOR2I) {
  2238. ret.push_back(Vector2i(r[i]));
  2239. }
  2240. }
  2241. }
  2242. } break;
  2243. case STRUCTURED_TEXT_NONE:
  2244. case STRUCTURED_TEXT_DEFAULT:
  2245. default: {
  2246. ret.push_back(Vector2i(0, p_text.length()));
  2247. }
  2248. }
  2249. return ret;
  2250. }
  2251. void Control::set_rotation(real_t p_radians) {
  2252. data.rotation = p_radians;
  2253. update();
  2254. _notify_transform();
  2255. }
  2256. real_t Control::get_rotation() const {
  2257. return data.rotation;
  2258. }
  2259. void Control::_override_changed() {
  2260. notification(NOTIFICATION_THEME_CHANGED);
  2261. emit_signal(SceneStringNames::get_singleton()->theme_changed);
  2262. minimum_size_changed(); // overrides are likely to affect minimum size
  2263. }
  2264. void Control::set_pivot_offset(const Vector2 &p_pivot) {
  2265. data.pivot_offset = p_pivot;
  2266. update();
  2267. _notify_transform();
  2268. }
  2269. Vector2 Control::get_pivot_offset() const {
  2270. return data.pivot_offset;
  2271. }
  2272. void Control::set_scale(const Vector2 &p_scale) {
  2273. data.scale = p_scale;
  2274. // Avoid having 0 scale values, can lead to errors in physics and rendering.
  2275. if (data.scale.x == 0) {
  2276. data.scale.x = CMP_EPSILON;
  2277. }
  2278. if (data.scale.y == 0) {
  2279. data.scale.y = CMP_EPSILON;
  2280. }
  2281. update();
  2282. _notify_transform();
  2283. }
  2284. Vector2 Control::get_scale() const {
  2285. return data.scale;
  2286. }
  2287. Control *Control::get_root_parent_control() const {
  2288. const CanvasItem *ci = this;
  2289. const Control *root = this;
  2290. while (ci) {
  2291. const Control *c = Object::cast_to<Control>(ci);
  2292. if (c) {
  2293. root = c;
  2294. if (c->data.RI || c->is_top_level_control()) {
  2295. break;
  2296. }
  2297. }
  2298. ci = ci->get_parent_item();
  2299. }
  2300. return const_cast<Control *>(root);
  2301. }
  2302. void Control::set_block_minimum_size_adjust(bool p_block) {
  2303. data.block_minimum_size_adjust = p_block;
  2304. }
  2305. bool Control::is_minimum_size_adjust_blocked() const {
  2306. return data.block_minimum_size_adjust;
  2307. }
  2308. void Control::set_disable_visibility_clip(bool p_ignore) {
  2309. data.disable_visibility_clip = p_ignore;
  2310. update();
  2311. }
  2312. bool Control::is_visibility_clip_disabled() const {
  2313. return data.disable_visibility_clip;
  2314. }
  2315. void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  2316. Node::get_argument_options(p_function, p_idx, r_options);
  2317. if (p_idx == 0) {
  2318. List<StringName> sn;
  2319. String pf = p_function;
  2320. if (pf == "add_theme_color_override" || pf == "has_theme_color" || pf == "has_theme_color_override" || pf == "get_theme_color") {
  2321. Theme::get_default()->get_color_list(get_class(), &sn);
  2322. } else if (pf == "add_theme_style_override" || pf == "has_theme_style" || pf == "has_theme_style_override" || pf == "get_theme_style") {
  2323. Theme::get_default()->get_stylebox_list(get_class(), &sn);
  2324. } else if (pf == "add_theme_font_override" || pf == "has_theme_font" || pf == "has_theme_font_override" || pf == "get_theme_font") {
  2325. Theme::get_default()->get_font_list(get_class(), &sn);
  2326. } else if (pf == "add_theme_font_size_override" || pf == "has_theme_font_size" || pf == "has_theme_font_size_override" || pf == "get_theme_font_size") {
  2327. Theme::get_default()->get_font_size_list(get_class(), &sn);
  2328. } else if (pf == "add_theme_constant_override" || pf == "has_theme_constant" || pf == "has_theme_constant_override" || pf == "get_theme_constant") {
  2329. Theme::get_default()->get_constant_list(get_class(), &sn);
  2330. }
  2331. sn.sort_custom<StringName::AlphCompare>();
  2332. for (const StringName &name : sn) {
  2333. r_options->push_back(String(name).quote());
  2334. }
  2335. }
  2336. }
  2337. TypedArray<String> Control::get_configuration_warnings() const {
  2338. TypedArray<String> warnings = Node::get_configuration_warnings();
  2339. if (data.mouse_filter == MOUSE_FILTER_IGNORE && data.tooltip != "") {
  2340. warnings.push_back(TTR("The Hint Tooltip won't be displayed as the control's Mouse Filter is set to \"Ignore\". To solve this, set the Mouse Filter to \"Stop\" or \"Pass\"."));
  2341. }
  2342. return warnings;
  2343. }
  2344. void Control::set_clip_contents(bool p_clip) {
  2345. data.clip_contents = p_clip;
  2346. update();
  2347. }
  2348. bool Control::is_clipping_contents() {
  2349. return data.clip_contents;
  2350. }
  2351. void Control::set_h_grow_direction(GrowDirection p_direction) {
  2352. ERR_FAIL_INDEX((int)p_direction, 3);
  2353. data.h_grow = p_direction;
  2354. _size_changed();
  2355. }
  2356. Control::GrowDirection Control::get_h_grow_direction() const {
  2357. return data.h_grow;
  2358. }
  2359. void Control::set_v_grow_direction(GrowDirection p_direction) {
  2360. ERR_FAIL_INDEX((int)p_direction, 3);
  2361. data.v_grow = p_direction;
  2362. _size_changed();
  2363. }
  2364. Control::GrowDirection Control::get_v_grow_direction() const {
  2365. return data.v_grow;
  2366. }
  2367. void Control::_bind_methods() {
  2368. //ClassDB::bind_method(D_METHOD("_window_resize_event"),&Control::_window_resize_event);
  2369. ClassDB::bind_method(D_METHOD("_update_minimum_size"), &Control::_update_minimum_size);
  2370. ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event);
  2371. ClassDB::bind_method(D_METHOD("get_minimum_size"), &Control::get_minimum_size);
  2372. ClassDB::bind_method(D_METHOD("get_combined_minimum_size"), &Control::get_combined_minimum_size);
  2373. ClassDB::bind_method(D_METHOD("set_anchors_preset", "preset", "keep_offsets"), &Control::set_anchors_preset, DEFVAL(false));
  2374. ClassDB::bind_method(D_METHOD("set_offsets_preset", "preset", "resize_mode", "margin"), &Control::set_offsets_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0));
  2375. ClassDB::bind_method(D_METHOD("set_anchors_and_offsets_preset", "preset", "resize_mode", "margin"), &Control::set_anchors_and_offsets_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0));
  2376. ClassDB::bind_method(D_METHOD("_set_anchor", "side", "anchor"), &Control::_set_anchor);
  2377. ClassDB::bind_method(D_METHOD("set_anchor", "side", "anchor", "keep_offset", "push_opposite_anchor"), &Control::set_anchor, DEFVAL(false), DEFVAL(true));
  2378. ClassDB::bind_method(D_METHOD("get_anchor", "side"), &Control::get_anchor);
  2379. ClassDB::bind_method(D_METHOD("set_offset", "side", "offset"), &Control::set_offset);
  2380. ClassDB::bind_method(D_METHOD("set_anchor_and_offset", "side", "anchor", "offset", "push_opposite_anchor"), &Control::set_anchor_and_offset, DEFVAL(false));
  2381. ClassDB::bind_method(D_METHOD("set_begin", "position"), &Control::set_begin);
  2382. ClassDB::bind_method(D_METHOD("set_end", "position"), &Control::set_end);
  2383. ClassDB::bind_method(D_METHOD("set_position", "position", "keep_offsets"), &Control::set_position, DEFVAL(false));
  2384. ClassDB::bind_method(D_METHOD("_set_position", "position"), &Control::_set_position);
  2385. ClassDB::bind_method(D_METHOD("set_size", "size", "keep_offsets"), &Control::set_size, DEFVAL(false));
  2386. ClassDB::bind_method(D_METHOD("_set_size", "size"), &Control::_set_size);
  2387. ClassDB::bind_method(D_METHOD("set_custom_minimum_size", "size"), &Control::set_custom_minimum_size);
  2388. ClassDB::bind_method(D_METHOD("set_global_position", "position", "keep_offsets"), &Control::set_global_position, DEFVAL(false));
  2389. ClassDB::bind_method(D_METHOD("_set_global_position", "position"), &Control::_set_global_position);
  2390. ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Control::set_rotation);
  2391. ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Control::set_scale);
  2392. ClassDB::bind_method(D_METHOD("set_pivot_offset", "pivot_offset"), &Control::set_pivot_offset);
  2393. ClassDB::bind_method(D_METHOD("get_offset", "offset"), &Control::get_offset);
  2394. ClassDB::bind_method(D_METHOD("get_begin"), &Control::get_begin);
  2395. ClassDB::bind_method(D_METHOD("get_end"), &Control::get_end);
  2396. ClassDB::bind_method(D_METHOD("get_position"), &Control::get_position);
  2397. ClassDB::bind_method(D_METHOD("get_size"), &Control::get_size);
  2398. ClassDB::bind_method(D_METHOD("get_rotation"), &Control::get_rotation);
  2399. ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale);
  2400. ClassDB::bind_method(D_METHOD("get_pivot_offset"), &Control::get_pivot_offset);
  2401. ClassDB::bind_method(D_METHOD("get_custom_minimum_size"), &Control::get_custom_minimum_size);
  2402. ClassDB::bind_method(D_METHOD("get_parent_area_size"), &Control::get_parent_area_size);
  2403. ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position);
  2404. ClassDB::bind_method(D_METHOD("get_rect"), &Control::get_rect);
  2405. ClassDB::bind_method(D_METHOD("get_global_rect"), &Control::get_global_rect);
  2406. ClassDB::bind_method(D_METHOD("set_focus_mode", "mode"), &Control::set_focus_mode);
  2407. ClassDB::bind_method(D_METHOD("get_focus_mode"), &Control::get_focus_mode);
  2408. ClassDB::bind_method(D_METHOD("has_focus"), &Control::has_focus);
  2409. ClassDB::bind_method(D_METHOD("grab_focus"), &Control::grab_focus);
  2410. ClassDB::bind_method(D_METHOD("release_focus"), &Control::release_focus);
  2411. ClassDB::bind_method(D_METHOD("find_prev_valid_focus"), &Control::find_prev_valid_focus);
  2412. ClassDB::bind_method(D_METHOD("find_next_valid_focus"), &Control::find_next_valid_focus);
  2413. ClassDB::bind_method(D_METHOD("get_focus_owner"), &Control::get_focus_owner);
  2414. ClassDB::bind_method(D_METHOD("set_h_size_flags", "flags"), &Control::set_h_size_flags);
  2415. ClassDB::bind_method(D_METHOD("get_h_size_flags"), &Control::get_h_size_flags);
  2416. ClassDB::bind_method(D_METHOD("set_stretch_ratio", "ratio"), &Control::set_stretch_ratio);
  2417. ClassDB::bind_method(D_METHOD("get_stretch_ratio"), &Control::get_stretch_ratio);
  2418. ClassDB::bind_method(D_METHOD("set_v_size_flags", "flags"), &Control::set_v_size_flags);
  2419. ClassDB::bind_method(D_METHOD("get_v_size_flags"), &Control::get_v_size_flags);
  2420. ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Control::set_theme);
  2421. ClassDB::bind_method(D_METHOD("get_theme"), &Control::get_theme);
  2422. ClassDB::bind_method(D_METHOD("set_theme_type_variation", "theme_type"), &Control::set_theme_type_variation);
  2423. ClassDB::bind_method(D_METHOD("get_theme_type_variation"), &Control::get_theme_type_variation);
  2424. ClassDB::bind_method(D_METHOD("begin_bulk_theme_override"), &Control::begin_bulk_theme_override);
  2425. ClassDB::bind_method(D_METHOD("end_bulk_theme_override"), &Control::end_bulk_theme_override);
  2426. ClassDB::bind_method(D_METHOD("add_theme_icon_override", "name", "texture"), &Control::add_theme_icon_override);
  2427. ClassDB::bind_method(D_METHOD("add_theme_stylebox_override", "name", "stylebox"), &Control::add_theme_style_override);
  2428. ClassDB::bind_method(D_METHOD("add_theme_font_override", "name", "font"), &Control::add_theme_font_override);
  2429. ClassDB::bind_method(D_METHOD("add_theme_font_size_override", "name", "font_size"), &Control::add_theme_font_size_override);
  2430. ClassDB::bind_method(D_METHOD("add_theme_color_override", "name", "color"), &Control::add_theme_color_override);
  2431. ClassDB::bind_method(D_METHOD("add_theme_constant_override", "name", "constant"), &Control::add_theme_constant_override);
  2432. ClassDB::bind_method(D_METHOD("remove_theme_icon_override", "name"), &Control::remove_theme_icon_override);
  2433. ClassDB::bind_method(D_METHOD("remove_theme_stylebox_override", "name"), &Control::remove_theme_style_override);
  2434. ClassDB::bind_method(D_METHOD("remove_theme_font_override", "name"), &Control::remove_theme_font_override);
  2435. ClassDB::bind_method(D_METHOD("remove_theme_font_size_override", "name"), &Control::remove_theme_font_size_override);
  2436. ClassDB::bind_method(D_METHOD("remove_theme_color_override", "name"), &Control::remove_theme_color_override);
  2437. ClassDB::bind_method(D_METHOD("remove_theme_constant_override", "name"), &Control::remove_theme_constant_override);
  2438. ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "theme_type"), &Control::get_theme_icon, DEFVAL(""));
  2439. ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "theme_type"), &Control::get_theme_stylebox, DEFVAL(""));
  2440. ClassDB::bind_method(D_METHOD("get_theme_font", "name", "theme_type"), &Control::get_theme_font, DEFVAL(""));
  2441. ClassDB::bind_method(D_METHOD("get_theme_font_size", "name", "theme_type"), &Control::get_theme_font_size, DEFVAL(""));
  2442. ClassDB::bind_method(D_METHOD("get_theme_color", "name", "theme_type"), &Control::get_theme_color, DEFVAL(""));
  2443. ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "theme_type"), &Control::get_theme_constant, DEFVAL(""));
  2444. ClassDB::bind_method(D_METHOD("has_theme_icon_override", "name"), &Control::has_theme_icon_override);
  2445. ClassDB::bind_method(D_METHOD("has_theme_stylebox_override", "name"), &Control::has_theme_stylebox_override);
  2446. ClassDB::bind_method(D_METHOD("has_theme_font_override", "name"), &Control::has_theme_font_override);
  2447. ClassDB::bind_method(D_METHOD("has_theme_font_size_override", "name"), &Control::has_theme_font_size_override);
  2448. ClassDB::bind_method(D_METHOD("has_theme_color_override", "name"), &Control::has_theme_color_override);
  2449. ClassDB::bind_method(D_METHOD("has_theme_constant_override", "name"), &Control::has_theme_constant_override);
  2450. ClassDB::bind_method(D_METHOD("has_theme_icon", "name", "theme_type"), &Control::has_theme_icon, DEFVAL(""));
  2451. ClassDB::bind_method(D_METHOD("has_theme_stylebox", "name", "theme_type"), &Control::has_theme_stylebox, DEFVAL(""));
  2452. ClassDB::bind_method(D_METHOD("has_theme_font", "name", "theme_type"), &Control::has_theme_font, DEFVAL(""));
  2453. ClassDB::bind_method(D_METHOD("has_theme_font_size", "name", "theme_type"), &Control::has_theme_font_size, DEFVAL(""));
  2454. ClassDB::bind_method(D_METHOD("has_theme_color", "name", "theme_type"), &Control::has_theme_color, DEFVAL(""));
  2455. ClassDB::bind_method(D_METHOD("has_theme_constant", "name", "theme_type"), &Control::has_theme_constant, DEFVAL(""));
  2456. ClassDB::bind_method(D_METHOD("get_theme_default_base_scale"), &Control::get_theme_default_base_scale);
  2457. ClassDB::bind_method(D_METHOD("get_theme_default_font"), &Control::get_theme_default_font);
  2458. ClassDB::bind_method(D_METHOD("get_theme_default_font_size"), &Control::get_theme_default_font_size);
  2459. ClassDB::bind_method(D_METHOD("get_parent_control"), &Control::get_parent_control);
  2460. ClassDB::bind_method(D_METHOD("set_h_grow_direction", "direction"), &Control::set_h_grow_direction);
  2461. ClassDB::bind_method(D_METHOD("get_h_grow_direction"), &Control::get_h_grow_direction);
  2462. ClassDB::bind_method(D_METHOD("set_v_grow_direction", "direction"), &Control::set_v_grow_direction);
  2463. ClassDB::bind_method(D_METHOD("get_v_grow_direction"), &Control::get_v_grow_direction);
  2464. ClassDB::bind_method(D_METHOD("set_tooltip", "tooltip"), &Control::set_tooltip);
  2465. ClassDB::bind_method(D_METHOD("get_tooltip", "at_position"), &Control::get_tooltip, DEFVAL(Point2()));
  2466. ClassDB::bind_method(D_METHOD("_get_tooltip"), &Control::_get_tooltip);
  2467. ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Control::set_default_cursor_shape);
  2468. ClassDB::bind_method(D_METHOD("get_default_cursor_shape"), &Control::get_default_cursor_shape);
  2469. ClassDB::bind_method(D_METHOD("get_cursor_shape", "position"), &Control::get_cursor_shape, DEFVAL(Point2()));
  2470. ClassDB::bind_method(D_METHOD("set_focus_neighbor", "side", "neighbor"), &Control::set_focus_neighbor);
  2471. ClassDB::bind_method(D_METHOD("get_focus_neighbor", "side"), &Control::get_focus_neighbor);
  2472. ClassDB::bind_method(D_METHOD("set_focus_next", "next"), &Control::set_focus_next);
  2473. ClassDB::bind_method(D_METHOD("get_focus_next"), &Control::get_focus_next);
  2474. ClassDB::bind_method(D_METHOD("set_focus_previous", "previous"), &Control::set_focus_previous);
  2475. ClassDB::bind_method(D_METHOD("get_focus_previous"), &Control::get_focus_previous);
  2476. ClassDB::bind_method(D_METHOD("force_drag", "data", "preview"), &Control::force_drag);
  2477. ClassDB::bind_method(D_METHOD("set_mouse_filter", "filter"), &Control::set_mouse_filter);
  2478. ClassDB::bind_method(D_METHOD("get_mouse_filter"), &Control::get_mouse_filter);
  2479. ClassDB::bind_method(D_METHOD("set_clip_contents", "enable"), &Control::set_clip_contents);
  2480. ClassDB::bind_method(D_METHOD("is_clipping_contents"), &Control::is_clipping_contents);
  2481. ClassDB::bind_method(D_METHOD("grab_click_focus"), &Control::grab_click_focus);
  2482. ClassDB::bind_method(D_METHOD("set_drag_forwarding", "target"), &Control::set_drag_forwarding);
  2483. ClassDB::bind_method(D_METHOD("set_drag_preview", "control"), &Control::set_drag_preview);
  2484. ClassDB::bind_method(D_METHOD("warp_mouse", "to_position"), &Control::warp_mouse);
  2485. ClassDB::bind_method(D_METHOD("minimum_size_changed"), &Control::minimum_size_changed);
  2486. ClassDB::bind_method(D_METHOD("set_layout_direction", "direction"), &Control::set_layout_direction);
  2487. ClassDB::bind_method(D_METHOD("get_layout_direction"), &Control::get_layout_direction);
  2488. ClassDB::bind_method(D_METHOD("is_layout_rtl"), &Control::is_layout_rtl);
  2489. ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Control::set_auto_translate);
  2490. ClassDB::bind_method(D_METHOD("is_auto_translating"), &Control::is_auto_translating);
  2491. ADD_GROUP("Anchor", "anchor_");
  2492. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_LEFT);
  2493. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_top", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_TOP);
  2494. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_right", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_RIGHT);
  2495. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_bottom", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_BOTTOM);
  2496. ADD_GROUP("Offset", "offset_");
  2497. ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_left", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_LEFT);
  2498. ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_top", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_TOP);
  2499. ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_right", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_RIGHT);
  2500. ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_bottom", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_BOTTOM);
  2501. ADD_GROUP("Grow Direction", "grow_");
  2502. ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_horizontal", PROPERTY_HINT_ENUM, "Begin,End,Both"), "set_h_grow_direction", "get_h_grow_direction");
  2503. ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_vertical", PROPERTY_HINT_ENUM, "Begin,End,Both"), "set_v_grow_direction", "get_v_grow_direction");
  2504. ADD_GROUP("Layout Direction", "layout_");
  2505. ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_direction", PROPERTY_HINT_ENUM, "Inherited,Locale,Left-to-Right,Right-to-Left"), "set_layout_direction", "get_layout_direction");
  2506. ADD_GROUP("Auto Translate", "");
  2507. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
  2508. ADD_GROUP("Rect", "rect_");
  2509. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_position", "get_position");
  2510. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_global_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "_set_global_position", "get_global_position");
  2511. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_size", "get_size");
  2512. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size");
  2513. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rect_rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater,radians"), "set_rotation", "get_rotation");
  2514. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_scale"), "set_scale", "get_scale");
  2515. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_pivot_offset"), "set_pivot_offset", "get_pivot_offset");
  2516. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents");
  2517. ADD_GROUP("Hint", "hint_");
  2518. ADD_PROPERTY(PropertyInfo(Variant::STRING, "hint_tooltip", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip", "_get_tooltip");
  2519. ADD_GROUP("Focus", "focus_");
  2520. ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_left", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_LEFT);
  2521. ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_top", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_TOP);
  2522. ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_right", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_RIGHT);
  2523. ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_bottom", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_BOTTOM);
  2524. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "focus_next", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_next", "get_focus_next");
  2525. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "focus_previous", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_previous", "get_focus_previous");
  2526. ADD_PROPERTY(PropertyInfo(Variant::INT, "focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_focus_mode", "get_focus_mode");
  2527. ADD_GROUP("Mouse", "mouse_");
  2528. ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_filter", PROPERTY_HINT_ENUM, "Stop,Pass,Ignore"), "set_mouse_filter", "get_mouse_filter");
  2529. ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_default_cursor_shape", PROPERTY_HINT_ENUM, "Arrow,I-Beam,Pointing Hand,Cross,Wait,Busy,Drag,Can Drop,Forbidden,Vertical Resize,Horizontal Resize,Secondary Diagonal Resize,Main Diagonal Resize,Move,Vertical Split,Horizontal Split,Help"), "set_default_cursor_shape", "get_default_cursor_shape");
  2530. ADD_GROUP("Size Flags", "size_flags_");
  2531. ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
  2532. ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");
  2533. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio");
  2534. ADD_GROUP("Theme", "theme_");
  2535. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
  2536. ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation");
  2537. BIND_ENUM_CONSTANT(FOCUS_NONE);
  2538. BIND_ENUM_CONSTANT(FOCUS_CLICK);
  2539. BIND_ENUM_CONSTANT(FOCUS_ALL);
  2540. BIND_CONSTANT(NOTIFICATION_RESIZED);
  2541. BIND_CONSTANT(NOTIFICATION_MOUSE_ENTER);
  2542. BIND_CONSTANT(NOTIFICATION_MOUSE_EXIT);
  2543. BIND_CONSTANT(NOTIFICATION_FOCUS_ENTER);
  2544. BIND_CONSTANT(NOTIFICATION_FOCUS_EXIT);
  2545. BIND_CONSTANT(NOTIFICATION_THEME_CHANGED);
  2546. BIND_CONSTANT(NOTIFICATION_SCROLL_BEGIN);
  2547. BIND_CONSTANT(NOTIFICATION_SCROLL_END);
  2548. BIND_CONSTANT(NOTIFICATION_LAYOUT_DIRECTION_CHANGED);
  2549. BIND_ENUM_CONSTANT(CURSOR_ARROW);
  2550. BIND_ENUM_CONSTANT(CURSOR_IBEAM);
  2551. BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND);
  2552. BIND_ENUM_CONSTANT(CURSOR_CROSS);
  2553. BIND_ENUM_CONSTANT(CURSOR_WAIT);
  2554. BIND_ENUM_CONSTANT(CURSOR_BUSY);
  2555. BIND_ENUM_CONSTANT(CURSOR_DRAG);
  2556. BIND_ENUM_CONSTANT(CURSOR_CAN_DROP);
  2557. BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN);
  2558. BIND_ENUM_CONSTANT(CURSOR_VSIZE);
  2559. BIND_ENUM_CONSTANT(CURSOR_HSIZE);
  2560. BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE);
  2561. BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE);
  2562. BIND_ENUM_CONSTANT(CURSOR_MOVE);
  2563. BIND_ENUM_CONSTANT(CURSOR_VSPLIT);
  2564. BIND_ENUM_CONSTANT(CURSOR_HSPLIT);
  2565. BIND_ENUM_CONSTANT(CURSOR_HELP);
  2566. BIND_ENUM_CONSTANT(PRESET_TOP_LEFT);
  2567. BIND_ENUM_CONSTANT(PRESET_TOP_RIGHT);
  2568. BIND_ENUM_CONSTANT(PRESET_BOTTOM_LEFT);
  2569. BIND_ENUM_CONSTANT(PRESET_BOTTOM_RIGHT);
  2570. BIND_ENUM_CONSTANT(PRESET_CENTER_LEFT);
  2571. BIND_ENUM_CONSTANT(PRESET_CENTER_TOP);
  2572. BIND_ENUM_CONSTANT(PRESET_CENTER_RIGHT);
  2573. BIND_ENUM_CONSTANT(PRESET_CENTER_BOTTOM);
  2574. BIND_ENUM_CONSTANT(PRESET_CENTER);
  2575. BIND_ENUM_CONSTANT(PRESET_LEFT_WIDE);
  2576. BIND_ENUM_CONSTANT(PRESET_TOP_WIDE);
  2577. BIND_ENUM_CONSTANT(PRESET_RIGHT_WIDE);
  2578. BIND_ENUM_CONSTANT(PRESET_BOTTOM_WIDE);
  2579. BIND_ENUM_CONSTANT(PRESET_VCENTER_WIDE);
  2580. BIND_ENUM_CONSTANT(PRESET_HCENTER_WIDE);
  2581. BIND_ENUM_CONSTANT(PRESET_WIDE);
  2582. BIND_ENUM_CONSTANT(PRESET_MODE_MINSIZE);
  2583. BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_WIDTH);
  2584. BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_HEIGHT);
  2585. BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_SIZE);
  2586. BIND_ENUM_CONSTANT(SIZE_FILL);
  2587. BIND_ENUM_CONSTANT(SIZE_EXPAND);
  2588. BIND_ENUM_CONSTANT(SIZE_EXPAND_FILL);
  2589. BIND_ENUM_CONSTANT(SIZE_SHRINK_CENTER);
  2590. BIND_ENUM_CONSTANT(SIZE_SHRINK_END);
  2591. BIND_ENUM_CONSTANT(MOUSE_FILTER_STOP);
  2592. BIND_ENUM_CONSTANT(MOUSE_FILTER_PASS);
  2593. BIND_ENUM_CONSTANT(MOUSE_FILTER_IGNORE);
  2594. BIND_ENUM_CONSTANT(GROW_DIRECTION_BEGIN);
  2595. BIND_ENUM_CONSTANT(GROW_DIRECTION_END);
  2596. BIND_ENUM_CONSTANT(GROW_DIRECTION_BOTH);
  2597. BIND_ENUM_CONSTANT(ANCHOR_BEGIN);
  2598. BIND_ENUM_CONSTANT(ANCHOR_END);
  2599. BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_INHERITED);
  2600. BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LOCALE);
  2601. BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LTR);
  2602. BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_RTL);
  2603. BIND_ENUM_CONSTANT(TEXT_DIRECTION_INHERITED);
  2604. BIND_ENUM_CONSTANT(TEXT_DIRECTION_AUTO);
  2605. BIND_ENUM_CONSTANT(TEXT_DIRECTION_LTR);
  2606. BIND_ENUM_CONSTANT(TEXT_DIRECTION_RTL);
  2607. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_DEFAULT);
  2608. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_URI);
  2609. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_FILE);
  2610. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_EMAIL);
  2611. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_LIST);
  2612. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_NONE);
  2613. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_CUSTOM);
  2614. ADD_SIGNAL(MethodInfo("resized"));
  2615. ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
  2616. ADD_SIGNAL(MethodInfo("mouse_entered"));
  2617. ADD_SIGNAL(MethodInfo("mouse_exited"));
  2618. ADD_SIGNAL(MethodInfo("focus_entered"));
  2619. ADD_SIGNAL(MethodInfo("focus_exited"));
  2620. ADD_SIGNAL(MethodInfo("size_flags_changed"));
  2621. ADD_SIGNAL(MethodInfo("minimum_size_changed"));
  2622. ADD_SIGNAL(MethodInfo("theme_changed"));
  2623. GDVIRTUAL_BIND(_has_point, "position");
  2624. GDVIRTUAL_BIND(_structured_text_parser, "args", "text");
  2625. GDVIRTUAL_BIND(_get_minimum_size);
  2626. GDVIRTUAL_BIND(_get_drag_data, "at_position");
  2627. GDVIRTUAL_BIND(_can_drop_data, "at_position", "data");
  2628. GDVIRTUAL_BIND(_drop_data, "at_position", "data");
  2629. GDVIRTUAL_BIND(_make_custom_tooltip, "for_text");
  2630. GDVIRTUAL_BIND(_gui_input, "event");
  2631. }