예제 #1
0
        private EventPropagation SendEventToIMGUIContainers(VisualElement root, Event evt, VisualElement skipElement)
        {
            IMGUIContainer   iMGUIContainer = root as IMGUIContainer;
            EventPropagation result;

            if (iMGUIContainer != null && iMGUIContainer != skipElement)
            {
                if (iMGUIContainer.HandleEvent(evt, iMGUIContainer) == EventPropagation.Stop)
                {
                    result = EventPropagation.Stop;
                }
                else
                {
                    result = EventPropagation.Continue;
                }
            }
            else
            {
                VisualContainer visualContainer = root as VisualContainer;
                if (visualContainer != null)
                {
                    for (int i = 0; i < visualContainer.childrenCount; i++)
                    {
                        if (this.SendEventToIMGUIContainers(visualContainer.GetChildAt(i), evt, skipElement) == EventPropagation.Stop)
                        {
                            result = EventPropagation.Stop;
                            return(result);
                        }
                    }
                }
                result = EventPropagation.Continue;
            }
            return(result);
        }
예제 #2
0
        // End the 2D GUI.
        internal static void EndContainerGUI(Event evt)
        {
            if (Event.current.type == EventType.Layout &&
                s_ContainerStack.Count > 0)
            {
                var r = s_ContainerStack.Peek().layout;
                GUILayoutUtility.LayoutFromContainer(r.width, r.height);
            }
            // restore cache
            GUILayoutUtility.SelectIDList(GUIUtility.s_OriginalID, false);
            GUIContent.ClearStaticCache();

            if (s_ContainerStack.Count > 0)
            {
                IMGUIContainer container = s_ContainerStack.Peek();
                if (s_EndContainerCallback != null)
                {
                    s_EndContainerCallback(container);
                }
            }

            evt.CopyFrom(Event.current);

            if (s_ContainerStack.Count > 0)
            {
                GUIUtility.EndContainer();
                s_ContainerStack.Pop();
            }
        }
예제 #3
0
 internal void SyncIMGUIFocus(int imguiKeyboardControlID, IMGUIContainer imguiContainerHavingKeyboardControl)
 {
     this.imguiKeyboardControl = imguiKeyboardControlID;
     if (this.imguiKeyboardControl != 0)
     {
         this.SwitchFocus(imguiContainerHavingKeyboardControl, FocusChangeDirection.unspecified);
     }
     else
     {
         this.SwitchFocus(null, FocusChangeDirection.unspecified);
     }
 }
예제 #4
0
 private static void GetCurrentTransformAndClip(IMGUIContainer container, Event evt, out Matrix4x4 transform, out Rect clipRect)
 {
     clipRect = container.lastWorldClip;
     if (clipRect.width == 0f || clipRect.height == 0f)
     {
         clipRect = container.worldBound;
     }
     transform = container.worldTransform;
     if (evt.type == EventType.Repaint && container.elementPanel != null && container.elementPanel.stylePainter != null)
     {
         transform = container.elementPanel.stylePainter.currentTransform;
     }
 }
 internal void SyncIMGUIFocus(IMGUIContainer imguiContainerHavingKeyboardControl)
 {
     if (GUIUtility.keyboardControl != this.imguiKeyboardControl)
     {
         this.imguiKeyboardControl = GUIUtility.keyboardControl;
         if (GUIUtility.keyboardControl != 0)
         {
             this.SwitchFocus(imguiContainerHavingKeyboardControl, FocusChangeDirection.unspecified);
         }
         else
         {
             this.SwitchFocus(null, FocusChangeDirection.unspecified);
         }
     }
 }
예제 #6
0
 private static void TakeCapture()
 {
     if (UIElementsUtility.s_ContainerStack.Count > 0)
     {
         IMGUIContainer iMGUIContainer = UIElementsUtility.s_ContainerStack.Peek();
         if (iMGUIContainer.GUIDepth == GUIUtility.Internal_GetGUIDepth())
         {
             if (MouseCaptureController.IsMouseCaptureTaken() && !iMGUIContainer.HasMouseCapture())
             {
                 Debug.Log("Should not grab hot control with an active capture");
             }
             iMGUIContainer.TakeMouseCapture();
         }
     }
 }
 private static void TakeCapture()
 {
     if (UIElementsUtility.s_ContainerStack.Count > 0)
     {
         IMGUIContainer imguicontainer = UIElementsUtility.s_ContainerStack.Peek();
         if (imguicontainer.GUIDepth == GUIUtility.Internal_GetGUIDepth())
         {
             if (UIElementsUtility.eventDispatcher.capture != null && UIElementsUtility.eventDispatcher.capture != imguicontainer)
             {
                 Debug.Log(string.Format("Should not grab hot control with an active capture (current={0} new={1}", UIElementsUtility.eventDispatcher.capture, imguicontainer));
             }
             UIElementsUtility.eventDispatcher.TakeCapture(imguicontainer);
         }
     }
 }
