Example #1
0
        public float GetLineHeight(int characterIndex, MeshGenerationContextUtils.TextParams textParams, float textScaling, float pixelPerPoint)
        {
            textParams.wordWrapWidth = 0.0f;
            textParams.wordWrap      = false;

            return(ComputeTextHeight(textParams, textScaling));
        }
Example #2
0
        internal TextInfo Update(MeshGenerationContextUtils.TextParams parms, float pixelsPerPoint)
        {
            parms.rect = new Rect(Vector2.zero, parms.rect.size);
            int      hashCode = parms.GetHashCode();
            bool     flag     = this.m_PreviousGenerationSettingsHash == hashCode;
            TextInfo textInfo;

            if (flag)
            {
                textInfo = this.textInfo;
            }
            else
            {
                TextHandle.UpdateGenerationSettingsCommon(parms, this.m_CurrentGenerationSettings);
                this.m_CurrentGenerationSettings.color        = parms.fontColor;
                this.m_CurrentGenerationSettings.inverseYAxis = true;
                this.m_CurrentGenerationSettings.scale        = pixelsPerPoint;
                this.m_CurrentGenerationSettings.overflowMode = parms.textOverflowMode;
                this.textInfo.isDirty = true;
                UnityEngine.TextCore.TextGenerator.GenerateText(this.m_CurrentGenerationSettings, this.textInfo);
                this.m_PreviousGenerationSettingsHash = hashCode;
                textInfo = this.textInfo;
            }
            return(textInfo);
        }
Example #3
0
        public float GetLineHeight(int characterIndex, MeshGenerationContextUtils.TextParams textParams, float textScaling, float pixelPerPoint)
        {
            Update(textParams, pixelPerPoint);
            var character = m_TextInfo.textElementInfo[m_TextInfo.characterCount - 1];
            var line      = m_TextInfo.lineInfo[character.lineNumber];

            return(line.lineHeight);
        }
Example #4
0
        public static void Text(this MeshGenerationContext mgc, MeshGenerationContextUtils.TextParams textParams, TextHandle handle, float pixelsPerPoint)
        {
            bool flag = textParams.font != null;

            if (flag)
            {
                mgc.painter.DrawText(textParams, handle, pixelsPerPoint);
            }
        }
Example #5
0
 public float ComputeTextHeight(MeshGenerationContextUtils.TextParams parms, float scaling)
 {
     if (useLegacy)
     {
         return(TextNative.ComputeTextHeight(
                    MeshGenerationContextUtils.TextParams.GetTextNativeSettings(parms, scaling)));
     }
     UpdatePreferredValues(parms);
     return(m_PreferredSize.y);
 }
Example #6
0
        public int VerticesCount(MeshGenerationContextUtils.TextParams parms, float pixelPerPoint)
        {
            Update(parms, pixelPerPoint);
            var verticesCount = 0;

            foreach (var meshInfo in textInfo.meshInfo)
            {
                verticesCount += meshInfo.vertexCount;
            }
            return(verticesCount);
        }
Example #7
0
        private void UpdatePreferredValues(MeshGenerationContextUtils.TextParams parms)
        {
            parms.rect = new Rect(Vector2.zero, parms.rect.size);
            int  hashCode = parms.GetHashCode();
            bool flag     = this.m_PreviousLayoutSettingsHash == hashCode;

            if (!flag)
            {
                TextHandle.UpdateGenerationSettingsCommon(parms, this.m_CurrentLayoutSettings);
                this.m_PreferredSize = UnityEngine.TextCore.TextGenerator.GetPreferredValues(this.m_CurrentLayoutSettings, this.textInfo);
                this.m_PreviousLayoutSettingsHash = hashCode;
            }
        }
Example #8
0
        void UpdatePreferredValues(MeshGenerationContextUtils.TextParams parms)
        {
            // The screenRect in TextCore is not properly implemented with regards to the offset part, so zero it out for now and we will add it ourselves later
            parms.rect = new Rect(Vector2.zero, parms.rect.size);
            int paramsHash = parms.GetHashCode();

            if (m_PreviousLayoutSettingsHash == paramsHash)
            {
                return;
            }
            UpdateGenerationSettingsCommon(parms, m_CurrentLayoutSettings);
            m_PreferredSize = TextCore.TextGenerator.GetPreferredValues(m_CurrentLayoutSettings, textInfo);
            m_PreviousLayoutSettingsHash = paramsHash;
        }
