control.cpp 87 KB

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