window.cpp 122 KB

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