Ejemplo n.º 1
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0 || TextColor.Value.A == 0)
            {
                return;
            }

            base.Draw(ref parameters);

            if (_fontFace == null)
            {
                _fontFace = FontManager.Instance.FindFont(FontName);
            }

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

            Rectangle bounds = ScreenBounds;

            if (Text.Length > 0)
            {
                bounds = _textMargin.ComputeRect(bounds);
            }

            parameters.DrawBatch.DrawText(font, Text, bounds, TextAlign, TextColor.Value * opacity, (float)FontSpacing / 1000.0f, (float)LineHeight / 100.0f, scale, _rotation);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        void GetFont(out UniversalFont font, out float scale)
        {
            if (_fontFace == null)
            {
                _fontFace = FontManager.Instance.FindFont(FontName);
            }

            font = _fontFace.Find(FontSize, out scale);
        }
Ejemplo n.º 5
0
        void FillEntityData(RichViewEntity richEntity, Entity entity)
        {
            FontFace fontFace = _fonts[(int)entity.Font].Font;
            float    spacing  = _fonts[(int)entity.Font].FontSpacing;
            int      size     = _sizes[(int)entity.Size] + _fonts[(int)entity.Font].FontResize;
            float    scale;

            UniversalFont font = fontFace.Find(size, out scale);

            richEntity.Font        = font;
            richEntity.FontScale   = scale;
            richEntity.FontSpacing = spacing;
        }
Ejemplo n.º 6
0
        private void Add(string fontName, int size, UniversalFont font)
        {
            FontFace fonts = null;

            _fonts.TryGetValue(fontName, out fonts);

            if (fonts == null)
            {
                fonts = new FontFace(fontName);
                _fonts.Add(fontName, fonts);
            }

            fonts.Add(size, font);
        }
Ejemplo n.º 7
0
        public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info)
        {
            Update(info.EllapsedTime, info.ButtonState);

            SharedString str = _text != null ? _text : info.Text;

            float         scale = _font.Scale;
            UniversalFont font  = _font.Font;

            Color color = ColorFromState * info.Opacity * Opacity;

            Rectangle target = _margin.ComputeRect(info.Target);

            drawBatch.DrawText(font, str, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation);
        }
Ejemplo n.º 8
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            if (Colors == null)
            {
                base.Draw(ref parameters);
                return;
            }

            float opacity = parameters.Opacity;

            if (opacity == 0 || TextColor.Value.A == 0)
            {
                return;
            }

            if (_fontFace == null)
            {
                _fontFace = FontManager.Instance.FindFont(FontName);
            }

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

            if (font.SitanaFont == null)
            {
                throw new Exception("Only Sitana fonts support UiColoredLabel.");
            }

            lock (Text)
            {
                lock (Colors)
                {
                    parameters.DrawBatch.DrawText(font, Text.StringBuilder, ScreenBounds, TextAlign, Colors, opacity, (float)FontSpacing / 1000.0f, (float)LineHeight / 100.0f, scale);
                }
            }
        }
Ejemplo n.º 9
0
        public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info)
        {
            Update(info.EllapsedTime, info.ButtonState);

            SharedString str = _text != null ? _text : info.Text;

            float         scale = _font.Scale;
            UniversalFont font  = _font.Font;

            Color     color  = ColorFromState * info.Opacity * Opacity;
            Rectangle target = _margin.ComputeRect(info.Target);

            bool drawWithEllipsis = false;
            int  ellipsisSize     = _textRotation == TextRotation.Rotate90 || _textRotation == TextRotation.Rotate270 ? target.Height : target.Width;

            if (_pathEllipsis)
            {
                int length = (int)_font.MeasureString(str).X;

                if (length >= ellipsisSize)
                {
                    drawWithEllipsis = true;
                }
            }

            if (drawWithEllipsis)
            {
                int cut = 3;
                while (drawWithEllipsis)
                {
                    lock (str)
                    {
                        ComputeEllipsis(_stringBuilder, str.StringBuilder, cut);
                    }

                    int length = (int)_font.MeasureString(_stringBuilder).X;

                    if (length < ellipsisSize)
                    {
                        break;
                    }

                    cut += 2;
                }

                drawBatch.DrawText(font, _stringBuilder, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation);
            }
            else if (_line >= 0)
            {
                _stringBuilder.Clear();

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

                    int line = 0;

                    for (int idx = 0; idx < textStringBuilder.Length; ++idx)
                    {
                        char character = textStringBuilder[idx];

                        if (character == '\n')
                        {
                            line++;

                            if (line > _line)
                            {
                                break;
                            }
                        }

                        if (character == '\r')
                        {
                            continue;
                        }

                        if (line == _line)
                        {
                            _stringBuilder.Append(textStringBuilder[idx]);
                        }
                    }
                }

                drawBatch.DrawText(font, _stringBuilder, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation);
            }
            else
            {
                drawBatch.DrawText(font, str, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation);
            }
        }
Ejemplo n.º 10
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";
            }
        }
