control.cpp 100 KB

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