예제 #8
0
        private static void GetCurrentTransformAndClip(IMGUIContainer container, Event evt, out Matrix4x4 transform, out Rect clipRect)
        {
            clipRect = container.lastWorldClip;
            if (clipRect.width == 0.0f || clipRect.height == 0.0f)
            {
                // lastWorldClip will be empty until the first repaint occurred,
                // we fall back on the worldBound in this case.
                clipRect = container.worldBound;
            }

            transform = container.worldTransform;
            if (evt.type == EventType.Repaint &&
                container.elementPanel != null)
            {
                // during repaint, we must use in case the current transform is not relative to Panel
                // this is to account for the pixel caching feature
                transform = container.elementPanel.repaintData.currentOffset * container.worldTransform;
            }
        }
예제 #9
0
 internal static void EndContainerGUI()
 {
     if (Event.current.type == EventType.Layout && UIElementsUtility.s_ContainerStack.Count > 0)
     {
         Rect globalBound = UIElementsUtility.s_ContainerStack.Peek().globalBound;
         GUILayoutUtility.LayoutFromContainer(globalBound.width, globalBound.height);
     }
     GUILayoutUtility.SelectIDList(GUIUtility.s_OriginalID, false);
     GUIContent.ClearStaticCache();
     if (UIElementsUtility.s_ContainerStack.Count > 0)
     {
         IMGUIContainer obj = UIElementsUtility.s_ContainerStack.Peek();
         if (UIElementsUtility.s_EndContainerCallback != null)
         {
             UIElementsUtility.s_EndContainerCallback(obj);
         }
         GUIUtility.EndContainer();
         UIElementsUtility.s_ContainerStack.Pop();
     }
 }
예제 #10
0
        private static void PropagateToIMGUIContainer(VisualElement root, EventBase evt, VisualElement capture)
        {
            IMGUIContainer iMGUIContainer = root as IMGUIContainer;

            if (iMGUIContainer != null && (evt.imguiEvent.type == EventType.Used || root != capture))
            {
                if (iMGUIContainer.HandleIMGUIEvent(evt.imguiEvent))
                {
                    evt.StopPropagation();
                    evt.PreventDefault();
                }
            }
            else if (root != null)
            {
                for (int i = 0; i < root.shadow.childCount; i++)
                {
                    EventDispatcher.PropagateToIMGUIContainer(root.shadow[i], evt, capture);
                    if (evt.isPropagationStopped)
                    {
                        break;
                    }
                }
            }
        }
        internal static void BeginContainerGUI(GUILayoutUtility.LayoutCache cache, Event evt, IMGUIContainer container)
        {
            if (container.useOwnerObjectGUIState)
            {
                GUIUtility.BeginContainerFromOwner(container.elementPanel.ownerObject);
            }
            else
            {
                GUIUtility.BeginContainer(container.guiState);
            }
            UIElementsUtility.s_ContainerStack.Push(container);
            GUIUtility.s_SkinMode   = (int)container.contextType;
            GUIUtility.s_OriginalID = container.elementPanel.ownerObject.GetInstanceID();
            Event.current           = evt;
            GUI.enabled             = container.enabledInHierarchy;
            GUILayoutUtility.BeginContainer(cache);
            GUIUtility.ResetGlobalState();
            Rect clipRect = container.lastWorldClip;

            if (clipRect.width == 0f || clipRect.height == 0f)
            {
                clipRect = container.worldBound;
            }
            Matrix4x4 lhs = container.worldTransform;

            if (evt.type == EventType.Repaint && container.elementPanel != null && container.elementPanel.stylePainter != null)
            {
                lhs = container.elementPanel.stylePainter.currentTransform;
            }
            GUIClip.SetTransform(lhs * Matrix4x4.Translate(container.layout.position), clipRect);
        }