Example #9
0
        public NativeArray <TextVertex> GetVertices(MeshGenerationContextUtils.TextParams parms, float scaling)
        {
            int paramsHash = parms.GetHashCode();

            if (m_PreviousTextParamsHash == paramsHash)
            {
                return(textVertices);
            }

            m_PreviousTextParamsHash = paramsHash;
            TextNativeSettings textSettings = MeshGenerationContextUtils.TextParams.GetTextNativeSettings(parms, scaling);

            textVertices = TextNative.GetVertices(textSettings);
            return(textVertices);
        }
Example #10
0
        public float ComputeTextWidth(MeshGenerationContextUtils.TextParams parms, float scaling)
        {
            bool  flag = this.useLegacy;
            float result;

            if (flag)
            {
                result = TextNative.ComputeTextWidth(MeshGenerationContextUtils.TextParams.GetTextNativeSettings(parms, scaling));
            }
            else
            {
                this.UpdatePreferredValues(parms);
                result = this.m_PreferredSize.x;
            }
            return(result);
        }
Example #11
0
 private static TextOverflowMode GetTextOverflowMode(MeshGenerationContextUtils.TextParams textParams)
 {
     if (textParams.textOverflow == TextOverflow.Clip)
     {
         return(TextOverflowMode.Masking);
     }
     if (textParams.textOverflow != TextOverflow.Ellipsis)
     {
         return(TextOverflowMode.Overflow);
     }
     if (!textParams.wordWrap && textParams.overflow == OverflowInternal.Hidden)
     {
         return(TextOverflowMode.Ellipsis);
     }
     return(TextOverflowMode.Overflow);
 }
Example #12
0
            internal static TextNativeSettings GetTextNativeSettings(MeshGenerationContextUtils.TextParams textParams, float scaling)
            {
                TextNativeSettings result = new TextNativeSettings
                {
                    text          = textParams.text,
                    font          = textParams.font,
                    size          = textParams.fontSize,
                    scaling       = scaling,
                    style         = textParams.fontStyle,
                    color         = textParams.fontColor,
                    anchor        = textParams.anchor,
                    wordWrap      = textParams.wordWrap,
                    wordWrapWidth = textParams.wordWrapWidth,
                    richText      = textParams.richText
                };

                result.color *= textParams.playmodeTintColor;
                return(result);
            }
Example #13
0
        public TextInfo Update(MeshGenerationContextUtils.TextParams parms, float pixelsPerPoint)
        {
            // The screenRect in TextCore is not properly implemented with regards to the offset part, so zero it out for now and we will add it ourselves later
            parms.rect = new Rect(Vector2.zero, parms.rect.size);
            int paramsHash = parms.GetHashCode();

            if (m_PreviousGenerationSettingsHash == paramsHash)
            {
                return(uITKTextInfo);
            }
            UpdateGenerationSettingsCommon(parms, m_CurrentGenerationSettings);
            m_CurrentGenerationSettings.color        = parms.fontColor;
            m_CurrentGenerationSettings.inverseYAxis = true;
            m_CurrentGenerationSettings.scale        = pixelsPerPoint;
            m_CurrentGenerationSettings.overflowMode = GetTextOverflowMode(parms);
            textInfo.isDirty = true;
            TextCore.TextGenerator.GenerateText(m_CurrentGenerationSettings, textInfo);
            m_PreviousGenerationSettingsHash = paramsHash;
            return(ConvertTo(textInfo));
        }
