diff options
Diffstat (limited to 'servers/display_server.cpp')
-rw-r--r-- | servers/display_server.cpp | 329 |
1 files changed, 247 insertions, 82 deletions
diff --git a/servers/display_server.cpp b/servers/display_server.cpp index 6631d44f63..9ceb6909fe 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -31,6 +31,7 @@ #include "display_server.h" #include "core/input/input.h" +#include "scene/resources/atlas_texture.h" #include "scene/resources/texture.h" #include "servers/display_server_headless.h" @@ -51,231 +52,352 @@ void DisplayServer::help_set_search_callbacks(const Callable &p_search_callback, WARN_PRINT("Native help is not supported by this display server."); } +#ifndef DISABLE_DEPRECATED + +RID DisplayServer::_get_rid_from_name(NativeMenu *p_nmenu, const String &p_menu_root) const { + if (p_menu_root == "_main") { + return p_nmenu->get_system_menu(NativeMenu::MAIN_MENU_ID); + } else if (p_menu_root == "_apple") { + return p_nmenu->get_system_menu(NativeMenu::APPLICATION_MENU_ID); + } else if (p_menu_root == "_dock") { + return p_nmenu->get_system_menu(NativeMenu::DOCK_MENU_ID); + } else if (p_menu_root == "_help") { + return p_nmenu->get_system_menu(NativeMenu::HELP_MENU_ID); + } else if (p_menu_root == "_window") { + return p_nmenu->get_system_menu(NativeMenu::WINDOW_MENU_ID); + } else if (menu_names.has(p_menu_root)) { + return menu_names[p_menu_root]; + } + + RID rid = p_nmenu->create_menu(); + menu_names[p_menu_root] = rid; + return rid; +} + 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) { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + 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); } 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) { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + 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); } 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) { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + 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); } 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) { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + 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); } 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) { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + 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); } 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) { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + 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); } 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) { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + 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); } -void DisplayServer::global_menu_set_popup_callbacks(const String &p_menu_root, const Callable &p_open_callbacs, const Callable &p_close_callback) { - WARN_PRINT("Global menus not supported by this display server."); +void DisplayServer::global_menu_set_popup_callbacks(const String &p_menu_root, const Callable &p_open_callback, const Callable &p_close_callback) { + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_popup_open_callback(_get_rid_from_name(nmenu, p_menu_root), p_open_callback); + nmenu->set_popup_open_callback(_get_rid_from_name(nmenu, p_menu_root), p_close_callback); } int DisplayServer::global_menu_add_submenu_item(const String &p_menu_root, const String &p_label, const String &p_submenu, int p_index) { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + 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); } int DisplayServer::global_menu_add_separator(const String &p_menu_root, int p_index) { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + return nmenu->add_separator(_get_rid_from_name(nmenu, p_menu_root), p_index); } int DisplayServer::global_menu_get_item_index_from_text(const String &p_menu_root, const String &p_text) const { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + return nmenu->find_item_index_with_text(_get_rid_from_name(nmenu, p_menu_root), p_text); } int DisplayServer::global_menu_get_item_index_from_tag(const String &p_menu_root, const Variant &p_tag) const { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + return nmenu->find_item_index_with_tag(_get_rid_from_name(nmenu, p_menu_root), p_tag); } void DisplayServer::global_menu_set_item_callback(const String &p_menu_root, int p_idx, const Callable &p_callback) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_callback); } void DisplayServer::global_menu_set_item_hover_callbacks(const String &p_menu_root, int p_idx, const Callable &p_callback) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_hover_callbacks(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_callback); } void DisplayServer::global_menu_set_item_key_callback(const String &p_menu_root, int p_idx, const Callable &p_key_callback) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_key_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_key_callback); } bool DisplayServer::global_menu_is_item_checked(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return false; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, false); + return nmenu->is_item_checked(_get_rid_from_name(nmenu, p_menu_root), p_idx); } bool DisplayServer::global_menu_is_item_checkable(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return false; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, false); + return nmenu->is_item_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx); } bool DisplayServer::global_menu_is_item_radio_checkable(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return false; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, false); + return nmenu->is_item_radio_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx); } Callable DisplayServer::global_menu_get_item_callback(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return Callable(); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, Callable()); + return nmenu->get_item_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx); } Callable DisplayServer::global_menu_get_item_key_callback(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return Callable(); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, Callable()); + return nmenu->get_item_key_callback(_get_rid_from_name(nmenu, p_menu_root), p_idx); } Variant DisplayServer::global_menu_get_item_tag(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return Variant(); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, Variant()); + return nmenu->get_item_tag(_get_rid_from_name(nmenu, p_menu_root), p_idx); } String DisplayServer::global_menu_get_item_text(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return String(); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, String()); + return nmenu->get_item_text(_get_rid_from_name(nmenu, p_menu_root), p_idx); } String DisplayServer::global_menu_get_item_submenu(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, String()); + RID rid = nmenu->get_item_submenu(_get_rid_from_name(nmenu, p_menu_root), p_idx); + if (!nmenu->is_system_menu(rid)) { + for (HashMap<String, RID>::Iterator E = menu_names.begin(); E;) { + if (E->value == rid) { + return E->key; + } + } + } return String(); } Key DisplayServer::global_menu_get_item_accelerator(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return Key::NONE; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, Key::NONE); + return nmenu->get_item_accelerator(_get_rid_from_name(nmenu, p_menu_root), p_idx); } bool DisplayServer::global_menu_is_item_disabled(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return false; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, false); + return nmenu->is_item_disabled(_get_rid_from_name(nmenu, p_menu_root), p_idx); } bool DisplayServer::global_menu_is_item_hidden(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return false; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, false); + return nmenu->is_item_hidden(_get_rid_from_name(nmenu, p_menu_root), p_idx); } String DisplayServer::global_menu_get_item_tooltip(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return String(); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, String()); + return nmenu->get_item_tooltip(_get_rid_from_name(nmenu, p_menu_root), p_idx); } int DisplayServer::global_menu_get_item_state(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + return nmenu->get_item_state(_get_rid_from_name(nmenu, p_menu_root), p_idx); } int DisplayServer::global_menu_get_item_max_states(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return -1; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, -1); + return nmenu->get_item_max_states(_get_rid_from_name(nmenu, p_menu_root), p_idx); } Ref<Texture2D> DisplayServer::global_menu_get_item_icon(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return Ref<Texture2D>(); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, Ref<Texture2D>()); + return nmenu->get_item_icon(_get_rid_from_name(nmenu, p_menu_root), p_idx); } int DisplayServer::global_menu_get_item_indentation_level(const String &p_menu_root, int p_idx) const { - WARN_PRINT("Global menus not supported by this display server."); - return 0; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, 0); + return nmenu->get_item_indentation_level(_get_rid_from_name(nmenu, p_menu_root), p_idx); } void DisplayServer::global_menu_set_item_checked(const String &p_menu_root, int p_idx, bool p_checked) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_checked(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_checked); } void DisplayServer::global_menu_set_item_checkable(const String &p_menu_root, int p_idx, bool p_checkable) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_checkable); } void DisplayServer::global_menu_set_item_radio_checkable(const String &p_menu_root, int p_idx, bool p_checkable) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_radio_checkable(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_checkable); } void DisplayServer::global_menu_set_item_tag(const String &p_menu_root, int p_idx, const Variant &p_tag) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_tag(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_tag); } void DisplayServer::global_menu_set_item_text(const String &p_menu_root, int p_idx, const String &p_text) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_text(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_text); } void DisplayServer::global_menu_set_item_submenu(const String &p_menu_root, int p_idx, const String &p_submenu) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_submenu(_get_rid_from_name(nmenu, p_menu_root), p_idx, _get_rid_from_name(nmenu, p_submenu)); } void DisplayServer::global_menu_set_item_accelerator(const String &p_menu_root, int p_idx, Key p_keycode) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_accelerator(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_keycode); } void DisplayServer::global_menu_set_item_disabled(const String &p_menu_root, int p_idx, bool p_disabled) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_disabled(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_disabled); } void DisplayServer::global_menu_set_item_hidden(const String &p_menu_root, int p_idx, bool p_hidden) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_hidden(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_hidden); } void DisplayServer::global_menu_set_item_tooltip(const String &p_menu_root, int p_idx, const String &p_tooltip) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_tooltip(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_tooltip); } void DisplayServer::global_menu_set_item_state(const String &p_menu_root, int p_idx, int p_state) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_state(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_state); } void DisplayServer::global_menu_set_item_max_states(const String &p_menu_root, int p_idx, int p_max_states) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_max_states(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_max_states); } void DisplayServer::global_menu_set_item_icon(const String &p_menu_root, int p_idx, const Ref<Texture2D> &p_icon) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_icon(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_icon); } void DisplayServer::global_menu_set_item_indentation_level(const String &p_menu_root, int p_idx, int p_level) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->set_item_indentation_level(_get_rid_from_name(nmenu, p_menu_root), p_idx, p_level); } int DisplayServer::global_menu_get_item_count(const String &p_menu_root) const { - WARN_PRINT("Global menus not supported by this display server."); - return 0; + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, 0); + return nmenu->get_item_count(_get_rid_from_name(nmenu, p_menu_root)); } void DisplayServer::global_menu_remove_item(const String &p_menu_root, int p_idx) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + nmenu->remove_item(_get_rid_from_name(nmenu, p_menu_root), p_idx); } void DisplayServer::global_menu_clear(const String &p_menu_root) { - WARN_PRINT("Global menus not supported by this display server."); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL(nmenu); + RID rid = _get_rid_from_name(nmenu, p_menu_root); + nmenu->clear(rid); + if (!nmenu->is_system_menu(rid)) { + nmenu->free_menu(rid); + menu_names.erase(p_menu_root); + } } Dictionary DisplayServer::global_menu_get_system_menu_roots() const { - WARN_PRINT("Global menus not supported by this display server."); - return Dictionary(); + NativeMenu *nmenu = NativeMenu::get_singleton(); + ERR_FAIL_NULL_V(nmenu, Dictionary()); + + Dictionary out; + if (nmenu->has_system_menu(NativeMenu::DOCK_MENU_ID)) { + out["_dock"] = "@Dock"; + } + if (nmenu->has_system_menu(NativeMenu::APPLICATION_MENU_ID)) { + out["_apple"] = "@Apple"; + } + if (nmenu->has_system_menu(NativeMenu::WINDOW_MENU_ID)) { + out["_window"] = "Window"; + } + if (nmenu->has_system_menu(NativeMenu::HELP_MENU_ID)) { + out["_help"] = "Help"; + } + return out; } +#endif + bool DisplayServer::tts_is_speaking() const { WARN_PRINT("TTS is not supported by this display server."); return false; @@ -523,22 +645,22 @@ void DisplayServer::enable_for_stealing_focus(OS::ProcessID pid) { Error DisplayServer::dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) { WARN_PRINT("Native dialogs not supported by this display server."); - return OK; + return ERR_UNAVAILABLE; } Error DisplayServer::dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback) { WARN_PRINT("Native dialogs not supported by this display server."); - return OK; + return ERR_UNAVAILABLE; } 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) { WARN_PRINT("Native dialogs not supported by this display server."); - return OK; + return ERR_UNAVAILABLE; } 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) { WARN_PRINT("Native dialogs not supported by this display server."); - return OK; + return ERR_UNAVAILABLE; } int DisplayServer::keyboard_get_layout_count() const { @@ -639,6 +761,7 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("help_set_search_callbacks", "search_callback", "action_callback"), &DisplayServer::help_set_search_callbacks); +#ifndef DISABLE_DEPRECATED ClassDB::bind_method(D_METHOD("global_menu_set_popup_callbacks", "menu_root", "open_callback", "close_callback"), &DisplayServer::global_menu_set_popup_callbacks); ClassDB::bind_method(D_METHOD("global_menu_add_submenu_item", "menu_root", "label", "submenu", "index"), &DisplayServer::global_menu_add_submenu_item, DEFVAL(-1)); 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)); @@ -694,6 +817,7 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("global_menu_clear", "menu_root"), &DisplayServer::global_menu_clear); ClassDB::bind_method(D_METHOD("global_menu_get_system_menu_roots"), &DisplayServer::global_menu_get_system_menu_roots); +#endif ClassDB::bind_method(D_METHOD("tts_is_speaking"), &DisplayServer::tts_is_speaking); ClassDB::bind_method(D_METHOD("tts_is_paused"), &DisplayServer::tts_is_paused); @@ -865,7 +989,9 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("tablet_get_current_driver"), &DisplayServer::tablet_get_current_driver); ClassDB::bind_method(D_METHOD("tablet_set_current_driver", "name"), &DisplayServer::tablet_set_current_driver); +#ifndef DISABLE_DEPRECATED BIND_ENUM_CONSTANT(FEATURE_GLOBAL_MENU); +#endif BIND_ENUM_CONSTANT(FEATURE_SUBWINDOWS); BIND_ENUM_CONSTANT(FEATURE_TOUCHSCREEN); BIND_ENUM_CONSTANT(FEATURE_MOUSE); @@ -888,6 +1014,8 @@ void DisplayServer::_bind_methods() { BIND_ENUM_CONSTANT(FEATURE_SCREEN_CAPTURE); BIND_ENUM_CONSTANT(FEATURE_STATUS_INDICATOR); BIND_ENUM_CONSTANT(FEATURE_NATIVE_HELP); + BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_INPUT); + BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_FILE); BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE); BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN); @@ -987,6 +1115,43 @@ void DisplayServer::_bind_methods() { BIND_ENUM_CONSTANT(TTS_UTTERANCE_BOUNDARY); } +Ref<Image> DisplayServer::_get_cursor_image_from_resource(const Ref<Resource> &p_cursor, const Vector2 &p_hotspot, Rect2 &r_atlas_rect) { + Ref<Image> image; + ERR_FAIL_COND_V_MSG(p_hotspot.x < 0 || p_hotspot.y < 0, image, "Hotspot outside cursor image."); + + Size2 texture_size; + + Ref<Texture2D> texture = p_cursor; + if (texture.is_valid()) { + Ref<AtlasTexture> atlas_texture = p_cursor; + + if (atlas_texture.is_valid()) { + texture = atlas_texture->get_atlas(); + r_atlas_rect.size = texture->get_size(); + r_atlas_rect.position = atlas_texture->get_region().position; + texture_size = atlas_texture->get_region().size; + } else { + texture_size = texture->get_size(); + } + image = texture->get_image(); + } else { + image = p_cursor; + ERR_FAIL_COND_V(image.is_null(), image); + texture_size = image->get_size(); + } + + ERR_FAIL_COND_V_MSG(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height, image, "Hotspot outside cursor image."); + ERR_FAIL_COND_V_MSG(texture_size.width > 256 || texture_size.height > 256, image, "Cursor image too big. Max supported size is 256x256."); + + ERR_FAIL_COND_V(image.is_null(), image); + if (image->is_compressed()) { + image = image->duplicate(true); + Error err = image->decompress(); + 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."); + } + return image; +} + void DisplayServer::register_create_function(const char *p_name, CreateFunction p_function, GetRenderingDriversFunction p_get_drivers) { ERR_FAIL_COND(server_create_count == MAX_SERVERS); // Headless display server is always last |