Example #1
0
        public void DrawAt(string text, TvPoint location, int zIndex, CharacterAttribute attr)
        {
            var start   = location.Left + (Width * location.Top);
            var end     = start + Math.Min(text.Length, Width - location.Left - 1);
            var textIdx = 0;
            var dirty   = IsDirty;
            var charCol = location.Left;
            var charRow = location.Top;

            for (var idx = start; idx < end; idx++)
            {
                var cchar   = _buffer[idx];
                var newchar = text[textIdx];
                if (cchar.ZIndex <= zIndex)
                {
                    var comparison = cchar.CompareContents(newchar, attr);
                    if (comparison != ConsoleCharacterComparison.Equals)
                    {
                        cchar.Character  = newchar;
                        cchar.Attributes = attr;
                        cchar.ZIndex     = zIndex;
                        dirty            = true;
                        _dirtyMap[idx]   = (DirtyStatus)comparison;
                    }
                    cchar.ZIndex = zIndex;
                }
                textIdx++;
                charCol++;
            }

            IsDirty = dirty;
        }
Example #2
0
        public void CopyCharacter(TvPoint location, ConsoleCharacter charToCopy, int count)
        {
            var start   = location.Left + (Width * location.Top);
            var zindex  = charToCopy.ZIndex;
            var end     = start + Math.Min(count, Width - location.Left - 1);
            var charCol = location.Left;
            var charRow = location.Top;
            var dirty   = IsDirty;

            for (var idx = start; idx < end; idx++)
            {
                var cchar = _buffer[idx];
                if (cchar.ZIndex <= zindex)
                {
                    var comparison = cchar.CompareContents(charToCopy.Character, charToCopy.Attributes);
                    if (comparison != ConsoleCharacterComparison.Equals)
                    {
                        cchar.Character  = charToCopy.Character;
                        cchar.Attributes = charToCopy.Attributes;
                        cchar.ZIndex     = charToCopy.ZIndex;
                        dirty            = true;
                        _dirtyMap[idx]   = (DirtyStatus)comparison;
                    }
                    cchar.ZIndex = zindex;
                }
                charCol++;
            }

            IsDirty = dirty;
        }
Example #3
0
        public static void DrawStringAt(string text, TvPoint location, CharacterAttribute attr, IViewport boxModel, VirtualConsole console)
        {
            var consoleLocation = ViewPointToConsolePoint(location, boxModel.Position);
            var zindex          = boxModel.ZIndex;

            if (boxModel.Columns < text.Length)
            {
                text = text.Substring(0, boxModel.Columns);
            }
            console.DrawAt(text, consoleLocation, zindex, attr);
        }
Example #4
0
        internal static void DrawChars(char value, int count, TvPoint location, CharacterAttribute attribute, IViewport boxModel, VirtualConsole console)
        {
            var chars  = new ConsoleCharacter[count];
            var zindex = boxModel.ZIndex;
            var cc     = new ConsoleCharacter()
            {
                Character = value, Attributes = attribute, ZIndex = zindex
            };
            var pos = ViewPointToConsolePoint(location, boxModel.Position);

            console.CopyCharacter(pos, cc, count);
        }
Example #5
0
        public static IViewport InnerViewport(this IViewport containerViewport, TvPoint pos, int cols, int rows)
        {
            var vppos        = pos + containerViewport.Position;
            var displacement = pos;

            var availableCols = containerViewport.Columns - displacement.Left;
            var availableRows = containerViewport.Rows - displacement.Top;
            var vpCols        = cols < availableCols ? cols : availableCols;
            var vpRows        = rows < availableRows ? rows : availableRows;
            var vp            = new Viewport(vppos, vpCols, vpRows, containerViewport.ZIndex);

            return(vp);
        }
Example #6
0
 public static IViewport InnerViewport(this IViewport containerViewport, IViewport innerViewport, TvPoint displacement)
 {
     if (innerViewport == null)
     {
         return(new Viewport(TvPoint.Zero + displacement, containerViewport.Columns, containerViewport.Rows, containerViewport.ZIndex));
     }
     else
     {
         return(containerViewport.InnerViewport(innerViewport.Position + displacement, innerViewport.Columns, innerViewport.Rows));
     }
 }
Example #7
0
 public void DrawChars(char value, int count, TvPoint location, CharacterAttribute attribute)
 {
     ViewportHelper.DrawChars(value, count, location, attribute, Viewport, _console);
 }
Example #8
0
 public void DrawStringAt(string value, TvPoint location, CharacterAttribute attr)
 {
     ViewportHelper.DrawStringAt(value, location, attr, Viewport, _console);
 }
Example #9
0
 public static TvPoint ConsolePointToViewport(TvPoint consolePoint, TvPoint viewportPosition) => consolePoint - viewportPosition;
Example #10
0
 public static TvPoint ViewPointToConsolePoint(TvPoint viewPoint, TvPoint viewportPosition) => viewPoint + viewportPosition;
Example #11
0
        public static bool IsConsolePointInside(TvPoint consolePoint, TvPoint viewportPosition)
        {
            var viewPoint = ConsolePointToViewport(consolePoint, viewportPosition);

            return(consolePoint.Top >= viewportPosition.Top && consolePoint.Left >= viewportPosition.Left);
        }