예제 #12
0
        internal static void BeginContainerGUI(GUILayoutUtility.LayoutCache cache, int instanceID, Event evt, IMGUIContainer container)
        {
            GUIUtility.BeginContainer(instanceID);
            UIElementsUtility.s_ContainerStack.Push(container);
            GUIUtility.s_SkinMode   = (int)container.contextType;
            GUIUtility.s_OriginalID = instanceID;
            Event.current           = evt;
            if (UIElementsUtility.s_BeginContainerCallback != null)
            {
                UIElementsUtility.s_BeginContainerCallback(container);
            }
            GUILayoutUtility.BeginContainer(cache);
            GUIUtility.ResetGlobalState();
            Rect clipRect = container.lastWorldClip;

            if (clipRect.width == 0f || clipRect.height == 0f)
            {
                clipRect = container.globalBound;
            }
            Matrix4x4 rhs = Matrix4x4.TRS(new Vector3(container.position.x, container.position.y, 0f), Quaternion.identity, Vector3.one);

            GUIClip.SetTransform(container.globalTransform * rhs, clipRect);
        }
예제 #13
0
        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);
        }
예제 #14
0
        public void DispatchEvent(EventBase evt, IPanel panel)
        {
            Event imguiEvent = evt.imguiEvent;

            if (imguiEvent == null || imguiEvent.type != EventType.Repaint)
            {
                if (panel != null && panel.panelDebug != null && panel.panelDebug.enabled && panel.panelDebug.interceptEvents != null && panel.panelDebug.interceptEvents(imguiEvent))
                {
                    evt.StopPropagation();
                }
                else
                {
                    bool          flag          = false;
                    VisualElement visualElement = null;
                    if ((evt is IMouseEvent || imguiEvent != null) && MouseCaptureController.mouseCapture != null)
                    {
                        visualElement = (MouseCaptureController.mouseCapture as VisualElement);
                        if (visualElement != null && visualElement.panel == null)
                        {
                            Debug.Log(string.Format("Capture has no panel, forcing removal (capture={0} eventType={1})", MouseCaptureController.mouseCapture, (imguiEvent == null) ? "null" : imguiEvent.type.ToString()));
                            MouseCaptureController.ReleaseMouseCapture();
                            visualElement = null;
                        }
                        if (panel != null)
                        {
                            if (visualElement != null && visualElement.panel.contextType != panel.contextType)
                            {
                                return;
                            }
                        }
                        flag         = true;
                        evt.dispatch = true;
                        if (MouseCaptureController.mouseCapture != null)
                        {
                            evt.target           = MouseCaptureController.mouseCapture;
                            evt.currentTarget    = MouseCaptureController.mouseCapture;
                            evt.propagationPhase = PropagationPhase.AtTarget;
                            MouseCaptureController.mouseCapture.HandleEvent(evt);
                        }
                        evt.propagationPhase = PropagationPhase.None;
                        evt.currentTarget    = null;
                        evt.dispatch         = false;
                    }
                    if (evt.isPropagationStopped)
                    {
                        if (evt.target == null && panel != null)
                        {
                            evt.target = panel.visualTree;
                        }
                        if (evt.target != null && evt.target != MouseCaptureController.mouseCapture)
                        {
                            evt.dispatch         = true;
                            evt.currentTarget    = evt.target;
                            evt.propagationPhase = PropagationPhase.AtTarget;
                            evt.target.HandleEvent(evt);
                            evt.propagationPhase = PropagationPhase.None;
                            evt.currentTarget    = null;
                            evt.dispatch         = false;
                        }
                    }
                    if (!evt.isPropagationStopped)
                    {
                        if (evt is IKeyboardEvent && panel != null)
                        {
                            if (panel.focusController.focusedElement != null)
                            {
                                IMGUIContainer iMGUIContainer = panel.focusController.focusedElement as IMGUIContainer;
                                flag = true;
                                if (iMGUIContainer != null)
                                {
                                    if (iMGUIContainer.HandleIMGUIEvent(evt.imguiEvent))
                                    {
                                        evt.StopPropagation();
                                        evt.PreventDefault();
                                    }
                                }
                                else
                                {
                                    evt.target = panel.focusController.focusedElement;
                                    EventDispatcher.PropagateEvent(evt);
                                }
                            }
                            else
                            {
                                evt.target = panel.visualTree;
                                EventDispatcher.PropagateEvent(evt);
                                flag = false;
                            }
                        }
                        else if (evt.GetEventTypeId() == EventBase <MouseEnterEvent> .TypeId() || evt.GetEventTypeId() == EventBase <MouseLeaveEvent> .TypeId())
                        {
                            Debug.Assert(evt.target != null);
                            flag = true;
                            EventDispatcher.PropagateEvent(evt);
                        }
                        else if (evt is IMouseEvent || (imguiEvent != null && (imguiEvent.type == EventType.ContextClick || imguiEvent.type == EventType.DragUpdated || imguiEvent.type == EventType.DragPerform || imguiEvent.type == EventType.DragExited)))
                        {
                            VisualElement topElementUnderMouse = this.m_TopElementUnderMouse;
                            if (evt.GetEventTypeId() == EventBase <MouseLeaveWindowEvent> .TypeId())
                            {
                                this.m_TopElementUnderMouse = null;
                                this.DispatchMouseEnterMouseLeave(topElementUnderMouse, this.m_TopElementUnderMouse, imguiEvent);
                                this.DispatchMouseOverMouseOut(topElementUnderMouse, this.m_TopElementUnderMouse, imguiEvent);
                            }
                            else if (evt is IMouseEvent || imguiEvent != null)
                            {
                                if (evt.target == null && panel != null)
                                {
                                    if (evt is IMouseEvent)
                                    {
                                        this.m_TopElementUnderMouse = panel.Pick((evt as IMouseEvent).localMousePosition);
                                    }
                                    else if (imguiEvent != null)
                                    {
                                        this.m_TopElementUnderMouse = panel.Pick(imguiEvent.mousePosition);
                                    }
                                    evt.target = this.m_TopElementUnderMouse;
                                }
                                if (evt.target != null)
                                {
                                    flag = true;
                                    EventDispatcher.PropagateEvent(evt);
                                }
                                if (evt.GetEventTypeId() == EventBase <MouseMoveEvent> .TypeId() || evt.GetEventTypeId() == EventBase <MouseEnterWindowEvent> .TypeId() || evt.GetEventTypeId() == EventBase <WheelEvent> .TypeId() || (imguiEvent != null && imguiEvent.type == EventType.DragUpdated))
                                {
                                    this.DispatchMouseEnterMouseLeave(topElementUnderMouse, this.m_TopElementUnderMouse, imguiEvent);
                                    this.DispatchMouseOverMouseOut(topElementUnderMouse, this.m_TopElementUnderMouse, imguiEvent);
                                }
                            }
                        }
                        else if (panel != null && imguiEvent != null && (imguiEvent.type == EventType.ExecuteCommand || imguiEvent.type == EventType.ValidateCommand))
                        {
                            IMGUIContainer iMGUIContainer2 = panel.focusController.focusedElement as IMGUIContainer;
                            if (iMGUIContainer2 != null)
                            {
                                flag = true;
                                if (iMGUIContainer2.HandleIMGUIEvent(evt.imguiEvent))
                                {
                                    evt.StopPropagation();
                                    evt.PreventDefault();
                                }
                            }
                            else if (panel.focusController.focusedElement != null)
                            {
                                flag       = true;
                                evt.target = panel.focusController.focusedElement;
                                EventDispatcher.PropagateEvent(evt);
                            }
                            else
                            {
                                flag = true;
                                EventDispatcher.PropagateToIMGUIContainer(panel.visualTree, evt, visualElement);
                            }
                        }
                        else if (evt is IPropagatableEvent || evt is IFocusEvent || evt is IChangeEvent || evt.GetEventTypeId() == EventBase <PostLayoutEvent> .TypeId() || evt.GetEventTypeId() == EventBase <InputEvent> .TypeId())
                        {
                            Debug.Assert(evt.target != null);
                            flag = true;
                            EventDispatcher.PropagateEvent(evt);
                        }
                    }
                    if (!evt.isPropagationStopped && imguiEvent != null && panel != null)
                    {
                        if (!flag || (imguiEvent != null && (imguiEvent.type == EventType.MouseEnterWindow || imguiEvent.type == EventType.MouseLeaveWindow || imguiEvent.type == EventType.Used)))
                        {
                            EventDispatcher.PropagateToIMGUIContainer(panel.visualTree, evt, visualElement);
                        }
                    }
                    if (evt.target == null && panel != null)
                    {
                        evt.target = panel.visualTree;
                    }
                    EventDispatcher.ExecuteDefaultAction(evt);
                }
            }
        }
