Пример #1
0
        /// <summary>
        /// fill out lastDrawPosition for Draw
        /// </summary>
        protected override void GetDrawPositions(Rect position)
        {
            lastDrawPosition        = position;
            lastDrawPosition.height = Height;

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }
Пример #2
0
        private void GetDrawPositions(Rect openPosition)
        {
            width = openPosition.width;

            viewRect        = openPosition;
            viewRect.width  = width;
            viewRect.height = TotalHeight;
            viewRect.x      = 0f;
            viewRect.y      = 0f;

            filterFieldRect        = viewRect;
            filterFieldRect.height = FilterAreaHeight;
            filterFieldRect.x     += 7f;
            filterFieldRect.y      = 6f;
            filterFieldRect.width -= 16f + 14f;

            filterDiscardRect       = filterFieldRect;
            filterDiscardRect.x    += filterFieldRect.width;
            filterDiscardRect.width = 16f;
            filterDiscardRect.y    += 1f;

            headerRect        = viewRect;
            headerRect.y     += FilterAreaHeight;
            headerRect.height = NavigationBarHeight;

            backArrowRect        = headerRect;
            backArrowRect.width  = 13f;
            backArrowRect.height = 13f;
            backArrowRect.x     += 3f;
            backArrowRect.y     += 5f;

            headerLabelRect = headerRect;
            float labelOffset = backArrowRect.xMax - headerRect.x;

            headerLabelRect.x     += labelOffset;
            headerLabelRect.width -= labelOffset;

            dividerRect        = headerRect;
            dividerRect.y      = TopPartHeight;
            dividerRect.height = 1f;
            dividerRect.width  = width;

            viewRect.y      = TopPartHeight;
            viewRect.height = ScrollAreaHeight;

            contentRect        = viewRect;
            contentRect.y      = 0f;
            contentRect.height = currentViewItemCount * DrawGUI.SingleLineHeight;

            bool hasVerticalScrollBar = contentRect.height > ScrollAreaHeight;

            if (hasVerticalScrollBar)
            {
                contentRect.width = width - DrawGUI.ScrollBarWidth;
            }

            viewRect.y = TopPartHeight;

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }
Пример #3
0
        /// <inheritdoc/>
        protected override void GetDrawPositions(Rect position)
        {
            lastDrawPosition = position;
            float totalHeight = Height;

            lastDrawPosition.height = totalHeight;

            lastDrawPosition = position;

            if (DrawInSingleRow)
            {
                lastDrawPosition.GetLabelAndControlRects(label, out labelLastDrawPosition, out bodyLastDrawPosition);
            }
            else
            {
                labelLastDrawPosition = position;
                float headerHeight = HeaderHeight;
                labelLastDrawPosition.height = headerHeight;

                bodyLastDrawPosition        = position;
                bodyLastDrawPosition.y     += headerHeight;
                bodyLastDrawPosition.height = totalHeight - headerHeight;
            }

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }
Пример #4
0
        /// <inheritdoc/>
        protected override void GetDrawPositions(Rect position)
        {
            if (!drawHeader && !DrawInSingleRow)
            {
                                #if DEV_MODE && PI_ASSERTATIONS
                Debug.Assert(position.width > 0f, ToString() + ".GetDrawPositions position width <= 0f: " + position);
                                #endif

                lastDrawPosition        = position;
                lastDrawPosition.height = 0f;                 //Height - HeaderHeight;

                labelLastDrawPosition = lastDrawPosition;

                bodyLastDrawPosition        = lastDrawPosition;
                bodyLastDrawPosition.y     += lastDrawPosition.height;
                bodyLastDrawPosition.height = DrawGUI.SingleLineHeight;

                DrawGUI.AddMarginsAndIndentation(ref labelLastDrawPosition);
                const float FoldoutArrowSize = 12f;
                labelLastDrawPosition.x     -= FoldoutArrowSize;
                labelLastDrawPosition.width += FoldoutArrowSize;

                localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
            }
            else
            {
                base.GetDrawPositions(position);
            }
        }
