native_menu.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**************************************************************************/
  2. /* native_menu.h */
  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. #ifndef NATIVE_MENU_H
  31. #define NATIVE_MENU_H
  32. #include "core/input/input.h"
  33. #include "core/io/resource.h"
  34. #include "core/os/os.h"
  35. #include "core/variant/callable.h"
  36. class Texture2D;
  37. class NativeMenu : public Object {
  38. GDCLASS(NativeMenu, Object)
  39. static NativeMenu *singleton;
  40. protected:
  41. static void _bind_methods();
  42. public:
  43. _FORCE_INLINE_ static NativeMenu *get_singleton() {
  44. return singleton;
  45. }
  46. enum Feature {
  47. FEATURE_GLOBAL_MENU,
  48. FEATURE_POPUP_MENU,
  49. FEATURE_OPEN_CLOSE_CALLBACK,
  50. FEATURE_HOVER_CALLBACK,
  51. FEATURE_KEY_CALLBACK,
  52. };
  53. enum SystemMenus {
  54. INVALID_MENU_ID,
  55. MAIN_MENU_ID,
  56. APPLICATION_MENU_ID,
  57. WINDOW_MENU_ID,
  58. HELP_MENU_ID,
  59. DOCK_MENU_ID,
  60. };
  61. virtual bool has_feature(Feature p_feature) const;
  62. virtual bool has_system_menu(SystemMenus p_menu_id) const;
  63. virtual RID get_system_menu(SystemMenus p_menu_id) const;
  64. virtual String get_system_menu_name(SystemMenus p_menu_id) const;
  65. virtual RID create_menu();
  66. virtual bool has_menu(const RID &p_rid) const;
  67. virtual void free_menu(const RID &p_rid);
  68. virtual Size2 get_size(const RID &p_rid) const;
  69. virtual void popup(const RID &p_rid, const Vector2i &p_position);
  70. virtual void set_interface_direction(const RID &p_rid, bool p_is_rtl);
  71. virtual void set_popup_open_callback(const RID &p_rid, const Callable &p_callback);
  72. virtual Callable get_popup_open_callback(const RID &p_rid) const;
  73. virtual void set_popup_close_callback(const RID &p_rid, const Callable &p_callback);
  74. virtual Callable get_popup_close_callback(const RID &p_rid) const;
  75. virtual void set_minimum_width(const RID &p_rid, float p_width);
  76. virtual float get_minimum_width(const RID &p_rid) const;
  77. virtual bool is_opened(const RID &p_rid) const;
  78. 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);
  79. 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);
  80. 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);
  81. 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);
  82. 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);
  83. 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);
  84. 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);
  85. 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);
  86. virtual int add_separator(const RID &p_rid, int p_index = -1);
  87. virtual int find_item_index_with_text(const RID &p_rid, const String &p_text) const;
  88. virtual int find_item_index_with_tag(const RID &p_rid, const Variant &p_tag) const;
  89. virtual int find_item_index_with_submenu(const RID &p_rid, const RID &p_submenu_rid) const;
  90. virtual bool is_item_checked(const RID &p_rid, int p_idx) const;
  91. virtual bool is_item_checkable(const RID &p_rid, int p_idx) const;
  92. virtual bool is_item_radio_checkable(const RID &p_rid, int p_idx) const;
  93. virtual Callable get_item_callback(const RID &p_rid, int p_idx) const;
  94. virtual Callable get_item_key_callback(const RID &p_rid, int p_idx) const;
  95. virtual Variant get_item_tag(const RID &p_rid, int p_idx) const;
  96. virtual String get_item_text(const RID &p_rid, int p_idx) const;
  97. virtual RID get_item_submenu(const RID &p_rid, int p_idx) const;
  98. virtual Key get_item_accelerator(const RID &p_rid, int p_idx) const;
  99. virtual bool is_item_disabled(const RID &p_rid, int p_idx) const;
  100. virtual bool is_item_hidden(const RID &p_rid, int p_idx) const;
  101. virtual String get_item_tooltip(const RID &p_rid, int p_idx) const;
  102. virtual int get_item_state(const RID &p_rid, int p_idx) const;
  103. virtual int get_item_max_states(const RID &p_rid, int p_idx) const;
  104. virtual Ref<Texture2D> get_item_icon(const RID &p_rid, int p_idx) const;
  105. virtual int get_item_indentation_level(const RID &p_rid, int p_idx) const;
  106. virtual void set_item_checked(const RID &p_rid, int p_idx, bool p_checked);
  107. virtual void set_item_checkable(const RID &p_rid, int p_idx, bool p_checkable);
  108. virtual void set_item_radio_checkable(const RID &p_rid, int p_idx, bool p_checkable);
  109. virtual void set_item_callback(const RID &p_rid, int p_idx, const Callable &p_callback);
  110. virtual void set_item_key_callback(const RID &p_rid, int p_idx, const Callable &p_key_callback);
  111. virtual void set_item_hover_callbacks(const RID &p_rid, int p_idx, const Callable &p_callback);
  112. virtual void set_item_tag(const RID &p_rid, int p_idx, const Variant &p_tag);
  113. virtual void set_item_text(const RID &p_rid, int p_idx, const String &p_text);
  114. virtual void set_item_submenu(const RID &p_rid, int p_idx, const RID &p_submenu_rid);
  115. virtual void set_item_accelerator(const RID &p_rid, int p_idx, Key p_keycode);
  116. virtual void set_item_disabled(const RID &p_rid, int p_idx, bool p_disabled);
  117. virtual void set_item_hidden(const RID &p_rid, int p_idx, bool p_hidden);
  118. virtual void set_item_tooltip(const RID &p_rid, int p_idx, const String &p_tooltip);
  119. virtual void set_item_state(const RID &p_rid, int p_idx, int p_state);
  120. virtual void set_item_max_states(const RID &p_rid, int p_idx, int p_max_states);
  121. virtual void set_item_icon(const RID &p_rid, int p_idx, const Ref<Texture2D> &p_icon);
  122. virtual void set_item_indentation_level(const RID &p_rid, int p_idx, int p_level);
  123. virtual int get_item_count(const RID &p_rid) const;
  124. virtual bool is_system_menu(const RID &p_rid) const;
  125. virtual void remove_item(const RID &p_rid, int p_idx);
  126. virtual void clear(const RID &p_rid);
  127. NativeMenu() {
  128. singleton = this;
  129. }
  130. ~NativeMenu() {
  131. singleton = nullptr;
  132. }
  133. };
  134. VARIANT_ENUM_CAST(NativeMenu::Feature);
  135. VARIANT_ENUM_CAST(NativeMenu::SystemMenus);
  136. #endif // NATIVE_MENU_H