Example #14
0
        private static void UpdateGenerationSettingsCommon(MeshGenerationContextUtils.TextParams painterParams, UnityEngine.TextCore.TextGenerationSettings settings)
        {
            settings.fontAsset = TextHandle.GetFontAsset(painterParams.font);
            settings.material  = settings.fontAsset.material;
            Rect rect = painterParams.rect;
            bool flag = float.IsNaN(rect.width);

            if (flag)
            {
                rect.width = painterParams.wordWrapWidth;
            }
            settings.screenRect    = rect;
            settings.text          = (string.IsNullOrEmpty(painterParams.text) ? " " : painterParams.text);
            settings.fontSize      = (float)((painterParams.fontSize > 0) ? painterParams.fontSize : painterParams.font.fontSize);
            settings.fontStyle     = TextGeneratorUtilities.LegacyStyleToNewStyle(painterParams.fontStyle);
            settings.textAlignment = TextGeneratorUtilities.LegacyAlignmentToNewAlignment(painterParams.anchor);
            settings.wordWrap      = painterParams.wordWrap;
            settings.richText      = false;
            settings.overflowMode  = TextOverflowMode.Overflow;
        }
Example #15
0
        private void UpdateVisibleText()
        {
            MeshGenerationContextUtils.TextParams textParams = MeshGenerationContextUtils.TextParams.MakeStyleBased(this, this.text);
            int  hashCode = textParams.GetHashCode();
            bool flag     = this.m_UpdateTextParams || hashCode != this.m_PreviousTextParamsHashCode;

            if (flag)
            {
                this.m_TextParams = textParams;
                bool flag2 = this.m_TextParams.textOverflowMode == TextOverflowMode.Ellipsis;
                if (flag2)
                {
                    this.m_TextParams.text = this.ElideText(this.m_TextParams.text, TextElement.k_EllipsisText, this.m_TextParams.rect.width, this.m_TextParams.textOverflowPosition);
                }
                this.isElided = (this.m_TextParams.textOverflowMode == TextOverflowMode.Ellipsis && this.m_TextParams.text != this.text);
                this.m_PreviousTextParamsHashCode = hashCode;
                this.m_UpdateTextParams           = false;
                this.UpdateTooltip();
            }
        }
Example #16
0
        private void UpdateVisibleText()
        {
            var textParams         = MeshGenerationContextUtils.TextParams.MakeStyleBased(this, text);
            var textParamsHashCode = textParams.GetHashCode();

            if (m_UpdateTextParams || textParamsHashCode != m_PreviousTextParamsHashCode)
            {
                m_TextParams = textParams;
                if (m_TextParams.textOverflowMode == TextOverflowMode.Ellipsis)
                {
                    m_TextParams.text = ElideText(m_TextParams.text, k_EllipsisText, m_TextParams.rect.width,
                                                  m_TextParams.textOverflowPosition);
                }

                isElided = m_TextParams.textOverflowMode == TextOverflowMode.Ellipsis && m_TextParams.text != text;
                m_PreviousTextParamsHashCode = textParamsHashCode;
                m_UpdateTextParams           = false;
                UpdateTooltip();
            }
        }
Example #17
0
        static void UpdateGenerationSettingsCommon(MeshGenerationContextUtils.TextParams painterParams,
                                                   TextCore.TextGenerationSettings settings)
        {
            settings.fontAsset = GetFontAsset(painterParams.font);
            settings.material  = settings.fontAsset.material;
            // in case rect is not properly set (ex: style has not been resolved), make sure its width at least matches wordWrapWidth
            var screenRect = painterParams.rect;

            if (float.IsNaN(screenRect.width))
            {
                screenRect.width = painterParams.wordWrapWidth;
            }
            settings.screenRect    = screenRect;
            settings.text          = string.IsNullOrEmpty(painterParams.text) ? " " : painterParams.text;
            settings.fontSize      = painterParams.fontSize > 0 ? painterParams.fontSize : painterParams.font.fontSize;
            settings.fontStyle     = TextGeneratorUtilities.LegacyStyleToNewStyle(painterParams.fontStyle);
            settings.textAlignment = TextGeneratorUtilities.LegacyAlignmentToNewAlignment(painterParams.anchor);
            settings.wordWrap      = painterParams.wordWrap;
            settings.richText      = false;
            settings.overflowMode  = TextOverflowMode.Overflow;
        }
