popup_menu.h
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-2016 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 
32 #include "scene/gui/popup.h"
33 
37 class PopupMenu : public Popup {
38 
39  OBJ_TYPE(PopupMenu, Popup );
40 
41  struct Item {
42  Ref<Texture> icon;
43  String text;
44  bool checked;
45  bool checkable;
46  bool separator;
47  bool disabled;
48  int ID;
49  Variant metadata;
50  String submenu;
51  String tooltip;
52  uint32_t accel;
53  int _ofs_cache;
54 
55  Item() { checked=false; checkable=false; separator=false; accel=0; disabled=false; _ofs_cache=0; }
56  };
57 
58 
59  Timer *submenu_timer;
60  List<Rect2> autohide_areas;
61  Vector<Item> items;
62  int mouse_over;
63  int submenu_over;
64  Rect2 parent_rect;
65  String _get_accel_text(uint32_t p_accel) const;
66  int _get_mouse_over(const Point2& p_over) const;
67  virtual Size2 get_minimum_size() const;
68  void _input_event(const InputEvent &p_event);
69  void _activate_submenu(int over);
70  void _submenu_timeout();
71 
72  bool invalidated_click;
73  Vector2 moved;
74 
75  Array _get_items() const;
76  void _set_items(const Array& p_items);
77 
78 protected:
79 
80  virtual bool has_point(const Point2& p_point) const;
81 
82 friend class MenuButton;
83  void _notification(int p_what);
84  static void _bind_methods();
85 public:
86 
87  void add_icon_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1,uint32_t p_accel=0);
88  void add_item(const String& p_label,int p_ID=-1,uint32_t p_accel=0);
89  void add_icon_check_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1,uint32_t p_accel=0);
90  void add_check_item(const String& p_label,int p_ID=-1,uint32_t p_accel=0);
91  void add_submenu_item(const String& p_label,const String& p_submenu, int p_ID=-1);
92 
93  void set_item_text(int p_idx,const String& p_text);
94  void set_item_icon(int p_idx,const Ref<Texture>& p_icon);
95  void set_item_checked(int p_idx,bool p_checked);
96  void set_item_ID(int p_idx,int p_ID);
97  void set_item_accelerator(int p_idx,uint32_t p_accel);
98  void set_item_metadata(int p_idx,const Variant& p_meta);
99  void set_item_disabled(int p_idx,bool p_disabled);
100  void set_item_submenu(int p_idx, const String& p_submenu);
101  void set_item_as_separator(int p_idx, bool p_separator);
102  void set_item_as_checkable(int p_idx, bool p_checkable);
103  void set_item_tooltip(int p_idx,const String& p_tooltip);
104 
105  String get_item_text(int p_idx) const;
106  Ref<Texture> get_item_icon(int p_idx) const;
107  bool is_item_checked(int p_idx) const;
108  int get_item_ID(int p_idx) const;
109  int get_item_index(int p_ID) const;
110  uint32_t get_item_accelerator(int p_idx) const;
111  Variant get_item_metadata(int p_idx) const;
112  bool is_item_disabled(int p_idx) const;
113  String get_item_submenu(int p_ID) const;
114  bool is_item_separator(int p_idx) const;
115  bool is_item_checkable(int p_idx) const;
116  String get_item_tooltip(int p_idx) const;
117 
118  int get_item_count() const;
119 
120  int find_item_by_accelerator(uint32_t p_accel) const;
121  void activate_item(int p_item);
122 
123  void remove_item(int p_idx);
124 
125  void add_separator();
126 
127  void clear();
128 
129  void set_parent_rect(const Rect2& p_rect);
130 
131  virtual String get_tooltip(const Point2& p_pos) const;
132 
133  virtual void get_translatable_strings(List<String> *p_strings) const;
134 
135  void add_autohide_area(const Rect2& p_area);
136  void clear_autohide_areas();
137 
138  void set_invalidate_click_until_motion();
139 
140  PopupMenu();
141  ~PopupMenu();
142 
143 };
144 
145 #endif
Definition: array.h:38
Definition: timer.h:34
Definition: variant.h:74
Definition: menu_button.h:37
Definition: math_2d.h:204
Definition: input_event.h:263
Definition: popup.h:37
Definition: math_2d.h:65
Definition: ustring.h:64
Definition: popup_menu.h:37