예제 #15
0
        public void DispatchEvent(EventBase evt, IPanel panel)
        {
            Event e = evt.imguiEvent;

            if (e != null && e.type == EventType.Repaint)
            {
                return;
            }

            if (panel != null && panel.panelDebug != null && panel.panelDebug.enabled && panel.panelDebug.interceptEvents != null)
            {
                if (panel.panelDebug.interceptEvents(e))
                {
                    evt.StopPropagation();
                    return;
                }
            }

            bool          invokedHandleEvent = false;
            VisualElement captureVE          = null;

            // Send all IMGUI events (for backward compatibility) and MouseEvents (because thats what we want to do in the new system)
            // to the capture, if there is one.
            if ((evt is IMouseEvent || e != null) && MouseCaptureController.mouseCapture != null)
            {
                captureVE = MouseCaptureController.mouseCapture as VisualElement;
                if (captureVE != null && captureVE.panel == null)
                {
                    Debug.Log(String.Format("Capture has no panel, forcing removal (capture={0} eventType={1})", MouseCaptureController.mouseCapture, e != null ? e.type.ToString() : "null"));
                    MouseCaptureController.ReleaseMouseCapture();
                    captureVE = null;
                }

                if (panel != null)
                {
                    if (captureVE != null && captureVE.panel.contextType != panel.contextType)
                    {
                        return;
                    }
                }

                invokedHandleEvent = true;
                evt.dispatch       = true;

                if (MouseCaptureController.mouseCapture != null)
                {
                    evt.target           = MouseCaptureController.mouseCapture;
                    evt.currentTarget    = MouseCaptureController.mouseCapture;
                    evt.propagationPhase = PropagationPhase.AtTarget;
                    MouseCaptureController.mouseCapture.HandleEvent(evt);
                }
                evt.propagationPhase = PropagationPhase.None;
                evt.currentTarget    = null;
                evt.dispatch         = false;
            }

            if (evt.isPropagationStopped)
            {
                // Make sure to call default actions at target, but dont call it twice on mouse capture
                if (evt.target == null && panel != null)
                {
                    evt.target = panel.visualTree;
                }
                if (evt.target != null && evt.target != MouseCaptureController.mouseCapture)
                {
                    evt.dispatch         = true;
                    evt.currentTarget    = evt.target;
                    evt.propagationPhase = PropagationPhase.AtTarget;
                    evt.target.HandleEvent(evt);
                    evt.propagationPhase = PropagationPhase.None;
                    evt.currentTarget    = null;
                    evt.dispatch         = false;
                }
            }

            if (!evt.isPropagationStopped)
            {
                if (evt is IKeyboardEvent && panel != null)
                {
                    if (panel.focusController.focusedElement != null)
                    {
                        IMGUIContainer imguiContainer = panel.focusController.focusedElement as IMGUIContainer;

                        invokedHandleEvent = true;
                        if (imguiContainer != null)
                        {
                            if (imguiContainer.HandleIMGUIEvent(evt.imguiEvent))
                            {
                                evt.StopPropagation();
                                evt.PreventDefault();
                            }
                        }
                        else
                        {
                            evt.target = panel.focusController.focusedElement;
                            PropagateEvent(evt);
                        }
                    }
                    else
                    {
                        evt.target = panel.visualTree;
                        PropagateEvent(evt);

                        // Force call to PropagateToIMGUIContainer(), even if capture != null.
                        invokedHandleEvent = false;
                    }
                }
                else if (evt.GetEventTypeId() == MouseEnterEvent.TypeId() ||
                         evt.GetEventTypeId() == MouseLeaveEvent.TypeId())
                {
                    Debug.Assert(evt.target != null);
                    invokedHandleEvent = true;
                    PropagateEvent(evt);
                }
                else if (evt is IMouseEvent || (
                             e != null && (
                                 e.type == EventType.ContextClick ||
                                 e.type == EventType.DragUpdated ||
                                 e.type == EventType.DragPerform ||
                                 e.type == EventType.DragExited
                                 )
                             ))
                {
                    // 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"
                    VisualElement currentTopElementUnderMouse = m_TopElementUnderMouse;

                    if (evt.GetEventTypeId() == MouseLeaveWindowEvent.TypeId())
                    {
                        m_TopElementUnderMouse = null;
                        DispatchMouseEnterMouseLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, e);
                        DispatchMouseOverMouseOut(currentTopElementUnderMouse, m_TopElementUnderMouse, e);
                    }
                    // update element under mouse and fire necessary events
                    else if (evt is IMouseEvent || e != null)
                    {
                        if (evt.target == null && panel != null)
                        {
                            if (evt is IMouseEvent)
                            {
                                m_TopElementUnderMouse = panel.Pick((evt as IMouseEvent).localMousePosition);
                            }
                            else if (e != null)
                            {
                                m_TopElementUnderMouse = panel.Pick(e.mousePosition);
                            }

                            evt.target = m_TopElementUnderMouse;
                        }

                        if (evt.target != null)
                        {
                            invokedHandleEvent = true;
                            PropagateEvent(evt);
                        }

                        if (evt.GetEventTypeId() == MouseMoveEvent.TypeId() ||
                            evt.GetEventTypeId() == MouseEnterWindowEvent.TypeId() ||
                            evt.GetEventTypeId() == WheelEvent.TypeId() ||
                            (e != null && e.type == EventType.DragUpdated))
                        {
                            DispatchMouseEnterMouseLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, e);
                            DispatchMouseOverMouseOut(currentTopElementUnderMouse, m_TopElementUnderMouse, e);
                        }
                    }
                }
                else if (panel != null && e != null && (e.type == EventType.ExecuteCommand || e.type == EventType.ValidateCommand))
                {
                    IMGUIContainer imguiContainer = panel.focusController.focusedElement as IMGUIContainer;

                    if (imguiContainer != null)
                    {
                        invokedHandleEvent = true;
                        if (imguiContainer.HandleIMGUIEvent(evt.imguiEvent))
                        {
                            evt.StopPropagation();
                            evt.PreventDefault();
                        }
                    }
                    else if (panel.focusController.focusedElement != null)
                    {
                        invokedHandleEvent = true;
                        evt.target         = panel.focusController.focusedElement;
                        PropagateEvent(evt);
                    }
                    else
                    {
                        invokedHandleEvent = true;
                        PropagateToIMGUIContainer(panel.visualTree, evt, captureVE);
                    }
                }
                else if (evt is IPropagatableEvent ||
                         evt is IFocusEvent ||
                         evt is IChangeEvent ||
                         evt.GetEventTypeId() == InputEvent.TypeId() ||
                         evt.GetEventTypeId() == PostLayoutEvent.TypeId())
                {
                    Debug.Assert(evt.target != null);
                    invokedHandleEvent = true;
                    PropagateEvent(evt);
                }
            }

            if (!evt.isPropagationStopped && e != null && panel != null)
            {
                if (!invokedHandleEvent || e != null && (
                        e.type == EventType.MouseEnterWindow ||
                        e.type == EventType.MouseLeaveWindow ||
                        e.type == EventType.Used
                        ))
                {
                    PropagateToIMGUIContainer(panel.visualTree, evt, captureVE);
                }
            }

            if (evt.target == null && panel != null)
            {
                evt.target = panel.visualTree;
            }
            ExecuteDefaultAction(evt);
        }
