popup_menu.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*************************************************************************/
  2. /* popup_menu.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef POPUP_MENU_H
  30. #define POPUP_MENU_H
  31. #include "scene/gui/popup.h"
  32. /**
  33. @author Juan Linietsky <[email protected]>
  34. */
  35. class PopupMenu : public Popup {
  36. OBJ_TYPE(PopupMenu, Popup );
  37. struct Item {
  38. Ref<Texture> icon;
  39. String text;
  40. bool checked;
  41. bool checkable;
  42. bool separator;
  43. bool disabled;
  44. int ID;
  45. Variant metadata;
  46. String submenu;
  47. String tooltip;
  48. uint32_t accel;
  49. int _ofs_cache;
  50. Item() { checked=false; checkable=false; separator=false; accel=0; disabled=false; _ofs_cache=0; }
  51. };
  52. Timer *submenu_timer;
  53. List<Rect2> autohide_areas;
  54. Vector<Item> items;
  55. int idcount;
  56. int mouse_over;
  57. int submenu_over;
  58. Rect2 parent_rect;
  59. String _get_accel_text(uint32_t p_accel) const;
  60. int _get_mouse_over(const Point2& p_over) const;
  61. virtual Size2 get_minimum_size() const;
  62. void _input_event(const InputEvent &p_event);
  63. void _activate_submenu(int over);
  64. void _submenu_timeout();
  65. bool invalidated_click;
  66. Vector2 moved;
  67. Array _get_items() const;
  68. void _set_items(const Array& p_items);
  69. protected:
  70. virtual bool has_point(const Point2& p_point) const;
  71. friend class MenuButton;
  72. void _notification(int p_what);
  73. static void _bind_methods();
  74. public:
  75. void add_icon_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1,uint32_t p_accel=0);
  76. void add_item(const String& p_label,int p_ID=-1,uint32_t p_accel=0);
  77. void add_icon_check_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1,uint32_t p_accel=0);
  78. void add_check_item(const String& p_label,int p_ID=-1,uint32_t p_accel=0);
  79. void add_submenu_item(const String& p_label,const String& p_submenu, int p_ID=-1);
  80. void set_item_text(int p_idx,const String& p_text);
  81. void set_item_icon(int p_idx,const Ref<Texture>& p_icon);
  82. void set_item_checked(int p_idx,bool p_checked);
  83. void set_item_ID(int p_idx,int p_ID);
  84. void set_item_accelerator(int p_idx,uint32_t p_accel);
  85. void set_item_metadata(int p_idx,const Variant& p_meta);
  86. void set_item_disabled(int p_idx,bool p_disabled);
  87. void set_item_submenu(int p_idx, const String& p_submenu);
  88. void set_item_as_separator(int p_idx, bool p_separator);
  89. void set_item_as_checkable(int p_idx, bool p_checkable);
  90. void set_item_tooltip(int p_idx,const String& p_tooltip);
  91. String get_item_text(int p_idx) const;
  92. Ref<Texture> get_item_icon(int p_idx) const;
  93. bool is_item_checked(int p_idx) const;
  94. int get_item_ID(int p_idx) const;
  95. int get_item_index(int p_ID) const;
  96. uint32_t get_item_accelerator(int p_idx) const;
  97. Variant get_item_metadata(int p_idx) const;
  98. bool is_item_disabled(int p_idx) const;
  99. String get_item_submenu(int p_ID) const;
  100. bool is_item_separator(int p_idx) const;
  101. bool is_item_checkable(int p_idx) const;
  102. String get_item_tooltip(int p_idx) const;
  103. int get_item_count() const;
  104. int find_item_by_accelerator(uint32_t p_accel) const;
  105. void activate_item(int p_item);
  106. void remove_item(int p_idx);
  107. void add_separator();
  108. void clear();
  109. void set_parent_rect(const Rect2& p_rect);
  110. virtual String get_tooltip(const Point2& p_pos) const;
  111. virtual void get_translatable_strings(List<String> *p_strings) const;
  112. void add_autohide_area(const Rect2& p_area);
  113. void clear_autohide_areas();
  114. void set_invalidate_click_until_motion();
  115. PopupMenu();
  116. ~PopupMenu();
  117. };
  118. #endif