UnityEditor.DockArea.DragTab C# (CSharp) Method

DragTab() private method

private DragTab ( Rect pos, GUIStyle tabStyle ) : void
pos UnityEngine.Rect
tabStyle UnityEngine.GUIStyle
return void
        private void DragTab(Rect pos, GUIStyle tabStyle)
        {
            int controlID = GUIUtility.GetControlID(FocusType.Passive);
            float tabWidth = this.GetTabWidth(pos.width);
            Event current = Event.current;
            if ((s_DragMode != 0) && (GUIUtility.hotControl == 0))
            {
                PaneDragTab.get.Close();
                ResetDragVars();
            }
            EventType typeForControl = current.GetTypeForControl(controlID);
            switch (typeForControl)
            {
                case EventType.MouseDown:
                    if (pos.Contains(current.mousePosition) && (GUIUtility.hotControl == 0))
                    {
                        int tabAtMousePos = this.GetTabAtMousePos(current.mousePosition, pos);
                        if (tabAtMousePos < this.m_Panes.Count)
                        {
                            switch (current.button)
                            {
                                case 0:
                                    if (tabAtMousePos != this.selected)
                                    {
                                        this.selected = tabAtMousePos;
                                    }
                                    GUIUtility.hotControl = controlID;
                                    s_StartDragPosition = current.mousePosition;
                                    s_DragMode = 0;
                                    current.Use();
                                    break;

                                case 2:
                                    this.m_Panes[tabAtMousePos].Close();
                                    current.Use();
                                    break;
                            }
                        }
                    }
                    goto Label_06B9;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == controlID)
                    {
                        Vector2 vector3 = GUIUtility.GUIToScreenPoint(current.mousePosition);
                        if (s_DragMode != 0)
                        {
                            s_DragMode = 0;
                            PaneDragTab.get.Close();
                            EditorApplication.update = (EditorApplication.CallbackFunction) Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
                            if ((s_DropInfo == null) || (s_DropInfo.dropArea == null))
                            {
                                EditorWindow pane = s_DragPane;
                                ResetDragVars();
                                this.RemoveTab(pane);
                                Rect position = pane.position;
                                position.x = vector3.x - (position.width * 0.5f);
                                position.y = vector3.y - (position.height * 0.5f);
                                if (Application.platform == RuntimePlatform.WindowsEditor)
                                {
                                    position.y = Mathf.Max(InternalEditorUtility.GetBoundsOfDesktopAtPoint(vector3).y, position.y);
                                }
                                EditorWindow.CreateNewWindowForEditorWindow(pane, false, false);
                                pane.position = pane.m_Parent.window.FitWindowRectToScreen(position, true, true);
                                GUIUtility.hotControl = 0;
                                GUIUtility.ExitGUI();
                            }
                            else
                            {
                                s_DropInfo.dropArea.PerformDrop(s_DragPane, s_DropInfo, vector3);
                            }
                            ResetDragVars();
                        }
                        GUIUtility.hotControl = 0;
                        current.Use();
                    }
                    goto Label_06B9;

                case EventType.MouseDrag:
                    if (GUIUtility.hotControl == controlID)
                    {
                        Vector2 vector = current.mousePosition - s_StartDragPosition;
                        current.Use();
                        Rect screenPosition = base.screenPosition;
                        if ((s_DragMode == 0) && (vector.sqrMagnitude > 99f))
                        {
                            s_DragMode = 1;
                            s_PlaceholderPos = this.selected;
                            s_DragPane = this.m_Panes[this.selected];
                            if (this.m_Panes.Count != 1)
                            {
                                s_IgnoreDockingForView = null;
                            }
                            else
                            {
                                s_IgnoreDockingForView = this;
                            }
                            s_OriginalDragSource = this;
                            PaneDragTab.get.content = s_DragPane.titleContent;
                            base.Internal_SetAsActiveWindow();
                            PaneDragTab.get.GrabThumbnail();
                            PaneDragTab.get.Show(new Rect((pos.x + screenPosition.x) + (tabWidth * this.selected), pos.y + screenPosition.y, tabWidth, pos.height), GUIUtility.GUIToScreenPoint(current.mousePosition));
                            EditorApplication.update = (EditorApplication.CallbackFunction) Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
                            GUIUtility.ExitGUI();
                        }
                        if (s_DragMode == 1)
                        {
                            DropInfo di = null;
                            ContainerWindow[] windows = ContainerWindow.windows;
                            Vector2 screenPos = GUIUtility.GUIToScreenPoint(current.mousePosition);
                            ContainerWindow inFrontOf = null;
                            foreach (ContainerWindow window2 in windows)
                            {
                                foreach (View view in window2.mainView.allChildren)
                                {
                                    IDropArea area = view as IDropArea;
                                    if (area != null)
                                    {
                                        di = area.DragOver(s_DragPane, screenPos);
                                    }
                                    if (di != null)
                                    {
                                        break;
                                    }
                                }
                                if (di != null)
                                {
                                    inFrontOf = window2;
                                    break;
                                }
                            }
                            if (di == null)
                            {
                                di = new DropInfo(null);
                            }
                            if (di.type != DropInfo.Type.Tab)
                            {
                                s_PlaceholderPos = -1;
                            }
                            s_DropInfo = di;
                            if (PaneDragTab.get.m_Window != null)
                            {
                                PaneDragTab.get.SetDropInfo(di, screenPos, inFrontOf);
                            }
                        }
                    }
                    goto Label_06B9;

                case EventType.Repaint:
                {
                    float xMin = pos.xMin;
                    int num8 = 0;
                    if (base.actualView == null)
                    {
                        Rect rect5 = new Rect(xMin, pos.yMin, tabWidth, pos.height);
                        float x = Mathf.Round(rect5.x);
                        Rect rect6 = new Rect(x, rect5.y, Mathf.Round(rect5.x + rect5.width) - x, rect5.height);
                        tabStyle.Draw(rect6, "Failed to load", false, false, true, false);
                    }
                    else
                    {
                        for (int i = 0; i < this.m_Panes.Count; i++)
                        {
                            if (s_DragPane != this.m_Panes[i])
                            {
                                if (((s_DropInfo != null) && object.ReferenceEquals(s_DropInfo.dropArea, this)) && (s_PlaceholderPos == num8))
                                {
                                    xMin += tabWidth;
                                }
                                Rect rect3 = new Rect(xMin, pos.yMin, tabWidth, pos.height);
                                float num10 = Mathf.Round(rect3.x);
                                Rect rect4 = new Rect(num10, rect3.y, Mathf.Round(rect3.x + rect3.width) - num10, rect3.height);
                                tabStyle.Draw(rect4, this.m_Panes[i].titleContent, false, false, i == this.selected, base.hasFocus);
                                xMin += tabWidth;
                                num8++;
                            }
                        }
                    }
                    goto Label_06B9;
                }
            }
            if ((typeForControl == EventType.ContextClick) && (pos.Contains(current.mousePosition) && (GUIUtility.hotControl == 0)))
            {
                int num4 = this.GetTabAtMousePos(current.mousePosition, pos);
                if (num4 < this.m_Panes.Count)
                {
                    base.PopupGenericMenu(this.m_Panes[num4], new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f));
                }
            }
        Label_06B9:
            this.selected = Mathf.Clamp(this.selected, 0, this.m_Panes.Count - 1);
        }