Пример #1
0
        /// <summary>
        /// Handles the resize functionality of the split for a horizontal window
        /// </summary>
        private void ResizeHorizontalSplit()
        {
            float width = GetConstrainedValue();

            Rect resizeHandleRect = new Rect(width,
                                             availableRect.y, 2f, availableRect.height);

            GUIExtensions.DrawVerticalLine(resizeHandleRect, Color.gray);

            EditorGUIUtility.AddCursorRect(resizeHandleRect, MouseCursor.ResizeHorizontal);

            CheckIsResizing(resizeHandleRect, SplitDirection.Horizontal);
        }
        private static void DrawSplitArea(Rect rect, bool splitVertically,
                                          System.Action <Rect> leftRender, System.Action <Rect> rightRender,
                                          float startSplit = 0.5f, Color?separatorColor = null, GUIStyle separatorStyle = null)
        {
            if (separatorColor == null)
            {
                separatorColor = Color.gray;
            }

            int controlId = GUIUtility.GetControlID(FocusType.Passive);

            SplitViewState state = (SplitViewState)GUIUtility.GetStateObject(
                typeof(SplitViewState), controlId);

            if (state.SplitLocation < 0f && rect.width != 1f)
            {
                state.SplitLocation = rect.width * startSplit;
            }

            float splitLocation = state.SplitLocation;

            Rect separatorRect;

            if (splitVertically)
            {
                separatorRect = new Rect(rect.xMin + splitLocation, rect.yMin, 5f, rect.height);
            }
            else
            {
                separatorRect = new Rect(rect.xMin, rect.yMin + splitLocation, rect.width, 5f);
            }

            switch (Event.current.GetTypeForControl(controlId))
            {
            case EventType.Repaint:

                Rect rect1 = GetSplitRect1(rect, splitVertically, splitLocation);
                Rect rect2 = GetSplitRect2(rect, splitVertically, splitLocation);

                leftRender(rect1);

                GUIExtensions.DrawVerticalLine(separatorRect,
                                               separatorColor.Value, separatorStyle);

                EditorGUIUtility.AddCursorRect(separatorRect, MouseCursor.ResizeHorizontal);

                rightRender(rect2);

                break;

            case EventType.MouseDown:

                if (separatorRect.Contains(Event.current.mousePosition))
                {
                    state.IsResizing = true;
                }

                break;

            case EventType.MouseUp:

                state.IsResizing = false;

                break;

            case EventType.MouseDrag:

                if (state.IsResizing)
                {
                    state.SplitLocation = Mathf.Clamp(Event.current.mousePosition.x, rect.xMin, rect.xMax - 30f);
                    GUI.changed         = true;
                }

                break;

            default:
                break;
            }

            if (state.IsResizing && Event.current.isMouse)
            {
                Event.current.Use();
            }
        }