Example #18
0
            internal static MeshGenerationContextUtils.TextParams MakeStyleBased(VisualElement ve, string text)
            {
                ComputedStyle computedStyle = ve.computedStyle;

                MeshGenerationContextUtils.TextParams result = default(MeshGenerationContextUtils.TextParams);
                result.rect          = ve.contentRect;
                result.text          = text;
                result.font          = computedStyle.unityFont.value;
                result.fontSize      = (int)computedStyle.fontSize.value.value;
                result.fontStyle     = computedStyle.unityFontStyleAndWeight.value;
                result.fontColor     = computedStyle.color.value;
                result.anchor        = computedStyle.unityTextAlign.value;
                result.wordWrap      = (computedStyle.whiteSpace.value == WhiteSpace.Normal);
                result.wordWrapWidth = ((computedStyle.whiteSpace.value == WhiteSpace.Normal) ? ve.contentRect.width : 0f);
                result.richText      = false;
                IPanel expr_F2 = ve.panel;

                result.playmodeTintColor    = ((expr_F2 != null && expr_F2.contextType == ContextType.Editor) ? UIElementsUtility.editorPlayModeTintColor : Color.white);
                result.textOverflowMode     = MeshGenerationContextUtils.TextParams.GetTextOverflowMode(computedStyle);
                result.textOverflowPosition = computedStyle.unityTextOverflowPosition.value;
                return(result);
            }
Example #19
0
 public void DrawText(UIRStylePainter painter, MeshGenerationContextUtils.TextParams parms, float pixelsPerPoint)
 {
     painter.DrawTextNative(parms, this, pixelsPerPoint);
 }
Example #20
0
 public float GetLineHeight(int characterIndex, MeshGenerationContextUtils.TextParams textParams, float textScaling, float pixelPerPoint)
 {
     return(textHandle.GetLineHeight(characterIndex, textParams, textScaling, pixelPerPoint));
 }
Example #21
0
        internal static Vector2 MeasureVisualElementTextSize(VisualElement ve, string textToMeasure, float width, VisualElement.MeasureMode widthMode, float height, VisualElement.MeasureMode heightMode, TextHandle textHandle)
        {
            float   num   = float.NaN;
            float   num2  = float.NaN;
            Font    value = ve.computedStyle.unityFont.value;
            bool    flag  = textToMeasure == null || value == null;
            Vector2 result;

            if (flag)
            {
                result = new Vector2(num, num2);
            }
            else
            {
                Vector3 vector = ve.ComputeGlobalScale();
                bool    flag2  = vector.x + vector.y <= 0f || ve.scaledPixelsPerPoint <= 0f;
                if (flag2)
                {
                    result = Vector2.zero;
                }
                else
                {
                    float scaledPixelsPerPoint = ve.scaledPixelsPerPoint;
                    float num3  = 0.02f;
                    float num4  = num3 / scaledPixelsPerPoint;
                    bool  flag3 = widthMode == VisualElement.MeasureMode.Exactly;
                    if (flag3)
                    {
                        num = width;
                    }
                    else
                    {
                        MeshGenerationContextUtils.TextParams textSettings = TextElement.GetTextSettings(ve, textToMeasure);
                        textSettings.wordWrap = false;
                        textSettings.richText = false;
                        num = textHandle.ComputeTextWidth(textSettings, scaledPixelsPerPoint);
                        num = ((num < num4) ? 0f : AlignmentUtils.CeilToPixelGrid(num, scaledPixelsPerPoint, num3));
                        bool flag4 = widthMode == VisualElement.MeasureMode.AtMost;
                        if (flag4)
                        {
                            num = Mathf.Min(num, width);
                        }
                    }
                    bool flag5 = heightMode == VisualElement.MeasureMode.Exactly;
                    if (flag5)
                    {
                        num2 = height;
                    }
                    else
                    {
                        MeshGenerationContextUtils.TextParams textSettings2 = TextElement.GetTextSettings(ve, textToMeasure);
                        textSettings2.wordWrapWidth = num;
                        textSettings2.richText      = false;
                        num2 = textHandle.ComputeTextHeight(textSettings2, scaledPixelsPerPoint);
                        num2 = ((num2 < num4) ? 0f : AlignmentUtils.CeilToPixelGrid(num2, scaledPixelsPerPoint, num3));
                        bool flag6 = heightMode == VisualElement.MeasureMode.AtMost;
                        if (flag6)
                        {
                            num2 = Mathf.Min(num2, height);
                        }
                    }
                    result = new Vector2(num, num2);
                }
            }
            return(result);
        }