Пример #5
0
        /// <inheritdoc />
        protected override void GetDrawPositions(Rect position)
        {
            lastDrawPosition        = position;
            lastDrawPosition.height = Height;

            lastDrawPosition.GetLabelAndControlRects(label, out labelLastDrawPosition, out textFieldDrawPosition);

            textAreaDrawPosition = lastDrawPosition;
            DrawGUI.AddMarginsAndIndentation(ref textAreaDrawPosition);
            DrawGUI.RemoveFirstLine(ref textAreaDrawPosition);

            if (textArea)
            {
                labelLastDrawPosition = lastDrawPosition;
                DrawGUI.AddMargins(ref labelLastDrawPosition);
                labelLastDrawPosition.height = DrawGUI.SingleLineHeight;
                controlLastDrawPosition      = textAreaDrawPosition;
            }
            else
            {
                controlLastDrawPosition = textFieldDrawPosition;
            }

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }
        /// <summary>
        /// fill out lastDrawPosition, labelLastDrawPosition and controlLastDrawPosition
        /// So that DrawPrefix and DrawControl etc. can do their things
        /// </summary>
        protected override void GetDrawPositions(Rect position)
        {
            lastDrawPosition        = position;
            lastDrawPosition.height = Height;

            lastDrawPosition.GetLabelAndControlRects(label, out labelLastDrawPosition, out controlLastDrawPosition);

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }
Пример #7
0
        /// <inheritdoc />
        protected override void GetDrawPositions(Rect position)
        {
            labelLastDrawPosition = position;
            DrawGUI.AddMarginsAndIndentation(ref labelLastDrawPosition);

            UpdateHeight(labelLastDrawPosition.width);

            lastDrawPosition        = position;
            lastDrawPosition.height = height;

            labelLastDrawPosition.y     += PreviousFieldOffset;
            labelLastDrawPosition.height = height - PreviousFieldOffset;

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }
Пример #8
0
        /// <inheritdoc />
        protected override void GetDrawPositions(Rect position)
        {
            splitterRect        = position;
            splitterRect.height = 1f;
            splitterRect.y     += 3f;
            splitterRect.width  = Screen.width;

            boxRect        = position;
            boxRect.y     += 8f;
            boxRect.height = BoxHeight;

            lastDrawPosition = position;

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }
Пример #9
0
        /// <inheritdoc />
        protected override void GetDrawPositions(Rect position)
        {
            lastDrawPosition        = position;
            lastDrawPosition.height = Height;

            labelLastDrawPosition = lastDrawPosition;

            //hide the prefix label if there's not enough space or if label is empty
            labelLastDrawPosition.width = labelLastDrawPosition.width >= DrawGUI.MinWidthWithSingleLetterPrefix && (label.text.Length > 0 || label.image != null) ? DrawGUI.SingleLetterPrefixWidth : 0f;

            controlLastDrawPosition       = labelLastDrawPosition;
            controlLastDrawPosition.x    += labelLastDrawPosition.width;
            controlLastDrawPosition.width = position.width - labelLastDrawPosition.width;

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }
Пример #10
0
        /// <inheritdoc />
        protected override void GetDrawPositions(Rect position)
        {
            splitterRect        = position;
            splitterRect.height = 1f;
            splitterRect.width  = Screen.width;

            buttonRect       = position;
            buttonRect.y    += 15f;
            buttonRect.width = ButtonWidth;
            //rounding to a whole number is important to avoid blurry text and textures
            buttonRect.x      = Mathf.FloorToInt(DrawGUI.InspectorWidth * 0.5f - ButtonWidth * 0.5f);
            buttonRect.height = ButtonHeight;

            lastDrawPosition = position;

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }
Пример #11
0
        /// <inheritdoc/>
        protected override void GetDrawPositions(Rect position)
        {
            lastDrawPosition        = position;
            lastDrawPosition.height = HeaderHeight;

            labelLastDrawPosition         = lastDrawPosition;
            labelLastDrawPosition.y      += VerticalPadding;
            labelLastDrawPosition.height -= VerticalPadding + VerticalPadding;

            DrawGUI.AddMarginsAndIndentation(ref labelLastDrawPosition);

            if (!DrawInSingleRow)
            {
                const float foldoutArrowSize = 12f;
                labelLastDrawPosition.x     -= foldoutArrowSize;
                labelLastDrawPosition.width += foldoutArrowSize;
            }

            buttonRect        = labelLastDrawPosition;
            buttonRect.width  = DrawGUI.MinControlFieldWidth - DrawGUI.RightPadding - DrawGUI.MiddlePadding - 1f;
            buttonRect.x      = lastDrawPosition.xMax - buttonRect.width - DrawGUI.RightPadding - 2f;
            buttonRect.y     += 1f;
            buttonRect.height = 18f;

            labelLastDrawPosition.width = buttonRect.x - labelLastDrawPosition.x;

            backgroundRect         = lastDrawPosition;
            backgroundRect.x      += DrawGUI.RightPadding;
            backgroundRect.width  -= DrawGUI.RightPadding + DrawGUI.RightPadding;
            backgroundRect.y      += 1f;
            backgroundRect.height -= 2f;

            if (DrawInSingleRow)
            {
                bodyLastDrawPosition = buttonRect;
            }
            else
            {
                bodyLastDrawPosition    = lastDrawPosition;
                bodyLastDrawPosition.y += lastDrawPosition.height;
            }

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }
        /// <inheritdoc />
        protected sealed override void GetDrawPositions(Rect position)
        {
            if (DrawSnapIcon)
            {
                lastDrawPosition        = position;
                lastDrawPosition.height = HeaderHeight;

                lastDrawPosition.GetLabelAndControlRects(label, out labelLastDrawPosition, out bodyLastDrawPosition);

                // make room for the snapping icon
                bodyLastDrawPosition.x     += DrawGUI.SingleLineHeight;
                bodyLastDrawPosition.width -= DrawGUI.SingleLineHeight;

                bodyLastDrawPosition.GetSingleRowControlRects(visibleMembers, ref memberRects);

                localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
                return;
            }

            base.GetDrawPositions(position);
        }
