display_server.cpp 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  1. /**************************************************************************/
  2. /* display_server.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 "display_server.h"
  31. #include "core/input/input.h"
  32. #include "scene/resources/texture.h"
  33. #include "servers/display_server_headless.h"
  34. DisplayServer *DisplayServer::singleton = nullptr;
  35. bool DisplayServer::hidpi_allowed = false;
  36. bool DisplayServer::window_early_clear_override_enabled = false;
  37. Color DisplayServer::window_early_clear_override_color = Color(0, 0, 0, 0);
  38. DisplayServer::DisplayServerCreate DisplayServer::server_create_functions[DisplayServer::MAX_SERVERS] = {
  39. { "headless", &DisplayServerHeadless::create_func, &DisplayServerHeadless::get_rendering_drivers_func }
  40. };
  41. int DisplayServer::server_create_count = 1;
  42. void DisplayServer::help_set_search_callbacks(const Callable &p_search_callback, const Callable &p_action_callback) {
  43. WARN_PRINT("Native help is not supported by this display server.");
  44. }
  45. #ifndef DISABLE_DEPRECATED
  46. RID DisplayServer::_get_rid_from_name(NativeMenu *p_nmenu, const String &p_menu_root) const {
  47. if (p_menu_root == "_main") {
  48. return p_nmenu->get_system_menu(NativeMenu::MAIN_MENU_ID);
  49. } else if (p_menu_root == "_apple") {
  50. return p_nmenu->get_system_menu(NativeMenu::APPLICATION_MENU_ID);
  51. } else if (p_menu_root == "_dock") {
  52. return p_nmenu->get_system_menu(NativeMenu::DOCK_MENU_ID);
  53. } else if (p_menu_root == "_help") {
  54. return p_nmenu->get_system_menu(NativeMenu::HELP_MENU_ID);
  55. } else if (p_menu_root == "_window") {
  56. return p_nmenu->get_system_menu(NativeMenu::WINDOW_MENU_ID);
  57. } else if (menu_names.has(p_menu_root)) {
  58. return menu_names[p_menu_root];
  59. }
  60. RID rid = p_nmenu->create_menu();
  61. menu_names[p_menu_root] = rid;
  62. return rid;
  63. }
  64. int DisplayServer::global_menu_add_item(const String &p_menu_root, const String &p_label, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  65. NativeMenu *nmenu = NativeMenu::get_singleton();
  66. ERR_FAIL_NULL_V(nmenu, -1);
  67. return nmenu->add_item(_get_rid_from_name(nmenu, p_menu_root), p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  68. }
  69. int DisplayServer::global_menu_add_check_item(const String &p_menu_root, const String &p_label, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  70. NativeMenu *nmenu = NativeMenu::get_singleton();
  71. ERR_FAIL_NULL_V(nmenu, -1);
  72. return nmenu->add_check_item(_get_rid_from_name(nmenu, p_menu_root), p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  73. }
  74. int DisplayServer::global_menu_add_icon_item(const String &p_menu_root, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  75. NativeMenu *nmenu = NativeMenu::get_singleton();
  76. ERR_FAIL_NULL_V(nmenu, -1);
  77. return nmenu->add_icon_item(_get_rid_from_name(nmenu, p_menu_root), p_icon, p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  78. }
  79. int DisplayServer::global_menu_add_icon_check_item(const String &p_menu_root, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  80. NativeMenu *nmenu = NativeMenu::get_singleton();
  81. ERR_FAIL_NULL_V(nmenu, -1);
  82. return nmenu->add_icon_check_item(_get_rid_from_name(nmenu, p_menu_root), p_icon, p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  83. }
  84. int DisplayServer::global_menu_add_radio_check_item(const String &p_menu_root, const String &p_label, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  85. NativeMenu *nmenu = NativeMenu::get_singleton();
  86. ERR_FAIL_NULL_V(nmenu, -1);
  87. return nmenu->add_radio_check_item(_get_rid_from_name(nmenu, p_menu_root), p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  88. }
  89. int DisplayServer::global_menu_add_icon_radio_check_item(const String &p_menu_root, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  90. NativeMenu *nmenu = NativeMenu::get_singleton();
  91. ERR_FAIL_NULL_V(nmenu, -1);
  92. return nmenu->add_icon_radio_check_item(_get_rid_from_name(nmenu, p_menu_root), p_icon, p_label, p_callback, p_key_callback, p_tag, p_accel, p_index);
  93. }
  94. int DisplayServer::global_menu_add_multistate_item(const String &p_menu_root, const String &p_label, int p_max_states, int p_default_state, const Callable &p_callback, const Callable &p_key_callback, const Variant &p_tag, Key p_accel, int p_index) {
  95. NativeMenu *nmenu = NativeMenu::get_singleton();
  96. ERR_FAIL_NULL_V(nmenu, -1);
  97. return nmenu->add_multistate_item(_get_rid_from_name(nmenu, p_menu_root), p_label, p_max_states, p_default_state, p_callback, p_key_callback, p_tag, p_accel, p_index);
  98. }
  99. void DisplayServer::global_menu_set_popup_callbacks(const String &p_menu_root, const Callable &p_open_callback, const Callable &p_close_callback) {
  100. NativeMenu *nmenu = NativeMenu::get_singleton();
  101. ERR_FAIL_NULL(nmenu);
  102. nmenu->set_popup_open_callback(_get_rid_from_name(nmenu, p_menu_root), p_open_callback);
  103. nmenu->set_popup_open_callback(_get_rid_from_name(nmenu, p_menu_root), p_close_callback);
  104. }
  105. int DisplayServer::global_menu_add_submenu_item(const String &p_menu_root, const String &p_label, const String &p_submenu, int p_index) {
  106. NativeMenu *nmenu = NativeMenu::get_singleton();
  107. ERR_FAIL_NULL_V(nmenu, -1);
  108. return nmenu->add_submenu_item(_get_rid_from_name(nmenu, p_menu_root), p_label, _get_rid_from_name(nmenu, p_submenu), Variant(), p_index);
  109. }
  110. int DisplayServer::global_menu_add_separator(const String &p_menu_root, int p_index) {
  111. NativeMenu *nmenu = NativeMenu::get_singleton();
  112. ERR_FAIL_NULL_V(nmenu, -1);
  113. return nmenu->add_separator(_get_rid_from_name(nmenu, p_menu_root), p_index);
  114. }
  115. int DisplayServer::global_menu_get_item_index_from_text(const String &p_menu_root, const String &p_text) const {
  116. NativeMenu *nmenu = NativeMenu::get_singleton();
  117. ERR_FAIL_NULL_V(nmenu, -1);
  118. return nmenu->find_item_index_with_text(_get_rid_from_name(nmenu, p_menu_root), p_text);
  119. }
  120. int DisplayServer::global_menu_get_item_index_from_tag(const String &p_menu_root, const Variant &p_tag) const {
  121. NativeMenu *nmenu = NativeMenu::get_singleton();
  122. ERR_FAIL_NULL_V(nmenu, -1);
  123. return nmenu->find_item_index_with_tag(_get_rid_from_name(nmenu, p_menu_root), p_tag);
  124. }
  125. void DisplayServer::global_menu_set_item_callback(const String &p_menu_root, int p_idx, const Callable &p_callback) {
  126. NativeMenu *nmenu = NativeMenu::get_singleton();
  127. ERR_FAIL_NULL(nmenu);
  128. nmenu->set_item_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_callback);
  129. }
  130. void DisplayServer::global_menu_set_item_hover_callbacks(const String &p_menu_root, int p_idx, const Callable &p_callback) {
  131. NativeMenu *nmenu = NativeMenu::get_singleton();
  132. ERR_FAIL_NULL(nmenu);
  133. nmenu->set_item_hover_callbacks(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_callback);
  134. }
  135. void DisplayServer::global_menu_set_item_key_callback(const String &p_menu_root, int p_idx, const Callable &p_key_callback) {
  136. NativeMenu *nmenu = NativeMenu::get_singleton();
  137. ERR_FAIL_NULL(nmenu);
  138. nmenu->set_item_key_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_key_callback);
  139. }
  140. bool DisplayServer::global_menu_is_item_checked(const String &p_menu_root, int p_idx) const {
  141. NativeMenu *nmenu = NativeMenu::get_singleton();
  142. ERR_FAIL_NULL_V(nmenu, false);
  143. return nmenu->is_item_checked(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  144. }
  145. bool DisplayServer::global_menu_is_item_checkable(const String &p_menu_root, int p_idx) const {
  146. NativeMenu *nmenu = NativeMenu::get_singleton();
  147. ERR_FAIL_NULL_V(nmenu, false);
  148. return nmenu->is_item_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  149. }
  150. bool DisplayServer::global_menu_is_item_radio_checkable(const String &p_menu_root, int p_idx) const {
  151. NativeMenu *nmenu = NativeMenu::get_singleton();
  152. ERR_FAIL_NULL_V(nmenu, false);
  153. return nmenu->is_item_radio_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  154. }
  155. Callable DisplayServer::global_menu_get_item_callback(const String &p_menu_root, int p_idx) const {
  156. NativeMenu *nmenu = NativeMenu::get_singleton();
  157. ERR_FAIL_NULL_V(nmenu, Callable());
  158. return nmenu->get_item_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  159. }
  160. Callable DisplayServer::global_menu_get_item_key_callback(const String &p_menu_root, int p_idx) const {
  161. NativeMenu *nmenu = NativeMenu::get_singleton();
  162. ERR_FAIL_NULL_V(nmenu, Callable());
  163. return nmenu->get_item_key_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  164. }
  165. Variant DisplayServer::global_menu_get_item_tag(const String &p_menu_root, int p_idx) const {
  166. NativeMenu *nmenu = NativeMenu::get_singleton();
  167. ERR_FAIL_NULL_V(nmenu, Variant());
  168. return nmenu->get_item_tag(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  169. }
  170. String DisplayServer::global_menu_get_item_text(const String &p_menu_root, int p_idx) const {
  171. NativeMenu *nmenu = NativeMenu::get_singleton();
  172. ERR_FAIL_NULL_V(nmenu, String());
  173. return nmenu->get_item_text(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  174. }
  175. String DisplayServer::global_menu_get_item_submenu(const String &p_menu_root, int p_idx) const {
  176. NativeMenu *nmenu = NativeMenu::get_singleton();
  177. ERR_FAIL_NULL_V(nmenu, String());
  178. RID rid = nmenu->get_item_submenu(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  179. if (!nmenu->is_system_menu(rid)) {
  180. for (HashMap<String, RID>::Iterator E = menu_names.begin(); E; ++E) {
  181. if (E->value == rid) {
  182. return E->key;
  183. }
  184. }
  185. }
  186. return String();
  187. }
  188. Key DisplayServer::global_menu_get_item_accelerator(const String &p_menu_root, int p_idx) const {
  189. NativeMenu *nmenu = NativeMenu::get_singleton();
  190. ERR_FAIL_NULL_V(nmenu, Key::NONE);
  191. return nmenu->get_item_accelerator(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  192. }
  193. bool DisplayServer::global_menu_is_item_disabled(const String &p_menu_root, int p_idx) const {
  194. NativeMenu *nmenu = NativeMenu::get_singleton();
  195. ERR_FAIL_NULL_V(nmenu, false);
  196. return nmenu->is_item_disabled(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  197. }
  198. bool DisplayServer::global_menu_is_item_hidden(const String &p_menu_root, int p_idx) const {
  199. NativeMenu *nmenu = NativeMenu::get_singleton();
  200. ERR_FAIL_NULL_V(nmenu, false);
  201. return nmenu->is_item_hidden(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  202. }
  203. String DisplayServer::global_menu_get_item_tooltip(const String &p_menu_root, int p_idx) const {
  204. NativeMenu *nmenu = NativeMenu::get_singleton();
  205. ERR_FAIL_NULL_V(nmenu, String());
  206. return nmenu->get_item_tooltip(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  207. }
  208. int DisplayServer::global_menu_get_item_state(const String &p_menu_root, int p_idx) const {
  209. NativeMenu *nmenu = NativeMenu::get_singleton();
  210. ERR_FAIL_NULL_V(nmenu, -1);
  211. return nmenu->get_item_state(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  212. }
  213. int DisplayServer::global_menu_get_item_max_states(const String &p_menu_root, int p_idx) const {
  214. NativeMenu *nmenu = NativeMenu::get_singleton();
  215. ERR_FAIL_NULL_V(nmenu, -1);
  216. return nmenu->get_item_max_states(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  217. }
  218. Ref<Texture2D> DisplayServer::global_menu_get_item_icon(const String &p_menu_root, int p_idx) const {
  219. NativeMenu *nmenu = NativeMenu::get_singleton();
  220. ERR_FAIL_NULL_V(nmenu, Ref<Texture2D>());
  221. return nmenu->get_item_icon(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  222. }
  223. int DisplayServer::global_menu_get_item_indentation_level(const String &p_menu_root, int p_idx) const {
  224. NativeMenu *nmenu = NativeMenu::get_singleton();
  225. ERR_FAIL_NULL_V(nmenu, 0);
  226. return nmenu->get_item_indentation_level(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  227. }
  228. void DisplayServer::global_menu_set_item_checked(const String &p_menu_root, int p_idx, bool p_checked) {
  229. NativeMenu *nmenu = NativeMenu::get_singleton();
  230. ERR_FAIL_NULL(nmenu);
  231. nmenu->set_item_checked(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_checked);
  232. }
  233. void DisplayServer::global_menu_set_item_checkable(const String &p_menu_root, int p_idx, bool p_checkable) {
  234. NativeMenu *nmenu = NativeMenu::get_singleton();
  235. ERR_FAIL_NULL(nmenu);
  236. nmenu->set_item_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_checkable);
  237. }
  238. void DisplayServer::global_menu_set_item_radio_checkable(const String &p_menu_root, int p_idx, bool p_checkable) {
  239. NativeMenu *nmenu = NativeMenu::get_singleton();
  240. ERR_FAIL_NULL(nmenu);
  241. nmenu->set_item_radio_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_checkable);
  242. }
  243. void DisplayServer::global_menu_set_item_tag(const String &p_menu_root, int p_idx, const Variant &p_tag) {
  244. NativeMenu *nmenu = NativeMenu::get_singleton();
  245. ERR_FAIL_NULL(nmenu);
  246. nmenu->set_item_tag(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_tag);
  247. }
  248. void DisplayServer::global_menu_set_item_text(const String &p_menu_root, int p_idx, const String &p_text) {
  249. NativeMenu *nmenu = NativeMenu::get_singleton();
  250. ERR_FAIL_NULL(nmenu);
  251. nmenu->set_item_text(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_text);
  252. }
  253. void DisplayServer::global_menu_set_item_submenu(const String &p_menu_root, int p_idx, const String &p_submenu) {
  254. NativeMenu *nmenu = NativeMenu::get_singleton();
  255. ERR_FAIL_NULL(nmenu);
  256. nmenu->set_item_submenu(_get_rid_from_name(nmenu, p_menu_root), p_idx, _get_rid_from_name(nmenu, p_submenu));
  257. }
  258. void DisplayServer::global_menu_set_item_accelerator(const String &p_menu_root, int p_idx, Key p_keycode) {
  259. NativeMenu *nmenu = NativeMenu::get_singleton();
  260. ERR_FAIL_NULL(nmenu);
  261. nmenu->set_item_accelerator(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_keycode);
  262. }
  263. void DisplayServer::global_menu_set_item_disabled(const String &p_menu_root, int p_idx, bool p_disabled) {
  264. NativeMenu *nmenu = NativeMenu::get_singleton();
  265. ERR_FAIL_NULL(nmenu);
  266. nmenu->set_item_disabled(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_disabled);
  267. }
  268. void DisplayServer::global_menu_set_item_hidden(const String &p_menu_root, int p_idx, bool p_hidden) {
  269. NativeMenu *nmenu = NativeMenu::get_singleton();
  270. ERR_FAIL_NULL(nmenu);
  271. nmenu->set_item_hidden(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_hidden);
  272. }
  273. void DisplayServer::global_menu_set_item_tooltip(const String &p_menu_root, int p_idx, const String &p_tooltip) {
  274. NativeMenu *nmenu = NativeMenu::get_singleton();
  275. ERR_FAIL_NULL(nmenu);
  276. nmenu->set_item_tooltip(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_tooltip);
  277. }
  278. void DisplayServer::global_menu_set_item_state(const String &p_menu_root, int p_idx, int p_state) {
  279. NativeMenu *nmenu = NativeMenu::get_singleton();
  280. ERR_FAIL_NULL(nmenu);
  281. nmenu->set_item_state(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_state);
  282. }
  283. void DisplayServer::global_menu_set_item_max_states(const String &p_menu_root, int p_idx, int p_max_states) {
  284. NativeMenu *nmenu = NativeMenu::get_singleton();
  285. ERR_FAIL_NULL(nmenu);
  286. nmenu->set_item_max_states(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_max_states);
  287. }
  288. void DisplayServer::global_menu_set_item_icon(const String &p_menu_root, int p_idx, const Ref<Texture2D> &p_icon) {
  289. NativeMenu *nmenu = NativeMenu::get_singleton();
  290. ERR_FAIL_NULL(nmenu);
  291. nmenu->set_item_icon(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_icon);
  292. }
  293. void DisplayServer::global_menu_set_item_indentation_level(const String &p_menu_root, int p_idx, int p_level) {
  294. NativeMenu *nmenu = NativeMenu::get_singleton();
  295. ERR_FAIL_NULL(nmenu);
  296. nmenu->set_item_indentation_level(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_level);
  297. }
  298. int DisplayServer::global_menu_get_item_count(const String &p_menu_root) const {
  299. NativeMenu *nmenu = NativeMenu::get_singleton();
  300. ERR_FAIL_NULL_V(nmenu, 0);
  301. return nmenu->get_item_count(_get_rid_from_name(nmenu, p_menu_root));
  302. }
  303. void DisplayServer::global_menu_remove_item(const String &p_menu_root, int p_idx) {
  304. NativeMenu *nmenu = NativeMenu::get_singleton();
  305. ERR_FAIL_NULL(nmenu);
  306. nmenu->remove_item(_get_rid_from_name(nmenu, p_menu_root), p_idx);
  307. }
  308. void DisplayServer::global_menu_clear(const String &p_menu_root) {
  309. NativeMenu *nmenu = NativeMenu::get_singleton();
  310. ERR_FAIL_NULL(nmenu);
  311. RID rid = _get_rid_from_name(nmenu, p_menu_root);
  312. nmenu->clear(rid);
  313. if (!nmenu->is_system_menu(rid)) {
  314. nmenu->free_menu(rid);
  315. menu_names.erase(p_menu_root);
  316. }
  317. }
  318. Dictionary DisplayServer::global_menu_get_system_menu_roots() const {
  319. NativeMenu *nmenu = NativeMenu::get_singleton();
  320. ERR_FAIL_NULL_V(nmenu, Dictionary());
  321. Dictionary out;
  322. if (nmenu->has_system_menu(NativeMenu::DOCK_MENU_ID)) {
  323. out["_dock"] = "@Dock";
  324. }
  325. if (nmenu->has_system_menu(NativeMenu::APPLICATION_MENU_ID)) {
  326. out["_apple"] = "@Apple";
  327. }
  328. if (nmenu->has_system_menu(NativeMenu::WINDOW_MENU_ID)) {
  329. out["_window"] = "Window";
  330. }
  331. if (nmenu->has_system_menu(NativeMenu::HELP_MENU_ID)) {
  332. out["_help"] = "Help";
  333. }
  334. return out;
  335. }
  336. #endif
  337. bool DisplayServer::tts_is_speaking() const {
  338. WARN_PRINT("TTS is not supported by this display server.");
  339. return false;
  340. }
  341. bool DisplayServer::tts_is_paused() const {
  342. WARN_PRINT("TTS is not supported by this display server.");
  343. return false;
  344. }
  345. void DisplayServer::tts_pause() {
  346. WARN_PRINT("TTS is not supported by this display server.");
  347. }
  348. void DisplayServer::tts_resume() {
  349. WARN_PRINT("TTS is not supported by this display server.");
  350. }
  351. TypedArray<Dictionary> DisplayServer::tts_get_voices() const {
  352. WARN_PRINT("TTS is not supported by this display server.");
  353. return TypedArray<Dictionary>();
  354. }
  355. PackedStringArray DisplayServer::tts_get_voices_for_language(const String &p_language) const {
  356. PackedStringArray ret;
  357. TypedArray<Dictionary> voices = tts_get_voices();
  358. for (int i = 0; i < voices.size(); i++) {
  359. const Dictionary &voice = voices[i];
  360. if (voice.has("id") && voice.has("language") && voice["language"].operator String().begins_with(p_language)) {
  361. ret.push_back(voice["id"]);
  362. }
  363. }
  364. return ret;
  365. }
  366. void DisplayServer::tts_speak(const String &p_text, const String &p_voice, int p_volume, float p_pitch, float p_rate, int p_utterance_id, bool p_interrupt) {
  367. WARN_PRINT("TTS is not supported by this display server.");
  368. }
  369. void DisplayServer::tts_stop() {
  370. WARN_PRINT("TTS is not supported by this display server.");
  371. }
  372. void DisplayServer::tts_set_utterance_callback(TTSUtteranceEvent p_event, const Callable &p_callable) {
  373. ERR_FAIL_INDEX(p_event, DisplayServer::TTS_UTTERANCE_MAX);
  374. utterance_callback[p_event] = p_callable;
  375. }
  376. void DisplayServer::tts_post_utterance_event(TTSUtteranceEvent p_event, int p_id, int p_pos) {
  377. ERR_FAIL_INDEX(p_event, DisplayServer::TTS_UTTERANCE_MAX);
  378. switch (p_event) {
  379. case DisplayServer::TTS_UTTERANCE_STARTED:
  380. case DisplayServer::TTS_UTTERANCE_ENDED:
  381. case DisplayServer::TTS_UTTERANCE_CANCELED: {
  382. if (utterance_callback[p_event].is_valid()) {
  383. utterance_callback[p_event].call_deferred(p_id); // Should be deferred, on some platforms utterance events can be called from different threads in a rapid succession.
  384. }
  385. } break;
  386. case DisplayServer::TTS_UTTERANCE_BOUNDARY: {
  387. if (utterance_callback[p_event].is_valid()) {
  388. utterance_callback[p_event].call_deferred(p_pos, p_id); // Should be deferred, on some platforms utterance events can be called from different threads in a rapid succession.
  389. }
  390. } break;
  391. default:
  392. break;
  393. }
  394. }
  395. bool DisplayServer::_get_window_early_clear_override(Color &r_color) {
  396. if (window_early_clear_override_enabled) {
  397. r_color = window_early_clear_override_color;
  398. return true;
  399. } else if (RenderingServer::get_singleton()) {
  400. r_color = RenderingServer::get_singleton()->get_default_clear_color();
  401. return true;
  402. } else {
  403. return false;
  404. }
  405. }
  406. void DisplayServer::set_early_window_clear_color_override(bool p_enabled, Color p_color) {
  407. window_early_clear_override_enabled = p_enabled;
  408. window_early_clear_override_color = p_color;
  409. }
  410. void DisplayServer::mouse_set_mode(MouseMode p_mode) {
  411. WARN_PRINT("Mouse is not supported by this display server.");
  412. }
  413. DisplayServer::MouseMode DisplayServer::mouse_get_mode() const {
  414. return MOUSE_MODE_VISIBLE;
  415. }
  416. void DisplayServer::warp_mouse(const Point2i &p_position) {
  417. }
  418. Point2i DisplayServer::mouse_get_position() const {
  419. ERR_FAIL_V_MSG(Point2i(), "Mouse is not supported by this display server.");
  420. }
  421. BitField<MouseButtonMask> DisplayServer::mouse_get_button_state() const {
  422. ERR_FAIL_V_MSG(0, "Mouse is not supported by this display server.");
  423. }
  424. void DisplayServer::clipboard_set(const String &p_text) {
  425. WARN_PRINT("Clipboard is not supported by this display server.");
  426. }
  427. String DisplayServer::clipboard_get() const {
  428. ERR_FAIL_V_MSG(String(), "Clipboard is not supported by this display server.");
  429. }
  430. Ref<Image> DisplayServer::clipboard_get_image() const {
  431. ERR_FAIL_V_MSG(Ref<Image>(), "Clipboard is not supported by this display server.");
  432. }
  433. bool DisplayServer::clipboard_has() const {
  434. return !clipboard_get().is_empty();
  435. }
  436. bool DisplayServer::clipboard_has_image() const {
  437. return clipboard_get_image().is_valid();
  438. }
  439. void DisplayServer::clipboard_set_primary(const String &p_text) {
  440. WARN_PRINT("Primary clipboard is not supported by this display server.");
  441. }
  442. String DisplayServer::clipboard_get_primary() const {
  443. ERR_FAIL_V_MSG(String(), "Primary clipboard is not supported by this display server.");
  444. }
  445. void DisplayServer::screen_set_orientation(ScreenOrientation p_orientation, int p_screen) {
  446. WARN_PRINT("Orientation not supported by this display server.");
  447. }
  448. DisplayServer::ScreenOrientation DisplayServer::screen_get_orientation(int p_screen) const {
  449. return SCREEN_LANDSCAPE;
  450. }
  451. float DisplayServer::screen_get_scale(int p_screen) const {
  452. return 1.0f;
  453. };
  454. bool DisplayServer::is_touchscreen_available() const {
  455. return Input::get_singleton() && Input::get_singleton()->is_emulating_touch_from_mouse();
  456. }
  457. void DisplayServer::screen_set_keep_on(bool p_enable) {
  458. WARN_PRINT("Keeping screen on not supported by this display server.");
  459. }
  460. bool DisplayServer::screen_is_kept_on() const {
  461. return false;
  462. }
  463. int DisplayServer::get_screen_from_rect(const Rect2 &p_rect) const {
  464. int nearest_area = 0;
  465. int pos_screen = -1;
  466. for (int i = 0; i < get_screen_count(); i++) {
  467. Rect2i r;
  468. r.position = screen_get_position(i);
  469. r.size = screen_get_size(i);
  470. Rect2 inters = r.intersection(p_rect);
  471. int area = inters.size.width * inters.size.height;
  472. if (area > nearest_area) {
  473. pos_screen = i;
  474. nearest_area = area;
  475. }
  476. }
  477. return pos_screen;
  478. }
  479. DisplayServer::WindowID DisplayServer::create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect, bool p_exclusive, WindowID p_transient_parent) {
  480. ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Sub-windows not supported by this display server.");
  481. }
  482. void DisplayServer::show_window(WindowID p_id) {
  483. ERR_FAIL_MSG("Sub-windows not supported by this display server.");
  484. }
  485. void DisplayServer::delete_sub_window(WindowID p_id) {
  486. ERR_FAIL_MSG("Sub-windows not supported by this display server.");
  487. }
  488. void DisplayServer::window_set_exclusive(WindowID p_window, bool p_exclusive) {
  489. // Do nothing, if not supported.
  490. }
  491. void DisplayServer::window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window) {
  492. ERR_FAIL_MSG("Mouse passthrough not supported by this display server.");
  493. }
  494. void DisplayServer::gl_window_make_current(DisplayServer::WindowID p_window_id) {
  495. // noop except in gles
  496. }
  497. void DisplayServer::window_set_ime_active(const bool p_active, WindowID p_window) {
  498. WARN_PRINT("IME not supported by this display server.");
  499. }
  500. void DisplayServer::window_set_ime_position(const Point2i &p_pos, WindowID p_window) {
  501. WARN_PRINT("IME not supported by this display server.");
  502. }
  503. Point2i DisplayServer::ime_get_selection() const {
  504. ERR_FAIL_V_MSG(Point2i(), "IME or NOTIFICATION_WM_IME_UPDATE not supported by this display server.");
  505. }
  506. String DisplayServer::ime_get_text() const {
  507. ERR_FAIL_V_MSG(String(), "IME or NOTIFICATION_WM_IME_UPDATEnot supported by this display server.");
  508. }
  509. void DisplayServer::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_length, int p_cursor_start, int p_cursor_end) {
  510. WARN_PRINT("Virtual keyboard not supported by this display server.");
  511. }
  512. void DisplayServer::virtual_keyboard_hide() {
  513. WARN_PRINT("Virtual keyboard not supported by this display server.");
  514. }
  515. // returns height of the currently shown keyboard (0 if keyboard is hidden)
  516. int DisplayServer::virtual_keyboard_get_height() const {
  517. ERR_FAIL_V_MSG(0, "Virtual keyboard not supported by this display server.");
  518. }
  519. void DisplayServer::cursor_set_shape(CursorShape p_shape) {
  520. WARN_PRINT("Cursor shape not supported by this display server.");
  521. }
  522. DisplayServer::CursorShape DisplayServer::cursor_get_shape() const {
  523. return CURSOR_ARROW;
  524. }
  525. void DisplayServer::cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
  526. WARN_PRINT("Custom cursor shape not supported by this display server.");
  527. }
  528. bool DisplayServer::get_swap_cancel_ok() {
  529. return false;
  530. }
  531. void DisplayServer::enable_for_stealing_focus(OS::ProcessID pid) {
  532. }
  533. Error DisplayServer::dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) {
  534. WARN_PRINT("Native dialogs not supported by this display server.");
  535. return ERR_UNAVAILABLE;
  536. }
  537. Error DisplayServer::dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback) {
  538. WARN_PRINT("Native dialogs not supported by this display server.");
  539. return ERR_UNAVAILABLE;
  540. }
  541. Error DisplayServer::file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) {
  542. WARN_PRINT("Native dialogs not supported by this display server.");
  543. return ERR_UNAVAILABLE;
  544. }
  545. Error DisplayServer::file_dialog_with_options_show(const String &p_title, const String &p_current_directory, const String &p_root, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const TypedArray<Dictionary> &p_options, const Callable &p_callback) {
  546. WARN_PRINT("Native dialogs not supported by this display server.");
  547. return ERR_UNAVAILABLE;
  548. }
  549. int DisplayServer::keyboard_get_layout_count() const {
  550. return 0;
  551. }
  552. int DisplayServer::keyboard_get_current_layout() const {
  553. return -1;
  554. }
  555. void DisplayServer::keyboard_set_current_layout(int p_index) {
  556. }
  557. String DisplayServer::keyboard_get_layout_language(int p_index) const {
  558. return "";
  559. }
  560. String DisplayServer::keyboard_get_layout_name(int p_index) const {
  561. return "Not supported";
  562. }
  563. Key DisplayServer::keyboard_get_keycode_from_physical(Key p_keycode) const {
  564. ERR_FAIL_V_MSG(p_keycode, "Not supported by this display server.");
  565. }
  566. Key DisplayServer::keyboard_get_label_from_physical(Key p_keycode) const {
  567. ERR_FAIL_V_MSG(p_keycode, "Not supported by this display server.");
  568. }
  569. void DisplayServer::force_process_and_drop_events() {
  570. }
  571. void DisplayServer::release_rendering_thread() {
  572. WARN_PRINT("Rendering thread not supported by this display server.");
  573. }
  574. void DisplayServer::swap_buffers() {
  575. WARN_PRINT("Swap buffers not supported by this display server.");
  576. }
  577. void DisplayServer::set_native_icon(const String &p_filename) {
  578. WARN_PRINT("Native icon not supported by this display server.");
  579. }
  580. void DisplayServer::set_icon(const Ref<Image> &p_icon) {
  581. WARN_PRINT("Icon not supported by this display server.");
  582. }
  583. DisplayServer::IndicatorID DisplayServer::create_status_indicator(const Ref<Texture2D> &p_icon, const String &p_tooltip, const Callable &p_callback) {
  584. WARN_PRINT("Status indicator not supported by this display server.");
  585. return INVALID_INDICATOR_ID;
  586. }
  587. void DisplayServer::status_indicator_set_icon(IndicatorID p_id, const Ref<Texture2D> &p_icon) {
  588. WARN_PRINT("Status indicator not supported by this display server.");
  589. }
  590. void DisplayServer::status_indicator_set_tooltip(IndicatorID p_id, const String &p_tooltip) {
  591. WARN_PRINT("Status indicator not supported by this display server.");
  592. }
  593. void DisplayServer::status_indicator_set_menu(IndicatorID p_id, const RID &p_menu_rid) {
  594. WARN_PRINT("Status indicator not supported by this display server.");
  595. }
  596. void DisplayServer::status_indicator_set_callback(IndicatorID p_id, const Callable &p_callback) {
  597. WARN_PRINT("Status indicator not supported by this display server.");
  598. }
  599. Rect2 DisplayServer::status_indicator_get_rect(IndicatorID p_id) const {
  600. WARN_PRINT("Status indicator not supported by this display server.");
  601. return Rect2();
  602. }
  603. void DisplayServer::delete_status_indicator(IndicatorID p_id) {
  604. WARN_PRINT("Status indicator not supported by this display server.");
  605. }
  606. int64_t DisplayServer::window_get_native_handle(HandleType p_handle_type, WindowID p_window) const {
  607. WARN_PRINT("Native handle not supported by this display server.");
  608. return 0;
  609. }
  610. void DisplayServer::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) {
  611. WARN_PRINT("Changing the V-Sync mode is not supported by this display server.");
  612. }
  613. DisplayServer::VSyncMode DisplayServer::window_get_vsync_mode(WindowID p_window) const {
  614. WARN_PRINT("Changing the V-Sync mode is not supported by this display server.");
  615. return VSyncMode::VSYNC_ENABLED;
  616. }
  617. DisplayServer::WindowID DisplayServer::get_focused_window() const {
  618. return MAIN_WINDOW_ID; // Proper value for single windows.
  619. }
  620. void DisplayServer::set_context(Context p_context) {
  621. }
  622. void DisplayServer::register_additional_output(Object *p_object) {
  623. ObjectID id = p_object->get_instance_id();
  624. if (!additional_outputs.has(id)) {
  625. additional_outputs.push_back(id);
  626. }
  627. }
  628. void DisplayServer::unregister_additional_output(Object *p_object) {
  629. additional_outputs.erase(p_object->get_instance_id());
  630. }
  631. void DisplayServer::_bind_methods() {
  632. ClassDB::bind_method(D_METHOD("has_feature", "feature"), &DisplayServer::has_feature);
  633. ClassDB::bind_method(D_METHOD("get_name"), &DisplayServer::get_name);
  634. ClassDB::bind_method(D_METHOD("help_set_search_callbacks", "search_callback", "action_callback"), &DisplayServer::help_set_search_callbacks);
  635. #ifndef DISABLE_DEPRECATED
  636. ClassDB::bind_method(D_METHOD("global_menu_set_popup_callbacks", "menu_root", "open_callback", "close_callback"), &DisplayServer::global_menu_set_popup_callbacks);
  637. ClassDB::bind_method(D_METHOD("global_menu_add_submenu_item", "menu_root", "label", "submenu", "index"), &DisplayServer::global_menu_add_submenu_item, DEFVAL(-1));
  638. ClassDB::bind_method(D_METHOD("global_menu_add_item", "menu_root", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  639. ClassDB::bind_method(D_METHOD("global_menu_add_check_item", "menu_root", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  640. ClassDB::bind_method(D_METHOD("global_menu_add_icon_item", "menu_root", "icon", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_icon_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  641. ClassDB::bind_method(D_METHOD("global_menu_add_icon_check_item", "menu_root", "icon", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_icon_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  642. ClassDB::bind_method(D_METHOD("global_menu_add_radio_check_item", "menu_root", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_radio_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  643. ClassDB::bind_method(D_METHOD("global_menu_add_icon_radio_check_item", "menu_root", "icon", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_icon_radio_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  644. ClassDB::bind_method(D_METHOD("global_menu_add_multistate_item", "menu_root", "label", "max_states", "default_state", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_multistate_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1));
  645. ClassDB::bind_method(D_METHOD("global_menu_add_separator", "menu_root", "index"), &DisplayServer::global_menu_add_separator, DEFVAL(-1));
  646. ClassDB::bind_method(D_METHOD("global_menu_get_item_index_from_text", "menu_root", "text"), &DisplayServer::global_menu_get_item_index_from_text);
  647. ClassDB::bind_method(D_METHOD("global_menu_get_item_index_from_tag", "menu_root", "tag"), &DisplayServer::global_menu_get_item_index_from_tag);
  648. ClassDB::bind_method(D_METHOD("global_menu_is_item_checked", "menu_root", "idx"), &DisplayServer::global_menu_is_item_checked);
  649. ClassDB::bind_method(D_METHOD("global_menu_is_item_checkable", "menu_root", "idx"), &DisplayServer::global_menu_is_item_checkable);
  650. ClassDB::bind_method(D_METHOD("global_menu_is_item_radio_checkable", "menu_root", "idx"), &DisplayServer::global_menu_is_item_radio_checkable);
  651. ClassDB::bind_method(D_METHOD("global_menu_get_item_callback", "menu_root", "idx"), &DisplayServer::global_menu_get_item_callback);
  652. ClassDB::bind_method(D_METHOD("global_menu_get_item_key_callback", "menu_root", "idx"), &DisplayServer::global_menu_get_item_key_callback);
  653. ClassDB::bind_method(D_METHOD("global_menu_get_item_tag", "menu_root", "idx"), &DisplayServer::global_menu_get_item_tag);
  654. ClassDB::bind_method(D_METHOD("global_menu_get_item_text", "menu_root", "idx"), &DisplayServer::global_menu_get_item_text);
  655. ClassDB::bind_method(D_METHOD("global_menu_get_item_submenu", "menu_root", "idx"), &DisplayServer::global_menu_get_item_submenu);
  656. ClassDB::bind_method(D_METHOD("global_menu_get_item_accelerator", "menu_root", "idx"), &DisplayServer::global_menu_get_item_accelerator);
  657. ClassDB::bind_method(D_METHOD("global_menu_is_item_disabled", "menu_root", "idx"), &DisplayServer::global_menu_is_item_disabled);
  658. ClassDB::bind_method(D_METHOD("global_menu_is_item_hidden", "menu_root", "idx"), &DisplayServer::global_menu_is_item_hidden);
  659. ClassDB::bind_method(D_METHOD("global_menu_get_item_tooltip", "menu_root", "idx"), &DisplayServer::global_menu_get_item_tooltip);
  660. ClassDB::bind_method(D_METHOD("global_menu_get_item_state", "menu_root", "idx"), &DisplayServer::global_menu_get_item_state);
  661. ClassDB::bind_method(D_METHOD("global_menu_get_item_max_states", "menu_root", "idx"), &DisplayServer::global_menu_get_item_max_states);
  662. ClassDB::bind_method(D_METHOD("global_menu_get_item_icon", "menu_root", "idx"), &DisplayServer::global_menu_get_item_icon);
  663. ClassDB::bind_method(D_METHOD("global_menu_get_item_indentation_level", "menu_root", "idx"), &DisplayServer::global_menu_get_item_indentation_level);
  664. ClassDB::bind_method(D_METHOD("global_menu_set_item_checked", "menu_root", "idx", "checked"), &DisplayServer::global_menu_set_item_checked);
  665. ClassDB::bind_method(D_METHOD("global_menu_set_item_checkable", "menu_root", "idx", "checkable"), &DisplayServer::global_menu_set_item_checkable);
  666. ClassDB::bind_method(D_METHOD("global_menu_set_item_radio_checkable", "menu_root", "idx", "checkable"), &DisplayServer::global_menu_set_item_radio_checkable);
  667. ClassDB::bind_method(D_METHOD("global_menu_set_item_callback", "menu_root", "idx", "callback"), &DisplayServer::global_menu_set_item_callback);
  668. ClassDB::bind_method(D_METHOD("global_menu_set_item_hover_callbacks", "menu_root", "idx", "callback"), &DisplayServer::global_menu_set_item_hover_callbacks);
  669. ClassDB::bind_method(D_METHOD("global_menu_set_item_key_callback", "menu_root", "idx", "key_callback"), &DisplayServer::global_menu_set_item_key_callback);
  670. ClassDB::bind_method(D_METHOD("global_menu_set_item_tag", "menu_root", "idx", "tag"), &DisplayServer::global_menu_set_item_tag);
  671. ClassDB::bind_method(D_METHOD("global_menu_set_item_text", "menu_root", "idx", "text"), &DisplayServer::global_menu_set_item_text);
  672. ClassDB::bind_method(D_METHOD("global_menu_set_item_submenu", "menu_root", "idx", "submenu"), &DisplayServer::global_menu_set_item_submenu);
  673. ClassDB::bind_method(D_METHOD("global_menu_set_item_accelerator", "menu_root", "idx", "keycode"), &DisplayServer::global_menu_set_item_accelerator);
  674. ClassDB::bind_method(D_METHOD("global_menu_set_item_disabled", "menu_root", "idx", "disabled"), &DisplayServer::global_menu_set_item_disabled);
  675. ClassDB::bind_method(D_METHOD("global_menu_set_item_hidden", "menu_root", "idx", "hidden"), &DisplayServer::global_menu_set_item_hidden);
  676. ClassDB::bind_method(D_METHOD("global_menu_set_item_tooltip", "menu_root", "idx", "tooltip"), &DisplayServer::global_menu_set_item_tooltip);
  677. ClassDB::bind_method(D_METHOD("global_menu_set_item_state", "menu_root", "idx", "state"), &DisplayServer::global_menu_set_item_state);
  678. ClassDB::bind_method(D_METHOD("global_menu_set_item_max_states", "menu_root", "idx", "max_states"), &DisplayServer::global_menu_set_item_max_states);
  679. ClassDB::bind_method(D_METHOD("global_menu_set_item_icon", "menu_root", "idx", "icon"), &DisplayServer::global_menu_set_item_icon);
  680. ClassDB::bind_method(D_METHOD("global_menu_set_item_indentation_level", "menu_root", "idx", "level"), &DisplayServer::global_menu_set_item_indentation_level);
  681. ClassDB::bind_method(D_METHOD("global_menu_get_item_count", "menu_root"), &DisplayServer::global_menu_get_item_count);
  682. ClassDB::bind_method(D_METHOD("global_menu_remove_item", "menu_root", "idx"), &DisplayServer::global_menu_remove_item);
  683. ClassDB::bind_method(D_METHOD("global_menu_clear", "menu_root"), &DisplayServer::global_menu_clear);
  684. ClassDB::bind_method(D_METHOD("global_menu_get_system_menu_roots"), &DisplayServer::global_menu_get_system_menu_roots);
  685. #endif
  686. ClassDB::bind_method(D_METHOD("tts_is_speaking"), &DisplayServer::tts_is_speaking);
  687. ClassDB::bind_method(D_METHOD("tts_is_paused"), &DisplayServer::tts_is_paused);
  688. ClassDB::bind_method(D_METHOD("tts_get_voices"), &DisplayServer::tts_get_voices);
  689. ClassDB::bind_method(D_METHOD("tts_get_voices_for_language", "language"), &DisplayServer::tts_get_voices_for_language);
  690. ClassDB::bind_method(D_METHOD("tts_speak", "text", "voice", "volume", "pitch", "rate", "utterance_id", "interrupt"), &DisplayServer::tts_speak, DEFVAL(50), DEFVAL(1.f), DEFVAL(1.f), DEFVAL(0), DEFVAL(false));
  691. ClassDB::bind_method(D_METHOD("tts_pause"), &DisplayServer::tts_pause);
  692. ClassDB::bind_method(D_METHOD("tts_resume"), &DisplayServer::tts_resume);
  693. ClassDB::bind_method(D_METHOD("tts_stop"), &DisplayServer::tts_stop);
  694. ClassDB::bind_method(D_METHOD("tts_set_utterance_callback", "event", "callable"), &DisplayServer::tts_set_utterance_callback);
  695. ClassDB::bind_method(D_METHOD("_tts_post_utterance_event", "event", "id", "char_pos"), &DisplayServer::tts_post_utterance_event);
  696. ClassDB::bind_method(D_METHOD("is_dark_mode_supported"), &DisplayServer::is_dark_mode_supported);
  697. ClassDB::bind_method(D_METHOD("is_dark_mode"), &DisplayServer::is_dark_mode);
  698. ClassDB::bind_method(D_METHOD("get_accent_color"), &DisplayServer::get_accent_color);
  699. ClassDB::bind_method(D_METHOD("get_base_color"), &DisplayServer::get_base_color);
  700. ClassDB::bind_method(D_METHOD("set_system_theme_change_callback", "callable"), &DisplayServer::set_system_theme_change_callback);
  701. ClassDB::bind_method(D_METHOD("mouse_set_mode", "mouse_mode"), &DisplayServer::mouse_set_mode);
  702. ClassDB::bind_method(D_METHOD("mouse_get_mode"), &DisplayServer::mouse_get_mode);
  703. ClassDB::bind_method(D_METHOD("warp_mouse", "position"), &DisplayServer::warp_mouse);
  704. ClassDB::bind_method(D_METHOD("mouse_get_position"), &DisplayServer::mouse_get_position);
  705. ClassDB::bind_method(D_METHOD("mouse_get_button_state"), &DisplayServer::mouse_get_button_state);
  706. ClassDB::bind_method(D_METHOD("clipboard_set", "clipboard"), &DisplayServer::clipboard_set);
  707. ClassDB::bind_method(D_METHOD("clipboard_get"), &DisplayServer::clipboard_get);
  708. ClassDB::bind_method(D_METHOD("clipboard_get_image"), &DisplayServer::clipboard_get_image);
  709. ClassDB::bind_method(D_METHOD("clipboard_has"), &DisplayServer::clipboard_has);
  710. ClassDB::bind_method(D_METHOD("clipboard_has_image"), &DisplayServer::clipboard_has_image);
  711. ClassDB::bind_method(D_METHOD("clipboard_set_primary", "clipboard_primary"), &DisplayServer::clipboard_set_primary);
  712. ClassDB::bind_method(D_METHOD("clipboard_get_primary"), &DisplayServer::clipboard_get_primary);
  713. ClassDB::bind_method(D_METHOD("get_display_cutouts"), &DisplayServer::get_display_cutouts);
  714. ClassDB::bind_method(D_METHOD("get_display_safe_area"), &DisplayServer::get_display_safe_area);
  715. ClassDB::bind_method(D_METHOD("get_screen_count"), &DisplayServer::get_screen_count);
  716. ClassDB::bind_method(D_METHOD("get_primary_screen"), &DisplayServer::get_primary_screen);
  717. ClassDB::bind_method(D_METHOD("get_keyboard_focus_screen"), &DisplayServer::get_keyboard_focus_screen);
  718. ClassDB::bind_method(D_METHOD("get_screen_from_rect", "rect"), &DisplayServer::get_screen_from_rect);
  719. ClassDB::bind_method(D_METHOD("screen_get_position", "screen"), &DisplayServer::screen_get_position, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  720. ClassDB::bind_method(D_METHOD("screen_get_size", "screen"), &DisplayServer::screen_get_size, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  721. ClassDB::bind_method(D_METHOD("screen_get_usable_rect", "screen"), &DisplayServer::screen_get_usable_rect, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  722. ClassDB::bind_method(D_METHOD("screen_get_dpi", "screen"), &DisplayServer::screen_get_dpi, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  723. ClassDB::bind_method(D_METHOD("screen_get_scale", "screen"), &DisplayServer::screen_get_scale, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  724. ClassDB::bind_method(D_METHOD("is_touchscreen_available"), &DisplayServer::is_touchscreen_available, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  725. ClassDB::bind_method(D_METHOD("screen_get_max_scale"), &DisplayServer::screen_get_max_scale);
  726. ClassDB::bind_method(D_METHOD("screen_get_refresh_rate", "screen"), &DisplayServer::screen_get_refresh_rate, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  727. ClassDB::bind_method(D_METHOD("screen_get_pixel", "position"), &DisplayServer::screen_get_pixel);
  728. ClassDB::bind_method(D_METHOD("screen_get_image", "screen"), &DisplayServer::screen_get_image, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  729. ClassDB::bind_method(D_METHOD("screen_set_orientation", "orientation", "screen"), &DisplayServer::screen_set_orientation, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  730. ClassDB::bind_method(D_METHOD("screen_get_orientation", "screen"), &DisplayServer::screen_get_orientation, DEFVAL(SCREEN_OF_MAIN_WINDOW));
  731. ClassDB::bind_method(D_METHOD("screen_set_keep_on", "enable"), &DisplayServer::screen_set_keep_on);
  732. ClassDB::bind_method(D_METHOD("screen_is_kept_on"), &DisplayServer::screen_is_kept_on);
  733. ClassDB::bind_method(D_METHOD("get_window_list"), &DisplayServer::get_window_list);
  734. ClassDB::bind_method(D_METHOD("get_window_at_screen_position", "position"), &DisplayServer::get_window_at_screen_position);
  735. ClassDB::bind_method(D_METHOD("window_get_native_handle", "handle_type", "window_id"), &DisplayServer::window_get_native_handle, DEFVAL(MAIN_WINDOW_ID));
  736. ClassDB::bind_method(D_METHOD("window_get_active_popup"), &DisplayServer::window_get_active_popup);
  737. ClassDB::bind_method(D_METHOD("window_set_popup_safe_rect", "window", "rect"), &DisplayServer::window_set_popup_safe_rect);
  738. ClassDB::bind_method(D_METHOD("window_get_popup_safe_rect", "window"), &DisplayServer::window_get_popup_safe_rect);
  739. ClassDB::bind_method(D_METHOD("window_set_title", "title", "window_id"), &DisplayServer::window_set_title, DEFVAL(MAIN_WINDOW_ID));
  740. ClassDB::bind_method(D_METHOD("window_get_title_size", "title", "window_id"), &DisplayServer::window_get_title_size, DEFVAL(MAIN_WINDOW_ID));
  741. ClassDB::bind_method(D_METHOD("window_set_mouse_passthrough", "region", "window_id"), &DisplayServer::window_set_mouse_passthrough, DEFVAL(MAIN_WINDOW_ID));
  742. ClassDB::bind_method(D_METHOD("window_get_current_screen", "window_id"), &DisplayServer::window_get_current_screen, DEFVAL(MAIN_WINDOW_ID));
  743. ClassDB::bind_method(D_METHOD("window_set_current_screen", "screen", "window_id"), &DisplayServer::window_set_current_screen, DEFVAL(MAIN_WINDOW_ID));
  744. ClassDB::bind_method(D_METHOD("window_get_position", "window_id"), &DisplayServer::window_get_position, DEFVAL(MAIN_WINDOW_ID));
  745. ClassDB::bind_method(D_METHOD("window_get_position_with_decorations", "window_id"), &DisplayServer::window_get_position_with_decorations, DEFVAL(MAIN_WINDOW_ID));
  746. ClassDB::bind_method(D_METHOD("window_set_position", "position", "window_id"), &DisplayServer::window_set_position, DEFVAL(MAIN_WINDOW_ID));
  747. ClassDB::bind_method(D_METHOD("window_get_size", "window_id"), &DisplayServer::window_get_size, DEFVAL(MAIN_WINDOW_ID));
  748. ClassDB::bind_method(D_METHOD("window_set_size", "size", "window_id"), &DisplayServer::window_set_size, DEFVAL(MAIN_WINDOW_ID));
  749. ClassDB::bind_method(D_METHOD("window_set_rect_changed_callback", "callback", "window_id"), &DisplayServer::window_set_rect_changed_callback, DEFVAL(MAIN_WINDOW_ID));
  750. ClassDB::bind_method(D_METHOD("window_set_window_event_callback", "callback", "window_id"), &DisplayServer::window_set_window_event_callback, DEFVAL(MAIN_WINDOW_ID));
  751. ClassDB::bind_method(D_METHOD("window_set_input_event_callback", "callback", "window_id"), &DisplayServer::window_set_input_event_callback, DEFVAL(MAIN_WINDOW_ID));
  752. ClassDB::bind_method(D_METHOD("window_set_input_text_callback", "callback", "window_id"), &DisplayServer::window_set_input_text_callback, DEFVAL(MAIN_WINDOW_ID));
  753. ClassDB::bind_method(D_METHOD("window_set_drop_files_callback", "callback", "window_id"), &DisplayServer::window_set_drop_files_callback, DEFVAL(MAIN_WINDOW_ID));
  754. ClassDB::bind_method(D_METHOD("window_get_attached_instance_id", "window_id"), &DisplayServer::window_get_attached_instance_id, DEFVAL(MAIN_WINDOW_ID));
  755. ClassDB::bind_method(D_METHOD("window_get_max_size", "window_id"), &DisplayServer::window_get_max_size, DEFVAL(MAIN_WINDOW_ID));
  756. ClassDB::bind_method(D_METHOD("window_set_max_size", "max_size", "window_id"), &DisplayServer::window_set_max_size, DEFVAL(MAIN_WINDOW_ID));
  757. ClassDB::bind_method(D_METHOD("window_get_min_size", "window_id"), &DisplayServer::window_get_min_size, DEFVAL(MAIN_WINDOW_ID));
  758. ClassDB::bind_method(D_METHOD("window_set_min_size", "min_size", "window_id"), &DisplayServer::window_set_min_size, DEFVAL(MAIN_WINDOW_ID));
  759. ClassDB::bind_method(D_METHOD("window_get_size_with_decorations", "window_id"), &DisplayServer::window_get_size_with_decorations, DEFVAL(MAIN_WINDOW_ID));
  760. ClassDB::bind_method(D_METHOD("window_get_mode", "window_id"), &DisplayServer::window_get_mode, DEFVAL(MAIN_WINDOW_ID));
  761. ClassDB::bind_method(D_METHOD("window_set_mode", "mode", "window_id"), &DisplayServer::window_set_mode, DEFVAL(MAIN_WINDOW_ID));
  762. ClassDB::bind_method(D_METHOD("window_set_flag", "flag", "enabled", "window_id"), &DisplayServer::window_set_flag, DEFVAL(MAIN_WINDOW_ID));
  763. ClassDB::bind_method(D_METHOD("window_get_flag", "flag", "window_id"), &DisplayServer::window_get_flag, DEFVAL(MAIN_WINDOW_ID));
  764. ClassDB::bind_method(D_METHOD("window_set_window_buttons_offset", "offset", "window_id"), &DisplayServer::window_set_window_buttons_offset, DEFVAL(MAIN_WINDOW_ID));
  765. ClassDB::bind_method(D_METHOD("window_get_safe_title_margins", "window_id"), &DisplayServer::window_get_safe_title_margins, DEFVAL(MAIN_WINDOW_ID));
  766. ClassDB::bind_method(D_METHOD("window_request_attention", "window_id"), &DisplayServer::window_request_attention, DEFVAL(MAIN_WINDOW_ID));
  767. ClassDB::bind_method(D_METHOD("window_move_to_foreground", "window_id"), &DisplayServer::window_move_to_foreground, DEFVAL(MAIN_WINDOW_ID));
  768. ClassDB::bind_method(D_METHOD("window_is_focused", "window_id"), &DisplayServer::window_is_focused, DEFVAL(MAIN_WINDOW_ID));
  769. ClassDB::bind_method(D_METHOD("window_can_draw", "window_id"), &DisplayServer::window_can_draw, DEFVAL(MAIN_WINDOW_ID));
  770. ClassDB::bind_method(D_METHOD("window_set_transient", "window_id", "parent_window_id"), &DisplayServer::window_set_transient);
  771. ClassDB::bind_method(D_METHOD("window_set_exclusive", "window_id", "exclusive"), &DisplayServer::window_set_exclusive);
  772. ClassDB::bind_method(D_METHOD("window_set_ime_active", "active", "window_id"), &DisplayServer::window_set_ime_active, DEFVAL(MAIN_WINDOW_ID));
  773. ClassDB::bind_method(D_METHOD("window_set_ime_position", "position", "window_id"), &DisplayServer::window_set_ime_position, DEFVAL(MAIN_WINDOW_ID));
  774. ClassDB::bind_method(D_METHOD("window_set_vsync_mode", "vsync_mode", "window_id"), &DisplayServer::window_set_vsync_mode, DEFVAL(MAIN_WINDOW_ID));
  775. ClassDB::bind_method(D_METHOD("window_get_vsync_mode", "window_id"), &DisplayServer::window_get_vsync_mode, DEFVAL(MAIN_WINDOW_ID));
  776. ClassDB::bind_method(D_METHOD("window_is_maximize_allowed", "window_id"), &DisplayServer::window_is_maximize_allowed, DEFVAL(MAIN_WINDOW_ID));
  777. ClassDB::bind_method(D_METHOD("window_maximize_on_title_dbl_click"), &DisplayServer::window_maximize_on_title_dbl_click);
  778. ClassDB::bind_method(D_METHOD("window_minimize_on_title_dbl_click"), &DisplayServer::window_minimize_on_title_dbl_click);
  779. ClassDB::bind_method(D_METHOD("ime_get_selection"), &DisplayServer::ime_get_selection);
  780. ClassDB::bind_method(D_METHOD("ime_get_text"), &DisplayServer::ime_get_text);
  781. ClassDB::bind_method(D_METHOD("virtual_keyboard_show", "existing_text", "position", "type", "max_length", "cursor_start", "cursor_end"), &DisplayServer::virtual_keyboard_show, DEFVAL(Rect2()), DEFVAL(KEYBOARD_TYPE_DEFAULT), DEFVAL(-1), DEFVAL(-1), DEFVAL(-1));
  782. ClassDB::bind_method(D_METHOD("virtual_keyboard_hide"), &DisplayServer::virtual_keyboard_hide);
  783. ClassDB::bind_method(D_METHOD("virtual_keyboard_get_height"), &DisplayServer::virtual_keyboard_get_height);
  784. ClassDB::bind_method(D_METHOD("cursor_set_shape", "shape"), &DisplayServer::cursor_set_shape);
  785. ClassDB::bind_method(D_METHOD("cursor_get_shape"), &DisplayServer::cursor_get_shape);
  786. ClassDB::bind_method(D_METHOD("cursor_set_custom_image", "cursor", "shape", "hotspot"), &DisplayServer::cursor_set_custom_image, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2()));
  787. ClassDB::bind_method(D_METHOD("get_swap_cancel_ok"), &DisplayServer::get_swap_cancel_ok);
  788. ClassDB::bind_method(D_METHOD("enable_for_stealing_focus", "process_id"), &DisplayServer::enable_for_stealing_focus);
  789. ClassDB::bind_method(D_METHOD("dialog_show", "title", "description", "buttons", "callback"), &DisplayServer::dialog_show);
  790. ClassDB::bind_method(D_METHOD("dialog_input_text", "title", "description", "existing_text", "callback"), &DisplayServer::dialog_input_text);
  791. ClassDB::bind_method(D_METHOD("file_dialog_show", "title", "current_directory", "filename", "show_hidden", "mode", "filters", "callback"), &DisplayServer::file_dialog_show);
  792. ClassDB::bind_method(D_METHOD("file_dialog_with_options_show", "title", "current_directory", "root", "filename", "show_hidden", "mode", "filters", "options", "callback"), &DisplayServer::file_dialog_with_options_show);
  793. ClassDB::bind_method(D_METHOD("keyboard_get_layout_count"), &DisplayServer::keyboard_get_layout_count);
  794. ClassDB::bind_method(D_METHOD("keyboard_get_current_layout"), &DisplayServer::keyboard_get_current_layout);
  795. ClassDB::bind_method(D_METHOD("keyboard_set_current_layout", "index"), &DisplayServer::keyboard_set_current_layout);
  796. ClassDB::bind_method(D_METHOD("keyboard_get_layout_language", "index"), &DisplayServer::keyboard_get_layout_language);
  797. ClassDB::bind_method(D_METHOD("keyboard_get_layout_name", "index"), &DisplayServer::keyboard_get_layout_name);
  798. ClassDB::bind_method(D_METHOD("keyboard_get_keycode_from_physical", "keycode"), &DisplayServer::keyboard_get_keycode_from_physical);
  799. ClassDB::bind_method(D_METHOD("keyboard_get_label_from_physical", "keycode"), &DisplayServer::keyboard_get_label_from_physical);
  800. ClassDB::bind_method(D_METHOD("process_events"), &DisplayServer::process_events);
  801. ClassDB::bind_method(D_METHOD("force_process_and_drop_events"), &DisplayServer::force_process_and_drop_events);
  802. ClassDB::bind_method(D_METHOD("set_native_icon", "filename"), &DisplayServer::set_native_icon);
  803. ClassDB::bind_method(D_METHOD("set_icon", "image"), &DisplayServer::set_icon);
  804. ClassDB::bind_method(D_METHOD("create_status_indicator", "icon", "tooltip", "callback"), &DisplayServer::create_status_indicator);
  805. ClassDB::bind_method(D_METHOD("status_indicator_set_icon", "id", "icon"), &DisplayServer::status_indicator_set_icon);
  806. ClassDB::bind_method(D_METHOD("status_indicator_set_tooltip", "id", "tooltip"), &DisplayServer::status_indicator_set_tooltip);
  807. ClassDB::bind_method(D_METHOD("status_indicator_set_menu", "id", "menu_rid"), &DisplayServer::status_indicator_set_menu);
  808. ClassDB::bind_method(D_METHOD("status_indicator_set_callback", "id", "callback"), &DisplayServer::status_indicator_set_callback);
  809. ClassDB::bind_method(D_METHOD("status_indicator_get_rect", "id"), &DisplayServer::status_indicator_get_rect);
  810. ClassDB::bind_method(D_METHOD("delete_status_indicator", "id"), &DisplayServer::delete_status_indicator);
  811. ClassDB::bind_method(D_METHOD("tablet_get_driver_count"), &DisplayServer::tablet_get_driver_count);
  812. ClassDB::bind_method(D_METHOD("tablet_get_driver_name", "idx"), &DisplayServer::tablet_get_driver_name);
  813. ClassDB::bind_method(D_METHOD("tablet_get_current_driver"), &DisplayServer::tablet_get_current_driver);
  814. ClassDB::bind_method(D_METHOD("tablet_set_current_driver", "name"), &DisplayServer::tablet_set_current_driver);
  815. ClassDB::bind_method(D_METHOD("is_window_transparency_available"), &DisplayServer::is_window_transparency_available);
  816. ClassDB::bind_method(D_METHOD("register_additional_output", "object"), &DisplayServer::register_additional_output);
  817. ClassDB::bind_method(D_METHOD("unregister_additional_output", "object"), &DisplayServer::unregister_additional_output);
  818. ClassDB::bind_method(D_METHOD("has_additional_outputs"), &DisplayServer::has_additional_outputs);
  819. #ifndef DISABLE_DEPRECATED
  820. BIND_ENUM_CONSTANT(FEATURE_GLOBAL_MENU);
  821. #endif
  822. BIND_ENUM_CONSTANT(FEATURE_SUBWINDOWS);
  823. BIND_ENUM_CONSTANT(FEATURE_TOUCHSCREEN);
  824. BIND_ENUM_CONSTANT(FEATURE_MOUSE);
  825. BIND_ENUM_CONSTANT(FEATURE_MOUSE_WARP);
  826. BIND_ENUM_CONSTANT(FEATURE_CLIPBOARD);
  827. BIND_ENUM_CONSTANT(FEATURE_VIRTUAL_KEYBOARD);
  828. BIND_ENUM_CONSTANT(FEATURE_CURSOR_SHAPE);
  829. BIND_ENUM_CONSTANT(FEATURE_CUSTOM_CURSOR_SHAPE);
  830. BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG);
  831. BIND_ENUM_CONSTANT(FEATURE_IME);
  832. BIND_ENUM_CONSTANT(FEATURE_WINDOW_TRANSPARENCY);
  833. BIND_ENUM_CONSTANT(FEATURE_HIDPI);
  834. BIND_ENUM_CONSTANT(FEATURE_ICON);
  835. BIND_ENUM_CONSTANT(FEATURE_NATIVE_ICON);
  836. BIND_ENUM_CONSTANT(FEATURE_ORIENTATION);
  837. BIND_ENUM_CONSTANT(FEATURE_SWAP_BUFFERS);
  838. BIND_ENUM_CONSTANT(FEATURE_CLIPBOARD_PRIMARY);
  839. BIND_ENUM_CONSTANT(FEATURE_TEXT_TO_SPEECH);
  840. BIND_ENUM_CONSTANT(FEATURE_EXTEND_TO_TITLE);
  841. BIND_ENUM_CONSTANT(FEATURE_SCREEN_CAPTURE);
  842. BIND_ENUM_CONSTANT(FEATURE_STATUS_INDICATOR);
  843. BIND_ENUM_CONSTANT(FEATURE_NATIVE_HELP);
  844. BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_INPUT);
  845. BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_FILE);
  846. BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE);
  847. BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN);
  848. BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED);
  849. BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED);
  850. BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED_HIDDEN);
  851. BIND_CONSTANT(SCREEN_WITH_MOUSE_FOCUS);
  852. BIND_CONSTANT(SCREEN_WITH_KEYBOARD_FOCUS);
  853. BIND_CONSTANT(SCREEN_PRIMARY);
  854. BIND_CONSTANT(SCREEN_OF_MAIN_WINDOW);
  855. BIND_CONSTANT(MAIN_WINDOW_ID);
  856. BIND_CONSTANT(INVALID_WINDOW_ID);
  857. BIND_CONSTANT(INVALID_INDICATOR_ID);
  858. BIND_ENUM_CONSTANT(SCREEN_LANDSCAPE);
  859. BIND_ENUM_CONSTANT(SCREEN_PORTRAIT);
  860. BIND_ENUM_CONSTANT(SCREEN_REVERSE_LANDSCAPE);
  861. BIND_ENUM_CONSTANT(SCREEN_REVERSE_PORTRAIT);
  862. BIND_ENUM_CONSTANT(SCREEN_SENSOR_LANDSCAPE);
  863. BIND_ENUM_CONSTANT(SCREEN_SENSOR_PORTRAIT);
  864. BIND_ENUM_CONSTANT(SCREEN_SENSOR);
  865. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_DEFAULT);
  866. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_MULTILINE);
  867. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_NUMBER);
  868. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_NUMBER_DECIMAL);
  869. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_PHONE);
  870. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_EMAIL_ADDRESS);
  871. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_PASSWORD);
  872. BIND_ENUM_CONSTANT(KEYBOARD_TYPE_URL);
  873. BIND_ENUM_CONSTANT(CURSOR_ARROW);
  874. BIND_ENUM_CONSTANT(CURSOR_IBEAM);
  875. BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND);
  876. BIND_ENUM_CONSTANT(CURSOR_CROSS);
  877. BIND_ENUM_CONSTANT(CURSOR_WAIT);
  878. BIND_ENUM_CONSTANT(CURSOR_BUSY);
  879. BIND_ENUM_CONSTANT(CURSOR_DRAG);
  880. BIND_ENUM_CONSTANT(CURSOR_CAN_DROP);
  881. BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN);
  882. BIND_ENUM_CONSTANT(CURSOR_VSIZE);
  883. BIND_ENUM_CONSTANT(CURSOR_HSIZE);
  884. BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE);
  885. BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE);
  886. BIND_ENUM_CONSTANT(CURSOR_MOVE);
  887. BIND_ENUM_CONSTANT(CURSOR_VSPLIT);
  888. BIND_ENUM_CONSTANT(CURSOR_HSPLIT);
  889. BIND_ENUM_CONSTANT(CURSOR_HELP);
  890. BIND_ENUM_CONSTANT(CURSOR_MAX);
  891. BIND_ENUM_CONSTANT(FILE_DIALOG_MODE_OPEN_FILE);
  892. BIND_ENUM_CONSTANT(FILE_DIALOG_MODE_OPEN_FILES);
  893. BIND_ENUM_CONSTANT(FILE_DIALOG_MODE_OPEN_DIR);
  894. BIND_ENUM_CONSTANT(FILE_DIALOG_MODE_OPEN_ANY);
  895. BIND_ENUM_CONSTANT(FILE_DIALOG_MODE_SAVE_FILE);
  896. BIND_ENUM_CONSTANT(WINDOW_MODE_WINDOWED);
  897. BIND_ENUM_CONSTANT(WINDOW_MODE_MINIMIZED);
  898. BIND_ENUM_CONSTANT(WINDOW_MODE_MAXIMIZED);
  899. BIND_ENUM_CONSTANT(WINDOW_MODE_FULLSCREEN);
  900. BIND_ENUM_CONSTANT(WINDOW_MODE_EXCLUSIVE_FULLSCREEN);
  901. BIND_ENUM_CONSTANT(WINDOW_FLAG_RESIZE_DISABLED);
  902. BIND_ENUM_CONSTANT(WINDOW_FLAG_BORDERLESS);
  903. BIND_ENUM_CONSTANT(WINDOW_FLAG_ALWAYS_ON_TOP);
  904. BIND_ENUM_CONSTANT(WINDOW_FLAG_TRANSPARENT);
  905. BIND_ENUM_CONSTANT(WINDOW_FLAG_NO_FOCUS);
  906. BIND_ENUM_CONSTANT(WINDOW_FLAG_POPUP);
  907. BIND_ENUM_CONSTANT(WINDOW_FLAG_EXTEND_TO_TITLE);
  908. BIND_ENUM_CONSTANT(WINDOW_FLAG_MOUSE_PASSTHROUGH);
  909. BIND_ENUM_CONSTANT(WINDOW_FLAG_MAX);
  910. BIND_ENUM_CONSTANT(WINDOW_EVENT_MOUSE_ENTER);
  911. BIND_ENUM_CONSTANT(WINDOW_EVENT_MOUSE_EXIT);
  912. BIND_ENUM_CONSTANT(WINDOW_EVENT_FOCUS_IN);
  913. BIND_ENUM_CONSTANT(WINDOW_EVENT_FOCUS_OUT);
  914. BIND_ENUM_CONSTANT(WINDOW_EVENT_CLOSE_REQUEST);
  915. BIND_ENUM_CONSTANT(WINDOW_EVENT_GO_BACK_REQUEST);
  916. BIND_ENUM_CONSTANT(WINDOW_EVENT_DPI_CHANGE);
  917. BIND_ENUM_CONSTANT(WINDOW_EVENT_TITLEBAR_CHANGE);
  918. BIND_ENUM_CONSTANT(VSYNC_DISABLED);
  919. BIND_ENUM_CONSTANT(VSYNC_ENABLED);
  920. BIND_ENUM_CONSTANT(VSYNC_ADAPTIVE);
  921. BIND_ENUM_CONSTANT(VSYNC_MAILBOX);
  922. BIND_ENUM_CONSTANT(DISPLAY_HANDLE);
  923. BIND_ENUM_CONSTANT(WINDOW_HANDLE);
  924. BIND_ENUM_CONSTANT(WINDOW_VIEW);
  925. BIND_ENUM_CONSTANT(OPENGL_CONTEXT);
  926. BIND_ENUM_CONSTANT(TTS_UTTERANCE_STARTED);
  927. BIND_ENUM_CONSTANT(TTS_UTTERANCE_ENDED);
  928. BIND_ENUM_CONSTANT(TTS_UTTERANCE_CANCELED);
  929. BIND_ENUM_CONSTANT(TTS_UTTERANCE_BOUNDARY);
  930. }
  931. Ref<Image> DisplayServer::_get_cursor_image_from_resource(const Ref<Resource> &p_cursor, const Vector2 &p_hotspot) {
  932. Ref<Image> image;
  933. ERR_FAIL_COND_V_MSG(p_hotspot.x < 0 || p_hotspot.y < 0, image, "Hotspot outside cursor image.");
  934. Ref<Texture2D> texture = p_cursor;
  935. if (texture.is_valid()) {
  936. image = texture->get_image();
  937. } else {
  938. image = p_cursor;
  939. }
  940. ERR_FAIL_COND_V(image.is_null(), image);
  941. Size2 image_size = image->get_size();
  942. ERR_FAIL_COND_V_MSG(p_hotspot.x > image_size.width || p_hotspot.y > image_size.height, image, "Hotspot outside cursor image.");
  943. ERR_FAIL_COND_V_MSG(image_size.width > 256 || image_size.height > 256, image, "Cursor image too big. Max supported size is 256x256.");
  944. if (image->is_compressed()) {
  945. image = image->duplicate(true);
  946. Error err = image->decompress();
  947. ERR_FAIL_COND_V_MSG(err != OK, Ref<Image>(), "Couldn't decompress VRAM-compressed custom mouse cursor image. Switch to a lossless compression mode in the Import dock.");
  948. }
  949. return image;
  950. }
  951. void DisplayServer::register_create_function(const char *p_name, CreateFunction p_function, GetRenderingDriversFunction p_get_drivers) {
  952. ERR_FAIL_COND(server_create_count == MAX_SERVERS);
  953. // Headless display server is always last
  954. server_create_functions[server_create_count] = server_create_functions[server_create_count - 1];
  955. server_create_functions[server_create_count - 1].name = p_name;
  956. server_create_functions[server_create_count - 1].create_function = p_function;
  957. server_create_functions[server_create_count - 1].get_rendering_drivers_function = p_get_drivers;
  958. server_create_count++;
  959. }
  960. int DisplayServer::get_create_function_count() {
  961. return server_create_count;
  962. }
  963. const char *DisplayServer::get_create_function_name(int p_index) {
  964. ERR_FAIL_INDEX_V(p_index, server_create_count, nullptr);
  965. return server_create_functions[p_index].name;
  966. }
  967. Vector<String> DisplayServer::get_create_function_rendering_drivers(int p_index) {
  968. ERR_FAIL_INDEX_V(p_index, server_create_count, Vector<String>());
  969. return server_create_functions[p_index].get_rendering_drivers_function();
  970. }
  971. DisplayServer *DisplayServer::create(int p_index, const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error) {
  972. ERR_FAIL_INDEX_V(p_index, server_create_count, nullptr);
  973. return server_create_functions[p_index].create_function(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_position, p_resolution, p_screen, p_context, r_error);
  974. }
  975. void DisplayServer::_input_set_mouse_mode(Input::MouseMode p_mode) {
  976. singleton->mouse_set_mode(MouseMode(p_mode));
  977. }
  978. Input::MouseMode DisplayServer::_input_get_mouse_mode() {
  979. return Input::MouseMode(singleton->mouse_get_mode());
  980. }
  981. void DisplayServer::_input_warp(const Vector2 &p_to_pos) {
  982. singleton->warp_mouse(p_to_pos);
  983. }
  984. Input::CursorShape DisplayServer::_input_get_current_cursor_shape() {
  985. return (Input::CursorShape)singleton->cursor_get_shape();
  986. }
  987. void DisplayServer::_input_set_custom_mouse_cursor_func(const Ref<Resource> &p_image, Input::CursorShape p_shape, const Vector2 &p_hostspot) {
  988. singleton->cursor_set_custom_image(p_image, (CursorShape)p_shape, p_hostspot);
  989. }
  990. DisplayServer::DisplayServer() {
  991. singleton = this;
  992. Input::set_mouse_mode_func = _input_set_mouse_mode;
  993. Input::get_mouse_mode_func = _input_get_mouse_mode;
  994. Input::warp_mouse_func = _input_warp;
  995. Input::get_current_cursor_shape_func = _input_get_current_cursor_shape;
  996. Input::set_custom_mouse_cursor_func = _input_set_custom_mouse_cursor_func;
  997. }
  998. DisplayServer::~DisplayServer() {
  999. singleton = nullptr;
  1000. }