Beispiel #1
0
 private VideoReader(VideoInfo info, Stream stream)
 {
     Info        = info;
     this.stream = stream;
     Current     = new ColoredChar[Info.Width, Info.Height];
     buffer      = new byte[info.TotalLength * 5];
 }
Beispiel #2
0
 public BoxElement(int x, int y, int width, int height, Func <Game, ColoredString> title, Func <Game, IEnumerable <ColoredString> > content)
     : base(x, y)
 {
     Width   = width;
     Height  = height;
     Text    = new ColoredChar[Height, Width];
     Title   = title;
     Content = content;
 }
Beispiel #3
0
        public override void Draw(ref ColoredChar[,] buffer)
        {
            if (!Visible)
            {
                ColoredChar cc = new ColoredChar('\0', Parent.ForeColor, Parent.BackColor);
                buffer.Populate(cc);
                return;
            }

            bool showPlaceholder = (!Focused && Placeholder.Length > 0 && Text.Length <= 0);

            for (int y = 0; y < Size.Height; y++)
            {
                for (int x = 0; x < Size.Width; x++)
                {
                    char chr       = '\0';
                    int  index     = (x - 1) + renderOffset;
                    bool showCaret = (CaretPosition == index && Focused);

                    Color4 fForeColor = ForeColor;
                    Color4 fBackColor = BackColor;

                    if (x == 0)
                    {
                        chr = '[';
                    }
                    else if (x == Size.Width - 1)
                    {
                        chr = ']';
                    }
                    else if (index >= 0 && index < Text.Length)
                    {
                        chr = Text[index];
                    }
                    else if (showPlaceholder && index >= 0 && index < Placeholder.Length)
                    {
                        chr = Placeholder[index];
                    }

                    if (x != 0 && x != Size.Width - 1)
                    {
                        fForeColor = (showCaret ? CaretForeColor : ForeColor);
                        fBackColor = (showCaret ? CaretBackColor : BackColor);

                        fForeColor = (showPlaceholder ? PlaceholderForeColor : fForeColor);
                        fBackColor = (showPlaceholder ? PlaceholderBackColor : fBackColor);
                    }

                    buffer[x, y] = new ColoredChar(chr, fForeColor, fBackColor);
                }
            }
        }
Beispiel #4
0
        /// <inheritdoc />
        public bool MoveNext()
        {
            var bytesRead = stream.Read(buffer);

            if (bytesRead == 0)
            {
                return(false);
            }

            if (bytesRead != Info.TotalLength * 5)
            {
                throw new Exception("Can't read full frame");
            }

            var offset = 0;

            for (var y = 0; y < Info.Height; y++)
            {
                for (var x = 0; x < Info.Width; x++)
                {
                    var style      = BitConverter.ToUInt16(buffer, offset);
                    var foreground = MyColorExt.FromInt((style & 0b11111_00000_000000) >> 11);
                    var background = MyColorExt.FromInt((style & 0b00000_11111_000000) >> 6);
                    var flags      = (byte)(style & 0b00000_00000_111111);

                    if (!Enum.IsDefined(typeof(MyColor), foreground))
                    {
                        foreground = default;
                    }

                    if (!Enum.IsDefined(typeof(MyColor), background))
                    {
                        background = default;
                    }

                    // Собираем из трёх байтов один int. Порядок little-endian, старшие разряды остаются пустыми.
                    var charNumber =
                        buffer[offset + 2]
                        | (buffer[offset + 3] << 8)
                        | (buffer[offset + 4] << 16);
                    var character = (char)charNumber;
                    offset += 5;

                    Current[x, y] = new ColoredChar(new Style(foreground, background), character);
                }
            }

            return(true);
        }
Beispiel #5
0
        public void Clear(string boxName)
        {
            DisplayBox box = displayBoxes.FirstOrDefault(x => x.Name == boxName);

            if (box != null)
            {
                for (int i = box.DisplayX; i < box.DisplayX + box.DisplayWidth; i++)
                {
                    for (int j = box.DisplayY; j < box.DisplayY + box.DisplayHeight; j++)
                    {
                        buffer[i, j] = new ColoredChar();
                    }
                }
            }
        }
