Esempio n. 1
0
        public override ConsoleCharBuffer Render()
        {
            if (!_dirty && displayBuffer != null)
            {
                return(displayBuffer);
            }

            ConsoleCharBuffer buffer;

            string[] lines = Text.Split(new string[] { "\n" }, StringSplitOptions.None);

            if (MaxLength == null)
            {
                buffer = new ConsoleCharBuffer(lines.Max(item => item.Length), lines.Length);

                for (int i = 0; i < lines.Length; i++)
                {
                    buffer.DrawString(this, lines[i], false, 0, i, BackgroundColor, ForegroundColor);
                }
            }
            else
            {
                buffer = new ConsoleCharBuffer(MaxLength.Value, lines.Length);

                for (int i = 0; i < lines.Length; i++)
                {
                    buffer.DrawString(this, lines[i].Truncate(MaxLength.Value), false, 0, i, BackgroundColor, ForegroundColor);
                }
            }

            Dirty = false;

            return(buffer);
        }
Esempio n. 2
0
        public override ConsoleCharBuffer Render()
        {
            if (!_dirty && displayBuffer != null)
            {
                return(displayBuffer);
            }

            ConsoleCharBuffer buffer = new ConsoleCharBuffer(Label.Length + 4, 1);

            if (_isChecked)
            {
                buffer.data[0, 0] = new ConsoleChar(this, '█', true, _focused ? BackgroundColorFocused : BackgroundColor, ActiveAreaForegroundColor);
                buffer.data[1, 0] = new ConsoleChar(this, '█', true, _focused ? BackgroundColorFocused : BackgroundColor, ActiveAreaForegroundColor);
                buffer.data[2, 0] = new ConsoleChar(this, '█', true, _focused ? BackgroundColorFocused : BackgroundColor, _focused ? CursorForegroundColorFocused : CursorForegroundColor);
            }
            else
            {
                buffer.data[0, 0] = new ConsoleChar(this, '█', true, _focused ? BackgroundColorFocused : BackgroundColor, _focused ? CursorForegroundColorFocused : CursorForegroundColor);
                buffer.data[1, 0] = new ConsoleChar(this, '█', true, _focused ? BackgroundColorFocused : BackgroundColor, InactiveAreaForegroundColor);
                buffer.data[2, 0] = new ConsoleChar(this, '█', true, _focused ? BackgroundColorFocused : BackgroundColor, InactiveAreaForegroundColor);
            }

            buffer.DrawString(this, _label, true, 4, 0, LabelBackgroundColor, LabelForegroundColor);

            _dirty = false;

            return(buffer);
        }
Esempio n. 3
0
        public override ConsoleCharBuffer Render()
        {
            if (!_dirty && displayBuffer != null)
            {
                return(displayBuffer);
            }

            ConsoleCharBuffer buffer = new ConsoleCharBuffer(Label.Length + 4, 1);

            if (_isChecked)
            {
                buffer.DrawString(this, "(O)", true, 0, 0, _focused ? BackgroundColorFocused : BackgroundColorChecked, _focused ? ForegroundColorFocused : ForegroundColorChecked);
            }
            else
            {
                buffer.DrawString(this, "( )", true, 0, 0, _focused ? BackgroundColorFocused : BackgroundColor, _focused ? ForegroundColorFocused : ForegroundColor);
            }


            buffer.DrawString(this, _label, false, 4, 0, LabelBackgroundColor, LabelForegroundColor);

            _dirty = false;

            return(buffer);
        }
Esempio n. 4
0
        public override ConsoleCharBuffer Render()
        {
            if (!_dirty && displayBuffer != null)
            {
                return(displayBuffer);
            }

            Font figfont = FontFactory.GetFont(FontName);

            FIGBuffer rendered = figfont.Render(Text);

            ConsoleCharBuffer buffer = new ConsoleCharBuffer(rendered.Width, rendered.Height);

            buffer.Clear();

            for (int x = 0; x < buffer.Width; x++)
            {
                for (int y = 0; y < buffer.Height; y++)
                {
                    char ch = rendered.data[x, y].Char;
                    if (ch != TransparentChar)
                    {
                        buffer.data[x, y] = new ConsoleChar(this, ch, false, BackgroundColor, ForegroundColor);
                    }
                }
            }

            Dirty = false;

            return(buffer);
        }
Esempio n. 5
0
        protected override ConsoleCharBuffer RenderContainer()
        {
            ConsoleCharBuffer buffer = new ConsoleCharBuffer(Width + 1, Height + 1);

            DrawingHelper.DrawBlockFull(buffer, this, false, 0, 0, Width, Height, BackgroundColor, ForegroundColor, Border, Shadow);

            buffer.DrawString(this, _title.Truncate(Width - 2), false, 1, 0, ConsoleColor.Black, ConsoleColor.White);

            return(buffer);
        }
