Пример #1
0
        private Vector2 CalculateSizeInPixels()
        {
            if (_fontFace == null)
            {
                _fontFace = FontManager.Instance.FindFont(FontName);
            }

            float         scale;
            UniversalFont font = _fontFace.Find(FontSize, out scale);

            Vector2 size;

            lock (Text)
            {
                size = font.MeasureString(Text.StringBuilder, (float)FontSpacing / 1000.0f, (float)LineHeight / 100.0f);
            }

            switch (_rotation)
            {
            case TextRotation.Rotate270:
            case TextRotation.Rotate90:
                size = new Vector2(size.Y, size.X);
                break;
            }

            Vector2 marginIfText = Vector2.Zero;

            if (Text.Length > 0)
            {
                marginIfText = new Vector2(_textMargin.Width, _textMargin.Height);
            }

            return(size * scale + marginIfText);
        }
Пример #2
0
        private Vector2 CalculateSizeInPixels()
        {
            if (_fontFace == null)
            {
                _fontFace = FontManager.Instance.FindFont(FontName);
            }

            if (_lines.Count == 0)
            {
                SetText(_text);
            }

            float         scale;
            UniversalFont font = _fontFace.Find(FontSize, out scale);

            Vector2 size   = Vector2.Zero;
            int     height = (int)(font.Height * scale * LineHeight / 100);

            for (int idx = 0; idx < _lines.Count; ++idx)
            {
                string line    = _lines[idx].Line;
                float  spacing = _lines[idx].Spacing;

                Vector2 lineSize = font.MeasureString(line, spacing, 0) * scale;

                size.X  = Math.Max(size.X, lineSize.X);
                size.Y += height;
            }

            return(size);
        }
Пример #3
0
        void SplitLine(List <string> lines, RichViewEntity entity, float position, int indent, int width)
        {
            float spacing = entity.FontSpacing;

            lines.Clear();

            int   maxWidth = (int)(width - position);
            float scale    = entity.FontScale;

            UniversalFont font = entity.Font;

            StringBuilder newLine = new StringBuilder();

            string line = entity.Text;

            for (int idx = 0; idx <= line.Length; ++idx)
            {
                char character = idx == line.Length ? ' ' : line[idx];

                if (Char.IsWhiteSpace(character) && character != 0xa0)
                {
                    Vector2 size = font.MeasureString(newLine, spacing, 0) * scale;

                    if (size.X > maxWidth)
                    {
                        for (int rev = newLine.Length - 1; rev >= 0; --rev)
                        {
                            if (Char.IsWhiteSpace(newLine[rev]) && newLine[rev] != 0xa0)
                            {
                                newLine.Remove(rev, newLine.Length - rev);
                                break;
                            }
                        }

                        if (newLine.Length == 0)
                        {
                            lines.Add(line);
                            maxWidth = width - indent;
                            return;
                        }

                        line = line.Substring(newLine.Length);
                        idx  = 0;

                        if (newLine.Length > 0 && Char.IsWhiteSpace(newLine[0]) && newLine[0] != 0xa0)
                        {
                            newLine.Remove(0, 1);
                        }

                        while (newLine.Length > 0 && Char.IsWhiteSpace(newLine[newLine.Length - 1]))
                        {
                            newLine.Remove(newLine.Length - 1, 1);
                        }

                        lines.Add(newLine.ToString());
                        maxWidth = width - indent;
                        newLine.Clear();
                        continue;
                    }
                }

                newLine.Append(character);
            }

            while (newLine.Length > 0 && Char.IsWhiteSpace(newLine[newLine.Length - 1]))
            {
                newLine.Remove(newLine.Length - 1, 1);
            }

            if (newLine.Length > 0)
            {
                if (Char.IsWhiteSpace(newLine[0]) && newLine[0] != 0xa0)
                {
                    newLine.Remove(0, 1);
                }

                lines.Add(newLine.ToString());
            }


            lines[lines.Count - 1] = lines.Last() + " ";
        }
