Ejemplo n.º 1
0
        public static Rect GetTextHighlightRectForFilter(string text, Rect position, GUIStyle style, int highlightStart, int highlightCount, float offsetX, float offsetY, float adjustWidth)
        {
                        #if ENABLE_PREFIX_HIGHLIGHTING
            var highlightRect = position;
            highlightRect.x += style.contentOffset.x + style.margin.left - 2f;

            var size = style.CalcSize(GUIContentPool.Temp(text.Substring(0, highlightStart)));
            highlightRect.x += size.x;

            size = style.CalcSize(GUIContentPool.Temp(text.Substring(highlightStart, highlightCount)));
            highlightRect.width = size.x;

            highlightRect.x     += offsetX;
            highlightRect.y     += offsetY;
            highlightRect.width += adjustWidth;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(highlightRect.x >= 0f);
            Debug.Assert(highlightRect.width > 0f);
            Debug.Assert(highlightRect.height > 0f);
                        #endif

            return(highlightRect);
                        #else
            return(null);
                        #endif
        }
Ejemplo n.º 2
0
        public override void AssetHeader(Rect position, Object target)
        {
            var label = GUIContentPool.Temp(target.name.Length == 0 ? " " : target.name);
            var pos   = position;

            pos.height = AssetTitlebarHeight(false);

            pos.x     -= IndentWidth;
            pos.width += IndentWidth;

            GUI.Label(pos, label, InspectorPreferences.Styles.GameObjectHeaderBackground);
        }
Ejemplo n.º 3
0
        protected bool DrawFoldableContent(Rect position)
        {
            bool dirty = false;

            for (int n = 0; n < 3; n++)
            {
                var draw = members[n];
                if (draw.ShouldShowInInspector)
                {
                    if (draw.Draw(position))
                    {
                        dirty = true;
                    }
                    DrawGUI.NextLine(ref position);
                }
            }

            if (!UsingLocalSpace)
            {
                position.y     += 3f;
                position.height = 18f;

                if (UsingSnapping)
                {
                    position.width = 90f;
                    position.x     = (DrawGUI.InspectorWidth - (90f + 138f + 5f)) * 0.5f;
                    DrawGUI.Active.Label(position, GUIContentPool.Temp("snapping", "You can open snap settings using menu item Edit/Snap Settings..."), "WarningOverlay");

                    position.x    += 95f;
                    position.width = 138f;
                    DrawGUI.Active.Label(position, GUIContentPool.Temp("using world space", "Position, rotation and scale are listed using world space instead of local space."), "WarningOverlay");
                }
                else
                {
                    position.width = 138f;
                    position.x     = (DrawGUI.InspectorWidth - position.width) * 0.5f;

                    DrawGUI.Active.Label(position, GUIContentPool.Temp("using world space", "Position, rotation and scale are listed using world space instead of local space."), "WarningOverlay");
                }
            }
            else if (UsingSnapping)
            {
                position.y     += 3f;
                position.height = 18f;
                position.width  = 90f;
                position.x      = (DrawGUI.InspectorWidth - position.width) * 0.5f;
                DrawGUI.Active.Label(position, GUIContentPool.Temp("snapping", "You can open snap settings using menu item Edit/Snap Settings..."), "WarningOverlay");
            }

            return(dirty);
        }
