Beispiel #1
0
        public bool OnPreRenderLine(UIDELine line)
        {
            if (line == null)
            {
                return(false);
            }
            ErrorDef errorDef = null;

            for (int i = 0; i < errors.Count; i++)
            {
                if (errors[i] != null && errors[i].line == line.index)
                {
                    errorDef = errors[i];
                }
            }
            if (errorDef != null)
            {
                Rect logLineRect = editor.actualTextAreaRect;
                logLineRect.x = editor.doc.scroll.x;
                float columnOffset   = line.GetScreenPosition(errorDef.column) * editor.charSize.x;
                float lineEnd        = line.GetScreenPosition(line.rawText.Length) * editor.charSize.x;
                float highlightLegth = lineEnd - columnOffset;

                logLineRect.x     += columnOffset;
                logLineRect.width  = highlightLegth;
                logLineRect.height = editor.charSize.y;
                logLineRect.y      = (line.index) * editor.charSize.y;

                if (logLineRect.Contains(Event.current.mousePosition))
                {
                    mouseOverError      = errorDef;
                    mouseOverRect       = logLineRect;
                    mouseOverRect.width = Mathf.Clamp(mouseOverRect.width, 100.0f, editor.actualTextAreaRect.width);
                }

                Rect underlineRect = logLineRect;
                underlineRect.height = errorUnderlineTex.height;
                underlineRect.y     += editor.charSize.y;
                underlineRect.y     -= underlineRect.height;

                Rect underlineUVRect = underlineRect;
                underlineUVRect.x      = 0;
                underlineUVRect.y      = 0;
                underlineUVRect.height = 1;

                underlineUVRect.width = underlineUVRect.width / (float)errorUnderlineTex.width;

                Color color = editor.editorWindow.theme.errorUnderlineColor;

                GUI.color = color;
                GUI.DrawTextureWithTexCoords(underlineRect, errorUnderlineTex, underlineUVRect);
                GUI.color = Color.white;
            }
            return(false);
        }
Beispiel #2
0
        public void UpdateRect()
        {
            UIDELine line = editor.doc.LineAt(editor.cursor.posY);

            if (line == null)
            {
                return;
            }
            Vector2 screenCursorPos;

            screenCursorPos.x = line.GetScreenPosition(editor.cursor.posX) * editor.charSize.x + editor.lineNumberWidth;
            //screenCursorPos.x -= editor.doc.scroll.x;
            screenCursorPos.y = editor.cursor.posY * editor.charSize.y;
            //screenCursorPos -= editor.doc.scroll;
            float height = Mathf.Max(Mathf.Min(maxHeight, itemList.Count), 1) * editor.charSize.y;

            rect = new Rect(screenCursorPos.x, screenCursorPos.y, boxWidth, height);

            float editorWidth = editor.textEditorNoScrollBarRectZeroPos.width;

            rect.y += editor.charSize.y;

            if (rect.x + rect.width > (editorWidth + editor.doc.scroll.x) - editor.lineNumberWidth)
            {
                float subtractFactor = (rect.x + rect.width) - ((editorWidth + editor.doc.scroll.x));
                //Debug.Log((rect.x+rect.width)+" "+(editorWidth+editor.doc.scroll.x)+" "+subtractFactor);
                rect.x -= subtractFactor;
            }
            boxExpandedWidth = 0.0f;
        }