Example #22
0
 public float ComputeTextHeight(MeshGenerationContextUtils.TextParams parms, float scaling)
 {
     return(textHandle.ComputeTextHeight(parms, scaling));
 }
Example #23
0
 public void DrawText(UIRStylePainter painter, MeshGenerationContextUtils.TextParams textParams, float pixelsPerPoint)
 {
     textHandle.DrawText(painter, textParams, pixelsPerPoint);
 }
Example #24
0
 public float ComputeTextHeight(MeshGenerationContextUtils.TextParams parms, float scaling)
 {
     return(TextNative.ComputeTextHeight(
                MeshGenerationContextUtils.TextParams.GetTextNativeSettings(parms, scaling)));
 }
Example #25
0
 public TextInfo Update(MeshGenerationContextUtils.TextParams parms, float pixelsPerPoint)
 {
     return(textHandle.Update(parms, pixelsPerPoint));
 }
Example #26
0
 public int VerticesCount(MeshGenerationContextUtils.TextParams parms, float pixelPerPoint)
 {
     return(GetVertices(parms, pixelPerPoint).Length);
 }
Example #27
0
 public float ComputeTextHeight(MeshGenerationContextUtils.TextParams parms, float scaling)
 {
     UpdatePreferredValues(parms);
     return(m_PreferredSize.y);
 }
Example #28
0
 public int VerticesCount(MeshGenerationContextUtils.TextParams parms, float pixelPerPoint)
 {
     return(textHandle.VerticesCount(parms, pixelPerPoint));
 }
