control.cpp 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555
  1. /*************************************************************************/
  2. /* control.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "control.h"
  30. #include "global_config.h"
  31. #include "scene/main/canvas_layer.h"
  32. #include "scene/main/viewport.h"
  33. #include "servers/visual_server.h"
  34. #include "message_queue.h"
  35. #include "os/keyboard.h"
  36. #include "os/os.h"
  37. #include "print_string.h"
  38. #include "scene/gui/label.h"
  39. #include "scene/gui/panel.h"
  40. #include "scene/scene_string_names.h"
  41. #ifdef TOOLS_ENABLED
  42. #include "editor/editor_settings.h"
  43. #endif
  44. #include <stdio.h>
  45. Variant Control::edit_get_state() const {
  46. Dictionary s;
  47. s["rect"] = get_rect();
  48. s["rot"] = get_rotation();
  49. s["scale"] = get_scale();
  50. return s;
  51. }
  52. void Control::edit_set_state(const Variant &p_state) {
  53. Dictionary s = p_state;
  54. Rect2 state = s["rect"];
  55. set_pos(state.pos);
  56. set_size(state.size);
  57. set_rotation(s["rot"]);
  58. set_scale(s["scale"]);
  59. }
  60. void Control::set_custom_minimum_size(const Size2 &p_custom) {
  61. if (p_custom == data.custom_minimum_size)
  62. return;
  63. data.custom_minimum_size = p_custom;
  64. minimum_size_changed();
  65. }
  66. Size2 Control::get_custom_minimum_size() const {
  67. return data.custom_minimum_size;
  68. }
  69. Size2 Control::get_combined_minimum_size() const {
  70. Size2 minsize = get_minimum_size();
  71. minsize.x = MAX(minsize.x, data.custom_minimum_size.x);
  72. minsize.y = MAX(minsize.y, data.custom_minimum_size.y);
  73. return minsize;
  74. }
  75. Size2 Control::edit_get_minimum_size() const {
  76. return get_combined_minimum_size();
  77. }
  78. void Control::edit_set_rect(const Rect2 &p_edit_rect) {
  79. Transform2D postxf;
  80. postxf.set_rotation_and_scale(data.rotation, data.scale);
  81. Vector2 new_pos = postxf.xform(p_edit_rect.pos);
  82. Vector2 pos = get_pos() + new_pos;
  83. Rect2 new_rect = get_rect();
  84. new_rect.pos = pos.snapped(Vector2(1, 1));
  85. new_rect.size = p_edit_rect.size.snapped(Vector2(1, 1));
  86. set_pos(new_rect.pos);
  87. set_size(new_rect.size);
  88. }
  89. bool Control::_set(const StringName &p_name, const Variant &p_value) {
  90. String name = p_name;
  91. if (!name.begins_with("custom")) {
  92. return false;
  93. }
  94. if (p_value.get_type() == Variant::NIL) {
  95. if (name.begins_with("custom_icons/")) {
  96. String dname = name.get_slicec('/', 1);
  97. data.icon_override.erase(dname);
  98. notification(NOTIFICATION_THEME_CHANGED);
  99. update();
  100. } else if (name.begins_with("custom_shaders/")) {
  101. String dname = name.get_slicec('/', 1);
  102. data.shader_override.erase(dname);
  103. notification(NOTIFICATION_THEME_CHANGED);
  104. update();
  105. } else if (name.begins_with("custom_styles/")) {
  106. String dname = name.get_slicec('/', 1);
  107. data.style_override.erase(dname);
  108. notification(NOTIFICATION_THEME_CHANGED);
  109. update();
  110. } else if (name.begins_with("custom_fonts/")) {
  111. String dname = name.get_slicec('/', 1);
  112. if (data.font_override.has(dname)) {
  113. _unref_font(data.font_override[dname]);
  114. }
  115. data.font_override.erase(dname);
  116. notification(NOTIFICATION_THEME_CHANGED);
  117. update();
  118. } else if (name.begins_with("custom_colors/")) {
  119. String dname = name.get_slicec('/', 1);
  120. data.color_override.erase(dname);
  121. notification(NOTIFICATION_THEME_CHANGED);
  122. update();
  123. } else if (name.begins_with("custom_constants/")) {
  124. String dname = name.get_slicec('/', 1);
  125. data.constant_override.erase(dname);
  126. notification(NOTIFICATION_THEME_CHANGED);
  127. update();
  128. } else
  129. return false;
  130. } else {
  131. if (name.begins_with("custom_icons/")) {
  132. String dname = name.get_slicec('/', 1);
  133. notification(NOTIFICATION_THEME_CHANGED);
  134. add_icon_override(dname, p_value);
  135. } else if (name.begins_with("custom_shaders/")) {
  136. String dname = name.get_slicec('/', 1);
  137. add_shader_override(dname, p_value);
  138. notification(NOTIFICATION_THEME_CHANGED);
  139. } else if (name.begins_with("custom_styles/")) {
  140. String dname = name.get_slicec('/', 1);
  141. add_style_override(dname, p_value);
  142. notification(NOTIFICATION_THEME_CHANGED);
  143. } else if (name.begins_with("custom_fonts/")) {
  144. String dname = name.get_slicec('/', 1);
  145. add_font_override(dname, p_value);
  146. notification(NOTIFICATION_THEME_CHANGED);
  147. } else if (name.begins_with("custom_colors/")) {
  148. String dname = name.get_slicec('/', 1);
  149. add_color_override(dname, p_value);
  150. notification(NOTIFICATION_THEME_CHANGED);
  151. } else if (name.begins_with("custom_constants/")) {
  152. String dname = name.get_slicec('/', 1);
  153. add_constant_override(dname, p_value);
  154. notification(NOTIFICATION_THEME_CHANGED);
  155. } else
  156. return false;
  157. }
  158. return true;
  159. }
  160. void Control::_update_minimum_size() {
  161. if (!is_inside_tree())
  162. return;
  163. data.pending_min_size_update = false;
  164. Size2 minsize = get_combined_minimum_size();
  165. if (minsize.x > data.size_cache.x ||
  166. minsize.y > data.size_cache.y) {
  167. _size_changed();
  168. }
  169. emit_signal(SceneStringNames::get_singleton()->minimum_size_changed);
  170. }
  171. bool Control::_get(const StringName &p_name, Variant &r_ret) const {
  172. String sname = p_name;
  173. if (!sname.begins_with("custom")) {
  174. return false;
  175. }
  176. if (sname.begins_with("custom_icons/")) {
  177. String name = sname.get_slicec('/', 1);
  178. r_ret = data.icon_override.has(name) ? Variant(data.icon_override[name]) : Variant();
  179. } else if (sname.begins_with("custom_shaders/")) {
  180. String name = sname.get_slicec('/', 1);
  181. r_ret = data.shader_override.has(name) ? Variant(data.shader_override[name]) : Variant();
  182. } else if (sname.begins_with("custom_styles/")) {
  183. String name = sname.get_slicec('/', 1);
  184. r_ret = data.style_override.has(name) ? Variant(data.style_override[name]) : Variant();
  185. } else if (sname.begins_with("custom_fonts/")) {
  186. String name = sname.get_slicec('/', 1);
  187. r_ret = data.font_override.has(name) ? Variant(data.font_override[name]) : Variant();
  188. } else if (sname.begins_with("custom_colors/")) {
  189. String name = sname.get_slicec('/', 1);
  190. r_ret = data.color_override.has(name) ? Variant(data.color_override[name]) : Variant();
  191. } else if (sname.begins_with("custom_constants/")) {
  192. String name = sname.get_slicec('/', 1);
  193. r_ret = data.constant_override.has(name) ? Variant(data.constant_override[name]) : Variant();
  194. } else
  195. return false;
  196. return true;
  197. }
  198. void Control::_get_property_list(List<PropertyInfo> *p_list) const {
  199. Ref<Theme> theme;
  200. if (data.theme.is_valid()) {
  201. theme = data.theme;
  202. } else {
  203. theme = Theme::get_default();
  204. }
  205. {
  206. List<StringName> names;
  207. theme->get_icon_list(get_class_name(), &names);
  208. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  209. uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  210. if (data.icon_override.has(E->get()))
  211. hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  212. p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Texture", hint));
  213. }
  214. }
  215. {
  216. List<StringName> names;
  217. theme->get_shader_list(get_class_name(), &names);
  218. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  219. uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  220. if (data.shader_override.has(E->get()))
  221. hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  222. p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_shaders/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph", hint));
  223. }
  224. }
  225. {
  226. List<StringName> names;
  227. theme->get_stylebox_list(get_class_name(), &names);
  228. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  229. uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  230. if (data.style_override.has(E->get()))
  231. hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  232. p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_styles/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", hint));
  233. }
  234. }
  235. {
  236. List<StringName> names;
  237. theme->get_font_list(get_class_name(), &names);
  238. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  239. uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  240. if (data.font_override.has(E->get()))
  241. hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  242. p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_fonts/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Font", hint));
  243. }
  244. }
  245. {
  246. List<StringName> names;
  247. theme->get_color_list(get_class_name(), &names);
  248. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  249. uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  250. if (data.color_override.has(E->get()))
  251. hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  252. p_list->push_back(PropertyInfo(Variant::COLOR, "custom_colors/" + E->get(), PROPERTY_HINT_NONE, "", hint));
  253. }
  254. }
  255. {
  256. List<StringName> names;
  257. theme->get_constant_list(get_class_name(), &names);
  258. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  259. uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  260. if (data.constant_override.has(E->get()))
  261. hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  262. p_list->push_back(PropertyInfo(Variant::INT, "custom_constants/" + E->get(), PROPERTY_HINT_RANGE, "-16384,16384", hint));
  263. }
  264. }
  265. }
  266. Control *Control::get_parent_control() const {
  267. return data.parent;
  268. }
  269. void Control::_resize(const Size2 &p_size) {
  270. _size_changed();
  271. }
  272. //moved theme configuration here, so controls can set up even if still not inside active scene
  273. void Control::add_child_notify(Node *p_child) {
  274. Control *child_c = p_child->cast_to<Control>();
  275. if (!child_c)
  276. return;
  277. if (child_c->data.theme.is_null() && data.theme_owner) {
  278. _propagate_theme_changed(child_c, data.theme_owner); //need to propagate here, since many controls may require setting up stuff
  279. }
  280. }
  281. void Control::remove_child_notify(Node *p_child) {
  282. Control *child_c = p_child->cast_to<Control>();
  283. if (!child_c)
  284. return;
  285. if (child_c->data.theme_owner && child_c->data.theme.is_null()) {
  286. _propagate_theme_changed(child_c, NULL);
  287. }
  288. }
  289. void Control::_update_canvas_item_transform() {
  290. Transform2D xform = Transform2D(data.rotation, get_pos());
  291. xform.scale_basis(data.scale);
  292. VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform);
  293. }
  294. void Control::_notification(int p_notification) {
  295. switch (p_notification) {
  296. case NOTIFICATION_ENTER_TREE: {
  297. _size_changed();
  298. } break;
  299. case NOTIFICATION_EXIT_TREE: {
  300. get_viewport()->_gui_remove_control(this);
  301. } break;
  302. case NOTIFICATION_ENTER_CANVAS: {
  303. data.parent = get_parent()->cast_to<Control>();
  304. if (is_set_as_toplevel()) {
  305. data.SI = get_viewport()->_gui_add_subwindow_control(this);
  306. if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) {
  307. data.theme_owner = data.parent->data.theme_owner;
  308. notification(NOTIFICATION_THEME_CHANGED);
  309. }
  310. } else {
  311. Node *parent = this; //meh
  312. Control *parent_control = NULL;
  313. bool subwindow = false;
  314. while (parent) {
  315. parent = parent->get_parent();
  316. if (!parent)
  317. break;
  318. CanvasItem *ci = parent->cast_to<CanvasItem>();
  319. if (ci && ci->is_set_as_toplevel()) {
  320. subwindow = true;
  321. break;
  322. }
  323. parent_control = parent->cast_to<Control>();
  324. if (parent_control) {
  325. break;
  326. } else if (ci) {
  327. } else {
  328. break;
  329. }
  330. }
  331. if (parent_control) {
  332. //do nothing, has a parent control
  333. if (data.theme.is_null() && parent_control->data.theme_owner) {
  334. data.theme_owner = parent_control->data.theme_owner;
  335. notification(NOTIFICATION_THEME_CHANGED);
  336. }
  337. } else if (subwindow) {
  338. //is a subwindow (process input before other controls for that canvas)
  339. data.SI = get_viewport()->_gui_add_subwindow_control(this);
  340. } else {
  341. //is a regular root control
  342. data.RI = get_viewport()->_gui_add_root_control(this);
  343. }
  344. data.parent_canvas_item = get_parent_item();
  345. if (data.parent_canvas_item) {
  346. data.parent_canvas_item->connect("item_rect_changed", this, "_size_changed");
  347. } else {
  348. //connect viewport
  349. get_viewport()->connect("size_changed", this, "_size_changed");
  350. }
  351. }
  352. /*
  353. if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) {
  354. data.theme_owner=data.parent->data.theme_owner;
  355. notification(NOTIFICATION_THEME_CHANGED);
  356. }
  357. */
  358. } break;
  359. case NOTIFICATION_EXIT_CANVAS: {
  360. if (data.parent_canvas_item) {
  361. data.parent_canvas_item->disconnect("item_rect_changed", this, "_size_changed");
  362. data.parent_canvas_item = NULL;
  363. } else if (!is_set_as_toplevel()) {
  364. //disconnect viewport
  365. get_viewport()->disconnect("size_changed", this, "_size_changed");
  366. }
  367. if (data.MI) {
  368. get_viewport()->_gui_remove_modal_control(data.MI);
  369. data.MI = NULL;
  370. }
  371. if (data.SI) {
  372. get_viewport()->_gui_remove_subwindow_control(data.SI);
  373. data.SI = NULL;
  374. }
  375. if (data.RI) {
  376. get_viewport()->_gui_remove_root_control(data.RI);
  377. data.RI = NULL;
  378. }
  379. data.parent = NULL;
  380. data.parent_canvas_item = NULL;
  381. /*
  382. if (data.theme_owner && data.theme.is_null()) {
  383. data.theme_owner=NULL;
  384. notification(NOTIFICATION_THEME_CHANGED);
  385. }
  386. */
  387. } break;
  388. case NOTIFICATION_MOVED_IN_PARENT: {
  389. // some parents need to know the order of the childrens to draw (like TabContainer)
  390. // update if necessary
  391. if (data.parent)
  392. data.parent->update();
  393. update();
  394. if (data.SI) {
  395. get_viewport()->_gui_set_subwindow_order_dirty();
  396. }
  397. if (data.RI) {
  398. get_viewport()->_gui_set_root_order_dirty();
  399. }
  400. } break;
  401. case NOTIFICATION_RESIZED: {
  402. emit_signal(SceneStringNames::get_singleton()->resized);
  403. } break;
  404. case NOTIFICATION_DRAW: {
  405. _update_canvas_item_transform();
  406. VisualServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size()));
  407. VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents);
  408. //emit_signal(SceneStringNames::get_singleton()->draw);
  409. } break;
  410. case NOTIFICATION_MOUSE_ENTER: {
  411. emit_signal(SceneStringNames::get_singleton()->mouse_entered);
  412. } break;
  413. case NOTIFICATION_MOUSE_EXIT: {
  414. emit_signal(SceneStringNames::get_singleton()->mouse_exited);
  415. } break;
  416. case NOTIFICATION_FOCUS_ENTER: {
  417. emit_signal(SceneStringNames::get_singleton()->focus_entered);
  418. update();
  419. } break;
  420. case NOTIFICATION_FOCUS_EXIT: {
  421. emit_signal(SceneStringNames::get_singleton()->focus_exited);
  422. update();
  423. } break;
  424. case NOTIFICATION_THEME_CHANGED: {
  425. update();
  426. } break;
  427. case NOTIFICATION_MODAL_CLOSE: {
  428. emit_signal("modal_closed");
  429. } break;
  430. case NOTIFICATION_VISIBILITY_CHANGED: {
  431. if (!is_visible_in_tree()) {
  432. if (get_viewport() != NULL)
  433. get_viewport()->_gui_hid_control(this);
  434. if (is_inside_tree()) {
  435. _modal_stack_remove();
  436. minimum_size_changed();
  437. }
  438. //remove key focus
  439. //remove modalness
  440. } else {
  441. _size_changed();
  442. }
  443. } break;
  444. case SceneTree::NOTIFICATION_WM_UNFOCUS_REQUEST: {
  445. get_viewport()->_gui_unfocus_control(this);
  446. } break;
  447. }
  448. }
  449. bool Control::clips_input() const {
  450. return false;
  451. }
  452. bool Control::has_point(const Point2 &p_point) const {
  453. if (get_script_instance()) {
  454. Variant v = p_point;
  455. const Variant *p = &v;
  456. Variant::CallError ce;
  457. Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->has_point, &p, 1, ce);
  458. if (ce.error == Variant::CallError::CALL_OK) {
  459. return ret;
  460. }
  461. }
  462. /*if (has_stylebox("mask")) {
  463. Ref<StyleBox> mask = get_stylebox("mask");
  464. return mask->test_mask(p_point,Rect2(Point2(),get_size()));
  465. }*/
  466. return Rect2(Point2(), get_size()).has_point(p_point);
  467. }
  468. void Control::set_drag_forwarding(Control *p_target) {
  469. if (p_target)
  470. data.drag_owner = p_target->get_instance_ID();
  471. else
  472. data.drag_owner = 0;
  473. }
  474. Variant Control::get_drag_data(const Point2 &p_point) {
  475. if (data.drag_owner) {
  476. Object *obj = ObjectDB::get_instance(data.drag_owner);
  477. if (obj) {
  478. Control *c = obj->cast_to<Control>();
  479. return c->call("get_drag_data_fw", p_point, this);
  480. }
  481. }
  482. if (get_script_instance()) {
  483. Variant v = p_point;
  484. const Variant *p = &v;
  485. Variant::CallError ce;
  486. Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->get_drag_data, &p, 1, ce);
  487. if (ce.error == Variant::CallError::CALL_OK)
  488. return ret;
  489. }
  490. return Variant();
  491. }
  492. bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
  493. if (data.drag_owner) {
  494. Object *obj = ObjectDB::get_instance(data.drag_owner);
  495. if (obj) {
  496. Control *c = obj->cast_to<Control>();
  497. return c->call("can_drop_data_fw", p_point, p_data, this);
  498. }
  499. }
  500. if (get_script_instance()) {
  501. Variant v = p_point;
  502. const Variant *p[2] = { &v, &p_data };
  503. Variant::CallError ce;
  504. Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->can_drop_data, p, 2, ce);
  505. if (ce.error == Variant::CallError::CALL_OK)
  506. return ret;
  507. }
  508. return Variant();
  509. }
  510. void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
  511. if (data.drag_owner) {
  512. Object *obj = ObjectDB::get_instance(data.drag_owner);
  513. if (obj) {
  514. Control *c = obj->cast_to<Control>();
  515. c->call("drop_data_fw", p_point, p_data, this);
  516. return;
  517. }
  518. }
  519. if (get_script_instance()) {
  520. Variant v = p_point;
  521. const Variant *p[2] = { &v, &p_data };
  522. Variant::CallError ce;
  523. Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->drop_data, p, 2, ce);
  524. if (ce.error == Variant::CallError::CALL_OK)
  525. return;
  526. }
  527. }
  528. void Control::force_drag(const Variant &p_data, Control *p_control) {
  529. ERR_FAIL_COND(!is_inside_tree());
  530. ERR_FAIL_COND(p_data.get_type() == Variant::NIL);
  531. get_viewport()->_gui_force_drag(this, p_data, p_control);
  532. }
  533. void Control::set_drag_preview(Control *p_control) {
  534. ERR_FAIL_COND(!is_inside_tree());
  535. get_viewport()->_gui_set_drag_preview(this, p_control);
  536. }
  537. bool Control::is_window_modal_on_top() const {
  538. if (!is_inside_tree())
  539. return false;
  540. return get_viewport()->_gui_is_modal_on_top(this);
  541. }
  542. uint64_t Control::get_modal_frame() const {
  543. return data.modal_frame;
  544. }
  545. Size2 Control::get_minimum_size() const {
  546. ScriptInstance *si = const_cast<Control *>(this)->get_script_instance();
  547. if (si) {
  548. Variant::CallError ce;
  549. Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, NULL, 0, ce);
  550. if (ce.error == Variant::CallError::CALL_OK)
  551. return s;
  552. }
  553. return Size2();
  554. }
  555. Ref<Texture> Control::get_icon(const StringName &p_name, const StringName &p_type) const {
  556. if (p_type == StringName() || p_type == "") {
  557. const Ref<Texture> *tex = data.icon_override.getptr(p_name);
  558. if (tex)
  559. return *tex;
  560. }
  561. StringName type = p_type ? p_type : get_class_name();
  562. // try with custom themes
  563. Control *theme_owner = data.theme_owner;
  564. while (theme_owner) {
  565. StringName class_name = type;
  566. while (class_name != StringName()) {
  567. if (theme_owner->data.theme->has_icon(p_name, class_name)) {
  568. return theme_owner->data.theme->get_icon(p_name, class_name);
  569. }
  570. class_name = ClassDB::get_parent_class_nocheck(class_name);
  571. }
  572. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  573. if (parent)
  574. theme_owner = parent->data.theme_owner;
  575. else
  576. theme_owner = NULL;
  577. }
  578. return Theme::get_default()->get_icon(p_name, type);
  579. }
  580. Ref<Shader> Control::get_shader(const StringName &p_name, const StringName &p_type) const {
  581. if (p_type == StringName() || p_type == "") {
  582. const Ref<Shader> *sdr = data.shader_override.getptr(p_name);
  583. if (sdr)
  584. return *sdr;
  585. }
  586. StringName type = p_type ? p_type : get_class_name();
  587. // try with custom themes
  588. Control *theme_owner = data.theme_owner;
  589. while (theme_owner) {
  590. StringName class_name = type;
  591. while (class_name != StringName()) {
  592. if (theme_owner->data.theme->has_shader(p_name, class_name)) {
  593. return theme_owner->data.theme->get_shader(p_name, class_name);
  594. }
  595. class_name = ClassDB::get_parent_class_nocheck(class_name);
  596. }
  597. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  598. if (parent)
  599. theme_owner = parent->data.theme_owner;
  600. else
  601. theme_owner = NULL;
  602. }
  603. return Theme::get_default()->get_shader(p_name, type);
  604. }
  605. Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName &p_type) const {
  606. if (p_type == StringName() || p_type == "") {
  607. const Ref<StyleBox> *style = data.style_override.getptr(p_name);
  608. if (style)
  609. return *style;
  610. }
  611. StringName type = p_type ? p_type : get_class_name();
  612. // try with custom themes
  613. Control *theme_owner = data.theme_owner;
  614. while (theme_owner) {
  615. StringName class_name = type;
  616. while (class_name != StringName()) {
  617. if (theme_owner->data.theme->has_stylebox(p_name, class_name)) {
  618. return theme_owner->data.theme->get_stylebox(p_name, class_name);
  619. }
  620. class_name = ClassDB::get_parent_class_nocheck(class_name);
  621. }
  622. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  623. if (parent)
  624. theme_owner = parent->data.theme_owner;
  625. else
  626. theme_owner = NULL;
  627. }
  628. return Theme::get_default()->get_stylebox(p_name, type);
  629. }
  630. Ref<Font> Control::get_font(const StringName &p_name, const StringName &p_type) const {
  631. if (p_type == StringName() || p_type == "") {
  632. const Ref<Font> *font = data.font_override.getptr(p_name);
  633. if (font)
  634. return *font;
  635. }
  636. StringName type = p_type ? p_type : get_class_name();
  637. // try with custom themes
  638. Control *theme_owner = data.theme_owner;
  639. while (theme_owner) {
  640. StringName class_name = type;
  641. while (class_name != StringName()) {
  642. if (theme_owner->data.theme->has_font(p_name, class_name)) {
  643. return theme_owner->data.theme->get_font(p_name, class_name);
  644. }
  645. class_name = ClassDB::get_parent_class_nocheck(class_name);
  646. }
  647. if (theme_owner->data.theme->get_default_theme_font().is_valid())
  648. return theme_owner->data.theme->get_default_theme_font();
  649. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  650. if (parent)
  651. theme_owner = parent->data.theme_owner;
  652. else
  653. theme_owner = NULL;
  654. }
  655. return Theme::get_default()->get_font(p_name, type);
  656. }
  657. Color Control::get_color(const StringName &p_name, const StringName &p_type) const {
  658. if (p_type == StringName() || p_type == "") {
  659. const Color *color = data.color_override.getptr(p_name);
  660. if (color)
  661. return *color;
  662. }
  663. StringName type = p_type ? p_type : get_class_name();
  664. // try with custom themes
  665. Control *theme_owner = data.theme_owner;
  666. while (theme_owner) {
  667. StringName class_name = type;
  668. while (class_name != StringName()) {
  669. if (theme_owner->data.theme->has_color(p_name, class_name)) {
  670. return theme_owner->data.theme->get_color(p_name, class_name);
  671. }
  672. class_name = ClassDB::get_parent_class_nocheck(class_name);
  673. }
  674. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  675. if (parent)
  676. theme_owner = parent->data.theme_owner;
  677. else
  678. theme_owner = NULL;
  679. }
  680. return Theme::get_default()->get_color(p_name, type);
  681. }
  682. int Control::get_constant(const StringName &p_name, const StringName &p_type) const {
  683. if (p_type == StringName() || p_type == "") {
  684. const int *constant = data.constant_override.getptr(p_name);
  685. if (constant)
  686. return *constant;
  687. }
  688. StringName type = p_type ? p_type : get_class_name();
  689. // try with custom themes
  690. Control *theme_owner = data.theme_owner;
  691. while (theme_owner) {
  692. StringName class_name = type;
  693. while (class_name != StringName()) {
  694. if (theme_owner->data.theme->has_constant(p_name, class_name)) {
  695. return theme_owner->data.theme->get_constant(p_name, class_name);
  696. }
  697. class_name = ClassDB::get_parent_class_nocheck(class_name);
  698. }
  699. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  700. if (parent)
  701. theme_owner = parent->data.theme_owner;
  702. else
  703. theme_owner = NULL;
  704. }
  705. return Theme::get_default()->get_constant(p_name, type);
  706. }
  707. bool Control::has_icon_override(const StringName &p_name) const {
  708. const Ref<Texture> *tex = data.icon_override.getptr(p_name);
  709. if (tex)
  710. return true;
  711. else
  712. return false;
  713. }
  714. bool Control::has_shader_override(const StringName &p_name) const {
  715. const Ref<Shader> *sdr = data.shader_override.getptr(p_name);
  716. if (sdr)
  717. return true;
  718. else
  719. return false;
  720. }
  721. bool Control::has_stylebox_override(const StringName &p_name) const {
  722. const Ref<StyleBox> *style = data.style_override.getptr(p_name);
  723. if (style)
  724. return true;
  725. else
  726. return false;
  727. }
  728. bool Control::has_font_override(const StringName &p_name) const {
  729. const Ref<Font> *font = data.font_override.getptr(p_name);
  730. if (font)
  731. return true;
  732. else
  733. return false;
  734. }
  735. bool Control::has_color_override(const StringName &p_name) const {
  736. const Color *color = data.color_override.getptr(p_name);
  737. if (color)
  738. return true;
  739. else
  740. return false;
  741. }
  742. bool Control::has_constant_override(const StringName &p_name) const {
  743. const int *constant = data.constant_override.getptr(p_name);
  744. if (constant)
  745. return true;
  746. else
  747. return false;
  748. }
  749. bool Control::has_icon(const StringName &p_name, const StringName &p_type) const {
  750. if (p_type == StringName() || p_type == "") {
  751. if (has_icon_override(p_name) == true)
  752. return true;
  753. }
  754. StringName type = p_type ? p_type : get_class_name();
  755. // try with custom themes
  756. Control *theme_owner = data.theme_owner;
  757. while (theme_owner) {
  758. StringName class_name = type;
  759. while (class_name != StringName()) {
  760. if (theme_owner->data.theme->has_icon(p_name, class_name)) {
  761. return true;
  762. }
  763. class_name = ClassDB::get_parent_class_nocheck(class_name);
  764. }
  765. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  766. if (parent)
  767. theme_owner = parent->data.theme_owner;
  768. else
  769. theme_owner = NULL;
  770. }
  771. return Theme::get_default()->has_icon(p_name, type);
  772. }
  773. bool Control::has_shader(const StringName &p_name, const StringName &p_type) const {
  774. if (p_type == StringName() || p_type == "") {
  775. if (has_shader_override(p_name) == true)
  776. return true;
  777. }
  778. StringName type = p_type ? p_type : get_class_name();
  779. // try with custom themes
  780. Control *theme_owner = data.theme_owner;
  781. while (theme_owner) {
  782. StringName class_name = type;
  783. while (class_name != StringName()) {
  784. if (theme_owner->data.theme->has_shader(p_name, class_name)) {
  785. return true;
  786. }
  787. class_name = ClassDB::get_parent_class_nocheck(class_name);
  788. }
  789. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  790. if (parent)
  791. theme_owner = parent->data.theme_owner;
  792. else
  793. theme_owner = NULL;
  794. }
  795. return Theme::get_default()->has_shader(p_name, type);
  796. }
  797. bool Control::has_stylebox(const StringName &p_name, const StringName &p_type) const {
  798. if (p_type == StringName() || p_type == "") {
  799. if (has_stylebox_override(p_name) == true)
  800. return true;
  801. }
  802. StringName type = p_type ? p_type : get_class_name();
  803. // try with custom themes
  804. Control *theme_owner = data.theme_owner;
  805. while (theme_owner) {
  806. StringName class_name = type;
  807. while (class_name != StringName()) {
  808. if (theme_owner->data.theme->has_stylebox(p_name, class_name)) {
  809. return true;
  810. }
  811. class_name = ClassDB::get_parent_class_nocheck(class_name);
  812. }
  813. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  814. if (parent)
  815. theme_owner = parent->data.theme_owner;
  816. else
  817. theme_owner = NULL;
  818. }
  819. return Theme::get_default()->has_stylebox(p_name, type);
  820. }
  821. bool Control::has_font(const StringName &p_name, const StringName &p_type) const {
  822. if (p_type == StringName() || p_type == "") {
  823. if (has_font_override(p_name) == true)
  824. return true;
  825. }
  826. StringName type = p_type ? p_type : get_class_name();
  827. // try with custom themes
  828. Control *theme_owner = data.theme_owner;
  829. while (theme_owner) {
  830. StringName class_name = type;
  831. while (class_name != StringName()) {
  832. if (theme_owner->data.theme->has_font(p_name, class_name)) {
  833. return true;
  834. }
  835. class_name = ClassDB::get_parent_class_nocheck(class_name);
  836. }
  837. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  838. if (parent)
  839. theme_owner = parent->data.theme_owner;
  840. else
  841. theme_owner = NULL;
  842. }
  843. return Theme::get_default()->has_font(p_name, type);
  844. }
  845. bool Control::has_color(const StringName &p_name, const StringName &p_type) const {
  846. if (p_type == StringName() || p_type == "") {
  847. if (has_color_override(p_name) == true)
  848. return true;
  849. }
  850. StringName type = p_type ? p_type : get_class_name();
  851. // try with custom themes
  852. Control *theme_owner = data.theme_owner;
  853. while (theme_owner) {
  854. StringName class_name = type;
  855. while (class_name != StringName()) {
  856. if (theme_owner->data.theme->has_color(p_name, class_name)) {
  857. return true;
  858. }
  859. class_name = ClassDB::get_parent_class_nocheck(class_name);
  860. }
  861. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  862. if (parent)
  863. theme_owner = parent->data.theme_owner;
  864. else
  865. theme_owner = NULL;
  866. }
  867. return Theme::get_default()->has_color(p_name, type);
  868. }
  869. bool Control::has_constant(const StringName &p_name, const StringName &p_type) const {
  870. if (p_type == StringName() || p_type == "") {
  871. if (has_constant_override(p_name) == true)
  872. return true;
  873. }
  874. StringName type = p_type ? p_type : get_class_name();
  875. // try with custom themes
  876. Control *theme_owner = data.theme_owner;
  877. while (theme_owner) {
  878. StringName class_name = type;
  879. while (class_name != StringName()) {
  880. if (theme_owner->data.theme->has_constant(p_name, class_name)) {
  881. return true;
  882. }
  883. class_name = ClassDB::get_parent_class_nocheck(class_name);
  884. }
  885. Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL;
  886. if (parent)
  887. theme_owner = parent->data.theme_owner;
  888. else
  889. theme_owner = NULL;
  890. }
  891. return Theme::get_default()->has_constant(p_name, type);
  892. }
  893. Size2 Control::get_parent_area_size() const {
  894. ERR_FAIL_COND_V(!is_inside_tree(), Size2());
  895. Size2 parent_size;
  896. if (data.parent_canvas_item) {
  897. parent_size = data.parent_canvas_item->get_item_rect().size;
  898. } else {
  899. parent_size = get_viewport()->get_visible_rect().size;
  900. }
  901. return parent_size;
  902. }
  903. void Control::_size_changed() {
  904. if (!is_inside_tree())
  905. return;
  906. Size2 parent_size = get_parent_area_size();
  907. float margin_pos[4];
  908. for (int i = 0; i < 4; i++) {
  909. float area = parent_size[i & 1];
  910. switch (data.anchor[i]) {
  911. case ANCHOR_BEGIN: {
  912. margin_pos[i] = data.margin[i];
  913. } break;
  914. case ANCHOR_END: {
  915. margin_pos[i] = area - data.margin[i];
  916. } break;
  917. case ANCHOR_CENTER: {
  918. margin_pos[i] = (area / 2) - data.margin[i];
  919. } break;
  920. }
  921. }
  922. Point2 new_pos_cache = Point2(margin_pos[0], margin_pos[1]).floor();
  923. Size2 new_size_cache = Point2(margin_pos[2], margin_pos[3]).floor() - new_pos_cache;
  924. Size2 minimum_size = get_combined_minimum_size();
  925. new_size_cache.x = MAX(minimum_size.x, new_size_cache.x);
  926. new_size_cache.y = MAX(minimum_size.y, new_size_cache.y);
  927. bool pos_changed = new_pos_cache != data.pos_cache;
  928. bool size_changed = new_size_cache != data.size_cache;
  929. data.pos_cache = new_pos_cache;
  930. data.size_cache = new_size_cache;
  931. if (size_changed) {
  932. notification(NOTIFICATION_RESIZED);
  933. }
  934. if (pos_changed || size_changed) {
  935. item_rect_changed(size_changed);
  936. _change_notify_margins();
  937. _notify_transform();
  938. }
  939. if (pos_changed && !size_changed) {
  940. _update_canvas_item_transform(); //move because it won't be updated
  941. }
  942. }
  943. float Control::_get_parent_range(int p_idx) const {
  944. if (!is_inside_tree()) {
  945. return 1.0;
  946. }
  947. if (data.parent_canvas_item) {
  948. return data.parent_canvas_item->get_item_rect().size[p_idx & 1];
  949. } else {
  950. return get_viewport()->get_visible_rect().size[p_idx & 1];
  951. }
  952. return 1.0;
  953. }
  954. float Control::_get_range(int p_idx) const {
  955. p_idx &= 1;
  956. float parent_range = _get_parent_range(p_idx);
  957. float from = _a2s(data.margin[p_idx], data.anchor[p_idx], parent_range);
  958. float to = _a2s(data.margin[p_idx + 2], data.anchor[p_idx + 2], parent_range);
  959. return to - from;
  960. }
  961. float Control::_s2a(float p_val, AnchorType p_anchor, float p_range) const {
  962. switch (p_anchor) {
  963. case ANCHOR_BEGIN: {
  964. return p_val;
  965. } break;
  966. case ANCHOR_END: {
  967. return p_range - p_val;
  968. } break;
  969. case ANCHOR_CENTER: {
  970. return (p_range / 2) - p_val;
  971. } break;
  972. }
  973. return 0;
  974. }
  975. float Control::_a2s(float p_val, AnchorType p_anchor, float p_range) const {
  976. switch (p_anchor) {
  977. case ANCHOR_BEGIN: {
  978. return Math::floor(p_val);
  979. } break;
  980. case ANCHOR_END: {
  981. return Math::floor(p_range - p_val);
  982. } break;
  983. case ANCHOR_CENTER: {
  984. return Math::floor((p_range / 2) - p_val);
  985. } break;
  986. }
  987. return 0;
  988. }
  989. void Control::set_anchor(Margin p_margin, AnchorType p_anchor, bool p_keep_margin) {
  990. if (!is_inside_tree()) {
  991. data.anchor[p_margin] = p_anchor;
  992. } else if (!p_keep_margin) {
  993. float pr = _get_parent_range(p_margin);
  994. float s = _a2s(data.margin[p_margin], data.anchor[p_margin], pr);
  995. data.anchor[p_margin] = p_anchor;
  996. data.margin[p_margin] = _s2a(s, p_anchor, pr);
  997. } else {
  998. data.anchor[p_margin] = p_anchor;
  999. _size_changed();
  1000. }
  1001. _change_notify();
  1002. }
  1003. void Control::_set_anchor(Margin p_margin, AnchorType p_anchor) {
  1004. #ifdef TOOLS_ENABLED
  1005. if (is_inside_tree() && get_tree()->is_editor_hint()) {
  1006. set_anchor(p_margin, p_anchor, EDITOR_DEF("editors/2d/keep_margins_when_changing_anchors", false));
  1007. } else {
  1008. set_anchor(p_margin, p_anchor, false);
  1009. }
  1010. #else
  1011. set_anchor(p_margin, p_anchor, false);
  1012. #endif
  1013. }
  1014. void Control::set_anchor_and_margin(Margin p_margin, AnchorType p_anchor, float p_pos) {
  1015. set_anchor(p_margin, p_anchor);
  1016. set_margin(p_margin, p_pos);
  1017. }
  1018. Control::AnchorType Control::get_anchor(Margin p_margin) const {
  1019. return data.anchor[p_margin];
  1020. }
  1021. void Control::_change_notify_margins() {
  1022. // this avoids sending the whole object data again on a change
  1023. _change_notify("margin_left");
  1024. _change_notify("margin_top");
  1025. _change_notify("margin_right");
  1026. _change_notify("margin_bottom");
  1027. _change_notify("rect_pos");
  1028. _change_notify("rect_size");
  1029. }
  1030. void Control::set_margin(Margin p_margin, float p_value) {
  1031. data.margin[p_margin] = p_value;
  1032. _size_changed();
  1033. }
  1034. void Control::set_begin(const Size2 &p_point) {
  1035. data.margin[0] = p_point.x;
  1036. data.margin[1] = p_point.y;
  1037. _size_changed();
  1038. }
  1039. void Control::set_end(const Size2 &p_point) {
  1040. data.margin[2] = p_point.x;
  1041. data.margin[3] = p_point.y;
  1042. _size_changed();
  1043. }
  1044. float Control::get_margin(Margin p_margin) const {
  1045. return data.margin[p_margin];
  1046. }
  1047. Size2 Control::get_begin() const {
  1048. return Size2(data.margin[0], data.margin[1]);
  1049. }
  1050. Size2 Control::get_end() const {
  1051. return Size2(data.margin[2], data.margin[3]);
  1052. }
  1053. Point2 Control::get_global_pos() const {
  1054. return get_global_transform().get_origin();
  1055. }
  1056. void Control::set_global_pos(const Point2 &p_point) {
  1057. Transform2D inv;
  1058. if (data.parent_canvas_item) {
  1059. inv = data.parent_canvas_item->get_global_transform().affine_inverse();
  1060. }
  1061. set_pos(inv.xform(p_point));
  1062. }
  1063. void Control::set_pos(const Size2 &p_point) {
  1064. float pw = _get_parent_range(0);
  1065. float ph = _get_parent_range(1);
  1066. float x = _a2s(data.margin[0], data.anchor[0], pw);
  1067. float y = _a2s(data.margin[1], data.anchor[1], ph);
  1068. float x2 = _a2s(data.margin[2], data.anchor[2], pw);
  1069. float y2 = _a2s(data.margin[3], data.anchor[3], ph);
  1070. Size2 ret = Size2(x2 - x, y2 - y);
  1071. Size2 min = get_combined_minimum_size();
  1072. Size2 size = Size2(MAX(min.width, ret.width), MAX(min.height, ret.height));
  1073. float w = size.x;
  1074. float h = size.y;
  1075. x = p_point.x;
  1076. y = p_point.y;
  1077. data.margin[0] = _s2a(x, data.anchor[0], pw);
  1078. data.margin[1] = _s2a(y, data.anchor[1], ph);
  1079. data.margin[2] = _s2a(x + w, data.anchor[2], pw);
  1080. data.margin[3] = _s2a(y + h, data.anchor[3], ph);
  1081. _size_changed();
  1082. }
  1083. void Control::set_size(const Size2 &p_size) {
  1084. Size2 new_size = p_size;
  1085. Size2 min = get_combined_minimum_size();
  1086. if (new_size.x < min.x)
  1087. new_size.x = min.x;
  1088. if (new_size.y < min.y)
  1089. new_size.y = min.y;
  1090. float pw = _get_parent_range(0);
  1091. float ph = _get_parent_range(1);
  1092. float x = _a2s(data.margin[0], data.anchor[0], pw);
  1093. float y = _a2s(data.margin[1], data.anchor[1], ph);
  1094. float w = new_size.width;
  1095. float h = new_size.height;
  1096. data.margin[2] = _s2a(x + w, data.anchor[2], pw);
  1097. data.margin[3] = _s2a(y + h, data.anchor[3], ph);
  1098. _size_changed();
  1099. }
  1100. Size2 Control::get_pos() const {
  1101. return data.pos_cache;
  1102. }
  1103. Size2 Control::get_size() const {
  1104. return data.size_cache;
  1105. }
  1106. Rect2 Control::get_global_rect() const {
  1107. return Rect2(get_global_pos(), get_size());
  1108. }
  1109. Rect2 Control::get_window_rect() const {
  1110. ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
  1111. Rect2 gr = get_global_rect();
  1112. gr.pos += get_viewport()->get_visible_rect().pos;
  1113. return gr;
  1114. }
  1115. Rect2 Control::get_rect() const {
  1116. return Rect2(get_pos(), get_size());
  1117. }
  1118. Rect2 Control::get_item_rect() const {
  1119. return Rect2(Point2(), get_size());
  1120. }
  1121. void Control::set_area_as_parent_rect(int p_margin) {
  1122. data.anchor[MARGIN_LEFT] = ANCHOR_BEGIN;
  1123. data.anchor[MARGIN_TOP] = ANCHOR_BEGIN;
  1124. data.anchor[MARGIN_RIGHT] = ANCHOR_END;
  1125. data.anchor[MARGIN_BOTTOM] = ANCHOR_END;
  1126. for (int i = 0; i < 4; i++)
  1127. data.margin[i] = p_margin;
  1128. _size_changed();
  1129. }
  1130. void Control::add_icon_override(const StringName &p_name, const Ref<Texture> &p_icon) {
  1131. ERR_FAIL_COND(p_icon.is_null());
  1132. data.icon_override[p_name] = p_icon;
  1133. notification(NOTIFICATION_THEME_CHANGED);
  1134. update();
  1135. }
  1136. void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) {
  1137. ERR_FAIL_COND(p_shader.is_null());
  1138. data.shader_override[p_name] = p_shader;
  1139. notification(NOTIFICATION_THEME_CHANGED);
  1140. update();
  1141. }
  1142. void Control::add_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
  1143. ERR_FAIL_COND(p_style.is_null());
  1144. data.style_override[p_name] = p_style;
  1145. notification(NOTIFICATION_THEME_CHANGED);
  1146. update();
  1147. }
  1148. void Control::add_font_override(const StringName &p_name, const Ref<Font> &p_font) {
  1149. ERR_FAIL_COND(p_font.is_null());
  1150. if (data.font_override.has(p_name)) {
  1151. _unref_font(data.font_override[p_name]);
  1152. }
  1153. data.font_override[p_name] = p_font;
  1154. if (p_font.is_valid()) {
  1155. _ref_font(p_font);
  1156. }
  1157. notification(NOTIFICATION_THEME_CHANGED);
  1158. update();
  1159. }
  1160. void Control::add_color_override(const StringName &p_name, const Color &p_color) {
  1161. data.color_override[p_name] = p_color;
  1162. notification(NOTIFICATION_THEME_CHANGED);
  1163. update();
  1164. }
  1165. void Control::add_constant_override(const StringName &p_name, int p_constant) {
  1166. data.constant_override[p_name] = p_constant;
  1167. notification(NOTIFICATION_THEME_CHANGED);
  1168. update();
  1169. }
  1170. void Control::set_focus_mode(FocusMode p_focus_mode) {
  1171. if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus())
  1172. release_focus();
  1173. data.focus_mode = p_focus_mode;
  1174. }
  1175. static Control *_next_control(Control *p_from) {
  1176. if (p_from->is_set_as_toplevel())
  1177. return NULL; // can't go above
  1178. Control *parent = p_from->get_parent() ? p_from->get_parent()->cast_to<Control>() : NULL;
  1179. if (!parent) {
  1180. return NULL;
  1181. }
  1182. int next = p_from->get_position_in_parent();
  1183. ERR_FAIL_INDEX_V(next, parent->get_child_count(), NULL);
  1184. for (int i = (next + 1); i < parent->get_child_count(); i++) {
  1185. Control *c = parent->get_child(i)->cast_to<Control>();
  1186. if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel())
  1187. continue;
  1188. return c;
  1189. }
  1190. //no next in parent, try the same in parent
  1191. return _next_control(parent);
  1192. }
  1193. Control *Control::find_next_valid_focus() const {
  1194. Control *from = const_cast<Control *>(this);
  1195. while (true) {
  1196. // find next child
  1197. Control *next_child = NULL;
  1198. for (int i = 0; i < from->get_child_count(); i++) {
  1199. Control *c = from->get_child(i)->cast_to<Control>();
  1200. if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
  1201. continue;
  1202. }
  1203. next_child = c;
  1204. break;
  1205. }
  1206. if (next_child) {
  1207. from = next_child;
  1208. } else {
  1209. next_child = _next_control(from);
  1210. if (!next_child) { //nothing else.. go up and find either window or subwindow
  1211. next_child = const_cast<Control *>(this);
  1212. while (next_child && !next_child->is_set_as_toplevel()) {
  1213. if (next_child->get_parent()) {
  1214. next_child = next_child->get_parent()->cast_to<Control>();
  1215. } else
  1216. next_child = NULL;
  1217. }
  1218. if (!next_child) {
  1219. next_child = const_cast<Control *>(this);
  1220. while (next_child) {
  1221. if (next_child->data.SI || next_child->data.RI)
  1222. break;
  1223. next_child = next_child->get_parent_control();
  1224. }
  1225. }
  1226. }
  1227. }
  1228. if (next_child == this) // no next control->
  1229. return (get_focus_mode() == FOCUS_ALL) ? next_child : NULL;
  1230. if (next_child) {
  1231. if (next_child->get_focus_mode() == FOCUS_ALL)
  1232. return next_child;
  1233. from = next_child;
  1234. } else
  1235. break;
  1236. }
  1237. return NULL;
  1238. }
  1239. static Control *_prev_control(Control *p_from) {
  1240. Control *child = NULL;
  1241. for (int i = p_from->get_child_count() - 1; i >= 0; i--) {
  1242. Control *c = p_from->get_child(i)->cast_to<Control>();
  1243. if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel())
  1244. continue;
  1245. child = c;
  1246. break;
  1247. }
  1248. if (!child)
  1249. return p_from;
  1250. //no prev in parent, try the same in parent
  1251. return _prev_control(child);
  1252. }
  1253. Control *Control::find_prev_valid_focus() const {
  1254. Control *from = const_cast<Control *>(this);
  1255. while (true) {
  1256. // find prev child
  1257. Control *prev_child = NULL;
  1258. if (from->is_set_as_toplevel() || !from->get_parent() || !from->get_parent()->cast_to<Control>()) {
  1259. //find last of the childs
  1260. prev_child = _prev_control(from);
  1261. } else {
  1262. for (int i = (from->get_position_in_parent() - 1); i >= 0; i--) {
  1263. Control *c = from->get_parent()->get_child(i)->cast_to<Control>();
  1264. if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
  1265. continue;
  1266. }
  1267. prev_child = c;
  1268. break;
  1269. }
  1270. if (!prev_child) {
  1271. prev_child = from->get_parent()->cast_to<Control>();
  1272. } else {
  1273. prev_child = _prev_control(prev_child);
  1274. }
  1275. }
  1276. if (prev_child == this) // no prev control->
  1277. return (get_focus_mode() == FOCUS_ALL) ? prev_child : NULL;
  1278. if (prev_child->get_focus_mode() == FOCUS_ALL)
  1279. return prev_child;
  1280. from = prev_child;
  1281. }
  1282. return NULL;
  1283. return NULL;
  1284. }
  1285. Control::FocusMode Control::get_focus_mode() const {
  1286. return data.focus_mode;
  1287. }
  1288. bool Control::has_focus() const {
  1289. return is_inside_tree() && get_viewport()->_gui_control_has_focus(this);
  1290. }
  1291. void Control::grab_focus() {
  1292. if (!is_inside_tree()) {
  1293. ERR_FAIL_COND(!is_inside_tree());
  1294. }
  1295. if (data.focus_mode == FOCUS_NONE)
  1296. return;
  1297. get_viewport()->_gui_control_grab_focus(this);
  1298. }
  1299. void Control::release_focus() {
  1300. ERR_FAIL_COND(!is_inside_tree());
  1301. if (!has_focus())
  1302. return;
  1303. get_viewport()->_gui_remove_focus();
  1304. update();
  1305. }
  1306. bool Control::is_toplevel_control() const {
  1307. return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_toplevel());
  1308. }
  1309. void Control::show_modal(bool p_exclusive) {
  1310. ERR_FAIL_COND(!is_inside_tree());
  1311. ERR_FAIL_COND(!data.SI);
  1312. if (is_visible_in_tree())
  1313. hide();
  1314. ERR_FAIL_COND(data.MI != NULL);
  1315. show();
  1316. raise();
  1317. data.modal_exclusive = p_exclusive;
  1318. data.MI = get_viewport()->_gui_show_modal(this);
  1319. data.modal_frame = Engine::get_singleton()->get_frames_drawn();
  1320. }
  1321. void Control::_modal_set_prev_focus_owner(ObjectID p_prev) {
  1322. data.modal_prev_focus_owner = p_prev;
  1323. }
  1324. void Control::_modal_stack_remove() {
  1325. ERR_FAIL_COND(!is_inside_tree());
  1326. if (!data.MI)
  1327. return;
  1328. get_viewport()->_gui_remove_from_modal_stack(data.MI, data.modal_prev_focus_owner);
  1329. data.MI = NULL;
  1330. data.modal_prev_focus_owner = 0;
  1331. }
  1332. void Control::_propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign) {
  1333. Control *c = p_at->cast_to<Control>();
  1334. if (c && c != p_owner && c->data.theme.is_valid()) // has a theme, this can't be propagated
  1335. return;
  1336. for (int i = 0; i < p_at->get_child_count(); i++) {
  1337. CanvasItem *child = p_at->get_child(i)->cast_to<CanvasItem>();
  1338. if (child) {
  1339. _propagate_theme_changed(child, p_owner, p_assign);
  1340. }
  1341. }
  1342. if (c) {
  1343. if (p_assign) {
  1344. c->data.theme_owner = p_owner;
  1345. }
  1346. c->notification(NOTIFICATION_THEME_CHANGED);
  1347. c->update();
  1348. }
  1349. }
  1350. void Control::_theme_changed() {
  1351. _propagate_theme_changed(this, this, false);
  1352. }
  1353. void Control::set_theme(const Ref<Theme> &p_theme) {
  1354. if (data.theme == p_theme)
  1355. return;
  1356. if (data.theme.is_valid()) {
  1357. data.theme->disconnect("changed", this, "_theme_changed");
  1358. }
  1359. data.theme = p_theme;
  1360. if (!p_theme.is_null()) {
  1361. _propagate_theme_changed(this, this);
  1362. } else {
  1363. Control *parent = get_parent() ? get_parent()->cast_to<Control>() : NULL;
  1364. if (parent && parent->data.theme_owner) {
  1365. _propagate_theme_changed(this, parent->data.theme_owner);
  1366. } else {
  1367. _propagate_theme_changed(this, NULL);
  1368. }
  1369. }
  1370. if (data.theme.is_valid()) {
  1371. data.theme->connect("changed", this, "_theme_changed");
  1372. }
  1373. }
  1374. void Control::accept_event() {
  1375. if (is_inside_tree())
  1376. get_viewport()->_gui_accept_event();
  1377. }
  1378. Ref<Theme> Control::get_theme() const {
  1379. return data.theme;
  1380. }
  1381. void Control::set_tooltip(const String &p_tooltip) {
  1382. data.tooltip = p_tooltip;
  1383. }
  1384. String Control::get_tooltip(const Point2 &p_pos) const {
  1385. return data.tooltip;
  1386. }
  1387. void Control::set_default_cursor_shape(CursorShape p_shape) {
  1388. data.default_cursor = p_shape;
  1389. }
  1390. Control::CursorShape Control::get_default_cursor_shape() const {
  1391. return data.default_cursor;
  1392. }
  1393. Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const {
  1394. return data.default_cursor;
  1395. }
  1396. Transform2D Control::get_transform() const {
  1397. Transform2D xform = Transform2D(data.rotation, get_pos());
  1398. xform.scale_basis(data.scale);
  1399. return xform;
  1400. }
  1401. String Control::_get_tooltip() const {
  1402. return data.tooltip;
  1403. }
  1404. void Control::set_focus_neighbour(Margin p_margin, const NodePath &p_neighbour) {
  1405. ERR_FAIL_INDEX(p_margin, 4);
  1406. data.focus_neighbour[p_margin] = p_neighbour;
  1407. }
  1408. NodePath Control::get_focus_neighbour(Margin p_margin) const {
  1409. ERR_FAIL_INDEX_V(p_margin, 4, NodePath());
  1410. return data.focus_neighbour[p_margin];
  1411. }
  1412. #define MAX_NEIGHBOUR_SEARCH_COUNT 512
  1413. Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
  1414. if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT)
  1415. return NULL;
  1416. if (!data.focus_neighbour[p_margin].is_empty()) {
  1417. Control *c = NULL;
  1418. Node *n = get_node(data.focus_neighbour[p_margin]);
  1419. if (n) {
  1420. c = n->cast_to<Control>();
  1421. if (!c) {
  1422. ERR_EXPLAIN("Next focus node is not a control: " + n->get_name());
  1423. ERR_FAIL_V(NULL);
  1424. }
  1425. } else {
  1426. return NULL;
  1427. }
  1428. bool valid = true;
  1429. if (!c->is_visible())
  1430. valid = false;
  1431. if (c->get_focus_mode() == FOCUS_NONE)
  1432. valid = false;
  1433. if (valid)
  1434. return c;
  1435. c = c->_get_focus_neighbour(p_margin, p_count + 1);
  1436. return c;
  1437. }
  1438. float dist = 1e7;
  1439. Control *result = NULL;
  1440. Point2 points[4];
  1441. Transform2D xform = get_global_transform();
  1442. Rect2 rect = get_item_rect();
  1443. points[0] = xform.xform(rect.pos);
  1444. points[1] = xform.xform(rect.pos + Point2(rect.size.x, 0));
  1445. points[2] = xform.xform(rect.pos + rect.size);
  1446. points[3] = xform.xform(rect.pos + Point2(0, rect.size.y));
  1447. const Vector2 dir[4] = {
  1448. Vector2(-1, 0),
  1449. Vector2(0, -1),
  1450. Vector2(1, 0),
  1451. Vector2(0, 1)
  1452. };
  1453. Vector2 vdir = dir[p_margin];
  1454. float maxd = -1e7;
  1455. for (int i = 0; i < 4; i++) {
  1456. float d = vdir.dot(points[i]);
  1457. if (d > maxd)
  1458. maxd = d;
  1459. }
  1460. Node *base = this;
  1461. while (base) {
  1462. Control *c = base->cast_to<Control>();
  1463. if (c) {
  1464. if (c->data.SI)
  1465. break;
  1466. if (c->data.RI)
  1467. break;
  1468. }
  1469. base = base->get_parent();
  1470. }
  1471. if (!base)
  1472. return NULL;
  1473. _window_find_focus_neighbour(vdir, base, points, maxd, dist, &result);
  1474. return result;
  1475. }
  1476. 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) {
  1477. if (p_at->cast_to<Viewport>())
  1478. return; //bye
  1479. Control *c = p_at->cast_to<Control>();
  1480. if (c && c != this && c->get_focus_mode() == FOCUS_ALL && c->is_visible_in_tree()) {
  1481. Point2 points[4];
  1482. Transform2D xform = c->get_global_transform();
  1483. Rect2 rect = c->get_item_rect();
  1484. points[0] = xform.xform(rect.pos);
  1485. points[1] = xform.xform(rect.pos + Point2(rect.size.x, 0));
  1486. points[2] = xform.xform(rect.pos + rect.size);
  1487. points[3] = xform.xform(rect.pos + Point2(0, rect.size.y));
  1488. float min = 1e7;
  1489. for (int i = 0; i < 4; i++) {
  1490. float d = p_dir.dot(points[i]);
  1491. if (d < min)
  1492. min = d;
  1493. }
  1494. if (min > (p_min - CMP_EPSILON)) {
  1495. for (int i = 0; i < 4; i++) {
  1496. Vector2 la = p_points[i];
  1497. Vector2 lb = p_points[(i + 1) % 4];
  1498. for (int j = 0; j < 4; j++) {
  1499. Vector2 fa = points[j];
  1500. Vector2 fb = points[(j + 1) % 4];
  1501. Vector2 pa, pb;
  1502. float d = Geometry::get_closest_points_between_segments(la, lb, fa, fb, pa, pb);
  1503. //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));
  1504. if (d < r_closest_dist) {
  1505. r_closest_dist = d;
  1506. *r_closest = c;
  1507. }
  1508. }
  1509. }
  1510. }
  1511. }
  1512. for (int i = 0; i < p_at->get_child_count(); i++) {
  1513. Node *child = p_at->get_child(i);
  1514. Control *childc = child->cast_to<Control>();
  1515. if (childc && childc->data.SI)
  1516. continue; //subwindow, ignore
  1517. _window_find_focus_neighbour(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest);
  1518. }
  1519. }
  1520. void Control::set_h_size_flags(int p_flags) {
  1521. if (data.h_size_flags == p_flags)
  1522. return;
  1523. data.h_size_flags = p_flags;
  1524. emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
  1525. }
  1526. int Control::get_h_size_flags() const {
  1527. return data.h_size_flags;
  1528. }
  1529. void Control::set_v_size_flags(int p_flags) {
  1530. if (data.v_size_flags == p_flags)
  1531. return;
  1532. data.v_size_flags = p_flags;
  1533. emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
  1534. }
  1535. void Control::set_stretch_ratio(float p_ratio) {
  1536. if (data.expand == p_ratio)
  1537. return;
  1538. data.expand = p_ratio;
  1539. emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
  1540. }
  1541. float Control::get_stretch_ratio() const {
  1542. return data.expand;
  1543. }
  1544. void Control::grab_click_focus() {
  1545. ERR_FAIL_COND(!is_inside_tree());
  1546. get_viewport()->_gui_grab_click_focus(this);
  1547. }
  1548. void Control::minimum_size_changed() {
  1549. if (!is_inside_tree() || data.block_minimum_size_adjust)
  1550. return;
  1551. if (data.pending_min_size_update)
  1552. return;
  1553. data.pending_min_size_update = true;
  1554. MessageQueue::get_singleton()->push_call(this, "_update_minimum_size");
  1555. if (!is_toplevel_control()) {
  1556. Control *pc = get_parent_control();
  1557. if (pc)
  1558. pc->minimum_size_changed();
  1559. }
  1560. }
  1561. int Control::get_v_size_flags() const {
  1562. return data.v_size_flags;
  1563. }
  1564. void Control::set_mouse_filter(MouseFilter p_filter) {
  1565. ERR_FAIL_INDEX(p_filter, 3);
  1566. data.mouse_filter = p_filter;
  1567. }
  1568. Control::MouseFilter Control::get_mouse_filter() const {
  1569. return data.mouse_filter;
  1570. }
  1571. Control *Control::get_focus_owner() const {
  1572. ERR_FAIL_COND_V(!is_inside_tree(), NULL);
  1573. return get_viewport()->_gui_get_focus_owner();
  1574. }
  1575. void Control::warp_mouse(const Point2 &p_to_pos) {
  1576. ERR_FAIL_COND(!is_inside_tree());
  1577. get_viewport()->warp_mouse(get_global_transform().xform(p_to_pos));
  1578. }
  1579. bool Control::is_text_field() const {
  1580. /*
  1581. if (get_script_instance()) {
  1582. Variant v=p_point;
  1583. const Variant *p[2]={&v,&p_data};
  1584. Variant::CallError ce;
  1585. Variant ret = get_script_instance()->call("is_text_field",p,2,ce);
  1586. if (ce.error==Variant::CallError::CALL_OK)
  1587. return ret;
  1588. }
  1589. */
  1590. return false;
  1591. }
  1592. void Control::set_rotation(float p_radians) {
  1593. data.rotation = p_radians;
  1594. update();
  1595. _notify_transform();
  1596. _change_notify("rect/rotation");
  1597. }
  1598. float Control::get_rotation() const {
  1599. return data.rotation;
  1600. }
  1601. void Control::set_rotation_deg(float p_degrees) {
  1602. set_rotation(Math::deg2rad(p_degrees));
  1603. }
  1604. float Control::get_rotation_deg() const {
  1605. return Math::rad2deg(get_rotation());
  1606. }
  1607. // Kept for compatibility after rename to {s,g}et_rotation_deg.
  1608. // Could be removed after a couple releases.
  1609. void Control::_set_rotation_deg(float p_degrees) {
  1610. WARN_PRINT("Deprecated method Control._set_rotation_deg(): This method was renamed to set_rotation_deg. Please adapt your code accordingly, as the old method will be obsoleted.");
  1611. set_rotation_deg(p_degrees);
  1612. }
  1613. float Control::_get_rotation_deg() const {
  1614. WARN_PRINT("Deprecated method Control._get_rotation_deg(): This method was renamed to get_rotation_deg. Please adapt your code accordingly, as the old method will be obsoleted.");
  1615. return get_rotation_deg();
  1616. }
  1617. //needed to update the control if the font changes..
  1618. void Control::_ref_font(Ref<Font> p_sc) {
  1619. if (!data.font_refcount.has(p_sc)) {
  1620. data.font_refcount[p_sc] = 1;
  1621. p_sc->connect("changed", this, "_font_changed");
  1622. } else {
  1623. data.font_refcount[p_sc] += 1;
  1624. }
  1625. }
  1626. void Control::_unref_font(Ref<Font> p_sc) {
  1627. ERR_FAIL_COND(!data.font_refcount.has(p_sc));
  1628. data.font_refcount[p_sc]--;
  1629. if (data.font_refcount[p_sc] == 0) {
  1630. p_sc->disconnect("changed", this, "_font_changed");
  1631. data.font_refcount.erase(p_sc);
  1632. }
  1633. }
  1634. void Control::_font_changed() {
  1635. update();
  1636. notification(NOTIFICATION_THEME_CHANGED);
  1637. minimum_size_changed(); //fonts affect minimum size pretty much almost always
  1638. }
  1639. void Control::set_scale(const Vector2 &p_scale) {
  1640. data.scale = p_scale;
  1641. update();
  1642. _notify_transform();
  1643. }
  1644. Vector2 Control::get_scale() const {
  1645. return data.scale;
  1646. }
  1647. Control *Control::get_root_parent_control() const {
  1648. const CanvasItem *ci = this;
  1649. const Control *root = this;
  1650. while (ci) {
  1651. const Control *c = ci->cast_to<Control>();
  1652. if (c) {
  1653. root = c;
  1654. if (c->data.RI || c->data.MI || c->is_toplevel_control())
  1655. break;
  1656. }
  1657. ci = ci->get_parent_item();
  1658. }
  1659. return const_cast<Control *>(root);
  1660. }
  1661. void Control::set_block_minimum_size_adjust(bool p_block) {
  1662. data.block_minimum_size_adjust = p_block;
  1663. }
  1664. bool Control::is_minimum_size_adjust_blocked() const {
  1665. return data.block_minimum_size_adjust;
  1666. }
  1667. void Control::set_disable_visibility_clip(bool p_ignore) {
  1668. data.disable_visibility_clip = p_ignore;
  1669. update();
  1670. }
  1671. bool Control::is_visibility_clip_disabled() const {
  1672. return data.disable_visibility_clip;
  1673. }
  1674. void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1675. Node::get_argument_options(p_function, p_idx, r_options);
  1676. if (p_idx == 0) {
  1677. List<StringName> sn;
  1678. String pf = p_function;
  1679. if (pf == "add_color_override" || pf == "has_color" || pf == "has_color_override" || pf == "get_color") {
  1680. Theme::get_default()->get_color_list(get_class(), &sn);
  1681. } else if (pf == "add_style_override" || pf == "has_style" || pf == "has_style_override" || pf == "get_style") {
  1682. Theme::get_default()->get_stylebox_list(get_class(), &sn);
  1683. } else if (pf == "add_font_override" || pf == "has_font" || pf == "has_font_override" || pf == "get_font") {
  1684. Theme::get_default()->get_font_list(get_class(), &sn);
  1685. } else if (pf == "add_constant_override" || pf == "has_constant" || pf == "has_constant_override" || pf == "get_constant") {
  1686. Theme::get_default()->get_constant_list(get_class(), &sn);
  1687. }
  1688. sn.sort_custom<StringName::AlphCompare>();
  1689. for (List<StringName>::Element *E = sn.front(); E; E = E->next()) {
  1690. r_options->push_back("\"" + E->get() + "\"");
  1691. }
  1692. }
  1693. }
  1694. void Control::set_clip_contents(bool p_clip) {
  1695. data.clip_contents = p_clip;
  1696. update();
  1697. }
  1698. bool Control::is_clipping_contents() {
  1699. return data.clip_contents;
  1700. }
  1701. void Control::_bind_methods() {
  1702. //ClassDB::bind_method(D_METHOD("_window_resize_event"),&Control::_window_resize_event);
  1703. ClassDB::bind_method(D_METHOD("_size_changed"), &Control::_size_changed);
  1704. ClassDB::bind_method(D_METHOD("_update_minimum_size"), &Control::_update_minimum_size);
  1705. ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event);
  1706. ClassDB::bind_method(D_METHOD("get_minimum_size"), &Control::get_minimum_size);
  1707. ClassDB::bind_method(D_METHOD("get_combined_minimum_size"), &Control::get_combined_minimum_size);
  1708. ClassDB::bind_method(D_METHOD("set_anchor", "margin", "anchor_mode", "keep_margin"), &Control::set_anchor, DEFVAL(false));
  1709. ClassDB::bind_method(D_METHOD("_set_anchor", "margin", "anchor_mode"), &Control::_set_anchor);
  1710. ClassDB::bind_method(D_METHOD("get_anchor", "margin"), &Control::get_anchor);
  1711. ClassDB::bind_method(D_METHOD("set_margin", "margin", "offset"), &Control::set_margin);
  1712. ClassDB::bind_method(D_METHOD("set_anchor_and_margin", "margin", "anchor_mode", "offset"), &Control::set_anchor_and_margin);
  1713. ClassDB::bind_method(D_METHOD("set_begin", "pos"), &Control::set_begin);
  1714. ClassDB::bind_method(D_METHOD("set_end", "pos"), &Control::set_end);
  1715. ClassDB::bind_method(D_METHOD("set_pos", "pos"), &Control::set_pos);
  1716. ClassDB::bind_method(D_METHOD("set_size", "size"), &Control::set_size);
  1717. ClassDB::bind_method(D_METHOD("set_custom_minimum_size", "size"), &Control::set_custom_minimum_size);
  1718. ClassDB::bind_method(D_METHOD("set_global_pos", "pos"), &Control::set_global_pos);
  1719. ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Control::set_rotation);
  1720. ClassDB::bind_method(D_METHOD("set_rotation_deg", "degrees"), &Control::set_rotation_deg);
  1721. // TODO: Obsolete this method (old name) properly (GH-4397)
  1722. ClassDB::bind_method(D_METHOD("_set_rotation_deg", "degrees"), &Control::_set_rotation_deg);
  1723. ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Control::set_scale);
  1724. ClassDB::bind_method(D_METHOD("get_margin", "margin"), &Control::get_margin);
  1725. ClassDB::bind_method(D_METHOD("get_begin"), &Control::get_begin);
  1726. ClassDB::bind_method(D_METHOD("get_end"), &Control::get_end);
  1727. ClassDB::bind_method(D_METHOD("get_pos"), &Control::get_pos);
  1728. ClassDB::bind_method(D_METHOD("get_size"), &Control::get_size);
  1729. ClassDB::bind_method(D_METHOD("get_rotation"), &Control::get_rotation);
  1730. ClassDB::bind_method(D_METHOD("get_rotation_deg"), &Control::get_rotation_deg);
  1731. // TODO: Obsolete this method (old name) properly (GH-4397)
  1732. ClassDB::bind_method(D_METHOD("_get_rotation_deg"), &Control::_get_rotation_deg);
  1733. ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale);
  1734. ClassDB::bind_method(D_METHOD("get_custom_minimum_size"), &Control::get_custom_minimum_size);
  1735. ClassDB::bind_method(D_METHOD("get_parent_area_size"), &Control::get_size);
  1736. ClassDB::bind_method(D_METHOD("get_global_pos"), &Control::get_global_pos);
  1737. ClassDB::bind_method(D_METHOD("get_rect"), &Control::get_rect);
  1738. ClassDB::bind_method(D_METHOD("get_global_rect"), &Control::get_global_rect);
  1739. ClassDB::bind_method(D_METHOD("set_area_as_parent_rect", "margin"), &Control::set_area_as_parent_rect, DEFVAL(0));
  1740. ClassDB::bind_method(D_METHOD("show_modal", "exclusive"), &Control::show_modal, DEFVAL(false));
  1741. ClassDB::bind_method(D_METHOD("set_focus_mode", "mode"), &Control::set_focus_mode);
  1742. ClassDB::bind_method(D_METHOD("get_focus_mode"), &Control::get_focus_mode);
  1743. ClassDB::bind_method(D_METHOD("has_focus"), &Control::has_focus);
  1744. ClassDB::bind_method(D_METHOD("grab_focus"), &Control::grab_focus);
  1745. ClassDB::bind_method(D_METHOD("release_focus"), &Control::release_focus);
  1746. ClassDB::bind_method(D_METHOD("get_focus_owner:Control"), &Control::get_focus_owner);
  1747. ClassDB::bind_method(D_METHOD("set_h_size_flags", "flags"), &Control::set_h_size_flags);
  1748. ClassDB::bind_method(D_METHOD("get_h_size_flags"), &Control::get_h_size_flags);
  1749. ClassDB::bind_method(D_METHOD("set_stretch_ratio", "ratio"), &Control::set_stretch_ratio);
  1750. ClassDB::bind_method(D_METHOD("get_stretch_ratio"), &Control::get_stretch_ratio);
  1751. ClassDB::bind_method(D_METHOD("set_v_size_flags", "flags"), &Control::set_v_size_flags);
  1752. ClassDB::bind_method(D_METHOD("get_v_size_flags"), &Control::get_v_size_flags);
  1753. ClassDB::bind_method(D_METHOD("set_theme", "theme:Theme"), &Control::set_theme);
  1754. ClassDB::bind_method(D_METHOD("get_theme:Theme"), &Control::get_theme);
  1755. ClassDB::bind_method(D_METHOD("add_icon_override", "name", "texture:Texture"), &Control::add_icon_override);
  1756. ClassDB::bind_method(D_METHOD("add_shader_override", "name", "shader:Shader"), &Control::add_shader_override);
  1757. ClassDB::bind_method(D_METHOD("add_style_override", "name", "stylebox:StyleBox"), &Control::add_style_override);
  1758. ClassDB::bind_method(D_METHOD("add_font_override", "name", "font:Font"), &Control::add_font_override);
  1759. ClassDB::bind_method(D_METHOD("add_color_override", "name", "color"), &Control::add_color_override);
  1760. ClassDB::bind_method(D_METHOD("add_constant_override", "name", "constant"), &Control::add_constant_override);
  1761. ClassDB::bind_method(D_METHOD("get_icon:Texture", "name", "type"), &Control::get_icon, DEFVAL(""));
  1762. ClassDB::bind_method(D_METHOD("get_stylebox:StyleBox", "name", "type"), &Control::get_stylebox, DEFVAL(""));
  1763. ClassDB::bind_method(D_METHOD("get_font:Font", "name", "type"), &Control::get_font, DEFVAL(""));
  1764. ClassDB::bind_method(D_METHOD("get_color", "name", "type"), &Control::get_color, DEFVAL(""));
  1765. ClassDB::bind_method(D_METHOD("get_constant", "name", "type"), &Control::get_constant, DEFVAL(""));
  1766. ClassDB::bind_method(D_METHOD("has_icon_override", "name"), &Control::has_icon_override);
  1767. ClassDB::bind_method(D_METHOD("has_stylebox_override", "name"), &Control::has_stylebox_override);
  1768. ClassDB::bind_method(D_METHOD("has_font_override", "name"), &Control::has_font_override);
  1769. ClassDB::bind_method(D_METHOD("has_color_override", "name"), &Control::has_color_override);
  1770. ClassDB::bind_method(D_METHOD("has_constant_override", "name"), &Control::has_constant_override);
  1771. ClassDB::bind_method(D_METHOD("has_icon", "name", "type"), &Control::has_icon, DEFVAL(""));
  1772. ClassDB::bind_method(D_METHOD("has_stylebox", "name", "type"), &Control::has_stylebox, DEFVAL(""));
  1773. ClassDB::bind_method(D_METHOD("has_font", "name", "type"), &Control::has_font, DEFVAL(""));
  1774. ClassDB::bind_method(D_METHOD("has_color", "name", "type"), &Control::has_color, DEFVAL(""));
  1775. ClassDB::bind_method(D_METHOD("has_constant", "name", "type"), &Control::has_constant, DEFVAL(""));
  1776. ClassDB::bind_method(D_METHOD("get_parent_control:Control"), &Control::get_parent_control);
  1777. ClassDB::bind_method(D_METHOD("set_tooltip", "tooltip"), &Control::set_tooltip);
  1778. ClassDB::bind_method(D_METHOD("get_tooltip", "atpos"), &Control::get_tooltip, DEFVAL(Point2()));
  1779. ClassDB::bind_method(D_METHOD("_get_tooltip"), &Control::_get_tooltip);
  1780. ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Control::set_default_cursor_shape);
  1781. ClassDB::bind_method(D_METHOD("get_default_cursor_shape"), &Control::get_default_cursor_shape);
  1782. ClassDB::bind_method(D_METHOD("get_cursor_shape", "pos"), &Control::get_cursor_shape, DEFVAL(Point2()));
  1783. ClassDB::bind_method(D_METHOD("set_focus_neighbour", "margin", "neighbour"), &Control::set_focus_neighbour);
  1784. ClassDB::bind_method(D_METHOD("get_focus_neighbour", "margin"), &Control::get_focus_neighbour);
  1785. ClassDB::bind_method(D_METHOD("force_drag", "data", "preview"), &Control::force_drag);
  1786. ClassDB::bind_method(D_METHOD("set_mouse_filter", "filter"), &Control::set_mouse_filter);
  1787. ClassDB::bind_method(D_METHOD("get_mouse_filter"), &Control::get_mouse_filter);
  1788. ClassDB::bind_method(D_METHOD("set_clip_contents", "enable"), &Control::set_clip_contents);
  1789. ClassDB::bind_method(D_METHOD("is_clipping_contents"), &Control::is_clipping_contents);
  1790. ClassDB::bind_method(D_METHOD("grab_click_focus"), &Control::grab_click_focus);
  1791. ClassDB::bind_method(D_METHOD("set_drag_forwarding", "target:Control"), &Control::set_drag_forwarding);
  1792. ClassDB::bind_method(D_METHOD("set_drag_preview", "control:Control"), &Control::set_drag_preview);
  1793. ClassDB::bind_method(D_METHOD("warp_mouse", "to_pos"), &Control::warp_mouse);
  1794. ClassDB::bind_method(D_METHOD("minimum_size_changed"), &Control::minimum_size_changed);
  1795. ClassDB::bind_method(D_METHOD("_theme_changed"), &Control::_theme_changed);
  1796. ClassDB::bind_method(D_METHOD("_font_changed"), &Control::_font_changed);
  1797. BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::INPUT_EVENT, "event")));
  1798. BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_get_minimum_size"));
  1799. BIND_VMETHOD(MethodInfo(Variant::OBJECT, "get_drag_data", PropertyInfo(Variant::VECTOR2, "pos")));
  1800. BIND_VMETHOD(MethodInfo(Variant::BOOL, "can_drop_data", PropertyInfo(Variant::VECTOR2, "pos"), PropertyInfo(Variant::NIL, "data")));
  1801. BIND_VMETHOD(MethodInfo("drop_data", PropertyInfo(Variant::VECTOR2, "pos"), PropertyInfo(Variant::NIL, "data")));
  1802. ADD_GROUP("Anchor", "anchor_");
  1803. ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "anchor_left", PROPERTY_HINT_ENUM, "Begin,End,Center"), "_set_anchor", "get_anchor", MARGIN_LEFT);
  1804. ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "anchor_top", PROPERTY_HINT_ENUM, "Begin,End,Center"), "_set_anchor", "get_anchor", MARGIN_TOP);
  1805. ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "anchor_right", PROPERTY_HINT_ENUM, "Begin,End,Center"), "_set_anchor", "get_anchor", MARGIN_RIGHT);
  1806. ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "anchor_bottom", PROPERTY_HINT_ENUM, "Begin,End,Center"), "_set_anchor", "get_anchor", MARGIN_BOTTOM);
  1807. ADD_GROUP("Margin", "margin_");
  1808. ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_left", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_LEFT);
  1809. ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_top", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_TOP);
  1810. ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_right", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_RIGHT);
  1811. ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_bottom", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_BOTTOM);
  1812. ADD_GROUP("Rect", "rect_");
  1813. ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_pos", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_pos", "get_pos");
  1814. ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_size", "get_size");
  1815. ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size");
  1816. ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rect_rotation", PROPERTY_HINT_RANGE, "-1080,1080,0.01"), "set_rotation_deg", "get_rotation_deg");
  1817. ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "rect_scale"), "set_scale", "get_scale");
  1818. ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents");
  1819. ADD_GROUP("Hint", "hint_");
  1820. ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "hint_tooltip", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip", "_get_tooltip");
  1821. ADD_GROUP("Focus", "focus_");
  1822. ADD_PROPERTYINZ(PropertyInfo(Variant::NODE_PATH, "focus_neighbour_left"), "set_focus_neighbour", "get_focus_neighbour", MARGIN_LEFT);
  1823. ADD_PROPERTYINZ(PropertyInfo(Variant::NODE_PATH, "focus_neighbour_top"), "set_focus_neighbour", "get_focus_neighbour", MARGIN_TOP);
  1824. ADD_PROPERTYINZ(PropertyInfo(Variant::NODE_PATH, "focus_neighbour_right"), "set_focus_neighbour", "get_focus_neighbour", MARGIN_RIGHT);
  1825. ADD_PROPERTYINZ(PropertyInfo(Variant::NODE_PATH, "focus_neighbour_bottom"), "set_focus_neighbour", "get_focus_neighbour", MARGIN_BOTTOM);
  1826. ADD_GROUP("Mouse", "mouse_");
  1827. ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_filter", PROPERTY_HINT_ENUM, "Stop,Pass,Ignore"), "set_mouse_filter", "get_mouse_filter");
  1828. ADD_GROUP("Size Flags", "size_flags_");
  1829. ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand"), "set_h_size_flags", "get_h_size_flags");
  1830. ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand"), "set_v_size_flags", "get_v_size_flags");
  1831. ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "1,128,0.01"), "set_stretch_ratio", "get_stretch_ratio");
  1832. ADD_GROUP("Theme", "");
  1833. ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
  1834. ADD_GROUP("", "");
  1835. BIND_CONSTANT(ANCHOR_BEGIN);
  1836. BIND_CONSTANT(ANCHOR_END);
  1837. BIND_CONSTANT(ANCHOR_CENTER);
  1838. BIND_CONSTANT(FOCUS_NONE);
  1839. BIND_CONSTANT(FOCUS_CLICK);
  1840. BIND_CONSTANT(FOCUS_ALL);
  1841. BIND_CONSTANT(NOTIFICATION_RESIZED);
  1842. BIND_CONSTANT(NOTIFICATION_MOUSE_ENTER);
  1843. BIND_CONSTANT(NOTIFICATION_MOUSE_EXIT);
  1844. BIND_CONSTANT(NOTIFICATION_FOCUS_ENTER);
  1845. BIND_CONSTANT(NOTIFICATION_FOCUS_EXIT);
  1846. BIND_CONSTANT(NOTIFICATION_THEME_CHANGED);
  1847. BIND_CONSTANT(NOTIFICATION_MODAL_CLOSE);
  1848. BIND_CONSTANT(CURSOR_ARROW);
  1849. BIND_CONSTANT(CURSOR_IBEAM);
  1850. BIND_CONSTANT(CURSOR_POINTING_HAND);
  1851. BIND_CONSTANT(CURSOR_CROSS);
  1852. BIND_CONSTANT(CURSOR_WAIT);
  1853. BIND_CONSTANT(CURSOR_BUSY);
  1854. BIND_CONSTANT(CURSOR_DRAG);
  1855. BIND_CONSTANT(CURSOR_CAN_DROP);
  1856. BIND_CONSTANT(CURSOR_FORBIDDEN);
  1857. BIND_CONSTANT(CURSOR_VSIZE);
  1858. BIND_CONSTANT(CURSOR_HSIZE);
  1859. BIND_CONSTANT(CURSOR_BDIAGSIZE);
  1860. BIND_CONSTANT(CURSOR_FDIAGSIZE);
  1861. BIND_CONSTANT(CURSOR_MOVE);
  1862. BIND_CONSTANT(CURSOR_VSPLIT);
  1863. BIND_CONSTANT(CURSOR_HSPLIT);
  1864. BIND_CONSTANT(CURSOR_HELP);
  1865. BIND_CONSTANT(SIZE_EXPAND);
  1866. BIND_CONSTANT(SIZE_FILL);
  1867. BIND_CONSTANT(SIZE_EXPAND_FILL);
  1868. BIND_CONSTANT(MOUSE_FILTER_STOP);
  1869. BIND_CONSTANT(MOUSE_FILTER_PASS);
  1870. BIND_CONSTANT(MOUSE_FILTER_IGNORE);
  1871. ADD_SIGNAL(MethodInfo("resized"));
  1872. ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::INPUT_EVENT, "ev")));
  1873. ADD_SIGNAL(MethodInfo("mouse_entered"));
  1874. ADD_SIGNAL(MethodInfo("mouse_exited"));
  1875. ADD_SIGNAL(MethodInfo("focus_entered"));
  1876. ADD_SIGNAL(MethodInfo("focus_exited"));
  1877. ADD_SIGNAL(MethodInfo("size_flags_changed"));
  1878. ADD_SIGNAL(MethodInfo("minimum_size_changed"));
  1879. ADD_SIGNAL(MethodInfo("modal_closed"));
  1880. BIND_VMETHOD(MethodInfo("has_point", PropertyInfo(Variant::VECTOR2, "point")));
  1881. }
  1882. Control::Control() {
  1883. data.parent = NULL;
  1884. data.mouse_filter = MOUSE_FILTER_STOP;
  1885. data.SI = NULL;
  1886. data.MI = NULL;
  1887. data.RI = NULL;
  1888. data.modal = false;
  1889. data.theme_owner = NULL;
  1890. data.modal_exclusive = false;
  1891. data.default_cursor = CURSOR_ARROW;
  1892. data.h_size_flags = SIZE_FILL;
  1893. data.v_size_flags = SIZE_FILL;
  1894. data.expand = 1;
  1895. data.pending_min_size_update = false;
  1896. data.rotation = 0;
  1897. data.parent_canvas_item = NULL;
  1898. data.scale = Vector2(1, 1);
  1899. data.drag_owner = 0;
  1900. data.modal_frame = 0;
  1901. data.block_minimum_size_adjust = false;
  1902. data.disable_visibility_clip = false;
  1903. data.clip_contents = false;
  1904. for (int i = 0; i < 4; i++) {
  1905. data.anchor[i] = ANCHOR_BEGIN;
  1906. data.margin[i] = 0;
  1907. }
  1908. data.focus_mode = FOCUS_NONE;
  1909. data.modal_prev_focus_owner = 0;
  1910. }
  1911. Control::~Control() {
  1912. }