void MenuButton::_unhandled_key_input(InputEvent p_event) { if (p_event.is_pressed() && !p_event.is_echo() && (p_event.type==InputEvent::KEY || p_event.type==InputEvent::ACTION || p_event.type==InputEvent::JOYSTICK_BUTTON)) { if (!get_parent() || !is_visible() || is_disabled()) return; if (popup->activate_item_by_event(p_event)) accept_event(); } }
void BaseButton::_unhandled_input(InputEvent p_event) { if (!is_disabled() && is_visible() && p_event.is_pressed() && !p_event.is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { if (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)) return; //ignore because of modal window if (is_toggle_mode()) { set_pressed(!is_pressed()); emit_signal("toggled",is_pressed()); } emit_signal("pressed"); } }
void BaseButton::_input_event(InputEvent p_event) { if (status.disabled) // no interaction with disabled button return; switch(p_event.type) { case InputEvent::MOUSE_BUTTON: { const InputEventMouseButton &b=p_event.mouse_button; if ( status.disabled || b.button_index!=1 ) return; if (status.pressing_button) break; if (status.click_on_press) { if (b.pressed) { emit_signal("button_down"); if (!toggle_mode) { //mouse press attempt status.press_attempt=true; status.pressing_inside=true; pressed(); if (get_script_instance()) { Variant::CallError ce; get_script_instance()->call(SceneStringNames::get_singleton()->_pressed,NULL,0,ce); } emit_signal("pressed"); } else { status.pressed=!status.pressed; pressed(); if (get_script_instance()) { Variant::CallError ce; get_script_instance()->call(SceneStringNames::get_singleton()->_pressed,NULL,0,ce); } emit_signal("pressed"); toggled(status.pressed); emit_signal("toggled",status.pressed); } } else { emit_signal("button_up"); if (status.press_attempt && status.pressing_inside) { // released(); emit_signal("released"); } status.press_attempt=false; } update(); break; } if (b.pressed) { status.press_attempt=true; status.pressing_inside=true; emit_signal("button_down"); } else { emit_signal("button_up"); if (status.press_attempt &&status.pressing_inside) { if (!toggle_mode) { //mouse press attempt pressed(); if (get_script_instance()) { Variant::CallError ce; get_script_instance()->call(SceneStringNames::get_singleton()->_pressed,NULL,0,ce); } emit_signal("pressed"); } else { status.pressed=!status.pressed; pressed(); emit_signal("pressed"); toggled(status.pressed); emit_signal("toggled",status.pressed); if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_toggled,status.pressed); } } } status.press_attempt=false; } update(); } break; case InputEvent::MOUSE_MOTION: { if (status.press_attempt && status.pressing_button==0) { bool last_press_inside=status.pressing_inside; status.pressing_inside=has_point(Point2(p_event.mouse_motion.x,p_event.mouse_motion.y)); if (last_press_inside!=status.pressing_inside) update(); } } break; case InputEvent::ACTION: case InputEvent::JOYSTICK_BUTTON: case InputEvent::KEY: { if (p_event.is_echo()) { break; } if (status.disabled) { break; } if (status.press_attempt && status.pressing_button==0) { break; } if (p_event.is_action("ui_accept")) { if (p_event.is_pressed()) { status.pressing_button++; status.press_attempt=true; status.pressing_inside=true; emit_signal("button_down"); } else if (status.press_attempt) { if (status.pressing_button) status.pressing_button--; if (status.pressing_button) break; status.press_attempt=false; status.pressing_inside=false; emit_signal("button_up"); if (!toggle_mode) { //mouse press attempt pressed(); emit_signal("pressed"); } else { status.pressed=!status.pressed; pressed(); emit_signal("pressed"); toggled(status.pressed); if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_toggled,status.pressed); } emit_signal("toggled",status.pressed); } } accept_event(); update(); } } } }