pandemonium_engine_minimal/scene/gui/popup_menu.h

214 lines
6.7 KiB
C++

#ifndef POPUP_MENU_H
#define POPUP_MENU_H
/* popup_menu.h */
#include "scene/gui/popup.h"
class ShortCut;
class MarginContainer;
class ScrollContainer;
class PopupMenu : public Popup {
GDCLASS(PopupMenu, Popup);
struct Item {
Ref<Texture> icon;
String text;
String xl_text;
bool checked;
enum {
CHECKABLE_TYPE_NONE,
CHECKABLE_TYPE_CHECK_BOX,
CHECKABLE_TYPE_RADIO_BUTTON,
} checkable_type;
int max_states;
int state;
bool separator;
bool disabled;
int id;
Variant metadata;
String submenu;
String tooltip;
uint32_t accel;
int _ofs_cache;
int _height_cache;
int h_ofs;
Ref<ShortCut> shortcut;
bool shortcut_is_global;
bool shortcut_is_disabled;
// Returns (0,0) if icon is null.
Size2 get_icon_size() const {
return icon.is_null() ? Size2() : icon->get_size();
}
Item();
~Item();
};
bool activated_by_keyboard;
Timer *submenu_timer;
List<Rect2> autohide_areas;
Vector<Item> items;
int initial_button_mask;
bool during_grabbed_click;
int mouse_over;
int submenu_over;
Rect2 parent_rect;
String _get_accel_text(int p_item) const;
int _get_mouse_over(const Point2 &p_over) const;
virtual Size2 get_minimum_size() const;
int _get_items_total_height() const;
void _scroll_to_item(int p_item);
void _gui_input(const Ref<InputEvent> &p_event);
void _activate_submenu(int over, bool p_by_keyboard = false);
void _submenu_timeout();
bool invalidated_click;
bool hide_on_item_selection;
bool hide_on_checkable_item_selection;
bool hide_on_multistate_item_selection;
bool hide_on_window_lose_focus;
Vector2 moved;
Array _get_items() const;
void _set_items(const Array &p_items);
RBMap<Ref<ShortCut>, int> shortcut_refcount;
void _ref_shortcut(Ref<ShortCut> p_sc);
void _unref_shortcut(Ref<ShortCut> p_sc);
bool allow_search;
uint64_t search_time_msec;
String search_string;
MarginContainer *margin_container;
ScrollContainer *scroll_container;
Control *control;
real_t max_height;
void _draw_items();
void _draw_background();
protected:
virtual bool has_point(const Point2 &p_point) const;
friend class MenuButton;
void _notification(int p_what);
static void _bind_methods();
public:
void add_item(const String &p_label, int p_id = -1, uint32_t p_accel = 0);
void add_icon_item(const Ref<Texture> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0);
void add_check_item(const String &p_label, int p_id = -1, uint32_t p_accel = 0);
void add_icon_check_item(const Ref<Texture> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0);
void add_radio_check_item(const String &p_label, int p_id = -1, uint32_t p_accel = 0);
void add_icon_radio_check_item(const Ref<Texture> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0);
void add_multistate_item(const String &p_label, int p_max_states, int p_default_state = 0, int p_id = -1, uint32_t p_accel = 0);
void add_shortcut(const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
void add_icon_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
void add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
void add_icon_check_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
void add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
void add_icon_radio_check_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
void add_submenu_item(const String &p_label, const String &p_submenu, int p_id = -1);
void set_item_text(int p_idx, const String &p_text);
void set_item_icon(int p_idx, const Ref<Texture> &p_icon);
void set_item_checked(int p_idx, bool p_checked);
void set_item_id(int p_idx, int p_id);
void set_item_accelerator(int p_idx, uint32_t p_accel);
void set_item_metadata(int p_idx, const Variant &p_meta);
void set_item_disabled(int p_idx, bool p_disabled);
void set_item_submenu(int p_idx, const String &p_submenu);
void set_item_as_separator(int p_idx, bool p_separator);
void set_item_as_checkable(int p_idx, bool p_checkable);
void set_item_as_radio_checkable(int p_idx, bool p_radio_checkable);
void set_item_tooltip(int p_idx, const String &p_tooltip);
void set_item_shortcut(int p_idx, const Ref<ShortCut> &p_shortcut, bool p_global = false);
void set_item_h_offset(int p_idx, int p_offset);
void set_item_multistate(int p_idx, int p_state);
void toggle_item_multistate(int p_idx);
void set_item_shortcut_disabled(int p_idx, bool p_disabled);
void toggle_item_checked(int p_idx);
String get_item_text(int p_idx) const;
int get_item_idx_from_text(const String &text) const;
Ref<Texture> get_item_icon(int p_idx) const;
bool is_item_checked(int p_idx) const;
int get_item_id(int p_idx) const;
int get_item_index(int p_id) const;
uint32_t get_item_accelerator(int p_idx) const;
Variant get_item_metadata(int p_idx) const;
bool is_item_disabled(int p_idx) const;
String get_item_submenu(int p_idx) const;
bool is_item_separator(int p_idx) const;
bool is_item_checkable(int p_idx) const;
bool is_item_radio_checkable(int p_idx) const;
bool is_item_shortcut_disabled(int p_idx) const;
String get_item_tooltip(int p_idx) const;
Ref<ShortCut> get_item_shortcut(int p_idx) const;
int get_item_state(int p_idx) const;
void set_current_index(int p_idx);
int get_current_index() const;
int get_item_count() const;
bool activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only = false);
void activate_item(int p_item);
void remove_item(int p_idx);
void add_separator(const String &p_text = String(), int p_id = -1);
void clear();
void set_parent_rect(const Rect2 &p_rect);
virtual String get_tooltip(const Point2 &p_pos) const;
virtual void get_translatable_strings(List<String> *p_strings) const;
void add_autohide_area(const Rect2 &p_area);
void clear_autohide_areas();
void set_hide_on_item_selection(bool p_enabled);
bool is_hide_on_item_selection() const;
void set_hide_on_checkable_item_selection(bool p_enabled);
bool is_hide_on_checkable_item_selection() const;
void set_hide_on_multistate_item_selection(bool p_enabled);
bool is_hide_on_multistate_item_selection() const;
void set_submenu_popup_delay(float p_time);
float get_submenu_popup_delay() const;
void set_allow_search(bool p_allow);
bool get_allow_search() const;
void set_max_height(real_t p_max_height);
real_t get_max_height() const;
virtual void popup(const Rect2 &p_bounds = Rect2());
void set_hide_on_window_lose_focus(bool p_enabled);
bool is_hide_on_window_lose_focus() const;
PopupMenu();
~PopupMenu();
};
#endif