Example #29
0
 public TextInfo Update(MeshGenerationContextUtils.TextParams parms, float pixelsPerPoint)
 {
     Debug.Log(("TextNative Update should not be called"));
     return(null);
 }
            internal void DrawWithTextSelectionAndCursor(MeshGenerationContext mgc, string newText, float pixelsPerPoint)
            {
                Color playmodeTintColor = (base.panel.contextType == ContextType.Editor) ? UIElementsUtility.editorPlayModeTintColor : Color.white;
                KeyboardTextEditorEventHandler keyboardTextEditorEventHandler = this.editorEventHandler as KeyboardTextEditorEventHandler;
                bool flag = keyboardTextEditorEventHandler == null;

                if (!flag)
                {
                    keyboardTextEditorEventHandler.PreDrawCursor(newText);
                    int     cursorIndex   = this.editorEngine.cursorIndex;
                    int     selectIndex   = this.editorEngine.selectIndex;
                    Rect    localPosition = this.editorEngine.localPosition;
                    Vector2 scrollOffset  = this.editorEngine.scrollOffset;
                    float   scaling       = TextHandle.ComputeTextScaling(base.worldTransform, pixelsPerPoint);
                    MeshGenerationContextUtils.TextParams textParams = MeshGenerationContextUtils.TextParams.MakeStyleBased(this, this.text);
                    textParams.text          = " ";
                    textParams.wordWrapWidth = 0f;
                    textParams.wordWrap      = false;
                    float num           = this.m_TextHandle.ComputeTextHeight(textParams, scaling);
                    float wordWrapWidth = 0f;
                    bool  flag2         = this.editorEngine.multiline && base.resolvedStyle.whiteSpace == WhiteSpace.Normal;
                    if (flag2)
                    {
                        wordWrapWidth = base.contentRect.width;
                    }
                    Vector2 p = this.editorEngine.graphicalCursorPos - scrollOffset;
                    p.y += num;
                    GUIUtility.compositionCursorPos = this.LocalToWorld(p);
                    Color cursorColor = this.cursorColor;
                    int   num2        = string.IsNullOrEmpty(GUIUtility.compositionString) ? selectIndex : (cursorIndex + GUIUtility.compositionString.Length);
                    bool  flag3       = cursorIndex != num2 && !this.isDragging;
                    if (flag3)
                    {
                        int cursorIndex2 = (cursorIndex < num2) ? cursorIndex : num2;
                        int cursorIndex3 = (cursorIndex > num2) ? cursorIndex : num2;
                        CursorPositionStylePainterParameters @default = CursorPositionStylePainterParameters.GetDefault(this, this.text);
                        @default.text          = this.editorEngine.text;
                        @default.wordWrapWidth = wordWrapWidth;
                        @default.cursorIndex   = cursorIndex2;
                        Vector2 vector = this.m_TextHandle.GetCursorPosition(@default, scaling);
                        @default.cursorIndex = cursorIndex3;
                        Vector2 vector2 = this.m_TextHandle.GetCursorPosition(@default, scaling);
                        vector  -= scrollOffset;
                        vector2 -= scrollOffset;
                        bool flag4 = Mathf.Approximately(vector.y, vector2.y);
                        if (flag4)
                        {
                            mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams
                            {
                                rect              = new Rect(vector.x, vector.y, vector2.x - vector.x, num),
                                color             = this.selectionColor,
                                playmodeTintColor = playmodeTintColor
                            });
                        }
                        else
                        {
                            mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams
                            {
                                rect              = new Rect(vector.x, vector.y, base.contentRect.xMax - vector.x, num),
                                color             = this.selectionColor,
                                playmodeTintColor = playmodeTintColor
                            });
                            float num3  = vector2.y - vector.y - num;
                            bool  flag5 = num3 > 0f;
                            if (flag5)
                            {
                                mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams
                                {
                                    rect              = new Rect(base.contentRect.xMin, vector.y + num, base.contentRect.width, num3),
                                    color             = this.selectionColor,
                                    playmodeTintColor = playmodeTintColor
                                });
                            }
                            bool flag6 = vector2.x != base.contentRect.x;
                            if (flag6)
                            {
                                mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams
                                {
                                    rect              = new Rect(base.contentRect.xMin, vector2.y, vector2.x, num),
                                    color             = this.selectionColor,
                                    playmodeTintColor = playmodeTintColor
                                });
                            }
                        }
                    }
                    bool flag7 = !string.IsNullOrEmpty(this.editorEngine.text) && base.contentRect.width > 0f && base.contentRect.height > 0f;
                    if (flag7)
                    {
                        textParams      = MeshGenerationContextUtils.TextParams.MakeStyleBased(this, this.text);
                        textParams.rect = new Rect(base.contentRect.x - scrollOffset.x, base.contentRect.y - scrollOffset.y, base.contentRect.width + scrollOffset.x, base.contentRect.height + scrollOffset.y);
                        textParams.text = this.editorEngine.text;
                        mgc.Text(textParams, this.m_TextHandle, base.scaledPixelsPerPoint);
                    }
                    bool flag8 = !this.isReadOnly && !this.isDragging;
                    if (flag8)
                    {
                        bool flag9 = cursorIndex == num2 && base.computedStyle.unityFont.value != null;
                        if (flag9)
                        {
                            CursorPositionStylePainterParameters @default = CursorPositionStylePainterParameters.GetDefault(this, this.text);
                            @default.text          = this.editorEngine.text;
                            @default.wordWrapWidth = wordWrapWidth;
                            @default.cursorIndex   = cursorIndex;
                            Vector2 vector3 = this.m_TextHandle.GetCursorPosition(@default, scaling);
                            vector3 -= scrollOffset;
                            mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams
                            {
                                rect              = new Rect(vector3.x, vector3.y, 1f, num),
                                color             = cursorColor,
                                playmodeTintColor = playmodeTintColor
                            });
                        }
                        bool flag10 = this.editorEngine.altCursorPosition != -1;
                        if (flag10)
                        {
                            CursorPositionStylePainterParameters @default = CursorPositionStylePainterParameters.GetDefault(this, this.text);
                            @default.text          = this.editorEngine.text.Substring(0, this.editorEngine.altCursorPosition);
                            @default.wordWrapWidth = wordWrapWidth;
                            @default.cursorIndex   = this.editorEngine.altCursorPosition;
                            Vector2 vector4 = this.m_TextHandle.GetCursorPosition(@default, scaling);
                            vector4 -= scrollOffset;
                            mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams
                            {
                                rect              = new Rect(vector4.x, vector4.y, 1f, num),
                                color             = cursorColor,
                                playmodeTintColor = playmodeTintColor
                            });
                        }
                    }
                    keyboardTextEditorEventHandler.PostDrawCursor();
                }
            }