Пример #13
0
        /// <summary>
        /// Waits until the active inspector has finished rendering and then opens the menu
        /// at the given position as a dropdown menu.
        /// Delaying the opening of the menu like this can help avoid with some graphical glitches that
        /// can happen if the menu is opened in the middle of an inspector being drawn
        /// </summary>
        /// <param name="menu"> Menu that should be opened. </param>
        /// <param name="position"> Position where menu should be opened. </param>
        /// <param name="disposeAfter">
        /// Should the menu object be disposed after menu has been opened?
        /// Set this to false if the Menu is cached and reused, otherwise set this true.
        /// </param>
        /// <param name="inspector"> Inspector for which the context menu is being opened. Null if not opening for any inspector. </param>
        /// <param name="inspectorPart"> Part of the inspector for which the context menu is being opened. None if not opening for any inspector. </param>
        /// <param name="subject"> IDrawer whose context menu is being opened. Null if context menu doesn't belong to any IDrawer (e.g. toolbar menu item). </param>
        /// <param name="part"> Can contain the part of the subject for which the context menu is opened. E.g. reference to the targeted toolbar item. </param>
        /// <param name="doOnMenuClosed"> Delegate to be called once menu has closed. Set to ContextMenuUtility.SelectLastContextMenuSubject to select the context menu subject once the context menu window has been closed. Can be null. </param>
        public static void OpenAt([NotNull] Menu menu, Rect position, bool disposeAfter, [CanBeNull] IInspector inspector, InspectorPart inspectorPart, [CanBeNull] IDrawer subject, [CanBeNull] object part, [CanBeNull] Action <object> doOnMenuClosed)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(menu != null);
            Debug.Assert(menu.Count > 0);
            Debug.Assert(position.x >= 0f);
            Debug.Assert(position.y >= 0f);
            Debug.Assert(position.x < Screen.currentResolution.width);
            Debug.Assert(position.y < Screen.currentResolution.height);
            if (subject != null)
            {
                Debug.Assert(inspector != null);
                Debug.Assert(inspector == subject.Inspector);
                Debug.Assert(inspectorPart == InspectorPart.Viewport);
            }
            Debug.Assert(inspectorPart != InspectorPart.None || inspector == null);
            Debug.Assert(inspectorPart == InspectorPart.None || inspector != null);
                        #endif

            openingMenu              = menu;
            openingMenuInspector     = inspector;
            openingMenuInspectorPart = inspectorPart;
            openingMenuSubject       = new DrawerTarget(subject);
            openingMenuPart          = part;
            disposeMenuAfterOpening  = disposeAfter;
            onMenuClosed             = doOnMenuClosed;

            var openAtLocalPoint  = position.position;
            var openAtScreenPoint = GUIUtility.GUIToScreenPoint(openAtLocalPoint);
            position.position   = openAtScreenPoint;
            openingMenuPosition = position;

            if (IsSafeToChangeInspectorContents || inspector == null)
            {
                                #if DEV_MODE && DEBUG_OPEN_MENU
                Debug.Log("Opening context menu @ " + position + " immediately.");
                                #endif
                OpenContextMenu();
            }
            else
            {
                                #if DEV_MODE && DEBUG_OPEN_MENU
                Debug.Log("Opening context menu @ " + position + " delayed... inspector.State.WindowRect.y=" + inspector.State.WindowRect.y + ", LocalDrawAreaOffset=" + DrawGUI.GetLocalDrawAreaOffset());
                                #endif

                openDelayCounter = 2;
                inspector.RefreshView();
            }
        }
