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);
         }
     }
 }
Esempio n. 2
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();
         }
     }
 }
Esempio n. 3
0
        private static void TakeCapture()
        {
            if (s_ContainerStack.Count > 0)
            {
                var topmostContainer = s_ContainerStack.Peek();

                if (topmostContainer.GUIDepth != GUIUtility.Internal_GetGUIDepth())
                {
                    return;
                }

                if (MouseCaptureController.IsMouseCaptureTaken() && !topmostContainer.HasMouseCapture())
                {
                    Debug.Log("Should not grab hot control with an active capture");
                }
                topmostContainer.TakeMouseCapture();
            }
        }
        private void DoOnGUI(Event evt)
        {
            if (m_OnGUIHandler == null ||
                panel == null)
            {
                return;
            }

            // Save the GUIClip count to make sanity checks after calling the OnGUI handler
            int guiClipCount = GUIClip.Internal_GetCount();

            SaveGlobals();

            UIElementsUtility.BeginContainerGUI(cache, evt, this);

            if (evt.type != EventType.Layout)
            {
                if (lostFocus)
                {
                    if (focusController != null)
                    {
                        // We dont want to clear the GUIUtility.keyboardControl if another IMGUIContainer
                        // just set it in the if (receivedFocus) block below. So we only clear it if either
                        //
                        // - there is no focused element
                        // - we are the currently focused element (that would be surprising)
                        // - the currently focused element is not an IMGUIContainer (in this case,
                        //   GUIUtility.keyboardControl should be 0).
                        if (focusController.focusedElement == null || focusController.focusedElement == this || !(focusController.focusedElement is IMGUIContainer))
                        {
                            GUIUtility.keyboardControl           = 0;
                            focusController.imguiKeyboardControl = 0;
                        }
                    }
                    lostFocus = false;
                }

                if (receivedFocus)
                {
                    // If we just received the focus and GUIUtility.keyboardControl is not already one of our control,
                    // set the GUIUtility.keyboardControl to our first or last focusable control.
                    if (focusChangeDirection != FocusChangeDirection.unspecified && focusChangeDirection != FocusChangeDirection.none)
                    {
                        // We assume we are using the VisualElementFocusRing.
                        if (focusChangeDirection == VisualElementFocusChangeDirection.left)
                        {
                            GUIUtility.SetKeyboardControlToLastControlId();
                        }
                        else if (focusChangeDirection == VisualElementFocusChangeDirection.right)
                        {
                            GUIUtility.SetKeyboardControlToFirstControlId();
                        }
                    }
                    receivedFocus        = false;
                    focusChangeDirection = FocusChangeDirection.unspecified;
                    if (focusController != null)
                    {
                        focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
                    }
                }
                // We intentionally don't send the NewKeuboardFocus command here since it creates an issue with the AutomatedWindow
                // newKeyboardFocusControlID = GUIUtility.keyboardControl;
            }

            GUIDepth = GUIUtility.Internal_GetGUIDepth();
            EventType originalEventType = Event.current.type;

            bool isExitGUIException = false;

            try
            {
                // On a layout event, we should not try to get the worldTransform... it is dependant on the layout, which is being calculated (thus, not good)
                if (originalEventType != EventType.Layout)
                {
                    Matrix4x4 currentTransform;
                    Rect      clippingRect;
                    GetCurrentTransformAndClip(this, evt, out currentTransform, out clippingRect);

                    // Push UIElements matrix in GUIClip to make mouse position relative to the IMGUIContainer top left
                    using (new GUIClip.ParentClipScope(currentTransform, clippingRect))
                    {
                        m_OnGUIHandler();
                    }
                }
                else
                {
                    m_OnGUIHandler();
                }
            }
            catch (Exception exception)
            {
                // only for layout events: we always intercept any exceptions to not interrupt event processing
                if (originalEventType == EventType.Layout)
                {
                    isExitGUIException = GUIUtility.IsExitGUIException(exception);
                    if (!isExitGUIException)
                    {
                        Debug.LogException(exception);
                    }
                }
                else
                {
                    // rethrow event if not in layout
                    throw;
                }
            }
            finally
            {
                if (evt.type != EventType.Layout)
                {
                    int currentKeyboardFocus = GUIUtility.keyboardControl;
                    int result = GUIUtility.CheckForTabEvent(evt);
                    if (focusController != null)
                    {
                        if (result < 0)
                        {
                            // If CheckForTabEvent returns -1 or -2, we have reach the end/beginning of its control list.
                            // We should switch the focus to the next VisualElement.
                            Focusable currentFocusedElement = focusController.focusedElement;
                            using (KeyDownEvent e = KeyDownEvent.GetPooled('\t', KeyCode.Tab, result == -1 ? EventModifiers.None : EventModifiers.Shift))
                            {
                                focusController.SwitchFocusOnEvent(e);
                            }

                            if (currentFocusedElement == this)
                            {
                                if (focusController.focusedElement == this)
                                {
                                    // We still have the focus. We should cycle around our controls.
                                    if (result == -2)
                                    {
                                        GUIUtility.SetKeyboardControlToLastControlId();
                                    }
                                    else if (result == -1)
                                    {
                                        GUIUtility.SetKeyboardControlToFirstControlId();
                                    }

                                    newKeyboardFocusControlID            = GUIUtility.keyboardControl;
                                    focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
                                }
                                else
                                {
                                    // We lost the focus. Set the focused element ID to 0 until next
                                    // IMGUIContainer have a chance to set it to its own control.
                                    // Doing this will ensure we draw ourselves without any focused control.
                                    GUIUtility.keyboardControl           = 0;
                                    focusController.imguiKeyboardControl = 0;
                                }
                            }
                        }
                        else if (result > 0)
                        {
                            // A positive result indicates that the focused control has changed to one of our elements; result holds the control id.
                            focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
                            newKeyboardFocusControlID            = GUIUtility.keyboardControl;
                        }
                        else if (result == 0)
                        {
                            // This means the event is not a tab. Synchronize our focus info with IMGUI.
                            if (currentKeyboardFocus != GUIUtility.keyboardControl || originalEventType == EventType.MouseDown)
                            {
                                focusController.SyncIMGUIFocus(GUIUtility.keyboardControl, this);
                            }
                        }
                    }

                    // Cache the fact that we have focusable controls or not.
                    hasFocusableControls = GUIUtility.HasFocusableControls();
                }
            }

            // The Event will probably be nuked with the next function call, so we get its type now.
            EventType eventType = Event.current.type;

            UIElementsUtility.EndContainerGUI();
            RestoreGlobals();

            if (!isExitGUIException)
            {
                // This is the same logic as GUIClipState::EndOnGUI
                if (eventType != EventType.Ignore && eventType != EventType.Used)
                {
                    int currentCount = GUIClip.Internal_GetCount();
                    if (currentCount > guiClipCount)
                    {
                        Debug.LogError("GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced)");
                    }
                    else if (currentCount < guiClipCount)
                    {
                        Debug.LogError("GUI Error: You are popping more GUIClips than you are pushing. Make sure they are balanced)");
                    }
                }
            }

            // Clear extraneous GUIClips
            while (GUIClip.Internal_GetCount() > guiClipCount)
            {
                GUIClip.Internal_Pop();
            }

            if (eventType == EventType.Used)
            {
                Dirty(ChangeType.Repaint);
            }
        }