예제 #16
0
        internal static void BeginContainerGUI(GUILayoutUtility.LayoutCache cache, Event evt, IMGUIContainer container)
        {
            if (container.useOwnerObjectGUIState)
            {
                GUIUtility.BeginContainerFromOwner(container.elementPanel.ownerObject);
            }
            else
            {
                GUIUtility.BeginContainer(container.guiState);
            }

            s_ContainerStack.Push(container);
            GUIUtility.s_SkinMode   = (int)container.contextType;
            GUIUtility.s_OriginalID = container.elementPanel.ownerObject.GetInstanceID();

            if (Event.current == null)
            {
                Event.current = evt;
            }
            else
            {
                Event.current.CopyFrom(evt);
            }

            // call AFTER setting current event
            if (s_BeginContainerCallback != null)
            {
                s_BeginContainerCallback(container);
            }

            GUI.enabled = container.enabledInHierarchy;
            GUILayoutUtility.BeginContainer(cache);
            GUIUtility.ResetGlobalState();
        }
예제 #17
0
 private void DoOnGUI(Event evt)
 {
     if (this.m_OnGUIHandler != null && base.panel != null)
     {
         int num = GUIClip.Internal_GetCount();
         this.SaveGlobals();
         UIElementsUtility.BeginContainerGUI(this.cache, evt, this);
         if (evt.type != EventType.Layout)
         {
             if (this.lostFocus)
             {
                 if (this.focusController != null)
                 {
                     if (this.focusController.focusedElement == null || this.focusController.focusedElement == this || !(this.focusController.focusedElement is IMGUIContainer))
                     {
                         GUIUtility.keyboardControl = 0;
                         this.focusController.imguiKeyboardControl = 0;
                     }
                 }
                 this.lostFocus = false;
             }
             if (this.receivedFocus)
             {
                 if (this.focusChangeDirection != FocusChangeDirection.unspecified && this.focusChangeDirection != FocusChangeDirection.none)
                 {
                     if (this.focusChangeDirection == VisualElementFocusChangeDirection.left)
                     {
                         GUIUtility.SetKeyboardControlToLastControlId();
                     }
                     else if (this.focusChangeDirection == VisualElementFocusChangeDirection.right)
                     {
                         GUIUtility.SetKeyboardControlToFirstControlId();
                     }
                 }
                 this.receivedFocus        = false;
                 this.focusChangeDirection = FocusChangeDirection.unspecified;
                 if (this.focusController != null)
                 {
                     this.focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
                 }
             }
         }
         this.GUIDepth = GUIUtility.Internal_GetGUIDepth();
         EventType type = Event.current.type;
         bool      flag = false;
         try
         {
             Matrix4x4 objectTransform;
             Rect      clipRect;
             IMGUIContainer.GetCurrentTransformAndClip(this, evt, out objectTransform, out clipRect);
             using (new GUIClip.ParentClipScope(objectTransform, clipRect))
             {
                 this.m_OnGUIHandler();
             }
         }
         catch (Exception exception)
         {
             if (type != EventType.Layout)
             {
                 throw;
             }
             flag = GUIUtility.IsExitGUIException(exception);
             if (!flag)
             {
                 Debug.LogException(exception);
             }
         }
         finally
         {
             if (evt.type != EventType.Layout)
             {
                 int keyboardControl = GUIUtility.keyboardControl;
                 int num2            = GUIUtility.CheckForTabEvent(evt);
                 if (this.focusController != null)
                 {
                     if (num2 < 0)
                     {
                         Focusable focusedElement = this.focusController.focusedElement;
                         using (KeyDownEvent pooled = KeyboardEventBase <KeyDownEvent> .GetPooled('\t', KeyCode.Tab, (num2 != -1) ? EventModifiers.Shift : EventModifiers.None))
                         {
                             this.focusController.SwitchFocusOnEvent(pooled);
                         }
                         if (focusedElement == this)
                         {
                             if (this.focusController.focusedElement == this)
                             {
                                 if (num2 == -2)
                                 {
                                     GUIUtility.SetKeyboardControlToLastControlId();
                                 }
                                 else if (num2 == -1)
                                 {
                                     GUIUtility.SetKeyboardControlToFirstControlId();
                                 }
                                 this.newKeyboardFocusControlID            = GUIUtility.keyboardControl;
                                 this.focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
                             }
                             else
                             {
                                 GUIUtility.keyboardControl = 0;
                                 this.focusController.imguiKeyboardControl = 0;
                             }
                         }
                     }
                     else if (num2 > 0)
                     {
                         this.focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
                         this.newKeyboardFocusControlID            = GUIUtility.keyboardControl;
                     }
                     else if (num2 == 0)
                     {
                         if (keyboardControl != GUIUtility.keyboardControl || type == EventType.MouseDown)
                         {
                             this.focusController.SyncIMGUIFocus(GUIUtility.keyboardControl, this);
                         }
                     }
                 }
                 this.hasFocusableControls = GUIUtility.HasFocusableControls();
             }
         }
         EventType type2 = Event.current.type;
         UIElementsUtility.EndContainerGUI();
         this.RestoreGlobals();
         if (!flag)
         {
             if (type2 != EventType.Ignore && type2 != EventType.Used)
             {
                 int num3 = GUIClip.Internal_GetCount();
                 if (num3 > num)
                 {
                     Debug.LogError("GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced)");
                 }
                 else if (num3 < num)
                 {
                     Debug.LogError("GUI Error: You are popping more GUIClips than you are pushing. Make sure they are balanced)");
                 }
             }
         }
         while (GUIClip.Internal_GetCount() > num)
         {
             GUIClip.Internal_Pop();
         }
         if (type2 == EventType.Used)
         {
             base.Dirty(ChangeType.Repaint);
         }
     }
 }