Пример #14
0
        /// <inheritdoc />
        protected override void GetDrawPositions(Rect position)
        {
            lastDrawPosition        = position;
            lastDrawPosition.height = HeaderHeight;

            bodyLastDrawPosition    = lastDrawPosition;
            bodyLastDrawPosition.y += lastDrawPosition.height;

            labelLastDrawPosition = lastDrawPosition;
            DrawGUI.AddMarginsAndIndentation(ref labelLastDrawPosition);
            if (!DrawInSingleRow)
            {
                float foldoutArrowSize = 12f;
                labelLastDrawPosition.x     -= foldoutArrowSize;
                labelLastDrawPosition.width += foldoutArrowSize;
            }

            backgroundRect        = lastDrawPosition;
            backgroundRect.x     += DrawGUI.RightPadding;
            backgroundRect.width -= DrawGUI.RightPadding + DrawGUI.RightPadding;

            if (showGetButton)
            {
                if (showSetButton)
                {
                    getButtonRect = labelLastDrawPosition;
                    float totalWidth = DrawGUI.MinControlFieldWidth - DrawGUI.MiddlePadding - DrawGUI.RightPadding - 1f;
                    getButtonRect.x = lastDrawPosition.xMax - totalWidth - DrawGUI.RightPadding - 2f;
                    float buttonWidth = (totalWidth - 3f) * 0.5f;
                    getButtonRect.width   = buttonWidth;
                    getButtonRect.y      += 1f;
                    getButtonRect.height -= 2f;

                    setButtonRect    = getButtonRect;
                    setButtonRect.x += getButtonRect.width + 3f;

                    if (DrawInSingleRow)
                    {
                        bodyLastDrawPosition       = getButtonRect;
                        bodyLastDrawPosition.width = totalWidth;
                    }
                }
                else
                {
                    getButtonRect         = labelLastDrawPosition;
                    getButtonRect.width   = DrawGUI.MinControlFieldWidth - DrawGUI.RightPadding - DrawGUI.MiddlePadding - 1f;
                    getButtonRect.x       = lastDrawPosition.xMax - getButtonRect.width - DrawGUI.RightPadding - 2f;
                    getButtonRect.y      += 1f;
                    getButtonRect.height -= 2f;

                    if (DrawInSingleRow)
                    {
                        bodyLastDrawPosition = getButtonRect;
                    }
                }

                labelLastDrawPosition.width = getButtonRect.x - labelLastDrawPosition.x;
            }
            else if (showSetButton)
            {
                setButtonRect         = labelLastDrawPosition;
                setButtonRect.width   = DrawGUI.MinControlFieldWidth - DrawGUI.RightPadding - DrawGUI.MiddlePadding - 1f;
                setButtonRect.x       = lastDrawPosition.xMax - setButtonRect.width - DrawGUI.RightPadding - 2f;
                setButtonRect.y      += 1f;
                setButtonRect.height -= 2f;

                labelLastDrawPosition.width = setButtonRect.x - labelLastDrawPosition.x;

                if (DrawInSingleRow)
                {
                    bodyLastDrawPosition = setButtonRect;
                }
            }

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }
Пример #15
0
        private void OnMouseoverSlider()
        {
            //trigger a repaint every frame for better responsiveness
            GUI.changed = true;

            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            var currentDrawAreaOffset    = DrawGUI.GetLocalDrawAreaOffset();
            var drawAreaOffsetDifference = currentDrawAreaOffset - localDrawAreaOffset;

            var visualSliderRect = SliderPosition;

            var effectiveSliderRect = SliderClickableAreaRect;

            var mousePos = Event.current.mousePosition;

            var effectiveMouseX = Mathf.Clamp(mousePos.x + drawAreaOffsetDifference.x, effectiveSliderRect.x + drawAreaOffsetDifference.x, effectiveSliderRect.x + drawAreaOffsetDifference.x + effectiveSliderRect.width);
            var valueAtCursor   = GetSliderValueAt(effectiveMouseX);

            double pCurrent      = MathUtils.Subtract(Value, min) / MathUtils.Subtract(max, min);
            int    currentValueX = (int)(visualSliderRect.x + MathUtils.Lerp(0d, visualSliderRect.width, pCurrent));

            //if cursor is not over the slider then draw the click cursor
            //and display value at current cursor position as a tooltip
            int diff = MathUtils.Abs(Mathf.RoundToInt(effectiveMouseX - currentValueX));

            if (diff > 6)
            {
                var tooltip = GUIContentPool.Create(StringUtils.ToString(valueAtCursor));

                var tooltipRect = labelLastDrawPosition;
                tooltipRect.x      -= drawAreaOffsetDifference.x;
                tooltipRect.y      -= drawAreaOffsetDifference.y;
                tooltipRect.height -= 2f;
                var tooltipWidth = DrawGUI.tooltipStyle.CalcSize(tooltip).x;
                tooltipRect.x     = mousePos.x - tooltipWidth * 0.5f + 1f;
                tooltipRect.y    -= DrawGUI.SingleLineHeight;
                tooltipRect.width = tooltipWidth;

                DrawGUI.Active.TooltipBox(tooltipRect, tooltip);
                GUIContentPool.Dispose(ref tooltip);

                effectiveSliderRect.x     = mousePos.x - 3f;
                effectiveSliderRect.y    -= drawAreaOffsetDifference.y;
                effectiveSliderRect.width = 8f;

                                #if UNITY_2019_3_OR_NEWER
                effectiveSliderRect.y -= 4f;
                                #endif

                var guiColorWas = GUI.color;
                var setGuiColor = guiColorWas;
                setGuiColor.a = 0.5f;
                GUI.color     = setGuiColor;
                GUI.Label(effectiveSliderRect, " ", InspectorPreferences.Styles.RangeIndicator);
                GUI.color = guiColorWas;
            }
        }
