void OnWheel(WheelEvent evt) { var graphView = target as GraphView; if (graphView == null) return; IPanel panel = (evt.target as VisualElement)?.panel; if (panel.GetCapturingElement(PointerId.mousePointerId) != null) return; Vector3 position = graphView.viewTransform.position; Vector3 scale = graphView.viewTransform.scale; // TODO: augment the data to have the position as well, so we don't have to read in data from the target. // 0-1 ranged center relative to size Vector2 zoomCenter = target.ChangeCoordinatesTo(graphView.contentViewContainer, evt.localMousePosition); float x = zoomCenter.x + graphView.contentViewContainer.layout.x; float y = zoomCenter.y + graphView.contentViewContainer.layout.y; position += Vector3.Scale(new Vector3(x, y, 0), scale); // Apply the new zoom. float zoom = CalculateNewZoom(scale.y, -evt.delta.y, scaleStep, referenceScale, minScale, maxScale); scale.x = zoom; scale.y = zoom; scale.z = 1; position -= Vector3.Scale(new Vector3(x, y, 0), scale); position.x = GraphViewStaticBridge.RoundToPixelGrid(position.x); position.y = GraphViewStaticBridge.RoundToPixelGrid(position.y); graphView.UpdateViewTransform(position, scale); evt.StopPropagation(); }
void OnWheel(WheelEvent evt) { var graphView = target as GraphView; if (graphView == null) { return; } IPanel panel = (evt.target as VisualElement)?.panel; if (panel.GetCapturingElement(PointerId.mousePointerId) != null) { return; } Vector3 position = graphView.viewTransform.position; Vector3 scale = graphView.viewTransform.scale; // TODO: augment the data to have the position as well, so we don't have to read in data from the target. // 0-1 ranged center relative to size Vector2 zoomCenter = target.ChangeCoordinatesTo(graphView.contentViewContainer, evt.localMousePosition); float x = zoomCenter.x + graphView.contentViewContainer.layout.x; float y = zoomCenter.y + graphView.contentViewContainer.layout.y; position += Vector3.Scale(new Vector3(x, y, 0), scale); // Apply the new zoom. float zoom = CalculateNewZoom(scale.y, -evt.delta.y, scaleStep, referenceScale, minScale, maxScale); scale.x = zoom; scale.y = zoom; scale.z = 1; position -= Vector3.Scale(new Vector3(x, y, 0), scale); position.x = GUIUtility.RoundToPixelGrid(position.x); position.y = GUIUtility.RoundToPixelGrid(position.y); // Delay updating of the pixel cache so the scrolling appears smooth. if (graphView.elementPanel != null && keepPixelCacheOnZoom) { graphView.elementPanel.keepPixelCacheOnWorldBoundChange = true; if (m_OnTimerTicker == null) { m_OnTimerTicker = graphView.schedule.Execute(OnTimer); } m_OnTimerTicker.ExecuteLater(500); delayRepaintScheduled = true; } graphView.UpdateViewTransform(position, scale); evt.StopPropagation(); }
public void Dispose() { if (m_Event != null && m_Event.log) { IPanel panel = (m_Event.target as VisualElement)?.panel; IEventHandler capture = panel?.GetCapturingElement(PointerId.mousePointerId); m_Event.eventLogger.LogIMGUICall(m_Event, (long)(Time.realtimeSinceStartup * 1000.0f) - m_Start, capture); } }
public void Dispose() { if (m_Event != null && m_Event.log) { IPanel panel = (m_Event.target as VisualElement)?.panel; IEventHandler capture = panel?.GetCapturingElement(PointerId.mousePointerId); m_Event.eventLogger.LogExecuteDefaultAction(m_Event, m_Event.propagationPhase, (long)(Time.realtimeSinceStartup * 1000.0f) - m_Start, capture); } }
public void Dispose() { bool flag = this.m_Event != null && this.m_Event.log; if (flag) { VisualElement expr_2C = this.m_Event.target as VisualElement; IPanel panel = (expr_2C != null) ? expr_2C.panel : null; IEventHandler mouseCapture = (panel != null) ? panel.GetCapturingElement(PointerId.mousePointerId) : null; this.m_Event.eventLogger.LogIMGUICall(this.m_Event, (long)(Time.realtimeSinceStartup * 1000f) - this.m_Start, mouseCapture); } }
public void Dispose() { bool flag = this.m_Event != null && this.m_Event.log; if (flag) { VisualElement expr_2F = this.m_Event.target as VisualElement; IPanel panel = (expr_2F != null) ? expr_2F.panel : null; IEventHandler mouseCapture = (panel != null) ? panel.GetCapturingElement(PointerId.mousePointerId) : null; this.m_Event.eventLogger.LogCall(this.GetCallbackHashCode(), this.GetCallbackName(), this.m_Event, this.m_IsPropagationStopped != this.m_Event.isPropagationStopped, this.m_IsImmediatePropagationStopped != this.m_Event.isImmediatePropagationStopped, this.m_IsDefaultPrevented != this.m_Event.isDefaultPrevented, (long)(Time.realtimeSinceStartup * 1000f) - this.m_Start, mouseCapture); } }
public void Dispose() { if (m_Event != null && m_Event.log) { IPanel panel = (m_Event.target as VisualElement)?.panel; IEventHandler capture = panel?.GetCapturingElement(PointerId.mousePointerId); m_Event.eventLogger.LogCall(GetCallbackHashCode(), GetCallbackName(), m_Event, m_IsPropagationStopped != m_Event.isPropagationStopped, m_IsImmediatePropagationStopped != m_Event.isImmediatePropagationStopped, m_IsDefaultPrevented != m_Event.isDefaultPrevented, (long)(Time.realtimeSinceStartup * 1000.0f) - m_Start, capture); } }
public void DispatchEvent(EventBase evt, IPanel panel) { IPointerEvent pointerEvent = evt as IPointerEvent; if (pointerEvent == null) { return; } IEventHandler targetOverride = panel.GetCapturingElement(pointerEvent.pointerId); if (targetOverride == null) { return; } // Release pointer capture if capture element is not in a panel. VisualElement captureVE = targetOverride as VisualElement; if (evt.eventTypeId != PointerCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { panel.ReleasePointer(pointerEvent.pointerId); return; } if (evt.target != null && evt.target != targetOverride) { return; } if (evt.eventTypeId != PointerCaptureEvent.TypeId() && evt.eventTypeId != PointerCaptureOutEvent.TypeId()) { panel.ProcessPointerCapture(pointerEvent.pointerId); } // Exclusive processing by capturing element. evt.dispatch = true; evt.target = targetOverride; evt.currentTarget = targetOverride; evt.propagationPhase = PropagationPhase.AtTarget; targetOverride.HandleEvent(evt); // Leave evt.target = originalCaptureElement for ExecuteDefaultAction() evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; evt.stopDispatch = true; evt.propagateToIMGUI = false; }
public void DispatchEvent(EventBase evt, IPanel panel) { IPointerEvent pointerEvent = evt as IPointerEvent; bool flag = pointerEvent == null; if (!flag) { IEventHandler capturingElement = panel.GetCapturingElement(pointerEvent.pointerId); bool flag2 = capturingElement == null; if (!flag2) { VisualElement visualElement = capturingElement as VisualElement; bool flag3 = evt.eventTypeId != EventBase <PointerCaptureOutEvent> .TypeId() && visualElement != null && visualElement.panel == null; if (flag3) { panel.ReleasePointer(pointerEvent.pointerId); } else { bool flag4 = evt.target != null && evt.target != capturingElement; if (!flag4) { bool flag5 = evt.eventTypeId != EventBase <PointerCaptureEvent> .TypeId() && evt.eventTypeId != EventBase <PointerCaptureOutEvent> .TypeId(); if (flag5) { panel.ProcessPointerCapture(pointerEvent.pointerId); } evt.dispatch = true; evt.target = capturingElement; evt.currentTarget = capturingElement; evt.propagationPhase = PropagationPhase.AtTarget; capturingElement.HandleEvent(evt); evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; evt.stopDispatch = true; evt.propagateToIMGUI = false; } } } } }
void OnMouseDown(MouseDownEvent e) { if (m_Active) { e.StopImmediatePropagation(); return; } IPanel panel = (e.target as VisualElement)?.panel; if (panel.GetCapturingElement(PointerId.mousePointerId) != null) { return; } var ce = parent as GraphElement; if (ce == null) { return; } if (!ce.IsResizable()) { return; } if (e.button == (int)activateButton) { m_Start = this.ChangeCoordinatesTo(parent, e.localMousePosition); m_StartPos = parent.layout; // Warn user if target uses a relative CSS position type if (!parent.isLayoutManual && parent.resolvedStyle.position == Position.Relative) { Debug.LogWarning("Attempting to resize an object with a non absolute position"); } m_Active = true; this.CaptureMouse(); e.StopPropagation(); } }
void OnKeyDown(KeyDownEvent evt) { IPanel panel = (evt.target as VisualElement)?.panel; if (panel.GetCapturingElement(PointerId.mousePointerId) != null) { return; } if (m_Dictionary.ContainsKey(evt.imguiEvent)) { var result = m_Dictionary[evt.imguiEvent](); if (result == EventPropagation.Stop) { evt.StopPropagation(); if (evt.imguiEvent != null) { evt.imguiEvent.Use(); } } } }
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; 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; } } }
public void DispatchEvent(EventBase evt, IPanel panel) { MouseCaptureDispatchingStrategy.EventBehavior eventBehavior = MouseCaptureDispatchingStrategy.EventBehavior.None; IEventHandler eventHandler = (panel != null) ? panel.GetCapturingElement(PointerId.mousePointerId) : null; bool flag = eventHandler == null; if (!flag) { VisualElement visualElement = eventHandler as VisualElement; bool flag2 = evt.eventTypeId != EventBase <MouseCaptureOutEvent> .TypeId() && visualElement != null && visualElement.panel == null; if (flag2) { visualElement.ReleaseMouse(); } else { bool flag3 = panel != null && visualElement != null && visualElement.panel.contextType != panel.contextType; if (!flag3) { IMouseEvent mouseEvent = evt as IMouseEvent; bool flag4 = mouseEvent != null && (evt.target == null || evt.target == eventHandler); if (flag4) { eventBehavior = MouseCaptureDispatchingStrategy.EventBehavior.IsCapturable; eventBehavior |= MouseCaptureDispatchingStrategy.EventBehavior.IsSentExclusivelyToCapturingElement; } else { bool flag5 = evt.imguiEvent != null && evt.target == null; if (flag5) { eventBehavior = MouseCaptureDispatchingStrategy.EventBehavior.IsCapturable; } } bool flag6 = evt.eventTypeId == EventBase <MouseEnterWindowEvent> .TypeId() || evt.eventTypeId == EventBase <MouseLeaveWindowEvent> .TypeId() || evt.eventTypeId == EventBase <WheelEvent> .TypeId(); if (flag6) { eventBehavior = MouseCaptureDispatchingStrategy.EventBehavior.None; } bool flag7 = (eventBehavior & MouseCaptureDispatchingStrategy.EventBehavior.IsCapturable) == MouseCaptureDispatchingStrategy.EventBehavior.IsCapturable; if (flag7) { BaseVisualElementPanel baseVisualElementPanel = panel as BaseVisualElementPanel; bool flag8 = mouseEvent != null && baseVisualElementPanel != null; if (flag8) { IMouseEventInternal expr_139 = mouseEvent as IMouseEventInternal; bool flag9 = expr_139 == null || expr_139.recomputeTopElementUnderMouse; bool flag10 = flag9; if (flag10) { baseVisualElementPanel.RecomputeTopElementUnderPointer(mouseEvent.mousePosition, evt); } } evt.dispatch = true; evt.target = eventHandler; CallbackEventHandler expr_175 = eventHandler as CallbackEventHandler; if (expr_175 != null) { expr_175.HandleEventAtTargetPhase(evt); } bool flag11 = (eventBehavior & MouseCaptureDispatchingStrategy.EventBehavior.IsSentExclusivelyToCapturingElement) != MouseCaptureDispatchingStrategy.EventBehavior.IsSentExclusivelyToCapturingElement; if (flag11) { evt.target = null; } evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; evt.skipElements.Add(eventHandler); evt.stopDispatch = ((eventBehavior & MouseCaptureDispatchingStrategy.EventBehavior.IsSentExclusivelyToCapturingElement) == MouseCaptureDispatchingStrategy.EventBehavior.IsSentExclusivelyToCapturingElement); bool flag12 = evt.target is IMGUIContainer; if (flag12) { evt.propagateToIMGUI = true; evt.skipElements.Add(evt.target); } else { evt.propagateToIMGUI = false; } } } } } }
public void DispatchEvent(EventBase evt, IPanel panel) { IPointerEvent pointerEvent = evt as IPointerEvent; if (pointerEvent == null) { return; } IEventHandler targetOverride = panel.GetCapturingElement(pointerEvent.pointerId); if (targetOverride == null) { return; } // Release pointer capture if capture element is not in a panel. VisualElement captureVE = targetOverride as VisualElement; if (evt.eventTypeId != PointerCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { panel.ReleasePointer(pointerEvent.pointerId); return; } if (evt.target != null && evt.target != targetOverride) { 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; } if (evt.eventTypeId != PointerCaptureEvent.TypeId() && evt.eventTypeId != PointerCaptureOutEvent.TypeId()) { panel.ProcessPointerCapture(pointerEvent.pointerId); } // Case 1353921: this will enforce PointerEnter/Out events even during pointer capture. // According to the W3 standard (https://www.w3.org/TR/pointerevents3/#the-pointerout-event), these events // are *not* supposed to occur, but we have been sending MouseEnter/Out events during mouse capture // since the early days of UI Toolkit, and users have been relying on it. if (panel is BaseVisualElementPanel basePanel) { bool shouldRecomputeTopElementUnderPointer = (pointerEvent as IPointerEventInternal)?.recomputeTopElementUnderPointer ?? true; if (shouldRecomputeTopElementUnderPointer) { basePanel.RecomputeTopElementUnderPointer(pointerEvent.pointerId, pointerEvent.position, evt); } } // Exclusive processing by capturing element. evt.dispatch = true; evt.target = targetOverride; evt.currentTarget = targetOverride; evt.propagationPhase = PropagationPhase.AtTarget; evt.skipDisabledElements = false; targetOverride.HandleEvent(evt); // Leave evt.target = originalCaptureElement for ExecuteDefaultAction() evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; evt.stopDispatch = true; evt.propagateToIMGUI = false; }