diff options
Diffstat (limited to 'servers')
| -rw-r--r-- | servers/audio/effects/audio_effect_pitch_shift.cpp | 17 | ||||
| -rw-r--r-- | servers/audio/effects/audio_effect_pitch_shift.h | 50 | ||||
| -rw-r--r-- | servers/display_server.cpp | 281 | ||||
| -rw-r--r-- | servers/display_server.h | 12 | ||||
| -rw-r--r-- | servers/native_menu.cpp | 422 | ||||
| -rw-r--r-- | servers/native_menu.h | 154 | ||||
| -rw-r--r-- | servers/register_server_types.cpp | 4 |
7 files changed, 816 insertions, 124 deletions
diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp index ddb17e050a..beca503904 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.cpp +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -87,10 +87,8 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff double magn, phase, tmp, window, real, imag; double freqPerBin, expct; long i,k, qpd, index, inFifoLatency, stepSize, fftFrameSize2; - unsigned long fftFrameBufferSize; /* set up some handy variables */ - fftFrameBufferSize = (unsigned long)fftFrameSize*sizeof(float); fftFrameSize2 = fftFrameSize/2; stepSize = fftFrameSize/osamp; freqPerBin = sampleRate/(double)fftFrameSize; @@ -162,8 +160,8 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff /* ***************** PROCESSING ******************* */ /* this does the actual pitch shifting */ - memset(gSynMagn, 0, fftFrameBufferSize); - memset(gSynFreq, 0, fftFrameBufferSize); + memset(gSynMagn, 0, fftFrameSize*sizeof(float)); + memset(gSynFreq, 0, fftFrameSize*sizeof(float)); for (k = 0; k <= fftFrameSize2; k++) { index = k*pitchShift; if (index <= fftFrameSize2) { @@ -216,7 +214,7 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff } /* shift accumulator */ - memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameBufferSize); + memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(float)); /* move input FIFO */ for (k = 0; k < inFifoLatency; k++) { gInFIFO[k] = gInFIFO[k+stepSize]; @@ -358,12 +356,3 @@ void AudioEffectPitchShift::_bind_methods() { BIND_ENUM_CONSTANT(FFT_SIZE_4096); BIND_ENUM_CONSTANT(FFT_SIZE_MAX); } - -AudioEffectPitchShift::AudioEffectPitchShift() { - pitch_scale = 1.0; - oversampling = 4; - fft_size = FFT_SIZE_2048; - wet = 0.0; - dry = 0.0; - filter = false; -} diff --git a/servers/audio/effects/audio_effect_pitch_shift.h b/servers/audio/effects/audio_effect_pitch_shift.h index f372cc2124..949ce96057 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.h +++ b/servers/audio/effects/audio_effect_pitch_shift.h @@ -38,34 +38,22 @@ class SMBPitchShift { MAX_FRAME_LENGTH = 8192 }; - float gInFIFO[MAX_FRAME_LENGTH]; - float gOutFIFO[MAX_FRAME_LENGTH]; - float gFFTworksp[2 * MAX_FRAME_LENGTH]; - float gLastPhase[MAX_FRAME_LENGTH / 2 + 1]; - float gSumPhase[MAX_FRAME_LENGTH / 2 + 1]; - float gOutputAccum[2 * MAX_FRAME_LENGTH]; - float gAnaFreq[MAX_FRAME_LENGTH]; - float gAnaMagn[MAX_FRAME_LENGTH]; - float gSynFreq[MAX_FRAME_LENGTH]; - float gSynMagn[MAX_FRAME_LENGTH]; - long gRover; + float gInFIFO[MAX_FRAME_LENGTH] = {}; + float gOutFIFO[MAX_FRAME_LENGTH] = {}; + float gFFTworksp[2 * MAX_FRAME_LENGTH] = {}; + float gLastPhase[MAX_FRAME_LENGTH / 2 + 1] = {}; + float gSumPhase[MAX_FRAME_LENGTH / 2 + 1] = {}; + float gOutputAccum[2 * MAX_FRAME_LENGTH] = {}; + float gAnaFreq[MAX_FRAME_LENGTH] = {}; + float gAnaMagn[MAX_FRAME_LENGTH] = {}; + float gSynFreq[MAX_FRAME_LENGTH] = {}; + float gSynMagn[MAX_FRAME_LENGTH] = {}; + long gRover = 0; void smbFft(float *fftBuffer, long fftFrameSize, long sign); public: void PitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata, int stride); - - SMBPitchShift() { - gRover = 0; - memset(gInFIFO, 0, MAX_FRAME_LENGTH * sizeof(float)); - memset(gOutFIFO, 0, MAX_FRAME_LENGTH * sizeof(float)); - memset(gFFTworksp, 0, 2 * MAX_FRAME_LENGTH * sizeof(float)); - memset(gLastPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(float)); - memset(gSumPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(float)); - memset(gOutputAccum, 0, 2 * MAX_FRAME_LENGTH * sizeof(float)); - memset(gAnaFreq, 0, MAX_FRAME_LENGTH * sizeof(float)); - memset(gAnaMagn, 0, MAX_FRAME_LENGTH * sizeof(float)); - } }; class AudioEffectPitchShift; @@ -75,7 +63,7 @@ class AudioEffectPitchShiftInstance : public AudioEffectInstance { friend class AudioEffectPitchShift; Ref<AudioEffectPitchShift> base; - int fft_size; + int fft_size = 0; SMBPitchShift shift_l; SMBPitchShift shift_r; @@ -98,12 +86,12 @@ public: FFT_SIZE_MAX }; - float pitch_scale; - int oversampling; - FFTSize fft_size; - float wet; - float dry; - bool filter; + float pitch_scale = 1.0; + int oversampling = 4; + FFTSize fft_size = FFT_SIZE_2048; + float wet = 0.0; + float dry = 0.0; + bool filter = false; protected: static void _bind_methods(); @@ -119,8 +107,6 @@ public: void set_fft_size(FFTSize); FFTSize get_fft_size() const; - - AudioEffectPitchShift(); }; VARIANT_ENUM_CAST(AudioEffectPitchShift::FFTSize); diff --git a/servers/display_server.cpp b/servers/display_server.cpp index 199152b5e8..72228c25f2 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -52,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; @@ -640,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)); @@ -695,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); @@ -866,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); diff --git a/servers/display_server.h b/servers/display_server.h index 7608d76b30..85b791ca69 100644 --- a/servers/display_server.h +++ b/servers/display_server.h @@ -36,6 +36,8 @@ #include "core/os/os.h" #include "core/variant/callable.h" +#include "native_menu.h" + class Texture2D; class Image; @@ -45,6 +47,12 @@ class DisplayServer : public Object { static DisplayServer *singleton; static bool hidpi_allowed; +#ifndef DISABLE_DEPRECATED + mutable HashMap<String, RID> menu_names; + + RID _get_rid_from_name(NativeMenu *p_nmenu, const String &p_menu_root) const; +#endif + public: _FORCE_INLINE_ static DisplayServer *get_singleton() { return singleton; @@ -106,7 +114,9 @@ protected: public: enum Feature { +#ifndef DISABLE_DEPRECATED FEATURE_GLOBAL_MENU, +#endif FEATURE_SUBWINDOWS, FEATURE_TOUCHSCREEN, FEATURE_MOUSE, @@ -137,6 +147,7 @@ public: virtual void help_set_search_callbacks(const Callable &p_search_callback = Callable(), const Callable &p_action_callback = Callable()); +#ifndef DISABLE_DEPRECATED virtual void global_menu_set_popup_callbacks(const String &p_menu_root, const Callable &p_open_callback = Callable(), const Callable &p_close_callback = Callable()); virtual int global_menu_add_submenu_item(const String &p_menu_root, const String &p_label, const String &p_submenu, int p_index = -1); @@ -193,6 +204,7 @@ public: virtual void global_menu_clear(const String &p_menu_root); virtual Dictionary global_menu_get_system_menu_roots() const; +#endif struct TTSUtterance { String text; diff --git a/servers/native_menu.cpp b/servers/native_menu.cpp new file mode 100644 index 0000000000..4372c10707 --- /dev/null +++ b/servers/native_menu.cpp @@ -0,0 +1,422 @@ +/**************************************************************************/ +/* native_menu.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "native_menu.h" + +#include "scene/resources/image_texture.h" + +NativeMenu *NativeMenu::singleton = nullptr; + +void NativeMenu::_bind_methods() { + ClassDB::bind_method(D_METHOD("has_feature", "feature"), &NativeMenu::has_feature); + + ClassDB::bind_method(D_METHOD("has_system_menu", "menu_id"), &NativeMenu::has_system_menu); + ClassDB::bind_method(D_METHOD("get_system_menu", "menu_id"), &NativeMenu::get_system_menu); + ClassDB::bind_method(D_METHOD("get_system_menu_name", "menu_id"), &NativeMenu::get_system_menu_name); + + ClassDB::bind_method(D_METHOD("create_menu"), &NativeMenu::create_menu); + ClassDB::bind_method(D_METHOD("has_menu", "rid"), &NativeMenu::has_menu); + ClassDB::bind_method(D_METHOD("free_menu", "rid"), &NativeMenu::free_menu); + + ClassDB::bind_method(D_METHOD("get_size", "rid"), &NativeMenu::get_size); + ClassDB::bind_method(D_METHOD("popup", "rid", "position"), &NativeMenu::popup); + + ClassDB::bind_method(D_METHOD("set_popup_open_callback", "rid", "callback"), &NativeMenu::set_popup_open_callback); + ClassDB::bind_method(D_METHOD("get_popup_open_callback", "rid"), &NativeMenu::get_popup_open_callback); + ClassDB::bind_method(D_METHOD("set_popup_close_callback", "rid", "callback"), &NativeMenu::set_popup_close_callback); + ClassDB::bind_method(D_METHOD("get_popup_close_callback", "rid"), &NativeMenu::get_popup_close_callback); + ClassDB::bind_method(D_METHOD("set_minimum_width", "rid", "width"), &NativeMenu::set_minimum_width); + ClassDB::bind_method(D_METHOD("get_minimum_width", "rid"), &NativeMenu::get_minimum_width); + + ClassDB::bind_method(D_METHOD("add_submenu_item", "rid", "label", "submenu_rid", "tag", "index"), &NativeMenu::add_submenu_item, DEFVAL(Variant()), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("add_item", "rid", "label", "callback", "key_callback", "tag", "accelerator", "index"), &NativeMenu::add_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("add_check_item", "rid", "label", "callback", "key_callback", "tag", "accelerator", "index"), &NativeMenu::add_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("add_icon_item", "rid", "icon", "label", "callback", "key_callback", "tag", "accelerator", "index"), &NativeMenu::add_icon_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("add_icon_check_item", "rid", "icon", "label", "callback", "key_callback", "tag", "accelerator", "index"), &NativeMenu::add_icon_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("add_radio_check_item", "rid", "label", "callback", "key_callback", "tag", "accelerator", "index"), &NativeMenu::add_radio_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("add_icon_radio_check_item", "rid", "icon", "label", "callback", "key_callback", "tag", "accelerator", "index"), &NativeMenu::add_icon_radio_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("add_multistate_item", "rid", "label", "max_states", "default_state", "callback", "key_callback", "tag", "accelerator", "index"), &NativeMenu::add_multistate_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("add_separator", "rid", "index"), &NativeMenu::add_separator, DEFVAL(-1)); + + ClassDB::bind_method(D_METHOD("find_item_index_with_text", "rid", "text"), &NativeMenu::find_item_index_with_text); + ClassDB::bind_method(D_METHOD("find_item_index_with_tag", "rid", "tag"), &NativeMenu::find_item_index_with_tag); + + ClassDB::bind_method(D_METHOD("is_item_checked", "rid", "idx"), &NativeMenu::is_item_checked); + ClassDB::bind_method(D_METHOD("is_item_checkable", "rid", "idx"), &NativeMenu::is_item_checkable); + ClassDB::bind_method(D_METHOD("is_item_radio_checkable", "rid", "idx"), &NativeMenu::is_item_radio_checkable); + ClassDB::bind_method(D_METHOD("get_item_callback", "rid", "idx"), &NativeMenu::get_item_callback); + ClassDB::bind_method(D_METHOD("get_item_key_callback", "rid", "idx"), &NativeMenu::get_item_key_callback); + ClassDB::bind_method(D_METHOD("get_item_tag", "rid", "idx"), &NativeMenu::get_item_tag); + ClassDB::bind_method(D_METHOD("get_item_text", "rid", "idx"), &NativeMenu::get_item_text); + ClassDB::bind_method(D_METHOD("get_item_submenu", "rid", "idx"), &NativeMenu::get_item_submenu); + ClassDB::bind_method(D_METHOD("get_item_accelerator", "rid", "idx"), &NativeMenu::get_item_accelerator); + ClassDB::bind_method(D_METHOD("is_item_disabled", "rid", "idx"), &NativeMenu::is_item_disabled); + ClassDB::bind_method(D_METHOD("is_item_hidden", "rid", "idx"), &NativeMenu::is_item_hidden); + ClassDB::bind_method(D_METHOD("get_item_tooltip", "rid", "idx"), &NativeMenu::get_item_tooltip); + ClassDB::bind_method(D_METHOD("get_item_state", "rid", "idx"), &NativeMenu::get_item_state); + ClassDB::bind_method(D_METHOD("get_item_max_states", "rid", "idx"), &NativeMenu::get_item_max_states); + ClassDB::bind_method(D_METHOD("get_item_icon", "rid", "idx"), &NativeMenu::get_item_icon); + ClassDB::bind_method(D_METHOD("get_item_indentation_level", "rid", "idx"), &NativeMenu::get_item_indentation_level); + + ClassDB::bind_method(D_METHOD("set_item_checked", "rid", "idx", "checked"), &NativeMenu::set_item_checked); + ClassDB::bind_method(D_METHOD("set_item_checkable", "rid", "idx", "checkable"), &NativeMenu::set_item_checkable); + ClassDB::bind_method(D_METHOD("set_item_radio_checkable", "rid", "idx", "checkable"), &NativeMenu::set_item_radio_checkable); + ClassDB::bind_method(D_METHOD("set_item_callback", "rid", "idx", "callback"), &NativeMenu::set_item_callback); + ClassDB::bind_method(D_METHOD("set_item_hover_callbacks", "rid", "idx", "callback"), &NativeMenu::set_item_hover_callbacks); + ClassDB::bind_method(D_METHOD("set_item_key_callback", "rid", "idx", "key_callback"), &NativeMenu::set_item_key_callback); + ClassDB::bind_method(D_METHOD("set_item_tag", "rid", "idx", "tag"), &NativeMenu::set_item_tag); + ClassDB::bind_method(D_METHOD("set_item_text", "rid", "idx", "text"), &NativeMenu::set_item_text); + ClassDB::bind_method(D_METHOD("set_item_submenu", "rid", "idx", "submenu_rid"), &NativeMenu::set_item_submenu); + ClassDB::bind_method(D_METHOD("set_item_accelerator", "rid", "idx", "keycode"), &NativeMenu::set_item_accelerator); + ClassDB::bind_method(D_METHOD("set_item_disabled", "rid", "idx", "disabled"), &NativeMenu::set_item_disabled); + ClassDB::bind_method(D_METHOD("set_item_hidden", "rid", "idx", "hidden"), &NativeMenu::set_item_hidden); + ClassDB::bind_method(D_METHOD("set_item_tooltip", "rid", "idx", "tooltip"), &NativeMenu::set_item_tooltip); + ClassDB::bind_method(D_METHOD("set_item_state", "rid", "idx", "state"), &NativeMenu::set_item_state); + ClassDB::bind_method(D_METHOD("set_item_max_states", "rid", "idx", "max_states"), &NativeMenu::set_item_max_states); + ClassDB::bind_method(D_METHOD("set_item_icon", "rid", "idx", "icon"), &NativeMenu::set_item_icon); + ClassDB::bind_method(D_METHOD("set_item_indentation_level", "rid", "idx", "level"), &NativeMenu::set_item_indentation_level); + + ClassDB::bind_method(D_METHOD("get_item_count", "rid"), &NativeMenu::get_item_count); + ClassDB::bind_method(D_METHOD("is_system_menu", "rid"), &NativeMenu::is_system_menu); + + ClassDB::bind_method(D_METHOD("remove_item", "rid", "idx"), &NativeMenu::remove_item); + ClassDB::bind_method(D_METHOD("clear", "rid"), &NativeMenu::clear); + + BIND_ENUM_CONSTANT(FEATURE_GLOBAL_MENU); + BIND_ENUM_CONSTANT(FEATURE_POPUP_MENU); + + BIND_ENUM_CONSTANT(INVALID_MENU_ID); + BIND_ENUM_CONSTANT(MAIN_MENU_ID); + BIND_ENUM_CONSTANT(APPLICATION_MENU_ID); + BIND_ENUM_CONSTANT(WINDOW_MENU_ID); + BIND_ENUM_CONSTANT(HELP_MENU_ID); + BIND_ENUM_CONSTANT(DOCK_MENU_ID); +} + +bool NativeMenu::has_feature(Feature p_feature) const { + return false; +} + +bool NativeMenu::has_system_menu(SystemMenus p_menu_id) const { + return false; +} + +RID NativeMenu::get_system_menu(SystemMenus p_menu_id) const { + WARN_PRINT("Global menus are not supported on this platform."); + return RID(); +} + +String NativeMenu::get_system_menu_name(SystemMenus p_menu_id) const { + switch (p_menu_id) { + case MAIN_MENU_ID: + return "Main menu"; + case APPLICATION_MENU_ID: + return "Application menu"; + case WINDOW_MENU_ID: + return "Window menu"; + case HELP_MENU_ID: + return "Help menu"; + case DOCK_MENU_ID: + return "Dock menu"; + default: + return "Invalid"; + } +} + +RID NativeMenu::create_menu() { + WARN_PRINT("Global menus are not supported on this platform."); + return RID(); +} + +bool NativeMenu::has_menu(const RID &p_rid) const { + WARN_PRINT("Global menus are not supported on this platform."); + return false; +} + +void NativeMenu::free_menu(const RID &p_rid) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +Size2 NativeMenu::get_size(const RID &p_rid) const { + WARN_PRINT("Global menus are not supported on this platform."); + return Size2(); +} + +void NativeMenu::popup(const RID &p_rid, const Vector2i &p_position) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_popup_open_callback(const RID &p_rid, const Callable &p_callback) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +Callable NativeMenu::get_popup_open_callback(const RID &p_rid) const { + WARN_PRINT("Global menus are not supported on this platform."); + return Callable(); +} + +void NativeMenu::set_popup_close_callback(const RID &p_rid, const Callable &p_callback) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +Callable NativeMenu::get_popup_close_callback(const RID &p_rid) const { + WARN_PRINT("Global menus are not supported on this platform."); + return Callable(); +} + +void NativeMenu::set_minimum_width(const RID &p_rid, float p_width) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +float NativeMenu::get_minimum_width(const RID &p_rid) const { + WARN_PRINT("Global menus are not supported on this platform."); + return 0.f; +} + +int NativeMenu::add_submenu_item(const RID &p_rid, const String &p_label, const RID &p_submenu_rid, const Variant &p_tag, int p_index) { + WARN_PRINT("Global menus are not supported on this platform."); + return -1; +} + +int NativeMenu::add_item(const RID &p_rid, 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 are not supported on this platform."); + return -1; +} + +int NativeMenu::add_check_item(const RID &p_rid, 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 are not supported on this platform."); + return -1; +} + +int NativeMenu::add_icon_item(const RID &p_rid, 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 are not supported on this platform."); + return -1; +} + +int NativeMenu::add_icon_check_item(const RID &p_rid, 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 are not supported on this platform."); + return -1; +} + +int NativeMenu::add_radio_check_item(const RID &p_rid, 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 are not supported on this platform."); + return -1; +} + +int NativeMenu::add_icon_radio_check_item(const RID &p_rid, 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 are not supported on this platform."); + return -1; +} + +int NativeMenu::add_multistate_item(const RID &p_rid, 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 are not supported on this platform."); + return -1; +} + +int NativeMenu::add_separator(const RID &p_rid, int p_index) { + WARN_PRINT("Global menus are not supported on this platform."); + return -1; +} + +int NativeMenu::find_item_index_with_text(const RID &p_rid, const String &p_text) const { + WARN_PRINT("Global menus are not supported on this platform."); + return -1; +} + +int NativeMenu::find_item_index_with_tag(const RID &p_rid, const Variant &p_tag) const { + WARN_PRINT("Global menus are not supported on this platform."); + return -1; +} + +bool NativeMenu::is_item_checked(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return false; +} + +bool NativeMenu::is_item_checkable(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return false; +} + +bool NativeMenu::is_item_radio_checkable(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return false; +} + +Callable NativeMenu::get_item_callback(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return Callable(); +} + +Callable NativeMenu::get_item_key_callback(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return Callable(); +} + +Variant NativeMenu::get_item_tag(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return Variant(); +} + +String NativeMenu::get_item_text(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return String(); +} + +RID NativeMenu::get_item_submenu(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return RID(); +} + +Key NativeMenu::get_item_accelerator(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return Key::NONE; +} + +bool NativeMenu::is_item_disabled(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return false; +} + +bool NativeMenu::is_item_hidden(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return false; +} + +String NativeMenu::get_item_tooltip(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return String(); +} + +int NativeMenu::get_item_state(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return -1; +} + +int NativeMenu::get_item_max_states(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return -1; +} + +Ref<Texture2D> NativeMenu::get_item_icon(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return Ref<Texture2D>(); +} + +int NativeMenu::get_item_indentation_level(const RID &p_rid, int p_idx) const { + WARN_PRINT("Global menus are not supported on this platform."); + return 0; +} + +void NativeMenu::set_item_checked(const RID &p_rid, int p_idx, bool p_checked) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_checkable(const RID &p_rid, int p_idx, bool p_checkable) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_radio_checkable(const RID &p_rid, int p_idx, bool p_checkable) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_callback(const RID &p_rid, int p_idx, const Callable &p_callback) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_key_callback(const RID &p_rid, int p_idx, const Callable &p_key_callback) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_hover_callbacks(const RID &p_rid, int p_idx, const Callable &p_callback) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_tag(const RID &p_rid, int p_idx, const Variant &p_tag) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_text(const RID &p_rid, int p_idx, const String &p_text) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_submenu(const RID &p_rid, int p_idx, const RID &p_submenu_rid) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_accelerator(const RID &p_rid, int p_idx, Key p_keycode) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_disabled(const RID &p_rid, int p_idx, bool p_disabled) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_hidden(const RID &p_rid, int p_idx, bool p_hidden) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_tooltip(const RID &p_rid, int p_idx, const String &p_tooltip) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_state(const RID &p_rid, int p_idx, int p_state) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_max_states(const RID &p_rid, int p_idx, int p_max_states) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_icon(const RID &p_rid, int p_idx, const Ref<Texture2D> &p_icon) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::set_item_indentation_level(const RID &p_rid, int p_idx, int p_level) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +int NativeMenu::get_item_count(const RID &p_rid) const { + WARN_PRINT("Global menus are not supported on this platform."); + return 0; +} + +bool NativeMenu::is_system_menu(const RID &p_rid) const { + WARN_PRINT("Global menus are not supported on this platform."); + return false; +} + +void NativeMenu::remove_item(const RID &p_rid, int p_idx) { + WARN_PRINT("Global menus are not supported on this platform."); +} + +void NativeMenu::clear(const RID &p_rid) { + WARN_PRINT("Global menus are not supported on this platform."); +} diff --git a/servers/native_menu.h b/servers/native_menu.h new file mode 100644 index 0000000000..bb61caa633 --- /dev/null +++ b/servers/native_menu.h @@ -0,0 +1,154 @@ +/**************************************************************************/ +/* native_menu.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef NATIVE_MENU_H +#define NATIVE_MENU_H + +#include "core/input/input.h" +#include "core/io/resource.h" +#include "core/os/os.h" +#include "core/variant/callable.h" + +class Texture2D; + +class NativeMenu : public Object { + GDCLASS(NativeMenu, Object) + + static NativeMenu *singleton; + +protected: + static void _bind_methods(); + +public: + _FORCE_INLINE_ static NativeMenu *get_singleton() { + return singleton; + } + + enum Feature { + FEATURE_GLOBAL_MENU, + FEATURE_POPUP_MENU, + }; + + enum SystemMenus { + INVALID_MENU_ID, + MAIN_MENU_ID, + APPLICATION_MENU_ID, + WINDOW_MENU_ID, + HELP_MENU_ID, + DOCK_MENU_ID, + }; + + virtual bool has_feature(Feature p_feature) const; + + virtual bool has_system_menu(SystemMenus p_menu_id) const; + virtual RID get_system_menu(SystemMenus p_menu_id) const; + virtual String get_system_menu_name(SystemMenus p_menu_id) const; + + virtual RID create_menu(); + virtual bool has_menu(const RID &p_rid) const; + virtual void free_menu(const RID &p_rid); + + virtual Size2 get_size(const RID &p_rid) const; + virtual void popup(const RID &p_rid, const Vector2i &p_position); + + virtual void set_popup_open_callback(const RID &p_rid, const Callable &p_callback); + virtual Callable get_popup_open_callback(const RID &p_rid) const; + virtual void set_popup_close_callback(const RID &p_rid, const Callable &p_callback); + virtual Callable get_popup_close_callback(const RID &p_rid) const; + virtual void set_minimum_width(const RID &p_rid, float p_width); + virtual float get_minimum_width(const RID &p_rid) const; + + virtual int add_submenu_item(const RID &p_rid, const String &p_label, const RID &p_submenu_rid, const Variant &p_tag = Variant(), int p_index = -1); + virtual int add_item(const RID &p_rid, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); + virtual int add_check_item(const RID &p_rid, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); + virtual int add_icon_item(const RID &p_rid, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); + virtual int add_icon_check_item(const RID &p_rid, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); + virtual int add_radio_check_item(const RID &p_rid, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); + virtual int add_icon_radio_check_item(const RID &p_rid, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); + virtual int add_multistate_item(const RID &p_rid, const String &p_label, int p_max_states, int p_default_state, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1); + virtual int add_separator(const RID &p_rid, int p_index = -1); + + virtual int find_item_index_with_text(const RID &p_rid, const String &p_text) const; + virtual int find_item_index_with_tag(const RID &p_rid, const Variant &p_tag) const; + + virtual bool is_item_checked(const RID &p_rid, int p_idx) const; + virtual bool is_item_checkable(const RID &p_rid, int p_idx) const; + virtual bool is_item_radio_checkable(const RID &p_rid, int p_idx) const; + virtual Callable get_item_callback(const RID &p_rid, int p_idx) const; + virtual Callable get_item_key_callback(const RID &p_rid, int p_idx) const; + virtual Variant get_item_tag(const RID &p_rid, int p_idx) const; + virtual String get_item_text(const RID &p_rid, int p_idx) const; + virtual RID get_item_submenu(const RID &p_rid, int p_idx) const; + virtual Key get_item_accelerator(const RID &p_rid, int p_idx) const; + virtual bool is_item_disabled(const RID &p_rid, int p_idx) const; + virtual bool is_item_hidden(const RID &p_rid, int p_idx) const; + virtual String get_item_tooltip(const RID &p_rid, int p_idx) const; + virtual int get_item_state(const RID &p_rid, int p_idx) const; + virtual int get_item_max_states(const RID &p_rid, int p_idx) const; + virtual Ref<Texture2D> get_item_icon(const RID &p_rid, int p_idx) const; + virtual int get_item_indentation_level(const RID &p_rid, int p_idx) const; + + virtual void set_item_checked(const RID &p_rid, int p_idx, bool p_checked); + virtual void set_item_checkable(const RID &p_rid, int p_idx, bool p_checkable); + virtual void set_item_radio_checkable(const RID &p_rid, int p_idx, bool p_checkable); + virtual void set_item_callback(const RID &p_rid, int p_idx, const Callable &p_callback); + virtual void set_item_key_callback(const RID &p_rid, int p_idx, const Callable &p_key_callback); + virtual void set_item_hover_callbacks(const RID &p_rid, int p_idx, const Callable &p_callback); + virtual void set_item_tag(const RID &p_rid, int p_idx, const Variant &p_tag); + virtual void set_item_text(const RID &p_rid, int p_idx, const String &p_text); + virtual void set_item_submenu(const RID &p_rid, int p_idx, const RID &p_submenu_rid); + virtual void set_item_accelerator(const RID &p_rid, int p_idx, Key p_keycode); + virtual void set_item_disabled(const RID &p_rid, int p_idx, bool p_disabled); + virtual void set_item_hidden(const RID &p_rid, int p_idx, bool p_hidden); + virtual void set_item_tooltip(const RID &p_rid, int p_idx, const String &p_tooltip); + virtual void set_item_state(const RID &p_rid, int p_idx, int p_state); + virtual void set_item_max_states(const RID &p_rid, int p_idx, int p_max_states); + virtual void set_item_icon(const RID &p_rid, int p_idx, const Ref<Texture2D> &p_icon); + virtual void set_item_indentation_level(const RID &p_rid, int p_idx, int p_level); + + virtual int get_item_count(const RID &p_rid) const; + virtual bool is_system_menu(const RID &p_rid) const; + + virtual void remove_item(const RID &p_rid, int p_idx); + virtual void clear(const RID &p_rid); + + NativeMenu() { + singleton = this; + } + + ~NativeMenu() { + singleton = nullptr; + } +}; + +VARIANT_ENUM_CAST(NativeMenu::Feature); +VARIANT_ENUM_CAST(NativeMenu::SystemMenus); + +#endif // NATIVE_MENU_H diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index ee2a65ad91..8547ebfad6 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -60,6 +60,7 @@ #include "movie_writer/movie_writer.h" #include "movie_writer/movie_writer_mjpeg.h" #include "movie_writer/movie_writer_pngwav.h" +#include "native_menu.h" #include "rendering/renderer_compositor.h" #include "rendering/renderer_rd/framebuffer_cache_rd.h" #include "rendering/renderer_rd/storage_rd/render_data_rd.h" @@ -162,6 +163,8 @@ void register_server_types() { GDREGISTER_ABSTRACT_CLASS(RenderingServer); GDREGISTER_CLASS(AudioServer); + GDREGISTER_CLASS(NativeMenu); + GDREGISTER_ABSTRACT_CLASS(NavigationServer2D); GDREGISTER_ABSTRACT_CLASS(NavigationServer3D); GDREGISTER_CLASS(NavigationPathQueryParameters2D); @@ -361,6 +364,7 @@ void register_server_singletons() { #ifndef _3D_DISABLED Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3D", PhysicsServer3D::get_singleton(), "PhysicsServer3D")); #endif // _3D_DISABLED + Engine::get_singleton()->add_singleton(Engine::Singleton("NativeMenu", NativeMenu::get_singleton(), "NativeMenu")); Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer2D", NavigationServer2D::get_singleton(), "NavigationServer2D")); Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton(), "NavigationServer3D")); Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer", XRServer::get_singleton(), "XRServer")); |