Beispiel #6
0
        public override void Draw(ref ColoredChar[,] buffer)
        {
            if (!Visible)
            {
                ColoredChar cc = new ColoredChar('\0', Parent.ForeColor, Parent.BackColor);
                buffer.Populate(cc);
                return;
            }

            Color4 fBackColor = BackColor;
            Color4 fForeColor = ForeColor;

            if (Highlighted)
            {
                fBackColor = HighlightedBackColor;
                fForeColor = HighlightedForeColor;
            }

            if (Clicked)
            {
                fBackColor = ClickingBackColor;
                fForeColor = ClickingForeColor;
            }

            if (!Enabled)
            {
                fForeColor = DisabledForeColor;
            }

            string fText   = $"({(Checked ? CheckedChar : ' ')}) {Text}";
            int    yMiddle = Size.Height / 2;

            for (int y = 0; y < Size.Height; y++)
            {
                for (int x = 0; x < Size.Width; x++)
                {
                    char chr = '\0';

                    if (y == yMiddle && x >= 0 && x < fText.Length)
                    {
                        chr = fText[x];
                    }

                    ColoredChar c = new ColoredChar(chr, fForeColor, fBackColor);
                    buffer[x, y] = c;
                }
            }
        }
Beispiel #7
0
        public override void Draw(ref ColoredChar[,] buffer)
        {
            if (!Visible)
            {
                ColoredChar cc = new ColoredChar('\0', Parent.ForeColor, Parent.BackColor);
                buffer.Populate(cc);
                return;
            }

            string t = Text;

            if (t.Length <= 0)
            {
                return;
            }

            int i = 0;

            Color4 fForeColor = ForeColor;

            if (!Enabled)
            {
                fForeColor = DisabledForeColor;
            }

            for (int y = 0; y < Size.Height; y++)
            {
                for (int x = 0; x < Size.Width; x++)
                {
                    if (i < Text.Length)
                    {
                        char c = Text[i++];

                        if (c == '\n')
                        {
                            break;
                        }

                        buffer[x, y] = new ColoredChar(c, fForeColor, BackColor);
                    }
                    else
                    {
                        buffer[x, y] = new ColoredChar('\0', fForeColor, BackColor);
                    }
                }
            }
        }
Beispiel #8
0
        /// <inheritdoc />
        public override void Render(RenderContext context)
        {
            var ctx = context.Derive((1, 1, 1));

            base.Render(ctx);

            var(width, height) = ctx.Size;

            if (width == 0 && height == 0)
            {
                return;
            }

            var right  = width + 1;
            var bottom = height + 1;

            var above = context.Derive((0, 0, 1));

            for (var x = 1; x <= width; x++)
            {
                above[x, 0]      = new ColoredChar(Style, '═');
                above[x, bottom] = new ColoredChar(Style, '═');
            }

            for (var y = 1; y <= height; y++)
            {
                above[0, y]     = new ColoredChar(Style, '║');
                above[right, y] = new ColoredChar(Style, '║');
            }

            above[0, 0]          = new ColoredChar(Style, '╔');
            above[right, 0]      = new ColoredChar(Style, '╗');
            above[0, bottom]     = new ColoredChar(Style, '╚');
            above[right, bottom] = new ColoredChar(Style, '╝');

            var bgStyle = new Style(Background, Background);

            for (var x = 0; x <= right; x++)
            {
                for (var y = 0; y <= bottom; y++)
                {
                    context[x, y] = new ColoredChar(bgStyle, ' ');
                }
            }
        }
