2023-01-10 14:26:54 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* popup_menu.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifndef POPUP_MENU_H
|
|
|
|
#define POPUP_MENU_H
|
|
|
|
|
|
|
|
#include "scene/gui/popup.h"
|
|
|
|
|
|
|
|
class PopupMenu : public Popup {
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(PopupMenu, Popup);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct Item {
|
|
|
|
Ref<Texture> icon;
|
|
|
|
String text;
|
2017-01-09 19:43:44 +00:00
|
|
|
String xl_text;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool checked;
|
2018-03-23 20:55:40 +00:00
|
|
|
enum {
|
|
|
|
CHECKABLE_TYPE_NONE,
|
|
|
|
CHECKABLE_TYPE_CHECK_BOX,
|
|
|
|
CHECKABLE_TYPE_RADIO_BUTTON,
|
|
|
|
} checkable_type;
|
2017-11-22 21:29:27 +00:00
|
|
|
int max_states;
|
|
|
|
int state;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool separator;
|
|
|
|
bool disabled;
|
2019-05-09 09:21:49 +00:00
|
|
|
int id;
|
2014-02-10 01:10:30 +00:00
|
|
|
Variant metadata;
|
|
|
|
String submenu;
|
|
|
|
String tooltip;
|
|
|
|
uint32_t accel;
|
|
|
|
int _ofs_cache;
|
2016-09-17 22:01:11 +00:00
|
|
|
int h_ofs;
|
2016-06-05 00:31:29 +00:00
|
|
|
Ref<ShortCut> shortcut;
|
2017-01-05 12:16:00 +00:00
|
|
|
bool shortcut_is_global;
|
2018-06-07 15:46:14 +00:00
|
|
|
bool shortcut_is_disabled;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item() {
|
|
|
|
checked = false;
|
2018-03-23 20:55:40 +00:00
|
|
|
checkable_type = CHECKABLE_TYPE_NONE;
|
2017-03-05 15:44:50 +00:00
|
|
|
separator = false;
|
2017-11-22 21:29:27 +00:00
|
|
|
max_states = 0;
|
|
|
|
state = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
accel = 0;
|
|
|
|
disabled = false;
|
|
|
|
_ofs_cache = 0;
|
|
|
|
h_ofs = 0;
|
|
|
|
shortcut_is_global = false;
|
2018-06-07 15:46:14 +00:00
|
|
|
shortcut_is_disabled = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2022-08-19 18:19:34 +00:00
|
|
|
bool activated_by_keyboard;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Timer *submenu_timer;
|
|
|
|
List<Rect2> autohide_areas;
|
|
|
|
Vector<Item> items;
|
2018-03-27 21:41:27 +00:00
|
|
|
int initial_button_mask;
|
|
|
|
bool during_grabbed_click;
|
2014-02-10 01:10:30 +00:00
|
|
|
int mouse_over;
|
|
|
|
int submenu_over;
|
|
|
|
Rect2 parent_rect;
|
2016-06-05 00:31:29 +00:00
|
|
|
String _get_accel_text(int p_item) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
int _get_mouse_over(const Point2 &p_over) const;
|
2016-03-08 23:00:52 +00:00
|
|
|
virtual Size2 get_minimum_size() const;
|
2018-01-06 15:21:27 +00:00
|
|
|
void _scroll(float p_factor, const Point2 &p_over);
|
2017-05-20 15:38:03 +00:00
|
|
|
void _gui_input(const Ref<InputEvent> &p_event);
|
2022-08-19 18:19:34 +00:00
|
|
|
void _activate_submenu(int over, bool p_by_keyboard = false);
|
2014-02-10 01:10:30 +00:00
|
|
|
void _submenu_timeout();
|
|
|
|
|
2015-01-03 19:52:37 +00:00
|
|
|
bool invalidated_click;
|
2016-12-23 14:43:45 +00:00
|
|
|
bool hide_on_item_selection;
|
2017-04-14 11:49:00 +00:00
|
|
|
bool hide_on_checkable_item_selection;
|
2017-12-12 02:37:37 +00:00
|
|
|
bool hide_on_multistate_item_selection;
|
2018-01-02 07:10:49 +00:00
|
|
|
bool hide_on_window_lose_focus;
|
2015-01-03 19:52:37 +00:00
|
|
|
Vector2 moved;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Array _get_items() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
void _set_items(const Array &p_items);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<Ref<ShortCut>, int> shortcut_refcount;
|
2016-06-05 00:31:29 +00:00
|
|
|
|
|
|
|
void _ref_shortcut(Ref<ShortCut> p_sc);
|
2017-03-05 15:44:50 +00:00
|
|
|
void _unref_shortcut(Ref<ShortCut> p_sc);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-05-11 16:32:53 +00:00
|
|
|
bool allow_search;
|
|
|
|
uint64_t search_time_msec;
|
|
|
|
String search_string;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
protected:
|
|
|
|
virtual bool has_point(const Point2 &p_point) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
friend class MenuButton;
|
2014-02-10 01:10:30 +00:00
|
|
|
void _notification(int p_what);
|
2016-03-08 23:00:52 +00:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2019-05-09 09:21:49 +00:00
|
|
|
void add_item(const String &p_label, int p_id = -1, uint32_t p_accel = 0);
|
2019-10-08 06:28:26 +00:00
|
|
|
void add_icon_item(const Ref<Texture> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0);
|
2019-05-09 09:21:49 +00:00
|
|
|
void add_check_item(const String &p_label, int p_id = -1, uint32_t p_accel = 0);
|
2019-10-08 06:28:26 +00:00
|
|
|
void add_icon_check_item(const Ref<Texture> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0);
|
2019-05-09 09:21:49 +00:00
|
|
|
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);
|
|
|
|
|
2019-10-08 06:28:26 +00:00
|
|
|
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);
|
|
|
|
|
2019-05-09 09:21:49 +00:00
|
|
|
void add_shortcut(const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
|
2019-10-08 06:28:26 +00:00
|
|
|
void add_icon_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
|
2019-05-09 09:21:49 +00:00
|
|
|
void add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
|
2019-10-08 06:28:26 +00:00
|
|
|
void add_icon_check_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
|
2019-05-09 09:21:49 +00:00
|
|
|
void add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
|
2019-10-08 06:28:26 +00:00
|
|
|
void add_icon_radio_check_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false);
|
2019-05-09 09:21:49 +00:00
|
|
|
|
2019-10-08 06:28:26 +00:00
|
|
|
void add_submenu_item(const String &p_label, const String &p_submenu, int p_id = -1);
|
2017-11-22 21:29:27 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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);
|
2019-05-09 09:21:49 +00:00
|
|
|
void set_item_id(int p_idx, int p_id);
|
2017-03-05 15:44:50 +00:00
|
|
|
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);
|
2014-02-10 01:10:30 +00:00
|
|
|
void set_item_as_separator(int p_idx, bool p_separator);
|
|
|
|
void set_item_as_checkable(int p_idx, bool p_checkable);
|
2018-03-23 20:55:40 +00:00
|
|
|
void set_item_as_radio_checkable(int p_idx, bool p_radio_checkable);
|
2017-03-05 15:44:50 +00:00
|
|
|
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);
|
2016-09-17 22:01:11 +00:00
|
|
|
void set_item_h_offset(int p_idx, int p_offset);
|
2017-12-12 02:37:37 +00:00
|
|
|
void set_item_multistate(int p_idx, int p_state);
|
|
|
|
void toggle_item_multistate(int p_idx);
|
2018-06-07 15:46:14 +00:00
|
|
|
void set_item_shortcut_disabled(int p_idx, bool p_disabled);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-01 13:50:54 +00:00
|
|
|
void toggle_item_checked(int p_idx);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String get_item_text(int p_idx) const;
|
2017-07-14 08:45:24 +00:00
|
|
|
int get_item_idx_from_text(const String &text) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
Ref<Texture> get_item_icon(int p_idx) const;
|
|
|
|
bool is_item_checked(int p_idx) const;
|
2017-08-07 10:17:31 +00:00
|
|
|
int get_item_id(int p_idx) const;
|
2019-05-09 09:21:49 +00:00
|
|
|
int get_item_index(int p_id) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
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;
|
2017-08-11 19:10:05 +00:00
|
|
|
String get_item_submenu(int p_idx) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool is_item_separator(int p_idx) const;
|
|
|
|
bool is_item_checkable(int p_idx) const;
|
2018-03-23 20:55:40 +00:00
|
|
|
bool is_item_radio_checkable(int p_idx) const;
|
2018-06-07 15:46:14 +00:00
|
|
|
bool is_item_shortcut_disabled(int p_idx) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
String get_item_tooltip(int p_idx) const;
|
2016-06-05 00:31:29 +00:00
|
|
|
Ref<ShortCut> get_item_shortcut(int p_idx) const;
|
2017-11-22 21:29:27 +00:00
|
|
|
int get_item_state(int p_idx) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-02-04 20:20:26 +00:00
|
|
|
void set_current_index(int p_idx);
|
2020-05-06 20:27:35 +00:00
|
|
|
int get_current_index() const;
|
2022-02-04 20:20:26 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
int get_item_count() const;
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
bool activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only = false);
|
2014-02-10 01:10:30 +00:00
|
|
|
void activate_item(int p_item);
|
|
|
|
|
|
|
|
void remove_item(int p_idx);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2020-12-27 12:18:47 +00:00
|
|
|
void add_separator(const String &p_text = String(), int p_id = -1);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void clear();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_parent_rect(const Rect2 &p_rect);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual String get_tooltip(const Point2 &p_pos) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
virtual void get_translatable_strings(List<String> *p_strings) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void add_autohide_area(const Rect2 &p_area);
|
2014-02-10 01:10:30 +00:00
|
|
|
void clear_autohide_areas();
|
|
|
|
|
2016-12-23 14:43:45 +00:00
|
|
|
void set_hide_on_item_selection(bool p_enabled);
|
2017-11-22 21:29:27 +00:00
|
|
|
bool is_hide_on_item_selection() const;
|
2015-01-03 19:52:37 +00:00
|
|
|
|
2017-04-14 11:49:00 +00:00
|
|
|
void set_hide_on_checkable_item_selection(bool p_enabled);
|
2017-11-22 21:29:27 +00:00
|
|
|
bool is_hide_on_checkable_item_selection() const;
|
|
|
|
|
2017-12-12 02:37:37 +00:00
|
|
|
void set_hide_on_multistate_item_selection(bool p_enabled);
|
|
|
|
bool is_hide_on_multistate_item_selection() const;
|
2017-04-14 11:49:00 +00:00
|
|
|
|
2018-07-09 12:16:06 +00:00
|
|
|
void set_submenu_popup_delay(float p_time);
|
|
|
|
float get_submenu_popup_delay() const;
|
|
|
|
|
2019-05-11 16:32:53 +00:00
|
|
|
void set_allow_search(bool p_allow);
|
|
|
|
bool get_allow_search() const;
|
|
|
|
|
2018-03-27 21:41:27 +00:00
|
|
|
virtual void popup(const Rect2 &p_bounds = Rect2());
|
|
|
|
|
2018-01-02 07:10:49 +00:00
|
|
|
void set_hide_on_window_lose_focus(bool p_enabled);
|
|
|
|
bool is_hide_on_window_lose_focus() const;
|
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
PopupMenu();
|
2014-02-10 01:10:30 +00:00
|
|
|
~PopupMenu();
|
|
|
|
};
|
|
|
|
|
2022-07-25 10:33:41 +00:00
|
|
|
#endif // POPUP_MENU_H
|