diff options
Diffstat (limited to 'scene/gui/popup_menu.h')
-rw-r--r-- | scene/gui/popup_menu.h | 149 |
1 files changed, 92 insertions, 57 deletions
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index 2eef1f009d..428076c6da 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -31,97 +31,123 @@ #ifndef POPUP_MENU_H #define POPUP_MENU_H +#include "core/input/shortcut.h" +#include "scene/gui/margin_container.h" #include "scene/gui/popup.h" -#include "scene/gui/shortcut.h" +#include "scene/gui/scroll_container.h" +#include "scene/resources/text_line.h" class PopupMenu : public Popup { - GDCLASS(PopupMenu, Popup); struct Item { Ref<Texture2D> icon; String text; String xl_text; - bool checked; + Ref<TextLine> text_buf; + Ref<TextLine> accel_text_buf; + + Dictionary opentype_features; + String language; + Control::TextDirection text_direction = Control::TEXT_DIRECTION_AUTO; + + bool checked = false; 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; + int max_states = 0; + int state = 0; + bool separator = false; + bool disabled = false; + bool dirty = true; + int id = 0; Variant metadata; String submenu; String tooltip; - uint32_t accel; - int _ofs_cache; - int h_ofs; - Ref<ShortCut> shortcut; - bool shortcut_is_global; - bool shortcut_is_disabled; + uint32_t accel = 0; + int _ofs_cache = 0; + int _height_cache = 0; + int h_ofs = 0; + Ref<Shortcut> shortcut; + bool shortcut_is_global = false; + bool shortcut_is_disabled = false; + + // Returns (0,0) if icon is null. + Size2 get_icon_size() const { + return icon.is_null() ? Size2() : icon->get_size(); + } Item() { - checked = false; + text_buf.instantiate(); + accel_text_buf.instantiate(); checkable_type = CHECKABLE_TYPE_NONE; - separator = false; - max_states = 0; - state = 0; - accel = 0; - disabled = false; - _ofs_cache = 0; - h_ofs = 0; - shortcut_is_global = false; - shortcut_is_disabled = false; } }; + bool close_allowed = false; + + Timer *minimum_lifetime_timer = nullptr; Timer *submenu_timer; List<Rect2> autohide_areas; Vector<Item> items; - int initial_button_mask; - bool during_grabbed_click; - int mouse_over; - int submenu_over; + int initial_button_mask = 0; + bool during_grabbed_click = false; + int mouse_over = -1; + int submenu_over = -1; Rect2 parent_rect; - String _get_accel_text(int p_item) const; + String _get_accel_text(const Item &p_item) const; int _get_mouse_over(const Point2 &p_over) const; - virtual Size2 _get_contents_minimum_size() const; - void _scroll(float p_factor, const Point2 &p_over); - void _gui_input(const Ref<InputEvent> &p_event); - void _activate_submenu(int over); + virtual Size2 _get_contents_minimum_size() const override; + + int _get_item_height(int p_item) const; + int _get_items_total_height() const; + void _scroll_to_item(int p_item); + + void _shape_item(int p_item); + + virtual void gui_input(const Ref<InputEvent> &p_event); + void _activate_submenu(int p_over); void _submenu_timeout(); - bool invalidated_click; - bool hide_on_item_selection; - bool hide_on_checkable_item_selection; - bool hide_on_multistate_item_selection; + uint64_t popup_time_msec = 0; + bool hide_on_item_selection = true; + bool hide_on_checkable_item_selection = true; + bool hide_on_multistate_item_selection = false; Vector2 moved; Array _get_items() const; void _set_items(const Array &p_items); - Map<Ref<ShortCut>, int> shortcut_refcount; + Map<Ref<Shortcut>, int> shortcut_refcount; - void _ref_shortcut(Ref<ShortCut> p_sc); - void _unref_shortcut(Ref<ShortCut> p_sc); + 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; + bool allow_search = true; + uint64_t search_time_msec = 0; + String search_string = ""; + MarginContainer *margin_container; + ScrollContainer *scroll_container; Control *control; - void _draw(); + void _draw_items(); + void _draw_background(); + + void _minimum_lifetime_timeout(); + void _close_pressed(); protected: - friend class MenuButton; void _notification(int p_what); static void _bind_methods(); public: + // ATTENTION: This is used by the POT generator's scene parser. If the number of properties returned by `_get_items()` ever changes, + // this value should be updated to reflect the new size. + static const int ITEM_PROPERTY_SIZE = 10; + void add_item(const String &p_label, int p_id = -1, uint32_t p_accel = 0); void add_icon_item(const Ref<Texture2D> &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); @@ -131,16 +157,21 @@ public: 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<Texture2D> &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<Texture2D> &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<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false); + void add_shortcut(const Ref<Shortcut> &p_shortcut, int p_id = -1, bool p_global = false); + void add_icon_shortcut(const Ref<Texture2D> &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<Texture2D> &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<Texture2D> &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_text_direction(int p_idx, Control::TextDirection p_text_direction); + void set_item_opentype_feature(int p_idx, const String &p_name, int p_value); + void clear_item_opentype_features(int p_idx); + void set_item_language(int p_idx, const String &p_language); void set_item_icon(int p_idx, const Ref<Texture2D> &p_icon); void set_item_checked(int p_idx, bool p_checked); void set_item_id(int p_idx, int p_id); @@ -152,7 +183,7 @@ public: 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_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); @@ -161,6 +192,9 @@ public: void toggle_item_checked(int p_idx); String get_item_text(int p_idx) const; + Control::TextDirection get_item_text_direction(int p_idx) const; + int get_item_opentype_feature(int p_idx, const String &p_name) const; + String get_item_language(int p_idx) const; int get_item_idx_from_text(const String &text) const; Ref<Texture2D> get_item_icon(int p_idx) const; bool is_item_checked(int p_idx) const; @@ -175,9 +209,10 @@ public: 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; + Ref<Shortcut> get_item_shortcut(int p_idx) const; int get_item_state(int p_idx) const; + 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); @@ -185,7 +220,7 @@ public: void remove_item(int p_idx); - void add_separator(const String &p_text = String()); + void add_separator(const String &p_text = String(), int p_id = -1); void clear(); @@ -193,7 +228,7 @@ public: virtual String get_tooltip(const Point2 &p_pos) const; - virtual void get_translatable_strings(List<String> *p_strings) const; + virtual void get_translatable_strings(List<String> *p_strings) const override; void add_autohide_area(const Rect2 &p_area); void clear_autohide_areas(); |