Ejemplo n.º 4
0
        public static Rect?GetTextHighlightRectForFilter(string text, Rect position, GUIStyle style, SearchFilter filter, string fullClassName, FilterTestType passedTestMethod, float offsetX, float offsetY, float adjustWidth)
        {
                        #if ENABLE_PREFIX_HIGHLIGHTING
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(filter.HasFilter, "!HasFilter");
            Debug.Assert(passedTestMethod != FilterTestType.None, passedTestMethod.ToString());
            Debug.Assert(fullClassName.Length >= text.Length, "\"" + fullClassName + "\"");
                        #endif

            string filterText = filter.FilterFieldLabel;
            if (filterText.Length == 0)
            {
                filterText = filter.FilterGeneric;
                if (filterText.Length == 0)
                {
                    return(null);
                }
            }

            int highlightStart;
            int highlightCount;
            switch (passedTestMethod)
            {
            case FilterTestType.Label:
                if (!TryGetHighlightStartIndexAndCharCount(text, filterText, out highlightStart, out highlightCount))
                {
                    return(null);
                }
                break;

            case FilterTestType.FullClassName:
            case FilterTestType.Indetermined:
                if (fullClassName.Length > text.Length && filterText.IndexOf('.') != -1)
                {
                    highlightStart = GetHighlightStartIndex(text, filterText, out filterText);
                    highlightCount = filterText.Length;
                }
                else
                {
                    if (!TryGetHighlightStartIndexAndCharCount(text, filterText, out highlightStart, out highlightCount))
                    {
                        return(null);
                    }
                }
                break;

            default:
                return(null);
            }

            if (highlightStart == -1)
            {
                return(null);
            }

            var highlightRect = position;
            highlightRect.x += style.contentOffset.x + style.margin.left - 2f;

            var size = style.CalcSize(GUIContentPool.Temp(text.Substring(0, highlightStart)));
            highlightRect.x += size.x;

            size = style.CalcSize(GUIContentPool.Temp(text.Substring(highlightStart, highlightCount)));
            highlightRect.width = size.x;

            highlightRect.x     += offsetX;
            highlightRect.y     += offsetY;
            highlightRect.width += adjustWidth;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(highlightRect.x >= 0f);
            Debug.Assert(highlightRect.width > 0f);
            Debug.Assert(highlightRect.height > 0f);
                        #endif

            return(highlightRect);
                        #else
            return(null);
                        #endif
        }