Пример #4
0
        void SplitLine(List <string> lines, UniversalFont font, string line, float scale, int maxWidth)
        {
            float spacing    = (float)FontSpacing / 1000.0f;
            float lineHeight = (float)LineHeight / 100.0f;

            lines.Clear();

            StringBuilder newLine = new StringBuilder();

            for (int idx = 0; idx <= line.Length; ++idx)
            {
                char character = idx == line.Length ? ' ' : line[idx];

                if (Char.IsWhiteSpace(character) && character != 0xa0)
                {
                    Vector2 size = font.MeasureString(newLine, spacing, lineHeight) * scale;

                    if (size.X > maxWidth)
                    {
                        for (int rev = newLine.Length - 1; rev >= 0; --rev)
                        {
                            if (Char.IsWhiteSpace(newLine[rev]) && newLine[rev] != 0xa0)
                            {
                                newLine.Remove(rev, newLine.Length - rev);
                                break;
                            }
                        }

                        if (newLine.Length == 0)
                        {
                            lines.Add(line);
                            return;
                        }

                        line = line.Substring(newLine.Length);
                        idx  = 0;

                        if (newLine.Length > 0 && char.IsWhiteSpace(newLine[0]) && newLine[0] != 0xa0)
                        {
                            newLine.Remove(0, 1);
                        }

                        while (newLine.Length > 0 && char.IsWhiteSpace(newLine[newLine.Length - 1]))
                        {
                            newLine.Remove(newLine.Length - 1, 1);
                        }

                        lines.Add(newLine.ToString());
                        newLine.Clear();
                        continue;
                    }
                }

                newLine.Append(character);
            }

            while (newLine.Length > 0 && char.IsWhiteSpace(newLine[newLine.Length - 1]))
            {
                newLine.Remove(newLine.Length - 1, 1);
            }

            if (newLine.Length > 0)
            {
                if (char.IsWhiteSpace(newLine[0]) && newLine[0] != 0xa0)
                {
                    newLine.Remove(0, 1);
                }

                lines.Add(newLine.ToString());
            }

            if (lines.Count > 0)
            {
                lines[lines.Count - 1] = lines.Last() + "\r";
            }
        }
Пример #5
0
        public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info)
        {
            int  carretPosition = info.Additional != null ? (int)info.Additional : -1;
            bool focused        = false;

            Update(info.EllapsedTime, info.ButtonState);

            if (info.ButtonState.HasFlag(ButtonState.Checked) && carretPosition >= 0)
            {
                _flash += info.EllapsedTime * 2;
                _flash %= 2;
                focused = true;
            }
            else
            {
                _flash = 0;
            }

            SharedString str = info.Text;

            float         scale = _font.Scale;
            UniversalFont font  = _font.Font;
            Color         color = ColorFromState * info.Opacity * Opacity;

            Rectangle target  = _margin.ComputeRect(info.Target);
            float     spacing = _font.Spacing;

            lock (str)
            {
                StringBuilder builder = str.StringBuilder;

                if (_flash > 1)
                {
                    _string.Clear();
                    carretPosition = Math.Min(builder.Length, carretPosition);
                    for (int idx = 0; idx < carretPosition; ++idx)
                    {
                        _string.Append(builder[idx]);
                    }

                    carretPosition = (int)(font.MeasureString(_string, spacing, 0) * scale).X;
                }

                _string.Clear();
                _string.Append(builder);
            }

            Vector2 size = font.MeasureString(_string, spacing, 0) * scale;

            if (focused)
            {
                size.X += font.MeasureString("|", spacing).X *scale;
            }

            int positionX = target.X;

            if (size.X >= target.Width)
            {
                positionX = target.Right - (int)size.X;
            }
            else
            {
                switch (_textAlign & TextAlign.Horz)
                {
                case TextAlign.Right:
                    positionX = target.Right - (int)size.X;
                    break;

                case TextAlign.Center:
                    positionX = target.Center.X - (int)size.X / 2;
                    break;
                }
            }

            drawBatch.PushClip(target);

            target.X = positionX;

            drawBatch.DrawText(font, _string, target, _textAlign & TextAlign.Vert, color, spacing, 0, scale, TextRotation.None);

            if (_flash > 1)
            {
                target.X += carretPosition;

                drawBatch.DrawText(font, "|", target, _textAlign & TextAlign.Vert, color, spacing, 0, scale);
            }

            drawBatch.PopClip();
        }