diff options
Diffstat (limited to 'scene/gui/popup_menu.cpp')
-rw-r--r-- | scene/gui/popup_menu.cpp | 131 |
1 files changed, 0 insertions, 131 deletions
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 9c48801ec1..52fe991f83 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -38,7 +38,6 @@ #include "scene/gui/control.h" String PopupMenu::_get_accel_text(int p_item) const { - ERR_FAIL_INDEX_V(p_item, items.size(), String()); if (items[p_item].shortcut.is_valid()) @@ -49,7 +48,6 @@ String PopupMenu::_get_accel_text(int p_item) const { } Size2 PopupMenu::_get_contents_minimum_size() const { - int vseparation = get_theme_constant("vseparation"); int hseparation = get_theme_constant("hseparation"); @@ -64,15 +62,12 @@ Size2 PopupMenu::_get_contents_minimum_size() const { bool has_check = false; for (int i = 0; i < items.size(); i++) { - Size2 size; if (!items[i].icon.is_null()) { - Size2 icon_size = items[i].icon->get_size(); size.height = MAX(icon_size.height, font_h); icon_w = MAX(icon_size.width + hseparation, icon_w); } else { - size.height = font_h; } @@ -87,7 +82,6 @@ Size2 PopupMenu::_get_contents_minimum_size() const { size.height += vseparation; if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) { - int accel_w = hseparation * 2; accel_w += font->get_string_size(_get_accel_text(i)).width; accel_max_w = MAX(accel_w, accel_max_w); @@ -109,7 +103,6 @@ Size2 PopupMenu::_get_contents_minimum_size() const { } int PopupMenu::_get_mouse_over(const Point2 &p_over) const { - if (p_over.x < 0 || p_over.x >= get_size().width) return -1; @@ -125,16 +118,13 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const { float font_h = font->get_height(); for (int i = 0; i < items.size(); i++) { - ofs.y += vseparation; float h; if (!items[i].icon.is_null()) { - Size2 icon_size = items[i].icon->get_size(); h = MAX(icon_size.height, font_h); } else { - h = font_h; } @@ -148,7 +138,6 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const { } void PopupMenu::_activate_submenu(int over) { - Node *n = get_node(items[over].submenu); ERR_FAIL_COND_MSG(!n, "Item subnode does not exist: " + items[over].submenu + "."); Popup *pm = Object::cast_to<Popup>(n); @@ -172,7 +161,6 @@ void PopupMenu::_activate_submenu(int over) { PopupMenu *pum = Object::cast_to<PopupMenu>(pm); if (pum) { - pr.position -= pum->get_position(); pum->clear_autohide_areas(); pum->add_autohide_area(Rect2(pr.position.x, pr.position.y, pr.size.x, items[over]._ofs_cache)); @@ -184,7 +172,6 @@ void PopupMenu::_activate_submenu(int over) { } void PopupMenu::_submenu_timeout() { - //if (!has_focus()) { // return; //do not activate if not has focus //} @@ -195,7 +182,6 @@ void PopupMenu::_submenu_timeout() { } void PopupMenu::_scroll(float p_factor, const Point2 &p_over) { - int vseparation = get_theme_constant("vseparation"); Ref<Font> font = get_theme_font("font"); @@ -226,20 +212,16 @@ void PopupMenu::_scroll(float p_factor, const Point2 &p_over) { } void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { - if (p_event->is_action("ui_down") && p_event->is_pressed()) { - int search_from = mouse_over + 1; if (search_from >= items.size()) search_from = 0; for (int i = search_from; i < items.size(); i++) { - if (i < 0 || i >= items.size()) continue; if (!items[i].separator && !items[i].disabled) { - mouse_over = i; emit_signal("id_focused", i); control->update(); @@ -248,18 +230,15 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { } } } else if (p_event->is_action("ui_up") && p_event->is_pressed()) { - int search_from = mouse_over - 1; if (search_from < 0) search_from = items.size() - 1; for (int i = search_from; i >= 0; i--) { - if (i >= items.size()) continue; if (!items[i].separator && !items[i].disabled) { - mouse_over = i; emit_signal("id_focused", i); control->update(); @@ -268,22 +247,18 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { } } } else if (p_event->is_action("ui_left") && p_event->is_pressed()) { - Node *n = get_parent(); if (n && Object::cast_to<PopupMenu>(n)) { hide(); set_input_as_handled(); } } else if (p_event->is_action("ui_right") && p_event->is_pressed()) { - if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator && items[mouse_over].submenu != "" && submenu_over != mouse_over) { _activate_submenu(mouse_over); set_input_as_handled(); } } else if (p_event->is_action("ui_accept") && p_event->is_pressed()) { - if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator) { - if (items[mouse_over].submenu != "" && submenu_over != mouse_over) { _activate_submenu(mouse_over); } else { @@ -296,25 +271,20 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> b = p_event; if (b.is_valid()) { - if (b->is_pressed()) return; int button_idx = b->get_button_index(); switch (button_idx) { - case BUTTON_WHEEL_DOWN: { - _scroll(-b->get_factor(), b->get_position()); } break; case BUTTON_WHEEL_UP: { - _scroll(b->get_factor(), b->get_position()); } break; default: { // Allow activating item by releasing the LMB or any that was down when the popup appeared if (button_idx == BUTTON_LEFT || (initial_button_mask & (1 << (button_idx - 1)))) { - bool was_during_grabbed_click = during_grabbed_click; during_grabbed_click = false; initial_button_mask = 0; @@ -336,7 +306,6 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { break; if (items[over].submenu != "") { - _activate_submenu(over); return; } @@ -351,7 +320,6 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> m = p_event; if (m.is_valid()) { - if (invalidated_click) { moved += m->get_relative(); if (moved.length() > 4) @@ -359,9 +327,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { } for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) { - if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E->get().has_point(m->get_position())) { - _close_pressed(); return; } @@ -395,7 +361,6 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventKey> k = p_event; if (allow_search && k.is_valid() && k->get_unicode() && k->is_pressed()) { - uint64_t now = OS::get_singleton()->get_ticks_msec(); uint64_t diff = now - search_time_msec; uint64_t max_interval = uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000)); @@ -431,7 +396,6 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { } void PopupMenu::_draw() { - RID ci = control->get_canvas_item(); Size2 size = get_size(); @@ -460,7 +424,6 @@ void PopupMenu::_draw() { float icon_ofs = 0.0; bool has_check = false; for (int i = 0; i < items.size(); i++) { - if (!items[i].icon.is_null()) icon_ofs = MAX(items[i].icon->get_size().width, icon_ofs); @@ -475,7 +438,6 @@ void PopupMenu::_draw() { check_ofs = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation; for (int i = 0; i < items.size(); i++) { - if (i > 0) ofs.y += vseparation; Point2 item_ofs = ofs; @@ -483,16 +445,13 @@ void PopupMenu::_draw() { float h; if (!items[i].icon.is_null()) { - icon_size = items[i].icon->get_size(); h = MAX(icon_size.height, font_h); } else { - h = font_h; } if (i == mouse_over) { - hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation / 2), Size2(get_size().width - style->get_minimum_size().width + hseparation * 2, h + vseparation))); } @@ -500,7 +459,6 @@ void PopupMenu::_draw() { item_ofs.x += items[i].h_ofs; if (items[i].separator) { - int sep_h = separator->get_center_size().height + separator->get_minimum_size().height; if (text != String()) { int ss = font->get_string_size(text).width; @@ -535,13 +493,11 @@ void PopupMenu::_draw() { item_ofs.y += font->get_ascent(); if (items[i].separator) { - if (text != String()) { int center = (get_size().width - font->get_string_size(text).width) / 2; font->draw(ci, Point2(center, item_ofs.y + Math::floor((h - font_h) / 2.0)), text, font_color_disabled); } } else { - item_ofs.x += icon_ofs + check_ofs; font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, items[i].disabled ? font_color_disabled : (i == mouse_over ? font_color_hover : font_color)); } @@ -560,11 +516,8 @@ void PopupMenu::_draw() { } void PopupMenu::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - PopupMenu *pm = Object::cast_to<PopupMenu>(get_parent()); if (pm) { // Inherit submenu's popup delay time from parent menu @@ -573,7 +526,6 @@ void PopupMenu::_notification(int p_what) { } } break; case NOTIFICATION_TRANSLATION_CHANGED: { - for (int i = 0; i < items.size(); i++) { items.write[i].xl_text = tr(items[i].text); } @@ -582,23 +534,19 @@ void PopupMenu::_notification(int p_what) { control->update(); } break; case NOTIFICATION_WM_MOUSE_ENTER: { - //grab_focus(); } break; case NOTIFICATION_WM_MOUSE_EXIT: { - if (mouse_over >= 0 && (items[mouse_over].submenu == "" || submenu_over != -1)) { mouse_over = -1; control->update(); } } break; case NOTIFICATION_POST_POPUP: { - initial_button_mask = Input::get_singleton()->get_mouse_button_mask(); during_grabbed_click = (bool)initial_button_mask; } break; case NOTIFICATION_WM_SIZE_CHANGED: { - } break; case NOTIFICATION_INTERNAL_PROCESS: { //only used when using operating system windows @@ -607,7 +555,6 @@ void PopupMenu::_notification(int p_what) { mouse_pos -= get_position(); for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) { - if (!Rect2(Point2(), get_size()).has_point(mouse_pos) && E->get().has_point(mouse_pos)) { _close_pressed(); return; @@ -616,7 +563,6 @@ void PopupMenu::_notification(int p_what) { } } break; case NOTIFICATION_VISIBILITY_CHANGED: { - if (!is_visible()) { if (mouse_over >= 0) { mouse_over = -1; @@ -659,7 +605,6 @@ void PopupMenu::_notification(int p_what) { item.accel = p_accel; void PopupMenu::add_item(const String &p_label, int p_id, uint32_t p_accel) { - Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); items.push_back(item); @@ -668,7 +613,6 @@ void PopupMenu::add_item(const String &p_label, int p_id, uint32_t p_accel) { } void PopupMenu::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { - Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.icon = p_icon; @@ -678,7 +622,6 @@ void PopupMenu::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_labe } void PopupMenu::add_check_item(const String &p_label, int p_id, uint32_t p_accel) { - Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX; @@ -688,7 +631,6 @@ void PopupMenu::add_check_item(const String &p_label, int p_id, uint32_t p_accel } void PopupMenu::add_icon_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { - Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.icon = p_icon; @@ -699,7 +641,6 @@ void PopupMenu::add_icon_check_item(const Ref<Texture2D> &p_icon, const String & } void PopupMenu::add_radio_check_item(const String &p_label, int p_id, uint32_t p_accel) { - Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON; @@ -709,7 +650,6 @@ void PopupMenu::add_radio_check_item(const String &p_label, int p_id, uint32_t p } void PopupMenu::add_icon_radio_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { - Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.icon = p_icon; @@ -720,7 +660,6 @@ void PopupMenu::add_icon_radio_check_item(const Ref<Texture2D> &p_icon, const St } void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int p_default_state, int p_id, uint32_t p_accel) { - Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.max_states = p_max_states; @@ -740,7 +679,6 @@ void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int item.shortcut_is_global = p_global; void PopupMenu::add_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { - Item item; ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); items.push_back(item); @@ -749,7 +687,6 @@ void PopupMenu::add_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_g } void PopupMenu::add_icon_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { - Item item; ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); item.icon = p_icon; @@ -759,7 +696,6 @@ void PopupMenu::add_icon_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortC } void PopupMenu::add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { - Item item; ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX; @@ -769,7 +705,6 @@ void PopupMenu::add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bo } void PopupMenu::add_icon_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { - Item item; ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); item.icon = p_icon; @@ -780,7 +715,6 @@ void PopupMenu::add_icon_check_shortcut(const Ref<Texture2D> &p_icon, const Ref< } void PopupMenu::add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { - Item item; ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON; @@ -790,7 +724,6 @@ void PopupMenu::add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_ } void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { - Item item; ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); item.icon = p_icon; @@ -801,7 +734,6 @@ void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, cons } void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, int p_id) { - Item item; item.text = p_label; item.xl_text = tr(p_label); @@ -818,7 +750,6 @@ void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, /* Methods to modify existing items. */ void PopupMenu::set_item_text(int p_idx, const String &p_text) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].text = p_text; items.write[p_idx].xl_text = tr(p_text); @@ -827,7 +758,6 @@ void PopupMenu::set_item_text(int p_idx, const String &p_text) { child_controls_changed(); } void PopupMenu::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].icon = p_icon; @@ -835,7 +765,6 @@ void PopupMenu::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) { child_controls_changed(); } void PopupMenu::set_item_checked(int p_idx, bool p_checked) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].checked = p_checked; @@ -844,7 +773,6 @@ void PopupMenu::set_item_checked(int p_idx, bool p_checked) { child_controls_changed(); } void PopupMenu::set_item_id(int p_idx, int p_id) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].id = p_id; @@ -853,7 +781,6 @@ void PopupMenu::set_item_id(int p_idx, int p_id) { } void PopupMenu::set_item_accelerator(int p_idx, uint32_t p_accel) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].accel = p_accel; @@ -862,7 +789,6 @@ void PopupMenu::set_item_accelerator(int p_idx, uint32_t p_accel) { } void PopupMenu::set_item_metadata(int p_idx, const Variant &p_meta) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].metadata = p_meta; control->update(); @@ -870,7 +796,6 @@ void PopupMenu::set_item_metadata(int p_idx, const Variant &p_meta) { } void PopupMenu::set_item_disabled(int p_idx, bool p_disabled) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].disabled = p_disabled; control->update(); @@ -878,7 +803,6 @@ void PopupMenu::set_item_disabled(int p_idx, bool p_disabled) { } void PopupMenu::set_item_submenu(int p_idx, const String &p_submenu) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].submenu = p_submenu; control->update(); @@ -886,7 +810,6 @@ void PopupMenu::set_item_submenu(int p_idx, const String &p_submenu) { } void PopupMenu::toggle_item_checked(int p_idx) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].checked = !items[p_idx].checked; control->update(); @@ -894,13 +817,11 @@ void PopupMenu::toggle_item_checked(int p_idx) { } String PopupMenu::get_item_text(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), ""); return items[p_idx].text; } int PopupMenu::get_item_idx_from_text(const String &text) const { - for (int idx = 0; idx < items.size(); idx++) { if (items[idx].text == text) return idx; @@ -910,45 +831,37 @@ int PopupMenu::get_item_idx_from_text(const String &text) const { } Ref<Texture2D> PopupMenu::get_item_icon(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<Texture2D>()); return items[p_idx].icon; } uint32_t PopupMenu::get_item_accelerator(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), 0); return items[p_idx].accel; } Variant PopupMenu::get_item_metadata(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), Variant()); return items[p_idx].metadata; } bool PopupMenu::is_item_disabled(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), false); return items[p_idx].disabled; } bool PopupMenu::is_item_checked(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), false); return items[p_idx].checked; } int PopupMenu::get_item_id(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), 0); return items[p_idx].id; } int PopupMenu::get_item_index(int p_id) const { - for (int i = 0; i < items.size(); i++) { - if (items[i].id == p_id) return i; } @@ -957,19 +870,16 @@ int PopupMenu::get_item_index(int p_id) const { } String PopupMenu::get_item_submenu(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), ""); return items[p_idx].submenu; } String PopupMenu::get_item_tooltip(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), ""); return items[p_idx].tooltip; } Ref<ShortCut> PopupMenu::get_item_shortcut(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<ShortCut>()); return items[p_idx].shortcut; } @@ -980,7 +890,6 @@ int PopupMenu::get_item_state(int p_idx) const { } void PopupMenu::set_item_as_separator(int p_idx, bool p_separator) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].separator = p_separator; control->update(); @@ -992,21 +901,18 @@ bool PopupMenu::is_item_separator(int p_idx) const { } void PopupMenu::set_item_as_checkable(int p_idx, bool p_checkable) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].checkable_type = p_checkable ? Item::CHECKABLE_TYPE_CHECK_BOX : Item::CHECKABLE_TYPE_NONE; control->update(); } void PopupMenu::set_item_as_radio_checkable(int p_idx, bool p_radio_checkable) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].checkable_type = p_radio_checkable ? Item::CHECKABLE_TYPE_RADIO_BUTTON : Item::CHECKABLE_TYPE_NONE; control->update(); } void PopupMenu::set_item_tooltip(int p_idx, const String &p_tooltip) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].tooltip = p_tooltip; control->update(); @@ -1028,7 +934,6 @@ void PopupMenu::set_item_shortcut(int p_idx, const Ref<ShortCut> &p_shortcut, bo } void PopupMenu::set_item_h_offset(int p_idx, int p_offset) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].h_ofs = p_offset; control->update(); @@ -1036,21 +941,18 @@ void PopupMenu::set_item_h_offset(int p_idx, int p_offset) { } void PopupMenu::set_item_multistate(int p_idx, int p_state) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].state = p_state; control->update(); } void PopupMenu::set_item_shortcut_disabled(int p_idx, bool p_disabled) { - ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].shortcut_is_disabled = p_disabled; control->update(); } void PopupMenu::toggle_item_multistate(int p_idx) { - ERR_FAIL_INDEX(p_idx, items.size()); if (0 >= items[p_idx].max_states) { return; @@ -1074,23 +976,19 @@ bool PopupMenu::is_item_radio_checkable(int p_idx) const { } bool PopupMenu::is_item_shortcut_disabled(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), false); return items[p_idx].shortcut_is_disabled; } int PopupMenu::get_current_index() const { - return mouse_over; } int PopupMenu::get_item_count() const { - return items.size(); } bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only) { - uint32_t code = 0; Ref<InputEventKey> k = p_event; @@ -1140,7 +1038,6 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo } void PopupMenu::activate_item(int p_item) { - ERR_FAIL_INDEX(p_item, items.size()); ERR_FAIL_COND(items[p_item].separator); int id = items[p_item].id >= 0 ? items[p_item].id : p_item; @@ -1189,7 +1086,6 @@ void PopupMenu::activate_item(int p_item) { } void PopupMenu::remove_item(int p_idx) { - ERR_FAIL_INDEX(p_idx, items.size()); if (items[p_idx].shortcut.is_valid()) { @@ -1202,7 +1098,6 @@ void PopupMenu::remove_item(int p_idx) { } void PopupMenu::add_separator(const String &p_text) { - Item sep; sep.separator = true; sep.id = -1; @@ -1215,7 +1110,6 @@ void PopupMenu::add_separator(const String &p_text) { } void PopupMenu::clear() { - for (int i = 0; i < items.size(); i++) { if (items[i].shortcut.is_valid()) { _unref_shortcut(items[i].shortcut); @@ -1228,10 +1122,8 @@ void PopupMenu::clear() { } Array PopupMenu::_get_items() const { - Array items; for (int i = 0; i < get_item_count(); i++) { - items.push_back(get_item_text(i)); items.push_back(get_item_icon(i)); // For compatibility, use false/true for no/checkbox and integers for other values @@ -1251,7 +1143,6 @@ Array PopupMenu::_get_items() const { } void PopupMenu::_ref_shortcut(Ref<ShortCut> p_sc) { - if (!shortcut_refcount.has(p_sc)) { shortcut_refcount[p_sc] = 1; p_sc->connect("changed", callable_mp((CanvasItem *)this, &CanvasItem::update)); @@ -1261,7 +1152,6 @@ void PopupMenu::_ref_shortcut(Ref<ShortCut> p_sc) { } void PopupMenu::_unref_shortcut(Ref<ShortCut> p_sc) { - ERR_FAIL_COND(!shortcut_refcount.has(p_sc)); shortcut_refcount[p_sc]--; if (shortcut_refcount[p_sc] == 0) { @@ -1271,12 +1161,10 @@ void PopupMenu::_unref_shortcut(Ref<ShortCut> p_sc) { } void PopupMenu::_set_items(const Array &p_items) { - ERR_FAIL_COND(p_items.size() % 10); clear(); for (int i = 0; i < p_items.size(); i += 10) { - String text = p_items[i + 0]; Ref<Texture2D> icon = p_items[i + 1]; // For compatibility, use false/true for no/checkbox and integers for other values @@ -1313,37 +1201,30 @@ void PopupMenu::_set_items(const Array &p_items) { // Hide on item selection determines whether or not the popup will close after item selection void PopupMenu::set_hide_on_item_selection(bool p_enabled) { - hide_on_item_selection = p_enabled; } bool PopupMenu::is_hide_on_item_selection() const { - return hide_on_item_selection; } void PopupMenu::set_hide_on_checkable_item_selection(bool p_enabled) { - hide_on_checkable_item_selection = p_enabled; } bool PopupMenu::is_hide_on_checkable_item_selection() const { - return hide_on_checkable_item_selection; } void PopupMenu::set_hide_on_multistate_item_selection(bool p_enabled) { - hide_on_multistate_item_selection = p_enabled; } bool PopupMenu::is_hide_on_multistate_item_selection() const { - return hide_on_multistate_item_selection; } void PopupMenu::set_submenu_popup_delay(float p_time) { - if (p_time <= 0) p_time = 0.01; @@ -1351,22 +1232,18 @@ void PopupMenu::set_submenu_popup_delay(float p_time) { } float PopupMenu::get_submenu_popup_delay() const { - return submenu_timer->get_wait_time(); } void PopupMenu::set_allow_search(bool p_allow) { - allow_search = p_allow; } bool PopupMenu::get_allow_search() const { - return allow_search; } String PopupMenu::get_tooltip(const Point2 &p_pos) const { - int over = _get_mouse_over(p_pos); if (over < 0 || over >= items.size()) return ""; @@ -1374,26 +1251,21 @@ String PopupMenu::get_tooltip(const Point2 &p_pos) const { } void PopupMenu::set_parent_rect(const Rect2 &p_rect) { - parent_rect = p_rect; } void PopupMenu::get_translatable_strings(List<String> *p_strings) const { - for (int i = 0; i < items.size(); i++) { - if (items[i].xl_text != "") p_strings->push_back(items[i].xl_text); } } void PopupMenu::add_autohide_area(const Rect2 &p_area) { - autohide_areas.push_back(p_area); } void PopupMenu::clear_autohide_areas() { - autohide_areas.clear(); } @@ -1406,7 +1278,6 @@ void PopupMenu::take_mouse_focus() { } void PopupMenu::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &PopupMenu::_gui_input); ClassDB::bind_method(D_METHOD("add_item", "label", "id", "accel"), &PopupMenu::add_item, DEFVAL(-1), DEFVAL(0)); @@ -1501,14 +1372,12 @@ void PopupMenu::_bind_methods() { } void PopupMenu::popup(const Rect2 &p_bounds) { - moved = Vector2(); invalidated_click = true; Popup::popup(p_bounds); } PopupMenu::PopupMenu() { - control = memnew(Control); add_child(control); |