Esempio n. 6
0
        public Engine(int width = 120, int height = 30)
        {
            _currentConsole = new WindowsConsole();


            _currentConsole.Width  = width;
            _currentConsole.Height = height;

            _engineBuffer = new ConsoleCharBuffer(width, height);

            _debounceDirty.AutoReset = false;
            _debounceDirty.Elapsed  += DebounceDirty_Elapsed;
        }
Esempio n. 7
0
        public override ConsoleCharBuffer Render()
        {
            if (!_dirty && displayBuffer != null)
            {
                return(displayBuffer);
            }

            ConsoleCharBuffer baseBuffer = RenderContainer();

            ConsoleCharBuffer componentsBuffer = new ConsoleCharBuffer(Width - 2, Height - 2);

            foreach (DisplayObject child in Children.Where(item => item.Visible))
            {
                componentsBuffer = componentsBuffer.Merge(child.Render(), child.X, child.Y);
            }

            baseBuffer.Merge(componentsBuffer, 1, 1);

            displayBuffer = baseBuffer;

            _dirty = false;

            return(baseBuffer);
        }
Esempio n. 8
0
        public override ConsoleCharBuffer Render()
        {
            if (!_dirty && displayBuffer != null)
            {
                return(displayBuffer);
            }



            DisplayObject rootScreenCandidate = this.Parents <DisplayObject>(item => item.Parent).LastOrDefault();

            if (!(rootScreenCandidate is Screen))
            {
                _dirty = false;
                return(new ConsoleCharBuffer(0, 0));
            }

            Screen screen = (Screen)rootScreenCandidate;



            if (screen.Height == 0)
            {
                _dirty = false;
                return(new ConsoleCharBuffer(0, 0));
            }

            ConsoleCharBuffer baseBuffer = new ConsoleCharBuffer(screen.Width, 1);

            baseBuffer.yOffset = screen.Height - 1;

            string textLeftTruncated = _textLeft.Truncate(screen.Width);

            string textCenterTruncated = _textCenter.Truncate(screen.Width);

            string textRightTruncated = _textRight.Truncate(screen.Width);


            StringBuilder outputLine = new StringBuilder(new string(' ', screen.Width));


            int centerStartOffset = (screen.Width - textCenterTruncated.Length) / 2;


            for (int i = 0; i < textCenterTruncated.Length; i++)
            {
                outputLine[i + centerStartOffset] = textCenterTruncated[i];
            }

            for (int i = 0; i < textRightTruncated.Length; i++)
            {
                outputLine[screen.Width - textRightTruncated.Length + i] = textRightTruncated[i];
            }

            for (int i = 0; i < textLeftTruncated.Length; i++)
            {
                outputLine[i] = textLeftTruncated[i];
            }

            baseBuffer.DrawString(this, outputLine.ToString(), false, 0, 0, BackgroundColor, ForegroundColor);

            displayBuffer = baseBuffer;

            _dirty = false;

            return(baseBuffer);
        }
