control.cpp 86 KB

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