Ejemplo n.º 5
0
        public string DrawFilterField(IInspector inspector, int id, Rect position, string text, bool setIsSelected, out bool textChanged)
        {
            var e         = Event.current;
            var eventType = e.GetTypeForControl(id);

            editor.style = style;

            bool wasSelected = isSelected;

            if (setIsSelected != isSelected)
            {
                                #if DEV_MODE && DEBUG_ENABLED
                Debug.Log(StringUtils.ToColorizedString("SearchBox.isSelected = ", setIsSelected));
                                #endif

                isSelected = setIsSelected;

                if (isSelected)
                {
                    KeyboardControlUtility.KeyboardControl = id;
                    BeginEditing(id, position, style);

                    if (eventType == EventType.MouseDown || eventType == EventType.MouseUp)
                    {
                        editor.MoveCursorToPosition(e.mousePosition);
                        if (GUI.skin.settings.cursorColor.a > 0f)
                        {
                                                        #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.SelectAllOnMouseUp");
                                                        #endif
                            selectAllOnMouseUp = true;
                        }
                    }
                    else
                    {
                                                #if DEV_MODE && DEBUG_ENABLED
                        Debug.Log("SearchBox.SelectAll");
                                                #endif
                        editor.SelectAll();
                    }
                }
            }

            string textInput = text;

            if (text == null)
            {
                text = "";
            }

                        #if DEV_MODE && DEBUG_ENABLED
            if (e.rawType == EventType.MouseDown || e.rawType == EventType.MouseUp || GUIUtility.hotControl == id)
            {
                Debug.Log(StringUtils.ToColorizedString("SearchBox Event=", e, ", typeForControl=", eventType, ", button=", e.button, ", pos=", position, ", mousePos=", e.mousePosition, ", pos.Contains(mousePos)=", position.Contains(e.mousePosition), ", HasKeyboardFocus=", HasKeyboardFocus(), ", isSelected=", isSelected, ", GUIUtility.hotControl=", GUIUtility.hotControl, ", id=", id));
            }
                        #endif

            if (isSelected && inspector.InspectorDrawer.HasFocus)
            {
                KeyboardControlUtility.KeyboardControl = id;
            }

            if (HasKeyboardFocus() && eventType != EventType.Layout)
            {
                if (IsEditingControl())
                {
                    editor.position  = position;
                    editor.controlID = id;
                    editor.DetectFocusChange();
                }
                else if (DrawGUI.EditingTextField || eventType == EventType.ExecuteCommand && string.Equals(e.commandName, "NewKeyboardFocus"))
                {
                    BeginEditing(id, position, style);
                    if (GUI.skin.settings.cursorColor.a > 0f)
                    {
                                                #if DEV_MODE && DEBUG_ENABLED
                        Debug.Log("SearchBox.SelectAll");
                                                #endif
                        editor.SelectAll();
                    }
                    if (e.GetTypeForControl(id) == EventType.ExecuteCommand)
                    {
                        DrawGUI.Use(e);
                    }
                }
            }

            if (editor.controlID == id && !isSelected)
            {
                EndEditing();
            }

            bool   flag1 = false;
            string text1 = editor.text;
            switch (eventType)
            {
            case EventType.MouseDown:
                if (position.Contains(e.mousePosition) && e.button == 0)
                {
                    var dropdownButtonRect = position;
                    dropdownButtonRect.width = 15f;
                    if (onDropdownClicked != null && dropdownButtonRect.Contains(e.mousePosition))
                    {
                        onDropdownClicked(position);

                        if (IsEditingControl())
                        {
                            Clear();
                            EndEditing();
                            flag1 = true;
                        }
                    }
                    else if (wasSelected)
                    {
                        if (e.clickCount == 2 && GUI.skin.settings.doubleClickSelectsWord)
                        {
                            editor.MoveCursorToPosition(Event.current.mousePosition);
                            editor.SelectCurrentWord();
                            editor.MouseDragSelectsWholeWords(true);
                            editor.DblClickSnap(TextEditor.DblClickSnapping.WORDS);
                            dragToPosition = false;
                        }
                        else if (e.clickCount == 3 && GUI.skin.settings.tripleClickSelectsLine)
                        {
                            editor.MoveCursorToPosition(e.mousePosition);
                            editor.SelectCurrentParagraph();
                            editor.MouseDragSelectsWholeWords(true);
                            editor.DblClickSnap(TextEditor.DblClickSnapping.PARAGRAPHS);
                            dragToPosition = false;
                        }
                        else
                        {
                            editor.MoveCursorToPosition(e.mousePosition);
                            selectAllOnMouseUp = false;
                        }
                    }
                    else
                    {
                        KeyboardControlUtility.KeyboardControl = id;
                        BeginEditing(id, position, style);
                        editor.MoveCursorToPosition(e.mousePosition);
                        if (GUI.skin.settings.cursorColor.a > 0f)
                        {
                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.SelectAllOnMouseUp");
                                                                #endif
                            selectAllOnMouseUp = true;
                        }
                    }
                    KeyboardControlUtility.JustClickedControl = id;
                    DrawGUI.Use(e);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    if (dragged && dragToPosition)
                    {
                                                        #if DEV_MODE && DEBUG_ENABLED
                        Debug.Log("SearchBox.MoveSelectionToAltCursor");
                                                        #endif
                        editor.MoveSelectionToAltCursor();
                        flag1 = true;
                    }
                    else if (postPoneMove)
                    {
                        editor.MoveCursorToPosition(e.mousePosition);
                    }
                    else if (selectAllOnMouseUp)
                    {
                        if (GUI.skin.settings.cursorColor.a > 0f)
                        {
                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.SelectAll");
                                                                #endif
                            editor.SelectAll();
                        }
                        selectAllOnMouseUp = false;
                    }
                    editor.MouseDragSelectsWholeWords(false);
                    dragToPosition = true;
                    dragged        = false;
                    postPoneMove   = false;
                    if (e.button == 0)
                    {
                        KeyboardControlUtility.JustClickedControl = 0;
                        DrawGUI.Use(e);
                    }
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    if (!e.shift && editor.hasSelection && dragToPosition)
                    {
                                                        #if DEV_MODE && DEBUG_ENABLED
                        Debug.Log("SearchBox.MoveAltCursorToPosition");
                                                        #endif
                        editor.MoveAltCursorToPosition(e.mousePosition);
                    }
                    else
                    {
                        if (e.shift)
                        {
                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.MoveCursorToPosition");
                                                                #endif
                            editor.MoveCursorToPosition(e.mousePosition);
                        }
                        else
                        {
                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.SelectToPosition");
                                                                #endif
                            editor.SelectToPosition(e.mousePosition);
                        }
                        dragToPosition     = false;
                        selectAllOnMouseUp = !editor.hasSelection;
                                                        #if DEV_MODE && DEBUG_ENABLED
                        Debug.Log("SearchBox.SelectAllOnMouseUp = " + selectAllOnMouseUp);
                                                        #endif
                    }
                    dragged = true;
                    DrawGUI.Use(e);
                }
                break;

            case EventType.KeyDown:
                if (!isSelected)
                {
                    break;
                }
                bool flag2     = false;
                char character = e.character;
                if (IsEditingControl() && editor.HandleKeyEvent(e))
                {
                    DrawGUI.Use(e);
                    flag1 = true;
                    break;
                }
                if (e.keyCode == KeyCode.Escape)
                {
                    if (IsEditingControl())
                    {
                        Clear();
                        EndEditing();
                        flag1 = true;
                    }
                }
                else if (character == 10 || character == 3)
                {
                    if (!IsEditingControl())
                    {
                        BeginEditing(id, position, style);
                        editor.SelectAll();
                    }
                    else
                    {
                        EndEditing();
                    }
                    DrawGUI.Use(e);
                }
                else if (character == 9 || e.keyCode == KeyCode.Tab)
                {
                    flag2 = true;
                }
                else if (character != 25 && character != 27 && IsEditingControl())
                {
                    if (character != 0)
                    {
                        editor.Insert(character);
                        flag1 = true;
                    }
                    else if (Input.compositionString.Length > 0)
                    {
                        editor.ReplaceSelection("");
                        flag1 = true;
                    }
                }
                if (IsEditingControl() && MightBePrintableKey(e) && !flag2)
                {
                    DrawGUI.Use(e);
                }
                break;

            case EventType.Repaint:
                                        #if DEV_MODE && PI_ASSERTATIONS
                Debug.Assert(string.Equals(text, editor.text), "text (" + text + ") != editor.text (" + editor.text + ")");
                                        #endif

                if (GUIUtility.hotControl == 0)
                {
                    // new test
                    if (inspector.MouseoveredPart != InspectorPart.None)
                    {
                        DrawGUI.Active.AddCursorRect(position, MouseCursor.Text);
                    }
                }

                string renderedText = !IsEditingControl() ? text : editor.text;
                if (!IsEditingControl())
                {
                    style.Draw(position, GUIContentPool.Temp(renderedText), id, false);
                    break;
                }
                editor.DrawCursor(renderedText);
                break;

            default:
                switch (eventType - 13)
                {
                case EventType.MouseDown:
                    if (KeyboardControlUtility.KeyboardControl == id)
                    {
                        switch (e.commandName)
                        {
                        case "Cut":
                        case "Copy":
                            if (editor.hasSelection)
                            {
                                DrawGUI.Use(e);
                            }
                            break;

                        case "Paste":
                            if (editor.CanPaste())
                            {
                                DrawGUI.Use(e);
                            }
                            break;

                        case "SelectAll":
                        case "Delete":
                            DrawGUI.Use(e);
                            break;

                        case "UndoRedoPerformed":
                            Text = text;
                            DrawGUI.Use(e);
                            break;
                        }
                    }
                    break;

                case EventType.MouseUp:
                    if (KeyboardControlUtility.KeyboardControl == id)
                    {
                        switch (e.commandName)
                        {
                        case "OnLostFocus":
                                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox - MouseUp / OnLostFocus: end editing");
                                                                                #endif
                            if (nowEditingAFilterField)
                            {
                                EndEditing();
                            }
                            DrawGUI.Use(e);
                            break;

                        case "Cut":
                            BeginEditing(id, position, style);
                            editor.Cut();
                            flag1 = true;
                            break;

                        case "Copy":
                            editor.Copy();
                            DrawGUI.Use(e);
                            break;

                        case "Paste":
                            BeginEditing(id, position, style);
                            editor.Paste();
                            flag1 = true;
                            break;

                        case "SelectAll":
                                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.SelectAll");
                                                                                #endif
                            editor.SelectAll();
                            DrawGUI.Use(e);
                            break;

                        case "Delete":
                            BeginEditing(id, position, style);
                            if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
                            {
                                editor.Delete();
                            }
                            else
                            {
                                editor.Cut();
                            }
                            flag1 = true;
                            DrawGUI.Use(e);
                            break;
                        }
                    }
                    break;

                case EventType.MouseDrag:
                    if (position.Contains(e.mousePosition))
                    {
                        if (!IsEditingControl())
                        {
                            KeyboardControlUtility.KeyboardControl = id;
                            BeginEditing(id, position, style);
                            editor.MoveCursorToPosition(e.mousePosition);
                        }
                        ShowTextEditorPopupMenu(inspector);
                        DrawGUI.Use(e);
                    }
                    break;
                }
                break;
            }

            textChanged = false;
            if (flag1)
            {
                textChanged = !string.Equals(text1, editor.text);
                if (Event.current.type != EventType.Used)
                {
                    DrawGUI.Use(e);
                }
            }
            if (textChanged)
            {
                SaveCursorPositions();
                GUI.changed = true;
                return(editor.text);
            }
            return(textInput);
        }
