示例#1
0
        protected bool TextBlockWithLink(
            string url, string formattedExplanation,
            GUIStyle textblockStyle)
        {
            string explanationColored = string.Format(
                formattedExplanation, url);

            var lines = GetLines(explanationColored, textblockStyle);

            if (lines == null)
            {
                return(false);
            }

            Rect linkHitbox = Rect.zero;

            foreach (string rawLine in lines)
            {
                string line = ReplaceUrlWithRichTextUrl(rawLine, url);

                GUILayout.Label(line, textblockStyle);
                Rect lineRect = GUILayoutUtility.GetLastRect();
                GUILayout.Space(DEFAULT_LINE_SPACING);

                if (Event.current.type == EventType.Layout)
                {
                    continue;
                }

                int beginChar = line.IndexOf(url);
                if (beginChar == -1)
                {
                    continue;
                }

                int        lastChar    = beginChar + url.Length;
                GUIContent lineContent = new GUIContent(line);

                Vector2 beginPos = textblockStyle.GetCursorPixelPosition(
                    lineRect, lineContent, beginChar);
                Vector2 endPos = textblockStyle.GetCursorPixelPosition(
                    lineRect, lineContent, lastChar);

                linkHitbox = new Rect(
                    beginPos.x,
                    beginPos.y,
                    endPos.x - beginPos.x,
                    textblockStyle.lineHeight * 1.2f);
            }

            EditorGUIUtility.AddCursorRect(linkHitbox, MouseCursor.Link);

            return(Mouse.IsLeftMouseButtonPressed(Event.current) &&
                   linkHitbox.Contains(Event.current.mousePosition));
        }
示例#2
0
        private static void ResolveSourceLink(CGUIStyleTextMeasure measure, ref CStackTraceLine stackLine)
        {
            Color color = CEditorSkin.GetColor(stackLine.sourcePathExists ? CColorCode.Link : CColorCode.LinkInnactive);

            int sourceStart = stackLine.sourcePathStart;
            int sourceEnd   = stackLine.sourcePathEnd;

            GUIStyle   style   = measure.Style;
            GUIContent content = new GUIContent(stackLine.line);

            float startPosX = style.GetCursorPixelPosition(stackLine.frame, content, sourceStart).x - 1;
            float endPosX   = style.GetCursorPixelPosition(stackLine.frame, content, sourceEnd).x + 1;

            stackLine.sourceFrame = new Rect(startPosX, stackLine.frame.y, endPosX - startPosX, stackLine.frame.height);
            stackLine.line        = CStringUtils.C(stackLine.line, color, sourceStart, sourceEnd);
        }
示例#3
0
        private void UpdateText(TextEditor te, Event ev, int endpos, GUIStyle textStyle, int backupPos, int backupSelPos)
        {
            te.MoveTextStart();
            _lines = 0;
            var teTextContent = new GUIContent(te.text);

            // highlighting by drawing read only text over the actual invisibile text
            while (GetPos(te) != endpos)
            {
                te.SelectToStartOfNextWord();
                var wordtext = te.SelectedText;

                //set word color
                GUI.contentColor = GetColor(wordtext);

                var pixelselpos = textStyle.GetCursorPixelPosition(te.position, teTextContent, GetSelectPos(te));
                var pixelpos    = textStyle.GetCursorPixelPosition(te.position, teTextContent, GetPos(te));

                GUI.Label(
                    new Rect(
                        pixelselpos.x - textStyle.border.left - 2f,
                        pixelselpos.y - textStyle.border.top,
                        pixelpos.x,
                        pixelpos.y
                        ),
                    wordtext
                    );
                if (wordtext.Contains("\n"))
                {
                    _lines++;
                }

                te.MoveToStartOfNextWord();
            }
            _lines++;

            //Reposition selection
            var bkpixelselpos = textStyle.GetCursorPixelPosition(te.position, teTextContent, backupSelPos);

            te.MoveCursorToPosition(bkpixelselpos);

            //Remake selection
            var bkpixelpos = textStyle.GetCursorPixelPosition(te.position, teTextContent, backupPos);

            te.SelectToPosition(bkpixelpos);
        }
    static void DrawHighlight(GUIStyle style, TextEditor editor, string text, int charFrom, int charTo, Color tint)
    {
        string word = text.Substring(charFrom, charTo - charFrom);
        var    rect = new Rect(style.GetCursorPixelPosition(editor.position, textContent, charFrom)
                               , style.GetCursorPixelPosition(editor.position, textContent, charTo));

        rect.size -= rect.position;
        if (rect.height > 0)
        {
            return;
        }
        rect.position -= editor.scrollOffset;
        rect.height   += 16;

        var c = GUI.backgroundColor;

        GUI.backgroundColor = tint;
        GUI.Label(rect, word, styleBg);
        GUI.backgroundColor = c;
    }
示例#5
0
        static Rect GetLinkRect(
            string labelText,
            string linkText,
            GUIContent labelContent,
            GUIStyle labelStyle,
            Rect rect)
        {
            int beginLinkChar = labelText.IndexOf(linkText);
            int endLinkChar   = beginLinkChar + linkText.Length;

            Vector2 beginPos = labelStyle.GetCursorPixelPosition(
                rect, labelContent, beginLinkChar);
            Vector2 endPos = labelStyle.GetCursorPixelPosition(
                rect, labelContent, endLinkChar);

            Rect linkRect = new Rect(
                beginPos.x,
                beginPos.y,
                endPos.x - beginPos.x,
                labelStyle.lineHeight * 1.2f);

            return(linkRect);
        }
示例#6
0
        static void DoHelpPanelLinks(
            HelpPanel helpPanel,
            GUIStyle helpParagraph)
        {
            var lastRect = GUILayoutUtility.GetLastRect();

            bool       linkWasClicked = false;
            GUIContent charContent    = new GUIContent();

            for (int charIdx = 0; charIdx < helpPanel.GUIContent.text.Length; charIdx++)
            {
                HelpLink link;
                if (!helpPanel.TryGetLinkAtChar(charIdx, out link))
                {
                    continue;
                }

                charContent.text = helpPanel.GUIContent.text[charIdx].ToString();

                var pos = helpParagraph.GetCursorPixelPosition(
                    lastRect, helpPanel.GUIContent, charIdx);

                float charWidth = helpParagraph.CalcSize(charContent).x;

                Rect charRect = new Rect(pos, new Vector2(
                                             charWidth - 4, helpParagraph.lineHeight));

                if (!linkWasClicked &&
                    Mouse.IsLeftMouseButtonPressed(Event.current) &&
                    charRect.Contains(Event.current.mousePosition))
                {
                    linkWasClicked = true;
                    OnHelpLinkClicked(helpPanel, link);
                }

                // Underline for links
                charRect.y      = charRect.yMax - 1;
                charRect.height = 1;
                GUI.DrawTexture(charRect, Images.GetLinkUnderlineImage());
            }
        }