private void Init(EventBase evt) { this.eventBaseName = evt.GetType().Name; this.eventTypeId = evt.eventTypeId; this.eventId = evt.eventId; this.triggerEventId = evt.triggerEventId; this.timestamp = evt.timestamp; this.target = evt.target; this.skipElements = evt.skipElements; this.isPropagationStopped = evt.isPropagationStopped; this.isImmediatePropagationStopped = evt.isImmediatePropagationStopped; this.isDefaultPrevented = evt.isDefaultPrevented; IMouseEvent mouseEvent = evt as IMouseEvent; IMouseEventInternal mouseEventInternal = evt as IMouseEventInternal; this.hasUnderlyingPhysicalEvent = (mouseEvent != null && mouseEventInternal != null && mouseEventInternal.triggeredByOS); this.propagationPhase = evt.propagationPhase; this.originalMousePosition = evt.originalMousePosition; this.currentTarget = evt.currentTarget; this.dispatch = evt.dispatch; bool flag = mouseEvent != null; if (flag) { this.modifiers = mouseEvent.modifiers; this.mousePosition = mouseEvent.mousePosition; this.button = mouseEvent.button; this.pressedButtons = mouseEvent.pressedButtons; this.clickCount = mouseEvent.clickCount; } IPointerEvent pointerEvent = evt as IPointerEvent; IPointerEventInternal pointerEventInternal = evt as IPointerEventInternal; this.hasUnderlyingPhysicalEvent = (pointerEvent != null && pointerEventInternal != null && pointerEventInternal.triggeredByOS); bool flag2 = pointerEvent != null; if (flag2) { this.modifiers = pointerEvent.modifiers; this.mousePosition = pointerEvent.position; this.button = pointerEvent.button; this.pressedButtons = pointerEvent.pressedButtons; this.clickCount = pointerEvent.clickCount; } IKeyboardEvent keyboardEvent = evt as IKeyboardEvent; bool flag3 = keyboardEvent != null; if (flag3) { this.character = keyboardEvent.character; this.keyCode = keyboardEvent.keyCode; } ICommandEvent commandEvent = evt as ICommandEvent; bool flag4 = commandEvent != null; if (flag4) { this.commandName = commandEvent.commandName; } }
public static ContextualMenuPopulateEvent GetPooled(EventBase triggerEvent, DropdownMenu menu, IEventHandler target, ContextualMenuManager menuManager) { ContextualMenuPopulateEvent e = GetPooled(triggerEvent); if (triggerEvent != null) { triggerEvent.Acquire(); e.triggerEvent = triggerEvent; IMouseEvent mouseEvent = triggerEvent as IMouseEvent; if (mouseEvent != null) { e.modifiers = mouseEvent.modifiers; e.mousePosition = mouseEvent.mousePosition; e.localMousePosition = mouseEvent.mousePosition; e.mouseDelta = mouseEvent.mouseDelta; e.button = mouseEvent.button; e.clickCount = mouseEvent.clickCount; } IMouseEventInternal mouseEventInternal = triggerEvent as IMouseEventInternal; if (mouseEventInternal != null) { ((IMouseEventInternal)e).triggeredByOS = mouseEventInternal.triggeredByOS; } } e.target = target; e.menu = menu; e.m_ContextualMenuManager = menuManager; return(e); }
public static ContextualMenuPopulateEvent GetPooled(EventBase triggerEvent, ContextualMenu menu, IEventHandler target) { ContextualMenuPopulateEvent e = GetPooled(); if (triggerEvent != null) { IMouseEvent mouseEvent = triggerEvent as IMouseEvent; if (mouseEvent != null) { e.modifiers = mouseEvent.modifiers; e.mousePosition = mouseEvent.mousePosition; e.localMousePosition = mouseEvent.mousePosition; e.mouseDelta = mouseEvent.mouseDelta; e.button = mouseEvent.button; e.clickCount = mouseEvent.clickCount; } IMouseEventInternal mouseEventInternal = triggerEvent as IMouseEventInternal; if (mouseEventInternal != null) { ((IMouseEventInternal)e).hasUnderlyingPhysicalEvent = mouseEventInternal.hasUnderlyingPhysicalEvent; } e.target = target; e.menu = menu; } return(e); }
internal static T GetPooled(IMouseEvent triggerEvent) { T pooled = EventBase <T> .GetPooled(); bool flag = triggerEvent != null; if (flag) { pooled.pointerId = PointerId.mousePointerId; pooled.pointerType = PointerType.mouse; pooled.isPrimary = true; pooled.button = triggerEvent.button; pooled.pressedButtons = triggerEvent.pressedButtons; pooled.position = triggerEvent.mousePosition; pooled.localPosition = triggerEvent.mousePosition; pooled.deltaPosition = triggerEvent.mouseDelta; pooled.deltaTime = 0f; pooled.clickCount = triggerEvent.clickCount; pooled.pressure = ((triggerEvent.pressedButtons == 0) ? 0f : 0.5f); pooled.tangentialPressure = 0f; pooled.altitudeAngle = 0f; pooled.azimuthAngle = 0f; pooled.twist = 0f; pooled.radius = default(Vector2); pooled.radiusVariance = default(Vector2); pooled.modifiers = triggerEvent.modifiers; IMouseEventInternal mouseEventInternal = triggerEvent as IMouseEventInternal; bool flag2 = mouseEventInternal != null; if (flag2) { pooled.triggeredByOS = mouseEventInternal.triggeredByOS; } } return(pooled); }
public static T GetPooled(IMouseEvent triggerEvent) { T pooled = EventBase <T> .GetPooled(triggerEvent as EventBase); bool flag = triggerEvent != null; if (flag) { pooled.modifiers = triggerEvent.modifiers; pooled.mousePosition = triggerEvent.mousePosition; pooled.localMousePosition = triggerEvent.mousePosition; pooled.mouseDelta = triggerEvent.mouseDelta; pooled.button = triggerEvent.button; pooled.pressedButtons = triggerEvent.pressedButtons; pooled.clickCount = triggerEvent.clickCount; IMouseEventInternal mouseEventInternal = triggerEvent as IMouseEventInternal; bool flag2 = mouseEventInternal != null; if (flag2) { pooled.triggeredByOS = mouseEventInternal.triggeredByOS; pooled.recomputeTopElementUnderMouse = false; } } return(pooled); }
void Init(EventBase evt) { eventBaseName = evt.GetType().Name; eventTypeId = evt.eventTypeId; eventId = evt.eventId; triggerEventId = evt.triggerEventId; timestamp = evt.timestamp; target = evt.target; skipElements = evt.skipElements; isPropagationStopped = evt.isPropagationStopped; isImmediatePropagationStopped = evt.isImmediatePropagationStopped; isDefaultPrevented = evt.isDefaultPrevented; IMouseEvent mouseEvent = evt as IMouseEvent; IMouseEventInternal mouseEventInternal = evt as IMouseEventInternal; hasUnderlyingPhysicalEvent = mouseEvent != null && mouseEventInternal != null && mouseEventInternal.triggeredByOS; propagationPhase = evt.propagationPhase; originalMousePosition = evt.originalMousePosition; currentTarget = evt.currentTarget; dispatch = evt.dispatch; if (mouseEvent != null) { modifiers = mouseEvent.modifiers; mousePosition = mouseEvent.mousePosition; button = mouseEvent.button; clickCount = mouseEvent.clickCount; // TODO: Scroll Wheel //delta = mouseEvent.delta; } IKeyboardEvent keyboardEvent = evt as IKeyboardEvent; if (keyboardEvent != null) { character = keyboardEvent.character; keyCode = keyboardEvent.keyCode; } ICommandEvent commandEvent = evt as ICommandEvent; if (commandEvent != null) { commandName = commandEvent.commandName; } }
public static ContextualMenuPopulateEvent GetPooled(EventBase triggerEvent, DropdownMenu menu, IEventHandler target, ContextualMenuManager menuManager) { ContextualMenuPopulateEvent pooled = EventBase <ContextualMenuPopulateEvent> .GetPooled(triggerEvent); bool flag = triggerEvent != null; if (flag) { triggerEvent.Acquire(); pooled.triggerEvent = triggerEvent; IMouseEvent mouseEvent = triggerEvent as IMouseEvent; bool flag2 = mouseEvent != null; if (flag2) { pooled.modifiers = mouseEvent.modifiers; pooled.mousePosition = mouseEvent.mousePosition; pooled.localMousePosition = mouseEvent.mousePosition; pooled.mouseDelta = mouseEvent.mouseDelta; pooled.button = mouseEvent.button; pooled.clickCount = mouseEvent.clickCount; } else { IPointerEvent pointerEvent = triggerEvent as IPointerEvent; bool flag3 = pointerEvent != null; if (flag3) { pooled.modifiers = pointerEvent.modifiers; pooled.mousePosition = pointerEvent.position; pooled.localMousePosition = pointerEvent.position; pooled.mouseDelta = pointerEvent.deltaPosition; pooled.button = pointerEvent.button; pooled.clickCount = pointerEvent.clickCount; } } IMouseEventInternal mouseEventInternal = triggerEvent as IMouseEventInternal; bool flag4 = mouseEventInternal != null; if (flag4) { ((IMouseEventInternal)pooled).triggeredByOS = mouseEventInternal.triggeredByOS; } else { IPointerEventInternal pointerEventInternal = triggerEvent as IPointerEventInternal; bool flag5 = pointerEventInternal != null; if (flag5) { ((IMouseEventInternal)pooled).triggeredByOS = pointerEventInternal.triggeredByOS; } } } pooled.target = target; pooled.menu = menu; pooled.m_ContextualMenuManager = menuManager; return(pooled); }
void ProcessEvent(EventBase evt, IPanel panel) { Event e = evt.imguiEvent; // Sometimes (in tests only?) we receive Used events. Protect our verification from this case. bool imguiEventIsInitiallyUsed = e != null && e.type == EventType.Used; using (new EventDispatcherGate(this)) { evt.PreDispatch(panel); IMouseEvent mouseEvent = evt as IMouseEvent; IMouseEventInternal mouseEventInternal = evt as IMouseEventInternal; if (mouseEvent != null && mouseEventInternal != null && mouseEventInternal.triggeredByOS) { MousePositionTracker.SaveMousePosition(mouseEvent.mousePosition, panel); } foreach (var strategy in m_DispatchingStrategies) { if (strategy.CanDispatchEvent(evt)) { strategy.DispatchEvent(evt, panel); Debug.Assert(imguiEventIsInitiallyUsed || evt.isPropagationStopped || e == null || e.type != EventType.Used, "Unexpected condition: !evt.isPropagationStopped && evt.imguiEvent.type == EventType.Used."); if (evt.stopDispatch || evt.isPropagationStopped) { break; } } } if (evt.path != null) { foreach (var element in evt.path.targetElements) { evt.target = element; EventDispatchUtilities.ExecuteDefaultAction(evt, panel); } evt.target = evt.leafTarget; } else { EventDispatchUtilities.ExecuteDefaultAction(evt, panel); } evt.PostDispatch(panel); m_DebuggerEventDispatchingStrategy.PostDispatch(evt, panel); Debug.Assert(imguiEventIsInitiallyUsed || evt.isPropagationStopped || e == null || e.type != EventType.Used, "Event is used but not stopped."); } }
private static void UpdateElementUnderMouse(EventBase evt, BaseVisualElementPanel panel, out VisualElement elementUnderMouse) { IMouseEventInternal expr_07 = evt as IMouseEventInternal; elementUnderMouse = ((expr_07 == null || expr_07.recomputeTopElementUnderMouse) ? panel.RecomputeTopElementUnderPointer(((IMouseEvent)evt).mousePosition, evt) : panel.GetTopElementUnderPointer(PointerId.mousePointerId)); bool flag = evt.eventTypeId == EventBase <MouseLeaveWindowEvent> .TypeId() && (evt as MouseLeaveWindowEvent).pressedButtons == 0; if (flag) { panel.ClearCachedElementUnderPointer(evt); } }
public static T GetPooled(IMouseEvent triggerEvent) { T e = GetPooled(); if (triggerEvent != null) { e.modifiers = triggerEvent.modifiers; e.mousePosition = triggerEvent.mousePosition; e.localMousePosition = triggerEvent.mousePosition; e.mouseDelta = triggerEvent.mouseDelta; e.button = triggerEvent.button; e.clickCount = triggerEvent.clickCount; IMouseEventInternal mouseEventInternal = triggerEvent as IMouseEventInternal; if (mouseEventInternal != null) { ((IMouseEventInternal)e).hasUnderlyingPhysicalEvent = mouseEventInternal.hasUnderlyingPhysicalEvent; } } return(e); }
public static T GetPooled(IMouseEvent triggerEvent) { T e = EventBase <T> .GetPooled(triggerEvent as EventBase); if (triggerEvent != null) { e.modifiers = triggerEvent.modifiers; e.mousePosition = triggerEvent.mousePosition; e.localMousePosition = triggerEvent.mousePosition; e.mouseDelta = triggerEvent.mouseDelta; e.button = triggerEvent.button; e.clickCount = triggerEvent.clickCount; IMouseEventInternal mouseEventInternal = triggerEvent as IMouseEventInternal; if (mouseEventInternal != null) { ((IMouseEventInternal)e).triggeredByOS = mouseEventInternal.triggeredByOS; ((IMouseEventInternal)e).recomputeTopElementUnderMouse = false; } } return(e); }
public void DispatchEvent(EventBase evt, IPanel panel) { if (evt.GetEventTypeId() == IMGUIEvent.TypeId()) { Event e = evt.imguiEvent; if (e.type == EventType.Repaint) { return; } } if (panel != null && panel.panelDebug != null && panel.panelDebug.enabled && panel.panelDebug.interceptEvents != null) { if (panel.panelDebug.interceptEvents(evt.imguiEvent)) { evt.StopPropagation(); return; } } IMouseEvent mouseEvent = evt as IMouseEvent; IMouseEventInternal mouseEventInternal = evt as IMouseEventInternal; if (mouseEvent != null && mouseEventInternal != null && mouseEventInternal.hasUnderlyingPhysicalEvent) { m_LastMousePosition = mouseEvent.mousePosition; } bool eventHandled = false; // Release mouse capture if capture element is not in a panel. VisualElement captureVE = MouseCaptureController.mouseCapture as VisualElement; if (evt.GetEventTypeId() != MouseCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { Event e = evt.imguiEvent; Debug.Log(String.Format("Capture has no panel, forcing removal (capture={0} eventType={1})", MouseCaptureController.mouseCapture, e != null ? e.type.ToString() : "null")); MouseCaptureController.ReleaseMouseCapture(); } // Send all IMGUI events (for backward compatibility) and MouseEvents with null target (because thats what we want to do in the new system) // to the capture, if there is one. Note that events coming from IMGUI have their target set to null. bool sendEventToMouseCapture = false; bool mouseEventWasCaptured = false; if (MouseCaptureController.mouseCapture != null) { if (evt.imguiEvent != null && evt.target == null) { // Non exclusive processing by capturing element. sendEventToMouseCapture = true; mouseEventWasCaptured = false; } if (mouseEvent != null && (evt.target == null || evt.target == MouseCaptureController.mouseCapture)) { // Exclusive processing by capturing element. sendEventToMouseCapture = true; mouseEventWasCaptured = true; } if (panel != null) { if (captureVE != null && captureVE.panel.contextType != panel.contextType) { // Capturing element is not in the right context. Ignore it. sendEventToMouseCapture = false; mouseEventWasCaptured = false; } } } evt.skipElement = null; if (sendEventToMouseCapture) { IEventHandler originalCaptureElement = MouseCaptureController.mouseCapture; eventHandled = true; 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 whould be done with mouseCapture as the target. if (!mouseEventWasCaptured) { evt.target = null; } evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; // Do not call HandleEvent again for this element. evt.skipElement = originalCaptureElement; } if (!mouseEventWasCaptured && !evt.isPropagationStopped) { if (evt is IKeyboardEvent && panel != null) { eventHandled = true; if (panel.focusController.focusedElement != null) { IMGUIContainer imguiContainer = panel.focusController.focusedElement as IMGUIContainer; if (imguiContainer != null) { // THINK ABOUT THIS PF: shoudln't we allow for the capture dispatch phase? if (imguiContainer != evt.skipElement && imguiContainer.HandleIMGUIEvent(evt.imguiEvent)) { evt.StopPropagation(); evt.PreventDefault(); } } else { evt.target = panel.focusController.focusedElement; PropagateEvent(evt); } } else { evt.target = panel.visualTree; PropagateEvent(evt); if (!evt.isPropagationStopped) { PropagateToIMGUIContainer(panel.visualTree, evt); } } } else if (mouseEvent != null) { // FIXME: we should not change hover state when capture is true. // However, when doing drag and drop, drop target should be highlighted. // TODO when EditorWindow is docked MouseLeaveWindow is not always sent // this is a problem in itself but it could leave some elements as "hover" if (evt.GetEventTypeId() == MouseLeaveWindowEvent.TypeId()) { VisualElement currentTopElementUnderMouse = m_TopElementUnderMouse; m_TopElementUnderMouse = null; DispatchMouseEnterMouseLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); DispatchMouseOverMouseOut(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } else if (evt.GetEventTypeId() == DragExitedEvent.TypeId()) { VisualElement currentTopElementUnderMouse = m_TopElementUnderMouse; m_TopElementUnderMouse = null; DispatchDragEnterDragLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } // update element under mouse and fire necessary events else { VisualElement currentTopElementUnderMouse = m_TopElementUnderMouse; if (evt.target == null && panel != null) { m_TopElementUnderMouse = panel.Pick(mouseEvent.mousePosition); evt.target = m_TopElementUnderMouse; } if (evt.target != null) { eventHandled = true; PropagateEvent(evt); } if (evt.GetEventTypeId() == MouseMoveEvent.TypeId() || evt.GetEventTypeId() == MouseDownEvent.TypeId() || evt.GetEventTypeId() == MouseUpEvent.TypeId() || evt.GetEventTypeId() == MouseEnterWindowEvent.TypeId() || evt.GetEventTypeId() == WheelEvent.TypeId()) { DispatchMouseEnterMouseLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); DispatchMouseOverMouseOut(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } else if (evt.GetEventTypeId() == DragUpdatedEvent.TypeId()) { DispatchDragEnterDragLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } } } else if (panel != null && evt is ICommandEvent) { IMGUIContainer imguiContainer = panel.focusController.focusedElement as IMGUIContainer; eventHandled = true; if (imguiContainer != null) { if (imguiContainer != evt.skipElement && imguiContainer.HandleIMGUIEvent(evt.imguiEvent)) { evt.StopPropagation(); evt.PreventDefault(); } } else if (panel.focusController.focusedElement != null) { evt.target = panel.focusController.focusedElement; PropagateEvent(evt); } else { PropagateToIMGUIContainer(panel.visualTree, evt); } } else if (evt is IPropagatableEvent || evt is IFocusEvent || evt is IChangeEvent || evt.GetEventTypeId() == InputEvent.TypeId() || evt.GetEventTypeId() == GeometryChangedEvent.TypeId()) { Debug.Assert(evt.target != null); eventHandled = true; PropagateEvent(evt); } } if (!mouseEventWasCaptured && !evt.isPropagationStopped && panel != null) { Event e = evt.imguiEvent; if (!eventHandled || (e != null && e.type == EventType.Used) || evt.GetEventTypeId() == MouseEnterWindowEvent.TypeId() || evt.GetEventTypeId() == MouseLeaveWindowEvent.TypeId()) { PropagateToIMGUIContainer(panel.visualTree, evt); } } if (evt.target == null && panel != null) { evt.target = panel.visualTree; } ExecuteDefaultAction(evt); }
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; } } } } } }