Beispiel #3
0
        public void OnPostRenderLine(UIDELine line)
        {
            if (!show)
            {
                return;
            }
            if (findTerm != "")
            {
                string lineText       = line.rawText;
                string actualFindTerm = findTerm;
                string actualLineText = line.rawText;

                if (!useCase)
                {
                    actualFindTerm = actualFindTerm.ToLower();
                    actualLineText = actualLineText.ToLower();
                }

                List <int> searchIndexes = AllIndexesOf(actualLineText, actualFindTerm);
                if (searchIndexes.Count > 0)
                {
                    float    yPos = line.index * editor.charSize.y;
                    GUIStyle hoverHighlightStyle = editor.editorWindow.theme.GetStyle("CursorHoverHighlight");
                    //float contentHeight = hoverHighlightStyle.CalcHeight(new GUIContent("#YOLO"),100);
                    for (int i = 0; i < searchIndexes.Count; i++)
                    {
                        int   index    = searchIndexes[i];
                        int   charXPos = line.GetScreenPosition(index);
                        float xPos     = charXPos * editor.charSize.x;
                        //float xEndPos = line.GetScreenPosition(index+findTerm.Length)*editor.charSize.x;

                        bool isSameAsSelection = false;
                        if (editor.cursor.selection.actualStart == new Vector2(index, line.index) && editor.cursor.selection.actualEnd == new Vector2(index + findTerm.Length, line.index))
                        {
                            isSameAsSelection = true;
                        }
                        string inlineText = lineText.Substring(index, findTerm.Length);
                        if (!isSameAsSelection)
                        {
                            UIDEElement element = new UIDEElement();
                            element.rawText = inlineText;
                            element.line    = line;

                            editor.RenderElement(element, new Vector2(xPos, yPos), index, hoverHighlightStyle, false);
                            //float width = xEndPos-xPos;
                            //Rect r = new Rect(xPos,yPos,width,contentHeight);
                            //GUI.Box(r,"",hoverHighlightStyle);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public void OnNewLine()
        {
            if (editor.cursor.posY <= 0)
            {
                return;
            }

            UIDELine line         = editor.doc.LineAt(editor.cursor.posY);
            UIDELine previousLine = editor.doc.GetLastNoneWhitespaceOrCommentLine(editor.cursor.posY - 1);

            if (previousLine == null)
            {
                return;
            }
            UIDEElement firstElement         = previousLine.GetFirstNonWhitespaceElement();
            int         previousLineStartPos = previousLine.GetElementStartPos(firstElement);
            int         screenPos            = previousLine.GetScreenPosition(previousLineStartPos);
            UIDEElement lastElement          = previousLine.GetLastNonWhitespaceElement();

            string originalText = line.rawText;
            int    tabCount     = screenPos / 4;

            if (lastElement != null && lastElement.rawText == "{")
            {
                tabCount += 1;
            }
            line.rawText = line.GetTrimmedWhitespaceText();
            for (int i = 0; i < tabCount; i++)
            {
                line.rawText = "\t" + line.rawText;
            }
            line.RebuildElements();

            Vector2 oldCursorPos = editor.cursor.GetVectorPosition();

            editor.cursor.posX = tabCount;
            Vector2 newCursorPos = editor.cursor.GetVectorPosition();

            //add another undo with the same name as the previous one so it gets grouped.
            if (editor.undoManager.undos.Count > 0)
            {
                string undoName = editor.undoManager.undos[editor.undoManager.undos.Count - 1].groupID;
                editor.undoManager.RegisterUndo(undoName, UIDEUndoType.LineModify, line.index, originalText, line.rawText, oldCursorPos, newCursorPos);
            }
        }
Beispiel #5
0
        public void OnCloseCurly()
        {
            if (editor.cursor.posY <= 0)
            {
                return;
            }
            UIDELine line         = editor.doc.LineAt(editor.cursor.posY);
            UIDELine previousLine = editor.doc.GetLastNoneWhitespaceOrCommentLine(editor.cursor.posY - 1);

            if (previousLine == line)
            {
                return;
            }

            if (!line.IsLineWhitespace())
            {
                return;
            }

            UIDEElement firstElement         = previousLine.GetFirstNonWhitespaceElement();
            int         previousLineStartPos = previousLine.GetElementStartPos(firstElement);
            int         screenPos            = previousLine.GetScreenPosition(previousLineStartPos);
            UIDEElement lastElement          = previousLine.GetLastNonWhitespaceElement();

            int tabCount = screenPos / 4;

            if (lastElement != null)
            {
                if (lastElement.tokenDef.HasType("LineEnd"))
                {
                    tabCount -= 1;
                }
            }
            tabCount     = Mathf.Max(tabCount, 0);
            line.rawText = line.GetTrimmedWhitespaceText();
            for (int i = 0; i < tabCount; i++)
            {
                line.rawText = "\t" + line.rawText;
            }

            //line.rawText += startingText;
            line.RebuildElements();
            editor.cursor.posX = tabCount;
        }
        public bool OnPreRenderLine(UIDELine line)
        {
            if (line == null) return false;
            ErrorDef errorDef = null;
            for (int i = 0; i < errors.Count; i++) {
                if (errors[i] != null && errors[i].line == line.index) {
                    errorDef = errors[i];
                }
            }
            if (errorDef != null) {
                Rect logLineRect = editor.actualTextAreaRect;
                logLineRect.x = editor.doc.scroll.x;
                float columnOffset = line.GetScreenPosition(errorDef.column)*editor.charSize.x;
                float lineEnd = line.GetScreenPosition(line.rawText.Length)*editor.charSize.x;
                float highlightLegth = lineEnd-columnOffset;

                logLineRect.x += columnOffset;
                logLineRect.width = highlightLegth;
                logLineRect.height = editor.charSize.y;
                logLineRect.y = (line.index)*editor.charSize.y;

                if (logLineRect.Contains(Event.current.mousePosition)) {
                    mouseOverError = errorDef;
                    mouseOverRect = logLineRect;
                    mouseOverRect.width = Mathf.Clamp(mouseOverRect.width,100.0f,editor.actualTextAreaRect.width);
                }

                Rect underlineRect = logLineRect;
                underlineRect.height = errorUnderlineTex.height;
                underlineRect.y += editor.charSize.y;
                underlineRect.y -= underlineRect.height;

                Rect underlineUVRect = underlineRect;
                underlineUVRect.x = 0;
                underlineUVRect.y = 0;
                underlineUVRect.height = 1;

                underlineUVRect.width = underlineUVRect.width/(float)errorUnderlineTex.width;

                Color color = editor.editorWindow.theme.errorUnderlineColor;

                GUI.color = color;
                GUI.DrawTextureWithTexCoords(underlineRect,errorUnderlineTex,underlineUVRect);
                GUI.color = Color.white;
            }
            return false;
        }
Beispiel #7
0
        public void UpdateToolTipRect()
        {
            UIDELine line = editor.doc.LineAt((int)toolTipPos.y);

            if (line == null)
            {
                return;
            }

            GUIStyle tooltipStyle = skin.GetStyle("ToolTip");

            toolTipMaxWidth = editor.textEditorNoScrollBarRectZeroPos.width - 100.0f;
            toolTipMaxWidth = Mathf.Max(toolTipMaxWidth, 100.0f);

            GUIContent content = new GUIContent(tooltipText);

            if (currentTooltip != null && currentTooltip.item != null)
            {
                Texture2D icon = editor.editorWindow.theme.GetLanguageIcon(currentTooltip.item.GetLanguageIconName());
                if (icon != null)
                {
                    content.image = icon;
                }
            }

            //Create a tmp style to check the size without wordwrap.
            GUIStyle tooltipStyleTMP = new GUIStyle(tooltipStyle);

            tooltipStyleTMP.wordWrap = false;
            Vector2 clacedSize   = tooltipStyleTMP.CalcSize(content);
            float   desiredWidth = clacedSize.x;

            if (desiredWidth > toolTipMaxWidth)
            {
                desiredWidth = toolTipMaxWidth;
            }

            float height = tooltipStyle.CalcHeight(content, desiredWidth);

            tooltipRect.x      = 0;
            tooltipRect.y      = 0;
            tooltipRect.width  = desiredWidth;
            tooltipRect.height = height;

            Vector2 screenCursorPos;

            screenCursorPos.x = line.GetScreenPosition((int)toolTipPos.x) * editor.charSize.x + editor.lineNumberWidth;
            screenCursorPos.y = toolTipPos.y * editor.charSize.y;

            screenCursorPos.x -= editor.doc.scroll.x;
            screenCursorPos.y -= editor.doc.scroll.y;

            tooltipRect.x = screenCursorPos.x - (desiredWidth * 0.5f);
            tooltipRect.y = screenCursorPos.y - (height + editor.charSize.y * 0.5f);

            float editorWidth = editor.textEditorNoScrollBarRectZeroPos.width;

            if (tooltipRect.x + tooltipRect.width > (editorWidth))
            {
                float subtractFactor = (tooltipRect.x + tooltipRect.width) - (editorWidth);
                tooltipRect.x -= subtractFactor;
            }
            if (tooltipRect.x < editor.lineNumberWidth)
            {
                tooltipRect.x = editor.lineNumberWidth;
            }
            wantsTooltipRectUpdate = false;
        }
Beispiel #8
0
        public void OnPostRenderLine(UIDELine line)
        {
            if (!show) return;
            if (findTerm != "") {
                string lineText = line.rawText;
                string actualFindTerm = findTerm;
                string actualLineText = line.rawText;

                if (!useCase) {
                    actualFindTerm = actualFindTerm.ToLower();
                    actualLineText = actualLineText.ToLower();
                }

                List<int> searchIndexes = AllIndexesOf(actualLineText,actualFindTerm);
                if (searchIndexes.Count > 0) {
                    float yPos = line.index*editor.charSize.y;
                    GUIStyle hoverHighlightStyle = editor.editorWindow.theme.GetStyle("CursorHoverHighlight");
                    //float contentHeight = hoverHighlightStyle.CalcHeight(new GUIContent("#YOLO"),100);
                    for (int i = 0; i < searchIndexes.Count; i++) {
                        int index = searchIndexes[i];
                        int charXPos = line.GetScreenPosition(index);
                        float xPos = charXPos*editor.charSize.x;
                        //float xEndPos = line.GetScreenPosition(index+findTerm.Length)*editor.charSize.x;

                        bool isSameAsSelection = false;
                        if (editor.cursor.selection.actualStart == new Vector2(index,line.index) && editor.cursor.selection.actualEnd == new Vector2(index+findTerm.Length,line.index)) {
                            isSameAsSelection = true;
                        }
                        string inlineText = lineText.Substring(index,findTerm.Length);
                        if (!isSameAsSelection) {
                            UIDEElement element = new UIDEElement();
                            element.rawText = inlineText;
                            element.line = line;

                            editor.RenderElement(element, new Vector2(xPos,yPos),index,hoverHighlightStyle,false);
                            //float width = xEndPos-xPos;
                            //Rect r = new Rect(xPos,yPos,width,contentHeight);
                            //GUI.Box(r,"",hoverHighlightStyle);
                        }
                    }
                }
            }
        }