Beispiel #9
0
        public void LoadBorders()
        {
            foreach (DisplayBox box in displayBoxes)
            {
                if (box.Border != null)
                {
                    for (int i = box.DisplayY; i < box.DisplayY + box.Border.Thickness[DisplayBorder.TOP] + box.Border.Thickness[DisplayBorder.BOTTOM]; i++)
                    {
                        int line = i;
                        if (i >= box.DisplayY + box.Border.Thickness[DisplayBorder.TOP])
                        {
                            line = (i - box.Border.Thickness[DisplayBorder.TOP]) + (box.DisplayHeight - box.Border.Thickness[DisplayBorder.BOTTOM]);
                        }
                        for (int j = box.DisplayX; j < box.DisplayX + box.DisplayWidth; j++)
                        {
                            buffer[j, line] = new ColoredChar {
                                BackgroundColor = box.Border.BackgroundColor, Character = box.Border.Symbol, ForegroundColor = box.Border.ForegroundColor
                            };
                        }
                    }

                    for (int i = box.DisplayY + box.Border.Thickness[DisplayBorder.TOP]; i < box.DisplayY + box.DisplayHeight - box.Border.Thickness[DisplayBorder.BOTTOM]; i++)
                    {
                        for (int j = box.DisplayX; j < box.DisplayX + box.Border.Thickness[DisplayBorder.LEFT]; j++)
                        {
                            buffer[j, i] = new ColoredChar {
                                BackgroundColor = box.Border.BackgroundColor, Character = box.Border.Symbol, ForegroundColor = box.Border.ForegroundColor
                            };
                        }

                        for (int j = box.DisplayX + box.DisplayWidth - box.Border.Thickness[DisplayBorder.RIGHT]; j < box.DisplayX + box.DisplayWidth; j++)
                        {
                            buffer[j, i] = new ColoredChar {
                                BackgroundColor = box.Border.BackgroundColor, Character = box.Border.Symbol, ForegroundColor = box.Border.ForegroundColor
                            };
                        }
                    }
                }
            }
        }
Beispiel #10
0
 public Projection(int row, int col, ColoredChar c)
 {
     Row  = row;
     Col  = col;
     Char = c;
 }
Beispiel #11
0
        public override void Draw(ref ColoredChar[,] buffer)
        {
            if (!Visible)
            {
                ColoredChar cc = new ColoredChar('\0', Parent.ForeColor, Parent.BackColor);
                buffer.Populate(cc);
                return;
            }

            Color4 fBackColor = BackColor;
            Color4 fForeColor = ForeColor;

            if (Highlighted)
            {
                fBackColor = HighlightedBackColor;
                fForeColor = HighlightedForeColor;
            }

            if (Clicked)
            {
                fBackColor = ClickingBackColor;
                fForeColor = ClickingForeColor;
            }

            if (!Enabled)
            {
                fForeColor = DisabledForeColor;
            }

            int yMiddle = Size.Height / 2;

            for (int y = 0; y < Size.Height; y++)
            {
                for (int x = 0; x < Size.Width; x++)
                {
                    char chr = '\0';

                    if (y == yMiddle)
                    {
                        var index = 0;
                        switch (TextAlign)
                        {
                        case TextAlignement.Left:
                            index = x;
                            chr   = (index >= 0 && index < Text.Length ? Text[index] : '\0');
                            break;

                        case TextAlignement.Middle:
                            index = x - Size.Width / 2 + Text.Length / 2;
                            chr   = (index >= 0 && index < Text.Length ? Text[index] : '\0');
                            break;

                        case TextAlignement.Right:
                            index = x - (Size.Width - Text.Length);
                            chr   = (index >= 0 && index < Text.Length ? Text[index] : '\0');
                            break;

                        default:
                            break;
                        }
                    }

                    ColoredChar c = new ColoredChar(chr, fForeColor, fBackColor);
                    buffer[x, y] = c;
                }
            }
        }
Beispiel #12
0
 /// <summary>
 /// Сравнивает два символа.
 /// </summary>
 /// <param name="other">Символ, с которым нужно сравнить текущий.</param>
 /// <returns>true, если они одинаковы.</returns>
 public bool Equals(ColoredChar other)
 {
     return(FlatEquals(other) && Layer == other.Layer);
 }
Beispiel #13
0
 /// <summary>
 /// Сравнивает два символа, независимо от их слоёв.
 /// </summary>
 /// <param name="other">Символ, на равенство с которым необходимо сравнить этот.</param>
 /// <returns>true, если они одинаковы.</returns>
 public bool FlatEquals(ColoredChar other)
 {
     return(Style.Equals(other.Style) && Char == other.Char);
 }
Beispiel #14
0
        public override void Draw(ref ColoredChar[,] buffer)
        {
            ColoredChar c = new ColoredChar('\0', ForeColor, BackColor);

            buffer.Populate(c);
        }