public static void ReleaseMouse() { if (mouseCapture != null) { IEventHandler currentMouseCapture = mouseCapture; mouseCapture = null; using (MouseCaptureOutEvent e = MouseCaptureOutEvent.GetPooled(currentMouseCapture, null)) { currentMouseCapture.SendEvent(e); } } }
public void ProcessPointerCapture(int pointerId) { if (m_PointerCapture[pointerId] == m_PendingPointerCapture[pointerId]) { return; } if (m_PointerCapture[pointerId] != null) { using (var e = PointerCaptureOutEvent.GetPooled(m_PointerCapture[pointerId], m_PendingPointerCapture[pointerId], pointerId)) { m_PointerCapture[pointerId].SendEvent(e); } if (pointerId == PointerId.mousePointerId) { using (var e = MouseCaptureOutEvent.GetPooled(m_PointerCapture[pointerId], m_PendingPointerCapture[pointerId], pointerId)) { m_PointerCapture[pointerId].SendEvent(e); } } } if (m_PendingPointerCapture[pointerId] != null) { using (var e = PointerCaptureEvent.GetPooled(m_PendingPointerCapture[pointerId], m_PointerCapture[pointerId], pointerId)) { m_PendingPointerCapture[pointerId].SendEvent(e); } if (pointerId == PointerId.mousePointerId) { using (var e = MouseCaptureEvent.GetPooled(m_PendingPointerCapture[pointerId], m_PointerCapture[pointerId], pointerId)) { m_PendingPointerCapture[pointerId].SendEvent(e); } } } m_PointerCapture[pointerId] = m_PendingPointerCapture[pointerId]; }
public void ProcessPointerCapture(int pointerId) { bool flag = this.m_PointerCapture[pointerId] == this.m_PendingPointerCapture[pointerId]; if (!flag) { bool flag2 = this.m_PointerCapture[pointerId] != null; if (flag2) { using (PointerCaptureOutEvent pooled = PointerCaptureEventBase <PointerCaptureOutEvent> .GetPooled(this.m_PointerCapture[pointerId], this.m_PendingPointerCapture[pointerId], pointerId)) { this.m_PointerCapture[pointerId].SendEvent(pooled); } bool flag3 = pointerId == PointerId.mousePointerId; if (flag3) { using (MouseCaptureOutEvent pooled2 = PointerCaptureEventBase <MouseCaptureOutEvent> .GetPooled(this.m_PointerCapture[pointerId], this.m_PendingPointerCapture[pointerId], pointerId)) { this.m_PointerCapture[pointerId].SendEvent(pooled2); } } } bool flag4 = this.m_PendingPointerCapture[pointerId] != null; if (flag4) { using (PointerCaptureEvent pooled3 = PointerCaptureEventBase <PointerCaptureEvent> .GetPooled(this.m_PendingPointerCapture[pointerId], this.m_PointerCapture[pointerId], pointerId)) { this.m_PendingPointerCapture[pointerId].SendEvent(pooled3); } bool flag5 = pointerId == PointerId.mousePointerId; if (flag5) { using (MouseCaptureEvent pooled4 = PointerCaptureEventBase <MouseCaptureEvent> .GetPooled(this.m_PendingPointerCapture[pointerId], this.m_PointerCapture[pointerId], pointerId)) { this.m_PendingPointerCapture[pointerId].SendEvent(pooled4); } } } this.m_PointerCapture[pointerId] = this.m_PendingPointerCapture[pointerId]; } }
public static void CaptureMouse(this IEventHandler handler) { if (mouseCapture == handler) { return; } if (handler == null) { ReleaseMouse(); return; } if (GUIUtility.hotControl != 0) { Debug.Log("Should not be capturing when there is a hotcontrol"); return; } // TODO: assign a reserved control id to hotControl so that repaint events in OnGUI() have their hotcontrol check behave normally IEventHandler currentMouseCapture = mouseCapture; mouseCapture = handler; if (currentMouseCapture != null) { using (MouseCaptureOutEvent releaseEvent = MouseCaptureOutEvent.GetPooled(currentMouseCapture, mouseCapture)) { currentMouseCapture.SendEvent(releaseEvent); } } using (MouseCaptureEvent captureEvent = MouseCaptureEvent.GetPooled(mouseCapture, currentMouseCapture)) { mouseCapture.SendEvent(captureEvent); } }
public void DispatchEvent(EventBase evt, IPanel panel) { EventBehavior captureBehavior = EventBehavior.None; IEventHandler capturingElement = panel?.GetCapturingElement(PointerId.mousePointerId); if (capturingElement == null) { return; } // Release mouse capture if capture element is not in a panel. VisualElement captureVE = capturingElement as VisualElement; if (evt.eventTypeId != MouseCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { captureVE.ReleaseMouse(); return; } if (panel != null && captureVE != null && captureVE.panel.contextType != panel.contextType) { return; } IMouseEvent mouseEvent = evt as IMouseEvent; if (mouseEvent != null && (evt.target == null || evt.target == capturingElement)) { // Exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; captureBehavior |= EventBehavior.IsSentExclusivelyToCapturingElement; } else if (evt.imguiEvent != null && evt.target == null) { // Non exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; } if (evt.eventTypeId == MouseEnterWindowEvent.TypeId() || evt.eventTypeId == MouseLeaveWindowEvent.TypeId() || evt.eventTypeId == WheelEvent.TypeId()) { captureBehavior = EventBehavior.None; } if ((captureBehavior & EventBehavior.IsCapturable) == EventBehavior.IsCapturable) { BaseVisualElementPanel basePanel = panel as BaseVisualElementPanel; if (mouseEvent != null && basePanel != null) { bool shouldRecomputeTopElementUnderMouse = (mouseEvent as IMouseEventInternal)?.recomputeTopElementUnderMouse ?? true; if (shouldRecomputeTopElementUnderMouse) { basePanel.RecomputeTopElementUnderPointer(mouseEvent.mousePosition, evt); } } evt.dispatch = true; evt.target = capturingElement; evt.currentTarget = capturingElement; (capturingElement as CallbackEventHandler)?.HandleEventAtTargetPhase(evt); // Do further processing with a target computed the usual way. // However, if IsSentExclusivelyToCapturingElement, the only thing remaining to do is ExecuteDefaultAction, // which should be done with mouseCapture as the target. if ((captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) != EventBehavior.IsSentExclusivelyToCapturingElement) { evt.target = null; } evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; // Do not call HandleEvent again for this element. evt.skipElements.Add(capturingElement); evt.stopDispatch = (captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) == EventBehavior.IsSentExclusivelyToCapturingElement; if (evt.target is IMGUIContainer) { evt.propagateToIMGUI = true; evt.skipElements.Add(evt.target); } else { evt.propagateToIMGUI = false; } } }
public void DispatchEvent(EventBase evt, IPanel panel) { EventBehavior captureBehavior = EventBehavior.None; if (MouseCaptureController.mouseCapture == null) { return; } // Release mouse capture if capture element is not in a panel. VisualElement captureVE = MouseCaptureController.mouseCapture as VisualElement; if (evt.eventTypeId != MouseCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { MouseCaptureController.ReleaseMouse(); return; } if (panel != null && captureVE != null && captureVE.panel.contextType != panel.contextType) { return; } IMouseEvent mouseEvent = evt as IMouseEvent; if (mouseEvent != null && (evt.target == null || evt.target == MouseCaptureController.mouseCapture)) { // Exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; captureBehavior |= EventBehavior.IsSentExclusivelyToCapturingElement; } else if (evt.imguiEvent != null && evt.target == null) { // Non exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; } if (evt.eventTypeId == MouseEnterWindowEvent.TypeId() || evt.eventTypeId == MouseLeaveWindowEvent.TypeId() || evt.eventTypeId == WheelEvent.TypeId()) { captureBehavior = EventBehavior.None; } if ((captureBehavior & EventBehavior.IsCapturable) == EventBehavior.IsCapturable) { BaseVisualElementPanel basePanel = panel as BaseVisualElementPanel; if (mouseEvent != null && basePanel != null) { bool shouldRecomputeTopElementUnderMouse = true; if ((IMouseEventInternal)mouseEvent != null) { shouldRecomputeTopElementUnderMouse = ((IMouseEventInternal)mouseEvent).recomputeTopElementUnderMouse; } VisualElement elementUnderMouse = shouldRecomputeTopElementUnderMouse ? basePanel.Pick(mouseEvent.mousePosition) : basePanel.topElementUnderMouse; basePanel.SetElementUnderMouse(elementUnderMouse, evt); } IEventHandler originalCaptureElement = MouseCaptureController.mouseCapture; evt.dispatch = true; evt.target = MouseCaptureController.mouseCapture; evt.currentTarget = MouseCaptureController.mouseCapture; evt.propagationPhase = PropagationPhase.AtTarget; MouseCaptureController.mouseCapture.HandleEvent(evt); // Do further processing with a target computed the usual way. // However, if mouseEventWasCaptured, the only thing remaining to do is ExecuteDefaultAction, // which should be done with mouseCapture as the target. if ((captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) != EventBehavior.IsSentExclusivelyToCapturingElement) { evt.target = null; } evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; // Do not call HandleEvent again for this element. evt.skipElements.Add(originalCaptureElement); evt.stopDispatch = (captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) == EventBehavior.IsSentExclusivelyToCapturingElement; evt.propagateToIMGUI = false; } }
public void DispatchEvent(EventBase evt, IPanel panel) { EventBehavior captureBehavior = EventBehavior.None; IEventHandler capturingElement = panel?.GetCapturingElement(PointerId.mousePointerId); if (capturingElement == null) { return; } // Release mouse capture if capture element is not in a panel. VisualElement captureVE = capturingElement as VisualElement; if (evt.eventTypeId != MouseCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { captureVE.ReleaseMouse(); return; } // Case 1342115: mouse position is in local panel coordinates; sending event to a target from a different // panel will lead to a wrong position, so we don't allow it. Note that in general the mouse-down-move-up // sequence still works properly because the OS captures the mouse on the starting EditorWindow. if (panel != null && captureVE != null && captureVE.panel != panel) { return; } IMouseEvent mouseEvent = evt as IMouseEvent; if (mouseEvent != null && (evt.target == null || evt.target == capturingElement)) { // Exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; captureBehavior |= EventBehavior.IsSentExclusivelyToCapturingElement; } else if (evt.imguiEvent != null && evt.target == null) { // Non exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; } if (evt.eventTypeId == MouseEnterWindowEvent.TypeId() || evt.eventTypeId == MouseLeaveWindowEvent.TypeId() || evt.eventTypeId == WheelEvent.TypeId()) { captureBehavior = EventBehavior.None; } if ((captureBehavior & EventBehavior.IsCapturable) == EventBehavior.IsCapturable) { BaseVisualElementPanel basePanel = panel as BaseVisualElementPanel; if (mouseEvent != null && basePanel != null) { bool shouldRecomputeTopElementUnderMouse = (mouseEvent as IMouseEventInternal)?.recomputeTopElementUnderMouse ?? true; if (shouldRecomputeTopElementUnderMouse) { basePanel.RecomputeTopElementUnderPointer(PointerId.mousePointerId, mouseEvent.mousePosition, evt); } } evt.dispatch = true; evt.target = capturingElement; var skipDisabledElements = evt.skipDisabledElements; evt.skipDisabledElements = false; (capturingElement as CallbackEventHandler)?.HandleEventAtTargetPhase(evt); // Do further processing with a target computed the usual way. // However, if IsSentExclusivelyToCapturingElement, the only thing remaining to do is ExecuteDefaultAction, // which should be done with mouseCapture as the target. if ((captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) != EventBehavior.IsSentExclusivelyToCapturingElement) { evt.target = null; evt.skipDisabledElements = skipDisabledElements; } evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; // Do not call HandleEvent again for this element. evt.skipElements.Add(capturingElement); evt.stopDispatch = (captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) == EventBehavior.IsSentExclusivelyToCapturingElement; if (evt.target is IMGUIContainer) { evt.propagateToIMGUI = true; evt.skipElements.Add(evt.target); } else { evt.propagateToIMGUI = false; } } }