瀏覽代碼

respect mouse mode when setting enter/exit notifications and signals, fixes #19785

Juan Linietsky 6 年之前
父節點
當前提交
93d8f3cdd5
共有 2 個文件被更改,包括 37 次插入4 次删除
  1. 35 4
      scene/main/viewport.cpp
  2. 2 0
      scene/main/viewport.h

+ 35 - 4
scene/main/viewport.cpp

@@ -1533,6 +1533,35 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu
 	//_unblock();
 }
 
+void Viewport::_gui_call_notification(Control *p_control, int p_what) {
+
+	CanvasItem *ci = p_control;
+	while (ci) {
+
+		Control *control = Object::cast_to<Control>(ci);
+		if (control) {
+
+			if (control->data.mouse_filter != Control::MOUSE_FILTER_IGNORE) {
+				control->notification(p_what);
+			}
+
+			if (!control->is_inside_tree())
+				break;
+
+			if (!control->is_inside_tree() || control->is_set_as_toplevel())
+				break;
+			if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
+				break;
+		}
+
+		if (ci->is_set_as_toplevel())
+			break;
+
+		ci = ci->get_parent_item();
+	}
+
+	//_unblock();
+}
 Control *Viewport::_gui_find_control(const Point2 &p_global) {
 
 	_gui_prepare_subwindows();
@@ -1975,13 +2004,15 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
 
 		if (over != gui.mouse_over) {
 
-			if (gui.mouse_over)
-				gui.mouse_over->notification(Control::NOTIFICATION_MOUSE_EXIT);
+			if (gui.mouse_over) {
+				_gui_call_notification(gui.mouse_over, Control::NOTIFICATION_MOUSE_EXIT);
+			}
 
 			_gui_cancel_tooltip();
 
-			if (over)
-				over->notification(Control::NOTIFICATION_MOUSE_ENTER);
+			if (over) {
+				_gui_call_notification(over, Control::NOTIFICATION_MOUSE_ENTER);
+			}
 		}
 
 		gui.mouse_over = over;

+ 2 - 0
scene/main/viewport.h

@@ -305,6 +305,8 @@ private:
 	bool disable_input;
 
 	void _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input);
+	void _gui_call_notification(Control *p_control, int p_what);
+
 	void _gui_prepare_subwindows();
 	void _gui_sort_subwindows();
 	void _gui_sort_roots();