示例#1
0
        internal void Render(Region window, DotConsoleRegion owner)
        {
            int height = Options.Orgin.Y + window.Top + (contentBuffer.GetLengthOfY());
            int width  = Options.Orgin.X + window.Left + (contentBuffer.GetLengthOfX());

            int top  = Options.Orgin.Y + window.Top;
            int left = Options.Orgin.X + window.Left;

            //If we're rendering at the bottom the orgin moves the content up.
            if (Options.Position == ContentPosition.Bottom)
            {
                height = window.Height - Options.Orgin.Y;

                int sizeOfY = contentBuffer.GetLengthOfY();

                if (sizeOfY < window.Height)
                {
                    top = window.Height - Options.Orgin.Y - (contentBuffer.GetLengthOfY());
                }
            }

            if (Options.WillScrollContent == true)
            {
                top = Options.Orgin.Y;
            }
            //Scrollable content regions will not move with the window so theres no point to save state.
            else
            {
                savedContentBuffer = null;
                if (owner != null)
                {
                    savedContentBuffer = Restore(owner, new Region()
                    {
                        Left = left, Top = top, Height = height, Width = width
                    });
                }
                else
                {
                    savedContentBuffer = Renderer.ReadOutput(new Region()
                    {
                        Left = left, Top = top, Height = height, Width = width
                    });
                }
            }

            savedCoordsWithOffset.X = left;
            savedCoordsWithOffset.Y = top;

            if (owner != null)
            {
                Merge(owner.contentBuffer, this.contentBuffer);
            }
            else
            {
                Renderer.WriteOutput(savedCoordsWithOffset, this.contentBuffer);
            }
        }
示例#2
0
 /// <summary>
 ///Hides the contents of this buffer and shows orginal contents under the region.
 /// </summary>
 internal void Restore(DotConsoleRegion owner)
 {
     if (savedContentBuffer != null)
     {
         if (owner != null)
         {
             Merge(owner.contentBuffer, savedContentBuffer);
         }
         else
         {
             Renderer.WriteOutput(savedCoordsWithOffset, savedContentBuffer);
         }
     }
 }
示例#3
0
        /// <summary>
        /// Calculates where to put the cursor.
        /// </summary>
        internal void CalculateCursorBetweenRegions()
        {
            var wnd = Renderer.GetOutputBufferWindow();

            //Pick the max buffer size and scroll to that spot, this is mainly done to reducre the flickering.
            var maxY = -1;
            var maxX = -1;
            DotConsoleRegion maxYRegion = null;
            int current = maxY;

            //Always pick the parent if child regions don't need to scroll the window.
            var wndY = wnd.Top + wnd.Height;

            foreach (var region in regions)
            {
                current = region.currentBufferSize.Y + region.Options.Orgin.Y;
                if (current > maxY)
                {
                    maxY       = current;
                    maxYRegion = region;
                }
            }

            current = this.currentBufferSize.Y + Options.Orgin.Y;

            if (current > maxY)
            {
                maxYRegion = this;
                maxY       = current;
            }
            else if (maxY < wndY)
            {
                maxYRegion = this;
                maxY       = current;
            }

            //Once we have the region with the biggest value of Y we use it's X coordinate.
            maxX = Math.Min(maxYRegion.currentBufferSize.X + maxYRegion.Options.Orgin.X, maxYRegion.Options.BufferSize.X);

            var position = new Coordinates()
            {
                X = Math.Min(maxX, maxYRegion.Options.BufferSize.X - 1), Y = Math.Min(maxY, maxYRegion.Options.BufferSize.Y - 1)
            };

            if (savedCursorPosition.X != position.X || savedCursorPosition.Y != position.Y)
            {
                Renderer.SetCursorPosition(position);
                savedCursorPosition = position;
            }
        }
示例#4
0
        public DotConsoleRegion(RegionCreationOptions config)
        {
            Options = config;

            this.contentBuffer = new CellBuffer(Options.BufferSize.Y, Options.BufferSize.X);
            this.InputLoop     = new DotConsoleInputLoop(this);

            if (Options.ForegroundColor.Equals(default(Color)))
            {
                Options.ForegroundColor = new Color(255, 255, 255);
            }

            if (Options.Parent != null)
            {
                this.parent = config.Parent;
                this.parent.RegisterRegion(this);
            }
        }
示例#5
0
        private void Initialize()
        {
            renderer = new DotConsoleRenderer();

            //Set encoding.
            Console.OutputEncoding = System.Text.Encoding.Unicode;

            //Create the main content region.
            //This might not be the efficient way since content regions are extremly expensive so this may change.
            var size = renderer.GetOutputBufferWindowSize();

            var options = new RegionCreationOptions(renderer, null, size);

            options.WillScrollContent = true;

            main = new DotConsoleRegion(options);

            this.BackgroundColor = main.Options.BackgroundColor;
            this.ForegroundColor = main.Options.ForegroundColor;

            Console.CursorVisible = true;

            Controls = new List <IConsoleControl>();
        }
示例#6
0
        private CellBuffer Restore(DotConsoleRegion owner, Region region)
        {
            CellBuffer result = new CellBuffer(Options.BufferSize.Y, Options.BufferSize.X);

            int resultY = 0;
            int resultX = 0;

            int height = region.Top + (region.Height - region.Top);
            int width  = region.Left + (region.Width - region.Left);

            for (int y = region.Top; y < height; y++)
            {
                resultX = 0;
                for (int x = region.Left; x < width; x++)
                {
                    result[resultY, resultX] = owner.contentBuffer[y, x];
                    resultX++;
                }

                resultY++;
            }

            return(result);
        }
示例#7
0
 /// <summary>
 /// Registers a content region and reconfigures it so that they
 /// are controled by this dotConsole instance.
 /// </summary>
 /// <param name="region"></param>
 public void RegisterRegion(DotConsoleRegion region)
 {
     this.regions.Add(region);
 }