Esempio n. 9
0
        public override ConsoleCharBuffer Render()
        {
            lock (templock)
            {
                if (!_dirty && displayBuffer != null)
                {
                    return(displayBuffer);
                }


                int width = 1 + Data.Count;
                int height;

                float trueMin = MinY ?? Data.Min();
                float trueMax = MaxY ?? Data.Max();

                if (Height.HasValue)
                {
                    height = Height.Value;
                }
                else
                {
                    height = (int)Math.Ceiling(Data.Max() - Data.Min()) + 1;
                }

                int labelLength = 0;

                if (ShowYMinMax)
                {
                    labelLength = Math.Max(trueMin.ToString().Length, trueMax.ToString().Length);
                    width      += labelLength;
                }


                ConsoleCharBuffer buffer = new ConsoleCharBuffer(width, height);

                // Axes
                for (int y = 0; y < buffer.Height; y++)
                {
                    buffer.data[labelLength, y] = new ConsoleChar(this,
                                                                  DrawingHelper.GetVerticalBorder(BorderStyle.Thin)[0], false, null, AxesForegroundColor);
                }

                buffer.DrawString(this, new string(DrawingHelper.GetHorizontalBorder(BorderStyle.Thin)[0], width),
                                  false, labelLength, height - 1, null, AxesForegroundColor);

                buffer.data[labelLength, height - 1].Char =
                    DrawingHelper.GetBottomLeftCornerBorder(BorderStyle.Thin)[0];

                if (ShowYMinMax)
                {
                    buffer.data[labelLength, 0].Char          = DrawingHelper.GetBottomTJunctionBorder(BorderStyle.Thin)[0];
                    buffer.data[labelLength, height - 1].Char =
                        DrawingHelper.GetTopTJunctionBorder(BorderStyle.Thin)[0];

                    buffer.DrawString(this, trueMax.ToString(), false, labelLength - trueMax.ToString().Length, 0, null,
                                      AxesForegroundColor);
                    buffer.DrawString(this, trueMin.ToString(), false, labelLength - trueMin.ToString().Length,
                                      height - 1, null, AxesForegroundColor);
                }



                int pointRange  = (int)Math.Ceiling(trueMax - trueMin);
                int pointOffset = (int)Math.Round(trueMin);

                int displayRange = (height - 1) * 2;
                int origin       = (int)Math.Round(pointOffset / pointRange * displayRange * 1.0);

                for (var pointIdx = 0; pointIdx < Data.Count; pointIdx++)
                {
                    float point = Data[pointIdx];

                    int rounded = (int)Math.Round((point - pointOffset) / pointRange * displayRange);

                    if (ChartType == ChartType.Line)
                    {
                        if (rounded == origin)
                        {
                            buffer.data[pointIdx + labelLength + 1, height - 1] = new ConsoleChar(this,
                                                                                                  DrawingHelper.GetHorizontalBorder(BorderStyle.Thin)[0], false, null,
                                                                                                  DataForegroundColor[pointIdx % DataForegroundColor.Length]);
                        }
                        else
                        {
                            buffer.data[pointIdx + labelLength + 1, height - 1] = new ConsoleChar(this,
                                                                                                  DrawingHelper.GetTopTJunctionBorder(BorderStyle.Thin)[0], false, null,
                                                                                                  DataForegroundColor[pointIdx % DataForegroundColor.Length]);

                            for (int i = 0; i < rounded - 1; i += 2)
                            {
                                buffer.data[pointIdx + labelLength + 1, height - 2 - (i / 2)] = new ConsoleChar(this,
                                                                                                                DrawingHelper.GetVerticalBorder(BorderStyle.Thin)[0], false, null,
                                                                                                                DataForegroundColor[pointIdx % DataForegroundColor.Length]);
                            }

                            if (rounded % 2 == 0)
                            {
                                buffer.data[pointIdx + labelLength + 1, height - 1 - (rounded / 2)] = new ConsoleChar(
                                    this, DrawingHelper.GetTopRightCornerBorder(BorderStyle.Thin)[0], false, null,
                                    DataForegroundColor[pointIdx % DataForegroundColor.Length]);
                            }
                        }
                    }
                    else if (ChartType == ChartType.Bar)
                    {
                        if (rounded == origin)
                        {
                            buffer.data[pointIdx + labelLength + 1, height - 1] = new ConsoleChar(this,
                                                                                                  DrawingHelper.GetHorizontalBorder(BorderStyle.Thin)[0], false, null,
                                                                                                  DataForegroundColor[pointIdx % DataForegroundColor.Length]);
                        }
                        else
                        {
                            buffer.data[pointIdx + labelLength + 1, height - 1] = new ConsoleChar(this,
                                                                                                  DrawingHelper.GetBottomLeftCornerBorder(BorderStyle.Block)[0], false, null,
                                                                                                  DataForegroundColor[pointIdx % DataForegroundColor.Length]);

                            for (int i = 0; i < rounded - 1; i += 2)
                            {
                                buffer.data[pointIdx + labelLength + 1, height - 2 - (i / 2)] = new ConsoleChar(this,
                                                                                                                DrawingHelper.GetVerticalBorder(BorderStyle.Block)[0], false, null,
                                                                                                                DataForegroundColor[pointIdx % DataForegroundColor.Length]);
                            }

                            if (rounded % 2 == 0)
                            {
                                buffer.data[pointIdx + labelLength + 1, height - 1 - (rounded / 2)] = new ConsoleChar(
                                    this, DrawingHelper.GetTopRightCornerBorder(BorderStyle.Block)[0], false, null,
                                    DataForegroundColor[pointIdx % DataForegroundColor.Length]);
                            }
                        }
                    }
                    else if (ChartType == ChartType.Point)
                    {
                        buffer.data[pointIdx + labelLength + 1, height - 1 - rounded / 2] = new ConsoleChar(this,
                                                                                                            '*', false, null, DataForegroundColor[pointIdx % DataForegroundColor.Length]);
                    }
                }

                Dirty = false;

                return(buffer);
            }
        }