window.cpp 125 KB

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