control.cpp 122 KB

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