Ejemplo n.º 6
0
        private static float CalculateDynamicHeight(string text, bool forTextArea, float textAreaWidth)
        {
            if (textAreaWidth <= 0f)
            {
                                #if DEV_MODE && PI_ASSERTATIONS
                Debug.LogError("CalculateDynamicHeight called with textAreaWidth " + textAreaWidth);
                                #endif
                textAreaWidth = Mathf.Infinity;
            }

            try
            {
                float setHeight = InspectorUtility.Preferences.GUISkin.textArea.CalcHeight(GUIContentPool.Temp(text), textAreaWidth);
                return(setHeight + (forTextArea ? DrawGUI.SingleLineHeight + 3f : 3f));
            }
                        #if DEV_MODE
            catch (Exception e)
            {
                Debug.LogError(e);
                if (InspectorUtility.Preferences == null)
                {
                    Debug.LogError("CalculateDynamicHeight: InspectorUtility.Preferences was null - " + e);
                }
                else if (InspectorUtility.Preferences.GUISkin == null)
                {
                    Debug.LogError("CalculateDynamicHeight: InspectorUtility.Preferences.GUISkin was null - " + e);
                }
                else if (InspectorUtility.Preferences.GUISkin.textArea == null)
                {
                    Debug.LogError("CalculateDynamicHeight: InspectorUtility.Preferences.GUISkin.textArea was null - " + e);
                }
                else if (text == null)
                {
                    Debug.LogError("CalculateDynamicHeight: text was null - " + e);
                }
                else
                {
                    Debug.LogError("CalculateDynamicHeight - " + e);
                }
                        #else
            catch (Exception)
            {
                        #endif

                return(DrawGUI.SingleLineHeight + (forTextArea ? DrawGUI.SingleLineHeight + 3f : 3f));
            }
        }