PowerArgs.Cli.ScrollablePanel.OnPaint C# (CSharp) Method

OnPaint() protected method

protected OnPaint ( ConsoleBitmap context ) : void
context ConsoleBitmap
return void
        protected override void OnPaint(ConsoleBitmap context)
        {
            var fullSize = ScrollableContentSize;
            ConsoleBitmap fullyPaintedPanel = new ConsoleBitmap(0, 0, fullSize.Width, fullSize.Height);
            ScrollableContent.PaintTo(fullyPaintedPanel);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    int scrollX = x + HorizontalScrollUnits;
                    int scrollY = y + VerticalScrollUnits;

                    if (scrollX >= fullyPaintedPanel.Width || scrollY >= fullyPaintedPanel.Height)
                    {
                        continue;
                    }

                    var scrolledPixel = fullyPaintedPanel.GetPixel(scrollX, scrollY);

                    if (scrolledPixel.Value.HasValue)
                    {
                        context.Pen = scrolledPixel.Value.Value;
                    }
                    else
                    {
                        context.Pen = new ConsoleCharacter(' ', backgroundColor: Background);
                    }

                    context.DrawPoint(x, y);
                }
            }

            base.OnPaint(context);
        }