Ejemplo n.º 11
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            base.Draw(ref parameters);

            Rectangle target = ScreenBounds;

            if (_height < target.Height)
            {
                switch (_textAlign & TextAlign.Vert)
                {
                case TextAlign.Middle:
                    target.Y = target.Center.Y - _height / 2;
                    break;

                case TextAlign.Bottom:
                    target.Y = target.Bottom - _height;
                    break;
                }
            }

            int startX = target.X;

            int endY = target.Bottom;

            int top    = parameters.DrawBatch.ClipRect.Top;
            int bottom = parameters.DrawBatch.ClipRect.Bottom;

            _firstVisibleLine = -1;

            for (int idx = 0; idx < _lines.Count; ++idx)
            {
                RichViewLine line = _lines[idx];

                if (target.Y > bottom)
                {
                    break;
                }

                target.Height = line.Height;

                if (target.Y + line.Height >= top)
                {
                    if (_firstVisibleLine < 0)
                    {
                        _firstVisibleLine = idx;
                    }

                    _lastVisibleLine = idx;

                    int lineOffset = OffsetFromWidthAndAlign(line.Width);

                    for (int ent = 0; ent < line.Entities.Count; ++ent)
                    {
                        RichViewEntity entity = line.Entities[ent];

                        float         spacing = entity.FontSpacing;
                        float         scale   = entity.FontScale;
                        UniversalFont font    = entity.Font;

                        int offset = 0;

                        if (font != null)
                        {
                            offset = line.BaseLine - (int)((font.BaseLine - 1) * scale);
                        }

                        target.X = startX + entity.Offset + lineOffset;

                        switch (entity.Type)
                        {
                        case EntityType.HorizontalLine:
                        {
                            Rectangle rect = new Rectangle(target.X, target.Y, Bounds.Width, _horizontalRulerHeight.Compute(0));
                            parameters.DrawBatch.DrawRectangle(rect, _colorRuler.Value * opacity);
                        }
                        break;

                        case EntityType.String:
                        {
                            Color textColor = _colorNormal.Value;

                            if (entity.Url != null)
                            {
                                textColor = _selected == entity ? _colorClickableActive.Value : _colorClickable.Value;
                            }

                            target.Y += offset;
                            parameters.DrawBatch.DrawText(font, entity.Text, target, TextAlign.Left, textColor * opacity, spacing, 0, scale);
                            target.Y -= offset;
                        }
                        break;

                        case EntityType.Image:
                        {
                            Point size = new Point((int)(entity.Image.Width * UiUnit.Unit), (int)(entity.Image.Height * UiUnit.Unit));

                            int maxWidth = Bounds.Width - entity.Offset;

                            if (size.X > maxWidth)
                            {
                                size.Y = maxWidth * size.Y / size.X;
                                size.X = maxWidth;
                            }

                            parameters.DrawBatch.DrawImage(entity.Image, target.Location, size, Point.Zero, (float)size.X / (float)entity.Image.Width, Color.White * opacity);
                        }
                        break;
                        }
                    }
                }

                target.Y += line.Height;
            }
        }
Ejemplo n.º 12
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() + " ";
        }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            base.Draw(ref parameters);

            int position      = 0;
            int startPosition = ScreenBounds.Top;

            int separatorHeight = _separator != null?Math.Max(1, _separatorHeight.Compute(Bounds.Height)) : 0;

            int rowHeight = _rowHeight.Compute(Bounds.Height);

            Rectangle target = new Rectangle();


            float startIndexF = _scrollingService.ScrollPositionY / (float)(rowHeight + separatorHeight);

            int startIndex = (int)startIndexF;

            startPosition -= (int)_scrollingService.ScrollPositionY % (rowHeight + separatorHeight);

            if (_reversed)
            {
                startIndex = _items.Count - startIndex - 1;
            }

            Rectangle textTarget = new Rectangle();
            int       maxY       = ScreenBounds.Bottom;

            parameters.DrawBatch.PushClip(ScreenBounds);

            target        = ScreenBounds;
            target.Y      = startPosition;
            target.Height = separatorHeight;

            if (separatorHeight > 0)
            {
                for (int dataIndex = startIndex; dataIndex < _items.Count && dataIndex >= 0;)
                {
                    _separator.Draw(parameters.DrawBatch, target, parameters.Opacity);

                    target.Y += rowHeight + separatorHeight;

                    if (target.Y > maxY)
                    {
                        break;
                    }

                    dataIndex += _reversed ? -1 : 1;
                }
            }

            startPosition += separatorHeight;

            for (int columnIndex = 0; columnIndex < _columns.Count; ++columnIndex)
            {
                var column = _columns[columnIndex];
                int width  = column.Width.Compute(Bounds.Width);

                UniversalFont font        = column.Font.Font;
                float         fontScale   = column.Font.Scale;
                float         fontSpacing = column.Font.Spacing;

                int lineHeight = column.LineHeight;

                TextAlign textAlign = column.TextAlign;

                target.X     = position + column.TextMargin.Left + ScreenBounds.Left;
                target.Width = width - column.TextMargin.Width;

                target.Y      = startPosition;
                target.Height = rowHeight;

                Margin textMargin = column.TextMargin;

                int dataIndex = startIndex;
                int count     = _items.Count;

                for (int idx = 0; idx < count; idx++)
                {
                    textTarget.X     = target.X;
                    textTarget.Width = target.Width;

                    textTarget.Y      = target.Y + textMargin.Top;
                    textTarget.Height = target.Height - textMargin.Height;

                    if (dataIndex >= 0 && dataIndex < count)
                    {
                        QuickDataRow row = (QuickDataRow)(_items.ElementAt(dataIndex));

                        Color  color = row.Colors[columnIndex].Value;
                        string text  = row.Labels[columnIndex];

                        parameters.DrawBatch.DrawText(font, text, textTarget, textAlign, color, fontSpacing, lineHeight, fontScale);
                    }

                    target.Y += target.Height + separatorHeight;

                    if (target.Y > maxY)
                    {
                        break;
                    }

                    dataIndex += _reversed ? -1 : 1;
                }

                position += width;
            }

            parameters.DrawBatch.PopClip();
        }