Пример #16
0
        private void GetDrawPositions(Rect openPosition)
        {
            viewRect        = openPosition;
            viewRect.width  = Width;
            viewRect.height = TotalHeight;
            viewRect.x      = 0f;
            viewRect.y      = 0f;

            filterFieldRect        = viewRect;
            filterFieldRect.height = FilterAreaHeight;
            filterFieldRect.x     += 7f;
            filterFieldRect.y      = 6f;
            filterFieldRect.width -= 16f + 14f;

            filterDiscardRect       = filterFieldRect;
            filterDiscardRect.x    += filterFieldRect.width;
            filterDiscardRect.width = 16f;
            filterDiscardRect.y    += 1f;

            headerRect        = viewRect;
            headerRect.y     += FilterAreaHeight;
            headerRect.height = NavigationBarHeight;

            backArrowRect        = headerRect;
            backArrowRect.width  = 13f;
            backArrowRect.height = 13f;
            backArrowRect.x     += 3f;
            backArrowRect.y     += 5f;

                        #if UNITY_EDITOR
            createScriptButtonRect        = headerRect;
            createScriptButtonRect.width  = 10f;
            createScriptButtonRect.height = 10f;
            createScriptButtonRect.x      = headerRect.width - 18f;
            createScriptButtonRect.y     += 4f;
                        #endif

            headerLabelRect = headerRect;
            float leftOffset = backArrowRect.xMax - headerRect.x;
            headerLabelRect.x += leftOffset;
            float removeWidth = leftOffset;
                        #if UNITY_EDITOR
            removeWidth += createScriptButtonRect.x - createScriptButtonRect.xMax;
                        #endif
            headerLabelRect.width -= removeWidth;

            dividerRect        = headerRect;
            dividerRect.y      = TopPartHeight;
            dividerRect.height = 1f;
            dividerRect.width  = Width;

            viewRect.y      = TopPartHeight;
            viewRect.height = ScrollAreaHeight;

            contentRect        = viewRect;
            contentRect.height = members.Length * DrawGUI.SingleLineHeight;

            bool hasVerticalScrollBar = contentRect.height > ScrollAreaHeight;
            if (hasVerticalScrollBar)
            {
                contentRect.width = Width - DrawGUI.ScrollBarWidth;
            }

            viewRect.y = TopPartHeight;

            localDrawAreaOffset = DrawGUI.GetLocalDrawAreaOffset();
        }