control.cpp 89 KB

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