Esempio n. 5
0
        private bool DoOnGUI(Event evt)
        {
            bool result;

            if (this.m_OnGUIHandler == null || base.panel == null)
            {
                result = false;
            }
            else
            {
                int num = GUIClip.Internal_GetCount();
                this.SaveGlobals();
                int instanceID = (this.executionContext == 0) ? base.elementPanel.instanceID : this.executionContext;
                UIElementsUtility.BeginContainerGUI(this.cache, instanceID, evt, this);
                this.GUIDepth = GUIUtility.Internal_GetGUIDepth();
                EventType type = Event.current.type;
                bool      flag = false;
                try
                {
                    this.m_OnGUIHandler();
                }
                catch (Exception exception)
                {
                    if (type != EventType.Layout)
                    {
                        throw;
                    }
                    flag = GUIUtility.IsExitGUIException(exception);
                    if (!flag)
                    {
                        Debug.LogException(exception);
                    }
                }
                GUIUtility.CheckForTabEvent(evt);
                EventType type2 = Event.current.type;
                UIElementsUtility.EndContainerGUI();
                this.RestoreGlobals();
                if (!flag)
                {
                    if (type2 != EventType.Ignore && type2 != EventType.Used)
                    {
                        int num2 = GUIClip.Internal_GetCount();
                        if (num2 > num)
                        {
                            Debug.LogError("GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced)");
                        }
                        else if (num2 < 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);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            return(result);
        }
Esempio n. 6
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);
         }
     }
 }