window.cpp 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462
  1. /**************************************************************************/
  2. /* window.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "window.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/debugger/engine_debugger.h"
  33. #include "core/string/translation_server.h"
  34. #include "scene/gui/control.h"
  35. #include "scene/theme/theme_db.h"
  36. #include "scene/theme/theme_owner.h"
  37. // Editor integration.
  38. int Window::root_layout_direction = 0;
  39. void Window::set_root_layout_direction(int p_root_dir) {
  40. root_layout_direction = p_root_dir;
  41. }
  42. // Dynamic properties.
  43. Window *Window::focused_window = nullptr;
  44. bool Window::_set(const StringName &p_name, const Variant &p_value) {
  45. ERR_MAIN_THREAD_GUARD_V(false);
  46. String name = p_name;
  47. if (!name.begins_with("theme_override")) {
  48. return false;
  49. }
  50. if (p_value.get_type() == Variant::NIL || (p_value.get_type() == Variant::OBJECT && (Object *)p_value == nullptr)) {
  51. if (name.begins_with("theme_override_icons/")) {
  52. String dname = name.get_slicec('/', 1);
  53. if (theme_icon_override.has(dname)) {
  54. theme_icon_override[dname]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  55. }
  56. theme_icon_override.erase(dname);
  57. _notify_theme_override_changed();
  58. } else if (name.begins_with("theme_override_styles/")) {
  59. String dname = name.get_slicec('/', 1);
  60. if (theme_style_override.has(dname)) {
  61. theme_style_override[dname]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  62. }
  63. theme_style_override.erase(dname);
  64. _notify_theme_override_changed();
  65. } else if (name.begins_with("theme_override_fonts/")) {
  66. String dname = name.get_slicec('/', 1);
  67. if (theme_font_override.has(dname)) {
  68. theme_font_override[dname]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  69. }
  70. theme_font_override.erase(dname);
  71. _notify_theme_override_changed();
  72. } else if (name.begins_with("theme_override_font_sizes/")) {
  73. String dname = name.get_slicec('/', 1);
  74. theme_font_size_override.erase(dname);
  75. _notify_theme_override_changed();
  76. } else if (name.begins_with("theme_override_colors/")) {
  77. String dname = name.get_slicec('/', 1);
  78. theme_color_override.erase(dname);
  79. _notify_theme_override_changed();
  80. } else if (name.begins_with("theme_override_constants/")) {
  81. String dname = name.get_slicec('/', 1);
  82. theme_constant_override.erase(dname);
  83. _notify_theme_override_changed();
  84. } else {
  85. return false;
  86. }
  87. } else {
  88. if (name.begins_with("theme_override_icons/")) {
  89. String dname = name.get_slicec('/', 1);
  90. add_theme_icon_override(dname, p_value);
  91. } else if (name.begins_with("theme_override_styles/")) {
  92. String dname = name.get_slicec('/', 1);
  93. add_theme_style_override(dname, p_value);
  94. } else if (name.begins_with("theme_override_fonts/")) {
  95. String dname = name.get_slicec('/', 1);
  96. add_theme_font_override(dname, p_value);
  97. } else if (name.begins_with("theme_override_font_sizes/")) {
  98. String dname = name.get_slicec('/', 1);
  99. add_theme_font_size_override(dname, p_value);
  100. } else if (name.begins_with("theme_override_colors/")) {
  101. String dname = name.get_slicec('/', 1);
  102. add_theme_color_override(dname, p_value);
  103. } else if (name.begins_with("theme_override_constants/")) {
  104. String dname = name.get_slicec('/', 1);
  105. add_theme_constant_override(dname, p_value);
  106. } else {
  107. return false;
  108. }
  109. }
  110. return true;
  111. }
  112. bool Window::_get(const StringName &p_name, Variant &r_ret) const {
  113. ERR_READ_THREAD_GUARD_V(false);
  114. String sname = p_name;
  115. if (!sname.begins_with("theme_override")) {
  116. return false;
  117. }
  118. if (sname.begins_with("theme_override_icons/")) {
  119. String name = sname.get_slicec('/', 1);
  120. r_ret = theme_icon_override.has(name) ? Variant(theme_icon_override[name]) : Variant();
  121. } else if (sname.begins_with("theme_override_styles/")) {
  122. String name = sname.get_slicec('/', 1);
  123. r_ret = theme_style_override.has(name) ? Variant(theme_style_override[name]) : Variant();
  124. } else if (sname.begins_with("theme_override_fonts/")) {
  125. String name = sname.get_slicec('/', 1);
  126. r_ret = theme_font_override.has(name) ? Variant(theme_font_override[name]) : Variant();
  127. } else if (sname.begins_with("theme_override_font_sizes/")) {
  128. String name = sname.get_slicec('/', 1);
  129. r_ret = theme_font_size_override.has(name) ? Variant(theme_font_size_override[name]) : Variant();
  130. } else if (sname.begins_with("theme_override_colors/")) {
  131. String name = sname.get_slicec('/', 1);
  132. r_ret = theme_color_override.has(name) ? Variant(theme_color_override[name]) : Variant();
  133. } else if (sname.begins_with("theme_override_constants/")) {
  134. String name = sname.get_slicec('/', 1);
  135. r_ret = theme_constant_override.has(name) ? Variant(theme_constant_override[name]) : Variant();
  136. } else {
  137. return false;
  138. }
  139. return true;
  140. }
  141. void Window::_get_property_list(List<PropertyInfo> *p_list) const {
  142. ERR_READ_THREAD_GUARD;
  143. Ref<Theme> default_theme = ThemeDB::get_singleton()->get_default_theme();
  144. p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Theme Overrides", "theme_override_"), PROPERTY_HINT_NONE, "theme_override_", PROPERTY_USAGE_GROUP));
  145. {
  146. List<StringName> names;
  147. default_theme->get_color_list(get_class_name(), &names);
  148. for (const StringName &E : names) {
  149. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  150. if (theme_color_override.has(E)) {
  151. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  152. }
  153. p_list->push_back(PropertyInfo(Variant::COLOR, PNAME("theme_override_colors") + String("/") + E, PROPERTY_HINT_NONE, "", usage));
  154. }
  155. }
  156. {
  157. List<StringName> names;
  158. default_theme->get_constant_list(get_class_name(), &names);
  159. for (const StringName &E : names) {
  160. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  161. if (theme_constant_override.has(E)) {
  162. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  163. }
  164. p_list->push_back(PropertyInfo(Variant::INT, PNAME("theme_override_constants") + String("/") + E, PROPERTY_HINT_RANGE, "-16384,16384", usage));
  165. }
  166. }
  167. {
  168. List<StringName> names;
  169. default_theme->get_font_list(get_class_name(), &names);
  170. for (const StringName &E : names) {
  171. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  172. if (theme_font_override.has(E)) {
  173. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  174. }
  175. p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_fonts") + String("/") + E, PROPERTY_HINT_RESOURCE_TYPE, "Font", usage));
  176. }
  177. }
  178. {
  179. List<StringName> names;
  180. default_theme->get_font_size_list(get_class_name(), &names);
  181. for (const StringName &E : names) {
  182. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  183. if (theme_font_size_override.has(E)) {
  184. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  185. }
  186. p_list->push_back(PropertyInfo(Variant::INT, PNAME("theme_override_font_sizes") + String("/") + E, PROPERTY_HINT_RANGE, "1,256,1,or_greater,suffix:px", usage));
  187. }
  188. }
  189. {
  190. List<StringName> names;
  191. default_theme->get_icon_list(get_class_name(), &names);
  192. for (const StringName &E : names) {
  193. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  194. if (theme_icon_override.has(E)) {
  195. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  196. }
  197. p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_icons") + String("/") + E, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage));
  198. }
  199. }
  200. {
  201. List<StringName> names;
  202. default_theme->get_stylebox_list(get_class_name(), &names);
  203. for (const StringName &E : names) {
  204. uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
  205. if (theme_style_override.has(E)) {
  206. usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
  207. }
  208. p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_styles") + String("/") + E, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage));
  209. }
  210. }
  211. }
  212. void Window::_validate_property(PropertyInfo &p_property) const {
  213. if (p_property.name == "position") {
  214. if (initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
  215. p_property.usage = PROPERTY_USAGE_NONE;
  216. }
  217. } else if (p_property.name == "current_screen") {
  218. if (initial_position != WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN) {
  219. p_property.usage = PROPERTY_USAGE_NONE;
  220. }
  221. } else if (Engine::get_singleton()->is_editor_hint() && p_property.name == "theme_type_variation") {
  222. List<StringName> names;
  223. ThemeDB::get_singleton()->get_default_theme()->get_type_variation_list(get_class_name(), &names);
  224. // Iterate to find all themes.
  225. Control *tmp_control = Object::cast_to<Control>(get_parent());
  226. Window *tmp_window = Object::cast_to<Window>(get_parent());
  227. while (tmp_control || tmp_window) {
  228. // We go up and any non Control/Window will break the chain.
  229. if (tmp_control) {
  230. if (tmp_control->get_theme().is_valid()) {
  231. tmp_control->get_theme()->get_type_variation_list(get_class_name(), &names);
  232. }
  233. tmp_window = Object::cast_to<Window>(tmp_control->get_parent());
  234. tmp_control = Object::cast_to<Control>(tmp_control->get_parent());
  235. } else { // Window.
  236. if (tmp_window->get_theme().is_valid()) {
  237. tmp_window->get_theme()->get_type_variation_list(get_class_name(), &names);
  238. }
  239. tmp_control = Object::cast_to<Control>(tmp_window->get_parent());
  240. tmp_window = Object::cast_to<Window>(tmp_window->get_parent());
  241. }
  242. }
  243. if (get_theme().is_valid()) {
  244. get_theme()->get_type_variation_list(get_class_name(), &names);
  245. }
  246. if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
  247. ThemeDB::get_singleton()->get_project_theme()->get_type_variation_list(get_class_name(), &names);
  248. }
  249. names.sort_custom<StringName::AlphCompare>();
  250. Vector<StringName> unique_names;
  251. String hint_string;
  252. for (const StringName &E : names) {
  253. // Skip duplicate values.
  254. if (unique_names.has(E)) {
  255. continue;
  256. }
  257. hint_string += String(E) + ",";
  258. unique_names.append(E);
  259. }
  260. p_property.hint_string = hint_string;
  261. }
  262. }
  263. //
  264. Window *Window::get_from_id(DisplayServer::WindowID p_window_id) {
  265. if (p_window_id == DisplayServer::INVALID_WINDOW_ID) {
  266. return nullptr;
  267. }
  268. return ObjectDB::get_instance<Window>(DisplayServer::get_singleton()->window_get_attached_instance_id(p_window_id));
  269. }
  270. void Window::set_title(const String &p_title) {
  271. ERR_MAIN_THREAD_GUARD;
  272. title = p_title;
  273. _update_displayed_title();
  274. emit_signal("title_changed");
  275. }
  276. String Window::get_title() const {
  277. ERR_READ_THREAD_GUARD_V(String());
  278. return title;
  279. }
  280. String Window::get_displayed_title() const {
  281. ERR_READ_THREAD_GUARD_V(String());
  282. return displayed_title;
  283. }
  284. void Window::_settings_changed() {
  285. if (visible && initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE && is_in_edited_scene_root()) {
  286. Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
  287. position = (screen_size - size) / 2;
  288. if (embedder) {
  289. embedder->_sub_window_update(this);
  290. }
  291. }
  292. }
  293. void Window::set_initial_position(Window::WindowInitialPosition p_initial_position) {
  294. ERR_MAIN_THREAD_GUARD;
  295. initial_position = p_initial_position;
  296. _settings_changed();
  297. notify_property_list_changed();
  298. }
  299. Window::WindowInitialPosition Window::get_initial_position() const {
  300. ERR_READ_THREAD_GUARD_V(WINDOW_INITIAL_POSITION_ABSOLUTE);
  301. return initial_position;
  302. }
  303. void Window::set_current_screen(int p_screen) {
  304. ERR_MAIN_THREAD_GUARD;
  305. current_screen = p_screen;
  306. if (window_id == DisplayServer::INVALID_WINDOW_ID) {
  307. return;
  308. }
  309. DisplayServer::get_singleton()->window_set_current_screen(p_screen, window_id);
  310. }
  311. int Window::get_current_screen() const {
  312. ERR_READ_THREAD_GUARD_V(0);
  313. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  314. current_screen = DisplayServer::get_singleton()->window_get_current_screen(window_id);
  315. }
  316. return current_screen;
  317. }
  318. void Window::set_position(const Point2i &p_position) {
  319. ERR_MAIN_THREAD_GUARD;
  320. position = p_position;
  321. if (embedder) {
  322. embedder->_sub_window_update(this);
  323. } else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  324. DisplayServer::get_singleton()->window_set_position(p_position, window_id);
  325. }
  326. }
  327. Point2i Window::get_position() const {
  328. ERR_READ_THREAD_GUARD_V(Point2i());
  329. return position;
  330. }
  331. void Window::move_to_center() {
  332. ERR_MAIN_THREAD_GUARD;
  333. ERR_FAIL_COND(!is_inside_tree());
  334. Rect2 parent_rect;
  335. if (is_embedded()) {
  336. parent_rect = get_embedder()->get_visible_rect();
  337. } else {
  338. int parent_screen = DisplayServer::get_singleton()->window_get_current_screen(get_window_id());
  339. parent_rect.position = DisplayServer::get_singleton()->screen_get_position(parent_screen);
  340. parent_rect.size = DisplayServer::get_singleton()->screen_get_size(parent_screen);
  341. }
  342. if (parent_rect != Rect2()) {
  343. set_position(parent_rect.position + (parent_rect.size - get_size()) / 2);
  344. }
  345. }
  346. void Window::set_size(const Size2i &p_size) {
  347. ERR_MAIN_THREAD_GUARD;
  348. #if defined(ANDROID_ENABLED)
  349. if (!get_parent() && is_inside_tree()) {
  350. // Can't set root window size on Android.
  351. return;
  352. }
  353. #endif
  354. size = p_size;
  355. _update_window_size();
  356. _settings_changed();
  357. }
  358. Size2i Window::get_size() const {
  359. ERR_READ_THREAD_GUARD_V(Size2i());
  360. return size;
  361. }
  362. void Window::reset_size() {
  363. ERR_MAIN_THREAD_GUARD;
  364. set_size(Size2i());
  365. }
  366. Point2i Window::get_position_with_decorations() const {
  367. ERR_READ_THREAD_GUARD_V(Point2i());
  368. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  369. return DisplayServer::get_singleton()->window_get_position_with_decorations(window_id);
  370. }
  371. if (visible && is_embedded() && !get_flag(Window::FLAG_BORDERLESS)) {
  372. Size2 border_offset;
  373. if (theme_cache.embedded_border.is_valid()) {
  374. border_offset = theme_cache.embedded_border->get_offset();
  375. }
  376. if (theme_cache.embedded_unfocused_border.is_valid()) {
  377. border_offset = border_offset.max(theme_cache.embedded_unfocused_border->get_offset());
  378. }
  379. return position - border_offset;
  380. }
  381. return position;
  382. }
  383. Size2i Window::get_size_with_decorations() const {
  384. ERR_READ_THREAD_GUARD_V(Size2i());
  385. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  386. return DisplayServer::get_singleton()->window_get_size_with_decorations(window_id);
  387. }
  388. if (visible && is_embedded() && !get_flag(Window::FLAG_BORDERLESS)) {
  389. Size2 border_size;
  390. if (theme_cache.embedded_border.is_valid()) {
  391. border_size = theme_cache.embedded_border->get_minimum_size();
  392. }
  393. if (theme_cache.embedded_unfocused_border.is_valid()) {
  394. border_size = border_size.max(theme_cache.embedded_unfocused_border->get_minimum_size());
  395. }
  396. return size + border_size;
  397. }
  398. return size;
  399. }
  400. Size2i Window::_clamp_limit_size(const Size2i &p_limit_size) {
  401. // Force window limits to respect size limitations of rendering server.
  402. Size2i max_window_size = RS::get_singleton()->get_maximum_viewport_size();
  403. if (max_window_size != Size2i()) {
  404. return p_limit_size.clamp(Vector2i(), max_window_size);
  405. } else {
  406. return p_limit_size.maxi(0);
  407. }
  408. }
  409. void Window::_validate_limit_size() {
  410. // When max_size is invalid, max_size_used falls back to respect size limitations of rendering server.
  411. bool max_size_valid = (max_size.x > 0 || max_size.y > 0) && max_size.x >= min_size.x && max_size.y >= min_size.y;
  412. max_size_used = max_size_valid ? max_size : RS::get_singleton()->get_maximum_viewport_size();
  413. }
  414. void Window::set_max_size(const Size2i &p_max_size) {
  415. ERR_MAIN_THREAD_GUARD;
  416. #if defined(ANDROID_ENABLED)
  417. if (!get_parent() && is_inside_tree()) {
  418. // Can't set root window size on Android.
  419. return;
  420. }
  421. #endif
  422. Size2i max_size_clamped = _clamp_limit_size(p_max_size);
  423. if (max_size == max_size_clamped) {
  424. return;
  425. }
  426. max_size = max_size_clamped;
  427. _validate_limit_size();
  428. _update_window_size();
  429. }
  430. Size2i Window::get_max_size() const {
  431. ERR_READ_THREAD_GUARD_V(Size2i());
  432. return max_size;
  433. }
  434. void Window::set_min_size(const Size2i &p_min_size) {
  435. ERR_MAIN_THREAD_GUARD;
  436. #if defined(ANDROID_ENABLED)
  437. if (!get_parent() && is_inside_tree()) {
  438. // Can't set root window size on Android.
  439. return;
  440. }
  441. #endif
  442. Size2i min_size_clamped = _clamp_limit_size(p_min_size);
  443. if (min_size == min_size_clamped) {
  444. return;
  445. }
  446. min_size = min_size_clamped;
  447. _validate_limit_size();
  448. _update_window_size();
  449. }
  450. Size2i Window::get_min_size() const {
  451. ERR_READ_THREAD_GUARD_V(Size2i());
  452. return min_size;
  453. }
  454. void Window::set_mode(Mode p_mode) {
  455. ERR_MAIN_THREAD_GUARD;
  456. mode = p_mode;
  457. if (embedder) {
  458. embedder->_sub_window_update(this);
  459. } else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  460. DisplayServer::get_singleton()->window_set_mode(DisplayServer::WindowMode(p_mode), window_id);
  461. }
  462. }
  463. Window::Mode Window::get_mode() const {
  464. ERR_READ_THREAD_GUARD_V(MODE_WINDOWED);
  465. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  466. mode = (Mode)DisplayServer::get_singleton()->window_get_mode(window_id);
  467. }
  468. return mode;
  469. }
  470. void Window::set_flag(Flags p_flag, bool p_enabled) {
  471. ERR_MAIN_THREAD_GUARD;
  472. ERR_FAIL_INDEX(p_flag, FLAG_MAX);
  473. flags[p_flag] = p_enabled;
  474. if (p_flag == FLAG_TRANSPARENT) {
  475. set_transparent_background(p_enabled);
  476. }
  477. if (embedder) {
  478. embedder->_sub_window_update(this);
  479. } else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  480. if (!is_in_edited_scene_root()) {
  481. DisplayServer::get_singleton()->window_set_flag(DisplayServer::WindowFlags(p_flag), p_enabled, window_id);
  482. }
  483. }
  484. }
  485. bool Window::get_flag(Flags p_flag) const {
  486. ERR_READ_THREAD_GUARD_V(false);
  487. ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
  488. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  489. if (!is_in_edited_scene_root()) {
  490. flags[p_flag] = DisplayServer::get_singleton()->window_get_flag(DisplayServer::WindowFlags(p_flag), window_id);
  491. }
  492. }
  493. return flags[p_flag];
  494. }
  495. bool Window::is_maximize_allowed() const {
  496. ERR_READ_THREAD_GUARD_V(false);
  497. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  498. return DisplayServer::get_singleton()->window_is_maximize_allowed(window_id);
  499. }
  500. return true;
  501. }
  502. void Window::request_attention() {
  503. ERR_MAIN_THREAD_GUARD;
  504. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  505. DisplayServer::get_singleton()->window_request_attention(window_id);
  506. }
  507. }
  508. #ifndef DISABLE_DEPRECATED
  509. void Window::move_to_foreground() {
  510. WARN_DEPRECATED_MSG(R"*(The "move_to_foreground()" method is deprecated, use "grab_focus()" instead.)*");
  511. grab_focus();
  512. }
  513. #endif // DISABLE_DEPRECATED
  514. bool Window::can_draw() const {
  515. ERR_READ_THREAD_GUARD_V(false);
  516. if (!is_inside_tree()) {
  517. return false;
  518. }
  519. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  520. return DisplayServer::get_singleton()->window_can_draw(window_id);
  521. }
  522. return visible;
  523. }
  524. void Window::set_ime_active(bool p_active) {
  525. ERR_MAIN_THREAD_GUARD;
  526. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  527. DisplayServer::get_singleton()->window_set_ime_active(p_active, window_id);
  528. }
  529. }
  530. void Window::set_ime_position(const Point2i &p_pos) {
  531. ERR_MAIN_THREAD_GUARD;
  532. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  533. DisplayServer::get_singleton()->window_set_ime_position(p_pos, window_id);
  534. }
  535. }
  536. bool Window::is_embedded() const {
  537. ERR_READ_THREAD_GUARD_V(false);
  538. return get_embedder() != nullptr;
  539. }
  540. bool Window::is_in_edited_scene_root() const {
  541. ERR_READ_THREAD_GUARD_V(false);
  542. #ifdef TOOLS_ENABLED
  543. return is_part_of_edited_scene();
  544. #else
  545. return false;
  546. #endif
  547. }
  548. void Window::_make_window() {
  549. ERR_FAIL_COND(window_id != DisplayServer::INVALID_WINDOW_ID);
  550. if (transient && transient_to_focused) {
  551. _make_transient();
  552. }
  553. uint32_t f = 0;
  554. for (int i = 0; i < FLAG_MAX; i++) {
  555. if (flags[i]) {
  556. f |= (1 << i);
  557. }
  558. }
  559. DisplayServer::VSyncMode vsync_mode = DisplayServer::get_singleton()->window_get_vsync_mode(DisplayServer::MAIN_WINDOW_ID);
  560. Rect2i window_rect;
  561. if (initial_position == WINDOW_INITIAL_POSITION_ABSOLUTE) {
  562. window_rect = Rect2i(position, size);
  563. } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_PRIMARY_SCREEN) {
  564. window_rect = Rect2i(DisplayServer::get_singleton()->screen_get_position(DisplayServer::SCREEN_PRIMARY) + (DisplayServer::get_singleton()->screen_get_size(DisplayServer::SCREEN_PRIMARY) - size) / 2, size);
  565. } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN) {
  566. window_rect = Rect2i(DisplayServer::get_singleton()->screen_get_position(DisplayServer::SCREEN_OF_MAIN_WINDOW) + (DisplayServer::get_singleton()->screen_get_size(DisplayServer::SCREEN_OF_MAIN_WINDOW) - size) / 2, size);
  567. } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN) {
  568. window_rect = Rect2i(DisplayServer::get_singleton()->screen_get_position(current_screen) + (DisplayServer::get_singleton()->screen_get_size(current_screen) - size) / 2, size);
  569. } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_MOUSE_FOCUS) {
  570. window_rect = Rect2i(DisplayServer::get_singleton()->screen_get_position(DisplayServer::SCREEN_WITH_MOUSE_FOCUS) + (DisplayServer::get_singleton()->screen_get_size(DisplayServer::SCREEN_WITH_MOUSE_FOCUS) - size) / 2, size);
  571. } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_KEYBOARD_FOCUS) {
  572. window_rect = Rect2i(DisplayServer::get_singleton()->screen_get_position(DisplayServer::SCREEN_WITH_KEYBOARD_FOCUS) + (DisplayServer::get_singleton()->screen_get_size(DisplayServer::SCREEN_WITH_KEYBOARD_FOCUS) - size) / 2, size);
  573. }
  574. window_id = DisplayServer::get_singleton()->create_sub_window(DisplayServer::WindowMode(mode), vsync_mode, f, window_rect, is_in_edited_scene_root() ? false : exclusive, transient_parent ? transient_parent->window_id : DisplayServer::INVALID_WINDOW_ID);
  575. ERR_FAIL_COND(window_id == DisplayServer::INVALID_WINDOW_ID);
  576. DisplayServer::get_singleton()->window_set_max_size(Size2i(), window_id);
  577. DisplayServer::get_singleton()->window_set_min_size(Size2i(), window_id);
  578. DisplayServer::get_singleton()->window_set_mouse_passthrough(mpath, window_id);
  579. DisplayServer::get_singleton()->window_set_title(displayed_title, window_id);
  580. DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
  581. _update_window_size();
  582. if (transient_parent) {
  583. for (const Window *E : transient_children) {
  584. if (E->window_id != DisplayServer::INVALID_WINDOW_ID) {
  585. DisplayServer::get_singleton()->window_set_transient(E->window_id, transient_parent->window_id);
  586. }
  587. }
  588. }
  589. if (get_tree() && get_tree()->is_accessibility_supported()) {
  590. get_tree()->_accessibility_force_update();
  591. _accessibility_notify_enter(this);
  592. }
  593. _update_window_callbacks();
  594. RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE);
  595. DisplayServer::get_singleton()->show_window(window_id);
  596. }
  597. void Window::_update_from_window() {
  598. ERR_FAIL_COND(window_id == DisplayServer::INVALID_WINDOW_ID);
  599. mode = (Mode)DisplayServer::get_singleton()->window_get_mode(window_id);
  600. for (int i = 0; i < FLAG_MAX; i++) {
  601. flags[i] = DisplayServer::get_singleton()->window_get_flag(DisplayServer::WindowFlags(i), window_id);
  602. }
  603. }
  604. void Window::_clear_window() {
  605. ERR_FAIL_COND(window_id == DisplayServer::INVALID_WINDOW_ID);
  606. bool had_focus = has_focus();
  607. if (transient_parent && transient_parent->window_id != DisplayServer::INVALID_WINDOW_ID) {
  608. DisplayServer::get_singleton()->window_set_transient(window_id, DisplayServer::INVALID_WINDOW_ID);
  609. }
  610. for (const Window *E : transient_children) {
  611. if (E->window_id != DisplayServer::INVALID_WINDOW_ID) {
  612. DisplayServer::get_singleton()->window_set_transient(E->window_id, DisplayServer::INVALID_WINDOW_ID);
  613. }
  614. }
  615. _update_from_window();
  616. if (get_tree() && get_tree()->is_accessibility_supported()) {
  617. _accessibility_notify_exit(this);
  618. }
  619. DisplayServer::get_singleton()->delete_sub_window(window_id);
  620. window_id = DisplayServer::INVALID_WINDOW_ID;
  621. // If closing window was focused and has a parent, return focus.
  622. if (had_focus && transient_parent) {
  623. transient_parent->grab_focus();
  624. }
  625. _update_viewport_size();
  626. RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
  627. if (transient && transient_to_focused) {
  628. _clear_transient();
  629. }
  630. }
  631. void Window::_rect_changed_callback(const Rect2i &p_callback) {
  632. //we must always accept this as the truth
  633. if (size == p_callback.size && position == p_callback.position) {
  634. return;
  635. }
  636. if (position != p_callback.position) {
  637. position = p_callback.position;
  638. _propagate_window_notification(this, NOTIFICATION_WM_POSITION_CHANGED);
  639. }
  640. if (size != p_callback.size) {
  641. size = p_callback.size;
  642. _update_viewport_size();
  643. }
  644. if (window_id != DisplayServer::INVALID_WINDOW_ID && !DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SELF_FITTING_WINDOWS)) {
  645. Vector2 sz_out = DisplayServer::get_singleton()->window_get_size_with_decorations(window_id);
  646. Vector2 pos_out = DisplayServer::get_singleton()->window_get_position_with_decorations(window_id);
  647. Vector2 sz_in = DisplayServer::get_singleton()->window_get_size(window_id);
  648. Vector2 pos_in = DisplayServer::get_singleton()->window_get_position(window_id);
  649. DisplayServer::get_singleton()->accessibility_set_window_rect(window_id, Rect2(pos_out, sz_out), Rect2(pos_in, sz_in));
  650. }
  651. queue_accessibility_update();
  652. }
  653. void Window::_propagate_window_notification(Node *p_node, int p_notification) {
  654. p_node->notification(p_notification);
  655. for (int i = 0; i < p_node->get_child_count(); i++) {
  656. Node *child = p_node->get_child(i);
  657. Window *window = Object::cast_to<Window>(child);
  658. if (window) {
  659. continue;
  660. }
  661. _propagate_window_notification(child, p_notification);
  662. }
  663. }
  664. void Window::_event_callback(DisplayServer::WindowEvent p_event) {
  665. switch (p_event) {
  666. case DisplayServer::WINDOW_EVENT_MOUSE_ENTER: {
  667. if (!is_inside_tree()) {
  668. return;
  669. }
  670. Window *root = get_tree()->get_root();
  671. if (mouse_in_window && root->gui.windowmanager_window_over == this) {
  672. return;
  673. }
  674. if (root->gui.windowmanager_window_over) {
  675. #ifdef DEV_ENABLED
  676. WARN_PRINT_ONCE("Entering a window while a window is hovered should never happen in DisplayServer.");
  677. #endif // DEV_ENABLED
  678. root->gui.windowmanager_window_over->_event_callback(DisplayServer::WINDOW_EVENT_MOUSE_EXIT);
  679. }
  680. _propagate_window_notification(this, NOTIFICATION_WM_MOUSE_ENTER);
  681. root->gui.windowmanager_window_over = this;
  682. mouse_in_window = true;
  683. if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CURSOR_SHAPE)) {
  684. DisplayServer::get_singleton()->cursor_set_shape(DisplayServer::CURSOR_ARROW); //restore cursor shape
  685. }
  686. } break;
  687. case DisplayServer::WINDOW_EVENT_MOUSE_EXIT: {
  688. if (!is_inside_tree()) {
  689. return;
  690. }
  691. // Ensure keeping the order of input events and window events when input events are buffered or accumulated.
  692. Input::get_singleton()->flush_buffered_events();
  693. Window *root = get_tree()->get_root();
  694. if (!root->gui.windowmanager_window_over) {
  695. #ifdef DEV_ENABLED
  696. WARN_PRINT_ONCE("Exiting a window while no window is hovered should never happen in DisplayServer.");
  697. #endif // DEV_ENABLED
  698. return;
  699. }
  700. mouse_in_window = false;
  701. root->gui.windowmanager_window_over->_mouse_leave_viewport();
  702. root->gui.windowmanager_window_over = nullptr;
  703. _propagate_window_notification(this, NOTIFICATION_WM_MOUSE_EXIT);
  704. } break;
  705. case DisplayServer::WINDOW_EVENT_FOCUS_IN: {
  706. focused = true;
  707. focused_window = this;
  708. _propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_IN);
  709. emit_signal(SceneStringName(focus_entered));
  710. } break;
  711. case DisplayServer::WINDOW_EVENT_FOCUS_OUT: {
  712. focused = false;
  713. if (focused_window == this) {
  714. focused_window = nullptr;
  715. }
  716. _propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_OUT);
  717. emit_signal(SceneStringName(focus_exited));
  718. } break;
  719. case DisplayServer::WINDOW_EVENT_CLOSE_REQUEST: {
  720. if (exclusive_child != nullptr) {
  721. break; //has an exclusive child, can't get events until child is closed
  722. }
  723. _propagate_window_notification(this, NOTIFICATION_WM_CLOSE_REQUEST);
  724. emit_signal(SNAME("close_requested"));
  725. } break;
  726. case DisplayServer::WINDOW_EVENT_GO_BACK_REQUEST: {
  727. _propagate_window_notification(this, NOTIFICATION_WM_GO_BACK_REQUEST);
  728. emit_signal(SNAME("go_back_requested"));
  729. } break;
  730. case DisplayServer::WINDOW_EVENT_DPI_CHANGE: {
  731. _update_viewport_size();
  732. _propagate_window_notification(this, NOTIFICATION_WM_DPI_CHANGE);
  733. emit_signal(SNAME("dpi_changed"));
  734. } break;
  735. case DisplayServer::WINDOW_EVENT_TITLEBAR_CHANGE: {
  736. emit_signal(SNAME("titlebar_changed"));
  737. } break;
  738. case DisplayServer::WINDOW_EVENT_FORCE_CLOSE: {
  739. hide();
  740. } break;
  741. }
  742. }
  743. void Window::update_mouse_cursor_state() {
  744. ERR_MAIN_THREAD_GUARD;
  745. // Update states based on mouse cursor position.
  746. // This includes updated mouse_enter or mouse_exit signals or the current mouse cursor shape.
  747. // These details are set in Viewport::_gui_input_event. To instantly
  748. // see the changes in the viewport, we need to trigger a mouse motion event.
  749. // This function should be called whenever scene tree changes affect the mouse cursor.
  750. Ref<InputEventMouseMotion> mm;
  751. Vector2 pos = get_mouse_position();
  752. Transform2D xform = get_global_canvas_transform().affine_inverse();
  753. mm.instantiate();
  754. mm->set_position(pos);
  755. mm->set_global_position(xform.xform(pos));
  756. mm->set_device(InputEvent::DEVICE_ID_INTERNAL);
  757. push_input(mm, true);
  758. }
  759. void Window::show() {
  760. ERR_MAIN_THREAD_GUARD;
  761. set_visible(true);
  762. }
  763. void Window::hide() {
  764. ERR_MAIN_THREAD_GUARD;
  765. set_visible(false);
  766. }
  767. void Window::_accessibility_notify_enter(Node *p_node) {
  768. p_node->queue_accessibility_update();
  769. if (p_node != this) {
  770. const Window *window = Object::cast_to<Window>(p_node);
  771. if (window && !window->is_embedded()) {
  772. return;
  773. }
  774. }
  775. for (int i = 0; i < p_node->get_child_count(); i++) {
  776. _accessibility_notify_enter(p_node->get_child(i));
  777. }
  778. }
  779. void Window::_accessibility_notify_exit(Node *p_node) {
  780. p_node->notification(Node::NOTIFICATION_ACCESSIBILITY_INVALIDATE);
  781. if (p_node != this) {
  782. const Window *window = Object::cast_to<Window>(p_node);
  783. if (window && !window->is_embedded()) {
  784. return;
  785. }
  786. }
  787. for (int i = 0; i < p_node->get_child_count(); i++) {
  788. _accessibility_notify_exit(p_node->get_child(i));
  789. }
  790. }
  791. void Window::set_visible(bool p_visible) {
  792. ERR_MAIN_THREAD_GUARD;
  793. if (visible == p_visible) {
  794. return;
  795. }
  796. if (!is_inside_tree()) {
  797. visible = p_visible;
  798. return;
  799. }
  800. ERR_FAIL_NULL_MSG(get_parent(), "Can't change visibility of main window.");
  801. visible = p_visible;
  802. // Stop any queued resizing, as the window will be resized right now.
  803. updating_child_controls = false;
  804. Viewport *embedder_vp = get_embedder();
  805. if (!embedder_vp) {
  806. if (!p_visible && window_id != DisplayServer::INVALID_WINDOW_ID) {
  807. _clear_window();
  808. }
  809. if (p_visible && window_id == DisplayServer::INVALID_WINDOW_ID) {
  810. _make_window();
  811. }
  812. } else {
  813. if (visible) {
  814. embedder = embedder_vp;
  815. if (initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
  816. if (is_in_edited_scene_root()) {
  817. Size2 screen_size = Size2(GLOBAL_GET_CACHED(real_t, "display/window/size/viewport_width"), GLOBAL_GET_CACHED(real_t, "display/window/size/viewport_height"));
  818. position = (screen_size - size) / 2;
  819. } else {
  820. position = (embedder->get_visible_rect().size - size) / 2;
  821. }
  822. }
  823. embedder->_sub_window_register(this);
  824. embedder->queue_accessibility_update();
  825. RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
  826. } else {
  827. embedder->_sub_window_remove(this);
  828. embedder->queue_accessibility_update();
  829. embedder = nullptr;
  830. RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
  831. }
  832. _update_window_size();
  833. }
  834. if (!visible) {
  835. focused = false;
  836. if (focused_window == this) {
  837. focused_window = nullptr;
  838. }
  839. }
  840. notification(NOTIFICATION_VISIBILITY_CHANGED);
  841. emit_signal(SceneStringName(visibility_changed));
  842. RS::get_singleton()->viewport_set_active(get_viewport_rid(), visible);
  843. //update transient exclusive
  844. if (transient_parent) {
  845. _set_transient_exclusive_child(true);
  846. }
  847. }
  848. void Window::_clear_transient() {
  849. if (transient_parent) {
  850. if (transient_parent->window_id != DisplayServer::INVALID_WINDOW_ID && window_id != DisplayServer::INVALID_WINDOW_ID) {
  851. DisplayServer::get_singleton()->window_set_transient(window_id, DisplayServer::INVALID_WINDOW_ID);
  852. }
  853. transient_parent->transient_children.erase(this);
  854. if (transient_parent->exclusive_child == this) {
  855. transient_parent->exclusive_child = nullptr;
  856. }
  857. transient_parent = nullptr;
  858. }
  859. }
  860. void Window::_make_transient() {
  861. if (!get_parent()) {
  862. //main window, can't be transient
  863. return;
  864. }
  865. //find transient parent
  866. Window *window = nullptr;
  867. if (!is_embedded() && transient_to_focused) {
  868. DisplayServer::WindowID focused_window_id = DisplayServer::get_singleton()->get_focused_window();
  869. if (focused_window_id != DisplayServer::INVALID_WINDOW_ID) {
  870. window = Window::get_from_id(focused_window_id);
  871. }
  872. }
  873. if (!window) {
  874. Viewport *vp = get_parent()->get_viewport();
  875. while (vp) {
  876. window = Object::cast_to<Window>(vp);
  877. if (window) {
  878. break;
  879. }
  880. if (!vp->get_parent()) {
  881. break;
  882. }
  883. vp = vp->get_parent()->get_viewport();
  884. }
  885. }
  886. if (window) {
  887. transient_parent = window;
  888. window->transient_children.insert(this);
  889. _set_transient_exclusive_child();
  890. }
  891. //see if we can make transient
  892. if (transient_parent->window_id != DisplayServer::INVALID_WINDOW_ID && window_id != DisplayServer::INVALID_WINDOW_ID) {
  893. DisplayServer::get_singleton()->window_set_transient(window_id, transient_parent->window_id);
  894. }
  895. }
  896. void Window::_set_transient_exclusive_child(bool p_clear_invalid) {
  897. if (exclusive && visible && is_inside_tree()) {
  898. if (!is_in_edited_scene_root()) {
  899. // Transient parent has another exclusive child.
  900. if (transient_parent->exclusive_child && transient_parent->exclusive_child != this) {
  901. ERR_PRINT(vformat("Attempting to make child window exclusive, but the parent window already has another exclusive child. This window: %s, parent window: %s, current exclusive child window: %s", get_description(), transient_parent->get_description(), transient_parent->exclusive_child->get_description()));
  902. }
  903. transient_parent->exclusive_child = this;
  904. }
  905. } else if (p_clear_invalid) {
  906. if (transient_parent->exclusive_child == this) {
  907. transient_parent->exclusive_child = nullptr;
  908. }
  909. }
  910. }
  911. void Window::set_transient(bool p_transient) {
  912. ERR_MAIN_THREAD_GUARD;
  913. if (transient == p_transient) {
  914. return;
  915. }
  916. transient = p_transient;
  917. if (!is_inside_tree()) {
  918. return;
  919. }
  920. if (transient) {
  921. if (!transient_to_focused) {
  922. _make_transient();
  923. }
  924. } else {
  925. _clear_transient();
  926. }
  927. }
  928. bool Window::is_transient() const {
  929. return transient;
  930. }
  931. void Window::set_transient_to_focused(bool p_transient_to_focused) {
  932. ERR_MAIN_THREAD_GUARD;
  933. if (transient_to_focused == p_transient_to_focused) {
  934. return;
  935. }
  936. transient_to_focused = p_transient_to_focused;
  937. }
  938. bool Window::is_transient_to_focused() const {
  939. ERR_READ_THREAD_GUARD_V(false);
  940. return transient_to_focused;
  941. }
  942. void Window::set_exclusive(bool p_exclusive) {
  943. ERR_MAIN_THREAD_GUARD;
  944. if (exclusive == p_exclusive) {
  945. return;
  946. }
  947. exclusive = p_exclusive;
  948. if (!embedder && window_id != DisplayServer::INVALID_WINDOW_ID) {
  949. if (is_in_edited_scene_root()) {
  950. DisplayServer::get_singleton()->window_set_exclusive(window_id, false);
  951. } else {
  952. DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
  953. }
  954. }
  955. if (transient_parent) {
  956. _set_transient_exclusive_child(true);
  957. }
  958. }
  959. bool Window::is_exclusive() const {
  960. ERR_READ_THREAD_GUARD_V(false);
  961. return exclusive;
  962. }
  963. bool Window::is_visible() const {
  964. ERR_READ_THREAD_GUARD_V(false);
  965. return visible;
  966. }
  967. Size2i Window::_clamp_window_size(const Size2i &p_size) {
  968. Size2i window_size_clamped = p_size;
  969. Size2 minsize = get_clamped_minimum_size();
  970. window_size_clamped = window_size_clamped.max(minsize);
  971. if (max_size_used != Size2i()) {
  972. window_size_clamped = window_size_clamped.min(max_size_used);
  973. }
  974. return window_size_clamped;
  975. }
  976. void Window::_update_window_size() {
  977. Size2i size_limit = get_clamped_minimum_size();
  978. if (!embedder && window_id != DisplayServer::INVALID_WINDOW_ID && keep_title_visible) {
  979. Size2i title_size = DisplayServer::get_singleton()->window_get_title_size(displayed_title, window_id);
  980. size_limit = size_limit.max(title_size);
  981. }
  982. size = size.max(size_limit);
  983. bool reset_min_first = false;
  984. if (max_size_used != Size2i()) {
  985. // Force window size to respect size limitations of max_size_used.
  986. size = size.min(max_size_used);
  987. if (size_limit.x > max_size_used.x) {
  988. size_limit.x = max_size_used.x;
  989. reset_min_first = true;
  990. }
  991. if (size_limit.y > max_size_used.y) {
  992. size_limit.y = max_size_used.y;
  993. reset_min_first = true;
  994. }
  995. }
  996. if (embedder) {
  997. size = size.maxi(1);
  998. embedder->_sub_window_update(this);
  999. } else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  1000. // When main window embedded in the editor, we can't resize the main window.
  1001. if (window_id != DisplayServer::MAIN_WINDOW_ID || !Engine::get_singleton()->is_embedded_in_editor()) {
  1002. if (reset_min_first && wrap_controls) {
  1003. // Avoid an error if setting max_size to a value between min_size and the previous size_limit.
  1004. DisplayServer::get_singleton()->window_set_min_size(Size2i(), window_id);
  1005. }
  1006. DisplayServer::get_singleton()->window_set_max_size(max_size_used, window_id);
  1007. DisplayServer::get_singleton()->window_set_min_size(size_limit, window_id);
  1008. DisplayServer::get_singleton()->window_set_size(size, window_id);
  1009. }
  1010. }
  1011. //update the viewport
  1012. _update_viewport_size();
  1013. }
  1014. void Window::_update_viewport_size() {
  1015. //update the viewport part
  1016. Size2i final_size;
  1017. Size2 final_size_override;
  1018. Rect2i attach_to_screen_rect(Point2i(), size);
  1019. window_transform = Transform2D();
  1020. if (content_scale_stretch == Window::CONTENT_SCALE_STRETCH_INTEGER) {
  1021. // We always want to make sure that the content scale factor is a whole
  1022. // number, else there will be pixel wobble no matter what.
  1023. content_scale_factor = Math::floor(content_scale_factor);
  1024. // A content scale factor of zero is pretty useless.
  1025. if (content_scale_factor < 1) {
  1026. content_scale_factor = 1;
  1027. }
  1028. }
  1029. if (content_scale_mode == CONTENT_SCALE_MODE_DISABLED || content_scale_size.x == 0 || content_scale_size.y == 0) {
  1030. final_size = size;
  1031. final_size_override = Size2(size) / content_scale_factor;
  1032. } else {
  1033. //actual screen video mode
  1034. Size2 video_mode = size;
  1035. Size2 desired_res = content_scale_size;
  1036. Size2 viewport_size;
  1037. Size2 screen_size;
  1038. float viewport_aspect = desired_res.aspect();
  1039. float video_mode_aspect = video_mode.aspect();
  1040. if (content_scale_aspect == CONTENT_SCALE_ASPECT_IGNORE || Math::is_equal_approx(viewport_aspect, video_mode_aspect)) {
  1041. //same aspect or ignore aspect
  1042. viewport_size = desired_res;
  1043. screen_size = video_mode;
  1044. } else if (viewport_aspect < video_mode_aspect) {
  1045. // screen ratio is smaller vertically
  1046. if (content_scale_aspect == CONTENT_SCALE_ASPECT_KEEP_HEIGHT || content_scale_aspect == CONTENT_SCALE_ASPECT_EXPAND) {
  1047. //will stretch horizontally
  1048. viewport_size.x = desired_res.y * video_mode_aspect;
  1049. viewport_size.y = desired_res.y;
  1050. screen_size = video_mode;
  1051. } else {
  1052. //will need black bars
  1053. viewport_size = desired_res;
  1054. screen_size.x = video_mode.y * viewport_aspect;
  1055. screen_size.y = video_mode.y;
  1056. }
  1057. } else {
  1058. //screen ratio is smaller horizontally
  1059. if (content_scale_aspect == CONTENT_SCALE_ASPECT_KEEP_WIDTH || content_scale_aspect == CONTENT_SCALE_ASPECT_EXPAND) {
  1060. //will stretch horizontally
  1061. viewport_size.x = desired_res.x;
  1062. viewport_size.y = desired_res.x / video_mode_aspect;
  1063. screen_size = video_mode;
  1064. } else {
  1065. //will need black bars
  1066. viewport_size = desired_res;
  1067. screen_size.x = video_mode.x;
  1068. screen_size.y = video_mode.x / viewport_aspect;
  1069. }
  1070. }
  1071. screen_size = screen_size.floor();
  1072. viewport_size = viewport_size.floor();
  1073. if (content_scale_stretch == Window::CONTENT_SCALE_STRETCH_INTEGER) {
  1074. Size2i screen_scale = (screen_size / viewport_size).floor();
  1075. int scale_factor = MIN(screen_scale.x, screen_scale.y);
  1076. if (scale_factor < 1) {
  1077. scale_factor = 1;
  1078. }
  1079. screen_size = viewport_size * scale_factor;
  1080. }
  1081. Size2 margin;
  1082. Size2 offset;
  1083. if (screen_size.x < video_mode.x) {
  1084. margin.x = Math::round((video_mode.x - screen_size.x) / 2.0);
  1085. offset.x = Math::round(margin.x * viewport_size.y / screen_size.y);
  1086. }
  1087. if (screen_size.y < video_mode.y) {
  1088. margin.y = Math::round((video_mode.y - screen_size.y) / 2.0);
  1089. offset.y = Math::round(margin.y * viewport_size.x / screen_size.x);
  1090. }
  1091. switch (content_scale_mode) {
  1092. case CONTENT_SCALE_MODE_DISABLED: {
  1093. } break;
  1094. case CONTENT_SCALE_MODE_CANVAS_ITEMS: {
  1095. final_size = screen_size;
  1096. final_size_override = viewport_size / content_scale_factor;
  1097. attach_to_screen_rect = Rect2(margin, screen_size);
  1098. window_transform.translate_local(margin);
  1099. } break;
  1100. case CONTENT_SCALE_MODE_VIEWPORT: {
  1101. final_size = (viewport_size / content_scale_factor).floor();
  1102. attach_to_screen_rect = Rect2(margin, screen_size);
  1103. window_transform.translate_local(margin);
  1104. if (final_size.x != 0 && final_size.y != 0) {
  1105. Transform2D scale_transform;
  1106. scale_transform.scale(Vector2(attach_to_screen_rect.size) / Vector2(final_size));
  1107. window_transform *= scale_transform;
  1108. }
  1109. } break;
  1110. }
  1111. }
  1112. bool allocate = is_inside_tree() && visible && (window_id != DisplayServer::INVALID_WINDOW_ID || embedder != nullptr);
  1113. _set_size(final_size, final_size_override, allocate);
  1114. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  1115. RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), attach_to_screen_rect, window_id);
  1116. } else if (!is_embedded()) {
  1117. RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), Rect2i(), DisplayServer::INVALID_WINDOW_ID);
  1118. }
  1119. notification(NOTIFICATION_WM_SIZE_CHANGED);
  1120. if (embedder) {
  1121. float scale = MIN(embedder->stretch_transform.get_scale().width, embedder->stretch_transform.get_scale().height);
  1122. Viewport::set_oversampling_override(scale);
  1123. Size2 s = Size2(final_size.width * scale, final_size.height * scale).ceil();
  1124. RS::get_singleton()->viewport_set_global_canvas_transform(get_viewport_rid(), global_canvas_transform * scale * content_scale_factor);
  1125. RS::get_singleton()->viewport_set_size(get_viewport_rid(), s.width, s.height);
  1126. embedder->_sub_window_update(this);
  1127. }
  1128. }
  1129. void Window::_update_window_callbacks() {
  1130. DisplayServer::get_singleton()->window_set_rect_changed_callback(callable_mp(this, &Window::_rect_changed_callback), window_id);
  1131. DisplayServer::get_singleton()->window_set_window_event_callback(callable_mp(this, &Window::_event_callback), window_id);
  1132. DisplayServer::get_singleton()->window_set_input_event_callback(callable_mp(this, &Window::_window_input), window_id);
  1133. DisplayServer::get_singleton()->window_set_input_text_callback(callable_mp(this, &Window::_window_input_text), window_id);
  1134. DisplayServer::get_singleton()->window_set_drop_files_callback(callable_mp(this, &Window::_window_drop_files), window_id);
  1135. }
  1136. void Window::set_force_native(bool p_force_native) {
  1137. if (force_native == p_force_native) {
  1138. return;
  1139. }
  1140. if (is_visible() && !is_in_edited_scene_root()) {
  1141. ERR_FAIL_MSG("Can't change \"force_native\" while a window is displayed. Consider hiding window before changing this value.");
  1142. }
  1143. if (window_id == DisplayServer::MAIN_WINDOW_ID) {
  1144. return;
  1145. }
  1146. force_native = p_force_native;
  1147. if (!is_in_edited_scene_root() && is_inside_tree() && get_tree()->get_root()->is_embedding_subwindows()) {
  1148. set_embedding_subwindows(force_native);
  1149. }
  1150. }
  1151. bool Window::get_force_native() const {
  1152. return force_native;
  1153. }
  1154. Viewport *Window::get_embedder() const {
  1155. ERR_READ_THREAD_GUARD_V(nullptr);
  1156. if (force_native && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SUBWINDOWS) && !is_in_edited_scene_root()) {
  1157. return nullptr;
  1158. }
  1159. Viewport *vp = get_parent_viewport();
  1160. while (vp) {
  1161. if (vp->is_embedding_subwindows()) {
  1162. return vp;
  1163. }
  1164. if (vp->get_parent()) {
  1165. vp = vp->get_parent()->get_viewport();
  1166. } else {
  1167. vp = nullptr;
  1168. }
  1169. }
  1170. return nullptr;
  1171. }
  1172. RID Window::get_accessibility_element() const {
  1173. if (is_part_of_edited_scene()) {
  1174. return RID();
  1175. }
  1176. if (get_embedder()) {
  1177. return Node::get_accessibility_element();
  1178. } else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  1179. return DisplayServer::get_singleton()->accessibility_get_window_root(window_id);
  1180. } else {
  1181. return RID();
  1182. }
  1183. }
  1184. RID Window::get_focused_accessibility_element() const {
  1185. if (window_id == DisplayServer::MAIN_WINDOW_ID) {
  1186. if (get_child_count() > 0) {
  1187. return get_child(0)->get_focused_accessibility_element(); // Try scene tree root node.
  1188. }
  1189. }
  1190. return Node::get_focused_accessibility_element();
  1191. }
  1192. void Window::_notification(int p_what) {
  1193. ERR_MAIN_THREAD_GUARD;
  1194. switch (p_what) {
  1195. case NOTIFICATION_ACCESSIBILITY_INVALIDATE: {
  1196. accessibility_title_element = RID();
  1197. accessibility_announcement_element = RID();
  1198. } break;
  1199. case NOTIFICATION_ACCESSIBILITY_UPDATE: {
  1200. RID ae = get_accessibility_element();
  1201. ERR_FAIL_COND(ae.is_null());
  1202. DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_WINDOW);
  1203. if (accessibility_name.is_empty()) {
  1204. DisplayServer::get_singleton()->accessibility_update_set_name(ae, displayed_title);
  1205. } else {
  1206. DisplayServer::get_singleton()->accessibility_update_set_name(ae, accessibility_name);
  1207. }
  1208. DisplayServer::get_singleton()->accessibility_update_set_description(ae, accessibility_description);
  1209. DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_MODAL, exclusive);
  1210. DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_FOCUS, callable_mp(this, &Window::_accessibility_action_grab_focus));
  1211. DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_HIDDEN, !visible);
  1212. if (get_embedder()) {
  1213. Control *parent_ctrl = Object::cast_to<Control>(get_parent());
  1214. Transform2D parent_tr = parent_ctrl ? parent_ctrl->get_global_transform() : Transform2D();
  1215. Transform2D tr;
  1216. tr.set_origin(position);
  1217. DisplayServer::get_singleton()->accessibility_update_set_transform(ae, parent_tr.affine_inverse() * tr);
  1218. DisplayServer::get_singleton()->accessibility_update_set_bounds(ae, Rect2(Point2(), size));
  1219. if (accessibility_title_element.is_null()) {
  1220. accessibility_title_element = DisplayServer::get_singleton()->accessibility_create_sub_element(ae, DisplayServer::AccessibilityRole::ROLE_TITLE_BAR);
  1221. }
  1222. int w = get_theme_constant(SNAME("title_height"));
  1223. DisplayServer::get_singleton()->accessibility_update_set_name(accessibility_title_element, displayed_title);
  1224. DisplayServer::get_singleton()->accessibility_update_set_bounds(accessibility_title_element, Rect2(Vector2(0, -w), Size2(size.x, w)));
  1225. } else {
  1226. DisplayServer::get_singleton()->accessibility_update_set_transform(ae, get_final_transform());
  1227. if (_get_size_2d_override() != Size2()) {
  1228. DisplayServer::get_singleton()->accessibility_update_set_bounds(ae, Rect2(Point2(), _get_size_2d_override()));
  1229. } else {
  1230. DisplayServer::get_singleton()->accessibility_update_set_bounds(ae, Rect2(Point2(), _get_size()));
  1231. }
  1232. if (accessibility_announcement_element.is_null()) {
  1233. accessibility_announcement_element = DisplayServer::get_singleton()->accessibility_create_sub_element(ae, DisplayServer::AccessibilityRole::ROLE_STATIC_TEXT);
  1234. }
  1235. if (announcement.is_empty()) {
  1236. DisplayServer::get_singleton()->accessibility_update_set_live(accessibility_announcement_element, DisplayServer::LIVE_OFF);
  1237. } else {
  1238. DisplayServer::get_singleton()->accessibility_update_set_name(accessibility_announcement_element, announcement);
  1239. DisplayServer::get_singleton()->accessibility_update_set_live(accessibility_announcement_element, DisplayServer::LIVE_ASSERTIVE);
  1240. }
  1241. }
  1242. } break;
  1243. case NOTIFICATION_POSTINITIALIZE: {
  1244. initialized = true;
  1245. _invalidate_theme_cache();
  1246. _update_theme_item_cache();
  1247. } break;
  1248. case NOTIFICATION_PARENTED: {
  1249. theme_owner->assign_theme_on_parented(this);
  1250. } break;
  1251. case NOTIFICATION_UNPARENTED: {
  1252. theme_owner->clear_theme_on_unparented(this);
  1253. } break;
  1254. case NOTIFICATION_ENTER_TREE: {
  1255. if (is_in_edited_scene_root()) {
  1256. if (!ProjectSettings::get_singleton()->is_connected("settings_changed", callable_mp(this, &Window::_settings_changed))) {
  1257. ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &Window::_settings_changed));
  1258. }
  1259. } else if (get_parent() && get_tree()->get_root()->is_embedding_subwindows()) {
  1260. // Is not the main window and main window is embedding.
  1261. set_embedding_subwindows(force_native);
  1262. }
  1263. bool embedded = false;
  1264. {
  1265. embedder = get_embedder();
  1266. if (embedder) {
  1267. embedded = true;
  1268. if (!visible) {
  1269. embedder = nullptr; // Not yet since not visible.
  1270. }
  1271. }
  1272. }
  1273. if (embedded) {
  1274. // Create as embedded.
  1275. if (embedder) {
  1276. if (initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
  1277. if (is_in_edited_scene_root()) {
  1278. Size2 screen_size = Size2(GLOBAL_GET_CACHED(real_t, "display/window/size/viewport_width"), GLOBAL_GET_CACHED(real_t, "display/window/size/viewport_height"));
  1279. position = (screen_size - size) / 2;
  1280. } else {
  1281. position = (embedder->get_visible_rect().size - size) / 2;
  1282. }
  1283. }
  1284. embedder->_sub_window_register(this);
  1285. RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
  1286. _update_window_size();
  1287. }
  1288. } else {
  1289. if (!get_parent()) {
  1290. // It's the root window!
  1291. visible = true; // Always visible.
  1292. window_id = DisplayServer::MAIN_WINDOW_ID;
  1293. focused_window = this;
  1294. DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
  1295. _update_from_window();
  1296. // Since this window already exists (created on start), we must update pos and size from it.
  1297. {
  1298. position = DisplayServer::get_singleton()->window_get_position(window_id);
  1299. size = DisplayServer::get_singleton()->window_get_size(window_id);
  1300. focused = DisplayServer::get_singleton()->window_is_focused(window_id);
  1301. }
  1302. _update_window_size(); // Inform DisplayServer of minimum and maximum size.
  1303. _update_viewport_size(); // Then feed back to the viewport.
  1304. _update_window_callbacks();
  1305. // Simulate mouse-enter event when mouse is over the window, since OS event might arrive before setting callbacks.
  1306. if (!mouse_in_window && Rect2(position, size).has_point(DisplayServer::get_singleton()->mouse_get_position())) {
  1307. _event_callback(DisplayServer::WINDOW_EVENT_MOUSE_ENTER);
  1308. }
  1309. RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE);
  1310. if (DisplayServer::get_singleton()->window_get_flag(DisplayServer::WindowFlags(FLAG_TRANSPARENT), window_id)) {
  1311. set_transparent_background(true);
  1312. }
  1313. } else {
  1314. // Create.
  1315. if (visible) {
  1316. _make_window();
  1317. }
  1318. }
  1319. }
  1320. if (transient && !transient_to_focused) {
  1321. _make_transient();
  1322. }
  1323. if (visible) {
  1324. notification(NOTIFICATION_VISIBILITY_CHANGED);
  1325. emit_signal(SceneStringName(visibility_changed));
  1326. RS::get_singleton()->viewport_set_active(get_viewport_rid(), true);
  1327. }
  1328. // Emits NOTIFICATION_THEME_CHANGED internally.
  1329. set_theme_context(ThemeDB::get_singleton()->get_nearest_theme_context(this));
  1330. } break;
  1331. case NOTIFICATION_READY: {
  1332. if (wrap_controls) {
  1333. // Finish any resizing immediately so it doesn't interfere on stuff overriding _ready().
  1334. _update_child_controls();
  1335. }
  1336. } break;
  1337. case NOTIFICATION_THEME_CHANGED: {
  1338. emit_signal(SceneStringName(theme_changed));
  1339. _invalidate_theme_cache();
  1340. _update_theme_item_cache();
  1341. } break;
  1342. case NOTIFICATION_TRANSLATION_CHANGED: {
  1343. _invalidate_theme_cache();
  1344. _update_theme_item_cache();
  1345. _update_displayed_title();
  1346. } break;
  1347. case NOTIFICATION_VISIBILITY_CHANGED: {
  1348. if (unparent_when_invisible && !is_visible()) {
  1349. Node *p = get_parent();
  1350. if (p) {
  1351. p->remove_child(this);
  1352. }
  1353. }
  1354. } break;
  1355. case NOTIFICATION_EXIT_TREE: {
  1356. if (ProjectSettings::get_singleton()->is_connected("settings_changed", callable_mp(this, &Window::_settings_changed))) {
  1357. ProjectSettings::get_singleton()->disconnect("settings_changed", callable_mp(this, &Window::_settings_changed));
  1358. }
  1359. set_theme_context(nullptr, false);
  1360. accessibility_title_element = RID();
  1361. accessibility_announcement_element = RID();
  1362. if (transient) {
  1363. _clear_transient();
  1364. }
  1365. if (!is_embedded() && window_id != DisplayServer::INVALID_WINDOW_ID) {
  1366. if (window_id == DisplayServer::MAIN_WINDOW_ID) {
  1367. RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
  1368. _update_window_callbacks();
  1369. } else {
  1370. _clear_window();
  1371. }
  1372. } else {
  1373. if (embedder) {
  1374. embedder->_sub_window_remove(this);
  1375. embedder = nullptr;
  1376. RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
  1377. }
  1378. _update_viewport_size(); //called by clear and make, which does not happen here
  1379. }
  1380. RS::get_singleton()->viewport_set_active(get_viewport_rid(), false);
  1381. } break;
  1382. case NOTIFICATION_VP_MOUSE_ENTER: {
  1383. emit_signal(SceneStringName(mouse_entered));
  1384. } break;
  1385. case NOTIFICATION_VP_MOUSE_EXIT: {
  1386. emit_signal(SceneStringName(mouse_exited));
  1387. } break;
  1388. }
  1389. }
  1390. void Window::set_content_scale_size(const Size2i &p_size) {
  1391. ERR_MAIN_THREAD_GUARD;
  1392. ERR_FAIL_COND(p_size.x < 0);
  1393. ERR_FAIL_COND(p_size.y < 0);
  1394. content_scale_size = p_size;
  1395. _update_viewport_size();
  1396. }
  1397. Size2i Window::get_content_scale_size() const {
  1398. ERR_READ_THREAD_GUARD_V(Size2i());
  1399. return content_scale_size;
  1400. }
  1401. void Window::set_content_scale_mode(ContentScaleMode p_mode) {
  1402. ERR_MAIN_THREAD_GUARD;
  1403. content_scale_mode = p_mode;
  1404. _update_viewport_size();
  1405. }
  1406. Window::ContentScaleMode Window::get_content_scale_mode() const {
  1407. ERR_READ_THREAD_GUARD_V(CONTENT_SCALE_MODE_DISABLED);
  1408. return content_scale_mode;
  1409. }
  1410. void Window::set_content_scale_aspect(ContentScaleAspect p_aspect) {
  1411. ERR_MAIN_THREAD_GUARD;
  1412. content_scale_aspect = p_aspect;
  1413. _update_viewport_size();
  1414. }
  1415. Window::ContentScaleAspect Window::get_content_scale_aspect() const {
  1416. ERR_READ_THREAD_GUARD_V(CONTENT_SCALE_ASPECT_IGNORE);
  1417. return content_scale_aspect;
  1418. }
  1419. void Window::set_content_scale_stretch(ContentScaleStretch p_stretch) {
  1420. content_scale_stretch = p_stretch;
  1421. _update_viewport_size();
  1422. }
  1423. Window::ContentScaleStretch Window::get_content_scale_stretch() const {
  1424. return content_scale_stretch;
  1425. }
  1426. void Window::set_keep_title_visible(bool p_title_visible) {
  1427. if (keep_title_visible == p_title_visible) {
  1428. return;
  1429. }
  1430. keep_title_visible = p_title_visible;
  1431. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  1432. _update_window_size();
  1433. }
  1434. }
  1435. bool Window::get_keep_title_visible() const {
  1436. return keep_title_visible;
  1437. }
  1438. void Window::set_content_scale_factor(real_t p_factor) {
  1439. ERR_MAIN_THREAD_GUARD;
  1440. ERR_FAIL_COND(p_factor <= 0);
  1441. content_scale_factor = p_factor;
  1442. _update_viewport_size();
  1443. }
  1444. real_t Window::get_content_scale_factor() const {
  1445. ERR_READ_THREAD_GUARD_V(0);
  1446. return content_scale_factor;
  1447. }
  1448. DisplayServer::WindowID Window::get_window_id() const {
  1449. ERR_READ_THREAD_GUARD_V(DisplayServer::INVALID_WINDOW_ID);
  1450. if (get_embedder()) {
  1451. #ifdef TOOLS_ENABLED
  1452. if (is_part_of_edited_scene()) {
  1453. return DisplayServer::MAIN_WINDOW_ID;
  1454. }
  1455. #endif
  1456. return parent->get_window_id();
  1457. }
  1458. return window_id;
  1459. }
  1460. void Window::set_mouse_passthrough_polygon(const Vector<Vector2> &p_region) {
  1461. ERR_MAIN_THREAD_GUARD;
  1462. mpath = p_region;
  1463. if (window_id == DisplayServer::INVALID_WINDOW_ID) {
  1464. return;
  1465. }
  1466. DisplayServer::get_singleton()->window_set_mouse_passthrough(mpath, window_id);
  1467. }
  1468. Vector<Vector2> Window::get_mouse_passthrough_polygon() const {
  1469. return mpath;
  1470. }
  1471. void Window::set_wrap_controls(bool p_enable) {
  1472. ERR_MAIN_THREAD_GUARD;
  1473. wrap_controls = p_enable;
  1474. if (!is_inside_tree()) {
  1475. return;
  1476. }
  1477. if (updating_child_controls) {
  1478. _update_child_controls();
  1479. } else {
  1480. _update_window_size();
  1481. }
  1482. }
  1483. bool Window::is_wrapping_controls() const {
  1484. ERR_READ_THREAD_GUARD_V(false);
  1485. return wrap_controls;
  1486. }
  1487. Size2 Window::_get_contents_minimum_size() const {
  1488. Size2 max;
  1489. for (int i = 0; i < get_child_count(); i++) {
  1490. Control *c = Object::cast_to<Control>(get_child(i));
  1491. if (c) {
  1492. Point2i pos = c->get_position();
  1493. Size2i min = c->get_combined_minimum_size();
  1494. max = max.max(pos + min);
  1495. }
  1496. }
  1497. return max * content_scale_factor;
  1498. }
  1499. void Window::child_controls_changed() {
  1500. ERR_MAIN_THREAD_GUARD;
  1501. if (!is_inside_tree() || !visible || updating_child_controls) {
  1502. return;
  1503. }
  1504. updating_child_controls = true;
  1505. callable_mp(this, &Window::_update_child_controls).call_deferred();
  1506. }
  1507. void Window::_update_child_controls() {
  1508. if (!updating_child_controls) {
  1509. return;
  1510. }
  1511. _update_window_size();
  1512. updating_child_controls = false;
  1513. }
  1514. bool Window::_can_consume_input_events() const {
  1515. return exclusive_child == nullptr;
  1516. }
  1517. void Window::_window_input(const Ref<InputEvent> &p_ev) {
  1518. ERR_MAIN_THREAD_GUARD;
  1519. if (exclusive_child != nullptr) {
  1520. if (!is_embedding_subwindows()) { // Not embedding, no need for event.
  1521. return;
  1522. }
  1523. }
  1524. // If the event needs to be handled in a Window-derived class, then it should overwrite
  1525. // `_input_from_window` instead of subscribing to the `window_input` signal, because the signal
  1526. // filters out internal events.
  1527. _input_from_window(p_ev);
  1528. if (p_ev->get_device() != InputEvent::DEVICE_ID_INTERNAL && is_inside_tree()) {
  1529. emit_signal(SceneStringName(window_input), p_ev);
  1530. }
  1531. if (is_inside_tree()) {
  1532. push_input(p_ev);
  1533. }
  1534. }
  1535. void Window::_window_input_text(const String &p_text) {
  1536. push_text_input(p_text);
  1537. }
  1538. void Window::_window_drop_files(const Vector<String> &p_files) {
  1539. emit_signal(SNAME("files_dropped"), p_files);
  1540. }
  1541. Viewport *Window::get_parent_viewport() const {
  1542. ERR_READ_THREAD_GUARD_V(nullptr);
  1543. if (get_parent()) {
  1544. return get_parent()->get_viewport();
  1545. } else {
  1546. return nullptr;
  1547. }
  1548. }
  1549. Window *Window::get_parent_visible_window() const {
  1550. ERR_READ_THREAD_GUARD_V(nullptr);
  1551. Viewport *vp = get_parent_viewport();
  1552. Window *window = nullptr;
  1553. while (vp) {
  1554. window = Object::cast_to<Window>(vp);
  1555. if (window && window->visible) {
  1556. break;
  1557. }
  1558. if (!vp->get_parent()) {
  1559. break;
  1560. }
  1561. vp = vp->get_parent()->get_viewport();
  1562. }
  1563. return window;
  1564. }
  1565. void Window::popup_on_parent(const Rect2i &p_parent_rect) {
  1566. ERR_MAIN_THREAD_GUARD;
  1567. ERR_FAIL_COND(!is_inside_tree());
  1568. ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window.");
  1569. if (!is_embedded()) {
  1570. Window *window = get_parent_visible_window();
  1571. if (!window) {
  1572. popup(p_parent_rect);
  1573. } else {
  1574. popup(Rect2i(window->get_position() + p_parent_rect.position, p_parent_rect.size));
  1575. }
  1576. } else {
  1577. popup(p_parent_rect);
  1578. }
  1579. }
  1580. void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio) {
  1581. ERR_MAIN_THREAD_GUARD;
  1582. ERR_FAIL_COND(!is_inside_tree());
  1583. ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window.");
  1584. // Consider the current size when calling with the default value.
  1585. Size2i expected_size = p_size == Size2i() ? size : p_size;
  1586. Rect2 parent_rect;
  1587. if (is_embedded()) {
  1588. parent_rect = get_embedder()->get_visible_rect();
  1589. } else {
  1590. DisplayServer::WindowID parent_id = get_parent_visible_window()->get_window_id();
  1591. int parent_screen = DisplayServer::get_singleton()->window_get_current_screen(parent_id);
  1592. parent_rect.position = DisplayServer::get_singleton()->screen_get_position(parent_screen);
  1593. parent_rect.size = DisplayServer::get_singleton()->screen_get_size(parent_screen);
  1594. }
  1595. Vector2i size_ratio = parent_rect.size * p_fallback_ratio;
  1596. Rect2i popup_rect;
  1597. popup_rect.size = size_ratio.min(expected_size);
  1598. popup_rect.size = _clamp_window_size(popup_rect.size);
  1599. if (parent_rect != Rect2()) {
  1600. popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
  1601. }
  1602. popup(popup_rect);
  1603. }
  1604. void Window::popup_centered(const Size2i &p_minsize) {
  1605. ERR_MAIN_THREAD_GUARD;
  1606. ERR_FAIL_COND(!is_inside_tree());
  1607. ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window.");
  1608. // Consider the current size when calling with the default value.
  1609. Size2i expected_size = p_minsize == Size2i() ? size : p_minsize;
  1610. Rect2 parent_rect;
  1611. if (is_embedded()) {
  1612. parent_rect = get_embedder()->get_visible_rect();
  1613. } else {
  1614. DisplayServer::WindowID parent_id = get_parent_visible_window()->get_window_id();
  1615. int parent_screen = DisplayServer::get_singleton()->window_get_current_screen(parent_id);
  1616. parent_rect.position = DisplayServer::get_singleton()->screen_get_position(parent_screen);
  1617. parent_rect.size = DisplayServer::get_singleton()->screen_get_size(parent_screen);
  1618. }
  1619. Rect2i popup_rect;
  1620. popup_rect.size = _clamp_window_size(expected_size);
  1621. if (parent_rect != Rect2()) {
  1622. popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
  1623. }
  1624. popup(popup_rect);
  1625. }
  1626. void Window::popup_centered_ratio(float p_ratio) {
  1627. ERR_MAIN_THREAD_GUARD;
  1628. ERR_FAIL_COND(!is_inside_tree());
  1629. ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window.");
  1630. ERR_FAIL_COND_MSG(p_ratio <= 0.0 || p_ratio > 1.0, "Ratio must be between 0.0 and 1.0!");
  1631. Rect2 parent_rect;
  1632. if (is_embedded()) {
  1633. parent_rect = get_embedder()->get_visible_rect();
  1634. } else {
  1635. DisplayServer::WindowID parent_id = get_parent_visible_window()->get_window_id();
  1636. int parent_screen = DisplayServer::get_singleton()->window_get_current_screen(parent_id);
  1637. parent_rect.position = DisplayServer::get_singleton()->screen_get_position(parent_screen);
  1638. parent_rect.size = DisplayServer::get_singleton()->screen_get_size(parent_screen);
  1639. }
  1640. Rect2i popup_rect;
  1641. if (parent_rect != Rect2()) {
  1642. popup_rect.size = parent_rect.size * p_ratio;
  1643. popup_rect.size = _clamp_window_size(popup_rect.size);
  1644. popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
  1645. }
  1646. popup(popup_rect);
  1647. }
  1648. void Window::popup(const Rect2i &p_screen_rect) {
  1649. ERR_MAIN_THREAD_GUARD;
  1650. emit_signal(SNAME("about_to_popup"));
  1651. _pre_popup();
  1652. if (!get_embedder() && get_flag(FLAG_POPUP)) {
  1653. // Send a focus-out notification when opening a Window Manager Popup.
  1654. SceneTree *scene_tree = get_tree();
  1655. if (scene_tree) {
  1656. scene_tree->notify_group_flags(SceneTree::GROUP_CALL_DEFERRED, "_viewports", NOTIFICATION_WM_WINDOW_FOCUS_OUT);
  1657. }
  1658. }
  1659. // Update window size to calculate the actual window size based on contents minimum size and minimum size.
  1660. _update_window_size();
  1661. bool should_fit = is_embedded() || !DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SELF_FITTING_WINDOWS);
  1662. if (p_screen_rect != Rect2i()) {
  1663. set_position(p_screen_rect.position);
  1664. if (should_fit) {
  1665. int screen_id = DisplayServer::get_singleton()->get_screen_from_rect(p_screen_rect);
  1666. Size2i screen_size = DisplayServer::get_singleton()->screen_get_usable_rect(screen_id).size;
  1667. Size2i new_size = p_screen_rect.size.min(screen_size);
  1668. set_size(new_size);
  1669. } else {
  1670. set_size(p_screen_rect.size);
  1671. }
  1672. }
  1673. Rect2i adjust = _popup_adjust_rect();
  1674. if (adjust != Rect2i()) {
  1675. set_position(adjust.position);
  1676. set_size(adjust.size);
  1677. }
  1678. int scr = DisplayServer::get_singleton()->get_screen_count();
  1679. for (int i = 0; i < scr; i++) {
  1680. Rect2i r = DisplayServer::get_singleton()->screen_get_usable_rect(i);
  1681. if (r.has_point(position)) {
  1682. current_screen = i;
  1683. break;
  1684. }
  1685. }
  1686. set_transient(true);
  1687. set_visible(true);
  1688. Rect2i parent_rect;
  1689. if (is_embedded()) {
  1690. parent_rect = get_embedder()->get_visible_rect();
  1691. } else {
  1692. int screen_id = DisplayServer::get_singleton()->window_get_current_screen(get_window_id());
  1693. parent_rect = DisplayServer::get_singleton()->screen_get_usable_rect(screen_id);
  1694. }
  1695. if (should_fit && parent_rect != Rect2i() && !parent_rect.intersects(Rect2i(position, size))) {
  1696. ERR_PRINT(vformat("Window %d spawned at invalid position: %s.", get_window_id(), position));
  1697. set_position((parent_rect.size - size) / 2);
  1698. }
  1699. if (parent_rect != Rect2i() && is_clamped_to_embedder() && is_embedded()) {
  1700. Rect2i new_rect = fit_rect_in_parent(Rect2i(position, size), parent_rect);
  1701. set_position(new_rect.position);
  1702. set_size(new_rect.size);
  1703. }
  1704. _post_popup();
  1705. notification(NOTIFICATION_POST_POPUP);
  1706. }
  1707. bool Window::_try_parent_dialog(Node *p_from_node) {
  1708. ERR_FAIL_NULL_V(p_from_node, false);
  1709. ERR_FAIL_COND_V_MSG(is_inside_tree(), false, "Attempting to parent and popup a dialog that already has a parent.");
  1710. Window *w = p_from_node->get_last_exclusive_window();
  1711. if (w && w != this) {
  1712. w->add_child(this);
  1713. return true;
  1714. }
  1715. return false;
  1716. }
  1717. void Window::popup_exclusive(Node *p_from_node, const Rect2i &p_screen_rect) {
  1718. if (_try_parent_dialog(p_from_node)) {
  1719. popup(p_screen_rect);
  1720. }
  1721. }
  1722. void Window::popup_exclusive_on_parent(Node *p_from_node, const Rect2i &p_parent_rect) {
  1723. if (_try_parent_dialog(p_from_node)) {
  1724. popup_on_parent(p_parent_rect);
  1725. }
  1726. }
  1727. void Window::popup_exclusive_centered(Node *p_from_node, const Size2i &p_minsize) {
  1728. if (_try_parent_dialog(p_from_node)) {
  1729. popup_centered(p_minsize);
  1730. }
  1731. }
  1732. void Window::popup_exclusive_centered_ratio(Node *p_from_node, float p_ratio) {
  1733. if (_try_parent_dialog(p_from_node)) {
  1734. popup_centered_ratio(p_ratio);
  1735. }
  1736. }
  1737. void Window::popup_exclusive_centered_clamped(Node *p_from_node, const Size2i &p_size, float p_fallback_ratio) {
  1738. if (_try_parent_dialog(p_from_node)) {
  1739. popup_centered_clamped(p_size, p_fallback_ratio);
  1740. }
  1741. }
  1742. Rect2i Window::fit_rect_in_parent(Rect2i p_rect, const Rect2i &p_parent_rect) const {
  1743. ERR_READ_THREAD_GUARD_V(Rect2i());
  1744. Size2i limit = p_parent_rect.size;
  1745. if (p_rect.position.x + p_rect.size.x > limit.x) {
  1746. p_rect.position.x = limit.x - p_rect.size.x;
  1747. }
  1748. if (p_rect.position.y + p_rect.size.y > limit.y) {
  1749. p_rect.position.y = limit.y - p_rect.size.y;
  1750. }
  1751. if (p_rect.position.x < 0) {
  1752. p_rect.position.x = 0;
  1753. }
  1754. int title_height = get_flag(Window::FLAG_BORDERLESS) ? 0 : theme_cache.title_height;
  1755. if (p_rect.position.y < title_height) {
  1756. p_rect.position.y = title_height;
  1757. }
  1758. return p_rect;
  1759. }
  1760. Size2 Window::get_contents_minimum_size() const {
  1761. ERR_READ_THREAD_GUARD_V(Size2());
  1762. Vector2 ms;
  1763. if (GDVIRTUAL_CALL(_get_contents_minimum_size, ms)) {
  1764. return ms;
  1765. }
  1766. return _get_contents_minimum_size();
  1767. }
  1768. Size2 Window::get_clamped_minimum_size() const {
  1769. ERR_READ_THREAD_GUARD_V(Size2());
  1770. if (!wrap_controls) {
  1771. return min_size;
  1772. }
  1773. return min_size.max(get_contents_minimum_size() * get_content_scale_factor());
  1774. }
  1775. void Window::grab_focus() {
  1776. ERR_MAIN_THREAD_GUARD;
  1777. if (embedder) {
  1778. embedder->_sub_window_grab_focus(this);
  1779. } else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  1780. DisplayServer::get_singleton()->window_move_to_foreground(window_id);
  1781. }
  1782. }
  1783. bool Window::has_focus() const {
  1784. ERR_READ_THREAD_GUARD_V(false);
  1785. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  1786. return DisplayServer::get_singleton()->window_is_focused(window_id);
  1787. }
  1788. return focused;
  1789. }
  1790. bool Window::has_focus_or_active_popup() const {
  1791. ERR_READ_THREAD_GUARD_V(false);
  1792. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  1793. return DisplayServer::get_singleton()->window_is_focused(window_id) || (DisplayServer::get_singleton()->window_get_active_popup() == window_id);
  1794. }
  1795. return focused;
  1796. }
  1797. void Window::start_drag() {
  1798. ERR_MAIN_THREAD_GUARD;
  1799. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  1800. DisplayServer::get_singleton()->window_start_drag(window_id);
  1801. } else if (embedder) {
  1802. embedder->_window_start_drag(this);
  1803. }
  1804. }
  1805. void Window::start_resize(DisplayServer::WindowResizeEdge p_edge) {
  1806. ERR_MAIN_THREAD_GUARD;
  1807. if (get_flag(FLAG_RESIZE_DISABLED)) {
  1808. return;
  1809. }
  1810. if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  1811. DisplayServer::get_singleton()->window_start_resize(p_edge, window_id);
  1812. } else if (embedder) {
  1813. switch (p_edge) {
  1814. case DisplayServer::WINDOW_EDGE_TOP_LEFT: {
  1815. embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_TOP_LEFT, this);
  1816. } break;
  1817. case DisplayServer::WINDOW_EDGE_TOP: {
  1818. embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_TOP, this);
  1819. } break;
  1820. case DisplayServer::WINDOW_EDGE_TOP_RIGHT: {
  1821. embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_TOP_RIGHT, this);
  1822. } break;
  1823. case DisplayServer::WINDOW_EDGE_LEFT: {
  1824. embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_LEFT, this);
  1825. } break;
  1826. case DisplayServer::WINDOW_EDGE_RIGHT: {
  1827. embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_RIGHT, this);
  1828. } break;
  1829. case DisplayServer::WINDOW_EDGE_BOTTOM_LEFT: {
  1830. embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_BOTTOM_LEFT, this);
  1831. } break;
  1832. case DisplayServer::WINDOW_EDGE_BOTTOM: {
  1833. embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_BOTTOM, this);
  1834. } break;
  1835. case DisplayServer::WINDOW_EDGE_BOTTOM_RIGHT: {
  1836. embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_BOTTOM_RIGHT, this);
  1837. } break;
  1838. default:
  1839. break;
  1840. }
  1841. }
  1842. }
  1843. Rect2i Window::get_usable_parent_rect() const {
  1844. ERR_READ_THREAD_GUARD_V(Rect2i());
  1845. ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
  1846. Rect2i parent_rect;
  1847. if (is_embedded()) {
  1848. parent_rect = get_embedder()->get_visible_rect();
  1849. } else {
  1850. const Window *w = is_visible() ? this : get_parent_visible_window();
  1851. //find a parent that can contain us
  1852. ERR_FAIL_NULL_V(w, Rect2());
  1853. parent_rect = DisplayServer::get_singleton()->screen_get_usable_rect(DisplayServer::get_singleton()->window_get_current_screen(w->get_window_id()));
  1854. }
  1855. return parent_rect;
  1856. }
  1857. void Window::set_accessibility_name(const String &p_name) {
  1858. ERR_MAIN_THREAD_GUARD;
  1859. if (accessibility_name != p_name) {
  1860. accessibility_name = p_name;
  1861. queue_accessibility_update();
  1862. update_configuration_warnings();
  1863. }
  1864. }
  1865. String Window::get_accessibility_name() const {
  1866. return tr(accessibility_name);
  1867. }
  1868. void Window::set_accessibility_description(const String &p_description) {
  1869. ERR_MAIN_THREAD_GUARD;
  1870. if (accessibility_description != p_description) {
  1871. accessibility_description = p_description;
  1872. queue_accessibility_update();
  1873. }
  1874. }
  1875. String Window::get_accessibility_description() const {
  1876. return tr(accessibility_description);
  1877. }
  1878. void Window::accessibility_announcement(const String &p_announcement) {
  1879. ERR_MAIN_THREAD_GUARD;
  1880. announcement = p_announcement;
  1881. queue_accessibility_update();
  1882. }
  1883. void Window::add_child_notify(Node *p_child) {
  1884. if (is_inside_tree() && wrap_controls) {
  1885. child_controls_changed();
  1886. }
  1887. }
  1888. void Window::remove_child_notify(Node *p_child) {
  1889. if (is_inside_tree() && wrap_controls) {
  1890. child_controls_changed();
  1891. }
  1892. }
  1893. // Theming.
  1894. void Window::set_theme_owner_node(Node *p_node) {
  1895. ERR_MAIN_THREAD_GUARD;
  1896. theme_owner->set_owner_node(p_node);
  1897. }
  1898. Node *Window::get_theme_owner_node() const {
  1899. ERR_READ_THREAD_GUARD_V(nullptr);
  1900. return theme_owner->get_owner_node();
  1901. }
  1902. bool Window::has_theme_owner_node() const {
  1903. ERR_READ_THREAD_GUARD_V(false);
  1904. return theme_owner->has_owner_node();
  1905. }
  1906. void Window::set_theme_context(ThemeContext *p_context, bool p_propagate) {
  1907. ERR_MAIN_THREAD_GUARD;
  1908. theme_owner->set_owner_context(p_context, p_propagate);
  1909. }
  1910. void Window::set_theme(const Ref<Theme> &p_theme) {
  1911. ERR_MAIN_THREAD_GUARD;
  1912. if (theme == p_theme) {
  1913. return;
  1914. }
  1915. if (theme.is_valid()) {
  1916. theme->disconnect_changed(callable_mp(this, &Window::_theme_changed));
  1917. }
  1918. theme = p_theme;
  1919. if (theme.is_valid()) {
  1920. theme_owner->propagate_theme_changed(this, this, is_inside_tree(), true);
  1921. theme->connect_changed(callable_mp(this, &Window::_theme_changed), CONNECT_DEFERRED);
  1922. return;
  1923. }
  1924. Control *parent_c = Object::cast_to<Control>(get_parent());
  1925. if (parent_c && parent_c->has_theme_owner_node()) {
  1926. theme_owner->propagate_theme_changed(this, parent_c->get_theme_owner_node(), is_inside_tree(), true);
  1927. return;
  1928. }
  1929. Window *parent_w = cast_to<Window>(get_parent());
  1930. if (parent_w && parent_w->has_theme_owner_node()) {
  1931. theme_owner->propagate_theme_changed(this, parent_w->get_theme_owner_node(), is_inside_tree(), true);
  1932. return;
  1933. }
  1934. theme_owner->propagate_theme_changed(this, nullptr, is_inside_tree(), true);
  1935. }
  1936. Ref<Theme> Window::get_theme() const {
  1937. ERR_READ_THREAD_GUARD_V(Ref<Theme>());
  1938. return theme;
  1939. }
  1940. void Window::_theme_changed() {
  1941. if (is_inside_tree()) {
  1942. theme_owner->propagate_theme_changed(this, this, true, false);
  1943. }
  1944. }
  1945. void Window::_notify_theme_override_changed() {
  1946. if (!bulk_theme_override && is_inside_tree()) {
  1947. notification(NOTIFICATION_THEME_CHANGED);
  1948. }
  1949. }
  1950. void Window::_invalidate_theme_cache() {
  1951. theme_icon_cache.clear();
  1952. theme_style_cache.clear();
  1953. theme_font_cache.clear();
  1954. theme_font_size_cache.clear();
  1955. theme_color_cache.clear();
  1956. theme_constant_cache.clear();
  1957. }
  1958. void Window::_update_theme_item_cache() {
  1959. // Request an update on the next frame to reflect theme changes.
  1960. // Updating without a delay can cause a lot of lag.
  1961. if (!wrap_controls) {
  1962. updating_embedded_window = true;
  1963. callable_mp(this, &Window::_update_embedded_window).call_deferred();
  1964. } else {
  1965. child_controls_changed();
  1966. }
  1967. ThemeDB::get_singleton()->update_class_instance_items(this);
  1968. }
  1969. void Window::_update_embedded_window() {
  1970. if (!updating_embedded_window) {
  1971. return;
  1972. }
  1973. if (embedder) {
  1974. embedder->_sub_window_update(this);
  1975. };
  1976. updating_embedded_window = false;
  1977. }
  1978. void Window::set_theme_type_variation(const StringName &p_theme_type) {
  1979. ERR_MAIN_THREAD_GUARD;
  1980. theme_type_variation = p_theme_type;
  1981. if (is_inside_tree()) {
  1982. notification(NOTIFICATION_THEME_CHANGED);
  1983. }
  1984. }
  1985. StringName Window::get_theme_type_variation() const {
  1986. ERR_READ_THREAD_GUARD_V(StringName());
  1987. return theme_type_variation;
  1988. }
  1989. /// Theme property lookup.
  1990. Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {
  1991. ERR_READ_THREAD_GUARD_V(Ref<Texture2D>());
  1992. if (!initialized) {
  1993. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  1994. }
  1995. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  1996. const Ref<Texture2D> *tex = theme_icon_override.getptr(p_name);
  1997. if (tex) {
  1998. return *tex;
  1999. }
  2000. }
  2001. if (theme_icon_cache.has(p_theme_type) && theme_icon_cache[p_theme_type].has(p_name)) {
  2002. return theme_icon_cache[p_theme_type][p_name];
  2003. }
  2004. Vector<StringName> theme_types;
  2005. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2006. Ref<Texture2D> icon = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types);
  2007. theme_icon_cache[p_theme_type][p_name] = icon;
  2008. return icon;
  2009. }
  2010. Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
  2011. ERR_READ_THREAD_GUARD_V(Ref<StyleBox>());
  2012. if (!initialized) {
  2013. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  2014. }
  2015. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  2016. const Ref<StyleBox> *style = theme_style_override.getptr(p_name);
  2017. if (style) {
  2018. return *style;
  2019. }
  2020. }
  2021. if (theme_style_cache.has(p_theme_type) && theme_style_cache[p_theme_type].has(p_name)) {
  2022. return theme_style_cache[p_theme_type][p_name];
  2023. }
  2024. Vector<StringName> theme_types;
  2025. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2026. Ref<StyleBox> style = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
  2027. theme_style_cache[p_theme_type][p_name] = style;
  2028. return style;
  2029. }
  2030. Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const {
  2031. ERR_READ_THREAD_GUARD_V(Ref<Font>());
  2032. if (!initialized) {
  2033. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  2034. }
  2035. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  2036. const Ref<Font> *font = theme_font_override.getptr(p_name);
  2037. if (font) {
  2038. return *font;
  2039. }
  2040. }
  2041. if (theme_font_cache.has(p_theme_type) && theme_font_cache[p_theme_type].has(p_name)) {
  2042. return theme_font_cache[p_theme_type][p_name];
  2043. }
  2044. Vector<StringName> theme_types;
  2045. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2046. Ref<Font> font = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types);
  2047. theme_font_cache[p_theme_type][p_name] = font;
  2048. return font;
  2049. }
  2050. int Window::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const {
  2051. ERR_READ_THREAD_GUARD_V(0);
  2052. if (!initialized) {
  2053. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  2054. }
  2055. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  2056. const int *font_size = theme_font_size_override.getptr(p_name);
  2057. if (font_size && (*font_size) > 0) {
  2058. return *font_size;
  2059. }
  2060. }
  2061. if (theme_font_size_cache.has(p_theme_type) && theme_font_size_cache[p_theme_type].has(p_name)) {
  2062. return theme_font_size_cache[p_theme_type][p_name];
  2063. }
  2064. Vector<StringName> theme_types;
  2065. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2066. int font_size = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
  2067. theme_font_size_cache[p_theme_type][p_name] = font_size;
  2068. return font_size;
  2069. }
  2070. Color Window::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const {
  2071. ERR_READ_THREAD_GUARD_V(Color());
  2072. if (!initialized) {
  2073. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  2074. }
  2075. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  2076. const Color *color = theme_color_override.getptr(p_name);
  2077. if (color) {
  2078. return *color;
  2079. }
  2080. }
  2081. if (theme_color_cache.has(p_theme_type) && theme_color_cache[p_theme_type].has(p_name)) {
  2082. return theme_color_cache[p_theme_type][p_name];
  2083. }
  2084. Vector<StringName> theme_types;
  2085. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2086. Color color = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types);
  2087. theme_color_cache[p_theme_type][p_name] = color;
  2088. return color;
  2089. }
  2090. int Window::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const {
  2091. ERR_READ_THREAD_GUARD_V(0);
  2092. if (!initialized) {
  2093. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  2094. }
  2095. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  2096. const int *constant = theme_constant_override.getptr(p_name);
  2097. if (constant) {
  2098. return *constant;
  2099. }
  2100. }
  2101. if (theme_constant_cache.has(p_theme_type) && theme_constant_cache[p_theme_type].has(p_name)) {
  2102. return theme_constant_cache[p_theme_type][p_name];
  2103. }
  2104. Vector<StringName> theme_types;
  2105. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2106. int constant = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
  2107. theme_constant_cache[p_theme_type][p_name] = constant;
  2108. return constant;
  2109. }
  2110. Variant Window::get_theme_item(Theme::DataType p_data_type, const StringName &p_name, const StringName &p_theme_type) const {
  2111. switch (p_data_type) {
  2112. case Theme::DATA_TYPE_COLOR:
  2113. return get_theme_color(p_name, p_theme_type);
  2114. case Theme::DATA_TYPE_CONSTANT:
  2115. return get_theme_constant(p_name, p_theme_type);
  2116. case Theme::DATA_TYPE_FONT:
  2117. return get_theme_font(p_name, p_theme_type);
  2118. case Theme::DATA_TYPE_FONT_SIZE:
  2119. return get_theme_font_size(p_name, p_theme_type);
  2120. case Theme::DATA_TYPE_ICON:
  2121. return get_theme_icon(p_name, p_theme_type);
  2122. case Theme::DATA_TYPE_STYLEBOX:
  2123. return get_theme_stylebox(p_name, p_theme_type);
  2124. case Theme::DATA_TYPE_MAX:
  2125. break; // Can't happen, but silences warning.
  2126. }
  2127. return Variant();
  2128. }
  2129. #ifdef TOOLS_ENABLED
  2130. Ref<Texture2D> Window::get_editor_theme_icon(const StringName &p_name) const {
  2131. return get_theme_icon(p_name, SNAME("EditorIcons"));
  2132. }
  2133. Ref<Texture2D> Window::get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const {
  2134. if (!p_global_menu) {
  2135. return get_theme_icon(p_name, SNAME("EditorIcons"));
  2136. }
  2137. if (p_dark_mode && has_theme_icon(String(p_name) + "Dark", SNAME("EditorIcons"))) {
  2138. return get_theme_icon(String(p_name) + "Dark", SNAME("EditorIcons"));
  2139. } else if (!p_dark_mode && has_theme_icon(String(p_name) + "Light", SNAME("EditorIcons"))) {
  2140. return get_theme_icon(String(p_name) + "Light", SNAME("EditorIcons"));
  2141. }
  2142. return get_theme_icon(p_name, SNAME("EditorIcons"));
  2143. }
  2144. #endif
  2145. bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {
  2146. ERR_READ_THREAD_GUARD_V(false);
  2147. if (!initialized) {
  2148. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  2149. }
  2150. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  2151. if (has_theme_icon_override(p_name)) {
  2152. return true;
  2153. }
  2154. }
  2155. Vector<StringName> theme_types;
  2156. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2157. return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types);
  2158. }
  2159. bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
  2160. ERR_READ_THREAD_GUARD_V(false);
  2161. if (!initialized) {
  2162. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  2163. }
  2164. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  2165. if (has_theme_stylebox_override(p_name)) {
  2166. return true;
  2167. }
  2168. }
  2169. Vector<StringName> theme_types;
  2170. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2171. return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
  2172. }
  2173. bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const {
  2174. ERR_READ_THREAD_GUARD_V(false);
  2175. if (!initialized) {
  2176. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  2177. }
  2178. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  2179. if (has_theme_font_override(p_name)) {
  2180. return true;
  2181. }
  2182. }
  2183. Vector<StringName> theme_types;
  2184. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2185. return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types);
  2186. }
  2187. bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const {
  2188. ERR_READ_THREAD_GUARD_V(false);
  2189. if (!initialized) {
  2190. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  2191. }
  2192. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  2193. if (has_theme_font_size_override(p_name)) {
  2194. return true;
  2195. }
  2196. }
  2197. Vector<StringName> theme_types;
  2198. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2199. return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
  2200. }
  2201. bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const {
  2202. ERR_READ_THREAD_GUARD_V(false);
  2203. if (!initialized) {
  2204. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  2205. }
  2206. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  2207. if (has_theme_color_override(p_name)) {
  2208. return true;
  2209. }
  2210. }
  2211. Vector<StringName> theme_types;
  2212. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2213. return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types);
  2214. }
  2215. bool Window::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const {
  2216. ERR_READ_THREAD_GUARD_V(false);
  2217. if (!initialized) {
  2218. WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description()));
  2219. }
  2220. if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
  2221. if (has_theme_constant_override(p_name)) {
  2222. return true;
  2223. }
  2224. }
  2225. Vector<StringName> theme_types;
  2226. theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
  2227. return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
  2228. }
  2229. /// Local property overrides.
  2230. void Window::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) {
  2231. ERR_MAIN_THREAD_GUARD;
  2232. ERR_FAIL_COND(p_icon.is_null());
  2233. if (theme_icon_override.has(p_name)) {
  2234. theme_icon_override[p_name]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  2235. }
  2236. theme_icon_override[p_name] = p_icon;
  2237. theme_icon_override[p_name]->connect_changed(callable_mp(this, &Window::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED);
  2238. _notify_theme_override_changed();
  2239. }
  2240. void Window::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
  2241. ERR_MAIN_THREAD_GUARD;
  2242. ERR_FAIL_COND(p_style.is_null());
  2243. if (theme_style_override.has(p_name)) {
  2244. theme_style_override[p_name]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  2245. }
  2246. theme_style_override[p_name] = p_style;
  2247. theme_style_override[p_name]->connect_changed(callable_mp(this, &Window::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED);
  2248. _notify_theme_override_changed();
  2249. }
  2250. void Window::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) {
  2251. ERR_MAIN_THREAD_GUARD;
  2252. ERR_FAIL_COND(p_font.is_null());
  2253. if (theme_font_override.has(p_name)) {
  2254. theme_font_override[p_name]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  2255. }
  2256. theme_font_override[p_name] = p_font;
  2257. theme_font_override[p_name]->connect_changed(callable_mp(this, &Window::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED);
  2258. _notify_theme_override_changed();
  2259. }
  2260. void Window::add_theme_font_size_override(const StringName &p_name, int p_font_size) {
  2261. ERR_MAIN_THREAD_GUARD;
  2262. theme_font_size_override[p_name] = p_font_size;
  2263. _notify_theme_override_changed();
  2264. }
  2265. void Window::add_theme_color_override(const StringName &p_name, const Color &p_color) {
  2266. ERR_MAIN_THREAD_GUARD;
  2267. theme_color_override[p_name] = p_color;
  2268. _notify_theme_override_changed();
  2269. }
  2270. void Window::add_theme_constant_override(const StringName &p_name, int p_constant) {
  2271. ERR_MAIN_THREAD_GUARD;
  2272. theme_constant_override[p_name] = p_constant;
  2273. _notify_theme_override_changed();
  2274. }
  2275. void Window::remove_theme_icon_override(const StringName &p_name) {
  2276. ERR_MAIN_THREAD_GUARD;
  2277. if (theme_icon_override.has(p_name)) {
  2278. theme_icon_override[p_name]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  2279. }
  2280. theme_icon_override.erase(p_name);
  2281. _notify_theme_override_changed();
  2282. }
  2283. void Window::remove_theme_style_override(const StringName &p_name) {
  2284. ERR_MAIN_THREAD_GUARD;
  2285. if (theme_style_override.has(p_name)) {
  2286. theme_style_override[p_name]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  2287. }
  2288. theme_style_override.erase(p_name);
  2289. _notify_theme_override_changed();
  2290. }
  2291. void Window::remove_theme_font_override(const StringName &p_name) {
  2292. ERR_MAIN_THREAD_GUARD;
  2293. if (theme_font_override.has(p_name)) {
  2294. theme_font_override[p_name]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  2295. }
  2296. theme_font_override.erase(p_name);
  2297. _notify_theme_override_changed();
  2298. }
  2299. void Window::remove_theme_font_size_override(const StringName &p_name) {
  2300. ERR_MAIN_THREAD_GUARD;
  2301. theme_font_size_override.erase(p_name);
  2302. _notify_theme_override_changed();
  2303. }
  2304. void Window::remove_theme_color_override(const StringName &p_name) {
  2305. ERR_MAIN_THREAD_GUARD;
  2306. theme_color_override.erase(p_name);
  2307. _notify_theme_override_changed();
  2308. }
  2309. void Window::remove_theme_constant_override(const StringName &p_name) {
  2310. ERR_MAIN_THREAD_GUARD;
  2311. theme_constant_override.erase(p_name);
  2312. _notify_theme_override_changed();
  2313. }
  2314. bool Window::has_theme_icon_override(const StringName &p_name) const {
  2315. ERR_READ_THREAD_GUARD_V(false);
  2316. const Ref<Texture2D> *tex = theme_icon_override.getptr(p_name);
  2317. return tex != nullptr;
  2318. }
  2319. bool Window::has_theme_stylebox_override(const StringName &p_name) const {
  2320. ERR_READ_THREAD_GUARD_V(false);
  2321. const Ref<StyleBox> *style = theme_style_override.getptr(p_name);
  2322. return style != nullptr;
  2323. }
  2324. bool Window::has_theme_font_override(const StringName &p_name) const {
  2325. ERR_READ_THREAD_GUARD_V(false);
  2326. const Ref<Font> *font = theme_font_override.getptr(p_name);
  2327. return font != nullptr;
  2328. }
  2329. bool Window::has_theme_font_size_override(const StringName &p_name) const {
  2330. ERR_READ_THREAD_GUARD_V(false);
  2331. const int *font_size = theme_font_size_override.getptr(p_name);
  2332. return font_size != nullptr;
  2333. }
  2334. bool Window::has_theme_color_override(const StringName &p_name) const {
  2335. ERR_READ_THREAD_GUARD_V(false);
  2336. const Color *color = theme_color_override.getptr(p_name);
  2337. return color != nullptr;
  2338. }
  2339. bool Window::has_theme_constant_override(const StringName &p_name) const {
  2340. ERR_READ_THREAD_GUARD_V(false);
  2341. const int *constant = theme_constant_override.getptr(p_name);
  2342. return constant != nullptr;
  2343. }
  2344. /// Default theme properties.
  2345. float Window::get_theme_default_base_scale() const {
  2346. ERR_READ_THREAD_GUARD_V(0);
  2347. return theme_owner->get_theme_default_base_scale();
  2348. }
  2349. Ref<Font> Window::get_theme_default_font() const {
  2350. ERR_READ_THREAD_GUARD_V(Ref<Font>());
  2351. return theme_owner->get_theme_default_font();
  2352. }
  2353. int Window::get_theme_default_font_size() const {
  2354. ERR_READ_THREAD_GUARD_V(0);
  2355. return theme_owner->get_theme_default_font_size();
  2356. }
  2357. /// Bulk actions.
  2358. void Window::begin_bulk_theme_override() {
  2359. ERR_MAIN_THREAD_GUARD;
  2360. bulk_theme_override = true;
  2361. }
  2362. void Window::end_bulk_theme_override() {
  2363. ERR_MAIN_THREAD_GUARD;
  2364. ERR_FAIL_COND(!bulk_theme_override);
  2365. bulk_theme_override = false;
  2366. _notify_theme_override_changed();
  2367. }
  2368. //
  2369. Rect2i Window::get_parent_rect() const {
  2370. ERR_READ_THREAD_GUARD_V(Rect2i());
  2371. ERR_FAIL_COND_V(!is_inside_tree(), Rect2i());
  2372. if (is_embedded()) {
  2373. //viewport
  2374. Node *n = get_parent();
  2375. ERR_FAIL_NULL_V(n, Rect2i());
  2376. Viewport *p = n->get_viewport();
  2377. ERR_FAIL_NULL_V(p, Rect2i());
  2378. return p->get_visible_rect();
  2379. } else {
  2380. int x = get_position().x;
  2381. int closest_dist = 0x7FFFFFFF;
  2382. Rect2i closest_rect;
  2383. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  2384. Rect2i s(DisplayServer::get_singleton()->screen_get_position(i), DisplayServer::get_singleton()->screen_get_size(i));
  2385. int d;
  2386. if (x >= s.position.x && x < s.size.x) {
  2387. //contained
  2388. closest_rect = s;
  2389. break;
  2390. } else if (x < s.position.x) {
  2391. d = s.position.x - x;
  2392. } else {
  2393. d = x - (s.position.x + s.size.x);
  2394. }
  2395. if (d < closest_dist) {
  2396. closest_dist = d;
  2397. closest_rect = s;
  2398. }
  2399. }
  2400. return closest_rect;
  2401. }
  2402. }
  2403. void Window::set_clamp_to_embedder(bool p_enable) {
  2404. ERR_MAIN_THREAD_GUARD;
  2405. clamp_to_embedder = p_enable;
  2406. }
  2407. bool Window::is_clamped_to_embedder() const {
  2408. ERR_READ_THREAD_GUARD_V(false);
  2409. return clamp_to_embedder;
  2410. }
  2411. void Window::set_unparent_when_invisible(bool p_unparent) {
  2412. unparent_when_invisible = p_unparent;
  2413. }
  2414. void Window::set_layout_direction(Window::LayoutDirection p_direction) {
  2415. ERR_MAIN_THREAD_GUARD;
  2416. ERR_FAIL_INDEX(p_direction, LAYOUT_DIRECTION_MAX);
  2417. layout_dir = p_direction;
  2418. propagate_notification(Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED);
  2419. }
  2420. Window::LayoutDirection Window::get_layout_direction() const {
  2421. ERR_READ_THREAD_GUARD_V(LAYOUT_DIRECTION_INHERITED);
  2422. return layout_dir;
  2423. }
  2424. bool Window::is_layout_rtl() const {
  2425. ERR_READ_THREAD_GUARD_V(false);
  2426. if (layout_dir == LAYOUT_DIRECTION_INHERITED) {
  2427. #ifdef TOOLS_ENABLED
  2428. if (is_part_of_edited_scene() && GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) {
  2429. return true;
  2430. }
  2431. if (is_inside_tree()) {
  2432. Node *edited_scene_root = get_tree()->get_edited_scene_root();
  2433. if (edited_scene_root == this) {
  2434. int proj_root_layout_direction = GLOBAL_GET_CACHED(int, "internationalization/rendering/root_node_layout_direction");
  2435. if (proj_root_layout_direction == 1) {
  2436. return false;
  2437. } else if (proj_root_layout_direction == 2) {
  2438. return true;
  2439. } else if (proj_root_layout_direction == 3) {
  2440. String locale = OS::get_singleton()->get_locale();
  2441. return TS->is_locale_right_to_left(locale);
  2442. } else {
  2443. const Ref<Translation> &t = TranslationServer::get_singleton()->get_translation_object(TranslationServer::get_singleton()->get_locale());
  2444. String locale = t.is_valid() ? t->get_locale() : TranslationServer::get_singleton()->get_fallback_locale();
  2445. return TS->is_locale_right_to_left(locale);
  2446. }
  2447. }
  2448. }
  2449. #else
  2450. if (GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) {
  2451. return true;
  2452. }
  2453. #endif
  2454. Node *parent_node = get_parent();
  2455. while (parent_node) {
  2456. Control *parent_control = Object::cast_to<Control>(parent_node);
  2457. if (parent_control) {
  2458. return parent_control->is_layout_rtl();
  2459. }
  2460. Window *parent_window = Object::cast_to<Window>(parent_node);
  2461. if (parent_window) {
  2462. return parent_window->is_layout_rtl();
  2463. }
  2464. parent_node = parent_node->get_parent();
  2465. }
  2466. if (root_layout_direction == 1) {
  2467. return false;
  2468. } else if (root_layout_direction == 2) {
  2469. return true;
  2470. } else if (root_layout_direction == 3) {
  2471. String locale = OS::get_singleton()->get_locale();
  2472. return TS->is_locale_right_to_left(locale);
  2473. } else {
  2474. String locale = TranslationServer::get_singleton()->get_tool_locale();
  2475. return TS->is_locale_right_to_left(locale);
  2476. }
  2477. } else if (layout_dir == LAYOUT_DIRECTION_APPLICATION_LOCALE) {
  2478. if (GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) {
  2479. return true;
  2480. } else {
  2481. String locale = TranslationServer::get_singleton()->get_tool_locale();
  2482. return TS->is_locale_right_to_left(locale);
  2483. }
  2484. } else if (layout_dir == LAYOUT_DIRECTION_SYSTEM_LOCALE) {
  2485. if (GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) {
  2486. return true;
  2487. } else {
  2488. String locale = OS::get_singleton()->get_locale();
  2489. return TS->is_locale_right_to_left(locale);
  2490. }
  2491. } else {
  2492. return (layout_dir == LAYOUT_DIRECTION_RTL);
  2493. }
  2494. }
  2495. #ifndef DISABLE_DEPRECATED
  2496. void Window::set_use_font_oversampling(bool p_oversampling) {
  2497. Viewport::set_use_oversampling(p_oversampling);
  2498. }
  2499. bool Window::is_using_font_oversampling() const {
  2500. return Viewport::is_using_oversampling();
  2501. }
  2502. void Window::set_auto_translate(bool p_enable) {
  2503. ERR_MAIN_THREAD_GUARD;
  2504. set_auto_translate_mode(p_enable ? AUTO_TRANSLATE_MODE_ALWAYS : AUTO_TRANSLATE_MODE_DISABLED);
  2505. }
  2506. bool Window::is_auto_translating() const {
  2507. ERR_READ_THREAD_GUARD_V(false);
  2508. return can_auto_translate();
  2509. }
  2510. #endif
  2511. Transform2D Window::get_final_transform() const {
  2512. ERR_READ_THREAD_GUARD_V(Transform2D());
  2513. return window_transform * stretch_transform * global_canvas_transform;
  2514. }
  2515. Transform2D Window::get_screen_transform_internal(bool p_absolute_position) const {
  2516. ERR_READ_THREAD_GUARD_V(Transform2D());
  2517. Transform2D embedder_transform;
  2518. if (get_embedder()) {
  2519. embedder_transform.translate_local(get_position());
  2520. embedder_transform = get_embedder()->get_screen_transform_internal(p_absolute_position) * embedder_transform;
  2521. } else if (p_absolute_position) {
  2522. embedder_transform.translate_local(get_position());
  2523. }
  2524. return embedder_transform * get_final_transform();
  2525. }
  2526. Transform2D Window::get_popup_base_transform_native() const {
  2527. ERR_READ_THREAD_GUARD_V(Transform2D());
  2528. if (!DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SUBWINDOWS)) {
  2529. return Transform2D();
  2530. }
  2531. Transform2D popup_base_transform;
  2532. popup_base_transform.set_origin(get_position());
  2533. popup_base_transform *= get_final_transform();
  2534. if (get_embedder()) {
  2535. return get_embedder()->get_popup_base_transform_native() * popup_base_transform;
  2536. }
  2537. return popup_base_transform;
  2538. }
  2539. Transform2D Window::get_popup_base_transform() const {
  2540. ERR_READ_THREAD_GUARD_V(Transform2D());
  2541. if (is_embedding_subwindows()) {
  2542. return Transform2D();
  2543. }
  2544. Transform2D popup_base_transform;
  2545. popup_base_transform.set_origin(get_position());
  2546. popup_base_transform *= get_final_transform();
  2547. if (get_embedder()) {
  2548. return get_embedder()->get_popup_base_transform() * popup_base_transform;
  2549. }
  2550. return popup_base_transform;
  2551. }
  2552. Viewport *Window::get_section_root_viewport() const {
  2553. if (get_embedder()) {
  2554. return get_embedder()->get_section_root_viewport();
  2555. }
  2556. if (is_inside_tree()) {
  2557. // Native window.
  2558. return SceneTree::get_singleton()->get_root();
  2559. }
  2560. Window *vp = const_cast<Window *>(this);
  2561. return vp;
  2562. }
  2563. bool Window::is_attached_in_viewport() const {
  2564. return get_embedder();
  2565. }
  2566. void Window::_update_mouse_over(Vector2 p_pos) {
  2567. if (!mouse_in_window) {
  2568. if (is_embedded()) {
  2569. mouse_in_window = true;
  2570. _propagate_window_notification(this, NOTIFICATION_WM_MOUSE_ENTER);
  2571. }
  2572. }
  2573. bool new_in = get_visible_rect().has_point(p_pos);
  2574. if (new_in == gui.mouse_in_viewport) {
  2575. if (new_in) {
  2576. Viewport::_update_mouse_over(p_pos);
  2577. }
  2578. return;
  2579. }
  2580. if (new_in) {
  2581. notification(NOTIFICATION_VP_MOUSE_ENTER);
  2582. Viewport::_update_mouse_over(p_pos);
  2583. } else {
  2584. Viewport::_mouse_leave_viewport();
  2585. }
  2586. }
  2587. void Window::_mouse_leave_viewport() {
  2588. Viewport::_mouse_leave_viewport();
  2589. if (is_embedded()) {
  2590. mouse_in_window = false;
  2591. _propagate_window_notification(this, NOTIFICATION_WM_MOUSE_EXIT);
  2592. }
  2593. }
  2594. void Window::_update_displayed_title() {
  2595. displayed_title = atr(title);
  2596. #ifdef DEBUG_ENABLED
  2597. if (window_id == DisplayServer::MAIN_WINDOW_ID && !Engine::get_singleton()->is_project_manager_hint()) {
  2598. // Append a suffix to the window title to denote that the project is running
  2599. // from a debug build (including the editor, excluding the project manager).
  2600. // Since this results in lower performance, this should be clearly presented
  2601. // to the user.
  2602. displayed_title = vformat("%s (DEBUG)", displayed_title);
  2603. }
  2604. #endif
  2605. if (embedder) {
  2606. embedder->_sub_window_update(this);
  2607. } else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
  2608. DisplayServer::get_singleton()->window_set_title(displayed_title, window_id);
  2609. if (keep_title_visible) {
  2610. Size2i title_size = DisplayServer::get_singleton()->window_get_title_size(displayed_title, window_id);
  2611. Size2i size_limit = get_clamped_minimum_size();
  2612. if (title_size.x > size_limit.x || title_size.y > size_limit.y) {
  2613. _update_window_size();
  2614. }
  2615. }
  2616. }
  2617. #ifdef DEBUG_ENABLED
  2618. if (EngineDebugger::get_singleton() && window_id == DisplayServer::MAIN_WINDOW_ID && !Engine::get_singleton()->is_project_manager_hint()) {
  2619. Array arr = { displayed_title };
  2620. EngineDebugger::get_singleton()->send_message("window:title", arr);
  2621. }
  2622. #endif
  2623. queue_accessibility_update();
  2624. }
  2625. void Window::_bind_methods() {
  2626. ClassDB::bind_method(D_METHOD("set_title", "title"), &Window::set_title);
  2627. ClassDB::bind_method(D_METHOD("get_title"), &Window::get_title);
  2628. ClassDB::bind_method(D_METHOD("set_initial_position", "initial_position"), &Window::set_initial_position);
  2629. ClassDB::bind_method(D_METHOD("get_initial_position"), &Window::get_initial_position);
  2630. ClassDB::bind_method(D_METHOD("set_current_screen", "index"), &Window::set_current_screen);
  2631. ClassDB::bind_method(D_METHOD("get_current_screen"), &Window::get_current_screen);
  2632. ClassDB::bind_method(D_METHOD("set_position", "position"), &Window::set_position);
  2633. ClassDB::bind_method(D_METHOD("get_position"), &Window::get_position);
  2634. ClassDB::bind_method(D_METHOD("move_to_center"), &Window::move_to_center);
  2635. ClassDB::bind_method(D_METHOD("set_size", "size"), &Window::set_size);
  2636. ClassDB::bind_method(D_METHOD("get_size"), &Window::get_size);
  2637. ClassDB::bind_method(D_METHOD("reset_size"), &Window::reset_size);
  2638. ClassDB::bind_method(D_METHOD("get_position_with_decorations"), &Window::get_position_with_decorations);
  2639. ClassDB::bind_method(D_METHOD("get_size_with_decorations"), &Window::get_size_with_decorations);
  2640. ClassDB::bind_method(D_METHOD("set_max_size", "max_size"), &Window::set_max_size);
  2641. ClassDB::bind_method(D_METHOD("get_max_size"), &Window::get_max_size);
  2642. ClassDB::bind_method(D_METHOD("set_min_size", "min_size"), &Window::set_min_size);
  2643. ClassDB::bind_method(D_METHOD("get_min_size"), &Window::get_min_size);
  2644. ClassDB::bind_method(D_METHOD("set_mode", "mode"), &Window::set_mode);
  2645. ClassDB::bind_method(D_METHOD("get_mode"), &Window::get_mode);
  2646. ClassDB::bind_method(D_METHOD("set_flag", "flag", "enabled"), &Window::set_flag);
  2647. ClassDB::bind_method(D_METHOD("get_flag", "flag"), &Window::get_flag);
  2648. ClassDB::bind_method(D_METHOD("is_maximize_allowed"), &Window::is_maximize_allowed);
  2649. ClassDB::bind_method(D_METHOD("request_attention"), &Window::request_attention);
  2650. #ifndef DISABLE_DEPRECATED
  2651. ClassDB::bind_method(D_METHOD("move_to_foreground"), &Window::move_to_foreground);
  2652. #endif // DISABLE_DEPRECATED
  2653. ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Window::set_visible);
  2654. ClassDB::bind_method(D_METHOD("is_visible"), &Window::is_visible);
  2655. ClassDB::bind_method(D_METHOD("hide"), &Window::hide);
  2656. ClassDB::bind_method(D_METHOD("show"), &Window::show);
  2657. ClassDB::bind_method(D_METHOD("set_transient", "transient"), &Window::set_transient);
  2658. ClassDB::bind_method(D_METHOD("is_transient"), &Window::is_transient);
  2659. ClassDB::bind_method(D_METHOD("set_transient_to_focused", "enable"), &Window::set_transient_to_focused);
  2660. ClassDB::bind_method(D_METHOD("is_transient_to_focused"), &Window::is_transient_to_focused);
  2661. ClassDB::bind_method(D_METHOD("set_exclusive", "exclusive"), &Window::set_exclusive);
  2662. ClassDB::bind_method(D_METHOD("is_exclusive"), &Window::is_exclusive);
  2663. ClassDB::bind_method(D_METHOD("set_unparent_when_invisible", "unparent"), &Window::set_unparent_when_invisible);
  2664. ClassDB::bind_method(D_METHOD("can_draw"), &Window::can_draw);
  2665. ClassDB::bind_method(D_METHOD("has_focus"), &Window::has_focus);
  2666. ClassDB::bind_method(D_METHOD("grab_focus"), &Window::grab_focus);
  2667. ClassDB::bind_method(D_METHOD("start_drag"), &Window::start_drag);
  2668. ClassDB::bind_method(D_METHOD("start_resize", "edge"), &Window::start_resize);
  2669. ClassDB::bind_method(D_METHOD("set_ime_active", "active"), &Window::set_ime_active);
  2670. ClassDB::bind_method(D_METHOD("set_ime_position", "position"), &Window::set_ime_position);
  2671. ClassDB::bind_method(D_METHOD("is_embedded"), &Window::is_embedded);
  2672. ClassDB::bind_method(D_METHOD("get_contents_minimum_size"), &Window::get_contents_minimum_size);
  2673. ClassDB::bind_method(D_METHOD("set_force_native", "force_native"), &Window::set_force_native);
  2674. ClassDB::bind_method(D_METHOD("get_force_native"), &Window::get_force_native);
  2675. ClassDB::bind_method(D_METHOD("set_content_scale_size", "size"), &Window::set_content_scale_size);
  2676. ClassDB::bind_method(D_METHOD("get_content_scale_size"), &Window::get_content_scale_size);
  2677. ClassDB::bind_method(D_METHOD("set_content_scale_mode", "mode"), &Window::set_content_scale_mode);
  2678. ClassDB::bind_method(D_METHOD("get_content_scale_mode"), &Window::get_content_scale_mode);
  2679. ClassDB::bind_method(D_METHOD("set_content_scale_aspect", "aspect"), &Window::set_content_scale_aspect);
  2680. ClassDB::bind_method(D_METHOD("get_content_scale_aspect"), &Window::get_content_scale_aspect);
  2681. ClassDB::bind_method(D_METHOD("set_content_scale_stretch", "stretch"), &Window::set_content_scale_stretch);
  2682. ClassDB::bind_method(D_METHOD("get_content_scale_stretch"), &Window::get_content_scale_stretch);
  2683. ClassDB::bind_method(D_METHOD("set_keep_title_visible", "title_visible"), &Window::set_keep_title_visible);
  2684. ClassDB::bind_method(D_METHOD("get_keep_title_visible"), &Window::get_keep_title_visible);
  2685. ClassDB::bind_method(D_METHOD("set_content_scale_factor", "factor"), &Window::set_content_scale_factor);
  2686. ClassDB::bind_method(D_METHOD("get_content_scale_factor"), &Window::get_content_scale_factor);
  2687. ClassDB::bind_method(D_METHOD("set_mouse_passthrough_polygon", "polygon"), &Window::set_mouse_passthrough_polygon);
  2688. ClassDB::bind_method(D_METHOD("get_mouse_passthrough_polygon"), &Window::get_mouse_passthrough_polygon);
  2689. ClassDB::bind_method(D_METHOD("set_wrap_controls", "enable"), &Window::set_wrap_controls);
  2690. ClassDB::bind_method(D_METHOD("is_wrapping_controls"), &Window::is_wrapping_controls);
  2691. ClassDB::bind_method(D_METHOD("child_controls_changed"), &Window::child_controls_changed);
  2692. ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Window::set_theme);
  2693. ClassDB::bind_method(D_METHOD("get_theme"), &Window::get_theme);
  2694. ClassDB::bind_method(D_METHOD("set_theme_type_variation", "theme_type"), &Window::set_theme_type_variation);
  2695. ClassDB::bind_method(D_METHOD("get_theme_type_variation"), &Window::get_theme_type_variation);
  2696. ClassDB::bind_method(D_METHOD("begin_bulk_theme_override"), &Window::begin_bulk_theme_override);
  2697. ClassDB::bind_method(D_METHOD("end_bulk_theme_override"), &Window::end_bulk_theme_override);
  2698. ClassDB::bind_method(D_METHOD("add_theme_icon_override", "name", "texture"), &Window::add_theme_icon_override);
  2699. ClassDB::bind_method(D_METHOD("add_theme_stylebox_override", "name", "stylebox"), &Window::add_theme_style_override);
  2700. ClassDB::bind_method(D_METHOD("add_theme_font_override", "name", "font"), &Window::add_theme_font_override);
  2701. ClassDB::bind_method(D_METHOD("add_theme_font_size_override", "name", "font_size"), &Window::add_theme_font_size_override);
  2702. ClassDB::bind_method(D_METHOD("add_theme_color_override", "name", "color"), &Window::add_theme_color_override);
  2703. ClassDB::bind_method(D_METHOD("add_theme_constant_override", "name", "constant"), &Window::add_theme_constant_override);
  2704. ClassDB::bind_method(D_METHOD("remove_theme_icon_override", "name"), &Window::remove_theme_icon_override);
  2705. ClassDB::bind_method(D_METHOD("remove_theme_stylebox_override", "name"), &Window::remove_theme_style_override);
  2706. ClassDB::bind_method(D_METHOD("remove_theme_font_override", "name"), &Window::remove_theme_font_override);
  2707. ClassDB::bind_method(D_METHOD("remove_theme_font_size_override", "name"), &Window::remove_theme_font_size_override);
  2708. ClassDB::bind_method(D_METHOD("remove_theme_color_override", "name"), &Window::remove_theme_color_override);
  2709. ClassDB::bind_method(D_METHOD("remove_theme_constant_override", "name"), &Window::remove_theme_constant_override);
  2710. ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "theme_type"), &Window::get_theme_icon, DEFVAL(StringName()));
  2711. ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "theme_type"), &Window::get_theme_stylebox, DEFVAL(StringName()));
  2712. ClassDB::bind_method(D_METHOD("get_theme_font", "name", "theme_type"), &Window::get_theme_font, DEFVAL(StringName()));
  2713. ClassDB::bind_method(D_METHOD("get_theme_font_size", "name", "theme_type"), &Window::get_theme_font_size, DEFVAL(StringName()));
  2714. ClassDB::bind_method(D_METHOD("get_theme_color", "name", "theme_type"), &Window::get_theme_color, DEFVAL(StringName()));
  2715. ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "theme_type"), &Window::get_theme_constant, DEFVAL(StringName()));
  2716. ClassDB::bind_method(D_METHOD("has_theme_icon_override", "name"), &Window::has_theme_icon_override);
  2717. ClassDB::bind_method(D_METHOD("has_theme_stylebox_override", "name"), &Window::has_theme_stylebox_override);
  2718. ClassDB::bind_method(D_METHOD("has_theme_font_override", "name"), &Window::has_theme_font_override);
  2719. ClassDB::bind_method(D_METHOD("has_theme_font_size_override", "name"), &Window::has_theme_font_size_override);
  2720. ClassDB::bind_method(D_METHOD("has_theme_color_override", "name"), &Window::has_theme_color_override);
  2721. ClassDB::bind_method(D_METHOD("has_theme_constant_override", "name"), &Window::has_theme_constant_override);
  2722. ClassDB::bind_method(D_METHOD("has_theme_icon", "name", "theme_type"), &Window::has_theme_icon, DEFVAL(StringName()));
  2723. ClassDB::bind_method(D_METHOD("has_theme_stylebox", "name", "theme_type"), &Window::has_theme_stylebox, DEFVAL(StringName()));
  2724. ClassDB::bind_method(D_METHOD("has_theme_font", "name", "theme_type"), &Window::has_theme_font, DEFVAL(StringName()));
  2725. ClassDB::bind_method(D_METHOD("has_theme_font_size", "name", "theme_type"), &Window::has_theme_font_size, DEFVAL(StringName()));
  2726. ClassDB::bind_method(D_METHOD("has_theme_color", "name", "theme_type"), &Window::has_theme_color, DEFVAL(StringName()));
  2727. ClassDB::bind_method(D_METHOD("has_theme_constant", "name", "theme_type"), &Window::has_theme_constant, DEFVAL(StringName()));
  2728. ClassDB::bind_method(D_METHOD("get_theme_default_base_scale"), &Window::get_theme_default_base_scale);
  2729. ClassDB::bind_method(D_METHOD("get_theme_default_font"), &Window::get_theme_default_font);
  2730. ClassDB::bind_method(D_METHOD("get_theme_default_font_size"), &Window::get_theme_default_font_size);
  2731. ClassDB::bind_method(D_METHOD("get_window_id"), &Window::get_window_id);
  2732. ClassDB::bind_method(D_METHOD("set_accessibility_name", "name"), &Window::set_accessibility_name);
  2733. ClassDB::bind_method(D_METHOD("get_accessibility_name"), &Window::get_accessibility_name);
  2734. ClassDB::bind_method(D_METHOD("set_accessibility_description", "description"), &Window::set_accessibility_description);
  2735. ClassDB::bind_method(D_METHOD("get_accessibility_description"), &Window::get_accessibility_description);
  2736. ClassDB::bind_static_method("Window", D_METHOD("get_focused_window"), &Window::get_focused_window);
  2737. ClassDB::bind_method(D_METHOD("set_layout_direction", "direction"), &Window::set_layout_direction);
  2738. ClassDB::bind_method(D_METHOD("get_layout_direction"), &Window::get_layout_direction);
  2739. ClassDB::bind_method(D_METHOD("is_layout_rtl"), &Window::is_layout_rtl);
  2740. #ifndef DISABLE_DEPRECATED
  2741. ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Window::set_auto_translate);
  2742. ClassDB::bind_method(D_METHOD("is_auto_translating"), &Window::is_auto_translating);
  2743. ClassDB::bind_method(D_METHOD("set_use_font_oversampling", "enable"), &Window::set_use_font_oversampling);
  2744. ClassDB::bind_method(D_METHOD("is_using_font_oversampling"), &Window::is_using_font_oversampling);
  2745. #endif
  2746. ClassDB::bind_method(D_METHOD("popup", "rect"), &Window::popup, DEFVAL(Rect2i()));
  2747. ClassDB::bind_method(D_METHOD("popup_on_parent", "parent_rect"), &Window::popup_on_parent);
  2748. ClassDB::bind_method(D_METHOD("popup_centered", "minsize"), &Window::popup_centered, DEFVAL(Size2i()));
  2749. ClassDB::bind_method(D_METHOD("popup_centered_ratio", "ratio"), &Window::popup_centered_ratio, DEFVAL(0.8));
  2750. ClassDB::bind_method(D_METHOD("popup_centered_clamped", "minsize", "fallback_ratio"), &Window::popup_centered_clamped, DEFVAL(Size2i()), DEFVAL(0.75));
  2751. ClassDB::bind_method(D_METHOD("popup_exclusive", "from_node", "rect"), &Window::popup_exclusive, DEFVAL(Rect2i()));
  2752. ClassDB::bind_method(D_METHOD("popup_exclusive_on_parent", "from_node", "parent_rect"), &Window::popup_exclusive_on_parent);
  2753. ClassDB::bind_method(D_METHOD("popup_exclusive_centered", "from_node", "minsize"), &Window::popup_exclusive_centered, DEFVAL(Size2i()));
  2754. ClassDB::bind_method(D_METHOD("popup_exclusive_centered_ratio", "from_node", "ratio"), &Window::popup_exclusive_centered_ratio, DEFVAL(0.8));
  2755. ClassDB::bind_method(D_METHOD("popup_exclusive_centered_clamped", "from_node", "minsize", "fallback_ratio"), &Window::popup_exclusive_centered_clamped, DEFVAL(Size2i()), DEFVAL(0.75));
  2756. // Keep the enum values in sync with the `Mode` enum.
  2757. ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen,Exclusive Fullscreen"), "set_mode", "get_mode");
  2758. ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
  2759. // Keep the enum values in sync with the `WindowInitialPosition` enum.
  2760. ADD_PROPERTY(PropertyInfo(Variant::INT, "initial_position", PROPERTY_HINT_ENUM, "Absolute,Center of Primary Screen,Center of Main Window Screen,Center of Other Screen,Center of Screen With Mouse Pointer,Center of Screen With Keyboard Focus"), "set_initial_position", "get_initial_position");
  2761. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "position", PROPERTY_HINT_NONE, "suffix:px"), "set_position", "get_position");
  2762. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "size", PROPERTY_HINT_NONE, "suffix:px"), "set_size", "get_size");
  2763. ADD_PROPERTY(PropertyInfo(Variant::INT, "current_screen", PROPERTY_HINT_RANGE, "0,64,1,or_greater"), "set_current_screen", "get_current_screen");
  2764. ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "mouse_passthrough_polygon"), "set_mouse_passthrough_polygon", "get_mouse_passthrough_polygon");
  2765. ADD_GROUP("Flags", "");
  2766. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
  2767. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "wrap_controls"), "set_wrap_controls", "is_wrapping_controls");
  2768. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transient"), "set_transient", "is_transient");
  2769. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transient_to_focused"), "set_transient_to_focused", "is_transient_to_focused");
  2770. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclusive"), "set_exclusive", "is_exclusive");
  2771. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "unresizable"), "set_flag", "get_flag", FLAG_RESIZE_DISABLED);
  2772. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "borderless"), "set_flag", "get_flag", FLAG_BORDERLESS);
  2773. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "always_on_top"), "set_flag", "get_flag", FLAG_ALWAYS_ON_TOP);
  2774. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "transparent"), "set_flag", "get_flag", FLAG_TRANSPARENT);
  2775. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "unfocusable"), "set_flag", "get_flag", FLAG_NO_FOCUS);
  2776. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "popup_window"), "set_flag", "get_flag", FLAG_POPUP);
  2777. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "extend_to_title"), "set_flag", "get_flag", FLAG_EXTEND_TO_TITLE);
  2778. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "mouse_passthrough"), "set_flag", "get_flag", FLAG_MOUSE_PASSTHROUGH);
  2779. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "sharp_corners"), "set_flag", "get_flag", FLAG_SHARP_CORNERS);
  2780. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "exclude_from_capture"), "set_flag", "get_flag", FLAG_EXCLUDE_FROM_CAPTURE);
  2781. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "popup_wm_hint"), "set_flag", "get_flag", FLAG_POPUP_WM_HINT);
  2782. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "minimize_disabled"), "set_flag", "get_flag", FLAG_MINIMIZE_DISABLED);
  2783. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "maximize_disabled"), "set_flag", "get_flag", FLAG_MAXIMIZE_DISABLED);
  2784. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "force_native"), "set_force_native", "get_force_native");
  2785. ADD_GROUP("Limits", "");
  2786. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "min_size", PROPERTY_HINT_NONE, "suffix:px"), "set_min_size", "get_min_size");
  2787. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "max_size", PROPERTY_HINT_NONE, "suffix:px"), "set_max_size", "get_max_size");
  2788. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_title_visible"), "set_keep_title_visible", "get_keep_title_visible");
  2789. ADD_GROUP("Content Scale", "content_scale_");
  2790. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "content_scale_size"), "set_content_scale_size", "get_content_scale_size");
  2791. ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_mode", PROPERTY_HINT_ENUM, "Disabled,Canvas Items,Viewport"), "set_content_scale_mode", "get_content_scale_mode");
  2792. ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_aspect", PROPERTY_HINT_ENUM, "Ignore,Keep,Keep Width,Keep Height,Expand"), "set_content_scale_aspect", "get_content_scale_aspect");
  2793. ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_stretch", PROPERTY_HINT_ENUM, "Fractional,Integer"), "set_content_scale_stretch", "get_content_scale_stretch");
  2794. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "content_scale_factor", PROPERTY_HINT_RANGE, "0.5,8.0,0.01"), "set_content_scale_factor", "get_content_scale_factor");
  2795. #ifndef DISABLE_DEPRECATED
  2796. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_auto_translate", "is_auto_translating");
  2797. #endif
  2798. ADD_GROUP("Accessibility", "accessibility_");
  2799. ADD_PROPERTY(PropertyInfo(Variant::STRING, "accessibility_name"), "set_accessibility_name", "get_accessibility_name");
  2800. ADD_PROPERTY(PropertyInfo(Variant::STRING, "accessibility_description"), "set_accessibility_description", "get_accessibility_description");
  2801. ADD_GROUP("Theme", "theme_");
  2802. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
  2803. ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation");
  2804. ADD_SIGNAL(MethodInfo("window_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
  2805. ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files")));
  2806. ADD_SIGNAL(MethodInfo("mouse_entered"));
  2807. ADD_SIGNAL(MethodInfo("mouse_exited"));
  2808. ADD_SIGNAL(MethodInfo("focus_entered"));
  2809. ADD_SIGNAL(MethodInfo("focus_exited"));
  2810. ADD_SIGNAL(MethodInfo("close_requested"));
  2811. ADD_SIGNAL(MethodInfo("go_back_requested"));
  2812. ADD_SIGNAL(MethodInfo("visibility_changed"));
  2813. ADD_SIGNAL(MethodInfo("about_to_popup"));
  2814. ADD_SIGNAL(MethodInfo("theme_changed"));
  2815. ADD_SIGNAL(MethodInfo("dpi_changed"));
  2816. ADD_SIGNAL(MethodInfo("titlebar_changed"));
  2817. ADD_SIGNAL(MethodInfo("title_changed"));
  2818. BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
  2819. BIND_CONSTANT(NOTIFICATION_THEME_CHANGED);
  2820. BIND_ENUM_CONSTANT(MODE_WINDOWED);
  2821. BIND_ENUM_CONSTANT(MODE_MINIMIZED);
  2822. BIND_ENUM_CONSTANT(MODE_MAXIMIZED);
  2823. BIND_ENUM_CONSTANT(MODE_FULLSCREEN);
  2824. BIND_ENUM_CONSTANT(MODE_EXCLUSIVE_FULLSCREEN);
  2825. BIND_ENUM_CONSTANT(FLAG_RESIZE_DISABLED);
  2826. BIND_ENUM_CONSTANT(FLAG_BORDERLESS);
  2827. BIND_ENUM_CONSTANT(FLAG_ALWAYS_ON_TOP);
  2828. BIND_ENUM_CONSTANT(FLAG_TRANSPARENT);
  2829. BIND_ENUM_CONSTANT(FLAG_NO_FOCUS);
  2830. BIND_ENUM_CONSTANT(FLAG_POPUP);
  2831. BIND_ENUM_CONSTANT(FLAG_EXTEND_TO_TITLE);
  2832. BIND_ENUM_CONSTANT(FLAG_MOUSE_PASSTHROUGH);
  2833. BIND_ENUM_CONSTANT(FLAG_SHARP_CORNERS);
  2834. BIND_ENUM_CONSTANT(FLAG_EXCLUDE_FROM_CAPTURE);
  2835. BIND_ENUM_CONSTANT(FLAG_POPUP_WM_HINT);
  2836. BIND_ENUM_CONSTANT(FLAG_MINIMIZE_DISABLED);
  2837. BIND_ENUM_CONSTANT(FLAG_MAXIMIZE_DISABLED);
  2838. BIND_ENUM_CONSTANT(FLAG_MAX);
  2839. BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_DISABLED);
  2840. BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_CANVAS_ITEMS);
  2841. BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_VIEWPORT);
  2842. BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_IGNORE);
  2843. BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_KEEP);
  2844. BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_KEEP_WIDTH);
  2845. BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_KEEP_HEIGHT);
  2846. BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_EXPAND);
  2847. BIND_ENUM_CONSTANT(CONTENT_SCALE_STRETCH_FRACTIONAL);
  2848. BIND_ENUM_CONSTANT(CONTENT_SCALE_STRETCH_INTEGER);
  2849. BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_INHERITED);
  2850. BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_APPLICATION_LOCALE);
  2851. BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LTR);
  2852. BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_RTL);
  2853. BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_SYSTEM_LOCALE);
  2854. BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_MAX);
  2855. #ifndef DISABLE_DEPRECATED
  2856. BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LOCALE);
  2857. #endif // DISABLE_DEPRECATED
  2858. BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_ABSOLUTE);
  2859. BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_PRIMARY_SCREEN);
  2860. BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN);
  2861. BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN);
  2862. BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_MOUSE_FOCUS);
  2863. BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_KEYBOARD_FOCUS);
  2864. GDVIRTUAL_BIND(_get_contents_minimum_size);
  2865. BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Window, embedded_border);
  2866. BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Window, embedded_unfocused_border);
  2867. BIND_THEME_ITEM(Theme::DATA_TYPE_FONT, Window, title_font);
  2868. BIND_THEME_ITEM(Theme::DATA_TYPE_FONT_SIZE, Window, title_font_size);
  2869. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Window, title_color);
  2870. BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Window, title_height);
  2871. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Window, title_outline_modulate);
  2872. BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Window, title_outline_size);
  2873. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Window, close);
  2874. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Window, close_pressed);
  2875. BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Window, close_h_offset);
  2876. BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Window, close_v_offset);
  2877. BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Window, resize_margin);
  2878. }
  2879. Window::Window() {
  2880. RenderingServer *rendering_server = RenderingServer::get_singleton();
  2881. if (rendering_server) {
  2882. max_size = rendering_server->get_maximum_viewport_size();
  2883. max_size_used = max_size; // Update max_size_used.
  2884. }
  2885. theme_owner = memnew(ThemeOwner(this));
  2886. RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
  2887. }
  2888. Window::~Window() {
  2889. if (focused_window == this) {
  2890. focused_window = nullptr;
  2891. }
  2892. memdelete(theme_owner);
  2893. // Resources need to be disconnected.
  2894. for (KeyValue<StringName, Ref<Texture2D>> &E : theme_icon_override) {
  2895. E.value->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  2896. }
  2897. for (KeyValue<StringName, Ref<StyleBox>> &E : theme_style_override) {
  2898. E.value->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  2899. }
  2900. for (KeyValue<StringName, Ref<Font>> &E : theme_font_override) {
  2901. E.value->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
  2902. }
  2903. // Then override maps can be simply cleared.
  2904. theme_icon_override.clear();
  2905. theme_style_override.clear();
  2906. theme_font_override.clear();
  2907. theme_font_size_override.clear();
  2908. theme_color_override.clear();
  2909. theme_constant_override.clear();
  2910. }